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: import com.caucho.xsl.JavaGenerator;
034: import com.caucho.xsl.XslParseException;
035:
036: /**
037: * Represents any XSL node from the stylesheet.
038: */
039: public class XslElementNode extends XslNode {
040: private static final QName _useAttributeSets = new QName("xsl",
041: "use-attribute-sets", JavaGenerator.XSLNS);
042:
043: private QName _name;
044:
045: public XslElementNode(QName name) {
046: _name = name;
047: }
048:
049: /**
050: * Returns the name of the tag.
051: */
052: public String getTagName() {
053: return _name.getName();
054: }
055:
056: /**
057: * Adds an attribute.
058: */
059: public void addAttribute(QName name, String value)
060: throws XslParseException {
061: if (_useAttributeSets.equals(name)) {
062: XslUseAttributeSets attr = new XslUseAttributeSets(value);
063:
064: attr.setGenerator(_gen);
065:
066: addChild(attr);
067: } else if (name.getName().startsWith("xmlns")) {
068: super .addAttribute(name, value);
069:
070: if (!JavaGenerator.XSLNS.equals(value)
071: && !JavaGenerator.XTPNS.equals(value)) {
072: XslNamespaceNode attr = new XslNamespaceNode(name,
073: value);
074:
075: attr.setParent(this );
076: attr.setGenerator(_gen);
077:
078: addChild(attr);
079: }
080: } else if (JavaGenerator.XSLNS.equals(name.getNamespaceURI())) {
081: } else if (JavaGenerator.XTPNS.equals(name.getNamespaceURI())) {
082: } else {
083: XslAttributeNode attr = new XslAttributeNode(name, value);
084:
085: attr.setParent(this );
086: attr.setGenerator(_gen);
087:
088: addChild(attr);
089: }
090: }
091:
092: /**
093: * Generates the code for the tag
094: *
095: * @param out the output writer for the generated java.
096: */
097: public void generate(JavaWriter out) throws Exception {
098: String namespace = _name.getNamespaceURI();
099: String prefix = _name.getPrefix();
100: String local = _name.getLocalName();
101: String name = _name.getName();
102:
103: _gen.printLocation(_systemId, _filename, _startLine);
104:
105: String[] postPrefix = _gen.getNamespaceAlias(namespace);
106:
107: if (postPrefix != null) {
108: prefix = postPrefix[0];
109: namespace = postPrefix[1];
110: if (prefix == null || prefix.equals(""))
111: name = local;
112: else
113: name = prefix + ":" + local;
114: }
115: /*
116: if (_excludedNamespaces.get(namespace) != null)
117: namespace = null;
118: */
119:
120: //if (_namespace != null) {
121: out.print("out.pushElement(");
122: out.print(namespace == null ? "\"\""
123: : ("\"" + namespace + "\""));
124: out.print(prefix == null ? ", null" : (", \"" + prefix + "\""));
125: out.print(local == null ? ", null" : (", \"" + local + "\""));
126: out.print(name == null ? ", null" : (", \"" + name + "\""));
127: out.println(");");
128: /*
129: }
130: else {
131: out.print("out.pushElement(");
132: out.print(name == null ? "null" : ("\"" + name + "\""));
133: out.println(");");
134: }
135: */
136:
137: generateChildren(out);
138:
139: out.println("out.popElement();");
140: }
141: }
|