Class TransformationHelper

java.lang.Object
org.openhab.core.transform.TransformationHelper

@NonNullByDefault public class TransformationHelper extends Object
Author:
Kai Kreuzer - Initial contribution, Jan N. Klug - Refactored to OSGi service
  • Field Details

    • FUNCTION_VALUE_DELIMITER

      public static final String FUNCTION_VALUE_DELIMITER
      See Also:
    • EXTRACT_TRANSFORMFUNCTION_PATTERN

      protected static final Pattern EXTRACT_TRANSFORMFUNCTION_PATTERN
  • Constructor Details

    • TransformationHelper

      public TransformationHelper(org.osgi.framework.BundleContext bundleContext)
  • Method Details

    • deactivate

      public void deactivate()
    • setTransformationService

      public void setTransformationService(org.osgi.framework.ServiceReference<TransformationService> ref)
    • unsetTransformationService

      public void unsetTransformationService(org.osgi.framework.ServiceReference<TransformationService> ref)
    • 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(String serviceName)
    • getTransformationService

      @Deprecated public static @Nullable TransformationService getTransformationService(@Nullable org.osgi.framework.BundleContext context, String transformationType)
      Deprecated.
      Return the transformation service that provides 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

      @Deprecated public static @Nullable String transform(org.osgi.framework.BundleContext context, String transformationString, String state) throws TransformationException
      Deprecated.
      Transforms a state string using transformation functions within a given pattern.
      Parameters:
      context - a valid bundle context, required for accessing the services
      transformationString - 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(String transformationString, String state) throws TransformationException
      Transforms a state string using transformation functions within a given pattern.
      Parameters:
      transformationString - 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