Class Translator
- java.lang.Object
-
- de.hybris.platform.commons.translator.Translator
-
public class Translator extends java.lang.Object
This is main class for translator functionality. After creating
with all required configuration it can be used inTranslatorConfiguration
Translator
constructor. Then it is ready to translate text.
-
-
Constructor Summary
Constructors Constructor Description Translator(TranslatorConfiguration config)
Translator
constructor
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
addAllContextProperties(java.util.HashMap<java.lang.String,java.lang.Object> additionalContextProperties)
Add a property to the translators context propertiesvoid
addContextProperty(java.lang.String propertyName, java.lang.Object propertyValue)
Add a property to the translators context propertiesAbstractNode
createNodesTree(java.lang.String text)
search for parts of text that would be changed to special nodes (by using parsers from
) and return nodes tree (TranslatorConfiguration
AbstractNode
) that can be translated in next phase to output textjava.util.HashMap<java.lang.String,java.lang.Object>
getContextProperties()
Returns the translators context propertiesjava.lang.Object
getContextProperty(java.lang.String propertyName)
Returns a translators context property for a given namejava.util.List<AbstractNode>
parseText(java.lang.String text)
convert text to nodes list (if find any recognized text that should be changed to node)AbstractNode
prepareNode(AbstractNode node)
This is an optional method during translate process.java.lang.String
renderContent(AbstractNode node)
generate output text from childNodes if they exists otherwise from nodeText from node itselfjava.lang.String
renderTextFromNode(AbstractNode node)
search for proper renderer and use it to render node content if render doesn't exist, get default renderer.java.lang.String[]
searchForClosingTag(AbstractParser abstractParser, java.lang.String startTag, java.lang.String textToSearch)
search in textToSearch closing tag for given startTag.void
setContextProperties(java.util.HashMap<java.lang.String,java.lang.Object> contextProperties)
Set additional properties that shall be accessale while translatingjava.lang.String
translate(java.lang.String htmlInput)
This method translate text from input to output format.
-
-
-
Constructor Detail
-
Translator
public Translator(TranslatorConfiguration config)
Translator
constructor- Parameters:
config
- an instance of
that contains all required information (configuration) for thisTranslatorConfiguration
Translator
-
-
Method Detail
-
createNodesTree
public AbstractNode createNodesTree(java.lang.String text)
search for parts of text that would be changed to special nodes (by using parsers from
) and return nodes tree (TranslatorConfiguration
AbstractNode
) 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
public java.util.List<AbstractNode> parseText(java.lang.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 java.lang.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 java.lang.String translate(java.lang.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 differentTranslator
methods.- Parameters:
htmlInput
- text that should be translated- Returns:
- output text depending on
TranslatorConfiguration
-
searchForClosingTag
public java.lang.String[] searchForClosingTag(AbstractParser abstractParser, java.lang.String startTag, java.lang.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 java.lang.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 java.util.HashMap<java.lang.String,java.lang.Object> getContextProperties()
Returns the translators context properties- Returns:
- A String:Object map
-
getContextProperty
public java.lang.Object getContextProperty(java.lang.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(java.util.HashMap<java.lang.String,java.lang.Object> contextProperties)
Set additional properties that shall be accessale while translating- Parameters:
contextProperties
- A String:Object map
-
addContextProperty
public void addContextProperty(java.lang.String propertyName, java.lang.Object propertyValue)
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
public void addAllContextProperties(java.util.HashMap<java.lang.String,java.lang.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 thecreateNodesTree
method. The method can be used before therendererContent
method starts rendering the output. By using theprepareNode(AbstractNode)
theTranslator
callsprepareNode
on each prerenderer included in the inprerendersList
of 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 thecreateNodesTree
method- Returns:
- usually the same node as this one in method input just modified however this is not a rule
-
-