1 28 29 package com.caucho.xml; 30 31 import java.io.IOException ; 32 33 38 class OtherEntities extends HtmlEntities { 39 private static Entities _html40; 40 private static Entities _html32; 41 42 static Entities create(double version) 43 { 44 if (version == 0 || version >= 4.0) { 45 if (_html40 == null) 46 _html40 = new OtherEntities(4.0); 47 48 return _html40; 49 } 50 else { 51 if (_html32 == null) 52 _html32 = new OtherEntities(3.2); 53 54 return _html32; 55 } 56 } 57 58 protected OtherEntities(double version) 59 { 60 super(version); 61 } 62 63 void printText(XmlPrinter os, 64 char []text, int offset, int length, 65 boolean attr) 66 throws IOException 67 { 68 for (int i = 0; i < length; i++) { 69 char ch = text[i + offset]; 70 71 if (ch == '&') { 73 if (i + 1 < length && text[i + 1] == '{') 74 os.print('&'); 75 else if (attr) 76 os.print(_attrLatin1[ch]); 77 else 78 os.print(_latin1[ch]); 79 } 80 else if (ch == '"') { 81 if (attr) 82 os.print("""); 83 else 84 os.print('"'); 85 } 86 else if (ch == '<') { 87 if (attr) 88 os.print('<'); 89 else 90 os.print("<"); 91 } 92 else if (ch == '>') { 93 if (attr) 94 os.print('>'); 95 else 96 os.print(">"); 97 } 98 else if (ch < 161) 99 os.print(_latin1[ch]); 100 else { 101 try { 102 os.print(ch); 103 } catch (IOException e) { 104 char []value = getSparseEntity(ch); 105 if (value != null) { 106 os.print(value); 107 } else { 108 os.print("&#"); 109 os.print((int) ch); 110 os.print(";"); 111 } 112 } 113 } 114 } 115 } 116 } 117 | Popular Tags |