Class AbstractMinimizeManager

java.lang.Object
org.ametys.runtime.plugin.component.AbstractLogEnabled
org.ametys.core.minimize.AbstractMinimizeManager
All Implemented Interfaces:
LogEnabled, Serviceable
Direct Known Subclasses:
MinimizeCSSManager, MinimizeJSManager

public abstract class AbstractMinimizeManager extends AbstractLogEnabled implements Serviceable
Abstract minimize manager for js and css
  • Field Details

  • Constructor Details

  • Method Details

    • service

      public void service(ServiceManager smanager) throws ServiceException
      Specified by:
      service in interface Serviceable
      Throws:
      ServiceException
    • minimizeAndAggregateURIs

      public String minimizeAndAggregateURIs(List<HashCache.UriData> uris, String fileName, boolean generateSourceMap)
      Compile a list of css URI, store the generated source map and returns the minimized concatenated result
      Parameters:
      uris - The URIs to compile, e.g a list of mixed .min.css and .css URIs
      fileName - The name of the result without extension, e.g. HASH
      generateSourceMap - True to generate the source map
      Returns:
      The minimized file
    • applyMediaToContent

      protected String applyMediaToContent(String content, String media)
      Defaut implementation to apply a media to a content.
      Parameters:
      content - The content
      media - The media
      Returns:
      The content with the media
    • convertSourceMapURIs

      protected String convertSourceMapURIs(String content, String uri) throws URISyntaxException
      Convert the source map "sources" attribute by correcting the path of those values
      Parameters:
      content - The source map content
      uri - The URI (without context path)
      Returns:
      The converted source map
      Throws:
      URISyntaxException - If an error occurred
    • validateAndOutputMinimizedFile

      public void validateAndOutputMinimizedFile(Source source, OutputStream out, String sourceUri) throws IOException
      Validate a source, fix it if required, and output the result to the output stream.
      Parameters:
      source - The source
      out - The output
      sourceUri - The source uri
      Throws:
      IOException - If an error occurred while reading the source
    • isSourceMappingURLLine

      protected abstract boolean isSourceMappingURLLine(String line)
      Test if the line contains a source mapping URL
      Parameters:
      line - The line
      Returns:
      True if a source mapping url is found
    • getSourceMappingURL

      protected abstract String getSourceMappingURL(String line)
      Get the source mapping URL value from the line
      Parameters:
      line - The line
      Returns:
      The source mapping URL
    • removeSourceMappingURLLine

      protected abstract String removeSourceMappingURLLine(String content)
      Remove the source mapping url from the content
      Parameters:
      content - The content
      Returns:
      The content without the mention of the source mapping URL
    • formatSourceMappingURL

      protected abstract String formatSourceMappingURL(String sourceMapName)
      Format a source mapping URL to be added at the end of a minimized file
      Parameters:
      sourceMapName - The map name
      Returns:
      The source mapping URL line
    • getMinimizedContent

      protected abstract String getMinimizedContent(String uri, String nestedParentFilesName)
      Get the minimized content at the specified URI
      Parameters:
      uri - The uri
      nestedParentFilesName - The parents file name, can be an empty string if there are no parents
      Returns:
      The minimized content of the specified URI
    • addSourceMap

      protected abstract void addSourceMap(com.google.debugging.sourcemap.SourceMapGeneratorV3 sourceMapGenerator, int lineCount, String fileContent, String fileUri, String sourceMapUri)
      Aggregate the source map of the single file with the others
      Parameters:
      sourceMapGenerator - The aggregator helper
      lineCount - The current line count
      fileContent - The content of the file
      fileUri - The uri of the file
      sourceMapUri - The sourceMappingURL found at the end of the file content