| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
package net.sf.saxon.serialize; |
| 9 |
|
| 10 |
import net.sf.saxon.event.ProxyReceiver; |
| 11 |
import net.sf.saxon.event.Receiver; |
| 12 |
import net.sf.saxon.expr.parser.Location; |
| 13 |
import net.sf.saxon.om.NodeName; |
| 14 |
import net.sf.saxon.serialize.charcode.UTF16CharacterSet; |
| 15 |
import net.sf.saxon.serialize.charcode.XMLCharacterData; |
| 16 |
import net.sf.saxon.trans.XPathException; |
| 17 |
import net.sf.saxon.type.SchemaType; |
| 18 |
import net.sf.saxon.type.SimpleType; |
| 19 |
|
| 20 |
|
| 21 |
|
| 22 |
|
| 23 |
|
| 24 |
|
| 25 |
|
| 26 |
|
| 27 |
|
| 28 |
|
| 29 |
public class XML10ContentChecker extends ProxyReceiver { |
| 30 |
|
| 31 |
|
| 32 |
public XML10ContentChecker(Receiver next) { |
| 33 |
super(next); |
| 34 |
} |
| 35 |
|
| 36 |
|
| 37 |
|
| 38 |
|
| 39 |
|
| 40 |
|
| 41 |
|
| 42 |
|
| 43 |
|
| 44 |
public void startElement(NodeName elemName, SchemaType typeCode, Location location, int properties) throws XPathException { |
| 45 |
nextReceiver.startElement(elemName, typeCode, location, properties); |
| 46 |
} |
| 47 |
|
| 48 |
|
| 49 |
|
| 50 |
|
| 51 |
|
| 52 |
|
| 53 |
|
| 54 |
|
| 55 |
|
| 56 |
|
| 57 |
|
| 58 |
|
| 59 |
|
| 60 |
|
| 61 |
|
| 62 |
|
| 63 |
|
| 64 |
|
| 65 |
public void attribute(NodeName attName, SimpleType typeCode, CharSequence value, Location locationId, int properties) throws XPathException { |
| 66 |
checkString(value, locationId); |
| 67 |
nextReceiver.attribute(attName, typeCode, value, locationId, properties); |
| 68 |
} |
| 69 |
|
| 70 |
|
| 71 |
|
| 72 |
|
| 73 |
|
| 74 |
public void characters(CharSequence chars, Location locationId, int properties) throws XPathException { |
| 75 |
checkString(chars, locationId); |
| 76 |
nextReceiver.characters(chars, locationId, properties); |
| 77 |
} |
| 78 |
|
| 79 |
|
| 80 |
|
| 81 |
|
| 82 |
|
| 83 |
public void comment(CharSequence chars, Location locationId, int properties) throws XPathException { |
| 84 |
checkString(chars, locationId); |
| 85 |
nextReceiver.comment(chars, locationId, properties); |
| 86 |
} |
| 87 |
|
| 88 |
|
| 89 |
|
| 90 |
|
| 91 |
|
| 92 |
public void processingInstruction(String target, CharSequence data, Location locationId, int properties) throws XPathException { |
| 93 |
checkString(data, locationId); |
| 94 |
nextReceiver.processingInstruction(target, data, locationId, properties); |
| 95 |
} |
| 96 |
|
| 97 |
|
| 98 |
|
| 99 |
|
| 100 |
|
| 101 |
|
| 102 |
|
| 103 |
|
| 104 |
private void checkString(CharSequence in, Location locationId) throws XPathException { |
| 105 |
final int len = in.length(); |
| 106 |
for (int c = 0; c < len; c++) { |
| 107 |
int ch32 = in.charAt(c); |
| 108 |
if (UTF16CharacterSet.isHighSurrogate(ch32)) { |
| 109 |
char low = in.charAt(++c); |
| 110 |
ch32 = UTF16CharacterSet.combinePair((char) ch32, low); |
| 111 |
} |
| 112 |
if (!XMLCharacterData.isValid10(ch32)) { |
| 113 |
XPathException err = new XPathException("The result tree contains a character not allowed by XML 1.0 (hex " + |
| 114 |
Integer.toHexString(ch32) + ')'); |
| 115 |
err.setErrorCode("SERE0006"); |
| 116 |
err.setLocator(locationId); |
| 117 |
throw err; |
| 118 |
} |
| 119 |
} |
| 120 |
} |
| 121 |
|
| 122 |
} |
| 123 |
|