KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > web > jsps > parserapi > PageInfo


1 /*
2  * The contents of this file are subject to the terms of the Common Development
3  * and Distribution License (the License). You may not use this file except in
4  * compliance with the License.
5  *
6  * You can obtain a copy of the License at http://www.netbeans.org/cddl.html
7  * or http://www.netbeans.org/cddl.txt.
8  *
9  * When distributing Covered Code, include this CDDL Header Notice in each file
10  * and include the License file at http://www.netbeans.org/cddl.txt.
11  * If applicable, add the following below the CDDL Header, with the fields
12  * enclosed by brackets [] replaced by your own identifying information:
13  * "Portions Copyrighted [year] [name of copyright owner]"
14  *
15  * The Original Software is NetBeans. The Initial Developer of the Original
16  * Software is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun
17  * Microsystems, Inc. All Rights Reserved.
18  */

19
20 package org.netbeans.modules.web.jsps.parserapi;
21
22 import java.util.*;
23
24 import org.openide.ErrorManager;
25
26 //import org.apache.jasper.Constants;
27
import javax.servlet.jsp.JspException JavaDoc;
28 import javax.servlet.jsp.PageContext JavaDoc;
29 import javax.servlet.jsp.el.FunctionMapper JavaDoc;
30 import javax.servlet.jsp.tagext.TagInfo JavaDoc;
31 import javax.servlet.jsp.tagext.TagFileInfo JavaDoc;
32 import javax.servlet.jsp.tagext.FunctionInfo JavaDoc;
33 import javax.servlet.jsp.tagext.TagAttributeInfo JavaDoc;
34 import javax.servlet.jsp.tagext.TagLibraryInfo JavaDoc;
35
36 /**
37  * A repository for various info about the translation unit under compilation.
38  *
39  * @author Kin-man Chung, Petr Jiricka
40  */

