Class AbstractFileTransformationService<T>

  • All Implemented Interfaces:

    public abstract class AbstractFileTransformationService<T>
    extends Object
    implements TransformationService
    Base class for cacheable and localizable file based transformation TransformationService. It expects the transformation to be applied to be read from a file stored under the 'transform' folder within the configuration path. To organize the various transformations one might use subfolders.
    Gaƫl L'hopital - Initial contribution, Kai Kreuzer - File caching mechanism, Markus Rathgeb - Add locale provider support
    • Field Detail

      • cachedFiles

        protected final Map<String,​T> cachedFiles
      • watchedDirectories

        protected final List<String> watchedDirectories
    • Constructor Detail

      • AbstractFileTransformationService

        public AbstractFileTransformationService()
    • Method Detail

      • activate

        protected void activate​(org.osgi.framework.BundleContext context)
      • deactivate

        protected void deactivate()
      • getLocale

        protected Locale getLocale()
      • transform

        public @Nullable String transform​(String filename,
                                          String source)
                                   throws TransformationException

        Transforms the input source by the according method defined in subclass to another string. It expects the transformation to be read from a file which is stored under the 'conf/transform'

        Specified by:
        transform in interface TransformationService
        filename - the name of the file which contains the transformation definition. The name may contain subfoldernames as well
        source - the input to transform
        the transformed result or null if the transformation's output is null.
      • internalTransform

        protected abstract @Nullable String internalTransform​(T transform,
                                                              String source)
                                                       throws TransformationException

        Abstract method defined by subclasses to effectively operate the transformation according to its rules

        transform - transformation held by the file provided to transform method
        source - the input to transform
        the transformed result or null if the transformation couldn't be completed for any reason.
      • internalLoadTransform

        protected abstract T internalLoadTransform​(String filename)
                                            throws TransformationException

        Abstract method defined by subclasses to effectively read the transformation source file according to their own needs.

        filename - Name of the file to be read. This filename may have been transposed to a localized one
        An object containing the source file
        TransformationException - file couldn't be read for any reason
      • getLocalizedProposedFilename

        protected String getLocalizedProposedFilename​(String filename,
                                                      WatchService watchService)
        Returns the name of the localized transformation file if it actually exists, keeps the original in the other case
        filename - name of the requested transformation file
        original or localized transformation file to use
      • getSourcePath

        protected String getSourcePath()
        Returns the path to the root of the transformation folder
      • getFilenames

        protected List<String> getFilenames​(String[] validExtensions)
        Returns a list of all files with the given extensions in the transformation folder