KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > icl > saxon > style > XSLValueOf


1 package com.icl.saxon.style;
2 import com.icl.saxon.tree.AttributeCollection;
3 import com.icl.saxon.*;
4
5 import com.icl.saxon.expr.*;
6 import com.icl.saxon.output.*;
7 import javax.xml.transform.*;
8 import com.icl.saxon.om.NodeInfo;
9
10
11 /**
12 * An xsl:value-of element in the stylesheet.<BR>
13 * The xsl:value-of element takes attributes:<ul>
14 * <li>an mandatory attribute select="expression".
15 * This must be a valid String expression</li>
16 * <li>an optional disable-output-escaping attribute, value "yes" or "no"</li>
17 * </ul>
18 */

19
20 public final class XSLValueOf extends StyleElement {
21
22     private Expression select;
23     private boolean disable = false;
24
25     /**
26     * Determine whether this node is an instruction.
27     * @return true - it is an instruction
28     */

29
30     public boolean isInstruction() {
31         return true;
32     }
33
34     public Expression getSelectExpression() {
35         if (select==null) {
36             return new ContextNodeExpression();
37         } else {
38             return select;
39         }
40     }
41
42     public boolean getDisableOutputEscaping() {
43         return disable;
44     }
45
46     public void prepareAttributes() throws TransformerConfigurationException {
47
48         String JavaDoc selectAtt = null;
49         String JavaDoc disableAtt = null;
50         
51         StandardNames sn = getStandardNames();
52         AttributeCollection atts = getAttributeList();
53                 
54         for (int a=0; a<atts.getLength(); a++) {
55             int nc = atts.getNameCode(a);
56             int f = nc & 0xfffff;
57             if (f==sn.DISABLE_OUTPUT_ESCAPING) {
58                 disableAtt = atts.getValue(a);
59             } else if (f==sn.SELECT) {
60                 selectAtt = atts.getValue(a);
61             } else {
62                 checkUnknownAttribute(nc);
63             }
64         }
65
66         if (selectAtt==null) {
67             reportAbsence("select");
68             return;
69         }
70         if (selectAtt.trim().equals(".")) {
71             select = null; // optimization
72
} else {
73             select = makeExpression(selectAtt);
74         }
75
76         if (disableAtt != null) {
77             if (disableAtt.equals("yes")) {
78                 disable = true;
79             } else if (disableAtt.equals("no")) {
80                 disable = false;
81             } else {
82                 compileError("disable-output-escaping attribute must be either yes or no");
83             }
84         }
85
86
87     }
88
89     public void validate() throws TransformerConfigurationException {
90         checkWithinTemplate();
91         checkEmpty();
92     }
93
94     public void process(Context context) throws TransformerException
95     {
96         Outputter out = context.getOutputter();
97         if (disable) out.setEscaping(false);
98         
99         if (select==null) {
100             (context.getCurrentNodeInfo()).copyStringValue(out);
101         } else {
102             select.outputStringValue(out, context);
103         }
104         
105         if (disable) out.setEscaping(true);
106     }
107
108 }
109
110 //
111
// The contents of this file are subject to the Mozilla Public License Version 1.0 (the "License");
112
// you may not use this file except in compliance with the License. You may obtain a copy of the
113
// License at http://www.mozilla.org/MPL/
114
//
115
// Software distributed under the License is distributed on an "AS IS" basis,
116
// WITHOUT WARRANTY OF ANY KIND, either express or implied.
117
// See the License for the specific language governing rights and limitations under the License.
118
//
119
// The Original Code is: all this file.
120
//
121
// The Initial Developer of the Original Code is
122
// Michael Kay of International Computers Limited (mhkay@iclway.co.uk).
123
//
124
// Portions created by (your name) are Copyright (C) (your legal entity). All Rights Reserved.
125
//
126
// Contributor(s): none.
127
//
128
Popular Tags