Class ResourceServingHelpers
java.lang.Object
com.atlassian.plugin.webresource.impl.helpers.BaseHelpers
com.atlassian.plugin.webresource.impl.helpers.url.UrlGenerationHelpers
com.atlassian.plugin.webresource.impl.helpers.ResourceServingHelpers
Stateless helper functions providing support for serving resources.
- Since:
- v6.3
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionprotected static interface -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprotected static ContentapplyStaticTransformers(Globals globals, Resource resource, Content content, Map<String, String> params, String sourceUrl) Apply Static Transformers to Resource.protected static ContentapplyTransformers(Globals globals, Resource resource, Content content, Map<String, String> params, String sourceUrl) Apply Transformers to Resource.static ContentasContent(com.atlassian.plugin.servlet.DownloadableResource downloadableResource, com.atlassian.sourcemap.ReadableSourceMap sourceMap, boolean isTransformed) Adapter, turns DownloadableResource into Content.static com.atlassian.plugin.servlet.DownloadableResourceasDownloadableResource(Content content) Adapter, turns Content into DownloadableResource.static ContentbuildEmptyContent(String contentType) static StringThe `params` contains all the params from url, so if we build the key using all params it will be correct but inefficient for the caching.static ContentbuildSafeContent(Content content, String fullResourceName) Intercept any exception and ignores it.static ResourcegetFromOSGiPluginModuleResource(Globals globals, String completeKeyOrPluginKey, String resourceName) Get Resource from an OSGi plugin module.protected static StringgetPluginKey(String completeKeyOrPluginKey) In case of Plugin Key - returns the same key, in case of Web Resource key - extracts Plugin key from it.protected static ResourcegetPluginResource(Globals globals, String completeKeyOrPluginKey, String resourceName) Get Resource for Plugin.static ResourcegetResource(RequestCache requestCache, String completeKey, String resourceName) Get resource for Web Resource or Plugin, also resolves relative paths.static ResourcegetResource(RequestCache requestCache, Collection<String> bundles, String resourceName) Get Resource for one of Web Resources.protected static ResourcegetResourceRelativeToPlugin(Globals globals, String completeKeyOrPluginKey, String resourceName) Deprecated.since v3.3.2protected static ResourcegetResourceRelativeToWebResource(RequestCache requestCache, String completeKey, String resourceName) Deprecated.since v3.3.2protected static ResourcegetWebResourceResource(RequestCache requestCache, String completeKey, String resourceName) Get Resource for Web Resource.protected static ContentSome transformers doesn't support source map, the result is that the source map chain is broken and not working.shouldBeIncludedInBatch(String type, Map<String, String> params) Select Resources that should be included in batch.static String[]splitLastPathPart(String resourcePath) Deprecated.since v3.3.2static Contenttransform(Globals globals, LinkedHashSet<String> requiredResources, String url, Resource resource, Map<String, String> params, boolean applyAnnotators) Transform given Resource by applying Transformers and Static Transformers.static Contenttransform(Globals globals, LinkedHashSet<String> requiredResources, String url, String type, Supplier<Collection<Resource>> resourcesSupplier, Map<String, String> params) Apply conditions and transformations to list of Resources and generate resulting Batch.static ContenttransformSafely(Globals globals, LinkedHashSet<String> requiredResources, String url, Resource resource, Map<String, String> params, boolean applyAnnotators) Transform given Resource by applying Transformers and Static Transformers.static ContenttransformWithoutCache(Globals globals, LinkedHashSet<String> requiredResources, String url, Resource resource, Map<String, String> params, boolean applyAnnotators) Transform given Resource by applying Transformers and Static Transformers.Methods inherited from class com.atlassian.plugin.webresource.impl.helpers.url.UrlGenerationHelpers
buildIncludedExcludedConditionsAndBatchingOptions, calculateBatches, calculateBundleHash, calculateBundlesHash, collectUrlStateAndBuildResourceUrls, createResourceUrlsForRedirectResources, encodeStateInUrlIfSupported, encodeStateInUrlIfSupported, resolveExcluded, resourcesOfType, splitBatchIntoSubBatches, splitIntoSubBatchesMethods inherited from class com.atlassian.plugin.webresource.impl.helpers.BaseHelpers
isConditionsSatisfied, isConditionsSatisfied
-
Constructor Details
-
ResourceServingHelpers
public ResourceServingHelpers()
-
-
Method Details
-
getResource
public static Resource getResource(RequestCache requestCache, String completeKey, String resourceName) Get resource for Web Resource or Plugin, also resolves relative paths.- Parameters:
completeKey- key of web resource or plugin.resourceName- name of Resource.
-
getResource
public static Resource getResource(RequestCache requestCache, Collection<String> bundles, String resourceName) Get Resource for one of Web Resources.- Parameters:
bundles- list of keys of Web Resources.resourceName- name of Resource.
-
transform
public static Content transform(Globals globals, LinkedHashSet<String> requiredResources, String url, String type, Supplier<Collection<Resource>> resourcesSupplier, Map<String, String> params) Apply conditions and transformations to list of Resources and generate resulting Batch.- Parameters:
requiredResources- only used by ModuleAnnotator#after and should be removed. see Controller#requiredResources for more details.resourcesSupplier- list of Resources supplierparams- http params.- Returns:
- resulting content.
-
transform
public static Content transform(Globals globals, LinkedHashSet<String> requiredResources, String url, Resource resource, Map<String, String> params, boolean applyAnnotators) Transform given Resource by applying Transformers and Static Transformers.- Parameters:
resource- the resource.params- http params.- Returns:
- resulting content.
-
buildKey
The `params` contains all the params from url, so if we build the key using all params it will be correct but inefficient for the caching. It's inefficient because not all params are used by transformers for the given resource.If we can detect the subset of params that's actually used by transformers fot the given resource we would be able to provide better cache hit ratio. This method calculates the key in the smart way, using only those parameters that are actually used.
-
transformWithoutCache
public static Content transformWithoutCache(Globals globals, LinkedHashSet<String> requiredResources, String url, Resource resource, Map<String, String> params, boolean applyAnnotators) Transform given Resource by applying Transformers and Static Transformers.- Parameters:
resource- the resource.params- http params.- Returns:
- resulting content.
-
transformSafely
public static Content transformSafely(Globals globals, LinkedHashSet<String> requiredResources, String url, Resource resource, Map<String, String> params, boolean applyAnnotators) Transform given Resource by applying Transformers and Static Transformers. In case of any error it will be intercepted and empty content returned.- Parameters:
resource- the resource.params- http params.- Returns:
- resulting content.
-
shouldBeIncludedInBatch
Select Resources that should be included in batch.- Parameters:
type- type of batch.params- http params of batch.- Returns:
- list of selected Resources.
-
asDownloadableResource
public static com.atlassian.plugin.servlet.DownloadableResource asDownloadableResource(Content content) Adapter, turns Content into DownloadableResource. -
asContent
public static Content asContent(com.atlassian.plugin.servlet.DownloadableResource downloadableResource, com.atlassian.sourcemap.ReadableSourceMap sourceMap, boolean isTransformed) Adapter, turns DownloadableResource into Content. -
buildEmptyContent
-
buildSafeContent
Intercept any exception and ignores it. -
applyTransformers
protected static Content applyTransformers(Globals globals, Resource resource, Content content, Map<String, String> params, String sourceUrl) Apply Transformers to Resource.- Parameters:
resource- resource.content- content of resource.params- http params.sourceUrl- url of source code for resource.- Returns:
- resulting content.
-
repairSourceMapChain
protected static Content repairSourceMapChain(Content input, ResourceServingHelpers.RepairSourceMapChainCallback cb) Some transformers doesn't support source map, the result is that the source map chain is broken and not working.We can try to fix it, if some transformer doesn't support source map - instead of breaking source map chain we'll use the previous source map.
-
applyStaticTransformers
protected static Content applyStaticTransformers(Globals globals, Resource resource, Content content, Map<String, String> params, String sourceUrl) Apply Static Transformers to Resource.- Parameters:
resource- resource.content- content of resource.params- http params.sourceUrl- url of source code for resource.- Returns:
- resulting content.
-
getWebResourceResource
protected static Resource getWebResourceResource(RequestCache requestCache, String completeKey, String resourceName) Get Resource for Web Resource.- Parameters:
completeKey- complete key of Web Resource.resourceName- name of Resource.
-
getFromOSGiPluginModuleResource
public static Resource getFromOSGiPluginModuleResource(Globals globals, String completeKeyOrPluginKey, String resourceName) Get Resource from an OSGi plugin module.- Parameters:
completeKeyOrPluginKey- complete key or plugin key.resourceName- name of Resource.
-
getResourceRelativeToWebResource
@Deprecated protected static Resource getResourceRelativeToWebResource(RequestCache requestCache, String completeKey, String resourceName) Deprecated.since v3.3.2Get Resource relative to Web Resource. -
getPluginResource
protected static Resource getPluginResource(Globals globals, String completeKeyOrPluginKey, String resourceName) Get Resource for Plugin.- Parameters:
completeKeyOrPluginKey- complete key or plugin key.resourceName- name of Resource.
-
getResourceRelativeToPlugin
@Deprecated protected static Resource getResourceRelativeToPlugin(Globals globals, String completeKeyOrPluginKey, String resourceName) Deprecated.since v3.3.2Get Resource relative to Plugin. -
splitLastPathPart
Deprecated.since v3.3.2Split path into parent folder and name. -
getPluginKey
In case of Plugin Key - returns the same key, in case of Web Resource key - extracts Plugin key from it.
-