| 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.event.ReceiverOptions; |
| 13 |
import net.sf.saxon.expr.parser.Location; |
| 14 |
import net.sf.saxon.om.NodeName; |
| 15 |
import net.sf.saxon.trans.XPathException; |
| 16 |
import net.sf.saxon.type.SimpleType; |
| 17 |
|
| 18 |
|
| 19 |
|
| 20 |
|
| 21 |
|
| 22 |
|
| 23 |
|
| 24 |
|
| 25 |
|
| 26 |
public class CharacterMapExpander extends ProxyReceiver { |
| 27 |
|
| 28 |
private CharacterMap charMap; |
| 29 |
private boolean useNullMarkers = true; |
| 30 |
|
| 31 |
public CharacterMapExpander(Receiver next) { |
| 32 |
super(next); |
| 33 |
} |
| 34 |
|
| 35 |
|
| 36 |
|
| 37 |
|
| 38 |
|
| 39 |
|
| 40 |
|
| 41 |
public void setCharacterMap(CharacterMap map) { |
| 42 |
charMap = map; |
| 43 |
} |
| 44 |
|
| 45 |
|
| 46 |
|
| 47 |
|
| 48 |
|
| 49 |
|
| 50 |
public CharacterMap getCharacterMap() { |
| 51 |
return charMap; |
| 52 |
} |
| 53 |
|
| 54 |
|
| 55 |
|
| 56 |
|
| 57 |
|
| 58 |
|
| 59 |
|
| 60 |
|
| 61 |
public void setUseNullMarkers(boolean use) { |
| 62 |
useNullMarkers = use; |
| 63 |
} |
| 64 |
|
| 65 |
|
| 66 |
|
| 67 |
|
| 68 |
|
| 69 |
public void attribute(NodeName nameCode, SimpleType typeCode, CharSequence value, Location locationId, int properties) |
| 70 |
throws XPathException { |
| 71 |
if ((properties & ReceiverOptions.DISABLE_CHARACTER_MAPS) == 0) { |
| 72 |
CharSequence mapped = charMap.map(value, useNullMarkers); |
| 73 |
if (mapped == value) { |
| 74 |
|
| 75 |
nextReceiver.attribute(nameCode, typeCode, value, locationId, properties); |
| 76 |
} else { |
| 77 |
nextReceiver.attribute(nameCode, typeCode, mapped, |
| 78 |
locationId, |
| 79 |
(properties | ReceiverOptions.USE_NULL_MARKERS) & ~ReceiverOptions.NO_SPECIAL_CHARS); |
| 80 |
} |
| 81 |
} else { |
| 82 |
nextReceiver.attribute(nameCode, typeCode, value, locationId, properties); |
| 83 |
} |
| 84 |
} |
| 85 |
|
| 86 |
|
| 87 |
|
| 88 |
|
| 89 |
|
| 90 |
public void characters( CharSequence chars, Location locationId, int properties) throws XPathException { |
| 91 |
|
| 92 |
if ((properties & ReceiverOptions.DISABLE_ESCAPING) == 0) { |
| 93 |
CharSequence mapped = charMap.map(chars, useNullMarkers); |
| 94 |
if (mapped != chars) { |
| 95 |
properties = (properties | ReceiverOptions.USE_NULL_MARKERS) & ~ReceiverOptions.NO_SPECIAL_CHARS; |
| 96 |
} |
| 97 |
nextReceiver.characters(mapped, locationId, properties); |
| 98 |
} else { |
| 99 |
|
| 100 |
|
| 101 |
nextReceiver.characters(chars, locationId, properties); |
| 102 |
} |
| 103 |
|
| 104 |
} |
| 105 |
|
| 106 |
|
| 107 |
} |
| 108 |
|