Debian Codegraph @

net/sf/saxon/style/XSLMessage.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.StringLiteral;
12 import net.sf.saxon.expr.instruct.Block;
13 import net.sf.saxon.expr.instruct.Message;
14 import net.sf.saxon.lib.NamespaceConstant;
15 import net.sf.saxon.om.AttributeCollection;
16 import net.sf.saxon.om.StructuredQName;
17 import net.sf.saxon.trans.XPathException;
18 import net.sf.saxon.value.Whitespace;
19
20
21 /**
22 * An xsl:message element in the stylesheet. <br>
23 */
24
25 public final class XSLMessage extends StyleElement {
26
27 private Expression terminate = null;
28 private Expression select = null;
29 private Expression errorCode = null;
30 private Expression timer = null;
31
32 /**
33 * Determine whether this node is an instruction.
34 *
35 * @return true - it is an instruction
36 */
37
38 public boolean isInstruction() {
39 return true;
40 }
41
42 /**
43 * Determine whether this type of element is allowed to contain a template-body
44 *
45 * @return true: yes, it may contain a template-body
46 */
47
48 public boolean mayContainSequenceConstructor() {
49 return true;
50 }
51
52 public void prepareAttributes() throws XPathException {
53
54 String terminateAtt = null;
55 String selectAtt = null;
56 String errorCodeAtt = null;
57 AttributeCollection atts = getAttributeList();
58
59 for (int a = 0; a < atts.getLength(); a++) {
60 String f = atts.getQName(a);
61 switch (f) {
62 case "terminate":
63 terminateAtt = Whitespace.trim(atts.getValue(a));
64 terminate = makeAttributeValueTemplate(terminateAtt, a);
65 break;
66 case "select":
67 selectAtt = atts.getValue(a);
68 select = makeExpression(selectAtt, a);
69 break;
70 case "error-code":
71 errorCodeAtt = atts.getValue(a);
72 errorCode = makeAttributeValueTemplate(errorCodeAtt, a);
73 break;
74 default:
75 if (atts.getURI(a).equals(NamespaceConstant.SAXON) && atts.getLocalName(a).equals("time")) {
76 boolean timed = processBooleanAttribute("saxon:time", atts.getValue(a));
77 if (timed) {
78 timer = makeExpression(
79 "format-dateTime(Q{http://saxon.sf.net/}timestamp(),'[Y0001]-[M01]-[D01]T[H01]:[m01]:[s01].[f,3-3] - ')", a);
80 }
81 } else {
82 checkUnknownAttribute(atts.getNodeName(a));
83 }
84 break;
85 }
86 }
87
88 if (terminateAtt == null) {
89 terminateAtt = "no";
90 terminate = makeAttributeValueTemplate(terminateAtt, -1);
91 }
92
93 checkAttributeValue("terminate", terminateAtt, true, StyleElement.YES_NO);
94
95 }
96
97 public void validate(ComponentDeclaration decl) throws XPathException {
98 select = typeCheck("select", select);
99 terminate = typeCheck("terminate", terminate);
100 if (errorCode == null) {
101 errorCode = new StringLiteral("Q{http://www.w3.org/2005/xqt-errors}XTMM9000");
102 } else {
103 errorCode = typeCheck("error-code", errorCode);
104 }
105 }
106
107 public Expression compile(Compilation exec, ComponentDeclaration decl) throws XPathException {
108 Expression b = compileSequenceConstructor(exec, decl, true);
109 if (b != null) {
110 if (select == null) {
111 select = b;
112 } else {
113 select = Block.makeBlock(select, b);
114 select.setLocation(
115 allocateLocation());
116 }
117 }
118 if (timer != null) {
119 select = Block.makeBlock(timer, select);
120 }
121 if (select == null) {
122 select = new StringLiteral("xsl:message (no content)");
123 }
124
125 if (errorCode instanceof StringLiteral) {
126 // resolve any QName prefix now
127 String code = ((StringLiteral) errorCode).getStringValue();
128 if (code.contains(":") && !code.startsWith("Q{")) {
129 StructuredQName name = makeQName(code);
130 errorCode = new StringLiteral(name.getEQName());
131 }
132 }
133 Message m = new Message(select, terminate, errorCode);
134 m.setRetainedStaticContext(makeRetainedStaticContext());
135 return m;
136 }
137
138 }