KickJava   Java API By Example, From Geeks To Geeks.

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


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 a namespace node from the stylesheet.
36  */

37 public class XslNamespaceNode extends XslNode {
38   private QName _name;
39   private String JavaDoc _value;
40
41   public XslNamespaceNode(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     if (name.equals("xmlns")) {
63       out.print("out.bindNamespace(null, \"");
64       out.printJavaString(_value);
65       out.println("\");");
66     }
67     else if (name.startsWith("xmlns:")) {
68       out.print("out.bindNamespace(\"" + name.substring(6) + "\", \"");
69       out.printJavaString(_value);
70       out.println("\");");
71     }
72     else if (namespace != null && _value.indexOf('{') < 0) {
73       out.print("out.attribute(");
74       out.print(namespace == null ? "null" : ("\"" + namespace + "\""));
75       out.print(prefix == null ? ", null" : (", \"" + prefix + "\""));
76       out.print(local == null ? ", null" : (", \"" + local + "\""));
77       out.print(name == null ? ", null" : (", \"" + name + "\""));
78       out.print(", ");
79       if (_value == null)
80     out.print("null");
81       else {
82     out.print("\"");
83     out.printJavaString(_value);
84     out.print("\"");
85       }
86       out.println(");");
87     }
88     else if (namespace != null) {
89       out.print("out.pushAttribute(");
90       out.print(namespace == null ? "null" : ("\"" + namespace + "\""));
91       out.print(prefix == null ? ", null" : (", \"" + prefix + "\""));
92       out.print(local == null ? ", null" : (", \"" + local + "\""));
93       out.print(name == null ? ", null" : (", \"" + name + "\""));
94       out.println(");");
95       printAttributeValue(out, _value);
96       out.println("out.popAttribute();");
97     }
98     else if (_value.indexOf('{') < 0) {
99       out.print("out.attribute(");
100       out.print(name == null ? "null" : ("\"" + name + "\""));
101       out.print(", ");
102       if (_value == null)
103     out.print("null");
104       else {
105     out.print("\"");
106     out.printJavaString(_value);
107     out.print("\"");
108       }
109       out.println(");");
110     }
111     else {
112       out.print("out.pushAttribute(");
113       out.print(name == null ? "null" : ("\"" + name + "\""));
114       out.println(");");
115       printAttributeValue(out, _value);
116       out.println("out.popAttribute();");
117     }
118   }
119 }
120
Popular Tags