Class Translator

java.lang.Object
de.hybris.platform.commons.translator.Translator

public class Translator extends Object
This is main class for translator functionality. After creating TranslatorConfiguration with all required configuration it can be used in Translator constructor. Then it is ready to translate text.
  • Constructor Details

  • Method Details

    • createNodesTree

      public AbstractNode createNodesTree(String text)
      search for parts of text that would be changed to special nodes (by using parsers from TranslatorConfiguration) and return nodes tree (AbstractNode) that can be translated in next phase to output text
      Parameters:
      text - for translation
      Returns:
      SimpleNode with name mainNode, with tree structure of nodes that were found in text
    • parseText

      public List<AbstractNode> parseText(String text)
      convert text to nodes list (if find any recognized text that should be changed to node)
      Returns:
      if text is null or none nodes were found in text then return null
    • renderTextFromNode

      public String renderTextFromNode(AbstractNode node)
      search for proper renderer and use it to render node content if render doesn't exist, get default renderer. This method doesn't check if node has children
      Parameters:
      node -
      Returns:
      String that node was translated to
    • translate

      public String translate(String htmlInput)
      This method translate text from input to output format. All translator phases are done after this one method call. To go trough the phases one by one use different Translator methods.
      Parameters:
      htmlInput - text that should be translated
      Returns:
      output text depending on TranslatorConfiguration
    • searchForClosingTag

      public String[] searchForClosingTag(AbstractParser abstractParser, String startTag, String textToSearch)
      search in textToSearch closing tag for given startTag. Mechanism find first closing tag in textToSearch and create initial tagText, then check if all opening tags in this textTag are closed, if not then mechanism search for next closing tag (next loop)
      Returns:
      String[] startTag, endTag ,tagText
    • renderContent

      public String renderContent(AbstractNode node)
      generate output text from childNodes if they exists otherwise from nodeText from node itself
      Parameters:
      node - AbstractNode that should be translated to output text
      Returns:
      String that was node was translated to
    • getContextProperties

      public HashMap<String,Object> getContextProperties()
      Returns the translators context properties
      Returns:
      A String:Object map
    • getContextProperty

      public Object getContextProperty(String propertyName)
      Returns a translators context property for a given name
      Parameters:
      propertyName - The name of the property for which to get the property value
      Returns:
      The property value
    • setContextProperties

      public void setContextProperties(HashMap<String,Object> contextProperties)
      Set additional properties that shall be accessale while translating
      Parameters:
      contextProperties - A String:Object map
    • addContextProperty

      public void addContextProperty(String propertyName, Object propertyValue)
      Add a property to the translators context properties
      Parameters:
      propertyName - The name of the property for which to add a property value
      propertyValue - The property value
    • addAllContextProperties

      public void addAllContextProperties(HashMap<String,Object> additionalContextProperties)
      Add a property to the translators context properties
      Parameters:
      additionalContextProperties - A String:Object map of properties that shall be added to the translators context properties
    • prepareNode

      public AbstractNode prepareNode(AbstractNode node)
      This is an optional method during translate process. It gives the possibility to do some changes on the nodes tree created by the createNodesTree method. The method can be used before the rendererContent method starts rendering the output. By using the prepareNode(AbstractNode) the Translator calls prepareNode on each prerenderer included in the in prerendersList of the TranslatorConfiguration. For example this mechanism is used when translating HTML text to InDesign. It replaces all angle brackets (> and < symbols), because they are not allowed in InDesign.
      Parameters:
      node - usually mainNode created by the createNodesTree method
      Returns:
      usually the same node as this one in method input just modified however this is not a rule