001: /*
002: * Copyright (c) 1998-2008 Caucho Technology -- all rights reserved
003: *
004: * This file is part of Resin(R) Open Source
005: *
006: * Each copy or derived work must preserve the copyright notice and this
007: * notice unmodified.
008: *
009: * Resin Open Source is free software; you can redistribute it and/or modify
010: * it under the terms of the GNU General Public License as published by
011: * the Free Software Foundation; either version 2 of the License, or
012: * (at your option) any later version.
013: *
014: * Resin Open Source is distributed in the hope that it will be useful,
015: * but WITHOUT ANY WARRANTY; without even the implied warranty of
016: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE, or any warranty
017: * of NON-INFRINGEMENT. See the GNU General Public License for more
018: * details.
019: *
020: * You should have received a copy of the GNU General Public License
021: * along with Resin Open Source; if not, write to the
022: * Free SoftwareFoundation, Inc.
023: * 59 Temple Place, Suite 330
024: * Boston, MA 02111-1307 USA
025: *
026: * @author Scott Ferguson
027: */
028:
029: package com.caucho.xml;
030:
031: import java.io.IOException;
032:
033: class XmlLatin1Entities extends XmlEntities {
034: private static Entities xmlEntities = new XmlLatin1Entities();
035:
036: static Entities create() {
037: return xmlEntities;
038: }
039:
040: void printText(XmlPrinter os, char[] text, int offset, int length,
041: boolean attr) throws IOException {
042: for (int i = 0; i < length; i++) {
043: char ch = text[offset + i];
044:
045: switch (ch) {
046: case '\t':
047: os.print(ch);
048: break;
049:
050: case '\n':
051: case '\r':
052: if (!attr)
053: os.print(ch);
054: else {
055: os.print("&#");
056: os.print((int) ch);
057: os.print(";");
058: }
059: break;
060:
061: /*
062: case '<':
063: if (! attr)
064: os.print("<");
065: else
066: os.print("<");
067: break;
068: */
069:
070: case '<':
071: os.print("<");
072: break;
073:
074: case '>':
075: os.print(">");
076: break;
077:
078: case '&':
079: os.print("&");
080: break;
081:
082: case '"':
083: if (attr)
084: os.print(""");
085: else
086: os.print('"');
087: break;
088:
089: default:
090: if (ch >= 0x20 && ch < 0x7f || ch > 160 && ch < 255) {
091: os.print(ch);
092: } else {
093: os.print("&#");
094: os.print((int) ch);
095: os.print(';');
096: }
097: }
098: }
099: }
100: }
|