KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > caucho > xsl > java > XslElementNode


1 /*
2  * Copyright (c) 1998-2006 Caucho Technology -- all rights reserved
3  *
4  * This file is part of Resin(R) Open Source
5  *
6  * Each copy or derived work must preserve the copyright notice and this
7  * notice unmodified.
8  *
9  * Resin Open Source is free software; you can redistribute it and/or modify
10  * it under the terms of the GNU General Public License as published by
11  * the Free Software Foundation; either version 2 of the License, or
12  * (at your option) any later version.
13  *
14  * Resin Open Source is distributed in the hope that it will be useful,
15  * but WITHOUT ANY WARRANTY; without even the implied warranty of
16  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE, or any warranty
17  * of NON-INFRINGEMENT. See the GNU General Public License for more
18  * details.
19  *
20  * You should have received a copy of the GNU General Public License
21  * along with Resin Open Source; if not, write to the
22  * Free SoftwareFoundation, Inc.
23  * 59 Temple Place, Suite 330
24  * Boston, MA 02111-1307 USA
25  *
26  * @author Scott Ferguson
27  */

28
29 package com.caucho.xsl.java;
30
31 import com.caucho.java.JavaWriter;
32 import com.caucho.xml.QName;
33 import com.caucho.xsl.JavaGenerator;
34 import com.caucho.xsl.XslParseException;
35
36 /**
37  * Represents any XSL node from the stylesheet.
38  */

39 public class XslElementNode extends XslNode {
40   private static final QName _useAttributeSets =
41     new QName("xsl", "use-attribute-sets", JavaGenerator.XSLNS);
42   
43   private QName _name;
44
45   public XslElementNode(QName name)
46   {
47     _name = name;
48   }
49
50   /**
51    * Returns the name of the tag.
52    */

53   public String JavaDoc getTagName()
54   {
55     return _name.getName();
56   }
57
58   /**
59    * Adds an attribute.
60    */

61   public void addAttribute(QName name, String JavaDoc value)
62     throws XslParseException
63   {
64     if (_useAttributeSets.equals(name)) {
65       XslUseAttributeSets attr = new XslUseAttributeSets(value);
66       
67       attr.setGenerator(_gen);
68     
69       addChild(attr);
70     }
71     else if (name.getName().startsWith("xmlns")) {
72       super.addAttribute(name, value);
73       
74       if (! JavaGenerator.XSLNS.equals(value) &&
75       ! JavaGenerator.XTPNS.equals(value)) {
76     XslNamespaceNode attr = new XslNamespaceNode(name, value);
77
78     attr.setParent(this);
79     attr.setGenerator(_gen);
80     
81     addChild(attr);
82       }
83     }
84     else if (JavaGenerator.XSLNS.equals(name.getNamespaceURI())) {
85     }
86     else if (JavaGenerator.XTPNS.equals(name.getNamespaceURI())) {
87     }
88     else {
89       XslAttributeNode attr = new XslAttributeNode(name, value);
90
91       attr.setParent(this);
92       attr.setGenerator(_gen);
93     
94       addChild(attr);
95     }
96   }
97
98   /**
99    * Generates the code for the tag
100    *
101    * @param out the output writer for the generated java.
102    */

103   public void generate(JavaWriter out)
104     throws Exception JavaDoc
105   {
106     String JavaDoc namespace = _name.getNamespaceURI();
107     String JavaDoc prefix = _name.getPrefix();
108     String JavaDoc local = _name.getLocalName();
109     String JavaDoc name = _name.getName();
110
111     _gen.printLocation(_systemId, _filename, _startLine);
112
113     String JavaDoc []postPrefix = _gen.getNamespaceAlias(namespace);
114
115     if (postPrefix != null) {
116       prefix = postPrefix[0];
117       namespace = postPrefix[1];
118       if (prefix == null || prefix.equals(""))
119         name = local;
120       else
121         name = prefix + ":" + local;
122     }
123     /*
124     if (_excludedNamespaces.get(namespace) != null)
125       namespace = null;
126     */

127     
128     //if (_namespace != null) {
129
out.print("out.pushElement(");
130       out.print(namespace == null ? "\"\"" : ("\"" + namespace + "\""));
131       out.print(prefix == null ? ", null" : (", \"" + prefix + "\""));
132       out.print(local == null ? ", null" : (", \"" + local + "\""));
133       out.print(name == null ? ", null" : (", \"" + name + "\""));
134       out.println(");");
135       /*
136     }
137     else {
138       out.print("out.pushElement(");
139       out.print(name == null ? "null" : ("\"" + name + "\""));
140       out.println(");");
141     }
142       */

143
144     generateChildren(out);
145
146     out.println("out.popElement();");
147   }
148 }
149
Popular Tags