KickJava   Java API By Example, From Geeks To Geeks.

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


1 package net.sf.saxon.style;
2 import net.sf.saxon.expr.Expression;
3 import net.sf.saxon.expr.ExpressionTool;
4 import net.sf.saxon.instruct.Executable;
5 import net.sf.saxon.instruct.ValueOf;
6 import net.sf.saxon.om.AttributeCollection;
7 import net.sf.saxon.value.StringValue;
8 import net.sf.saxon.trans.XPathException;
9
10 import javax.xml.transform.TransformerConfigurationException JavaDoc;
11
12
13
14 /**
15 * A saxon:entity-ref element in the stylesheet. This causes an entity reference
16 * to be output to the XML or HTML output stream. <br>
17 */

18
19 public class SaxonEntityRef extends StyleElement {
20
21     String JavaDoc nameAttribute;
22
23     /**
24     * Determine whether this node is an instruction.
25     * @return true - it is an instruction
26     */

27
28     public boolean isInstruction() {
29         return true;
30     }
31
32
33     public void prepareAttributes() throws XPathException {
34
35         AttributeCollection atts = getAttributeList();
36
37         for (int a=0; a<atts.getLength(); a++) {
38             int nc = atts.getNameCode(a);
39             String JavaDoc f = getNamePool().getClarkName(nc);
40             if (f==StandardNames.NAME) {
41                 nameAttribute = atts.getValue(a).trim();
42             } else {
43                 checkUnknownAttribute(nc);
44             }
45         }
46
47         if (nameAttribute==null) {
48             reportAbsence("name");
49         }
50     }
51
52     public void validate() throws XPathException {
53         checkWithinTemplate();
54         checkEmpty();
55     }
56
57     public Expression compile(Executable exec) throws XPathException {
58         ValueOf text = new ValueOf(new StringValue('&' + nameAttribute + ';'), true, false);
59 // try {
60
// text.setSelect(new StringValue('&' + nameAttribute + ';'));
61
// } catch (StaticError err) {
62
// compileError(err);
63
// }
64
ExpressionTool.makeParentReferences(text);
65         return text;
66     }
67
68 }
69 //
70
// The contents of this file are subject to the Mozilla Public License Version 1.0 (the "License");
71
// you may not use this file except in compliance with the License. You may obtain a copy of the
72
// License at http://www.mozilla.org/MPL/
73
//
74
// Software distributed under the License is distributed on an "AS IS" basis,
75
// WITHOUT WARRANTY OF ANY KIND, either express or implied.
76
// See the License for the specific language governing rights and limitations under the License.
77
//
78
// The Original Code is: all this file.
79
//
80
// The Initial Developer of the Original Code is Michael H. Kay.
81
//
82
// Portions created by (your name) are Copyright (C) (your legal entity). All Rights Reserved.
83
//
84
// Contributor(s): none.
85
//
86
Popular Tags