| 1 |
|
package com.atlassian.core.util.xml; |
| 2 |
|
|
| 3 |
|
|
| 4 |
|
import org.apache.log4j.Logger; |
| 5 |
|
|
| 6 |
|
import java.io.FilterReader; |
| 7 |
|
import java.io.IOException; |
| 8 |
|
import java.io.Reader; |
| 9 |
|
|
| 10 |
|
|
| 11 |
|
|
| 12 |
|
|
|
|
|
| 0% |
Uncovered Elements: 28 (28) |
Complexity: 17 |
Complexity Density: 1.13 |
|
| 13 |
|
public class XMLCleaningReader extends FilterReader |
| 14 |
|
{ |
| 15 |
|
private static final Logger log = Logger.getLogger(XMLCleaningReader.class); |
| 16 |
|
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
| 17 |
0
|
public XMLCleaningReader(Reader reader)... |
| 18 |
|
{ |
| 19 |
0
|
super(reader); |
| 20 |
|
} |
| 21 |
|
|
|
|
|
| 0% |
Uncovered Elements: 18 (18) |
Complexity: 10 |
Complexity Density: 1 |
|
| 22 |
0
|
public int read(char cbuf[], int off, int len) throws IOException... |
| 23 |
|
{ |
| 24 |
0
|
final int charsRead = super.read(cbuf, off, len); |
| 25 |
|
|
| 26 |
0
|
if (charsRead > -1) |
| 27 |
|
{ |
| 28 |
0
|
int limit = charsRead + off; |
| 29 |
0
|
for (int j = off; j < limit; j++) |
| 30 |
|
{ |
| 31 |
0
|
char c = cbuf[j]; |
| 32 |
0
|
if (c > -1 && c != 9 && c != 10 && c != 13) |
| 33 |
|
{ |
| 34 |
0
|
if (c < 32 || (c > 55295 && c < 57344)) |
| 35 |
|
{ |
| 36 |
0
|
log.warn("Replaced invalid XML character " + c + " (" + (int) c + ")."); |
| 37 |
0
|
cbuf[j] = '\uFFFD'; |
| 38 |
|
} |
| 39 |
|
} |
| 40 |
|
} |
| 41 |
|
} |
| 42 |
|
|
| 43 |
0
|
return charsRead; |
| 44 |
|
} |
| 45 |
|
|
|
|
|
| 0% |
Uncovered Elements: 6 (6) |
Complexity: 6 |
Complexity Density: 1.5 |
|
| 46 |
0
|
public int read() throws IOException... |
| 47 |
|
{ |
| 48 |
0
|
final int i = super.read(); |
| 49 |
0
|
if (i < 32 && i > -1 && i != 9 && i != 10 && i != 13) |
| 50 |
|
{ |
| 51 |
0
|
return '\uFFFD'; |
| 52 |
|
} |
| 53 |
0
|
return i; |
| 54 |
|
} |
| 55 |
|
} |