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.XslParseException;
034:
035: import java.util.ArrayList;
036:
037: /**
038: * Represents an attribute set.
039: */
040: public class XslAttributeSet extends XslNode implements XslTopNode {
041: private String _name;
042: private ArrayList<XslAttribute> _attributes = new ArrayList<XslAttribute>();
043: private ArrayList<String> _useAttributeSets = new ArrayList<String>();
044:
045: /**
046: * Returns the tag name.
047: */
048: public String getTagName() {
049: return "xsl:attribute-set";
050: }
051:
052: /**
053: * Returns the attributes.
054: */
055: public ArrayList<XslAttribute> getAttributes() {
056: ArrayList<XslAttribute> attributes = new ArrayList<XslAttribute>();
057:
058: attributes.addAll(_attributes);
059:
060: for (int i = 0; i < _useAttributeSets.size(); i++) {
061: String useSet = _useAttributeSets.get(i);
062:
063: attributes.addAll(_gen.getAttributeSetList(useSet));
064: }
065:
066: return attributes;
067: }
068:
069: /**
070: * Adds an attribute.
071: */
072: public void addAttribute(QName name, String value)
073: throws XslParseException {
074: if (name.getName().equals("name"))
075: _name = value;
076: else if (name.getName().equals("use-attribute-sets")) {
077: _useAttributeSets.add(value);
078: } else
079: super .addAttribute(name, value);
080: }
081:
082: /**
083: * Ends the attributes.
084: */
085: public void endAttributes() throws XslParseException {
086: if (_name == null)
087: throw error(L
088: .l("xsl:attribute-set needs a 'name' attribute."));
089: }
090:
091: /**
092: * Adds a child node.
093: */
094: public void addChild(XslNode node) throws XslParseException {
095: if (node instanceof XslAttribute) {
096: _attributes.add((XslAttribute) node);
097: } else if (node instanceof TextNode) {
098: } else
099: throw error(L
100: .l("<xsl:attribute-set> can only have <xsl:attribute> children."));
101: }
102:
103: /**
104: * Called when the tag closes.
105: */
106: public void endElement() throws Exception {
107: _gen.addAttributeSet(_name, this );
108: }
109:
110: /**
111: * Generates the code for the tag
112: *
113: * @param out the output writer for the generated java.
114: */
115: public void generate(JavaWriter out) throws Exception {
116: }
117: }
|