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 JstlXmlOut extends JstlNode {
038: private static final QName SELECT = new QName("select");
039: private static final QName ESCAPE_XML = new QName("escapeXml");
040:
041: private String _select;
042:
043: private String _escapeXml = "true";
044: private JspAttribute _escapeXmlAttr;
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 (ESCAPE_XML.equals(name))
054: _escapeXml = value;
055: else
056: throw error(L.l("`{0}' is an unknown attribute for <{1}>.",
057: name.getName(), getTagName()));
058: }
059:
060: /**
061: * Adds an attribute.
062: */
063: public void addAttribute(QName name, JspAttribute value)
064: throws JspParseException {
065: if (ESCAPE_XML.equals(name))
066: _escapeXmlAttr = value;
067: else
068: throw error(L.l("`{0}' is an unknown attribute for <{1}>.",
069: name.getName(), getTagName()));
070: }
071:
072: /**
073: * Generates the XML text representation for the tag validation.
074: *
075: * @param os write stream to the generated XML.
076: */
077: public void printXml(WriteStream os) throws IOException {
078: os.print("<x:out");
079:
080: if (_select != null) {
081: os.print(" select=\"");
082: printXmlText(os, _select);
083: os.print("\"");
084: }
085: os.print("/>");
086: }
087:
088: /**
089: * Generates the code for the c:out tag.
090: */
091: public void generate(JspJavaWriter out) throws Exception {
092: if (_select == null)
093: throw error(L.l(
094: "required attribute `select' missing from <{0}>",
095: getTagName()));
096:
097: String select = _gen.addXPathExpr(_select,
098: getNamespaceContext());
099:
100: String escapeXml = "true";
101:
102: if (_escapeXml != null)
103: escapeXml = generateValue(boolean.class, _escapeXml);
104: else if (_escapeXmlAttr != null)
105: escapeXml = _escapeXmlAttr.generateValue(String.class);
106:
107: out
108: .println("com.caucho.jstl.el.XmlOutTag.toStream(out, pageContext, "
109: + select + ", " + escapeXml + ");");
110: }
111: }
|