KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > net > sf > saxon > style > XSLMessage


1 package net.sf.saxon.style;
2 import net.sf.saxon.expr.Expression;
3 import net.sf.saxon.expr.ExpressionTool;
4 import net.sf.saxon.instruct.Block;
5 import net.sf.saxon.instruct.Executable;
6 import net.sf.saxon.instruct.Message;
7 import net.sf.saxon.om.AttributeCollection;
8 import net.sf.saxon.om.Axis;
9 import net.sf.saxon.value.StringValue;
10 import net.sf.saxon.trans.XPathException;
11
12 import javax.xml.transform.TransformerConfigurationException JavaDoc;
13
14
15 /**
16 * An xsl:message element in the stylesheet. <br>
17 */

18
19 public final class XSLMessage extends StyleElement {
20
21     private Expression terminate = null;
22     private Expression select = null;
23
24     /**
25     * Determine whether this node is an instruction.
26     * @return true - it is an instruction
27     */

28
29     public boolean isInstruction() {
30         return true;
31     }
32
33     /**
34     * Determine whether this type of element is allowed to contain a template-body
35     * @return true: yes, it may contain a template-body
36     */

37
38     public boolean mayContainSequenceConstructor() {
39         return true;
40     }
41
42     public void prepareAttributes() throws XPathException {
43
44         String JavaDoc terminateAtt = null;
45         String JavaDoc selectAtt = null;
46         AttributeCollection atts = getAttributeList();
47
48         for (int a=0; a<atts.getLength(); a++) {
49             int nc = atts.getNameCode(a);
50             String JavaDoc f = getNamePool().getClarkName(nc);
51             if (f == StandardNames.TERMINATE) {
52                 terminateAtt = atts.getValue(a).trim();
53             } else if (f == StandardNames.SELECT) {
54                 selectAtt = atts.getValue(a);
55
56             } else {
57                 checkUnknownAttribute(nc);
58             }
59         }
60         if (selectAtt!=null) {
61             select = makeExpression(selectAtt);
62         }
63
64
65         if (terminateAtt==null) {
66             terminateAtt = "no";
67         }
68
69         terminate = makeAttributeValueTemplate(terminateAtt);
70         if (terminate instanceof StringValue) {
71             String JavaDoc t = ((StringValue)terminate).getStringValue();
72             if (!(t.equals("yes") || t.equals("no"))) {
73                 compileError("terminate must be 'yes' or 'no'", "XTSE0020");
74             }
75         }
76     }
77
78     public void validate() throws XPathException {
79         if (!(getParent() instanceof XSLFunction)) {
80             checkWithinTemplate();
81         }
82         select = typeCheck("select", select);
83         terminate = typeCheck("terminate", terminate);
84     }
85
86     public Expression compile(Executable exec) throws XPathException {
87         Expression b = compileSequenceConstructor(exec, iterateAxis(Axis.CHILD), true);
88         if (b != null) {
89             if (select == null) {
90                 select = b;
91             } else {
92                 //select = new AppendExpression(select, Token.COMMA, b);
93
select = Block.makeBlock(select, b);
94             }
95         }
96         if (select == null) {
97             select = new StringValue("xsl:message (no content)");
98         }
99         Message inst = new Message(select, terminate);
100         ExpressionTool.makeParentReferences(inst);
101         return inst;
102     }
103
104 }
105 //
106
// The contents of this file are subject to the Mozilla Public License Version 1.0 (the "License");
107
// you may not use this file except in compliance with the License. You may obtain a copy of the
108
// License at http://www.mozilla.org/MPL/
109
//
110
// Software distributed under the License is distributed on an "AS IS" basis,
111
// WITHOUT WARRANTY OF ANY KIND, either express or implied.
112
// See the License for the specific language governing rights and limitations under the License.
113
//
114
// The Original Code is: all this file.
115
//
116
// The Initial Developer of the Original Code is Michael H. Kay.
117
//
118
// Portions created by (your name) are Copyright (C) (your legal entity). All Rights Reserved.
119
//
120
// Contributor(s): none.
121
//
122
Popular Tags