KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > caucho > xml > XmlLatin1Entities


1 /*
2  * Copyright (c) 1998-2006 Caucho Technology -- all rights reserved
3  *
4  * This file is part of Resin(R) Open Source
5  *
6  * Each copy or derived work must preserve the copyright notice and this
7  * notice unmodified.
8  *
9  * Resin Open Source is free software; you can redistribute it and/or modify
10  * it under the terms of the GNU General Public License as published by
11  * the Free Software Foundation; either version 2 of the License, or
12  * (at your option) any later version.
13  *
14  * Resin Open Source is distributed in the hope that it will be useful,
15  * but WITHOUT ANY WARRANTY; without even the implied warranty of
16  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE, or any warranty
17  * of NON-INFRINGEMENT. See the GNU General Public License for more
18  * details.
19  *
20  * You should have received a copy of the GNU General Public License
21  * along with Resin Open Source; if not, write to the
22  * Free SoftwareFoundation, Inc.
23  * 59 Temple Place, Suite 330
24  * Boston, MA 02111-1307 USA
25  *
26  * @author Scott Ferguson
27  */

28
29 package com.caucho.xml;
30
31 import java.io.IOException JavaDoc;
32
33 class XmlLatin1Entities extends XmlEntities {
34   private static Entities xmlEntities = new XmlLatin1Entities();
35
36   static Entities create()
37   {
38     return xmlEntities;
39   }
40
41   void printText(XmlPrinter os,
42                  char []text, int offset, int length,
43                  boolean attr)
44     throws IOException JavaDoc
45   {
46     for (int i = 0; i < length; i++) {
47       char ch = text[offset + i];
48
49       switch (ch) {
50       case '\t':
51     os.print(ch); break;
52         
53       case '\n':
54       case '\r':
55         if (! attr)
56           os.print(ch);
57         else {
58           os.print("&#");
59           os.print((int) ch);
60           os.print(";");
61         }
62         break;
63
64         /*
65       case '<':
66         if (! attr)
67           os.print("&lt;");
68         else
69           os.print("<");
70         break;
71         */

72         
73       case '<':
74         os.print("&lt;");
75         break;
76         
77       case '>':
78         os.print("&gt;");
79         break;
80         
81       case '&':
82         os.print("&amp;");
83         break;
84         
85       case '"':
86     if (attr)
87       os.print("&quot;");
88     else
89       os.print('"');
90     break;
91
92       default:
93     if (ch >= 0x20 && ch < 0x7f || ch > 160 && ch < 255) {
94       os.print(ch);
95     }
96     else {
97       os.print("&#");
98       os.print((int) ch);
99       os.print(';');
100     }
101       }
102     }
103   }
104 }
105
Popular Tags