Class TranslationUtils


  • public class TranslationUtils
    extends java.lang.Object
    Utility helper functions for translation.
    • Field Summary

      Fields 
      Modifier and Type Field Description
      static com.fasterxml.jackson.databind.ObjectMapper mapper  
      static java.lang.String PN_TRANSLATION_IDS  
      static java.lang.String TRANSLATION_TOKEN  
    • Method Summary

      All Methods Static Methods Concrete Methods 
      Modifier and Type Method Description
      static void addPropertyToTranslationIds​(Resource resource, java.lang.String propertyName, java.lang.String dictKeyForPropertyName)
      Adds the given dictionary key to the resource value map
      static java.lang.String get​(java.lang.String path, java.lang.String propertyOrObjectKey, java.lang.Integer index, boolean isProperty)
      Returns unique dictionary key based on path and property provided.
      static java.lang.String get​(java.lang.String path, java.lang.String propertyOrObjectKey, java.lang.Integer index, boolean isProperty, java.lang.String originalKey)
      Returns unique dictionary key based on path and property provided.
      static java.lang.String getDictionaryPath​(ResourceResolver resourceResolver, java.lang.String guideContainerPath)
      Returns path to the old or new dictionary based on the container path provided
      static javax.jcr.Node getOrAddDictionaryNode​(ResourceResolver resolver, java.lang.String containerPath)
      Returns or adds dictionary node based on the adaptive form container path provided
      static java.lang.String getTranslationId​(Resource resource, java.lang.String propertyName, java.lang.String propertyValue)
      Returns translation id for the property name and property value
      static java.lang.String getTranslationId​(Resource resource, java.lang.String propertyName, java.lang.String propertyValue, boolean checkArray)
      Returns translation id for the property name and property value
      static java.lang.String getTranslationId​(ValueMap properties, java.lang.String propertyName, java.lang.String propertyValue)
      Returns translation id for the property name and property value
      static java.lang.String getTranslationId​(ValueMap properties, java.lang.String propertyName, java.lang.String propertyValue, boolean checkArray)
      Returns translation id for the property name and property value
      static boolean isNewTranslation​(Resource resource)
      Checks if the given resource use's new translation technique (unique keys for each property)
      static boolean isNewTranslation​(ValueMap properties)
      Checks if the given resource use's new translation technique (unique keys for each property)
      static void removePropertyFromTranslationIds​(Resource resource, java.lang.String propertyName)
      Deletes the given dictionary key from the resource value map
      • Methods inherited from class java.lang.Object

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

      • TRANSLATION_TOKEN

        public static final java.lang.String TRANSLATION_TOKEN
        See Also:
        Constant Field Values
      • PN_TRANSLATION_IDS

        public static final java.lang.String PN_TRANSLATION_IDS
        See Also:
        Constant Field Values
      • mapper

        public static final com.fasterxml.jackson.databind.ObjectMapper mapper
    • Method Detail

      • get

        public static java.lang.String get​(java.lang.String path,
                                           java.lang.String propertyOrObjectKey,
                                           java.lang.Integer index,
                                           boolean isProperty,
                                           java.lang.String originalKey)
        Returns unique dictionary key based on path and property provided. Additionally for array types, index could be provided.
        Parameters:
        path - path of the current object from its parent
        propertyOrObjectKey - property or name of the object
        index - index, if property value is of type array
        isProperty - isProperty, true if the key is a property
        originalKey - existing dictionary key, if a random id is not provided
        Returns:
        unique dictionary key
      • get

        public static java.lang.String get​(java.lang.String path,
                                           java.lang.String propertyOrObjectKey,
                                           java.lang.Integer index,
                                           boolean isProperty)
        Returns unique dictionary key based on path and property provided. Additionally for array types, index could be provided.
        Parameters:
        path - path of the current object from its parent
        propertyOrObjectKey - property or name of the object
        index - index, if property value is of type array
        isProperty - isProperty, true if the key is a property
        Returns:
        unique dictionary key
      • getDictionaryPath

        public static java.lang.String getDictionaryPath​(ResourceResolver resourceResolver,
                                                         java.lang.String guideContainerPath)
        Returns path to the old or new dictionary based on the container path provided
        Parameters:
        resourceResolver - reference to the ResourceResolver
        guideContainerPath - path to the form container
        Returns:
        path to the dictionary
      • getOrAddDictionaryNode

        public static javax.jcr.Node getOrAddDictionaryNode​(ResourceResolver resolver,
                                                            java.lang.String containerPath)
                                                     throws javax.jcr.RepositoryException
        Returns or adds dictionary node based on the adaptive form container path provided
        Parameters:
        resolver - reference to the ResourceResolver
        containerPath - path to the form container
        Returns:
        returns dicitionary node or add's one if it does not exist
        Throws:
        javax.jcr.RepositoryException
      • getTranslationId

        public static java.lang.String getTranslationId​(ValueMap properties,
                                                        java.lang.String propertyName,
                                                        java.lang.String propertyValue,
                                                        boolean checkArray)
                                                 throws java.io.IOException
        Returns translation id for the property name and property value
        Parameters:
        properties - reference to the properties ValueMap
        propertyName - name of the property
        propertyValue - property value
        checkArray - if property value is of array type, this should be true
        Returns:
        translation id of the property name stored in the resource
        Throws:
        java.io.IOException
      • getTranslationId

        public static java.lang.String getTranslationId​(ValueMap properties,
                                                        java.lang.String propertyName,
                                                        java.lang.String propertyValue)
                                                 throws java.io.IOException
        Returns translation id for the property name and property value
        Parameters:
        properties - reference to the properties ValueMap
        propertyName - name of the property
        propertyValue - property value
        Returns:
        translation id of the property name stored in the resource
        Throws:
        java.io.IOException
      • isNewTranslation

        public static boolean isNewTranslation​(ValueMap properties)
        Checks if the given resource use's new translation technique (unique keys for each property)
        Parameters:
        properties - reference to the ValueMap
        Returns:
        true for new translation technique
      • isNewTranslation

        public static boolean isNewTranslation​(Resource resource)
        Checks if the given resource use's new translation technique (unique keys for each property)
        Parameters:
        resource - reference to the Resource
        Returns:
        true for new translation technique
      • getTranslationId

        public static java.lang.String getTranslationId​(Resource resource,
                                                        java.lang.String propertyName,
                                                        java.lang.String propertyValue)
                                                 throws java.io.IOException
        Returns translation id for the property name and property value
        Parameters:
        resource - reference to the resource Resource
        propertyName - name of the property
        propertyValue - property value
        Returns:
        translation id of the property name stored in the resource
        Throws:
        java.io.IOException
      • getTranslationId

        public static java.lang.String getTranslationId​(Resource resource,
                                                        java.lang.String propertyName,
                                                        java.lang.String propertyValue,
                                                        boolean checkArray)
                                                 throws java.io.IOException
        Returns translation id for the property name and property value
        Parameters:
        resource - reference to the resource Resource
        propertyName - name of the property
        propertyValue - property value
        checkArray - if property value is of array type, this should be true
        Returns:
        translation id of the property name stored in the resource
        Throws:
        java.io.IOException
      • addPropertyToTranslationIds

        public static void addPropertyToTranslationIds​(Resource resource,
                                                       java.lang.String propertyName,
                                                       java.lang.String dictKeyForPropertyName)
                                                throws java.io.IOException,
                                                       javax.jcr.RepositoryException
        Adds the given dictionary key to the resource value map
        Parameters:
        resource - reference to the Resource
        propertyName - name of the property
        dictKeyForPropertyName - dictionary key for the property
        Throws:
        java.io.IOException
        javax.jcr.RepositoryException
      • removePropertyFromTranslationIds

        public static void removePropertyFromTranslationIds​(Resource resource,
                                                            java.lang.String propertyName)
                                                     throws java.io.IOException,
                                                            javax.jcr.RepositoryException
        Deletes the given dictionary key from the resource value map
        Parameters:
        resource - reference to the Resource
        propertyName - name of the property
        Throws:
        java.io.IOException
        javax.jcr.RepositoryException