KickJava   Java API By Example, From Geeks To Geeks.

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


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  * Free SoftwareFoundation, Inc.
23  * 59 Temple Place, Suite 330
24  * Boston, MA 02111-1307 USA
25  *
26  * @author Scott Ferguson
27  */

28
29 package com.caucho.jsp.java;
30
31 import com.caucho.config.types.Signature;
32 import com.caucho.jsp.JspParseException;
33 import com.caucho.jsp.ParseTagManager;
34 import com.caucho.jsp.cfg.TldAttribute;
35 import com.caucho.jsp.cfg.TldTag;
36 import com.caucho.jsp.cfg.TldVariable;
37 import com.caucho.log.Log;
38 import com.caucho.util.L10N;
39
40 import javax.servlet.jsp.tagext.TagInfo JavaDoc;
41 import javax.servlet.jsp.tagext.TagLibraryInfo JavaDoc;
42 import java.io.IOException JavaDoc;
43 import java.util.ArrayList JavaDoc;
44 import java.util.HashSet JavaDoc;
45 import java.util.logging.Level JavaDoc;
46 import java.util.logging.Logger JavaDoc;
47
48 /**
49  * Generates JSP code. JavaGenerator, JavaScriptGenerator, and
50  * StaticGenerator specialize the JspGenerator for language-specific
51  * requirements.
52  *
53  * <p>JspParser parses the JSP file into an XML-DOM tree. JspGenerator
54  * generates code from that tree.
55  */

