Package com.thoughtworks.xstream.io.xml
Class XmlFriendlyNameCoder
- java.lang.Object
-
- com.thoughtworks.xstream.io.xml.XmlFriendlyNameCoder
-
- All Implemented Interfaces:
NameCoder
,java.lang.Cloneable
- Direct Known Subclasses:
XmlFriendlyReplacer
,XStream11NameCoder
public class XmlFriendlyNameCoder extends java.lang.Object implements NameCoder, java.lang.Cloneable
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.
-
-
Field Summary
Fields Modifier and Type Field Description private java.lang.String
dollarReplacement
private java.util.Map
escapeCache
private java.lang.String
escapeCharReplacement
private java.lang.String
hexPrefix
private java.util.Map
unescapeCache
private static java.util.BitSet
XML_NAME_CHARS
private static java.util.BitSet
XML_NAME_START_CHARS
-
Constructor Summary
Constructors Constructor Description XmlFriendlyNameCoder()
Construct a new XmlFriendlyNameCoder.XmlFriendlyNameCoder(java.lang.String dollarReplacement, java.lang.String escapeCharReplacement)
Construct a new XmlFriendlyNameCoder with custom replacement strings for dollar and the escape character.XmlFriendlyNameCoder(java.lang.String dollarReplacement, java.lang.String escapeCharReplacement, java.lang.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
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description java.lang.Object
clone()
protected java.util.Map
createCacheMap()
java.lang.String
decodeAttribute(java.lang.String attributeName)
Decode an attribute name to an object name.private java.lang.String
decodeName(java.lang.String name)
java.lang.String
decodeNode(java.lang.String elementName)
Decode a node name to an object name.java.lang.String
encodeAttribute(java.lang.String name)
Encode a meta-data name for an attribute in the target format.private java.lang.String
encodeName(java.lang.String name)
java.lang.String
encodeNode(java.lang.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 java.lang.Object
readResolve()
-
-
-
Field Detail
-
XML_NAME_START_CHARS
private static final java.util.BitSet XML_NAME_START_CHARS
-
XML_NAME_CHARS
private static final java.util.BitSet XML_NAME_CHARS
-
dollarReplacement
private final java.lang.String dollarReplacement
-
escapeCharReplacement
private final java.lang.String escapeCharReplacement
-
escapeCache
private transient java.util.Map escapeCache
-
unescapeCache
private transient java.util.Map unescapeCache
-
hexPrefix
private final java.lang.String hexPrefix
-
-
Constructor Detail
-
XmlFriendlyNameCoder
public XmlFriendlyNameCoder()
Construct a new XmlFriendlyNameCoder.- Since:
- 1.4
-
XmlFriendlyNameCoder
public XmlFriendlyNameCoder(java.lang.String dollarReplacement, java.lang.String escapeCharReplacement)
Construct a new XmlFriendlyNameCoder with custom replacement strings for dollar and the escape character.- Parameters:
dollarReplacement
-escapeCharReplacement
-- Since:
- 1.4
-
XmlFriendlyNameCoder
public XmlFriendlyNameCoder(java.lang.String dollarReplacement, java.lang.String escapeCharReplacement, java.lang.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 Detail
-
decodeAttribute
public java.lang.String decodeAttribute(java.lang.String attributeName)
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
public java.lang.String decodeNode(java.lang.String elementName)
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
public java.lang.String encodeAttribute(java.lang.String name)
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
public java.lang.String encodeNode(java.lang.String name)
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
private java.lang.String encodeName(java.lang.String name)
-
decodeName
private java.lang.String decodeName(java.lang.String name)
-
clone
public java.lang.Object clone()
- Overrides:
clone
in classjava.lang.Object
-
readResolve
private java.lang.Object readResolve()
-
createCacheMap
protected java.util.Map createCacheMap()
-
isXmlNameStartChar
private static boolean isXmlNameStartChar(int cp)
-
isXmlNameChar
private static boolean isXmlNameChar(int cp)
-
-