41
42 public abstract class PageInfo {
43
44     public static final String JavaDoc JSP_SERVLET_BASE = "org.apache.jasper.runtime.HttpJspBase";
45     
46     private List<String JavaDoc> imports;
47     private List<String JavaDoc> dependants;
48
49 // private BeanRepository beanRepository;
50
private BeanData[] beans;
51     private Map<String JavaDoc, TagLibraryInfo JavaDoc> taglibsMap;
52     private Map<String JavaDoc, String JavaDoc> jspPrefixMapper;
53     private Map<String JavaDoc, LinkedList<String JavaDoc>> xmlPrefixMapper;
54     /** Approximate XML prefix mapper. Same as xmlPrefixMapper, but does not "forget" mappings (by popping them). */
55     private Map approxXmlPrefixMapper;
56     private String JavaDoc defaultLanguage = "java";
57     private String JavaDoc language;
58     private String JavaDoc defaultExtends = JSP_SERVLET_BASE;
59     private String JavaDoc xtends;
60     private String JavaDoc contentType = null;
61     private String JavaDoc session;
62     private boolean isSession = true;
63     private String JavaDoc bufferValue;
64     private int buffer = 8*1024; // XXX confirm
65
private String JavaDoc autoFlush;
66     private boolean isAutoFlush = true;
67     private String JavaDoc isThreadSafeValue;
68     private boolean isThreadSafe = true;
69     private String JavaDoc isErrorPageValue;
70     private boolean isErrorPage = false;
71     private String JavaDoc errorPage = null;
72     private String JavaDoc info;
73
74     private boolean scriptless = false;
75     private boolean scriptingInvalid = false;
76     private String JavaDoc isELIgnoredValue;
77     private boolean isELIgnored = false;
78     private String JavaDoc omitXmlDecl = null;
79
80     private String JavaDoc doctypeName = null;
81     private String JavaDoc doctypePublic = null;
82     private String JavaDoc doctypeSystem = null;
83  
84     private boolean isJspPrefixHijacked;
85
86     // Set of all element and attribute prefixes used in this translation unit
87
private Set<String JavaDoc> prefixes;
88
89     private boolean hasJspRoot = false;
90     private List includePrelude;
91     private List includeCoda;
92     private List<String JavaDoc> pluginDcls; // Id's for tagplugin declarations
93

94
95     public PageInfo(/*BeanRepository beanRepository*/
96             Map<String JavaDoc, TagLibraryInfo JavaDoc> taglibsMap,
97             Map<String JavaDoc, String JavaDoc> jspPrefixMapper,
98             Map<String JavaDoc, LinkedList<String JavaDoc>> xmlPrefixMapper,
99             Map approxXmlPrefixMapper,
100             List<String JavaDoc> imports,
101             List<String JavaDoc> dependants,
102             List includePrelude,
103             List includeCoda,
104             List<String JavaDoc> pluginDcls,
105             Set<String JavaDoc> prefixes
106         ) {
107     //this.beanRepository = beanRepository;
108
this.taglibsMap = taglibsMap;
109     this.jspPrefixMapper = jspPrefixMapper;
110     this.xmlPrefixMapper = xmlPrefixMapper;
111         this.approxXmlPrefixMapper = approxXmlPrefixMapper;
112     this.imports = imports;
113         this.dependants = dependants;
114     this.includePrelude = includePrelude;
115     this.includeCoda = includeCoda;
116     this.pluginDcls = pluginDcls;
117     this.prefixes = prefixes;
118     }
119
120     /**
121      * Check if the plugin ID has been previously declared. Make a not
122      * that this Id is now declared.
123      * @return true if Id has been declared.
124      */

125     public boolean isPluginDeclared(String JavaDoc id) {
126     if (pluginDcls.contains(id))
127         return true;
128     pluginDcls.add(id);
129     return false;
130     }
131
132     public void addImports(List<String JavaDoc> imports) {
133     this.imports.addAll(imports);
134     }
135
136     public void addImport(String JavaDoc imp) {
137     this.imports.add(imp);
138     }
139
140     public List<String JavaDoc> getImports() {
141     return imports;
142     }
143
144     public void addDependant(String JavaDoc d) {
145     if (!dependants.contains(d))
146             dependants.add(d);
147     }
148      
149     public List<String JavaDoc> getDependants() {
150         return dependants;
151     }
152
153     public void setScriptless(boolean s) {
154     scriptless = s;
155     }
156
157     public boolean isScriptless() {
158     return scriptless;
159     }
160
161     public void setScriptingInvalid(boolean s) {
162     scriptingInvalid = s;
163     }
164
165     public boolean isScriptingInvalid() {
166     return scriptingInvalid;
167     }
168
169     public List getIncludePrelude() {
170     return includePrelude;
171     }
172
173     public void setIncludePrelude(Vector prelude) {
174     includePrelude = prelude;
175     }
176
177     public List getIncludeCoda() {
178     return includeCoda;
179     }
180
181     public void setIncludeCoda(Vector coda) {
182     includeCoda = coda;
183     }
184
185     public void setHasJspRoot(boolean s) {
186     hasJspRoot = s;
187     }
188
189     public boolean hasJspRoot() {
190     return hasJspRoot;
191     }
192
193     public String JavaDoc getOmitXmlDecl() {
194     return omitXmlDecl;
195     }
196
197     public void setOmitXmlDecl(String JavaDoc omit) {
198     omitXmlDecl = omit;
199     }
200
201     public String JavaDoc getDoctypeName() {
202         return doctypeName;
203     }
204
205     public void setDoctypeName(String JavaDoc doctypeName) {
206         this.doctypeName = doctypeName;
207     }
208
209     public String JavaDoc getDoctypeSystem() {
210         return doctypeSystem;
211     }
212
213     public void setDoctypeSystem(String JavaDoc doctypeSystem) {
214         this.doctypeSystem = doctypeSystem;
215     }
216
217     public String JavaDoc getDoctypePublic() {
218         return doctypePublic;
219     }
220
221     public void setDoctypePublic(String JavaDoc doctypePublic) {
222         this.doctypePublic = doctypePublic;
223     }
224
225     /* Tag library and XML namespace management methods */
226
227     public void setIsJspPrefixHijacked(boolean isHijacked) {
228     isJspPrefixHijacked = isHijacked;
229     }
230
231     public boolean isJspPrefixHijacked() {
232     return isJspPrefixHijacked;
233     }
234
235     /*
236      * Adds the given prefix to the set of prefixes of this translation unit.
237      *
238      * @param prefix The prefix to add
239      */

240     public void addPrefix(String JavaDoc prefix) {
241     prefixes.add(prefix);
242     }
243
244     /*
245      * Checks to see if this translation unit contains the given prefix.
246      *
247      * @param prefix The prefix to check
248      *
249      * @return true if this translation unit contains the given prefix, false
250      * otherwise
251      */

252     public boolean containsPrefix(String JavaDoc prefix) {
253     return prefixes.contains(prefix);
254     }
255
256     /*
257      * Maps the given URI to the given tag library.
258      *
259      * @param uri The URI to map
260      * @param info The tag library to be associated with the given URI
261      */

262     public void addTaglib(String JavaDoc uri, TagLibraryInfo JavaDoc info) {
263     taglibsMap.put(uri, info);
264     }
265
266     /*
267      * Gets the tag library corresponding to the given URI.
268      *
269      * @return Tag library corresponding to the given URI
270      */

271     public TagLibraryInfo JavaDoc getTaglib(String JavaDoc uri) {
272     return taglibsMap.get(uri);
273     }
274
275     /*
276      * Gets the collection of tag libraries that are associated with a URI
277      *
278      * @return Collection of tag libraries that are associated with a URI
279      */

280     public Collection<TagLibraryInfo JavaDoc> getTaglibs() {
281     return taglibsMap.values();
282     }
283
284     /*
285      * Checks to see if the given URI is mapped to a tag library.
286      *
287      * @param uri The URI to map
288      *
289      * @return true if the given URI is mapped to a tag library, false
290      * otherwise
291      */

292     public boolean hasTaglib(String JavaDoc uri) {
293     return taglibsMap.containsKey(uri);
294     }
295
296     /*
297      * Maps the given prefix to the given URI.
298      *
299      * @param prefix The prefix to map
300      * @param uri The URI to be associated with the given prefix
301      */

302     public void addPrefixMapping(String JavaDoc prefix, String JavaDoc uri) {
303     jspPrefixMapper.put(prefix, uri);
304     }
305
306     /*
307      * Pushes the given URI onto the stack of URIs to which the given prefix
308      * is mapped.
309      *
310      * @param prefix The prefix whose stack of URIs is to be pushed
311      * @param uri The URI to be pushed onto the stack
312      */

313     public void pushPrefixMapping(String JavaDoc prefix, String JavaDoc uri) {
314     LinkedList<String JavaDoc> stack = xmlPrefixMapper.get(prefix);
315     if (stack == null) {
316         stack = new LinkedList<String JavaDoc>();
317         xmlPrefixMapper.put(prefix, stack);
318     }
319     stack.addFirst(uri);
320     }
321
322     /*
323      * Removes the URI at the top of the stack of URIs to which the given
324      * prefix is mapped.
325      *
326      * @param prefix The prefix whose stack of URIs is to be popped
327      */

328     public void popPrefixMapping(String JavaDoc prefix) {
329     LinkedList<String JavaDoc> stack = xmlPrefixMapper.get(prefix);
330     if (stack == null || stack.size() == 0) {
331         // XXX throw new Exception("XXX");
332
}
333     stack.removeFirst();
334     }
335
336     /*
337      * Returns the URI to which the given prefix maps.
338      *
339      * @param prefix The prefix whose URI is sought
340      *
341      * @return The URI to which the given prefix maps
342      */

343     public String JavaDoc getURI(String JavaDoc prefix) {
344
345     String JavaDoc uri = null;
346
347     LinkedList<String JavaDoc> stack = xmlPrefixMapper.get(prefix);
348     if (stack == null || stack.size() == 0) {
349         uri = jspPrefixMapper.get(prefix);
350     } else {
351         uri = stack.getFirst();
352     }
353
354     return uri;
355     }
356
357
358     /* Page/Tag directive attributes */
359
360     /*
361      * language
362      */

363     public void setLanguage(String JavaDoc value) {
364     language = value;
365     }
366
367     public String JavaDoc getLanguage(boolean useDefault) {
368     return (language == null && useDefault ? defaultLanguage : language);
369     }
370
371     public String JavaDoc getLanguage() {
372     return getLanguage(true);
373     }
374
375
376     /*
377      * extends
378      */

379     public void setExtends(String JavaDoc value) {
380
381     xtends = value;
382
383     /*
384      * If page superclass is top level class (i.e. not in a package)
385      * explicitly import it. If this is not done, the compiler will assume
386      * the extended class is in the same pkg as the generated servlet.
387      */

388     //if (value.indexOf('.') < 0)
389
// n.addImport(value);
390
}
391
392     /**
393      * Gets the value of the 'extends' page directive attribute.
394      *
395      * @param useDefault TRUE if the default
396      * (org.apache.jasper.runtime.HttpJspBase) should be returned if this
397      * attribute has not been set, FALSE otherwise
398      *
399      * @return The value of the 'extends' page directive attribute, or the
400      * default (org.apache.jasper.runtime.HttpJspBase) if this attribute has
401      * not been set and useDefault is TRUE
402      */

403     public String JavaDoc getExtends(boolean useDefault) {
404     return (xtends == null && useDefault ? defaultExtends : xtends);
405     }
406
407     /**
408      * Gets the value of the 'extends' page directive attribute.
409      *
410      * @return The value of the 'extends' page directive attribute, or the
411      * default (org.apache.jasper.runtime.HttpJspBase) if this attribute has
412      * not been set
413      */

414     public String JavaDoc getExtends() {
415     return getExtends(true);
416     }
417
418
419     /*
420      * contentType
421      */

422     public void setContentType(String JavaDoc value) {
423     contentType = value;
424     }
425
426     public String JavaDoc getContentType() {
427     return contentType;
428     }
429
430
431     /*
432      * buffer
433      */

434     public void setBufferValue(String JavaDoc value) throws JspException JavaDoc {
435         if (value == null)
436             return;
437
438     if ("none".equalsIgnoreCase(value))
439         buffer = 0;
440     else {
441         if (value == null || !value.endsWith("kb"))
442         throw new JspException JavaDoc(value);
443         try {
444         Integer JavaDoc k = new Integer JavaDoc(value.substring(0, value.length()-2));
445         buffer = k.intValue() * 1024;
446         } catch (NumberFormatException JavaDoc e) {
447                 throw new JspException JavaDoc(value);
448         }
449     }
450
451     bufferValue = value;
452     }
453
454     public String JavaDoc getBufferValue() {
455     return bufferValue;
456     }
457
458     public int getBuffer() {
459     return buffer;
460     }
461
462
463     /*
464      * session
465      */

466     public void setSession(String JavaDoc value) throws JspException JavaDoc {
467         if (value == null)
468             return;
469
470     if ("true".equalsIgnoreCase(value))
471         isSession = true;
472     else if ("false".equalsIgnoreCase(value))
473         isSession = false;
474     else
475         throw new JspException JavaDoc(value);
476
477     session = value;
478     }
479
480     public String JavaDoc getSession() {
481     return session;
482     }
483
484     public boolean isSession() {
485     return isSession;
486     }
487
488
489     /*
490      * autoFlush
491      */

492     public void setAutoFlush(String JavaDoc value) throws JspException JavaDoc {
493         if (value == null)
494             return;
495
496     if ("true".equalsIgnoreCase(value))
497         isAutoFlush = true;
498     else if ("false".equalsIgnoreCase(value))
499         isAutoFlush = false;
500     else
501         throw new JspException JavaDoc(value);
502
503     autoFlush = value;
504     }
505
506     public String JavaDoc getAutoFlush() {
507     return autoFlush;
508     }
509
510     public boolean isAutoFlush() {
511     return isAutoFlush;
512     }
513
514
515     /*
516      * isThreadSafe
517      */

518     public void setIsThreadSafe(String JavaDoc value) throws JspException JavaDoc {
519         if (value == null)
520             return;
521
522     if ("true".equalsIgnoreCase(value))
523         isThreadSafe = true;
524     else if ("false".equalsIgnoreCase(value))
525         isThreadSafe = false;
526     else
527         throw new JspException JavaDoc(value);
528
529     isThreadSafeValue = value;
530     }
531
532     public String JavaDoc getIsThreadSafe() {
533     return isThreadSafeValue;
534     }
535
536     public boolean isThreadSafe() {
537     return isThreadSafe;
538     }
539
540
541     /*
542      * info
543      */

544     public void setInfo(String JavaDoc value) {
545     info = value;
546     }
547
548     public String JavaDoc getInfo() {
549     return info;
550     }
551
552     
553     /*
554      * errorPage
555      */

556     public void setErrorPage(String JavaDoc value) {
557     errorPage = value;
558     }
559
560     public String JavaDoc getErrorPage() {
561     return errorPage;
562     }
563
564
565     /*
566      * isErrorPage
567      */

568     public void setIsErrorPage(String JavaDoc value) throws JspException JavaDoc {
569         if (value == null)
570             return;
571
572     if ("true".equalsIgnoreCase(value))
573         isErrorPage = true;
574     else if ("false".equalsIgnoreCase(value))
575         isErrorPage = false;
576     else
577         throw new JspException JavaDoc(value);
578
579     isErrorPageValue = value;
580     }
581
582     public String JavaDoc getIsErrorPage() {
583     return isErrorPageValue;
584     }
585
586     public boolean isErrorPage() {
587     return isErrorPage;
588     }
589
590
591     /*
592      * isELIgnored
593      */

594     public void setIsELIgnored(String JavaDoc value) throws JspException JavaDoc {
595         if (value == null)
596             return;
597
598     if ("true".equalsIgnoreCase(value))
599         isELIgnored = true;
600     else if ("false".equalsIgnoreCase(value))
601         isELIgnored = false;
602     else {
603             throw new JspException JavaDoc(value);
604     }
605
606     isELIgnoredValue = value;
607     }
608
609     public void setELIgnored(boolean s) {
610     isELIgnored = s;
611     }
612
613     public String JavaDoc getIsELIgnored() {
614     return isELIgnoredValue;
615     }
616
617     public boolean isELIgnored() {
618     return isELIgnored;
619     }
620     
621     // added in NetBeans
622

623     public Map getTagLibraries() {
624         return taglibsMap;
625     }
626     
627     public Map<String JavaDoc, String JavaDoc> getJspPrefixMapper() {
628         return jspPrefixMapper;
629     }
630     
631     public Map getXMLPrefixMapper() {
632         return xmlPrefixMapper;
633     }
634     
635     public Map getApproxXmlPrefixMapper() {
636         return approxXmlPrefixMapper;
637     }
638     
639     public BeanData[] getBeans() {
640         return beans;
641     }
642
643     public void setBeans(BeanData beans[]) {
644         this.beans = beans;
645     }
646
647     
648     /** Returns the FunctionMapper for a particular prefix.
649      * @param currentPrefix relevant tag library prefix. If the expression to evaluate is
650      * inside an attribute value of a custom tag, then the prefix with which the tag's
651      * tag library is declared, should be passed in. If the expression is plain
652      * JSP text, null should be passed in.
653      * @return FunctionMapper relevant to the given prefix.
654      */

655     //public abstract FunctionMapper getFunctionMapper(String currentPrefix);
656

657     public String JavaDoc toString() {
658         StringBuilder JavaDoc sb = new StringBuilder JavaDoc();
659         String JavaDoc nl = "\n"; // NOI18N
660
String JavaDoc indent = " "; // NOI18N
661
String JavaDoc nlIndent = nl + indent;
662         
663         sb.append("----- PageInfo -----\n"); // NOI18N
664
sb.append(indent).append("imports:\n").append(collectionToString(imports, indent + " ")); // NOI18N
665
sb.append(indent).append("dependants:\n").append(collectionToString(dependants, indent + " ")); // NOI18N
666
sb.append(indent).append("taglibsMap:\n").append(taglibsMapToString(taglibsMap, indent + " ")); // NOI18N
667
sb.append(indent).append("prefixMapper:\n").append(mapToString(jspPrefixMapper, indent + " ")); // NOI18N
668
// PENDING -xmlPrefixMapper
669
// sb.append(indent).append("xmlprefixMapper:\n").append(mapToString(xmlPrefixMapper, indent + " "));
670
sb.append(indent).append("approxXmlPrefixMapper :\n").append(mapToString(approxXmlPrefixMapper, indent + " ")); // NOI18N
671
sb.append(indent).append("language : ").append(language).append('\n'); // NOI18N
672
sb.append(indent).append("xtends : ").append(xtends).append('\n'); // NOI18N
673
sb.append(indent).append("contentType : ").append(contentType).append('\n'); // NOI18N
674
sb.append(indent).append("session : ").append(isSession).append('\n'); // NOI18N
675
sb.append(indent).append("buffer : ").append(buffer).append('\n'); // NOI18N
676
sb.append(indent).append("autoFlush : ").append(isAutoFlush).append('\n'); // NOI18N
677
sb.append(indent).append("threadSafe : ").append(isThreadSafe).append('\n'); // NOI18N
678
sb.append(indent).append("isErrorPage : ").append(isErrorPage).append('\n'); // NOI18N
679
sb.append(indent).append("errorPage : ").append(errorPage).append('\n'); // NOI18N
680
sb.append(indent).append("scriptless : ").append(scriptless).append('\n'); // NOI18N
681
sb.append(indent).append("scriptingInvalid : ").append(scriptingInvalid).append('\n'); // NOI18N
682
sb.append(indent).append("elIgnored : ").append(isELIgnored).append('\n'); // NOI18N
683
sb.append(indent).append("omitXmlDecl : ").append(omitXmlDecl).append('\n'); // NOI18N
684
sb.append(indent).append("isJspPrefixHijacked : ").append(isJspPrefixHijacked).append('\n'); // NOI18N
685
sb.append(indent).append("doctypeName : ").append(doctypeName).append('\n'); // NOI18N
686
sb.append(indent).append("doctypeSystem : ").append(doctypeSystem).append('\n'); // NOI18N
687
sb.append(indent).append("doctypePublic : ").append(doctypePublic).append('\n'); // NOI18N
688
sb.append(indent).append("hasJspRoot : ").append(hasJspRoot).append('\n'); // NOI18N
689
sb.append(indent).append("prefixes:\n").append(collectionToString(prefixes, indent + " ")); // NOI18N
690
sb.append(indent).append("includePrelude:\n").append(collectionToString(includePrelude, indent + " ")); // NOI18N
691
sb.append(indent).append("includeCoda:\n").append(collectionToString(includeCoda, indent + " ")); // NOI18N
692
sb.append(indent).append("pluginDcls:\n").append(collectionToString(pluginDcls, indent + " ")); // NOI18N
693
sb.append(indent).append("beans:\n").append(beansToString(beans, indent + " ")); // NOI18N
694

695         return sb.toString();
696     }
697     
698     private String JavaDoc collectionToString(Collection c, String JavaDoc indent) { // XXX Arrays.toString() can be sufficient
699
StringBuilder JavaDoc sb = new StringBuilder JavaDoc();
700         Iterator it = c.iterator();
701         while (it.hasNext()) {
702             sb.append(indent).append(it.next()).append('\n'); // NOI18N
703
}
704         return sb.toString();
705     }
706     
707     private String JavaDoc taglibsMapToString(Map m, String JavaDoc indent) {
708         StringBuilder JavaDoc sb = new StringBuilder JavaDoc();
709         Iterator it = m.keySet().iterator();
710         while (it.hasNext()) {
711             Object JavaDoc key = it.next();
712             sb.append(indent).append("tag library: ").append(key).append('\n'); // NOI18N
713
sb.append(tagLibraryInfoToString((TagLibraryInfo JavaDoc)m.get(key), indent + " ")); // NOI18N
714
}
715         return sb.toString();
716     }
717     
718     public String JavaDoc tagLibraryInfoToString(TagLibraryInfo JavaDoc info, String JavaDoc indent) {
719         StringBuilder JavaDoc sb = new StringBuilder JavaDoc();
720         sb.append(indent).append("tlibversion : ").append(getFieldByReflection("tlibversion", info)).append('\n'); // NOI18N
721
sb.append(indent).append("jspversion : ").append(info.getRequiredVersion()).append('\n'); // NOI18N
722
sb.append(indent).append("shortname : ").append(info.getShortName()).append('\n'); // NOI18N
723
sb.append(indent).append("urn : ").append(info.getReliableURN()).append('\n'); // NOI18N
724
sb.append(indent).append("info : ").append(info.getInfoString()).append('\n'); // NOI18N
725
sb.append(indent).append("uri : ").append(info.getURI()).append('\n'); // NOI18N
726

727         TagInfo JavaDoc tags[] = info.getTags();
728         if (tags != null) {
729             for (int i = 0; i < tags.length; i++)
730                 sb.append(tagInfoToString(tags[i], indent + " ")); // NOI18N
731
}
732         
733         TagFileInfo JavaDoc tagFiles[] = info.getTagFiles();
734         if (tagFiles != null) {
735             for (int i = 0; i < tagFiles.length; i++)
736                 sb.append(tagFileToString(tagFiles[i], indent + " ")); // NOI18N
737
}
738         
739         FunctionInfo JavaDoc functions[] = info.getFunctions();
740         if (functions != null) {
741             for (int i = 0; i < functions.length; i++)
742                 sb.append(functionInfoToString(functions[i], indent + " ")); // NOI18N
743
}
744         
745         return sb.toString();
746     }
747     
748     public String JavaDoc tagInfoToString(TagInfo JavaDoc tag, String JavaDoc indent) {
749         StringBuilder JavaDoc sb = new StringBuilder JavaDoc();
750         if (tag != null) {
751             sb.append(indent).append("tag name : ").append(tag.getTagName()).append('\n'); // NOI18N
752
sb.append(indent).append(" class : ").append(tag.getTagClassName()).append('\n'); // NOI18N
753
sb.append(indent).append(" attribs : ["); // NOI18N
754
TagAttributeInfo JavaDoc attrs[] = tag.getAttributes();
755             for (int i = 0; i < attrs.length; i++) {
756                 sb.append(attrs[i].getName());
757                 if (i < attrs.length - 1) {
758                     sb.append(", "); // NOI18N
759
}
760             }
761             sb.append("]\n"); // NOI18N
762
}
763         else {
764             sb.append(indent).append("taginfo is null\n"); // NOI18N
765
}
766         return sb.toString();
767     }
768     
769     public String JavaDoc functionInfoToString(FunctionInfo JavaDoc function, String JavaDoc indent) {
770         StringBuilder JavaDoc sb = new StringBuilder JavaDoc();
771         if (function != null) {
772             sb.append(indent).append("function name : ").append(function.getName()).append('\n'); // NOI18N
773
sb.append(indent).append(" class : ").append(function.getFunctionClass()).append('\n'); // NOI18N
774
sb.append(indent).append(" signature: ").append(function.getFunctionSignature()).append('\n'); // NOI18N
775
}
776         else {
777             sb.append(indent).append("functioninfo is null\n"); // NOI18N
778
}
779         return sb.toString();
780     }
781     
782     public String JavaDoc tagFileToString(TagFileInfo JavaDoc tagFile, String JavaDoc indent) {
783         StringBuilder JavaDoc sb = new StringBuilder JavaDoc();
784         sb.append(indent).append("tagfile path : ").append(tagFile.getPath()).append('\n'); // NOI18N
785
sb.append(tagInfoToString(tagFile.getTagInfo(), indent));
786         return sb.toString();
787     }
788     
789     private Object JavaDoc getFieldByReflection(String JavaDoc fieldName, TagLibraryInfo JavaDoc info) {
790         try {
791             java.lang.reflect.Field JavaDoc f = TagLibraryInfo JavaDoc.class.getDeclaredField(fieldName);
792             f.setAccessible(true);
793             return f.get(info);
794         }
795         catch (NoSuchFieldException JavaDoc e) {
796             ErrorManager.getDefault().notify(ErrorManager.INFORMATIONAL, e);
797         }
798         catch (IllegalAccessException JavaDoc e) {
799             ErrorManager.getDefault().notify(ErrorManager.INFORMATIONAL, e);
800         }
801         return null;
802     }
803     
804     private String JavaDoc beansToString(BeanData beans[], String JavaDoc indent) {
805         StringBuilder JavaDoc sb = new StringBuilder JavaDoc();
806         for (int i = 0; i < beans.length; i++) {
807             sb.append(indent).append("bean : ").append(beans[i].getId()).append(", "). // NOI18N
808
append(scopeToString(beans[i].getScope())).append(", "). // NOI18N
809
append(beans[i].getClassName()).append('\n'); // NOI18N
810
}
811         return sb.toString();
812     }
813     
814     private String JavaDoc scopeToString(int scope) {
815         switch (scope) {
816             case PageContext.PAGE_SCOPE : return "PAGE"; // NOI18N
817
case PageContext.SESSION_SCOPE : return "SESSION"; // NOI18N
818
case PageContext.APPLICATION_SCOPE : return "APPLICATION"; // NOI18N
819
case PageContext.REQUEST_SCOPE : return "REQUEST"; // NOI18N
820
}
821         return " !!! ";
822     }
823
824     /** Interface which describes data for beans used by this page. */
825     public interface BeanData {
826
827         /** Identifier of the bean in the page (variable name). */
828         public String JavaDoc getId();
829
830         /** Scope for this bean. Returns constants defined in {@link javax.servlet.jsp.PageContext}. */
831         public int getScope();
832
833         /** Returns the class name for this bean. */
834         public String JavaDoc getClassName();
835
836     } // interface BeanData
837

838     // helper methods for help implement toString()
839
private static String JavaDoc mapToString(Map m, String JavaDoc indent) {
840         StringBuilder JavaDoc sb = new StringBuilder JavaDoc();
841         Iterator it = m.keySet().iterator();
842         while (it.hasNext()) {
843             Object JavaDoc key = it.next();
844             sb.append(indent).append(key).append(" -> ").append(m.get(key)).append('\n');
845         }
846         return sb.toString();
847     }
848     
849 }
850
Popular Tags