01: /*
02: * ====================================================================
03: * Copyright (c) 2004-2008 TMate Software Ltd. All rights reserved.
04: *
05: * This software is licensed as described in the file COPYING, which
06: * you should have received as part of this distribution. The terms
07: * are also available at http://svnkit.com/license.html
08: * If newer versions of this license are posted there, you may use a
09: * newer version instead, at your option.
10: * ====================================================================
11: */
12: package org.tmatesoft.svn.core.internal.io.dav.http;
13:
14: import java.io.IOException;
15: import java.io.InputStream;
16: import java.io.InputStreamReader;
17: import java.io.Reader;
18: import java.io.UnsupportedEncodingException;
19:
20: /**
21: * @version 1.1.1
22: * @author TMate Software Ltd.
23: */
24: public class XMLReader extends Reader {
25:
26: public static final char COLON_REPLACEMENT = '\u3007'; // ideografic char.
27:
28: private Reader mySource;
29: private boolean myIsEscaping;
30: private int myColonCount;
31: private boolean myIsClosed;
32:
33: public XMLReader(InputStream is)
34: throws UnsupportedEncodingException {
35: mySource = new InputStreamReader(is, "UTF-8");
36: }
37:
38: public int read(char[] b, int off, int len) throws IOException {
39: int read = mySource.read(b, off, len);
40: for (int i = 0; i < read; i++) {
41: char ch = b[off + i];
42: if (ch < 0x20 && ch != '\r' && ch != '\n' && ch != '\t') {
43: b[off + i] = ' ';
44: continue;
45: }
46: if (myIsEscaping) {
47: if (ch == ':') {
48: myColonCount++;
49: if (myColonCount > 1) {
50: b[off + i] = COLON_REPLACEMENT;
51: }
52: } else if (Character.isWhitespace(ch) || ch == '>') {
53: myIsEscaping = false;
54: }
55: } else if (!myIsEscaping && ch == '<') {
56: myIsEscaping = true;
57: myColonCount = 0;
58: }
59: }
60: myIsClosed = read <= 0;
61: return read;
62: }
63:
64: public boolean isClosed() {
65: return myIsClosed;
66: }
67:
68: public void close() throws IOException {
69: }
70:
71: }
|