FileDocCategorySizeDatePackage
AbstractXMLEncoder.javaAPI DocApache Axis 1.44481Sat Apr 22 18:57:28 BST 2006org.apache.axis.components.encoding

AbstractXMLEncoder

public abstract class AbstractXMLEncoder extends Object implements XMLEncoder
Abstract class for XML String encoders. The new encoding mechanism fixes the following bugs/issues: http://nagoya.apache.org/bugzilla/show_bug.cgi?id=15133 http://nagoya.apache.org/bugzilla/show_bug.cgi?id=15494 http://nagoya.apache.org/bugzilla/show_bug.cgi?id=19327
author
Jens Schumann
author
Davanum Srinivas

Fields Summary
protected static final String
AMP
protected static final String
QUOTE
protected static final String
LESS
protected static final String
GREATER
protected static final String
LF
protected static final String
CR
protected static final String
TAB
Constructors Summary
Methods Summary
public java.lang.Stringencode(java.lang.String xmlString)
Encode a string

param
xmlString string to be encoded
return
encoded string


                  
       

                     
        
        if(xmlString == null) {
            return "";
        }
        char[] characters = xmlString.toCharArray();
        StringBuffer out = null;
        char character;

        for (int i = 0; i < characters.length; i++) {
            character = characters[i];
            switch (character) {
                // we don't care about single quotes since axis will
                // use double quotes anyway
                case '&":
                    if (out == null) {
                        out = getInitialByteArray(xmlString, i);
                    }
                    out.append(AMP);
                    break;
                case '"":
                    if (out == null) {
                        out = getInitialByteArray(xmlString, i);
                    }
                    out.append(QUOTE);
                    break;
                case '<":
                    if (out == null) {
                        out = getInitialByteArray(xmlString, i);
                    }
                    out.append(LESS);
                    break;
                case '>":
                    if (out == null) {
                        out = getInitialByteArray(xmlString, i);
                    }
                    out.append(GREATER);
                    break;
                case '\n":
                    if (out == null) {
                        out = getInitialByteArray(xmlString, i);
                    }
                    out.append(LF);
                    break;
                case '\r":
                    if (out == null) {
                        out = getInitialByteArray(xmlString, i);
                    }
                    out.append(CR);
                    break;
                case '\t":
                    if (out == null) {
                        out = getInitialByteArray(xmlString, i);
                    }
                    out.append(TAB);
                    break;
                default:
                    if (character < 0x20) {
                        throw new IllegalArgumentException(Messages.getMessage("invalidXmlCharacter00", Integer.toHexString(character), xmlString.substring(0, i)));
                    } else {
                        if (out != null) {
                            out.append(character);
                        }
                    }
                    break;
            }
        }
        if (out == null) {
            return xmlString;
        }
        return out.toString();
    
public abstract java.lang.StringgetEncoding()
gets the encoding supported by this encoder

return
string

protected java.lang.StringBuffergetInitialByteArray(java.lang.String aXmlString, int pos)

        return new StringBuffer(aXmlString.substring(0, pos));