Class 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.

    Since:
    1.4
    Author:
    Jörg Schaible, Mauro Talevi, Tatu Saloranta, Michael Schnell
    See Also:
    XML 1.0 name definition (5th edition), XML 1.0 name definition (4th edition), XML 1.1 name definition, Java identifier definition
    • 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 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.
      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.
      java.lang.String encodeNode​(java.lang.String name)
      Encode an object name for a node in the target format.
      • Methods inherited from class java.lang.Object

        equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • 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 interface NameCoder
        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 interface NameCoder
        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 interface NameCoder
        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 interface NameCoder
        Parameters:
        name - the name of the object data
        Returns:
        the node name in the target format
      • clone

        public java.lang.Object clone()
        Overrides:
        clone in class java.lang.Object
      • createCacheMap

        protected java.util.Map createCacheMap()