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: import java.util.logging.Level;
037:
038: /**
039: * Represents a Java scriptlet.
040: */
041: public class JspParam extends JspNode {
042: private static final QName NAME = new QName("name");
043: private static final QName VALUE = new QName("value");
044:
045: private String _name;
046: private String _value;
047:
048: /**
049: * Adds an attribute.
050: */
051: public void addAttribute(QName name, String value)
052: throws JspParseException {
053: if (NAME.equals(name)) {
054: _name = value;
055:
056: if (hasRuntimeAttribute(value) || hasELAttribute(value))
057: throw error(L
058: .l(
059: "'name' attribute may not have a runtime value at {0}",
060: value));
061: } else if (VALUE.equals(name))
062: _value = value;
063: else
064: throw error(L.l(
065: "`{0}' is an invalid attribute in <jsp:param>",
066: name.getName()));
067: }
068:
069: /**
070: * Returns the param name.
071: */
072: public String getName() {
073: return _name;
074: }
075:
076: /**
077: * Returns the param value.
078: */
079: public String getValue() {
080: return _value;
081: }
082:
083: /**
084: * Called when the tag closes.
085: */
086: public void endElement() throws Exception {
087: if (_name == null)
088: throw error(L.l("jsp:param requires a 'name' attribute"));
089:
090: if (_value == null)
091: throw error(L.l("jsp:param requires a 'value' attribute"));
092: }
093:
094: /**
095: * Returns true if the param has scripting elements.
096: */
097: public boolean hasScripting() {
098: try {
099: return hasRuntimeAttribute(getName())
100: || hasRuntimeAttribute(getValue());
101: } catch (Exception e) {
102: log.log(Level.WARNING, e.toString(), e);
103: return true;
104: }
105: }
106:
107: /**
108: * Generates the XML text representation for the tag validation.
109: *
110: * @param os write stream to the generated XML.
111: */
112: public void printXml(WriteStream os) throws IOException {
113: throw new IOException(L
114: .l("<jsp:param> does not have a direct xml."));
115: }
116:
117: /**
118: * Generates the code for the scriptlet
119: *
120: * @param out the output writer for the generated java.
121: */
122: public void generate(JspJavaWriter out) throws Exception {
123: throw error(L.l("<jsp:param> does not generate code directly."));
124: }
125:
126: /**
127: * Generates the code for the scriptlet
128: *
129: * @param out the output writer for the generated java.
130: */
131: public void generateEmpty() throws Exception {
132: throw error(L.l("<jsp:param> does not generate code directly."));
133: }
134: }
|