public class Translator extends Object
TranslatorConfiguration with all
required configuration it can be used in Translator constructor. Then it is ready to translate text.| Constructor and Description |
|---|
Translator(TranslatorConfiguration config)
Translator constructor |
| Modifier and Type | Method and Description |
|---|---|
void |
addAllContextProperties(HashMap<String,Object> additionalContextProperties)
Add a property to the translators context properties
|
void |
addContextProperty(String propertyName,
Object propertyValue)
Add a property to the translators context properties
|
AbstractNode |
createNodesTree(String text)
search for parts of text that would be changed to special nodes (by using parsers from
) and return nodes tree (AbstractNode) that can be translated
in next phase to output text |
HashMap<String,Object> |
getContextProperties()
Returns the translators context properties
|
Object |
getContextProperty(String propertyName)
Returns a translators context property for a given name
|
List<AbstractNode> |
parseText(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.
|
String |
renderContent(AbstractNode node)
generate output text from childNodes if they exists otherwise from nodeText from node itself
|
String |
renderTextFromNode(AbstractNode node)
search 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.
|
void |
setContextProperties(HashMap<String,Object> contextProperties)
Set additional properties that shall be accessale while translating
|
String |
translate(String htmlInput)
This method translate text from input to output format.
|
public Translator(TranslatorConfiguration config)
Translator constructorconfig - an instance of TranslatorConfiguration that contains all required information
(configuration) for this Translatorpublic AbstractNode createNodesTree(String text)
TranslatorConfiguration) and return nodes tree (AbstractNode) that can be translated
in next phase to output texttext - for translationSimpleNode with name mainNode, with tree structure of nodes that were found in textpublic List<AbstractNode> parseText(String text)
public String renderTextFromNode(AbstractNode node)
node - public String translate(String htmlInput)
Translator methods.htmlInput - text that should be translatedTranslatorConfigurationpublic String[] searchForClosingTag(AbstractParser abstractParser, String startTag, String textToSearch)
public String renderContent(AbstractNode node)
node - AbstractNode that should be translated to output textpublic HashMap<String,Object> getContextProperties()
public Object getContextProperty(String propertyName)
propertyName - The name of the property for which to get the property valuepublic void setContextProperties(HashMap<String,Object> contextProperties)
contextProperties - A String:Object mappublic void addContextProperty(String propertyName, Object propertyValue)
propertyName - The name of the property for which to add a property valuepropertyValue - The property valuepublic void addAllContextProperties(HashMap<String,Object> additionalContextProperties)
additionalContextProperties - A String:Object map of properties that shall be added to the translators context propertiespublic AbstractNode prepareNode(AbstractNode node)
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.node - usually mainNode created by the createNodesTree methodCopyright © 2017 SAP SE. All Rights Reserved.