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: *
023: * Free Software Foundation, Inc.
024: * 59 Temple Place, Suite 330
025: * Boston, MA 02111-1307 USA
026: *
027: * @author Scott Ferguson
028: */
029:
030: package com.caucho.jsp.java;
031:
032: import com.caucho.jsp.JspParseException;
033: import com.caucho.vfs.WriteStream;
034: import com.caucho.xml.QName;
035:
036: import java.io.IOException;
037:
038: public class JstlFmtParam extends JstlNode {
039: private static final QName VALUE = new QName("value");
040:
041: private String _value;
042: private JspAttribute _valueAttr;
043:
044: /**
045: * Adds an attribute.
046: */
047: public void addAttribute(QName name, String value)
048: throws JspParseException {
049: if (VALUE.equals(name))
050: _value = value;
051: else
052: throw error(L.l("`{0}' is an unknown attribute for <{1}>.",
053: name.getName(), getTagName()));
054: }
055:
056: /**
057: * Returns true if the tag has scripting values.
058: */
059: public boolean hasScripting() {
060: return (super .hasScripting() || hasScripting(_value) || hasScripting(_valueAttr));
061: }
062:
063: /**
064: * Generates the XML text representation for the tag validation.
065: *
066: * @param os write stream to the generated XML.
067: */
068: public void printXml(WriteStream os) throws IOException {
069: os.print("<fmt:param>");
070:
071: printXmlText(os, _value);
072:
073: printXmlChildren(os);
074:
075: os.print("</fmt:param>");
076: }
077:
078: /**
079: * Generates the code for the fmt:param tag.
080: */
081: public void generate(JspJavaWriter out) throws Exception {
082: throw error(L.l("fmt:param can't be called directly."));
083: }
084:
085: /**
086: * Generates the code to set the fmt:param tag.
087: */
088: public void generateSet(JspJavaWriter out, String lhs)
089: throws Exception {
090: if (_value != null) {
091: if (!getRuntimeAttribute(_value).equals(_value)) {
092: // jsp/1c3s
093:
094: out.println(lhs + " = String.valueOf("
095: + getRuntimeAttribute(_value) + ");");
096: } else {
097: int paramIndex = _gen.addExpr(_value);
098:
099: out.println(lhs + " = _caucho_expr_" + paramIndex
100: + ".evalObject(_jsp_env);");
101: }
102: } else {
103: out.println("out = pageContext.pushBody();");
104:
105: generateChildren(out);
106:
107: out
108: .println(lhs
109: + " = ((com.caucho.jsp.BodyContentImpl) out).getTrimString();");
110:
111: out.println("out = pageContext.popBody();");
112: }
113: }
114: }
|