Class ResourceServingHelpers


public class ResourceServingHelpers extends UrlGenerationHelpers
Stateless helper functions providing support for serving resources.
Since:
v6.3
  • 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 supplier
      params - 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

      public static String buildKey(Globals globals, Resource resource, Map<String,String> params)
      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

      public static Predicate<Resource> shouldBeIncludedInBatch(String type, Map<String,String> params)
      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

      public static Content buildEmptyContent(String contentType)
    • buildSafeContent

      public static Content buildSafeContent(Content content, String fullResourceName)
      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.2
      Get 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.2
      Get Resource relative to Plugin.
    • splitLastPathPart

      @Deprecated public static String[] splitLastPathPart(String resourcePath)
      Deprecated.
      since v3.3.2
      Split path into parent folder and name.
    • getPluginKey

      protected static String getPluginKey(String completeKeyOrPluginKey)
      In case of Plugin Key - returns the same key, in case of Web Resource key - extracts Plugin key from it.