Top Description Fields Constructors Methods
com.thoughtworks.xstream.io.xml

public Class XmlFriendlyNameCoder

extends Object
implements NameCoder, Cloneable
Class Inheritance
All Implemented Interfaces
java.lang.Cloneable, com.thoughtworks.xstream.io.naming.NameCoder
Known Direct Subclasses
com.thoughtworks.xstream.io.xml.XmlFriendlyReplacer, com.thoughtworks.xstream.io.xml.XStream11NameCoder
Imports
com.thoughtworks.xstream.converters.reflection.ObjectAccessException, com.thoughtworks.xstream.io.naming.NameCoder, java.util.BitSet, .HashMap, .Map

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:

The valid characters are defined by the intersection of the XML 1.0 specification (4th edition) and later specifications till XML 1.1 specification.

Authors
Jörg Schaible, Mauro Talevi, Tatu Saloranta, Michael Schnell
Since
1.4
See Also
XML 1.0 name definition (5th edition), XML 1.0 name definition (4th edition), XML 1.1 name definition, Java identifier definition

Field Summary

Modifier and TypeField and Description
private final String
private transient Map<K, V>
private final String
private final String
private transient Map<K, V>
private static final BitSet
private static final BitSet

Constructor Summary

AccessConstructor and Description
public
XmlFriendlyNameCoder()

Construct a new XmlFriendlyNameCoder.

public
XmlFriendlyNameCoder(String dollarReplacement, String escapeCharReplacement)

Construct a new XmlFriendlyNameCoder with custom replacement strings for dollar and the escape character.

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.

Method Summary

Modifier and TypeMethod and Description
public Object
clone()

Overrides java.lang.Object.clone.

Creates and returns a copy of this object.
protected Map<K, V>
public String
decodeAttribute(String
the name of the attribute
attributeName
)

Implements com.thoughtworks.xstream.io.naming.NameCoder.decodeAttribute.

Decode an attribute name to an object name.
private String
public String
decodeNode(String
the name of the node
elementName
)

Implements com.thoughtworks.xstream.io.naming.NameCoder.decodeNode.

Decode a node name to an object name.
public String
encodeAttribute(String
the name of the meta-data
name
)

Implements com.thoughtworks.xstream.io.naming.NameCoder.encodeAttribute.

Encode a meta-data name for an attribute in the target format.
private String
public String
encodeNode(String
the name of the object data
name
)

Implements com.thoughtworks.xstream.io.naming.NameCoder.encodeNode.

Encode an object name for a node in the target format.
private static boolean
isXmlNameChar(final int cp)

private static boolean
isXmlNameStartChar(final int cp)

private Object
Inherited from java.lang.Object:
equalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

dollarReplacementback to summary
private final String dollarReplacement
escapeCacheback to summary
private transient Map<K, V> escapeCache
escapeCharReplacementback to summary
private final String escapeCharReplacement
hexPrefixback to summary
private final String hexPrefix
unescapeCacheback to summary
private transient Map<K, V> unescapeCache
XML_NAME_CHARSback to summary
private static final BitSet XML_NAME_CHARS
XML_NAME_START_CHARSback to summary
private static final BitSet XML_NAME_START_CHARS

Constructor Detail

XmlFriendlyNameCoderback to summary
public XmlFriendlyNameCoder()

Construct a new XmlFriendlyNameCoder.

Since
1.4
XmlFriendlyNameCoderback to summary
public XmlFriendlyNameCoder(String dollarReplacement, String escapeCharReplacement)

Construct a new XmlFriendlyNameCoder with custom replacement strings for dollar and the escape character.

Since
1.4
XmlFriendlyNameCoderback to summary
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.

Since
1.4

Method Detail

cloneback to summary
public Object clone()

Overrides java.lang.Object.clone.

Doc from java.lang.Object.clone.

Creates and returns a copy of this object. The precise meaning of "copy" may depend on the class of the object. The general intent is that, for any object x, the expression:

x.clone() != x
will be true, and that the expression:
x.clone().getClass() == x.getClass()
will be true, but these are not absolute requirements. While it is typically the case that:
x.clone().equals(x)
will be true, this is not an absolute requirement.

By convention, the returned object should be obtained by calling super.clone. If a class and all of its superclasses (except Object) obey this convention, it will be the case that x.clone().getClass() == x.getClass().

By convention, the object returned by this method should be independent of this object (which is being cloned). To achieve this independence, it may be necessary to modify one or more fields of the object returned by super.clone before returning it. Typically, this means copying any mutable objects that comprise the internal "deep structure" of the object being cloned and replacing the references to these objects with references to the copies. If a class contains only primitive fields or references to immutable objects, then it is usually the case that no fields in the object returned by super.clone need to be modified.

Returns:Object

a clone of this instance.

createCacheMapback to summary
protected Map<K, V> createCacheMap()
decodeAttributeback to summary
public String decodeAttribute(String attributeName)

Implements com.thoughtworks.xstream.io.naming.NameCoder.decodeAttribute.

Doc from com.thoughtworks.xstream.io.naming.NameCoder.decodeAttribute.

Decode an attribute name to an object name.

Parameters
attributeName:String

the name of the attribute

Returns:String

the name of the meta-data

decodeNameback to summary
private String decodeName(String name)
decodeNodeback to summary
public String decodeNode(String elementName)

Implements com.thoughtworks.xstream.io.naming.NameCoder.decodeNode.

Doc from com.thoughtworks.xstream.io.naming.NameCoder.decodeNode.

Decode a node name to an object name.

Parameters
elementName:String

the name of the node

Returns:String

the name of the object

encodeAttributeback to summary
public String encodeAttribute(String name)

Implements com.thoughtworks.xstream.io.naming.NameCoder.encodeAttribute.

Doc from com.thoughtworks.xstream.io.naming.NameCoder.encodeAttribute.

Encode a meta-data name for an attribute in the target format.

Parameters
name:String

the name of the meta-data

Returns:String

the attribute name in the target format

encodeNameback to summary
private String encodeName(String name)
encodeNodeback to summary
public String encodeNode(String name)

Implements com.thoughtworks.xstream.io.naming.NameCoder.encodeNode.

Doc from com.thoughtworks.xstream.io.naming.NameCoder.encodeNode.

Encode an object name for a node in the target format.

Parameters
name:String

the name of the object data

Returns:String

the node name in the target format

isXmlNameCharback to summary
private static boolean isXmlNameChar(final int cp)
isXmlNameStartCharback to summary
private static boolean isXmlNameStartChar(final int cp)
readResolveback to summary
private Object readResolve()