Class SharedDataContextUtils


  • public class SharedDataContextUtils
    extends java.lang.Object
    DataContextUtils provides methods for using a set of context data to substitute property references, generate environment variables, and expand tokens in a file.
    • Method Summary

      All Methods Static Methods Concrete Methods 
      Modifier and Type Method Description
      static java.lang.String escapeShell​(java.lang.String s)
      Escape characters meaningful to bash shell unless the string is already surrounded in single quotes
      static java.lang.String escapeWindowsShell​(java.lang.String s)
      Escape characters meaningful to windows unless the string is already surrounded in single quotes
      static ReadableSharedContext outputContext​(ContextView defaultView)  
      static <T extends ViewTraverse<T>>
      java.lang.String[]
      replaceDataReferences​(java.lang.String[] args, MultiDataContext<T,​DataContext> data, T currentContext, java.util.function.BiFunction<java.lang.Integer,​java.lang.String,​T> viewMap, Converter<java.lang.String,​java.lang.String> converter, boolean failIfUnexpanded, boolean blankIfUnexpanded)
      Replace the embedded properties of the form '${key.name}' in the input Strings with the value from the data context
      static <T extends ViewTraverse<T>>
      java.lang.String
      replaceDataReferences​(java.lang.String input, MultiDataContext<T,​DataContext> data, T currentContext, java.util.function.BiFunction<java.lang.Integer,​java.lang.String,​T> viewMap, Converter<java.lang.String,​java.lang.String> converter, boolean failOnUnexpanded, boolean blankIfUnexpanded)
      Replace the embedded properties of the form '${key.name}' in the input Strings with the value from the data context
      static <T extends ViewTraverse<T>>
      java.util.Map<java.lang.String,​java.lang.Object>
      replaceDataReferences​(java.util.Map<java.lang.String,​java.lang.Object> input, T currentContext, java.util.function.BiFunction<java.lang.Integer,​java.lang.String,​T> viewMap, Converter<java.lang.String,​java.lang.String> converter, MultiDataContext<T,​DataContext> data)
      Recursively replace data references in the values in a map which contains either string, collection or Map values.
      static <T extends ViewTraverse<T>>
      java.util.Map<java.lang.String,​java.lang.Object>
      replaceDataReferences​(java.util.Map<java.lang.String,​java.lang.Object> input, T currentContext, java.util.function.BiFunction<java.lang.Integer,​java.lang.String,​T> viewMap, Converter<java.lang.String,​java.lang.String> converter, MultiDataContext<T,​DataContext> data, boolean failOnUnexpanded, boolean blankIfUnexpanded)
      Recursively replace data references in the values in a map which contains either string, collection or Map values.
      static <T extends ViewTraverse<T>>
      java.util.Map<java.lang.String,​java.lang.Object>
      replaceDataReferences​(java.util.Map<java.lang.String,​java.lang.Object> input, T currentContext, java.util.function.BiFunction<java.lang.Integer,​java.lang.String,​T> viewMap, Converter<java.lang.String,​java.lang.String> converter, MultiDataContext<T,​DataContext> data, boolean failOnUnexpanded, java.util.Map<java.lang.String,​java.lang.Boolean> blankIfUnexpandedFieldMap)
      Recursively replace data references in the values in a map which contains either string, collection or Map values.
      static <T extends ViewTraverse<T>>
      java.util.Map<java.lang.String,​java.lang.Object>
      replaceDataReferences​(java.util.Map<java.lang.String,​java.lang.Object> input, T currentContext, java.util.function.BiFunction<java.lang.Integer,​java.lang.String,​T> viewMap, Converter<java.lang.String,​java.lang.String> converter, MultiDataContext<T,​DataContext> data, boolean failOnUnexpanded, java.util.Map<java.lang.String,​java.lang.Boolean> blankIfUnexpandedFieldMap, java.util.function.BiFunction<java.lang.String,​java.lang.Object,​java.lang.Object> inputConverter, java.util.function.BiFunction<java.lang.String,​java.lang.Object,​java.lang.Object> outputConverter)
      Recursively replace data references in the values in a map which contains either string, collection or Map values.
      static <T extends ViewTraverse<T>>
      java.lang.Object
      replaceDataReferencesInObject​(java.lang.Object o, T currentContext, java.util.function.BiFunction<java.lang.Integer,​java.lang.String,​T> viewMap, Converter<java.lang.String,​java.lang.String> converter, MultiDataContext<T,​DataContext> data)  
      static <T extends ViewTraverse<T>>
      java.lang.Object
      replaceDataReferencesInObject​(java.lang.Object o, T currentContext, java.util.function.BiFunction<java.lang.Integer,​java.lang.String,​T> viewMap, Converter<java.lang.String,​java.lang.String> converter, MultiDataContext<T,​DataContext> data, boolean failOnUnexpanded, boolean blankIfUnexpanded)  
      static void replaceTokensInReader​(java.io.Reader reader, MultiDataContext<ContextView,​DataContext> dataContext, ScriptfileUtils.LineEndingStyle style, java.io.File destination, java.lang.String nodeName)
      Copies the source stream to a temp file or specific destination, replacing the @key.X@ tokens with the values from the data context
      static void replaceTokensInReader​(java.io.Reader reader, MultiDataContext<ContextView,​DataContext> dataContext, ScriptfileUtils.LineEndingStyle style, java.io.File destination, java.lang.String nodeName, boolean blankIfMissing, boolean addBom)
      Copies the source stream to a temp file or specific destination, replacing the @key.X@ tokens with the values from the data context
      static void replaceTokensInScript​(java.lang.String script, MultiDataContext<ContextView,​DataContext> dataContext, ScriptfileUtils.LineEndingStyle style, java.io.File destination, java.lang.String nodeName, boolean addBom)
      Copies the source file to a file, replacing the @key.X@ tokens with the values from the data context
      static void replaceTokensInScript​(java.lang.String script, MultiDataContext<ContextView,​DataContext> dataContext, ScriptfileUtils.LineEndingStyle style, java.io.File destination, java.lang.String nodeName, boolean blankIfMissing, boolean addBom)
      Copies the source file to a file, replacing the @key.X@ tokens with the values from the data context
      static void replaceTokensInStream​(java.io.InputStream stream, MultiDataContext<ContextView,​DataContext> dataContext, ScriptfileUtils.LineEndingStyle style, java.io.File destination, java.lang.String nodeName, boolean addBom)
      Copies the source stream to a temp file or specific destination, replacing the @key.X@ tokens with the values from the data context
      static WFSharedContext sharedContext()  
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Field Detail

      • PROPERTY_REF_REGEX

        public static final java.lang.String PROPERTY_REF_REGEX
        See Also:
        Constant Field Values
      • PROPERTY_VIEW_REF_REGEX

        public static final java.lang.String PROPERTY_VIEW_REF_REGEX
        See Also:
        Constant Field Values
      • PROPERTY_REF_PATTERN

        public static final java.util.regex.Pattern PROPERTY_REF_PATTERN
      • UNQUOTEDPROPERTY_PREFIX

        public static final java.lang.String UNQUOTEDPROPERTY_PREFIX
        See Also:
        Constant Field Values
      • UNQUOTEDPROPERTY_REF_PATTERN

        public static final java.util.regex.Pattern UNQUOTEDPROPERTY_REF_PATTERN
    • Constructor Detail

      • SharedDataContextUtils

        public SharedDataContextUtils()
    • Method Detail

      • sharedContext

        public static WFSharedContext sharedContext()
        Returns:
        A new context
      • replaceDataReferences

        public static <T extends ViewTraverse<T>> java.lang.String[] replaceDataReferences​(java.lang.String[] args,
                                                                                           MultiDataContext<T,​DataContext> data,
                                                                                           T currentContext,
                                                                                           java.util.function.BiFunction<java.lang.Integer,​java.lang.String,​T> viewMap,
                                                                                           Converter<java.lang.String,​java.lang.String> converter,
                                                                                           boolean failIfUnexpanded,
                                                                                           boolean blankIfUnexpanded)
        Replace the embedded properties of the form '${key.name}' in the input Strings with the value from the data context
        Parameters:
        args - input string array
        data - data context map
        converter - converter to encode/convert the expanded values
        failIfUnexpanded - true to fail if a reference is not found
        blankIfUnexpanded - true to use blank if a reference is not found
        Returns:
        string with values substituted, or original string
      • replaceDataReferences

        public static <T extends ViewTraverse<T>> java.lang.String replaceDataReferences​(java.lang.String input,
                                                                                         MultiDataContext<T,​DataContext> data,
                                                                                         T currentContext,
                                                                                         java.util.function.BiFunction<java.lang.Integer,​java.lang.String,​T> viewMap,
                                                                                         Converter<java.lang.String,​java.lang.String> converter,
                                                                                         boolean failOnUnexpanded,
                                                                                         boolean blankIfUnexpanded)
        Replace the embedded properties of the form '${key.name}' in the input Strings with the value from the data context
        Parameters:
        input - input string
        data - data context map
        converter - converter to encode/convert the expanded values
        failOnUnexpanded - true to fail if a reference is not found
        blankIfUnexpanded - true to use blank if a reference is not found
        Returns:
        string with values substituted, or original string
      • escapeShell

        public static java.lang.String escapeShell​(java.lang.String s)
        Escape characters meaningful to bash shell unless the string is already surrounded in single quotes
        Parameters:
        s - string
        Returns:
        escaped string
      • escapeWindowsShell

        public static java.lang.String escapeWindowsShell​(java.lang.String s)
        Escape characters meaningful to windows unless the string is already surrounded in single quotes
        Parameters:
        s - string
        Returns:
        escaped string
      • replaceTokensInScript

        public static void replaceTokensInScript​(java.lang.String script,
                                                 MultiDataContext<ContextView,​DataContext> dataContext,
                                                 ScriptfileUtils.LineEndingStyle style,
                                                 java.io.File destination,
                                                 java.lang.String nodeName,
                                                 boolean addBom)
                                          throws java.io.IOException
        Copies the source file to a file, replacing the @key.X@ tokens with the values from the data context
        Parameters:
        script - source file path
        dataContext - input data context
        style - line ending style
        destination - destination file, or null to create a temp file
        Throws:
        java.io.IOException - on io error
      • replaceTokensInScript

        public static void replaceTokensInScript​(java.lang.String script,
                                                 MultiDataContext<ContextView,​DataContext> dataContext,
                                                 ScriptfileUtils.LineEndingStyle style,
                                                 java.io.File destination,
                                                 java.lang.String nodeName,
                                                 boolean blankIfMissing,
                                                 boolean addBom)
                                          throws java.io.IOException
        Copies the source file to a file, replacing the @key.X@ tokens with the values from the data context
        Parameters:
        script - source file path
        dataContext - input data context
        style - line ending style
        destination - destination file, or null to create a temp file
        Throws:
        java.io.IOException - on io error
      • replaceTokensInStream

        public static void replaceTokensInStream​(java.io.InputStream stream,
                                                 MultiDataContext<ContextView,​DataContext> dataContext,
                                                 ScriptfileUtils.LineEndingStyle style,
                                                 java.io.File destination,
                                                 java.lang.String nodeName,
                                                 boolean addBom)
                                          throws java.io.IOException
        Copies the source stream to a temp file or specific destination, replacing the @key.X@ tokens with the values from the data context
        Parameters:
        stream - source stream
        dataContext - input data context
        style - script file line ending style to use
        destination - destination file
        Throws:
        java.io.IOException - on io error
      • replaceTokensInReader

        public static void replaceTokensInReader​(java.io.Reader reader,
                                                 MultiDataContext<ContextView,​DataContext> dataContext,
                                                 ScriptfileUtils.LineEndingStyle style,
                                                 java.io.File destination,
                                                 java.lang.String nodeName)
                                          throws java.io.IOException
        Copies the source stream to a temp file or specific destination, replacing the @key.X@ tokens with the values from the data context
        Parameters:
        reader - reader
        dataContext - input data context
        style - script file line ending style to use
        destination - destination file
        Throws:
        java.io.IOException - on io error
      • replaceTokensInReader

        public static void replaceTokensInReader​(java.io.Reader reader,
                                                 MultiDataContext<ContextView,​DataContext> dataContext,
                                                 ScriptfileUtils.LineEndingStyle style,
                                                 java.io.File destination,
                                                 java.lang.String nodeName,
                                                 boolean blankIfMissing,
                                                 boolean addBom)
                                          throws java.io.IOException
        Copies the source stream to a temp file or specific destination, replacing the @key.X@ tokens with the values from the data context
        Parameters:
        reader - reader
        dataContext - input data context
        style - script file line ending style to use
        destination - destination file
        Throws:
        java.io.IOException - on io error
      • replaceDataReferences

        public static <T extends ViewTraverse<T>> java.util.Map<java.lang.String,​java.lang.Object> replaceDataReferences​(java.util.Map<java.lang.String,​java.lang.Object> input,
                                                                                                                               T currentContext,
                                                                                                                               java.util.function.BiFunction<java.lang.Integer,​java.lang.String,​T> viewMap,
                                                                                                                               Converter<java.lang.String,​java.lang.String> converter,
                                                                                                                               MultiDataContext<T,​DataContext> data)
        Recursively replace data references in the values in a map which contains either string, collection or Map values.
        Parameters:
        input - input map
        data - context data
        Returns:
        Map with all string values having references replaced
      • replaceDataReferences

        public static <T extends ViewTraverse<T>> java.util.Map<java.lang.String,​java.lang.Object> replaceDataReferences​(java.util.Map<java.lang.String,​java.lang.Object> input,
                                                                                                                               T currentContext,
                                                                                                                               java.util.function.BiFunction<java.lang.Integer,​java.lang.String,​T> viewMap,
                                                                                                                               Converter<java.lang.String,​java.lang.String> converter,
                                                                                                                               MultiDataContext<T,​DataContext> data,
                                                                                                                               boolean failOnUnexpanded,
                                                                                                                               boolean blankIfUnexpanded)
        Recursively replace data references in the values in a map which contains either string, collection or Map values.
        Parameters:
        input - input map
        data - context data
        Returns:
        Map with all string values having references replaced
      • replaceDataReferences

        public static <T extends ViewTraverse<T>> java.util.Map<java.lang.String,​java.lang.Object> replaceDataReferences​(java.util.Map<java.lang.String,​java.lang.Object> input,
                                                                                                                               T currentContext,
                                                                                                                               java.util.function.BiFunction<java.lang.Integer,​java.lang.String,​T> viewMap,
                                                                                                                               Converter<java.lang.String,​java.lang.String> converter,
                                                                                                                               MultiDataContext<T,​DataContext> data,
                                                                                                                               boolean failOnUnexpanded,
                                                                                                                               java.util.Map<java.lang.String,​java.lang.Boolean> blankIfUnexpandedFieldMap)
        Recursively replace data references in the values in a map which contains either string, collection or Map values.
        Parameters:
        input - input map
        data - context data
        Returns:
        Map with all string values having references replaced
      • replaceDataReferences

        public static <T extends ViewTraverse<T>> java.util.Map<java.lang.String,​java.lang.Object> replaceDataReferences​(java.util.Map<java.lang.String,​java.lang.Object> input,
                                                                                                                               T currentContext,
                                                                                                                               java.util.function.BiFunction<java.lang.Integer,​java.lang.String,​T> viewMap,
                                                                                                                               Converter<java.lang.String,​java.lang.String> converter,
                                                                                                                               MultiDataContext<T,​DataContext> data,
                                                                                                                               boolean failOnUnexpanded,
                                                                                                                               java.util.Map<java.lang.String,​java.lang.Boolean> blankIfUnexpandedFieldMap,
                                                                                                                               java.util.function.BiFunction<java.lang.String,​java.lang.Object,​java.lang.Object> inputConverter,
                                                                                                                               java.util.function.BiFunction<java.lang.String,​java.lang.Object,​java.lang.Object> outputConverter)
        Recursively replace data references in the values in a map which contains either string, collection or Map values.
        Parameters:
        input - input map
        data - context data
        Returns:
        Map with all string values having references replaced
      • replaceDataReferencesInObject

        public static <T extends ViewTraverse<T>> java.lang.Object replaceDataReferencesInObject​(java.lang.Object o,
                                                                                                 T currentContext,
                                                                                                 java.util.function.BiFunction<java.lang.Integer,​java.lang.String,​T> viewMap,
                                                                                                 Converter<java.lang.String,​java.lang.String> converter,
                                                                                                 MultiDataContext<T,​DataContext> data)
      • replaceDataReferencesInObject

        public static <T extends ViewTraverse<T>> java.lang.Object replaceDataReferencesInObject​(java.lang.Object o,
                                                                                                 T currentContext,
                                                                                                 java.util.function.BiFunction<java.lang.Integer,​java.lang.String,​T> viewMap,
                                                                                                 Converter<java.lang.String,​java.lang.String> converter,
                                                                                                 MultiDataContext<T,​DataContext> data,
                                                                                                 boolean failOnUnexpanded,
                                                                                                 boolean blankIfUnexpanded)