Class AbstractFileTransformationService<T>

  • All Implemented Interfaces:
    TransformationService

    @NonNullByDefault
    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.
    Author:
    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
        Parameters:
        filename - the name of the file which contains the transformation definition. The name may contain subfoldernames as well
        source - the input to transform
        Returns:
        the transformed result or null if the transformation's output is null.
        Throws:
        TransformationException
      • internalTransform

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

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

        Parameters:
        transform - transformation held by the file provided to transform method
        source - the input to transform
        Returns:
        the transformed result or null if the transformation couldn't be completed for any reason.
        Throws:
        TransformationException
      • 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.

        Parameters:
        filename - Name of the file to be read. This filename may have been transposed to a localized one
        Returns:
        An object containing the source file
        Throws:
        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
        Parameters:
        filename - name of the requested transformation file
        Returns:
        original or localized transformation file to use
      • getSourcePath

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