Package org.omegat.filters3.xml
Class DefaultXMLDialect
- java.lang.Object
-
- org.omegat.filters3.xml.DefaultXMLDialect
-
- All Implemented Interfaces:
XMLDialect
- Direct Known Subclasses:
AndroidDialect,CamtasiaWindowsDialect,DocBookDialect,FlashDialect,HelpAndManualDialect,InfixDialect,L10nmgrDialect,OpenDocDialect,OpenXMLDialect,PropertiesDialect,RelaxNGDialect,ResXDialect,SchematronDialect,ScribusDialect,SvgDialect,TXMLDialect,Typo3Dialect,VisioDialect,WiXDialect,WordpressDialect,XHTMLDialect,XLIFFDialect,XMLSpreadsheetDialect
public class DefaultXMLDialect extends java.lang.Object implements XMLDialect
Helper class for describing a certain XML dialect.
-
-
Field Summary
-
Fields inherited from interface org.omegat.filters3.xml.XMLDialect
CONSTRAINT_DOCTYPE, CONSTRAINT_DOCTYPE_UNBOXED, CONSTRAINT_PUBLIC_DOCTYPE, CONSTRAINT_PUBLIC_DOCTYPE_UNBOXED, CONSTRAINT_ROOT, CONSTRAINT_ROOT_UNBOXED, CONSTRAINT_SYSTEM_DOCTYPE, CONSTRAINT_SYSTEM_DOCTYPE_UNBOXED, CONSTRAINT_XMLNS, CONSTRAINT_XMLNS_UNBOXED
-
-
Constructor Summary
Constructors Constructor Description DefaultXMLDialect()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description java.lang.StringconstructShortcuts(java.util.List<Element> elements, java.util.List<ProtectedPart> protectedParts)Returns shortcut string representation of the entry source.voiddefineConstraint(java.lang.Integer constraintType, java.util.regex.Pattern template)Defines a constraint to restrict supported subset of XML files.voiddefineContentBasedTag(java.lang.String tag, Tag.Type type)voiddefineIntactTag(java.lang.String tag)Defines intact tag.voiddefineIntactTags(java.lang.String[] tags)Defines a set of intact tags from an array.voiddefineOutOfTurnTag(java.lang.String tag)Defines out of turn tag.voiddefineOutOfTurnTags(java.lang.String[] tags)Defines out of turn tags.voiddefineParagraphTag(java.lang.String tag)Defines paragraph tag.voiddefineParagraphTags(java.lang.String[] tags)Defines a set of paragraph tags from an array.voiddefinePreformatTag(java.lang.String tag)Defines preformat tag.voiddefinePreformatTags(java.lang.String[] tags)Defines a set of preformat tags from an array.voiddefineShortcut(java.lang.String tag, java.lang.String shortcut)Defines a shortcut for a tag, useful for formatting tags.voiddefineShortcuts(java.lang.String[] mappings)Defines shortcuts for formatting tags.voiddefineTranslatableAttribute(java.lang.String attribute)Defines always translatable attribute (no matter what tag it belongs to).voiddefineTranslatableAttributes(java.lang.String[] attributes)Defines always translatable attributes (no matter what tag it belongs to).voiddefineTranslatableTagAttribute(java.lang.String tag, java.lang.String attribute)Defines translatable attribute of a tag.voiddefineTranslatableTagAttributes(java.lang.String tag, java.lang.String[] attributes)Defines translatable attributes of a tag.voiddefineTranslatableTagsAttribute(java.lang.String[] tags, java.lang.String attribute)Defines translatable attribute of several tags.java.lang.BooleangetClosingTagRequired()Gives the value of closingTagjava.util.Map<java.lang.Integer,java.util.regex.Pattern>getConstraints()Returns defined constraints to restrict supported subset of XML files.java.util.Map<java.lang.String,Tag.Type>getContentBasedTags()Returns the set of content based tags.java.lang.BooleangetForceSpacePreserving()Gives the value of forceSpacePreserving;java.util.Set<java.lang.String>getIntactTags()Returns the set of tags that surround intact portions of document, that should not be translated at all.java.util.Set<java.lang.String>getOutOfTurnTags()Returns the set of "out-of-turn" tags.java.util.Set<java.lang.String>getParagraphTags()Returns the set of defined paragraph tags.java.util.Set<java.lang.String>getPreformatTags()Returns the set of tags that surround preformatted text.java.util.Map<java.lang.String,java.lang.String>getShortcuts()Returns the map of tags to their shortcuts.java.lang.BooleangetTagsAggregationEnabled()Gives the value of tagsAggregationEnabled.java.util.Set<java.lang.String>getTranslatableAttributes()Returns the set of translatable attributes (no matter what tag they belong to).MultiMap<java.lang.String,java.lang.String>getTranslatableTagAttributes()Returns the multimap of translatable attributes of each tag.voidhandleXMLTag(XMLTag tag, boolean translated)Implement general purpose function to handle XML tag/attributes when necessary.org.xml.sax.InputSourceresolveEntity(java.lang.String publicId, java.lang.String systemId)Resolves external entites if child filter needs it.voidsetClosingTagRequired(boolean onOff)Sets closingTag totrueorfalsevoidsetForceSpacePreserving(boolean onOff)Set forceSpacePreserving.voidsetTagsAggregationEnabled(boolean onOff)Sets tagsAggregationEnabled totrueorfalsejava.lang.BooleanvalidateContentBasedTag(java.lang.String tag, Attributes atts)For a given tag, return wether the content of this tag should be translated, depending on the content of one attribute and the presence or absence of other attributes.java.lang.BooleanvalidateIntactTag(java.lang.String tag, Attributes atts)For a given tag, return whether the content of this tag should be translated, depending on the content of one attribute and the presence or absence of other attributes.java.lang.BooleanvalidateParagraphTag(java.lang.String tag, Attributes atts)For a given tag, return whether the content of this tag is a paragraph tag, depending on the content of one attribute (and/or the presence or absence of other attributes).java.lang.BooleanvalidatePreformatTag(java.lang.String tag, Attributes atts)For a given tag, return whether the content of this tag is a preformat tag, depending on the content of one attribute (and/or the presence or absence of other attributes).java.lang.BooleanvalidateTranslatableTag(java.lang.String tag, Attributes atts)For a given tag, return whether the content of this tag should be translated, depending on the content of one attribute and the presence or absence of other attributes.java.lang.BooleanvalidateTranslatableTagAttribute(java.lang.String tag, java.lang.String attribute, Attributes atts)Returns for a given attribute of a given tag if the attribute should be translated with the given other attributes present.
-
-
-
Method Detail
-
defineParagraphTag
public void defineParagraphTag(java.lang.String tag)
Defines paragraph tag. Allows duplicates.
-
defineParagraphTags
public void defineParagraphTags(java.lang.String[] tags)
Defines a set of paragraph tags from an array. Allows duplicates.
-
defineContentBasedTag
public void defineContentBasedTag(java.lang.String tag, Tag.Type type)
-
definePreformatTag
public void definePreformatTag(java.lang.String tag)
Defines preformat tag. Allows duplicates.
-
definePreformatTags
public void definePreformatTags(java.lang.String[] tags)
Defines a set of preformat tags from an array. Allows duplicates.
-
defineIntactTag
public void defineIntactTag(java.lang.String tag)
Defines intact tag. Allows duplicates.
-
defineIntactTags
public void defineIntactTags(java.lang.String[] tags)
Defines a set of intact tags from an array. Allows duplicates.
-
defineTranslatableTagAttribute
public void defineTranslatableTagAttribute(java.lang.String tag, java.lang.String attribute)Defines translatable attribute of a tag.
-
defineTranslatableTagAttributes
public void defineTranslatableTagAttributes(java.lang.String tag, java.lang.String[] attributes)Defines translatable attributes of a tag.
-
defineTranslatableTagsAttribute
public void defineTranslatableTagsAttribute(java.lang.String[] tags, java.lang.String attribute)Defines translatable attribute of several tags.
-
defineTranslatableAttribute
public void defineTranslatableAttribute(java.lang.String attribute)
Defines always translatable attribute (no matter what tag it belongs to).
-
defineTranslatableAttributes
public void defineTranslatableAttributes(java.lang.String[] attributes)
Defines always translatable attributes (no matter what tag it belongs to).
-
defineOutOfTurnTag
public void defineOutOfTurnTag(java.lang.String tag)
Defines out of turn tag. Such tag surrounds chunk of text that should be translated separately, not breaking currently collected text.
-
defineOutOfTurnTags
public void defineOutOfTurnTags(java.lang.String[] tags)
Defines out of turn tags. Such tags surround chunks of text that should be translated separately, not breaking currently collected text.
-
defineConstraint
public void defineConstraint(java.lang.Integer constraintType, java.util.regex.Pattern template)Defines a constraint to restrict supported subset of XML files. There can be only one constraint of each type.- Parameters:
constraintType- Type of constraint, see CONSTRAINT_... constants.template- Regular expression for a specified constrained string.
-
defineShortcut
public void defineShortcut(java.lang.String tag, java.lang.String shortcut)Defines a shortcut for a tag, useful for formatting tags. Shortcut is a short form of a tag visible to translator, and stored in OmegaT's flavor of TMX files.- Parameters:
tag- Tag name.shortcut- The shortcut for a tag.
-
defineShortcuts
public void defineShortcuts(java.lang.String[] mappings)
Defines shortcuts for formatting tags. An alternative to callingdefineShortcut(String,String)multiple times.- Parameters:
mappings- Array of strings, where even elements (0th, 2nd, etc) are tags, and odd elements are their corresponding shortcuts.
-
getParagraphTags
public java.util.Set<java.lang.String> getParagraphTags()
Returns the set of defined paragraph tags.Each entry in a set should be a String class.
- Specified by:
getParagraphTagsin interfaceXMLDialect
-
getContentBasedTags
public java.util.Map<java.lang.String,Tag.Type> getContentBasedTags()
Returns the set of content based tags.- Specified by:
getContentBasedTagsin interfaceXMLDialect
-
getPreformatTags
public java.util.Set<java.lang.String> getPreformatTags()
Returns the set of tags that surround preformatted text.Each entry in a set should be a String class.
- Specified by:
getPreformatTagsin interfaceXMLDialect
-
getIntactTags
public java.util.Set<java.lang.String> getIntactTags()
Returns the set of tags that surround intact portions of document, that should not be translated at all.Each entry in a set should be a String class.
- Specified by:
getIntactTagsin interfaceXMLDialect
-
getTranslatableTagAttributes
public MultiMap<java.lang.String,java.lang.String> getTranslatableTagAttributes()
Returns the multimap of translatable attributes of each tag.Each entry should map from a String to a set of Strings.
- Specified by:
getTranslatableTagAttributesin interfaceXMLDialect
-
validateTranslatableTagAttribute
public java.lang.Boolean validateTranslatableTagAttribute(java.lang.String tag, java.lang.String attribute, Attributes atts)Returns for a given attribute of a given tag if the attribute should be translated with the given other attributes present. If the tagAttribute is returned by getTranslatable(Tag)Attributes(), this function is called to further test the attribute within its context. This allows for example the XHTML filter to not translate the value attribute of an input-element, except when it is a button or submit or reset.- Specified by:
validateTranslatableTagAttributein interfaceXMLDialect
-
validateIntactTag
public java.lang.Boolean validateIntactTag(java.lang.String tag, Attributes atts)For a given tag, return whether the content of this tag should be translated, depending on the content of one attribute and the presence or absence of other attributes. For instance, in the ResX filter, tags should not be translated when they contain the attribute "type", or when the attribute "name" starts with ">";- Specified by:
validateIntactTagin interfaceXMLDialect- Parameters:
tag- The tag that could be translatedatts- The list of the tag attributes- Returns:
trueorfalse
-
validateContentBasedTag
public java.lang.Boolean validateContentBasedTag(java.lang.String tag, Attributes atts)Description copied from interface:XMLDialectFor a given tag, return wether the content of this tag should be translated, depending on the content of one attribute and the presence or absence of other attributes.- Specified by:
validateContentBasedTagin interfaceXMLDialect- Parameters:
tag- The tag that could be translatedatts- The list of the tag attributes- Returns:
trueorfalse
-
validateTranslatableTag
public java.lang.Boolean validateTranslatableTag(java.lang.String tag, Attributes atts)For a given tag, return whether the content of this tag should be translated, depending on the content of one attribute and the presence or absence of other attributes. For instance, in the Typo3 filter, tags should be translated when the attribute locazible="1". Contrary to validateIntactTag, this applies only to the current tag, and the tags contained in it are not affected.- Specified by:
validateTranslatableTagin interfaceXMLDialect- Parameters:
tag- The tag that could be translatedatts- The list of the tag attributes- Returns:
trueorfalse
-
validateParagraphTag
public java.lang.Boolean validateParagraphTag(java.lang.String tag, Attributes atts)For a given tag, return whether the content of this tag is a paragraph tag, depending on the content of one attribute (and/or the presence or absence of other attributes). For instance, in the XLIFF filter, the <mark> tag should start a new paragraph when the attribute "mtype" contains "seg".- Specified by:
validateParagraphTagin interfaceXMLDialect- Parameters:
tag- The tag that could be a paragraph tagatts- The list of the tag attributes- Returns:
trueorfalse
-
validatePreformatTag
public java.lang.Boolean validatePreformatTag(java.lang.String tag, Attributes atts)For a given tag, return whether the content of this tag is a preformat tag, depending on the content of one attribute (and/or the presence or absence of other attributes). For instance, in the XLIFF filter, the <mark> tag should be a preformat tag when the attribute "mtype" contains "seg".- Specified by:
validatePreformatTagin interfaceXMLDialect- Parameters:
tag- The tag that could be a preformat tagatts- The list of the tag attributes- Returns:
trueorfalse
-
getTranslatableAttributes
public java.util.Set<java.lang.String> getTranslatableAttributes()
Returns the set of translatable attributes (no matter what tag they belong to).Each entry in a set should be a String class.
- Specified by:
getTranslatableAttributesin interfaceXMLDialect
-
getOutOfTurnTags
public java.util.Set<java.lang.String> getOutOfTurnTags()
Returns the set of "out-of-turn" tags. Such tags specify chunks of text that should be translated separately, not breaking currently collected text entry. For example, footnotes in OpenDocument.Each entry in a set should be a String class.
- Specified by:
getOutOfTurnTagsin interfaceXMLDialect
-
getConstraints
public java.util.Map<java.lang.Integer,java.util.regex.Pattern> getConstraints()
Returns defined constraints to restrict supported subset of XML files. There can be only one constraint of each type, see CONSTRAINT_... constants.Each entry should map an
Integerto aPattern-- regular expression for a specified constrained string.- Specified by:
getConstraintsin interfaceXMLDialect
-
resolveEntity
public org.xml.sax.InputSource resolveEntity(java.lang.String publicId, java.lang.String systemId)Resolves external entites if child filter needs it. Default implementation returnsnull.- Specified by:
resolveEntityin interfaceXMLDialect
-
getShortcuts
public java.util.Map<java.lang.String,java.lang.String> getShortcuts()
Returns the map of tags to their shortcuts.Each entry should map a
Stringto aString-- a tag to its shortcut.- Specified by:
getShortcutsin interfaceXMLDialect
-
setClosingTagRequired
public void setClosingTagRequired(boolean onOff)
Sets closingTag totrueorfalse- Specified by:
setClosingTagRequiredin interfaceXMLDialect- Parameters:
onOff- The parameter setting whether closing tags should be used or not for empty tags.
-
getClosingTagRequired
public java.lang.Boolean getClosingTagRequired()
Gives the value of closingTag- Specified by:
getClosingTagRequiredin interfaceXMLDialect
-
setTagsAggregationEnabled
public void setTagsAggregationEnabled(boolean onOff)
Sets tagsAggregationEnabled totrueorfalse- Specified by:
setTagsAggregationEnabledin interfaceXMLDialect- Parameters:
onOff- The parameter setting whether tags aggregation can be enabled in order to reduce the number of tags shown to the user.
-
getTagsAggregationEnabled
public java.lang.Boolean getTagsAggregationEnabled()
Gives the value of tagsAggregationEnabled.- Specified by:
getTagsAggregationEnabledin interfaceXMLDialect
-
getForceSpacePreserving
public java.lang.Boolean getForceSpacePreserving()
Gives the value of forceSpacePreserving;- Specified by:
getForceSpacePreservingin interfaceXMLDialect- Returns:
- whether forceSpacePreserving is set.
-
setForceSpacePreserving
public void setForceSpacePreserving(boolean onOff)
Set forceSpacePreserving.- Specified by:
setForceSpacePreservingin interfaceXMLDialect
-
handleXMLTag
public void handleXMLTag(XMLTag tag, boolean translated)
Implement general purpose function to handle XML tag/attributes when necessary.- Specified by:
handleXMLTagin interfaceXMLDialect
-
constructShortcuts
public java.lang.String constructShortcuts(java.util.List<Element> elements, java.util.List<ProtectedPart> protectedParts)
Returns shortcut string representation of the entry source. This is what the user translates. E.g. forHere's <b>bold text</b>should returnHere's <b0>bold text</b0>.- Specified by:
constructShortcutsin interfaceXMLDialect
-
-