1 16 package org.apache.axis.components.encoding; 17 18 import org.apache.axis.i18n.Messages; 19 20 import java.io.IOException ; 21 import java.io.Writer ; 22 23 30 class UTF8Encoder extends AbstractXMLEncoder { 31 36 public String getEncoding() { 37 return XMLEncoderFactory.ENCODING_UTF_8; 38 } 39 40 46 public void writeEncoded(Writer writer, String xmlString) 47 throws IOException { 48 if (xmlString == null) { 49 return; 50 } 51 int length = xmlString.length(); 52 char character; 53 for (int i = 0; i < length; i++) { 54 character = xmlString.charAt( i ); 55 switch (character) { 56 case '&': 59 writer.write(AMP); 60 break; 61 case '"': 62 writer.write(QUOTE); 63 break; 64 case '<': 65 writer.write(LESS); 66 break; 67 case '>': 68 writer.write(GREATER); 69 break; 70 case '\n': 71 writer.write(LF); 72 break; 73 case '\r': 74 writer.write(CR); 75 break; 76 case '\t': 77 writer.write(TAB); 78 break; 79 default: 80 if (character < 0x20) { 81 throw new IllegalArgumentException (Messages.getMessage( 82 "invalidXmlCharacter00", 83 Integer.toHexString(character), 84 xmlString)); 85 } else if (character > 0x7F) { 86 writer.write("&#x"); 87 writer.write(Integer.toHexString(character).toUpperCase()); 88 writer.write(";"); 89 } else { 90 writer.write(character); 91 } 92 break; 93 } 94 } 95 } 96 } 97 | Popular Tags |