001: /*
002: * Copyright (c) 1998-2008 Caucho Technology -- all rights reserved
003: *
004: * This file is part of Resin(R) Open Source
005: *
006: * Each copy or derived work must preserve the copyright notice and this
007: * notice unmodified.
008: *
009: * Resin Open Source is free software; you can redistribute it and/or modify
010: * it under the terms of the GNU General Public License as published by
011: * the Free Software Foundation; either version 2 of the License, or
012: * (at your option) any later version.
013: *
014: * Resin Open Source is distributed in the hope that it will be useful,
015: * but WITHOUT ANY WARRANTY; without even the implied warranty of
016: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE, or any warranty
017: * of NON-INFRINGEMENT. See the GNU General Public License for more
018: * details.
019: *
020: * You should have received a copy of the GNU General Public License
021: * along with Resin Open Source; if not, write to the
022: * Free SoftwareFoundation, Inc.
023: * 59 Temple Place, Suite 330
024: * Boston, MA 02111-1307 USA
025: *
026: * @author Scott Ferguson
027: */
028:
029: package com.caucho.xsl.java;
030:
031: import com.caucho.java.JavaWriter;
032: import com.caucho.xml.QName;
033:
034: /**
035: * Represents a namespace node from the stylesheet.
036: */
037: public class XslNamespaceNode extends XslNode {
038: private QName _name;
039: private String _value;
040:
041: public XslNamespaceNode(QName name, String value) {
042: _name = name;
043: _value = value;
044: }
045:
046: /**
047: * Generates the code for the attribute
048: *
049: * @param out the output writer for the generated java.
050: */
051: public void generate(JavaWriter out) throws Exception {
052: // XXX: filename:line
053:
054: String namespace = _name.getNamespaceURI();
055: String prefix = _name.getPrefix();
056: String local = _name.getLocalName();
057: String name = _name.getName();
058:
059: if (name.equals("xmlns")) {
060: out.print("out.bindNamespace(null, \"");
061: out.printJavaString(_value);
062: out.println("\");");
063: } else if (name.startsWith("xmlns:")) {
064: out.print("out.bindNamespace(\"" + name.substring(6)
065: + "\", \"");
066: out.printJavaString(_value);
067: out.println("\");");
068: } else if (namespace != null && _value.indexOf('{') < 0) {
069: out.print("out.attribute(");
070: out.print(namespace == null ? "null"
071: : ("\"" + namespace + "\""));
072: out.print(prefix == null ? ", null"
073: : (", \"" + prefix + "\""));
074: out.print(local == null ? ", null"
075: : (", \"" + local + "\""));
076: out.print(name == null ? ", null" : (", \"" + name + "\""));
077: out.print(", ");
078: if (_value == null)
079: out.print("null");
080: else {
081: out.print("\"");
082: out.printJavaString(_value);
083: out.print("\"");
084: }
085: out.println(");");
086: } else if (namespace != null) {
087: out.print("out.pushAttribute(");
088: out.print(namespace == null ? "null"
089: : ("\"" + namespace + "\""));
090: out.print(prefix == null ? ", null"
091: : (", \"" + prefix + "\""));
092: out.print(local == null ? ", null"
093: : (", \"" + local + "\""));
094: out.print(name == null ? ", null" : (", \"" + name + "\""));
095: out.println(");");
096: printAttributeValue(out, _value);
097: out.println("out.popAttribute();");
098: } else if (_value.indexOf('{') < 0) {
099: 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: } else {
111: out.print("out.pushAttribute(");
112: out.print(name == null ? "null" : ("\"" + name + "\""));
113: out.println(");");
114: printAttributeValue(out, _value);
115: out.println("out.popAttribute();");
116: }
117: }
118: }
|