Debian Codegraph @

net/sf/saxon/style/XSLText.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.expr.Literal;
12 import net.sf.saxon.expr.StringLiteral;
13 import net.sf.saxon.expr.instruct.Block;
14 import net.sf.saxon.expr.instruct.ValueOf;
15 import net.sf.saxon.om.AttributeCollection;
16 import net.sf.saxon.om.AxisInfo;
17 import net.sf.saxon.om.Item;
18 import net.sf.saxon.trans.XPathException;
19 import net.sf.saxon.tree.iter.AxisIterator;
20 import net.sf.saxon.tree.linked.TextImpl;
21 import net.sf.saxon.value.StringValue;
22 import net.sf.saxon.value.Whitespace;
23
24 import java.util.ArrayList;
25 import java.util.List;
26
27 /**
28 * Handler for xsl:text elements in stylesheet. <BR>
29 */
30
31 public class XSLText extends XSLLeafNodeConstructor {
32
33 private boolean disable = false;
34 private StringValue value;
35
36
37 public void prepareAttributes() throws XPathException {
38
39 String disableAtt = null;
40
41 AttributeCollection atts = getAttributeList();
42
43 for (int a = 0; a < atts.getLength(); a++) {
44 String f = atts.getQName(a);
45 if (f.equals("disable-output-escaping")) {
46 disableAtt = Whitespace.trim(atts.getValue(a));
47 } else {
48 checkUnknownAttribute(atts.getNodeName(a));
49 }
50 }
51
52 if (disableAtt != null) {
53 disable = processBooleanAttribute("disable-output-escaping", disableAtt);
54 }
55 }
56
57 public void validate(ComponentDeclaration decl) throws XPathException {
58
59 AxisIterator kids = iterateAxis(AxisInfo.CHILD);
60 value = StringValue.EMPTY_STRING;
61 Item child;
62 while ((child = kids.next()) != null) {
63 if (child instanceof StyleElement) {
64 ((StyleElement) child).compileError("xsl:text must not contain child elements", "XTSE0010");
65 return;
66 } else {
67 value = StringValue.makeStringValue(child.getStringValueCS());
68 //continue;
69 }
70 }
71 super.validate(decl);
72 }
73
74 /**
75 * Get the error code to be returned when the element has a select attribute but is not empty.
76 *
77 * @return the error code defined for this condition, for this particular instruction
78 */
79
80 /*@Nullable*/
81 protected String getErrorCodeForSelectPlusContent() {
82 return null; // not applicable
83 }
84
85 public Expression compile(Compilation exec, ComponentDeclaration decl) throws XPathException {
86 if (isExpandingText()) {
87 TextImpl child = (TextImpl)iterateAxis(AxisInfo.CHILD).next();
88 if (child != null) {
89 List<Expression> contents = new ArrayList<Expression>(10);
90 compileContentValueTemplate(child, contents);
91 Expression block = Block.makeBlock(contents);
92 block.setLocation(allocateLocation());
93 return block;
94 } else {
95 return new ValueOf(new StringLiteral(StringValue.EMPTY_STRING), disable, false);
96 }
97 } else {
98 return new ValueOf(Literal.makeLiteral(value), disable, false);
99 }
100 }
101
102 }
103