001: /*
002: License $Id: InternalJspParser.java,v 1.9 2004/09/27 01:34:11 hendriks73 Exp $
003:
004: Copyright (c) 2001-2005 tagtraum industries.
005:
006: LGPL
007: ====
008:
009: jo! is free software; you can redistribute it and/or
010: modify it under the terms of the GNU Lesser General Public
011: License as published by the Free Software Foundation; either
012: version 2.1 of the License, or (at your option) any later version.
013:
014: jo! 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. See the GNU
017: Lesser General Public License for more details.
018:
019: You should have received a copy of the GNU Lesser General Public
020: License along with this library; if not, write to the Free Software
021: Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
022:
023: For LGPL see <http://www.fsf.org/copyleft/lesser.txt>
024:
025:
026: Sun license
027: ===========
028:
029: This release contains software by Sun Microsystems. Therefore
030: the following conditions have to be met, too. They apply to the
031: files
032:
033: - lib/mail.jar
034: - lib/activation.jar
035: - lib/jsse.jar
036: - lib/jcert.jar
037: - lib/jaxp.jar
038: - lib/crimson.jar
039: - lib/servlet.jar
040: - lib/jnet.jar
041: - lib/jaas.jar
042: - lib/jaasmod.jar
043:
044: contained in this release.
045:
046: a. Licensee may not modify the Java Platform
047: Interface (JPI, identified as classes contained within the javax
048: package or any subpackages of the javax package), by creating additional
049: classes within the JPI or otherwise causing the addition to or modification
050: of the classes in the JPI. In the event that Licensee creates any
051: Java-related API and distribute such API to others for applet or
052: application development, you must promptly publish broadly, an accurate
053: specification for such API for free use by all developers of Java-based
054: software.
055:
056: b. Software is confidential copyrighted information of Sun and
057: title to all copies is retained by Sun and/or its licensors. Licensee
058: shall not modify, decompile, disassemble, decrypt, extract, or otherwise
059: reverse engineer Software. Software may not be leased, assigned, or
060: sublicensed, in whole or in part. Software is not designed or intended
061: for use in on-line control of aircraft, air traffic, aircraft navigation
062: or aircraft communications; or in the design, construction, operation or
063: maintenance of any nuclear facility. Licensee warrants that it will not
064: use or redistribute the Software for such purposes.
065:
066: c. Software is provided "AS IS," without a warranty
067: of any kind. ALL EXPRESS OR IMPLIED REPRESENTATIONS AND WARRANTIES,
068: INCLUDING ANY IMPLIED WARRANTY OF MERCHANTABILITY, FITNESS FOR A
069: PARTICULAR PURPOSE OR NON-INFRINGEMENT, ARE HEREBY EXCLUDED.
070:
071: d. This License is effective until terminated. Licensee may
072: terminate this License at any time by destroying all copies of Software.
073: This License will terminate immediately without notice from Sun if Licensee
074: fails to comply with any provision of this License. Upon such termination,
075: Licensee must destroy all copies of Software.
076:
077: e. Software, including technical data, is subject to U.S.
078: export control laws, including the U.S. Export Administration Act and its
079: associated regulations, and may be subject to export or import regulations
080: in other countries. Licensee agrees to comply strictly with all such
081: regulations and acknowledges that it has the responsibility to obtain
082: licenses to export, re-export, or import Software. Software may not be
083: downloaded, or otherwise exported or re-exported (i) into, or to a national
084: or resident of, Cuba, Iraq, Iran, North Korea, Libya, Sudan, Syria or any
085: country to which the U.S. has embargoed goods; or (ii) to anyone on the
086: U.S. Treasury Department's list of Specially Designated Nations or the U.S.
087: Commerce Department's Table of Denial Orders.
088:
089:
090: Feedback
091: ========
092:
093: We encourage your feedback and suggestions and want to use your feedback to
094: improve the Software. Send all such feedback to:
095: <feedback@tagtraum.com>
096:
097: For more information on tagtraum industries and jo!
098: please see <http://www.tagtraum.com/>.
099:
100:
101: */
102: package com.tagtraum.jo.jsp;
103:
104: import com.tagtraum.framework.markup.AbstractTag;
105: import com.tagtraum.framework.markup.Parser;
106: import com.tagtraum.framework.markup.ParserException;
107: import com.tagtraum.framework.markup.RawDataTag;
108:
109: import java.io.Reader;
110: import java.util.StringTokenizer;
111:
112: /**
113: * JspParser that returns I_Elements.
114: *
115: * @author <a href="mailto:hs@tagtraum.com">Hendrik Schreiber</a>
116: * @version 1.1beta1 $Id: InternalJspParser.java,v 1.9 2004/09/27 01:34:11 hendriks73 Exp $
117: */
118: public class InternalJspParser extends Parser {
119:
120: // element types
121: final static int TEXT = 0;
122: final static int PAGE = 1;
123: final static int SCRIPTLET = 2;
124: final static int DECLARATION = 3;
125: final static int EXPRESSION = 4;
126: final static int COMMENT = 5;
127: final static int TAGLIB = 6;
128: final static int TAG = 7;
129: final static int DIRECTIVE = 8;
130:
131: public InternalJspParser(Reader reader) throws ParserException {
132: super (reader);
133: try {
134: // initialize parser
135: addElementClass(JspDirective.class, "%@");
136: addElementClass(JspDeclaration.class, "%!");
137: addElementClass(JspExpression.class, "%=");
138: addElementClass(JspScriptlet.class, "%");
139: addElementClass(JspTag.class, "jsp:");
140: addElementClass(JspTag.class, "/jsp:");
141: addElementClass(JspComment.class, "%--");
142: addElementClass(RawDataTag.class, "");
143: } catch (NoSuchMethodException nsme) {
144: nsme.printStackTrace();
145: }
146: }
147:
148: void addJspTag(String start) throws ParserException {
149: try {
150: addElementClass(JspTag.class, start);
151: addElementClass(JspTag.class, "/" + start);
152: } catch (NoSuchMethodException e) {
153: e.printStackTrace();
154: }
155: }
156:
157: // the tag classes have to be public - otherwise they cannot be instantiated
158: // by the Parser class in package markup.
159:
160: public static class JspComment extends AbstractTag {
161: public JspComment(String aTagStart) {
162: super (aTagStart);
163: setEnableCComments(false);
164: setEnableCPPComments(false);
165: setEnableDoubleQuotes(false);
166: setEnableSingleQuotes(false);
167: }
168:
169: public String getName() {
170: return myName = "";
171: }
172:
173: public int getType() {
174: return COMMENT;
175: }
176:
177: public String getTagEnd() {
178: return "--%";
179: }
180:
181: public boolean isWellFormed() {
182: return true;
183: }
184:
185: protected void finish() {
186: myData = sb.substring(myTagStart.length(), sb.length()
187: - getTagEnd().length() - 1);
188: }
189:
190: public String toString() {
191: return "<" + getTagStart() + myData + getTagEnd() + ">";
192: }
193: }
194:
195: public static class JspDeclaration extends AbstractTag {
196: public JspDeclaration(String aTagStart) {
197: super (aTagStart);
198: setEnableCComments(false);
199: setEnableCPPComments(false);
200: setEnableDoubleQuotes(false);
201: setEnableSingleQuotes(false);
202: }
203:
204: protected void finish() {
205: myData = JspParser.unescape(sb.substring(myTagStart
206: .length(), sb.length() - getTagEnd().length() - 1));
207: }
208:
209: public String getTagEnd() {
210: return "%";
211: }
212:
213: public String toString() {
214: return "<" + getTagStart() + myData + getTagEnd() + ">";
215: }
216:
217: public String getName() {
218: return myName = "";
219: }
220:
221: public int getType() {
222: return DECLARATION;
223: }
224:
225: public boolean isWellFormed() {
226: return true;
227: }
228: }
229:
230: public static class JspDirective extends AbstractTag {
231: public JspDirective(String aTagStart) {
232: super (aTagStart);
233: setEnableCComments(false);
234: setEnableCPPComments(false);
235: }
236:
237: public int getType() {
238: return DIRECTIVE;
239: }
240:
241: public void addAttribute(String key, String value) {
242: String upperKey = key.toUpperCase();
243: // special rule for page import! (rik)
244: if ("IMPORT".equals(key)
245: && myAttributes.containsKey(upperKey)
246: && getName().equalsIgnoreCase("page")) {
247: myAttributes.put(upperKey, ((String) myAttributes
248: .get(upperKey))
249: + "," + value);
250: } else {
251: myAttributes.put(key.toUpperCase(), value);
252: }
253: }
254:
255: public String getName() {
256: if (st == null) {
257: st = new StringTokenizer(myData, "\\\r\n\t\f \"\'=/",
258: true);
259: }
260: if (myName == null) {
261: myName = skipWhiteSpace();
262: }
263: return myName;
264: }
265:
266: protected void finish() {
267: myData = JspParser.unescape(sb.substring(myTagStart
268: .length(), sb.length() - getTagEnd().length() - 1));
269: }
270:
271: public String getTagEnd() {
272: return "%";
273: }
274:
275: public String toString() {
276: return "<" + getTagStart() + myData + getTagEnd() + ">";
277: }
278: }
279:
280: public static class JspExpression extends JspDeclaration {
281: public JspExpression(String aTagStart) {
282: super (aTagStart);
283: }
284:
285: public int getType() {
286: return EXPRESSION;
287: }
288: }
289:
290: public static class JspScriptlet extends JspDeclaration {
291: public JspScriptlet(String aTagStart) {
292: super (aTagStart);
293: }
294:
295: public int getType() {
296: return SCRIPTLET;
297: }
298: }
299:
300: public static class JspTag extends AbstractTag {
301:
302: public JspTag(String aTagStart) {
303: super (aTagStart);
304: }
305:
306: /**
307: * Returns the name of this tag. I.e. P for <p>.
308: */
309: public String getName() {
310: if (st == null) {
311: st = new StringTokenizer(myData, "\\\r\n\t\f \"\'=/",
312: true);
313: }
314: if (myName == null) {
315: myName = skipWhiteSpace();
316:
317: if (myName.equals("/")) {
318: myName = skipWhiteSpace();
319: }
320: }
321: return myName;
322: }
323:
324: public void addAttribute(String key, String value) {
325: value = removeAngledBrackets(value);
326: super .addAttribute(key, JspParser.unescape(value));
327: }
328:
329: private String removeAngledBrackets(String value) {
330: if (value.startsWith("<%=") && value.endsWith("%>"))
331: value = value.substring(1, value.length() - 1);
332: return value;
333: }
334:
335: public int getType() {
336: return InternalJspParser.TAG;
337: }
338: }
339:
340: }
|