KickJava   Java API By Example, From Geeks To Geeks.

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


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
34 /**
35  * Represents any XSL node from the stylesheet.
36  */

37 public class XslAttributeNode extends XslNode {
38   private QName _name;
39   private String JavaDoc _value;
40
41   public XslAttributeNode(QName name, String JavaDoc value)
42   {
43     _name = name;
44     _value = value;
45   }
46
47   /**
48    * Generates the code for the attribute
49    *
50    * @param out the output writer for the generated java.
51    */

52   public void generate(JavaWriter out)
53     throws Exception JavaDoc
54   {
55     // XXX: filename:line
56

57     String JavaDoc namespace = _name.getNamespaceURI();
58     String JavaDoc prefix = _name.getPrefix();
59     String JavaDoc local = _name.getLocalName();
60     String JavaDoc name = _name.getName();
61     
62     String JavaDoc []postPrefix = _gen.getNamespaceAlias(namespace);
63     
64     if (postPrefix != null) {
65       prefix = postPrefix[0];
66       namespace = postPrefix[1];
67       if (prefix == null || prefix.equals(""))
68         name = local;
69       else
70         name = prefix + ":" + local;
71     }
72     /*
73     if (_excludedNamespaces.get(namespace) != null)
74       namespace = null;
75     */

76
77     if (name.equals("xmlns")) {
78       out.print("out.bindNamespace(null, \"");
79       out.printJavaString(_value);
80       out.println("\");");
81     }
82     else if (name.startsWith("xmlns:")) {
83       out.print("out.bindNamespace(\"" + name.substring(6) + "\", \"");
84       out.printJavaString(_value);
85       out.println("\");");
86     }
87     else if (namespace != null && _value.indexOf('{') < 0) {
88       out.print("out.attribute(");
89       out.print(namespace == null ? "null" : ("\"" + namespace + "\""));
90       out.print(prefix == null ? ", null" : (", \"" + prefix + "\""));
91       out.print(local == null ? ", null" : (", \"" + local + "\""));
92       out.print(name == null ? ", null" : (", \"" + name + "\""));
93       out.print(", ");
94       if (_value == null)
95     out.print("null");
96       else {
97     out.print("\"");
98     out.printJavaString(_value);
99     out.print("\"");
100       }
101       out.println(");");
102     }
103     else if (namespace != null) {
104       out.print("out.attribute(");
105       out.print(namespace == null ? "null" : ("\"" + namespace + "\""));
106       out.print(prefix == null ? ", null" : (", \"" + prefix + "\""));
107       out.print(local == null ? ", null" : (", \"" + local + "\""));
108       out.print(name == null ? ", null" : (", \"" + name + "\""));
109       out.print(",");
110       generateString(out, _value, '+');
111       out.println(");");
112     }
113     else if (_value.indexOf('{') < 0) {
114       out.print("out.attribute(");
115       out.print(name == null ? "null" : ("\"" + name + "\""));
116       out.print(", ");
117       if (_value == null)
118     out.print("null");
119       else {
120     out.print("\"");
121     out.printJavaString(_value);
122     out.print("\"");
123       }
124       out.println(");");
125     }
126     else {
127       out.print("out.attribute(");
128       out.print(name == null ? "null" : ("\"" + name + "\""));
129       out.print(", ");
130       generateString(out, _value, '+');
131       out.println(");");
132     }
133   }
134
135   public String JavaDoc toString()
136   {
137     return "XslAttributeNode[" + _name + "," + _value + "]";
138   }
139 }
140
Popular Tags