56 public class JavaTagGenerator extends JavaJspGenerator {
57   static final L10N L = new L10N(JavaTagGenerator.class);
58   static final Logger JavaDoc log = Log.open(JavaTagGenerator.class);
59
60   private static HashSet JavaDoc<String JavaDoc> _reserved
61     = new HashSet JavaDoc<String JavaDoc>();
62
63   private String JavaDoc _description = null;
64   private String JavaDoc _displayName = null;
65   private String JavaDoc _smallIcon = null;
66   private String JavaDoc _largeIcon = null;
67   private String JavaDoc _example = null;
68   private String JavaDoc _bodyContent = null;
69   private String JavaDoc _dynamicAttributes = null;
70   
71   private ArrayList JavaDoc<TldAttribute> _attributes = new ArrayList JavaDoc<TldAttribute>();
72   private ArrayList JavaDoc<TldVariable> _variables = new ArrayList JavaDoc<TldVariable>();
73
74   public JavaTagGenerator(ParseTagManager tagManager)
75   {
76     super(tagManager);
77
78     setOmitXmlDeclaration(true);
79   }
80
81   public void init()
82   {
83     super.init();
84     
85     setOmitXmlDeclaration(true);
86   }
87
88   /**
89    * Returns true if the XML declaration should be ignored.
90    */

91   /*
92   boolean isOmitXmlDeclaration()
93   {
94     // tags always omit the declaration
95     return true;
96   }
97   */

98
99   public void setDescription(String JavaDoc description)
100   {
101     _description = description;
102   }
103
104   public String JavaDoc getDescription()
105   {
106     return _description;
107   }
108
109   public void setDisplayName(String JavaDoc displayName)
110   {
111     _displayName = displayName;
112   }
113
114   public String JavaDoc getDisplayName()
115   {
116     return _displayName;
117   }
118
119   public void setSmallIcon(String JavaDoc smallIcon)
120   {
121     _smallIcon = smallIcon;
122   }
123
124   public String JavaDoc getSmallIcon()
125   {
126     return _smallIcon;
127   }
128
129   public void setLargeIcon(String JavaDoc largeIcon)
130   {
131     _largeIcon = largeIcon;
132   }
133
134   public String JavaDoc getLargeIcon()
135   {
136     return _largeIcon;
137   }
138
139   public void setExample(String JavaDoc example)
140   {
141     _example = example;
142   }
143
144   public String JavaDoc getExample()
145   {
146     return _example;
147   }
148
149   /**
150    * Sets the body content.
151    */

152   public void setBodyContent(String JavaDoc bodyContent)
153   {
154     _bodyContent = bodyContent;
155   }
156
157   /**
158    * Gets the body content.
159    */

160   public String JavaDoc getBodyContent()
161   {
162     return _bodyContent;
163   }
164
165   /**
166    * Sets the name of the dynamic attributes map
167    */

168   public void setDynamicAttributes(String JavaDoc dynamicAttributes)
169   {
170     _dynamicAttributes = dynamicAttributes;
171   }
172
173   /**
174    * Gets the body content.
175    */

176   public String JavaDoc getDynamicAttributes()
177   {
178     return _dynamicAttributes;
179   }
180
181   /**
182    * Adds an attribute.
183    */

184   public void addAttribute(TldAttribute attribute)
185   {
186     _attributes.add(attribute);
187   }
188
189   /**
190    * Returns the attributes.
191    */

192   public ArrayList JavaDoc<TldAttribute> getAttributes()
193   {
194     return _attributes;
195   }
196
197   /**
198    * Finds an attribute.
199    */

200   public TldAttribute findAttribute(String JavaDoc name)
201   {
202     for (int i = 0; i < _attributes.size(); i++) {
203       TldAttribute attr = _attributes.get(i);
204
205       if (name.equals(attr.getName()))
206     return attr;
207     }
208
209     return null;
210   }
211
212   /**
213    * Adds a variable.
214    */

215   public void addVariable(TldVariable var)
216   {
217     _variables.add(var);
218   }
219
220   /**
221    * Finds a variable.
222    */

223   public TldVariable findVariable(String JavaDoc name)
224   {
225     for (int i = 0; i < _variables.size(); i++) {
226       TldVariable var = _variables.get(i);
227
228       // jsp/1071
229
if (name.equals(var.getNameGiven())
230       || name.equals(var.getAlias()))
231     return var;
232     }
233
234     return null;
235   }
236
237   /**
238    * Returns the variables.
239    */

240   public ArrayList JavaDoc<TldVariable> getVariables()
241   {
242     return _variables;
243   }
244
245   public boolean isTag()
246   {
247     return true;
248   }
249
250   /**
251    * Returns true for XML.
252    */

253   boolean isXml()
254   {
255     return _parseState.isXml();
256   }
257
258   /**
259    * Generates the Java code.
260    */

261   protected void generate(JspJavaWriter out)
262     throws Exception JavaDoc
263   {
264     out.setLineMap(_lineMap);
265     
266     generateClassHeader(out);
267
268     generateAttributes(out);
269
270     if (_dynamicAttributes != null)
271       generateDynamicAttributes(out);
272
273     generateDoTag(out, _rootNode);
274
275     if (isStaticDoTag())
276       generateStaticDoTag(out, _rootNode);
277
278     generateTagInfo(out);
279     
280     generateClassFooter(out);
281   }
282
283   protected boolean isStaticDoTag()
284   {
285     return ! hasScripting();
286   }
287
288   /**
289    * Generates the class header.
290    *
291    * @param doc the XML document representing the JSP page.
292    */

293   protected void generateClassHeader(JspJavaWriter out)
294     throws IOException JavaDoc, JspParseException
295   {
296     out.println("/*");
297     out.println(" * JSP-Tag generated by " + com.caucho.Version.FULL_VERSION);
298     out.println(" */" );
299     out.println();
300
301     if (_pkg != null && ! _pkg.equals(""))
302       out.println("package " + _pkg + ";");
303
304     out.println("import javax.servlet.*;");
305     out.println("import javax.servlet.jsp.*;");
306     out.println("import javax.servlet.http.*;");
307
308     fillSingleTaglibImports();
309
310     ArrayList JavaDoc<String JavaDoc> imports = _parseState.getImportList();
311     for (int i = 0; i < imports.size(); i++) {
312       String JavaDoc name = imports.get(i);
313       out.print("import ");
314       out.print(name);
315       out.println(";");
316     }
317     _parseState.addImport("javax.servlet.*");
318     _parseState.addImport("javax.servlet.jsp.*");
319     _parseState.addImport("javax.servlet.http.*");
320     _parseState.addImport("java.lang.*");
321     out.println();
322
323     out.print("public class ");
324     out.print(_className);
325
326     if (hasScripting())
327       out.print(" extends com.caucho.jsp.java.JspTagSupport");
328     else
329       out.print(" extends com.caucho.jsp.java.JspTagFileSupport");
330
331     if (_dynamicAttributes != null)
332       out.print(" implements javax.servlet.jsp.tagext.DynamicAttributes");
333
334     out.println(" {");
335     out.pushDepth();
336
337     out.println("private final java.util.HashMap<String,java.lang.reflect.Method> _jsp_functionMap = new java.util.HashMap<String,java.lang.reflect.Method>();");
338
339     out.println("private boolean _caucho_isDead;");
340
341     for (int i = 0; i < _declarations.size(); i++) {
342       JspDeclaration decl = _declarations.get(i);
343
344       out.println();
345       decl.generateDeclaration(out);
346     }
347   }
348
349   /**
350    * Generates the attribute definitions.
351    *
352    * @param out the writer to the .java source
353    */

354   protected void generateAttributes(JspJavaWriter out)
355     throws IOException JavaDoc, JspParseException
356   {
357     for (int i = 0; i < _attributes.size(); i++) {
358       TldAttribute attr = _attributes.get(i);
359
360       String JavaDoc name = attr.getName();
361
362       String JavaDoc upperName;
363       char ch = name.charAt(0);
364       upperName = Character.toUpperCase(ch) + name.substring(1);
365
366       Class JavaDoc cl = attr.getType();
367       if (cl == null)
368         cl = String JavaDoc.class;
369       String JavaDoc type = cl.getName();
370
371       String JavaDoc isSetName = "_jsp_" + name + "_isSet";
372
373       String JavaDoc fieldName = toFieldName(name);
374
375       out.println();
376       out.print("private ");
377       out.printClass(cl);
378       out.println(" " + fieldName + ";");
379       out.println("private boolean " + isSetName + ";");
380       
381       out.println();
382       out.print("public void set" + upperName + "(");
383       out.printClass(cl);
384       out.println(" value)");
385       out.println("{");
386       out.pushDepth();
387       out.println("this." + isSetName + " = true;");
388       out.println("this." + fieldName + " = value;");
389       out.popDepth();
390       out.println("}");
391
392       /*
393       // jsp/101f
394       out.println();
395       out.println("public " + type + " get" + upperName + "()");
396       out.println("{");
397       out.pushDepth();
398       out.println("return " + fieldName + ";");
399       out.popDepth();
400       out.println("}");
401       */

402     }
403   }
404
405   /**
406    * Generates the attribute definitions.
407    *
408    * @param out the writer to the .java source
409    */

410   protected void generateDynamicAttributes(JspJavaWriter out)
411     throws IOException JavaDoc, JspParseException
412   {
413     String JavaDoc dyn = toFieldName(_dynamicAttributes);
414
415     out.println();
416     out.println("java.util.HashMap " + dyn + " = new java.util.HashMap();");
417     out.println();
418     out.println("public void setDynamicAttribute(String uri, String localName, Object value)");
419     out.println(" throws javax.servlet.jsp.JspException");
420     out.println("{");
421     out.println(" if (uri == null || \"\".equals(uri))");
422     out.println(" " + dyn + ".put(localName, value);");
423     out.println("}");
424   }
425
426   /**
427    * Prints the _jspService header
428    */

429   protected void generateDoTag(JspJavaWriter out, JspNode node)
430     throws Exception JavaDoc
431   {
432     out.println();
433     out.println("public void doTag()");
434     out.println(" throws javax.servlet.jsp.JspException, java.io.IOException");
435     out.println("{");
436     out.pushDepth();
437
438     out.println("javax.servlet.jsp.JspContext _jsp_parentContext = getJspContext();");
439     out.println("com.caucho.jsp.PageContextWrapper pageContext = com.caucho.jsp.PageContextWrapper.create(_jsp_parentContext);");
440     // jsp/1056
441
out.println("setJspContext(pageContext);");
442
443     if (hasScripting()) {
444       out.println("javax.servlet.http.HttpServletRequest request = (javax.servlet.http.HttpServletRequest) pageContext.getRequest();");
445       out.println("javax.servlet.http.HttpServletResponse response = (javax.servlet.http.HttpServletResponse) pageContext.getResponse();");
446       out.println("javax.servlet.http.HttpSession session = pageContext.getSession();");
447       out.println("javax.servlet.ServletContext application = pageContext.getServletContext();");
448       out.println("javax.servlet.ServletConfig config = pageContext.getServletConfig();");
449     }
450     
451     out.println("com.caucho.jsp.PageContextWrapper jspContext = pageContext;");
452     out.println("javax.el.ELContext _jsp_env = pageContext.getELContext();");
453     out.println("javax.servlet.jsp.JspWriter out = pageContext.getOut();");
454     generateTagAttributes(out);
455     if (hasScripting())
456       generatePrologue(out);
457
458     out.println("try {");
459     out.pushDepth();
460      
461     if (hasScripting()) {
462       node.generate(out);
463       
464       generateTagVariablesAtEnd(out);
465     } else {
466       out.println("doTag(_jsp_parentContext, pageContext, out, null);");
467     }
468     
469     out.popDepth();
470     out.println("} catch (Throwable e) {");
471     out.println(" if (e instanceof java.io.IOException)");
472     out.println(" throw (java.io.IOException) e;");
473     out.println(" throw com.caucho.jsp.QJspException.createJspException(e);");
474     out.println("}");
475
476     if (hasScripting() && _variables.size() > 0) {
477       out.println("finally {");
478       out.pushDepth();
479       
480       generateTagVariablesAtEnd(out);
481       
482       out.println("setJspContext(_jsp_parentContext);");
483       out.println("com.caucho.jsp.PageContextWrapper.free(pageContext);");
484       
485       out.popDepth();
486       out.println("}");
487     }
488   
489     out.popDepth();
490     out.println("}");
491   }
492
493   /**
494    * Generates the attribute definitions.
495    *
496    * @param out the writer to the .java source
497    */

498   protected void generateTagAttributes(JspJavaWriter out)
499     throws IOException JavaDoc, JspParseException
500   {
501     for (int i = 0; i < _attributes.size(); i++) {
502       TldAttribute attr = _attributes.get(i);
503
504       String JavaDoc name = attr.getName();
505
506       String JavaDoc upperName;
507       char ch = name.charAt(0);
508       upperName = Character.toUpperCase(ch) + name.substring(1);
509
510       Class JavaDoc cl = attr.getType();
511       if (cl == null)
512         cl = String JavaDoc.class;
513       String JavaDoc type = cl.getName();
514
515       String JavaDoc isSetName = "_jsp_" + name + "_isSet";
516       String JavaDoc fieldName = toFieldName(name);
517       
518       out.println("if (" + isSetName + ")");
519       out.println(" pageContext.setAttribute(\"" + name + "\", " +
520                   JspNode.toELObject(fieldName, cl) + ");");
521     }
522
523     // jsp/10a1
524
if (_dynamicAttributes != null) {
525       out.println("pageContext.setAttribute(\"" + _dynamicAttributes + "\"," +
526           toFieldName(_dynamicAttributes) + ");");
527     }
528   }
529
530   /**
531    * Prints the _jspService header
532    */

533   protected void generateStaticDoTag(JspJavaWriter out, JspNode node)
534     throws Exception JavaDoc
535   {
536     out.println();
537     out.println("public static void doTag(javax.servlet.jsp.JspContext _jsp_parentContext,");
538     out.println(" com.caucho.jsp.PageContextWrapper pageContext,");
539     out.println(" javax.servlet.jsp.JspWriter out,");
540     out.println(" javax.servlet.jsp.tagext.JspFragment _jspBody)");
541     out.println(" throws Throwable");
542     out.println("{");
543     out.pushDepth();
544
545     out.println("javax.el.ELContext _jsp_env = pageContext.getELContext();");
546     generatePrologue(out);
547
548     out.println("try {");
549     out.pushDepth();
550     
551     node.generate(out);
552
553     out.popDepth();
554     out.println("} finally {");
555     out.pushDepth();
556       
557     generateTagVariablesAtEnd(out);
558       
559     out.println("com.caucho.jsp.PageContextWrapper.free(pageContext);");
560       
561     out.popDepth();
562     out.println("}");
563
564     out.popDepth();
565     out.println("}");
566   }
567
568   /**
569    * Generates prologue stuff
570    *
571    * @param out the writer to the .java source
572    */

573   protected void generatePrologue(JspJavaWriter out)
574     throws Exception JavaDoc
575   {
576     _rootNode.generatePrologue(out);
577     
578     for (int i = 0; i < _variables.size(); i++) {
579       TldVariable var = _variables.get(i);
580
581       if (var.getNameFromAttribute() != null) {
582     out.print("String _jsp_var_from_attribute_" + i + " = (String) ");
583     out.println("pageContext.getAttribute(\"" +
584             var.getNameFromAttribute() + "\");");
585       }
586       
587       if ("AT_END".equals(var.getScope()))
588     continue;
589
590       String JavaDoc srcName = var.getNameGiven();
591       if (srcName == null)
592     srcName = var.getAlias();
593       
594       String JavaDoc dstName;
595       if (var.getNameGiven() != null)
596     dstName = "\"" + var.getNameGiven() + "\"";
597       else
598     dstName = "_jsp_var_from_attribute_" + i;
599
600       if ("NESTED".equals(var.getScope())) {
601     out.print("Object _jsp_nested_var_" + i + " = ");
602     out.println("_jsp_parentContext.getAttribute(" + dstName + ");");
603       }
604       /*
605       else {
606     out.print("pageContext.setAttribute(\"" + srcName + "\",");
607     out.println("_jsp_parentContext.getAttribute(" + dstName + "));");
608       }
609       */

610     }
611   }
612
613   /**
614    * Generates the variable setting.
615    *
616    * @param out the writer to the .java source
617    */

618   protected void generateTagVariablesAtEnd(JspJavaWriter out)
619     throws IOException JavaDoc, JspParseException
620   {
621     for (int i = 0; i < _variables.size(); i++) {
622       TldVariable var = _variables.get(i);
623       
624       String JavaDoc srcName = var.getNameGiven();
625       if (srcName == null)
626     srcName = var.getAlias();
627       
628       String JavaDoc dstName;
629       if (var.getNameGiven() != null)
630     dstName = "\"" + var.getNameGiven() + "\"";
631       else
632     dstName = "_jsp_var_from_attribute_" + i;
633
634       if ("NESTED".equals(var.getScope())) {
635     out.println("_jsp_parentContext.setAttribute(" + dstName + ", _jsp_nested_var_" + i + ");");
636       }
637       else {
638     out.print("_jsp_parentContext.setAttribute(" + dstName + ",");
639     out.println("pageContext.getAttribute(\"" + srcName + "\"));");
640       }
641     }
642   }
643
644   public TagInfo JavaDoc generateTagInfo(String JavaDoc className, TagLibraryInfo JavaDoc taglib)
645   {
646     init(className);
647     
648     TldTag tag = new TldTag();
649     
650     for (int i = 0; i < _attributes.size(); i++) {
651       TldAttribute attr = _attributes.get(i);
652
653       tag.addAttribute(attr);
654     }
655     
656     for (int i = 0; i < _variables.size(); i++) {
657       TldVariable var = _variables.get(i);
658
659       try {
660     tag.addVariable(var);
661       } catch (Exception JavaDoc e) {
662     log.log(Level.WARNING, e.toString(), e);
663       }
664     }
665     
666     String JavaDoc bodyContent = _bodyContent;
667     if (bodyContent == null)
668       bodyContent = "scriptless";
669     
670     return new TagInfoExt(tag.getName(),
671               _fullClassName,
672               bodyContent,
673               getDescription(),
674               taglib,
675               null,
676               tag.getAttributes(),
677               getDisplayName(),
678               getSmallIcon(),
679               getLargeIcon(),
680               tag.getVariables(),
681               _dynamicAttributes != null,
682               _dynamicAttributes,
683               null);
684   }
685   
686   /**
687    * Generates the attribute definitions.
688    *
689    * @param out the writer to the .java source
690    */

691   protected void generateTagInfo(JspJavaWriter out)
692     throws IOException JavaDoc, JspParseException
693   {
694     /*
695     out.println();
696     out.println("public javax.servlet.jsp.tagext.TagInfo _caucho_getTagInfo()");
697     out.println(" throws com.caucho.config.ConfigException");
698     out.println("{");
699     out.pushDepth();
700     out.println(" return _caucho_getTagInfo(_caucho_getTagLibrary());");
701     out.popDepth();
702     out.println("}");
703     */

704     
705     out.println();
706     out.println("public javax.servlet.jsp.tagext.TagInfo _caucho_getTagInfo(javax.servlet.jsp.tagext.TagLibraryInfo taglib)");
707     out.println(" throws com.caucho.config.ConfigException");
708     out.println("{");
709     out.pushDepth();
710     out.println("com.caucho.jsp.cfg.TldTag tag = new com.caucho.jsp.cfg.TldTag();");
711
712     out.println("tag.setName(\"test\");");
713
714     out.println("com.caucho.jsp.cfg.TldAttribute attr;");
715     for (int i = 0; i < _attributes.size(); i++) {
716       TldAttribute attr = _attributes.get(i);
717
718       out.println("attr = new com.caucho.jsp.cfg.TldAttribute();");
719       out.println("attr.setName(\"" + attr.getName() + "\");");
720
721       Class JavaDoc type = attr.getType();
722       if (type != null) {
723         out.print("attr.setType(");
724     out.printClass(type);
725     out.println(".class);");
726       }
727       out.println("attr.setRtexprvalue(" + attr.getRtexprvalue() + ");");
728       out.println("attr.setRequired(" + attr.getRequired() + ");");
729
730       if (attr.getDeferredValue() != null) {
731     out.println("attr.setDeferredValue(new com.caucho.jsp.cfg.TldAttribute.DeferredValue());");
732
733     if (attr.getDeferredValue().getType() != null) {
734       out.print("attr.getDeferredValue().setType(\"");
735       out.printJavaString(attr.getDeferredValue().getType());
736       out.println("\");");
737     }
738       }
739
740       if (attr.getDeferredMethod() != null) {
741     out.println("attr.setDeferredMethod(new com.caucho.jsp.cfg.TldAttribute.DeferredMethod());");
742
743     Signature sig = attr.getDeferredMethod().getMethodSignature();
744     
745     if (sig != null) {
746       out.print("attr.getDeferredMethod().setMethodSignature(");
747       out.print("new com.caucho.config.types.Signature(\"");
748       out.printJavaString(sig.getSignature());
749       out.println("\"));");
750     }
751       }
752
753       out.println("tag.addAttribute(attr);");
754     }
755
756     out.println("com.caucho.jsp.cfg.TldVariable var;");
757     for (int i = 0; i < _variables.size(); i++) {
758       TldVariable var = _variables.get(i);
759
760       out.println("var = new com.caucho.jsp.cfg.TldVariable();");
761
762       if (var.getNameGiven() != null)
763     out.println("var.setNameGiven(\"" + var.getNameGiven() + "\");");
764       
765       if (var.getNameFromAttribute() != null)
766     out.println("var.setNameFromAttribute(\"" + var.getNameFromAttribute() + "\");");
767
768       String JavaDoc type = var.getVariableClass();
769       if (type != null)
770         out.println("var.setVariableClass(\"" + type + "\");");
771       out.println("var.setDeclare(" + var.getDeclare() + ");");
772       if (var.getScope() != null)
773     out.println("var.setScope(\"" + var.getScope() + "\");");
774
775       out.println("tag.addVariable(var);");
776     }
777     
778     String JavaDoc bodyContent = _bodyContent;
779     if (bodyContent == null)
780       bodyContent = "scriptless";
781
782     out.println("return new com.caucho.jsp.java.TagInfoExt(tag.getName(),");
783     out.println(" getClass().getName(),");
784     out.println(" \"" + bodyContent + "\",");
785     out.print(" \"");
786     if (_description != null)
787       out.printJavaString(_description);
788     else
789       out.printJavaString("A simple tag");
790     out.println("\",");
791     out.println(" taglib,");
792     out.println(" null,");
793     out.println(" tag.getAttributes(),");
794     
795     if (_displayName != null) {
796       out.print(" \"");
797       out.printJavaString(_displayName);
798       out.println("\",");
799     }
800     else {
801       out.println(" null,");
802     }
803     
804     if (_smallIcon != null) {
805       out.print(" \"");
806       out.printJavaString(_smallIcon);
807       out.println("\",");
808     }
809     else {
810       out.println(" null,");
811     }
812     
813     if (_largeIcon != null) {
814       out.print(" \"");
815       out.printJavaString(_largeIcon);
816       out.println("\",");
817     }
818     else {
819       out.println(" null,");
820     }
821     
822     out.println(" tag.getVariables(),");
823     out.println(" " + (_dynamicAttributes != null) + ",");
824     if (_dynamicAttributes != null)
825       out.println(" \"" + _dynamicAttributes + "\",");
826     else
827       out.println(" null,");
828     out.println(" _caucho_depends);");
829
830     out.popDepth();
831     out.println("}");
832     
833     out.println();
834     out.println("public String _caucho_getDynamicAttributes()");
835     out.println("{");
836     out.pushDepth();
837
838     if (_dynamicAttributes != null)
839       out.println("return \"" + _dynamicAttributes + "\";");
840     else
841       out.println("return null;");
842     
843     out.popDepth();
844     out.println("}");
845
846     generateTagLibrary(out);
847   }
848   
849   /**
850    * Generates the attribute definitions.
851    *
852    * @param out the writer to the .java source
853    */

854   protected void generateTagLibrary(JspJavaWriter out)
855     throws IOException JavaDoc, JspParseException
856   {
857     out.println();
858     out.println("private javax.servlet.jsp.tagext.TagLibraryInfo _caucho_getTagLibrary()");
859     out.println(" throws com.caucho.config.ConfigException");
860     out.println("{");
861     out.pushDepth();
862
863     out.println("return new com.caucho.jsp.java.TagTaglib(\"x\", \"http://test.com\");");
864     out.popDepth();
865     out.println("}");
866   }
867
868   private String JavaDoc toFieldName(String JavaDoc name)
869   {
870     if (hasScripting() && ! _reserved.contains(name))
871       return name;
872     else
873       return "_" + name;
874   }
875
876   static {
877     _reserved.add("public");
878     _reserved.add("private");
879     _reserved.add("protected");
880     _reserved.add("static");
881     _reserved.add("final");
882     _reserved.add("class");
883     _reserved.add("interface");
884     _reserved.add("extends");
885     _reserved.add("implements");
886     _reserved.add("package");
887     _reserved.add("import");
888     _reserved.add("new");
889     _reserved.add("if");
890     _reserved.add("else");
891     _reserved.add("for");
892     _reserved.add("do");
893     _reserved.add("while");
894     _reserved.add("break");
895     _reserved.add("continue");
896     _reserved.add("switch");
897     _reserved.add("case");
898     _reserved.add("default");
899     _reserved.add("throw");
900     _reserved.add("enum");
901     _reserved.add("throws");
902     
903     _reserved.add("void");
904     _reserved.add("boolean");
905     _reserved.add("byte");
906     _reserved.add("char");
907     _reserved.add("short");
908     _reserved.add("int");
909     _reserved.add("long");
910     _reserved.add("float");
911     _reserved.add("double");
912   }
913 }
914
Popular Tags