KickJava   Java API By Example, From Geeks To Geeks.

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


1 package com.icl.saxon.style;
2 import com.icl.saxon.tree.AttributeCollection;
3 import com.icl.saxon.Context;
4 import com.icl.saxon.om.Name;
5 import com.icl.saxon.expr.Expression;
6 import com.icl.saxon.output.Outputter;
7 import javax.xml.transform.TransformerException JavaDoc;
8 import javax.xml.transform.TransformerConfigurationException JavaDoc;
9
10 //import java.util.*;
11

12 /**
13 * An xsl:processing-instruction element in the stylesheet.
14 */

15
16 public class XSLProcessingInstruction extends XSLStringConstructor {
17
18     Expression name;
19
20     public void prepareAttributes() throws TransformerConfigurationException JavaDoc {
21
22         String JavaDoc nameAtt = null;
23         
24         StandardNames sn = getStandardNames();
25         AttributeCollection atts = getAttributeList();
26
27         for (int a=0; a<atts.getLength(); a++) {
28             int nc = atts.getNameCode(a);
29             int f = nc & 0xfffff;
30             if (f==sn.NAME) {
31                 nameAtt = atts.getValue(a);
32             } else {
33                 checkUnknownAttribute(nc);
34             }
35         }
36         if (nameAtt==null) {
37             reportAbsence("name");
38         } else {
39             name = makeAttributeValueTemplate(nameAtt);
40         }
41     }
42
43     public void validate() throws TransformerConfigurationException JavaDoc {
44         checkWithinTemplate();
45         optimize();
46     }
47
48
49     public void process(Context context) throws TransformerException JavaDoc
50     {
51         String JavaDoc expandedName = name.evaluateAsString(context);
52
53         if (!(Name.isNCName(expandedName)) || expandedName.equalsIgnoreCase("xml")) {
54             context.getController().reportRecoverableError(
55                 "Processing instruction name is invalid: " + expandedName, this);
56             return;
57         }
58
59         String JavaDoc data = expandChildren(context);
60
61         int hh = data.indexOf("?>");
62         if (hh >= 0) {
63             context.getController().reportRecoverableError(
64                 "Invalid characters (?>) in processing instruction", this);
65             data = data.substring(0, hh+1) + " " + data.substring(hh+1);
66         }
67
68         context.getOutputter().writePI(expandedName, data);
69     }
70
71
72 }
73
74 //
75
// The contents of this file are subject to the Mozilla Public License Version 1.0 (the "License");
76
// you may not use this file except in compliance with the License. You may obtain a copy of the
77
// License at http://www.mozilla.org/MPL/
78
//
79
// Software distributed under the License is distributed on an "AS IS" basis,
80
// WITHOUT WARRANTY OF ANY KIND, either express or implied.
81
// See the License for the specific language governing rights and limitations under the License.
82
//
83
// The Original Code is: all this file.
84
//
85
// The Initial Developer of the Original Code is
86
// Michael Kay of International Computers Limited (mhkay@iclway.co.uk).
87
//
88
// Portions created by (your name) are Copyright (C) (your legal entity). All Rights Reserved.
89
//
90
// Contributor(s): none.
91
//
92
Popular Tags