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.jsp.java;
030:
031: import com.caucho.jsp.JspParseException;
032: import com.caucho.vfs.WriteStream;
033: import com.caucho.xml.QName;
034:
035: import java.io.IOException;
036:
037: public class JstlXmlSet extends JstlNode {
038: private static final QName SELECT = new QName("select");
039: private static final QName VAR = new QName("var");
040: private static final QName SCOPE = new QName("scope");
041:
042: private String _select;
043: private String _var;
044: private String _scope;
045:
046: /**
047: * Adds an attribute.
048: */
049: public void addAttribute(QName name, String value)
050: throws JspParseException {
051: if (SELECT.equals(name))
052: _select = value;
053: else if (VAR.equals(name))
054: _var = value;
055: else if (SCOPE.equals(name))
056: _scope = value;
057: else
058: throw error(L.l("`{0}' is an unknown attribute for <{1}>.",
059: name.getName(), getTagName()));
060: }
061:
062: /**
063: * Adds an attribute.
064: */
065: public void addAttribute(QName name, JspAttribute value)
066: throws JspParseException {
067: if (false)
068: throw error(L.l(
069: "`{0}' is an unsupported jsp:attribute for <{1}>.",
070: name.getName(), getTagName()));
071: }
072:
073: /**
074: * Generates the XML text representation for the tag validation.
075: *
076: * @param os write stream to the generated XML.
077: */
078: public void printXml(WriteStream os) throws IOException {
079: os.print("<x:set");
080:
081: if (_select != null) {
082: os.print(" select=\"");
083: printXmlText(os, _select);
084: os.print("\"");
085: }
086:
087: if (_var != null)
088: os.print(" var=\"" + _var + "\"");
089:
090: if (_scope != null)
091: os.print(" scope=\"" + _scope + "\"");
092:
093: os.print(">");
094:
095: printXmlChildren(os);
096:
097: os.print("</x:set>");
098: }
099:
100: /**
101: * Generates the code for the c:set tag.
102: */
103: public void generate(JspJavaWriter out) throws Exception {
104: if (_select == null)
105: throw error(L.l(
106: "required attribute `select' missing from <{0}>",
107: getTagName()));
108: if (_var == null)
109: throw error(L.l(
110: "required attribute `var' missing from <{0}>",
111: getTagName()));
112:
113: String select = ("com.caucho.jstl.el.XmlSetTag.evalObject(pageContext, "
114: + _gen.addXPathExpr(_select, getNamespaceContext()) + ")");
115:
116: generateSetOrRemove(out, _var, _scope, select);
117: }
118: }
|