001: /*
002: * $Header: /cvsroot/webman-cms/source/webman/com/teamkonzept/lib/TKXmlConverter.java,v 1.5 2000/05/22 15:01:22 careck Exp $
003: *
004: */
005: package com.teamkonzept.lib;
006:
007: /**
008: Konvertierungsklasse fuer XML-Text-Codierung
009: */
010: public class TKXmlConverter extends TKConverter {
011: public final static String CONV_ID = "XML";
012: public final static String CONV_NAME = "XML-ISO-8859_1";
013:
014: public String getName() {
015: return CONV_NAME;
016: }
017:
018: public final static String[] XML_CODES = {
019: /* 0*/null, null, null, null, null, null, null, null, null, null,
020: /* 10*/null, null, null, null, null, null, null, null, null, null,
021: /* 20*/null, null, null, null, null, null, null, null, null, null,
022: /* 30*/null, null, null, null, null, null, null, null, null, null,
023: /* 40*/null, null, null, null, null, null, null, null, null, null,
024: /* 50*/null, null, null, null, null, null, null, null, null, null,
025: /* 60*/"\\<", null, "\\>", null, null, null, null, null, null,
026: null,
027: /* 70*/null, null, null, null, null, null, null, null,
028: null, null,
029: /* 80*/null, null, null, null, null, null, null, null,
030: null, null,
031: /* 90*/null, null, "\\\\", null, null, null, null, null,
032: null, null,
033: /*100*/null, null, null, null, null, null, null, null,
034: null, null,
035: /*110*/null, null, null, null, null, null, null, null,
036: null, null,
037: /*120*/null, null, null, null, null, null, null, null,
038: null, null,
039: /*130*/null, null, null, null, null, null, null, null,
040: null, null,
041: /*140*/null, null, null, null, null, null, null, null,
042: null, null,
043: /*150*/null, null, null, null, null, null, null, null,
044: null, null,
045: /*160*/null, null, null, null, null, null, null, null,
046: null, null,
047: /*170*/null, null, null, null, null, null, null, null,
048: null, null,
049: /*180*/null, null, null, null, null, null, null, null,
050: null, null,
051: /*190*/null, null, null, null, null, null, null, null,
052: null, null,
053: /*200*/null, null, null, null, null, null, null, null,
054: null, null,
055: /*210*/null, null, null, null, null, null, null, null,
056: null, null,
057: /*220*/null, null, null, null, null, null, null, null,
058: null, null,
059: /*230*/null, null, null, null, null, null, null, null,
060: null, null,
061: /*240*/null, null, null, null, null, null, null, null,
062: null, null,
063: /*250*/null, null, null, null, null, null, null, null,
064: null, null };
065:
066: public final static byte BACKSLASH = (byte) '\\';
067:
068: public int getMaxBytesPerChar() {
069: return 8;
070: }
071:
072: public int minCharSize(int byteCount) {
073: return byteCount;
074: }
075:
076: public int charsToBytes(char src[], byte dst[], int srcBegin,
077: int length, int dstBegin) {
078: int lastPos = srcBegin + length;
079: int firstPos = dstBegin;
080: for (int i = srcBegin; i < lastPos; i++) {
081: char c = src[i];
082: byte b = (byte) c;
083: int code = (int) c;
084: String subst = XML_CODES[code];
085: if (subst == null) {
086: dst[dstBegin++] = b;
087: } else {
088: int len = subst.length();
089: subst.getBytes(0, len, dst, dstBegin);
090: dstBegin += len;
091: }
092: }
093:
094: return dstBegin - firstPos;
095: }
096:
097: public int bytesToChars(byte src[], char dst[], int srcBegin,
098: int length, int dstBegin) {
099: int lastPos = srcBegin + length;
100: int firstPos = dstBegin;
101: int i = srcBegin;
102:
103: while (i < lastPos) {
104: byte b = src[i++];
105:
106: if (b == BACKSLASH) {
107: if (i >= lastPos)
108: break;
109: b = src[i++];
110: }
111:
112: dst[dstBegin++] = (char) b;
113: }
114: return dstBegin - firstPos;
115: }
116:
117: }
|