Class Translator
java.lang.Object
de.hybris.platform.commons.translator.Translator
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 Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidaddAllContextProperties(HashMap<String, Object> additionalContextProperties) Add a property to the translators context propertiesvoidaddContextProperty(String propertyName, Object propertyValue) Add a property to the translators context propertiescreateNodesTree(String text) search for parts of text that would be changed to special nodes (by using parsers from) and return nodes tree (TranslatorConfigurationAbstractNode) that can be translated in next phase to output textReturns the translators context propertiesgetContextProperty(String propertyName) Returns a translators context property for a given nameconvert text to nodes list (if find any recognized text that should be changed to node)prepareNode(AbstractNode node) This is an optional method during translate process.renderContent(AbstractNode node) generate output text from childNodes if they exists otherwise from nodeText from node itselfsearch for proper renderer and use it to render node content if render doesn't exist, get default renderer.String[]searchForClosingTag(AbstractParser abstractParser, String startTag, String textToSearch) search in textToSearch closing tag for given startTag.voidsetContextProperties(HashMap<String, Object> contextProperties) Set additional properties that shall be accessale while translatingThis method translate text from input to output format.
-
Constructor Details
-
Translator
Translatorconstructor- Parameters:
config- an instance ofthat contains all required information (configuration) for thisTranslatorConfigurationTranslator
-
-
Method Details
-
createNodesTree
search for parts of text that would be changed to special nodes (by using parsers from) and return nodes tree (TranslatorConfigurationAbstractNode) that can be translated in next phase to output text- Parameters:
text- for translation- Returns:
with name mainNode, with tree structure of nodes that were found in textSimpleNode
-
parseText
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
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
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 differentTranslatormethods.- 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
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
Returns the translators context properties- Returns:
- A String:Object map
-
getContextProperty
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
Set additional properties that shall be accessale while translating- Parameters:
contextProperties- A String:Object map
-
addContextProperty
Add a property to the translators context properties- Parameters:
propertyName- The name of the property for which to add a property valuepropertyValue- The property value
-
addAllContextProperties
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
This is an optional method during translate process. It gives the possibility to do some changes on the nodes tree created by thecreateNodesTreemethod. The method can be used before therendererContentmethod starts rendering the output. By using theprepareNode(AbstractNode)theTranslatorcallsprepareNodeon each prerenderer included in the inprerendersListof the. 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.TranslatorConfiguration- Parameters:
node- usually mainNode created by thecreateNodesTreemethod- Returns:
- usually the same node as this one in method input just modified however this is not a rule
-