Debian Codegraph @

net/sf/saxon/style/XSLOutputCharacter.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.style;
9
10 import net.sf.saxon.expr.Expression;
11 import net.sf.saxon.om.AttributeCollection;
12 import net.sf.saxon.serialize.charcode.UTF16CharacterSet;
13 import net.sf.saxon.trans.XPathException;
14
15
16 /**
17 * An xsl:output-character element in the stylesheet. <br>
18 */
19
20 public class XSLOutputCharacter extends StyleElement {
21
22 private int codepoint = -1;
23 // the character to be substituted, as a Unicode codepoint (may be > 65535)
24 private String replacementString = null;
25
26 public void prepareAttributes() throws XPathException {
27
28 AttributeCollection atts = getAttributeList();
29
30 for (int a = 0; a < atts.getLength(); a++) {
31 String f = atts.getQName(a);
32 if (f.equals("character")) {
33 String s = atts.getValue(a);
34 switch (s.length()) {
35 case 0:
36 compileError("character attribute must not be zero-length", "XTSE0020");
37 codepoint = 256; // for error recovery
38 break;
39 case 1:
40 codepoint = s.charAt(0);
41 break;
42 case 2:
43 if (UTF16CharacterSet.isHighSurrogate(s.charAt(0)) &&
44 UTF16CharacterSet.isLowSurrogate(s.charAt(1))) {
45 codepoint = UTF16CharacterSet.combinePair(s.charAt(0), s.charAt(1));
46 } else {
47 compileError("character attribute must be a single XML character", "XTSE0020");
48 codepoint = 256; // for error recovery
49 }
50 break;
51 default:
52 compileError("character attribute must be a single XML character", "XTSE0020");
53 codepoint = 256; // for error recovery
54 }
55 } else if (f.equals("string")) {
56 replacementString = atts.getValue(a);
57 } else {
58 checkUnknownAttribute(atts.getNodeName(a));
59 }
60 }
61 if (codepoint == -1) {
62 reportAbsence("character");
63 return;
64 }
65
66 if (replacementString == null) {
67 reportAbsence("string");
68 }
69
70 }
71
72 public void validate(ComponentDeclaration decl) throws XPathException {
73 if (!(getParent() instanceof XSLCharacterMap)) {
74 compileError("xsl:output-character may appear only as a child of xsl:character-map", "XTSE0010");
75 }
76 }
77
78 public Expression compile(Compilation exec, ComponentDeclaration decl) throws XPathException {
79 return null;
80 }
81
82 public int getCodePoint() {
83 return codepoint;
84 }
85
86 public String getReplacementString() {
87 return replacementString;
88 }
89
90 }
91