KickJava   Java API By Example, From Geeks To Geeks.

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


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.Executable;
5 import net.sf.saxon.instruct.ValueOf;
6 import net.sf.saxon.om.AttributeCollection;
7 import net.sf.saxon.om.Axis;
8 import net.sf.saxon.om.AxisIterator;
9 import net.sf.saxon.om.Item;
10 import net.sf.saxon.pattern.NodeKindTest;
11 import net.sf.saxon.trans.XPathException;
12 import net.sf.saxon.type.ItemType;
13 import net.sf.saxon.value.StringValue;
14
15 /**
16 * Handler for xsl:text elements in stylesheet. <BR>
17 */

18
19 public class XSLText extends XSLStringConstructor {
20
21     private boolean disable = false;
22     private StringValue value;
23
24     /**
25      * Determine the type of item returned by this instruction (only relevant if
26      * it is an instruction).
27      * @return the item type returned
28      */

29
30     protected ItemType getReturnedItemType() {
31         return NodeKindTest.TEXT;
32     }
33
34     public void prepareAttributes() throws XPathException {
35
36         String JavaDoc disableAtt = null;
37
38         AttributeCollection atts = getAttributeList();
39
40         for (int a=0; a<atts.getLength(); a++) {
41             int nc = atts.getNameCode(a);
42             String JavaDoc f = getNamePool().getClarkName(nc);
43             if (f==StandardNames.DISABLE_OUTPUT_ESCAPING) {
44                 disableAtt = atts.getValue(a).trim();
45             } else {
46                 checkUnknownAttribute(nc);
47             }
48         }
49
50         if (disableAtt != null) {
51             if (disableAtt.equals("yes")) {
52                 disable = true;
53             } else if (disableAtt.equals("no")) {
54                 disable = false;
55             } else {
56                 compileError("disable-output-escaping attribute must be either 'yes' or 'no'", "XTSE0020");
57             }
58         }
59     }
60
61     public void validate() throws XPathException {
62         checkWithinTemplate();
63
64         // 2.0 spec has reverted to the 1.0 rule that xsl:text may not have child elements
65
AxisIterator kids = iterateAxis(Axis.CHILD);
66         value = StringValue.EMPTY_STRING;
67         while(true) {
68             Item child = kids.next();
69             if (child == null) {
70                 break;
71             } else if (child instanceof StyleElement) {
72                 ((StyleElement)child).compileError("xsl:text must not contain child elements", "XTSE0010");
73                 return;
74             } else {
75                 value = StringValue.makeStringValue(child.getStringValueCS());
76                 continue;
77             }
78         }
79         super.validate();
80     }
81
82     public Expression compile(Executable exec) throws XPathException {
83         ValueOf inst = new ValueOf(value, disable, false);
84         //compileContent(exec, inst);
85
ExpressionTool.makeParentReferences(inst);
86         return inst;
87     }
88
89 }
90
91 //
92
// The contents of this file are subject to the Mozilla Public License Version 1.0 (the "License");
93
// you may not use this file except in compliance with the License. You may obtain a copy of the
94
// License at http://www.mozilla.org/MPL/
95
//
96
// Software distributed under the License is distributed on an "AS IS" basis,
97
// WITHOUT WARRANTY OF ANY KIND, either express or implied.
98
// See the License for the specific language governing rights and limitations under the License.
99
//
100
// The Original Code is: all this file.
101
//
102
// The Initial Developer of the Original Code is Michael H. Kay.
103
//
104
// Portions created by (your name) are Copyright (C) (your legal entity). All Rights Reserved.
105
//
106
// Contributor(s): none.
107
//
108
Popular Tags