Class TransformationHelper


  • @NonNullByDefault
    public class TransformationHelper
    extends Object
    Author:
    Kai Kreuzer - Initial contribution
    • Field Detail

      • EXTRACT_TRANSFORMFUNCTION_PATTERN

        protected static final Pattern EXTRACT_TRANSFORMFUNCTION_PATTERN
    • Constructor Detail

      • TransformationHelper

        public TransformationHelper()
    • Method Detail

      • isTransform

        public static boolean isTransform​(String pattern)
        determines whether a pattern refers to a transformation service
        Parameters:
        pattern - the pattern to check
        Returns:
        true, if the pattern contains a transformation
      • getTransformationService

        public static @Nullable TransformationService getTransformationService​(@Nullable org.osgi.framework.BundleContext context,
                                                                               String transformationType)
        Queries the OSGi service registry for a service that provides a transformation service of a given transformation type (e.g. REGEX, XSLT, etc.)
        Parameters:
        context - the bundle context which can be null
        transformationType - the desired transformation type
        Returns:
        a service instance or null, if none could be found
      • transform

        public static @Nullable String transform​(org.osgi.framework.BundleContext context,
                                                 String stateDescPattern,
                                                 String state)
                                          throws TransformationException
        Transforms a state string using transformation functions within a given pattern.
        Parameters:
        context - a valid bundle context, required for accessing the services
        stateDescPattern - the pattern that contains the transformation instructions
        state - the state to be formatted before being passed into the transformation function
        Returns:
        the result of the transformation. If no transformation was done, null is returned
        Throws:
        TransformationException - if transformation service is not available or the transformation failed
      • transform

        public static @Nullable String transform​(TransformationService service,
                                                 String function,
                                                 String format,
                                                 String state)
                                          throws TransformationException
        Transforms a state string using a transformation service
        Parameters:
        service - the TransformationService to be used
        function - the function containing the transformation instruction
        format - the format the state should be converted to before transformation
        state - the state to be formatted before being passed into the transformation function
        Returns:
        the result of the transformation. If no transformation was done, null is returned
        Throws:
        TransformationException - if transformation service fails or the state cannot be formatted according to the format