KickJava   Java API By Example, From Geeks To Geeks.

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


1 package com.icl.saxon.style;
2 import com.icl.saxon.tree.AttributeCollection;
3 import com.icl.saxon.tree.NodeImpl;
4 import com.icl.saxon.*;
5 import com.icl.saxon.om.NodeInfo;
6 import com.icl.saxon.expr.*;
7 import com.icl.saxon.output.*;
8 import javax.xml.transform.*;
9
10 import org.w3c.dom.Node JavaDoc;
11
12 /**
13 * Handler for xsl:text elements in stylesheet. <BR>
14 */

15
16 public class XSLText extends StyleElement {
17
18     private boolean disable = false;
19     private String JavaDoc value = null;
20     
21
22     /**
23     * Determine whether this node is an instruction.
24     * @return true - it is an instruction
25     */

26
27     public boolean isInstruction() {
28         return true;
29     }
30
31     public void prepareAttributes() throws TransformerConfigurationException {
32         
33         String JavaDoc disableAtt = null;
34
35         StandardNames sn = getStandardNames();
36         AttributeCollection atts = getAttributeList();
37                 
38         for (int a=0; a<atts.getLength(); a++) {
39             int nc = atts.getNameCode(a);
40             int f = nc & 0xfffff;
41             if (f==sn.DISABLE_OUTPUT_ESCAPING) {
42                 disableAtt = atts.getValue(a);
43             } else {
44                 checkUnknownAttribute(nc);
45             }
46         }
47             
48         if (disableAtt != null) {
49             if (disableAtt.equals("yes")) {
50                 disable = true;
51             } else if (disableAtt.equals("no")) {
52                 disable = false;
53             } else {
54                 compileError("disable-output-escaping attribute must be either yes or no");
55             }
56         }
57     }
58
59     public void validate() throws TransformerConfigurationException {
60         checkWithinTemplate();
61         NodeImpl node = (NodeImpl)getFirstChild();
62         if (node==null) {
63             value = "";
64         } else {
65             value = node.getStringValue();
66             while (node!=null) {
67                 if (node.getNodeType()==NodeInfo.ELEMENT) {
68                     compileError("xsl:text must not have any child elements");
69                 }
70                 node = (NodeImpl)node.getNextSibling();
71             }
72         }
73     }
74
75     public void process(Context context) throws TransformerException {
76         if (!value.equals("")) {
77             Outputter out = context.getOutputter();
78             if (disable) {
79                 out.setEscaping(false);
80                 out.writeContent(value);
81                 out.setEscaping(true);
82             } else {
83                 out.writeContent(value);
84             }
85         }
86     }
87
88 }
89
90 //
91
// The contents of this file are subject to the Mozilla Public License Version 1.0 (the "License");
92
// you may not use this file except in compliance with the License. You may obtain a copy of the
93
// License at http://www.mozilla.org/MPL/
94
//
95
// Software distributed under the License is distributed on an "AS IS" basis,
96
// WITHOUT WARRANTY OF ANY KIND, either express or implied.
97
// See the License for the specific language governing rights and limitations under the License.
98
//
99
// The Original Code is: all this file.
100
//
101
// The Initial Developer of the Original Code is
102
// Michael Kay of International Computers Limited (mhkay@iclway.co.uk).
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