KickJava   Java API By Example, From Geeks To Geeks.

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


1 package net.sf.saxon.style;
2 import net.sf.saxon.Configuration;
3 import net.sf.saxon.expr.Expression;
4 import net.sf.saxon.expr.ExpressionTool;
5 import net.sf.saxon.instruct.CopyOf;
6 import net.sf.saxon.instruct.Executable;
7 import net.sf.saxon.om.AttributeCollection;
8 import net.sf.saxon.om.Validation;
9 import net.sf.saxon.trans.XPathException;
10 import net.sf.saxon.type.SchemaType;
11
12
13 /**
14 * An xsl:copy-of element in the stylesheet. <br>
15 */

16
17 public final class XSLCopyOf extends StyleElement {
18
19     private Expression select;
20     private boolean copyNamespaces;
21     private int validation = Validation.PRESERVE;
22     private SchemaType schemaType;
23     private boolean readOnce = false; // extension attribute to enable serial processing
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 void prepareAttributes() throws XPathException {
35
36         AttributeCollection atts = getAttributeList();
37         String JavaDoc selectAtt = null;
38         String JavaDoc copyNamespacesAtt = null;
39         String JavaDoc validationAtt = null;
40         String JavaDoc typeAtt = null;
41         String JavaDoc readOnceAtt = null;
42
43         for (int a=0; a<atts.getLength(); a++) {
44             int nc = atts.getNameCode(a);
45             String JavaDoc f = getNamePool().getClarkName(nc);
46             if (f==StandardNames.SELECT) {
47                 selectAtt = atts.getValue(a);
48             } else if (f==StandardNames.COPY_NAMESPACES) {
49                 copyNamespacesAtt = atts.getValue(a).trim();
50             } else if (f==StandardNames.VALIDATION) {
51                 validationAtt = atts.getValue(a).trim();
52             } else if (f==StandardNames.TYPE) {
53                 typeAtt = atts.getValue(a).trim();
54             } else if (f==StandardNames.SAXON_READ_ONCE) {
55                 readOnceAtt = atts.getValue(a).trim();
56             } else {
57                 checkUnknownAttribute(nc);
58             }
59         }
60
61         if (selectAtt!=null) {
62             select = makeExpression(selectAtt);
63         } else {
64             reportAbsence("select");
65         }
66
67         if (copyNamespacesAtt == null) {
68             copyNamespaces = true;
69         } else {
70             if (copyNamespacesAtt.equals("yes")) {
71                 copyNamespaces = true;
72             } else if (copyNamespacesAtt.equals("no")) {
73                 copyNamespaces = false;
74             } else {
75                 compileError("Value of copy-namespaces must be 'yes' or 'no'", "XTSE0020");
76             }
77         }
78
79         if (validationAtt!=null) {
80             validation = Validation.getCode(validationAtt);
81             if (validation != Validation.STRIP && !getConfiguration().isSchemaAware(Configuration.XSLT)) {
82                 compileError("To perform validation, a schema-aware XSLT processor is needed", "XTSE1660");
83             }
84             if (validation == Validation.INVALID) {
85                 compileError("invalid value of validation attribute", "XTSE0020");
86             }
87         } else {
88             validation = getContainingStylesheet().getDefaultValidation();
89         }
90
91         if (typeAtt!=null) {
92             schemaType = getSchemaType(typeAtt);
93             if (!getConfiguration().isSchemaAware(Configuration.XSLT)) {
94                 compileError("The @type attribute is available only with a schema-aware XSLT processor", "XTSE1660");
95             }
96         }
97
98         if (typeAtt != null && validationAtt != null) {
99             compileError("The @validation and @type attributes are mutually exclusive", "XTSE1505");
100         }
101
102         if (validation == Validation.PRESERVE && !copyNamespaces) {
103             compileError("copy-namespaces must be set to 'yes' when validation is set to 'preserve'", "XTSE0950");
104         }
105
106         if (readOnceAtt != null) {
107             if (readOnceAtt.equals("yes")) {
108                 readOnce = true;
109             } else if (readOnceAtt.equals("no")) {
110                 readOnce = false;
111             } else {
112                 compileError("saxon:read-once attribute must be 'yes' or 'no'");
113             }
114         }
115     }
116
117     public void validate() throws XPathException {
118         checkWithinTemplate();
119         checkEmpty();
120         select = typeCheck("select", select);
121     }
122
123     public Expression compile(Executable exec) {
124         CopyOf inst = new CopyOf(select, copyNamespaces, validation, schemaType, false);
125         if (readOnce) {
126             inst.setReadOnce(readOnce);
127         }
128         ExpressionTool.makeParentReferences(inst);
129         return inst;
130     }
131
132 }
133
134 //
135
// The contents of this file are subject to the Mozilla Public License Version 1.0 (the "License");
136
// you may not use this file except in compliance with the License. You may obtain a copy of the
137
// License at http://www.mozilla.org/MPL/
138
//
139
// Software distributed under the License is distributed on an "AS IS" basis,
140
// WITHOUT WARRANTY OF ANY KIND, either express or implied.
141
// See the License for the specific language governing rights and limitations under the License.
142
//
143
// The Original Code is: all this file.
144
//
145
// The Initial Developer of the Original Code is Michael H. Kay.
146
//
147
// Portions created by (your name) are Copyright (C) (your legal entity). All Rights Reserved.
148
//
149
// Contributor(s): none.
150
//
151
Popular Tags