FileDocCategorySizeDatePackage
UTF8Encoder.javaAPI DocApache Axis 1.43207Sat Apr 22 18:57:26 BST 2006org.apache.axis.components.encoding

UTF8Encoder

public class UTF8Encoder extends AbstractXMLEncoder
UTF-8 Encoder.
author
Jens Schumann
see
encoding.org
see
UTF 8 explained

Fields Summary
Constructors Summary
Methods Summary
public java.lang.StringgetEncoding()
gets the encoding supported by this encoder

return
string

        return XMLEncoderFactory.ENCODING_UTF_8;
    
public voidwriteEncoded(java.io.Writer writer, java.lang.String xmlString)
write the encoded version of a given string

param
writer writer to write this string to
param
xmlString string to be encoded

        if (xmlString == null) {
            return;
        }
        int length = xmlString.length();
        char character;
        for (int i = 0; i < length; i++) {
            character = xmlString.charAt( i );
            switch (character) {
                // we don't care about single quotes since axis will
                // use double quotes anyway
                case '&":
                    writer.write(AMP);
                    break;
                case '"":
                    writer.write(QUOTE);
                    break;
                case '<":
                    writer.write(LESS);
                    break;
                case '>":
                    writer.write(GREATER);
                    break;
                case '\n":
                    writer.write(LF);
                    break;
                case '\r":
                    writer.write(CR);
                    break;
                case '\t":
                    writer.write(TAB);
                    break;
                default:
                    if (character < 0x20) {
                        throw new IllegalArgumentException(Messages.getMessage(
                                "invalidXmlCharacter00",
                                Integer.toHexString(character),
                                xmlString.substring(0, i)));
                    } else if (character > 0x7F) {
                        writer.write("&#x");
                        writer.write(Integer.toHexString(character).toUpperCase());
                        writer.write(";");
                    } else {
                        writer.write(character);
                    }
                    break;
            }
        }