Package com.thoughtworks.xstream.io.xml
Class XmlFriendlyNameCoder
java.lang.Object
com.thoughtworks.xstream.io.xml.XmlFriendlyNameCoder
- Direct Known Subclasses:
XmlFriendlyReplacer
,XStream11NameCoder
Encode and decode tag and attribute names in XML drivers.
This NameCoder is designed to ensure the correct encoding and decoding of names used for Java types and fields to XML tags and attribute names.
The default replacements are:
- $ (dollar) chars are replaced with _- (underscore dash) string.
- _ (underscore) chars are replaced with __ (double underscore) string.
- other characters that are invalid in XML names are encoded with _.XXXX (underscore dot followed by hex representation of character).
The valid characters are defined by the intersection of the XML 1.0 specification (4th edition) and later specifications till XML 1.1 specification.
- Since:
- 1.4
- See Also:
-
Field Summary
Fields -
Constructor Summary
ConstructorsConstructorDescriptionConstruct a new XmlFriendlyNameCoder.XmlFriendlyNameCoder
(String dollarReplacement, String escapeCharReplacement) Construct a new XmlFriendlyNameCoder with custom replacement strings for dollar and the escape character.XmlFriendlyNameCoder
(String dollarReplacement, String escapeCharReplacement, String hexPrefix) Construct a new XmlFriendlyNameCoder with custom replacement strings for dollar, the escape character and the prefix for hexadecimal encoding of invalid characters in XML names. -
Method Summary
Modifier and TypeMethodDescriptionclone()
protected Map
decodeAttribute
(String attributeName) Decode an attribute name to an object name.private String
decodeName
(String name) decodeNode
(String elementName) Decode a node name to an object name.encodeAttribute
(String name) Encode a meta-data name for an attribute in the target format.private String
encodeName
(String name) encodeNode
(String name) Encode an object name for a node in the target format.private static boolean
isXmlNameChar
(int cp) private static boolean
isXmlNameStartChar
(int cp) private Object
-
Field Details
-
XML_NAME_START_CHARS
-
XML_NAME_CHARS
-
dollarReplacement
-
escapeCharReplacement
-
escapeCache
-
unescapeCache
-
hexPrefix
-
-
Constructor Details
-
XmlFriendlyNameCoder
public XmlFriendlyNameCoder()Construct a new XmlFriendlyNameCoder.- Since:
- 1.4
-
XmlFriendlyNameCoder
Construct a new XmlFriendlyNameCoder with custom replacement strings for dollar and the escape character.- Parameters:
dollarReplacement
-escapeCharReplacement
-- Since:
- 1.4
-
XmlFriendlyNameCoder
public XmlFriendlyNameCoder(String dollarReplacement, String escapeCharReplacement, String hexPrefix) Construct a new XmlFriendlyNameCoder with custom replacement strings for dollar, the escape character and the prefix for hexadecimal encoding of invalid characters in XML names.- Parameters:
dollarReplacement
-escapeCharReplacement
-- Since:
- 1.4
-
-
Method Details
-
decodeAttribute
Decode an attribute name to an object name.- Specified by:
decodeAttribute
in interfaceNameCoder
- Parameters:
attributeName
- the name of the attribute- Returns:
- the name of the meta-data
-
decodeNode
Decode a node name to an object name.- Specified by:
decodeNode
in interfaceNameCoder
- Parameters:
elementName
- the name of the node- Returns:
- the name of the object
-
encodeAttribute
Encode a meta-data name for an attribute in the target format.- Specified by:
encodeAttribute
in interfaceNameCoder
- Parameters:
name
- the name of the meta-data- Returns:
- the attribute name in the target format
-
encodeNode
Encode an object name for a node in the target format.- Specified by:
encodeNode
in interfaceNameCoder
- Parameters:
name
- the name of the object data- Returns:
- the node name in the target format
-
encodeName
-
decodeName
-
clone
-
readResolve
-
createCacheMap
-
isXmlNameStartChar
private static boolean isXmlNameStartChar(int cp) -
isXmlNameChar
private static boolean isXmlNameChar(int cp)
-