KickJava   Java API By Example, From Geeks To Geeks.

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


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.el.Expr;
33 import com.caucho.jsp.JspLineParseException;
34 import com.caucho.jsp.JspParseException;
35 import com.caucho.jsp.JspParser;
36 import com.caucho.jsp.Namespace;
37 import com.caucho.jsp.ParseState;
38 import com.caucho.jsp.TagInstance;
39 import com.caucho.log.Log;
40 import com.caucho.util.CharBuffer;
41 import com.caucho.util.CompileException;
42 import com.caucho.util.L10N;
43 import com.caucho.util.LineCompileException;
44 import com.caucho.vfs.Path;
45 import com.caucho.vfs.WriteStream;
46 import com.caucho.xml.QName;
47 import com.caucho.xml.XmlChar;
48 import com.caucho.xpath.NamespaceContext;
49 import com.caucho.xpath.XPath;
50
51 import javax.el.MethodExpression;
52 import javax.el.ValueExpression;
53 import javax.servlet.jsp.tagext.JspFragment JavaDoc;
54 import javax.servlet.jsp.tagext.TagAttributeInfo JavaDoc;
55 import java.beans.PropertyEditor JavaDoc;
56 import java.beans.PropertyEditorManager JavaDoc;
57 import java.io.IOException JavaDoc;
58 import java.lang.reflect.Method JavaDoc;
59 import java.math.BigDecimal JavaDoc;
60 import java.math.BigInteger JavaDoc;
61 import java.util.ArrayList JavaDoc;
62 import java.util.logging.Level JavaDoc;
63 import java.util.logging.Logger JavaDoc;
64
65 public abstract class JspNode {
66   static final L10N L = new L10N(JspNode.class);
67   static final Logger JavaDoc log = Log.open(JspNode.class);
68
69   static final String JavaDoc JSP_NS = JspParser.JSP_NS;
70
71   protected Path _sourcePath;
72   protected String JavaDoc _filename;
73   protected int _startLine;
74   protected int _endAttributeLine;
75   protected int _endLine;
76
77   protected Namespace _ns;
78   
79   protected JavaJspGenerator _gen;
80   protected ParseState _parseState;
81
82   protected QName _name;
83   protected JspNode _parent;
84
85   protected JspNode()
86   {
87   }
88
89   /**
90    * Sets the Java generator.
91    */

92   public void setGenerator(JavaJspGenerator gen)
93   {
94     _gen = gen;
95   }
96
97   /**
98    * Sets the parse state
99    */

100   public void setParseState(ParseState parseState)
101   {
102     _parseState = parseState;
103   }
104
105   /**
106    * Returns the qname of the node.
107    */

108   public QName getQName()
109   {
110     return _name;
111   }
112
113   /**
114    * Sets the node's qname
115    */

116   public void setQName(QName name)
117   {
118     _name = name;
119   }
120
121   /**
122    * Returns the qname of the node.
123    */

124   public String JavaDoc getTagName()
125   {
126     if (_name != null)
127       return _name.getName();
128     else
129       return "jsp:unknown";
130   }
131   
132   /**
133    * Returns the parent node.
134    */

135   public JspNode getParent()
136   {
137     return _parent;
138   }
139
140   /**
141    * Sets the parent node
142    */

143   public void setParent(JspNode parent)
144   {
145     _parent = parent;
146   }
147
148   /**
149    * Sets the start location of the node.
150    */

151   public void setStartLocation(Path sourcePath, String JavaDoc filename, int line)
152   {
153     _sourcePath = sourcePath;
154     _filename = filename;
155     _startLine = line;
156     _endAttributeLine = line;
157   }
158
159   /**
160    * Sets the end location of the node.
161    */

162   public void setEndAttributeLocation(String JavaDoc filename, int line)
163   {
164     if (_filename != null && _filename.equals(filename))
165       _endAttributeLine = line;
166   }
167
168   /**
169    * Sets the end location of the node.
170    */

171   public void setEndLocation(String JavaDoc filename, int line)
172   {
173     if (_filename != null && _filename.equals(filename))
174       _endLine = line;
175   }
176
177   /**
178    * Gets the filename of the node
179    */

180   public String JavaDoc getFilename()
181   {
182     return _filename;
183   }
184
185   /**
186    * Gets the starting line number
187    */

188   public int getStartLine()
189   {
190     return _startLine;
191   }
192
193   /**
194    * Gets the attribute ending line number
195    */

196   public int getEndAttributeLine()
197   {
198     return _endAttributeLine;
199   }
200
201   /**
202    * Gets the ending line number
203    */

204   public int getEndLine()
205   {
206     return _endLine;
207   }
208   
209   /**
210    * True if the node only has static text.
211    */

212   public boolean isStatic()
213   {
214     return false;
215   }
216
217   /**
218    * Returns the static text.
219    */

220   public String JavaDoc getStaticText()
221   {
222     CharBuffer cb = CharBuffer.allocate();
223
224     getStaticText(cb);
225
226     return cb.close();
227   }
228
229   /**
230    * Returns the static text.
231    */

232   public void getStaticText(CharBuffer cb)
233   {
234   }
235   
236   /**
237    * True if the node has scripting
238    */

239   public boolean hasScripting()
240   {
241     return false;
242   }
243
244   /**
245    * Returns the body content.
246    */

247   public String JavaDoc getBodyContent()
248   {
249     return "jsp";
250   }
251   
252   /**
253    * True if the node contains a child tag.
254    */

255   public boolean hasCustomTag()
256   {
257     return false;
258   }
259   
260   /**
261    * True if the node contains a child tag.
262    */

263   public boolean hasTag()
264   {
265     return hasCustomTag();
266   }
267
268   /**
269    * Returns the tag name for the current tag.
270    */

271   public String JavaDoc getCustomTagName()
272   {
273     return null;
274   }
275
276   /**
277    * Returns true for a simple tag.
278    */

279   public boolean isSimpleTag()
280   {
281     return false;
282   }
283
284   /**
285    * Returns parent tag node
286    */

287   public JspNode getParentTagNode()
288   {
289     if (getCustomTagName() != null)
290       return this;
291     else {
292       JspNode parent = getParent();
293
294       if (parent != null)
295     return parent.getParentTagNode();
296       else
297     return null;
298     }
299   }
300
301   /**
302    * Returns parent tag node
303    */

304   public String JavaDoc getParentTagName()
305   {
306     if (getCustomTagName() != null)
307       return getCustomTagName();
308     else {
309       JspNode parent = getParent();
310
311       if (parent != null)
312     return parent.getParentTagName();
313       else
314     return null;
315     }
316   }
317
318   /**
319    * Returns true if the namespace decl has been printed.
320    */

321   public boolean hasNamespace(String JavaDoc prefix, String JavaDoc uri)
322   {
323     if (_parent == null)
324       return false;
325     else
326       return _parent.hasNamespace(prefix, uri);
327   }
328
329   /**
330    * Adds a namespace, e.g. from a prefix declaration.
331    */

332   public final void addNamespace(String JavaDoc prefix, String JavaDoc value)
333   {
334     addNamespaceRec(prefix, value);
335   }
336
337   /**
338    * Adds a namespace, e.g. from a prefix declaration.
339    */

340   public final void setNamespace(Namespace ns)
341   {
342     _ns = ns;
343   }
344
345   /**
346    * Returns the XPath namespace context.
347    */

348   public final NamespaceContext getNamespaceContext()
349   {
350     NamespaceContext ns = null;
351
352     for (Namespace ptr = _ns; ptr != null; ptr = ptr.getNext()) {
353       ns = new NamespaceContext(ns, ptr.getPrefix(), ptr.getURI());
354     }
355
356     return ns;
357   }
358
359   /**
360    * Adds a namespace, e.g. from a prefix declaration.
361    */

362   public void addNamespaceRec(String JavaDoc prefix, String JavaDoc value)
363   {
364     if (_parent != null)
365       _parent.addNamespaceRec(prefix, value);
366   }
367
368   /**
369    * Returns true if the namespace decl has been printed.
370    */

371   public boolean hasNamespace(QName name)
372   {
373     return hasNamespace(name.getPrefix(), name.getNamespaceURI());
374   }
375
376   /**
377    * Adds an attribute.
378    */

379   public void addAttribute(QName name, String JavaDoc value)
380     throws JspParseException
381   {
382     throw error(L.l("attribute '{0}' is not allowed in <{1}>.",
383                     name.getName(), getTagName()));
384   }
385
386   /**
387    * Adds a JspAttribute attribute.
388    *
389    * @param name the name of the attribute.
390    * @param value the value of the attribute.
391    */

392   public void addAttribute(QName name, JspAttribute value)
393     throws JspParseException
394   {
395     if (value.isStatic()) {
396       addAttribute(name, value.getStaticText().trim());
397     }
398     else
399       throw error(L.l("attribute '{0}' is not allowed in <{1}>.",
400               name.getName(), getTagName()));
401   }
402
403   /**
404    * Called after all the attributes from the tag.
405    */

406   public void endAttributes()
407     throws JspParseException
408   {
409   }
410
411   /**
412    * Adds text.
413    */

414   public JspNode addText(String JavaDoc text)
415     throws JspParseException
416   {
417     for (int i = 0; i < text.length(); i++) {
418       char ch = text.charAt(i);
419
420       if (! XmlChar.isWhitespace(ch))
421         throw error(L.l("Text is not allowed in <{0}> at '{1}'.",
422                         _name.getName(), text));
423     }
424
425     return null;
426   }
427
428   /**
429    * Adds a child node.
430    */

431   public void addChild(JspNode node)
432     throws JspParseException
433   {
434     node.setParent(this);
435     
436     if (node instanceof JspAttribute) {
437     }
438     else if (node instanceof StaticText &&
439          ((StaticText) node).isWhitespace()) {
440     }
441     else
442       throw node.error(L.l("<{0}> does not allow any child elements at {1}",
443                getTagName(), node.getTagName()));
444   }
445
446
447   /**
448    * Adds a child node after its completely initialized..
449    */

450   public void addChildEnd(JspNode node)
451     throws JspParseException
452   {
453     if (node instanceof JspAttribute) {
454       JspAttribute attr = (JspAttribute) node;
455
456       QName name = attr.getName();
457
458       addAttribute(name, attr);
459     }
460   }
461   
462   /**
463    * Called when the tag closes.
464    */

465   public void endElement()
466     throws Exception JavaDoc
467   {
468   }
469
470   /**
471    * Returns the children.
472    */

473   public ArrayList JavaDoc<JspNode> getChildren()
474   {
475     return null;
476   }
477
478   /**
479    * Returns the TagInstance of the enclosing parent.
480    */

481   public TagInstance getTag()
482   {
483     JspNode parent = getParent();
484
485     if (parent != null)
486       return parent.getTag();
487     else
488       return _gen.getRootTag();
489   }
490
491   /**
492    * Generates the XML text representation for the tag validation.
493    *
494    * @param os write stream to the generated XML.
495    */

496   abstract public void printXml(WriteStream os)
497     throws IOException JavaDoc;
498
499   /**
500    * Prints the jsp:id
501    */

502   public void printJspId(WriteStream os)
503     throws IOException JavaDoc
504   {
505     os.print(" jsp:id=\"" + _gen.generateJspId() + "\"");
506   }
507
508   /**
509    * Generates the XML text representation for the tag validation.
510    *
511    * @param os write stream to the generated XML.
512    */

513   public void printXmlText(WriteStream os, String JavaDoc text)
514     throws IOException JavaDoc
515   {
516     os.print(xmlText(text));
517   }
518
519   /**
520    * Generates the XML text.
521    */

522   public String JavaDoc xmlText(String JavaDoc text)
523   {
524     if (text == null)
525       return "";
526     
527     CharBuffer cb = new CharBuffer();
528     
529     for (int i = 0; i < text.length(); i++) {
530       char ch = text.charAt(i);
531
532       switch (ch) {
533       case '<':
534     cb.append("&lt;");
535     break;
536       case '>':
537     cb.append("&gt;");
538     break;
539       case '&':
540     cb.append("&amp;");
541     break;
542       case '"':
543     cb.append("&quot;");
544     break;
545       default:
546     cb.append(ch);
547     break;
548       }
549     }
550
551     return cb.toString();
552   }
553
554   /**
555    * Generates the XML text.
556    */

557   public String JavaDoc xmlAttrText(String JavaDoc text)
558   {
559     if (text == null)
560       return "";
561     
562     CharBuffer cb = new CharBuffer();
563     
564     for (int i = 0; i < text.length(); i++) {
565       char ch = text.charAt(i);
566
567       switch (ch) {
568       case '&':
569     cb.append("&amp;");
570     break;
571       case '"':
572     cb.append("&quot;");
573     break;
574       default:
575     cb.append(ch);
576     break;
577       }
578     }
579
580     return cb.toString();
581   }
582
583
584   /**
585    * Generates the start location.
586    */

587   public void generateStartLocation(JspJavaWriter out)
588     throws IOException JavaDoc
589   {
590     out.setLocation(_filename, _startLine);
591   }
592
593   /**
594    * Generates the start location.
595    */

596   public void generateEndLocation(JspJavaWriter out)
597     throws IOException JavaDoc
598   {
599     out.setLocation(_filename, _endLine);
600   }
601
602   /**
603    * generates prologue data.
604    */

605   public void generatePrologue(JspJavaWriter out)
606     throws Exception JavaDoc
607   {
608     generatePrologueChildren(out);
609   }
610
611   /**
612    * generates prologue data.
613    */

614   public void generatePrologueDeclare(JspJavaWriter out)
615     throws Exception JavaDoc
616   {
617   }
618
619   /**
620    * generates data for prologue children.
621    */

622   public void generatePrologueChildren(JspJavaWriter out)
623     throws Exception JavaDoc
624   {
625   }
626
627   /**
628    * generates declaration data.
629    */

630   public void generateDeclaration(JspJavaWriter out)
631     throws IOException JavaDoc
632   {
633     generateDeclarationChildren(out);
634   }
635
636   /**
637    * generates data for declaration children.
638    */

639   public void generateDeclarationChildren(JspJavaWriter out)
640     throws IOException JavaDoc
641   {
642   }
643
644   /**
645    * Generates the code for the tag
646    *
647    * @param out the output writer for the generated java.
648    */

649   abstract public void generate(JspJavaWriter out)
650     throws Exception JavaDoc;
651
652   /**
653    * Generates the code for the children.
654    *
655    * @param out the output writer for the generated java.
656    */

657   public void generateChildren(JspJavaWriter out)
658     throws Exception JavaDoc
659   {
660   }
661
662   /**
663    * Generates the code for the tag
664    *
665    * @param out the output writer for the generated java.
666    */

667   public void generateStatic(JspJavaWriter out)
668     throws Exception JavaDoc
669   {
670   }
671
672   /**
673    * Generates the code for the tag
674    *
675    * @param out the output writer for the generated java.
676    */

677   public void generateEmpty()
678     throws Exception JavaDoc
679   {
680     generateChildrenEmpty();
681   }
682
683   /**
684    * Generates the code for the children.
685    *
686    * @param out the output writer for the generated java.
687    */

688   public void generateChildrenEmpty()
689     throws Exception JavaDoc
690   {
691   }
692
693   /**
694    * Converts the string to a boolean.
695    */

696   protected boolean attributeToBoolean(String JavaDoc attr, String JavaDoc value)
697     throws JspParseException
698   {
699     if (value.equals("yes") || value.equals("true"))
700       return true;
701     else if (value.equals("no") || value.equals("false"))
702       return false;
703     else
704       throw error(L.l("'{0}' is an unknown value for {1}. 'true' or 'false' are the expected values.",
705               value, attr));
706   }
707
708   /**
709    * Returns true if in a fragment
710    */

711   public boolean isInFragment()
712   {
713     for (JspNode node = getParent(); node != null; node = node.getParent()) {
714       if (node instanceof JspAttribute || node instanceof CustomSimpleTag)
715         return true;
716     }
717
718     return false;
719   }
720     
721   void generateSetParameter(JspJavaWriter out,
722                             String JavaDoc obj, Object JavaDoc objValue, Method JavaDoc method,
723                             boolean allowRtexpr, String JavaDoc contextVar,
724                 boolean isFragment, TagAttributeInfo JavaDoc attrInfo)
725     throws Exception JavaDoc
726   {
727     Class JavaDoc type = method.getParameterTypes()[0];
728
729     if (isFragment || JspFragment JavaDoc.class.equals(type)) {
730       generateFragmentParameter(out, obj, objValue, method,
731                 allowRtexpr, contextVar);
732       return;
733     }
734
735     if (objValue instanceof JspAttribute) {
736       JspAttribute attr = (JspAttribute) objValue;
737
738       if (attr.isStatic())
739     objValue = attr.getStaticText();
740       else {
741     String JavaDoc str = "_jsp_str_" + _gen.uniqueId();
742     out.println("String " + str + " = " + attr.generateValue() + ";");
743     out.println(obj + "." + method.getName() + "(" + stringToValue(type, str) + ");");
744     return;
745       }
746     }
747     else if (objValue instanceof JspNode)
748       throw error(L.l("jsp:attribute may not set this attribute."));
749     
750     String JavaDoc strValue = (String JavaDoc) objValue;
751     
752     String JavaDoc convValue = generateParameterValue(type,
753                           strValue,
754                           allowRtexpr,
755                           attrInfo);
756
757     PropertyEditor JavaDoc editor;
758     
759     if (convValue != null)
760       out.println(obj + "." + method.getName() + "(" + convValue + ");");
761     else if ((editor = PropertyEditorManager.findEditor(type)) != null) {
762       generateSetParameter(out, obj, strValue, method, editor.getClass());
763     }
764     else
765       throw error(L.l("expected '<%= ... %>' at '{0}' for tag attribute setter '{1}'. Tag attributes which can't be converted from strings must use a runtime attribute expression.",
766                       strValue, method.getName() + "(" + type.getName() + ")"));
767   }
768
769   void generateSetParameter(JspJavaWriter out,
770                             String JavaDoc obj, String JavaDoc value, Method JavaDoc method,
771                             Class JavaDoc editorClass)
772     throws Exception JavaDoc
773   {
774     Class JavaDoc type = method.getParameterTypes()[0];
775     
776     String JavaDoc name = "_jsp_editor" + _gen.uniqueId();
777     out.print("java.beans.PropertyEditor " + name + " = new " + editorClass.getName() + "();");
778     out.println(name + ".setAsText(\"" + escapeJavaString(value) + "\");");
779     out.println(obj + "." + method.getName() + "((" +
780             type.getName() + ") " + name + ".getValue());");
781   }
782   
783   void generateFragmentParameter(JspJavaWriter out,
784                                  Object JavaDoc obj, Object JavaDoc objValue, Method JavaDoc method,
785                                  boolean allowRtexpr, String JavaDoc contextVar)
786     throws Exception JavaDoc
787   {
788     out.print(obj + "." + method.getName() + "(");
789     if (objValue instanceof JspFragmentNode)
790       generateFragment(out, (JspFragmentNode) objValue, contextVar);
791     else if (objValue instanceof String JavaDoc) {
792       String JavaDoc string = (String JavaDoc) objValue;
793
794       int index = _gen.addExpr(string);
795
796       out.print("new com.caucho.jsp.ELExprFragment(pageContext, _caucho_expr_" + index + ")");
797     }
798     else {
799       throw error(L.l("can't handle fragment '{0}' of type {1}",
800                       objValue, objValue.getClass()));
801     }
802     out.println(");");
803   }
804   
805   String JavaDoc generateFragmentParameter(String JavaDoc string, boolean allowRtexpr)
806     throws Exception JavaDoc
807   {
808     int index = _gen.addExpr(string);
809
810     return ("new com.caucho.jsp.ELExprFragment(pageContext, _caucho_expr_" + index + ")");
811   }
812
813   /**
814    * Returns the containing segment.
815    */

816   public JspSegmentNode getSegment()
817   {
818     JspNode parent = getParent();
819
820     if (parent != null)
821       return parent.getSegment();
822     else
823       return null;
824   }
825
826   void generateFragment(JspJavaWriter out, JspFragmentNode frag,
827             String JavaDoc contextVar)
828     throws Exception JavaDoc
829   {
830     out.print(generateFragment(frag, contextVar));
831   }
832
833   void generateParentTag(JspJavaWriter out, TagInstance parent)
834     throws IOException JavaDoc
835   {
836     String JavaDoc parentId = parent.getId();
837     if (parentId == null || parentId.startsWith("top_")) {
838       out.print("null");
839     }
840     else if (parent.isSimpleTag()) {
841       out.print("(" + parentId + "_adapter != null ? ");
842       out.print(parentId + "_adapter : ");
843       out.print("(" + parentId + "_adapter = new javax.servlet.jsp.tagext.TagAdapter(" + parentId + ")))");
844     }
845     else
846       out.print(parentId);
847   }
848
849   String JavaDoc generateRTValue(Class JavaDoc type, Object JavaDoc value)
850     throws Exception JavaDoc
851   {
852     if (value instanceof String JavaDoc)
853       return generateParameterValue(type, (String JavaDoc) value, true, null);
854     else {
855       JspAttribute attr = (JspAttribute) value;
856       
857       return stringToValue(type, attr.generateValue());
858     }
859   }
860
861   /**
862    * Generates the code invoking a fragment to a string.
863    */

864   protected String JavaDoc invokeFragment(JspFragmentNode frag)
865     throws Exception JavaDoc
866   {
867     return frag.generateValue();
868   }
869
870   /**
871    * Generates the code for a fragment.
872    */

873   protected String JavaDoc generateFragment(JspFragmentNode frag, String JavaDoc contextVar)
874     throws Exception JavaDoc
875   {
876     int index = _gen.addFragment(frag);
877     
878     StringBuffer JavaDoc cb = new StringBuffer JavaDoc();
879
880     if (frag.isStatic()) {
881       String JavaDoc fragmentVar = frag.getFragmentName();
882
883       cb.append(fragmentVar + " = com.caucho.jsp.StaticJspFragmentSupport.create(" + fragmentVar + ", " + contextVar + ", \"");
884
885       cb.append(escapeJavaString(frag.getStaticText()));
886       cb.append("\")");
887
888       return cb.toString();
889     }
890
891     String JavaDoc fragmentVar = frag.getFragmentName();
892
893     cb.append(fragmentVar + " = _CauchoFragment.create(" + fragmentVar + ", " +
894           index + ", " + contextVar + ", ");
895
896     JspNode parentTag = getParentTagNode();
897
898     if (parentTag == null)
899       cb.append("null");
900     else if (frag.hasCustomTag() && parentTag instanceof CustomSimpleTag)
901       cb.append(parentTag.getCustomTagName() + "_adapter");
902     else
903       cb.append(parentTag.getCustomTagName());
904
905     if (_gen instanceof JavaTagGenerator) {
906       JavaTagGenerator tagGen = (JavaTagGenerator) _gen;
907       
908       if (tagGen.isStaticDoTag()) // jsp/1025
909
cb.append(", _jspBody");
910       else
911     cb.append(", getJspBody()");
912     }
913     else
914       cb.append(", null");
915       
916     cb.append(")");
917
918     return cb.toString();
919   }
920
921   /**
922    * Generates the code for the value of a parent tag.
923    */

924   protected String JavaDoc generateParentTag(TagInstance parent)
925     throws IOException JavaDoc
926   {
927     String JavaDoc parentId = parent.getId();
928     if (parent.isTop()) {
929       return "null";
930     }
931     else if (parent.isSimpleTag()) {
932       CharBuffer cb = CharBuffer.allocate();
933       
934       cb.append("(" + parentId + "_adapter != null ? ");
935       cb.append(parentId + "_adapter : ");
936       cb.append("(" + parentId + "_adapter = new javax.servlet.jsp.tagext.TagAdapter(" + parentId + ")))");
937
938       return cb.close();
939     }
940     else
941       return parentId;
942   }
943
944   /**
945    * Generate include params.
946    */

947   void generateIncludeParams(JspJavaWriter out,
948                              ArrayList JavaDoc params)
949     throws Exception JavaDoc
950   {
951     boolean hasQuery = false;
952     
953     for (int i = 0; i < params.size(); i++) {
954       JspParam param = (JspParam) params.get(i);
955       String JavaDoc value = param.getValue();
956         
957       if (hasQuery)
958         out.print("+ \"&\" + ");
959         
960       hasQuery = true;
961       out.print("\"" + param.getName() + "=\"");
962
963       String JavaDoc outValue = generateParameterValue(String JavaDoc.class, value);
964
965       if (outValue.equals("null")) {
966       }
967       else if (outValue.startsWith("\""))
968     out.print(" + (" + outValue + ")");
969       else
970     out.print(" + com.caucho.el.Expr.toString(" + outValue + ", null)");
971     }
972   }
973
974   String JavaDoc generateValue(Class JavaDoc type, String JavaDoc value)
975     throws Exception JavaDoc
976   {
977     return generateParameterValue(type, value, true, null);
978   }
979
980   String JavaDoc generateParameterValue(Class JavaDoc type, String JavaDoc value)
981     throws Exception JavaDoc
982   {
983     return generateParameterValue(type, value, true, null);
984   }
985
986   String JavaDoc generateParameterValue(Class JavaDoc type,
987                 String JavaDoc value,
988                 boolean rtexpr,
989                 TagAttributeInfo JavaDoc attrInfo)
990     throws Exception JavaDoc
991   {
992     boolean isEmpty = value == null || value.equals("");
993     if (isEmpty)
994       value = "0";
995
996     try {
997       if (JspFragment JavaDoc.class.equals(type))
998     return generateFragmentParameter(value, rtexpr);
999       else if (type.equals(ValueExpression.class)) {
1000        int exprIndex;
1001
1002    String JavaDoc typeName = attrInfo != null ? attrInfo.getExpectedTypeName() : "";
1003
1004        if (isEmpty)
1005          exprIndex = _gen.addValueExpr("", typeName);
1006        else
1007          exprIndex = _gen.addValueExpr(value, typeName);
1008      
1009        return ("_caucho_value_expr_" + exprIndex);
1010      }
1011      else if (type.equals(MethodExpression.class)) {
1012        int exprIndex;
1013
1014    String JavaDoc sig = attrInfo != null ? attrInfo.getMethodSignature() : "";
1015
1016        if (isEmpty)
1017          exprIndex = _gen.addMethodExpr("", sig);
1018        else
1019          exprIndex = _gen.addMethodExpr(value, sig);
1020      
1021        return ("_caucho_method_expr_" + exprIndex);
1022      }
1023      else if (com.caucho.el.Expr.class.equals(type)) {
1024        int exprIndex;
1025
1026        if (isEmpty)
1027          exprIndex = _gen.addExpr("");
1028        else
1029          exprIndex = _gen.addExpr(value);
1030      
1031        return ("_caucho_expr_" + exprIndex);
1032      }
1033      else if (com.caucho.xpath.Expr.class.equals(type)) {
1034        int exprIndex;
1035    
1036    com.caucho.xpath.Expr expr;
1037        if (isEmpty)
1038      expr = XPath.parseExpr("");
1039        else
1040      expr = XPath.parseExpr(value, getNamespaceContext());
1041    
1042    return _gen.addXPathExpr(expr);
1043      }
1044      else if (rtexpr && hasRuntimeAttribute(value)) {
1045        return getRuntimeAttribute(value);
1046      }
1047      else if (rtexpr && hasELAttribute(value)) { // jsp/0138 vs jsp/18s0
1048
return generateELValue(type, value);
1049      }
1050      else if (! rtexpr && hasELAttribute(value)) {
1051    // JSP.2.3.6 says this is an error
1052
// jsp/184v vs jsp/18cr
1053
throw error(L.l("EL expression '{0}' is only allowed for attributes with rtexprvalue='true'.",
1054            value));
1055      }
1056      else if (! rtexpr
1057           && hasDeferredAttribute(value)
1058           && ! _gen.getParseState().isDeferredSyntaxAllowedAsLiteral()) {
1059    throw error(L.l("Deferred syntax '{0}' is not allowed as a literal.",
1060            value));
1061      }
1062      else if (type.equals(boolean.class))
1063        return String.valueOf(Boolean.valueOf(isEmpty ? "false" : value));
1064      else if (type.equals(Boolean JavaDoc.class)) {
1065        if (isEmpty)
1066          return "java.lang.Boolean.FALSE";
1067        else
1068          return "new java.lang.Boolean(" + Boolean.valueOf(value) + ")";
1069      }
1070      else if (type.equals(byte.class))
1071        return "(byte) " + Byte.valueOf(value);
1072      else if (type.equals(Byte JavaDoc.class))
1073        return "new java.lang.Byte((byte) " + Byte.valueOf(value) + ")";
1074      else if (type.equals(char.class)) {
1075        if (isEmpty)
1076          return "'\\0'";
1077        else
1078          return "'" + value.charAt(0) + "'";
1079      }
1080      else if (type.equals(Character JavaDoc.class)) {
1081        if (isEmpty)
1082          return "new java.lang.Character('\\0')";
1083        else
1084          return ("new Character('" + value.charAt(0) + "')");
1085      }
1086      else if (type.equals(short.class))
1087        return ("(short) " + Short.valueOf(value));
1088      else if (type.equals(Short JavaDoc.class))
1089        return ("new java.lang.Short((short) " + Short.valueOf(value) + ")");
1090      else if (type.equals(int.class))
1091        return String.valueOf(Integer.valueOf(value));
1092      else if (type.equals(Integer JavaDoc.class))
1093        return ("new java.lang.Integer(" + Integer.valueOf(value) + ")");
1094      else if (type.equals(long.class))
1095        return String.valueOf(Long.valueOf(value));
1096      else if (type.equals(Long JavaDoc.class))
1097        return ("new java.lang.Long(" + Long.valueOf(value) + ")");
1098      else if (type.equals(float.class))
1099        return ("(float) " + Float.valueOf(value));
1100      else if (type.equals(Float JavaDoc.class))
1101        return ("new java.lang.Float((float) " + Float.valueOf(value) + ")");
1102      else if (type.equals(double.class))
1103        return String.valueOf(Double.valueOf(value));
1104      else if (type.equals(Double JavaDoc.class)) {
1105    double v = Double.valueOf(value);
1106
1107    if (Double.isNaN(v))
1108      return ("new java.lang.Double(Double.NaN)");
1109    else
1110      return ("new java.lang.Double(" + v + ")");
1111      }
1112      else if (! type.equals(String JavaDoc.class)
1113           && ! type.equals(Object JavaDoc.class)) {
1114        return null;
1115      }
1116      else if (! isEmpty) {
1117        return '"' + escapeJavaString(value) + '"';
1118      }
1119      else
1120        return "\"\"";
1121    } catch (NumberFormatException JavaDoc e) {
1122      throw error(L.l("parameter format error: {0}", e.getMessage()), e);
1123    }
1124  }
1125    
1126  protected String JavaDoc generateELValue(Class JavaDoc type, String JavaDoc value)
1127    throws Exception JavaDoc
1128  {
1129    if (type.equals(com.caucho.el.Expr.class)) {
1130      int exprIndex;
1131
1132      exprIndex = _gen.addExpr(value);
1133      
1134      return ("_caucho_expr_" + exprIndex);
1135    }
1136    else if (type.equals(ValueExpression.class)) {
1137      int exprIndex;
1138
1139      exprIndex = _gen.addValueExpr(value, "");
1140      
1141      return ("_caucho_value_expr_" + exprIndex);
1142    }
1143    else if (type.equals(com.caucho.xpath.Expr.class)) {
1144      com.caucho.xpath.Expr expr;
1145
1146      expr = XPath.parseExpr(value, getNamespaceContext());
1147      
1148      return _gen.addXPathExpr(expr);
1149    }
1150
1151    Expr expr = _gen.genExpr(value);
1152
1153    if (expr.isConstant()) {
1154      try {
1155    if (expr.evalObject(null) != null) {
1156    }
1157    else if (Character JavaDoc.class.isAssignableFrom(type)) {
1158      // jsp/18s0
1159
return "new Character((char) 0)";
1160    }
1161    else if (Boolean JavaDoc.class.isAssignableFrom(type)) {
1162      // jsp/18s1
1163
return "Boolean.FALSE";
1164    }
1165    else if (String JavaDoc.class.isAssignableFrom(type)) {
1166      // jsp/18s2
1167
return "\"\"";
1168    }
1169    else if (BigInteger JavaDoc.class.isAssignableFrom(type)) {
1170      return "java.math.BigInteger.ZERO";
1171    }
1172    else if (BigDecimal JavaDoc.class.isAssignableFrom(type)) {
1173      return "java.math.BigDecimal.ZERO";
1174    }
1175    else if (Number JavaDoc.class.isAssignableFrom(type)) {
1176      // jsp/18s6
1177
return "new " + type.getName() + "((byte) 0)";
1178    }
1179    else if (Object JavaDoc.class.isAssignableFrom(type))
1180      return "null";
1181      
1182    if (boolean.class.equals(type))
1183      return expr.evalBoolean(null) ? "true" : "false";
1184    else if (Boolean JavaDoc.class.equals(type))
1185      return expr.evalBoolean(null) ? "java.lang.Boolean.TRUE" : "java.lang.Boolean.FALSE";
1186    else if (byte.class.equals(type))
1187      return "(byte) " + expr.evalLong(null);
1188    else if (Byte JavaDoc.class.equals(type))
1189      return "new java.lang.Byte((byte) " + expr.evalLong(null) + "L)";
1190    else if (short.class.equals(type))
1191      return "(short) " + expr.evalLong(null);
1192    else if (Short JavaDoc.class.equals(type))
1193      return "new java.lang.Short((short) " + expr.evalLong(null) + "L)";
1194    else if (int.class.equals(type))
1195      return "(int) " + expr.evalLong(null);
1196    else if (Integer JavaDoc.class.equals(type))
1197      return "new java.lang.Integer((int) " + expr.evalLong(null) + "L)";
1198    else if (long.class.equals(type))
1199      return "" + expr.evalLong(null) + "L";
1200    else if (Long JavaDoc.class.equals(type))
1201      return "new java.lang.Long(" + expr.evalLong(null) + "L)";
1202    else if (float.class.equals(type))
1203      return "(float) " + expr.evalDouble(null);
1204    else if (Float JavaDoc.class.equals(type))
1205      return "new java.lang.Float((float) " + expr.evalDouble(null) + ")";
1206    else if (double.class.equals(type)) {
1207      double v = expr.evalDouble(null);
1208
1209      if (Double.isNaN(v))
1210        return "Double.NaN";
1211      else
1212        return "" + v;
1213    }
1214    else if (Double JavaDoc.class.equals(type)) {
1215      double v = expr.evalDouble(null);
1216
1217      if (Double.isNaN(v))
1218        return "new Double(Double.NaN)";
1219      else
1220        return "new java.lang.Double(" + v + ")";
1221    }
1222    else if (char.class.equals(type))
1223      return "((char) " + (int) expr.evalCharacter(null) + ")";
1224    else if (Character JavaDoc.class.equals(type)) {
1225      // jsp/18s0
1226
return "new Character((char) " + (int) expr.evalCharacter(null) + ")";
1227    }
1228    else if (String JavaDoc.class.equals(type))
1229      return "\"" + escapeJavaString(expr.evalString(null)) + "\"";
1230    else if (BigInteger JavaDoc.class.equals(type)) {
1231      String JavaDoc v = expr.evalBigInteger(null).toString();
1232
1233      // 18s3
1234
if (v.equals("") || v.equals("0"))
1235        return "java.math.BigInteger.ZERO";
1236      else
1237        return "new java.math.BigInteger(\"" + v + "\")";
1238    }
1239    else if (BigDecimal JavaDoc.class.equals(type)) {
1240      String JavaDoc v = expr.evalBigDecimal(null).toString();
1241
1242      // 18s4
1243
if (v.equals("") || v.equals("0.0"))
1244        return "java.math.BigDecimal.ZERO";
1245      else
1246        return "new java.math.BigDecimal(\"" + v + "\")";
1247    }
1248    else if (Object JavaDoc.class.equals(type)) {
1249      Object JavaDoc cValue = expr.evalObject(null);
1250
1251      String JavaDoc result = generateObject(cValue);
1252
1253      if (result != null)
1254        return result;
1255    }
1256    else {
1257      Object JavaDoc cValue = expr.evalObject(null);
1258
1259      // jsp/184t
1260
if ("".equals(cValue))
1261        return "null";
1262    }
1263      } catch (Throwable JavaDoc e) {
1264    // jsp/18co
1265
// exceptions are caught at runtime
1266
log.log(Level.FINER, e.toString(), e);
1267    
1268    log.fine(e.getMessage());
1269      }
1270    }
1271    
1272    int exprIndex = _gen.addExpr(expr);
1273    String JavaDoc var = "_caucho_expr_" + exprIndex;
1274
1275    if (boolean.class.equals(type))
1276      return var + ".evalBoolean(_jsp_env)";
1277    else if (Boolean JavaDoc.class.equals(type))
1278      return var + ".evalBoolean(_jsp_env) ? java.lang.Boolean.TRUE : java.lang.Boolean.FALSE";
1279    else if (byte.class.equals(type))
1280      return "(byte) " + var + ".evalLong(_jsp_env)";
1281    else if (Byte JavaDoc.class.equals(type))
1282      return "new java.lang.Byte((byte) " + var + ".evalLong(_jsp_env))";
1283    else if (short.class.equals(type))
1284      return "(short) " + var + ".evalLong(_jsp_env)";
1285    else if (Short JavaDoc.class.equals(type))
1286      return "new java.lang.Short((short) " + var + ".evalLong(_jsp_env))";
1287    else if (int.class.equals(type))
1288      return "(int) " + var + ".evalLong(_jsp_env)";
1289    else if (Integer JavaDoc.class.equals(type))
1290      return "new java.lang.Integer((int) " + var + ".evalLong(_jsp_env))";
1291    else if (long.class.equals(type))
1292      return var + ".evalLong(_jsp_env)";
1293    else if (Long JavaDoc.class.equals(type))
1294      return "new java.lang.Long(" + var + ".evalLong(_jsp_env))";
1295    else if (float.class.equals(type))
1296      return "(float) " + var + ".evalDouble(_jsp_env)";
1297    else if (Float JavaDoc.class.equals(type))
1298      return "new java.lang.Float((float) " + var + ".evalDouble(_jsp_env))";
1299    else if (double.class.equals(type))
1300      return var + ".evalDouble(_jsp_env)";
1301    else if (Double JavaDoc.class.equals(type))
1302      return "new java.lang.Double(" + var + ".evalDouble(_jsp_env))";
1303    else if (java.math.BigDecimal JavaDoc.class.equals(type))
1304      return "" + var + ".evalBigDecimal(_jsp_env)";
1305    else if (java.math.BigInteger JavaDoc.class.equals(type))
1306      return "" + var + ".evalBigInteger(_jsp_env)";
1307    else if (char.class.equals(type))
1308      return var + ".evalCharacter(_jsp_env)";
1309    else if (Character JavaDoc.class.equals(type))
1310      return "new Character(" + var + ".evalCharacter(_jsp_env))";
1311    else if (String JavaDoc.class.equals(type))
1312      return var + ".evalString(_jsp_env)";
1313    else if (BigInteger JavaDoc.class.equals(type))
1314      return var + ".evalBigInteger(_jsp_env)";
1315    else if (BigDecimal JavaDoc.class.equals(type))
1316      return var + ".evalBigDecimal(_jsp_env)";
1317    else if (Object JavaDoc.class.equals(type))
1318      return var + ".evalObject(_jsp_env)";
1319    else {
1320      return "(" + classToString(type) + ") " + var + ".evalObject(_jsp_env)";
1321    }
1322  }
1323
1324  public void convertParameterValue(JspJavaWriter out, String JavaDoc type, String JavaDoc value)
1325    throws IOException JavaDoc
1326  {
1327    if (type.equals("boolean"))
1328      out.print("java.lang.Boolean.TRUE.equals(" + value + ")");
1329    else if (type.equals("byte"))
1330      out.print("java.lang.Byte.valueOf(" + value + ")");
1331    else if (type.equals("char"))
1332      out.print("java.lang.Character.valueOf(" + value + ")");
1333    else if (type.equals("short"))
1334      out.print("java.lang.Short.valueOf(" + value + ")");
1335    else if (type.equals("int"))
1336      out.print("((java.lang.Integer) " + value + ").intValue()");
1337    else if (type.equals("long"))
1338      out.print("((java.lang.Long) " + value + ").longValue()");
1339    else if (type.equals("float"))
1340      out.print("((java.lang.Float) " + value + ").floatValue()");
1341    else if (type.equals("double"))
1342      out.print("((java.lang.Double) " + value + ").doubleValue()");
1343    else
1344      out.print("(" + type + ")" + value);
1345  }
1346
1347  protected String JavaDoc classToString(Class JavaDoc cl)
1348  {
1349    if (cl.isArray())
1350      return classToString(cl.getComponentType()) + "[]";
1351    else
1352      return cl.getName();
1353  }
1354
1355  /**
1356   * Returns true if the value is a runtime attribute.
1357   */

1358  public boolean hasRuntimeAttribute(String JavaDoc value)
1359    throws JspParseException
1360  {
1361    if (_parseState.isScriptingInvalid()) {
1362      // && value.indexOf("<%=") >= 0) {
1363
return false;
1364      /*
1365      throw error(L.l("Runtime expressions are forbidden here. Scripting has been disabled either:\n1) disabled by the web.xml scripting-invalid\n2) disabled in a tag's descriptor\n3) forbidden in <jsp:attribute> or <jsp:body> tags."));
1366      */

1367    }
1368        
1369    if (value.startsWith("<%=") && value.endsWith("%>"))
1370      return true;
1371    else if (value.startsWith("%=") && value.endsWith("%"))
1372      return true;
1373    else if (value.indexOf("<%=") >= 0 &&
1374             value.indexOf("<%=") < value.indexOf("%>"))
1375      throw error(L.l("interpolated runtime values are forbidden by the JSP spec at '{0}'",
1376                      value));
1377    else
1378      return false;
1379  }
1380
1381  /**
1382   * Returns true if the string has scripting.
1383   */

1384  public boolean hasScripting(String JavaDoc value)
1385  {
1386    try {
1387      return value != null && hasRuntimeAttribute(value);
1388    } catch (Exception JavaDoc e) {
1389      throw new RuntimeException JavaDoc(e);
1390    }
1391  }
1392
1393  /**
1394   * Returns true if the string has scripting.
1395   */

1396  public boolean hasScripting(JspAttribute value)
1397  {
1398    return value != null && value.hasScripting();
1399  }
1400  
1401  /**
1402   * Returns true if the value is a runtime attribute.
1403   */

1404  public boolean hasELAttribute(String JavaDoc value)
1405  {
1406    return ! _parseState.isELIgnored() && value.indexOf("${") >= 0;
1407  }
1408  
1409  /**
1410   * Returns true if the value is a runtime attribute.
1411   */

1412  public boolean hasDeferredAttribute(String JavaDoc value)
1413  {
1414    return ! _parseState.isELIgnored() && value.indexOf("#{") >= 0;
1415  }
1416
1417  /**
1418   * Returns the runtime attribute of the value.
1419   */

1420  public String JavaDoc getRuntimeAttribute(String JavaDoc value)
1421    throws Exception JavaDoc
1422  {
1423    if (value.startsWith("<%=") && value.endsWith("%>"))
1424      return value.substring(3, value.length() - 2);
1425    else if (value.startsWith("%=") && value.endsWith("%"))
1426      return value.substring(2, value.length() - 1);
1427    else
1428      return value;
1429  }
1430
1431  /**
1432   * Converts a string-valued expression to the given type.
1433   */

1434  String JavaDoc stringToValue(Class JavaDoc type, String JavaDoc obj)
1435  {
1436    if (boolean.class.equals(type))
1437      return "com.caucho.jsp.PageContextImpl.toBoolean(" + obj + ")";
1438    else if (Boolean JavaDoc.class.equals(type))
1439      return "java.lang.Boolean.valueOf(" + obj + ")";
1440    else if (byte.class.equals(type))
1441      return "java.lang.Byte.parseByte(" + obj + ")";
1442    else if (Byte JavaDoc.class.equals(type))
1443      return "java.lang.Byte.valueOf(" + obj + ")";
1444    else if (char.class.equals(type))
1445      return obj + ".charAt(0)";
1446    else if (Character JavaDoc.class.equals(type))
1447      return "new java.lang.Character(" + obj + ".charAt(0))";
1448    else if (short.class.equals(type))
1449      return "java.lang.Short.parseShort(" + obj + ")";
1450    else if (Short JavaDoc.class.equals(type))
1451      return "java.lang.Short.valueOf(" + obj + ")";
1452    else if (int.class.equals(type))
1453      return "java.lang.Integer.parseInt(" + obj + ")";
1454    else if (Integer JavaDoc.class.equals(type))
1455      return "java.lang.Integer.valueOf(" + obj + ")";
1456    else if (long.class.equals(type))
1457      return "java.lang.Long.parseLong(" + obj + ")";
1458    else if (Long JavaDoc.class.equals(type))
1459      return "java.lang.Long.valueOf(" + obj + ")";
1460    else if (float.class.equals(type))
1461      return "java.lang.Float.parseFloat(" + obj + ")";
1462    else if (Float JavaDoc.class.equals(type))
1463      return "java.lang.Float.valueOf(" + obj + ")";
1464    else if (double.class.equals(type))
1465      return "java.lang.Double.parseDouble(" + obj + ")";
1466    else if (Double JavaDoc.class.equals(type))
1467      return "java.lang.Double.valueOf(" + obj + ")";
1468    else if (type.isAssignableFrom(String JavaDoc.class))
1469      return obj;
1470    else
1471      return null;
1472  }
1473  
1474  protected String JavaDoc generateObject(Object JavaDoc obj)
1475  {
1476    if (obj instanceof String JavaDoc)
1477      return "\"" + escapeJavaString((String JavaDoc) obj) + "\"";
1478    else if (obj instanceof Long JavaDoc)
1479      return "new java.lang.Long(" + obj + "L)";
1480    else if (obj instanceof Integer JavaDoc)
1481      return "new java.lang.Integer((int) " + obj + "L)";
1482    else if (obj instanceof Double JavaDoc) {
1483      double v = (Double JavaDoc) obj;
1484
1485      if (Double.isNaN(v))
1486    return "new java.lang.Double(Double.NaN)";
1487      else
1488    return "new java.lang.Double(" + v + ")";
1489    }
1490    else if (obj instanceof Boolean JavaDoc)
1491      return ((Boolean JavaDoc) obj).booleanValue() ? "java.lang.Boolean.TRUE" : "java.lang.Boolean.FALSE";
1492    else
1493      return null;
1494  }
1495  
1496  public static String JavaDoc toELObject(String JavaDoc expr, Class JavaDoc type)
1497  {
1498    if (boolean.class.equals(type))
1499      return "((" + expr + ") ? Boolean.TRUE : Boolean.FALSE)";
1500    else if (byte.class.equals(type))
1501      return "new Long(" + expr + ")";
1502    else if (short.class.equals(type))
1503      return "new Long(" + expr + ")";
1504    else if (int.class.equals(type))
1505      return "new Long(" + expr + ")";
1506    else if (long.class.equals(type))
1507      return "new Long(" + expr + ")";
1508    else if (float.class.equals(type))
1509      return "new Double(" + expr + ")";
1510    else if (double.class.equals(type))
1511      return "new Double(" + expr + ")";
1512    else if (char.class.equals(type))
1513      return "String.valueOf(" + expr + ")";
1514    else
1515      return expr;
1516  }
1517
1518  /**
1519   * Escapes a java string.
1520   */

1521  public static String JavaDoc escapeJavaString(String JavaDoc s)
1522  {
1523    if (s == null)
1524      return "";
1525
1526    CharBuffer cb = CharBuffer.allocate();
1527    for (int i = 0; i < s.length(); i++) {
1528      if (s.charAt(i) == '\\')
1529        cb.append("\\\\");
1530      else if (s.charAt(i) == '"')
1531        cb.append("\\\"");
1532      else if (s.charAt(i) == '\n')
1533        cb.append("\\n");
1534      else if (s.charAt(i) == '\r')
1535        cb.append("\\r");
1536      else
1537        cb.append(s.charAt(i));
1538    }
1539
1540    return cb.close();
1541  }
1542
1543  protected Class JavaDoc loadClass(String JavaDoc type)
1544    throws JspParseException
1545  {
1546    if (type == null)
1547      return null;
1548    else {
1549      try {
1550        return _gen.getBeanClass(type);
1551      } catch (Exception JavaDoc e) {
1552        throw new JspParseException(e);
1553      }
1554    }
1555  }
1556
1557  /**
1558   * Creates a parse exception with the proper line information.
1559   */

1560  protected JspParseException error(String JavaDoc msg)
1561  {
1562    return error(msg, null);
1563  }
1564
1565  /**
1566   * Creates a parse exception with the proper line information.
1567   */

1568  protected JspParseException error(String JavaDoc msg, Throwable JavaDoc e)
1569  {
1570    if (_filename != null) {
1571      String JavaDoc lines = _gen.getSourceLines(_sourcePath, _startLine);
1572      
1573      return new JspLineParseException(_filename + ":" + _startLine + ": " + msg + lines, e);
1574    }
1575    else
1576      return new JspParseException(msg, e);
1577  }
1578
1579  /**
1580   * Creates a parse exception with the proper line information.
1581   */

1582  protected JspParseException error(Throwable JavaDoc e)
1583  {
1584    if (e instanceof JspLineParseException)
1585      return (JspParseException) e;
1586    else if (_filename == null || e instanceof LineCompileException)
1587      return new JspLineParseException(e);
1588    else if (e instanceof CompileException)
1589      return new JspLineParseException(_filename + ":" + _startLine + ": " +
1590                       e.getMessage(), e);
1591    else
1592      return new JspLineParseException(_filename + ":" + _startLine + ": " +
1593                       String.valueOf(e), e);
1594  }
1595
1596  /**
1597   * Returns a printable version of the node.
1598   */

1599  public String JavaDoc toString()
1600  {
1601    if (_name == null)
1602      return "<" + getClass().getName() + ">";
1603    else
1604      return "<" + _name.getName() + ">";
1605  }
1606}
1607
Popular Tags