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.util.L10N;
034: import com.caucho.vfs.WriteStream;
035: import com.caucho.xml.QName;
036:
037: import java.io.IOException;
038:
039: public class JspOutput extends JspNode {
040: static final L10N L = new L10N(JspOutput.class);
041:
042: static final private QName OMIT_XML_DECLARATION = new QName(
043: "omit-xml-declaration");
044: static final private QName DOCTYPE_SYSTEM = new QName(
045: "doctype-system");
046: static final private QName DOCTYPE_PUBLIC = new QName(
047: "doctype-public");
048: static final private QName DOCTYPE_ROOT_ELEMENT = new QName(
049: "doctype-root-element");
050:
051: private boolean _omitXmlDeclaration;
052:
053: private String _doctypeSystem;
054: private String _doctypePublic;
055: private String _doctypeRootElement;
056:
057: /**
058: * Adds an attribute.
059: *
060: * @param name the attribute name
061: * @param value the attribute value
062: */
063: public void addAttribute(QName name, String value)
064: throws JspParseException {
065: if (!_gen.isXml())
066: throw error(L
067: .l("jsp:output is only allowed in jspx files."));
068:
069: if (OMIT_XML_DECLARATION.equals(name)) {
070: _gen.setOmitXmlDeclaration(attributeToBoolean(name
071: .getName(), value));
072: } else if (DOCTYPE_SYSTEM.equals(name)) {
073: String oldValue = _gen.getDoctypeSystem();
074:
075: if (oldValue != null && !oldValue.equals(value)) {
076: throw error(L
077: .l(
078: "jsp:output doctype-system '{0}' conflicts with previous value '{1}'. The doctype-system attribute may only be specified once.",
079: value, oldValue));
080: }
081:
082: _gen.setDoctypeSystem(value);
083: _doctypeSystem = value;
084: } else if (DOCTYPE_PUBLIC.equals(name)) {
085: String oldValue = _gen.getDoctypePublic();
086:
087: if (oldValue != null && !oldValue.equals(value)) {
088: throw error(L
089: .l(
090: "jsp:output doctype-public '{0}' conflicts with previous value '{1}'. The doctype-public attribute may only be specified once.",
091: value, oldValue));
092: }
093:
094: _gen.setDoctypePublic(value);
095: _doctypePublic = value;
096: } else if (DOCTYPE_ROOT_ELEMENT.equals(name)) {
097: String oldValue = _gen.getDoctypeRootElement();
098:
099: if (oldValue != null && !oldValue.equals(value)) {
100: throw error(L
101: .l(
102: "jsp:output doctype-root-element '{0}' conflicts with previous value '{1}'. The doctype-root-element attribute may only be specified once.",
103: value, oldValue));
104: }
105:
106: _gen.setDoctypeRootElement(value);
107: _doctypeRootElement = value;
108: } else {
109: throw error(L
110: .l(
111: "'{0}' is an unknown jsp:output attribute. Value attributes are: doctype-public, doctype-system, doctype-root-element.",
112: name.getName()));
113: }
114: }
115:
116: /**
117: * When the element completes.
118: */
119: public void endElement() throws JspParseException {
120: if (_doctypeSystem != null && _doctypeRootElement == null) {
121: throw error(L
122: .l("<jsp:output> with a 'doctype-system' attribute requires a 'doctype-root-element' attribute."));
123: }
124:
125: if (_doctypePublic != null && _doctypeSystem == null) {
126: throw error(L
127: .l("<jsp:output> with a 'doctype-public' attribute requires a 'doctype-system' attribute."));
128: }
129:
130: if (_doctypeRootElement != null && _doctypeSystem == null) {
131: throw error(L
132: .l("<jsp:output> with a 'doctype-root-element' attribute requires a 'doctype-system' attribute."));
133: }
134:
135: _gen.setDoctypeSystem(_doctypeSystem);
136: _gen.setDoctypePublic(_doctypePublic);
137: _gen.setDoctypeRootElement(_doctypeRootElement);
138: }
139:
140: /**
141: * Return true if the node only has static text.
142: */
143: public boolean isStatic() {
144: return true;
145: }
146:
147: /**
148: * Generates the XML text representation for the tag validation.
149: *
150: * @param os write stream to the generated XML.
151: */
152: public void printXml(WriteStream os) throws IOException {
153: }
154:
155: /**
156: * Generates the code for the tag
157: *
158: * @param out the output writer for the generated java.
159: */
160: public void generate(JspJavaWriter out) throws Exception {
161: }
162: }
|