KickJava   Java API By Example, From Geeks To Geeks.

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


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.DocumentInstr;
6 import net.sf.saxon.instruct.Executable;
7 import net.sf.saxon.om.AttributeCollection;
8 import net.sf.saxon.om.Axis;
9 import net.sf.saxon.om.Validation;
10 import net.sf.saxon.trans.XPathException;
11 import net.sf.saxon.type.SchemaType;
12 import net.sf.saxon.value.EmptySequence;
13
14 /**
15 * An xsl:document instruction in the stylesheet. <BR>
16 * This instruction creates a document node in the result tree, optionally
17  * validating it.
18 */

19
20 public class XSLDocument extends StyleElement {
21
22     private int validationAction = Validation.STRIP;
23     private SchemaType schemaType = null;
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     /**
35     * Determine whether this type of element is allowed to contain a template-body
36     * @return true: yes, it may contain a template-body
37     */

38
39     public boolean mayContainSequenceConstructor() {
40         return true;
41     }
42
43     public void prepareAttributes() throws XPathException {
44         AttributeCollection atts = getAttributeList();
45
46         String JavaDoc validationAtt = null;
47         String JavaDoc typeAtt = null;
48
49         for (int a=0; a<atts.getLength(); a++) {
50             int nc = atts.getNameCode(a);
51             String JavaDoc f = getNamePool().getClarkName(nc);
52             if (f==StandardNames.VALIDATION) {
53                 validationAtt = atts.getValue(a).trim();
54             } else if (f==StandardNames.TYPE) {
55                 typeAtt = atts.getValue(a).trim();
56             } else {
57                 checkUnknownAttribute(nc);
58             }
59         }
60
61         if (validationAtt==null) {
62             validationAction = getContainingStylesheet().getDefaultValidation();
63         } else {
64             validationAction = Validation.getCode(validationAtt);
65             if (validationAction != Validation.STRIP && !getConfiguration().isSchemaAware(Configuration.XSLT)) {
66                 compileError("To perform validation, a schema-aware XSLT processor is needed", "XTSE1660");
67             }
68             if (validationAction == Validation.INVALID) {
69                 compileError("Invalid value of @validation attribute", "XTSE0020");
70             }
71         }
72         if (typeAtt!=null) {
73             if (!getConfiguration().isSchemaAware(Configuration.XSLT)) {
74                 compileError("The @type attribute is available only with a schema-aware XSLT processor", "XTSE1660");
75             }
76             schemaType = getSchemaType(typeAtt);
77         }
78
79         if (typeAtt != null && validationAtt != null) {
80             compileError("The @validation and @type attributes are mutually exclusive", "XTSE1505");
81         }
82     }
83
84     public void validate() throws XPathException {
85         checkWithinTemplate();
86     }
87
88     public Expression compile(Executable exec) throws XPathException {
89
90         DocumentInstr inst = new DocumentInstr(false, null, getBaseURI());
91         inst.setValidationAction(validationAction);
92         inst.setSchemaType(schemaType);
93         Expression b = compileSequenceConstructor(exec, iterateAxis(Axis.CHILD), true);
94         if (b == null) {
95             b = EmptySequence.getInstance();
96         }
97         inst.setContentExpression(b);
98         ExpressionTool.makeParentReferences(inst);
99         return inst;
100     }
101
102 }
103
104 //
105
// The contents of this file are subject to the Mozilla Public License Version 1.0 (the "License");
106
// you may not use this file except in compliance with the License. You may obtain a copy of the
107
// License at http://www.mozilla.org/MPL/
108
//
109
// Software distributed under the License is distributed on an "AS IS" basis,
110
// WITHOUT WARRANTY OF ANY KIND, either express or implied.
111
// See the License for the specific language governing rights and limitations under the License.
112
//
113
// The Original Code is: all this file.
114
//
115
// The Initial Developer of the Original Code is Michael H. Kay.
116
//
117
// Portions created by (your name) are Copyright (C) (your legal entity). All Rights Reserved.
118
//
119
// Additional Contributor(s): Brett Knights [brett@knightsofthenet.com]
120
//
121
Popular Tags