Debian Codegraph @

net/sf/saxon/serialize/CharacterMapExpander.java

raw symbols SCIP
1 ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
2 // Copyright (c) 2018 Saxonica Limited.
3 // This Source Code Form is subject to the terms of the Mozilla Public License, v. 2.0.
4 // If a copy of the MPL was not distributed with this file, You can obtain one at http://mozilla.org/MPL/2.0/.
5 // This Source Code Form is "Incompatible With Secondary Licenses", as defined by the Mozilla Public License, v. 2.0.
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 * CharacterMapExpander: This ProxyReceiver expands characters occurring in a character map,
20 * as specified by the XSLT 2.0 xsl:character-map declaration
21 *
22 * @author Michael Kay
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 * Set the character map to be used by this CharacterMapExpander.
37 * They will have been merged into a single character map if there is more than one.
38 * @param map the character map
39 */
40
41 public void setCharacterMap(CharacterMap map) {
42 charMap = map;
43 }
44
45 /**
46 * Get the character map used by this CharacterMapExpander
47 * @return the character map
48 */
49
50 public CharacterMap getCharacterMap() {
51 return charMap;
52 }
53
54 /**
55 * Indicate whether the result of character mapping should be marked using NUL
56 * characters to prevent subsequent XML or HTML character escaping. The default value
57 * is true (used for the XML and HTML output methods); the value false is used by the text
58 * output method.
59 */
60
61 public void setUseNullMarkers(boolean use) {
62 useNullMarkers = use;
63 }
64
65 /**
66 * Output an attribute
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 // no mapping was done
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 * Output character data
88 */
89
90 public void characters(/*@NotNull*/ 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 // if the user requests disable-output-escaping, this overrides the character
100 // mapping
101 nextReceiver.characters(chars, locationId, properties);
102 }
103
104 }
105
106
107 }
108