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:
034: import java.io.IOException;
035:
036: public class JstlCoreChoose extends JstlNode {
037: /**
038: * Children are handled specially.
039: */
040: public void addChild(JspNode node) throws JspParseException {
041: if (node instanceof JstlCoreWhen)
042: super .addChild(node);
043: else if (node instanceof JstlXmlWhen)
044: super .addChild(node);
045: else if (node instanceof JstlCoreOtherwise)
046: super .addChild(node);
047: else
048: throw error(L
049: .l(
050: "<{0}> is not allowed as a child of <{1}>. Only <when> and <otherwise> are allowed children.",
051: node.getTagName(), getTagName()));
052: }
053:
054: /**
055: * Whitespace text is ignored.
056: */
057: public JspNode addText(String text) throws JspParseException {
058: if (!isWhitespace(text))
059: throw error(L
060: .l(
061: "text is not allowed as a child of <{1}>. Only <c:when> and <c:otherwise> are allowed children.",
062: getTagName()));
063:
064: return null;
065: }
066:
067: /**
068: * Validity checking.
069: */
070: public void endElement() throws JspParseException {
071: if (_children == null || _children.size() == 0)
072: throw error(L.l(
073: "<{0}> must have at least one <c:when> clause.",
074: getTagName()));
075: }
076:
077: /**
078: * Generates the XML text representation for the tag validation.
079: *
080: * @param os write stream to the generated XML.
081: */
082: public void printXml(WriteStream os) throws IOException {
083: os.print("<c:choose>");
084:
085: printXmlChildren(os);
086:
087: os.print("</c:choose>");
088: }
089:
090: /**
091: * Generates the code for the c:out tag.
092: */
093: public void generate(JspJavaWriter out) throws Exception {
094: for (int i = 0; i < _children.size(); i++) {
095: JspNode node = _children.get(i);
096:
097: if (i != 0)
098: out.print("else ");
099:
100: node.generate(out);
101: }
102: }
103: }
|