KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > caucho > jsp > java > JspOutput


1 /*
2  * Copyright (c) 1998-2006 Caucho Technology -- all rights reserved
3  *
4  * This file is part of Resin(R) Open Source
5  *
6  * Each copy or derived work must preserve the copyright notice and this
7  * notice unmodified.
8  *
9  * Resin Open Source is free software; you can redistribute it and/or modify
10  * it under the terms of the GNU General Public License as published by
11  * the Free Software Foundation; either version 2 of the License, or
12  * (at your option) any later version.
13  *
14  * Resin Open Source is distributed in the hope that it will be useful,
15  * but WITHOUT ANY WARRANTY; without even the implied warranty of
16  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE, or any warranty
17  * of NON-INFRINGEMENT. See the GNU General Public License for more
18  * details.
19  *
20  * You should have received a copy of the GNU General Public License
21  * along with Resin Open Source; if not, write to the
22  *
23  * Free Software Foundation, Inc.
24  * 59 Temple Place, Suite 330
25  * Boston, MA 02111-1307 USA
26  *
27  * @author Scott Ferguson
28  */

29
30 package com.caucho.jsp.java;
31
32 import com.caucho.jsp.JspParseException;
33 import com.caucho.util.L10N;
34 import com.caucho.vfs.WriteStream;
35 import com.caucho.xml.QName;
36
37 import java.io.IOException JavaDoc;
38
39 public class JspOutput extends JspNode {
40   static final L10N L = new L10N(JspOutput.class);
41
42   static final private QName OMIT_XML_DECLARATION =
43     new QName("omit-xml-declaration");
44   static final private QName DOCTYPE_SYSTEM =
45     new QName("doctype-system");
46   static final private QName DOCTYPE_PUBLIC =
47     new QName("doctype-public");
48   static final private QName DOCTYPE_ROOT_ELEMENT =
49     new QName("doctype-root-element");
50
51   private boolean _omitXmlDeclaration;
52
53   private String JavaDoc _doctypeSystem;
54   private String JavaDoc _doctypePublic;
55   private String JavaDoc _doctypeRootElement;
56   
57   /**
58    * Adds an attribute.
59    *
60    * @param name the attribute name
61    * @param value the attribute value
62    */

63   public void addAttribute(QName name, String JavaDoc value)
64     throws JspParseException
65   {
66     if (! _gen.isXml())
67       throw error(L.l("jsp:output is only allowed in jspx files."));
68     
69     if (OMIT_XML_DECLARATION.equals(name)) {
70       _gen.setOmitXmlDeclaration(attributeToBoolean(name.getName(), value));
71     }
72     else if (DOCTYPE_SYSTEM.equals(name)) {
73       String JavaDoc oldValue = _gen.getDoctypeSystem();
74
75       if (oldValue != null && ! oldValue.equals(value)) {
76         throw error(L.l("jsp:output doctype-system '{0}' conflicts with previous value '{1}'. The doctype-system attribute may only be specified once.",
77             value, oldValue));
78       }
79
80       _gen.setDoctypeSystem(value);
81       _doctypeSystem = value;
82     }
83     else if (DOCTYPE_PUBLIC.equals(name)) {
84       String JavaDoc oldValue = _gen.getDoctypePublic();
85
86       if (oldValue != null && ! oldValue.equals(value)) {
87         throw error(L.l("jsp:output doctype-public '{0}' conflicts with previous value '{1}'. The doctype-public attribute may only be specified once.",
88             value, oldValue));
89       }
90
91       _gen.setDoctypePublic(value);
92       _doctypePublic = value;
93     }
94     else if (DOCTYPE_ROOT_ELEMENT.equals(name)) {
95       String JavaDoc oldValue = _gen.getDoctypeRootElement();
96
97       if (oldValue != null && ! oldValue.equals(value)) {
98         throw error(L.l("jsp:output doctype-root-element '{0}' conflicts with previous value '{1}'. The doctype-root-element attribute may only be specified once.",
99             value, oldValue));
100       }
101
102       _gen.setDoctypeRootElement(value);
103       _doctypeRootElement = value;
104     }
105     else {
106       throw error(L.l("'{0}' is an unknown jsp:output attribute. Value attributes are: doctype-public, doctype-system, doctype-root-element.",
107                       name.getName()));
108     }
109   }
110
111   /**
112    * When the element completes.
113    */

114   public void endElement()
115     throws JspParseException
116   {
117     if (_doctypeSystem != null && _doctypeRootElement == null) {
118       throw error(L.l("<jsp:output> with a 'doctype-system' attribute requires a 'doctype-root-element' attribute."));
119     }
120     
121     if (_doctypePublic != null && _doctypeSystem == null) {
122       throw error(L.l("<jsp:output> with a 'doctype-public' attribute requires a 'doctype-system' attribute."));
123     }
124     
125     if (_doctypeRootElement != null && _doctypeSystem == null) {
126       throw error(L.l("<jsp:output> with a 'doctype-root-element' attribute requires a 'doctype-system' attribute."));
127     }
128     
129     _gen.setDoctypeSystem(_doctypeSystem);
130     _gen.setDoctypePublic(_doctypePublic);
131     _gen.setDoctypeRootElement(_doctypeRootElement);
132   }
133   
134   /**
135    * Return true if the node only has static text.
136    */

137   public boolean isStatic()
138   {
139     return true;
140   }
141
142   /**
143    * Generates the XML text representation for the tag validation.
144    *
145    * @param os write stream to the generated XML.
146    */

147   public void printXml(WriteStream os)
148     throws IOException JavaDoc
149   {
150   }
151
152   /**
153    * Generates the code for the tag
154    *
155    * @param out the output writer for the generated java.
156    */

157   public void generate(JspJavaWriter out)
158     throws Exception JavaDoc
159   {
160   }
161 }
162
Popular Tags