KickJava   Java API By Example, From Geeks To Geeks.

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


1 package com.icl.saxon.style;
2 import com.icl.saxon.tree.AttributeCollection;
3 import com.icl.saxon.*;
4 import com.icl.saxon.om.*;
5 import com.icl.saxon.handlers.*;
6 import com.icl.saxon.expr.*;
7 import com.icl.saxon.output.*;
8
9 import javax.xml.transform.*;
10 import java.util.*;
11
12 /**
13 * Handler for xsl:copy elements in stylesheet.<BR>
14 */

15
16 public class XSLCopy extends StyleElement {
17
18     private String JavaDoc use; // value of use-attribute-sets attribute
19

20     /**
21     * Determine whether this node is an instruction.
22     * @return true - it is an instruction
23     */

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

33
34     public boolean mayContainTemplateBody() {
35         return true;
36     }
37
38     public void prepareAttributes() throws TransformerConfigurationException {
39
40         StandardNames sn = getStandardNames();
41         AttributeCollection atts = getAttributeList();
42
43         for (int a=0; a<atts.getLength(); a++) {
44             int nc = atts.getNameCode(a);
45             int f = nc & 0xfffff;
46             if (f==sn.USE_ATTRIBUTE_SETS) {
47                 use = atts.getValue(a);
48             } else {
49                 checkUnknownAttribute(nc);
50             }
51         }
52     }
53
54     public void validate() throws TransformerConfigurationException {
55         checkWithinTemplate();
56         if (use!=null) {
57             findAttributeSets(use); // find any referenced attribute sets
58
}
59     }
60
61     public void process(Context context) throws TransformerException
62     {
63         NodeInfo source = context.getCurrentNodeInfo();
64         Outputter out = context.getOutputter();
65
66         // Processing depends on the node type.
67

68         switch(source.getNodeType()) {
69
70         case NodeInfo.ELEMENT:
71             out.writeStartTag(source.getNameCode());
72     
73             source.outputNamespaceNodes(out, true);
74
75             processAttributeSets(context);
76             processChildren(context);
77             out.writeEndTag(source.getNameCode());
78             break;
79             
80         case NodeInfo.ATTRIBUTE:
81             int nameCode = source.getNameCode();
82             if (((nameCode>>20)&0xff) != 0) { // prefix!=""
83
nameCode = out.checkAttributePrefix(nameCode);
84             }
85             out.writeAttribute(nameCode, source.getStringValue());
86             break;
87             
88         case NodeInfo.TEXT:
89             out.writeContent(source.getStringValue());
90             break;
91
92         case NodeInfo.PI:
93             out.writePI(source.getDisplayName(), source.getStringValue());
94             break;
95             
96         case NodeInfo.COMMENT:
97             out.writeComment(source.getStringValue());
98             break;
99             
100         case NodeInfo.NAMESPACE:
101             source.copy(out);
102             break;
103             
104         case NodeInfo.ROOT:
105             processChildren(context);
106             break;
107             
108         default:
109             throw new IllegalArgumentException JavaDoc("Unknown node type " + source.getNodeType());
110         
111         }
112     }
113
114
115 }
116
117 //
118
// The contents of this file are subject to the Mozilla Public License Version 1.0 (the "License");
119
// you may not use this file except in compliance with the License. You may obtain a copy of the
120
// License at http://www.mozilla.org/MPL/
121
//
122
// Software distributed under the License is distributed on an "AS IS" basis,
123
// WITHOUT WARRANTY OF ANY KIND, either express or implied.
124
// See the License for the specific language governing rights and limitations under the License.
125
//
126
// The Original Code is: all this file.
127
//
128
// The Initial Developer of the Original Code is
129
// Michael Kay of International Computers Limited (mhkay@iclway.co.uk).
130
//
131
// Portions created by (your name) are Copyright (C) (your legal entity). All Rights Reserved.
132
//
133
// Contributor(s): none.
134
//
135
Popular Tags