KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > jasper > compiler > TagLibraryInfoImpl


1 /*
2  * Licensed to the Apache Software Foundation (ASF) under one or more
3  * contributor license agreements. See the NOTICE file distributed with
4  * this work for additional information regarding copyright ownership.
5  * The ASF licenses this file to You under the Apache License, Version 2.0
6  * (the "License"); you may not use this file except in compliance with
7  * the License. You may obtain a copy of the License at
8  *
9  * http://www.apache.org/licenses/LICENSE-2.0
10  *
11  * Unless required by applicable law or agreed to in writing, software
12  * distributed under the License is distributed on an "AS IS" BASIS,
13  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  * See the License for the specific language governing permissions and
15  * limitations under the License.
16  */

17
18 package org.apache.jasper.compiler;
19
20 import java.io.FileInputStream JavaDoc;
21 import java.io.FileNotFoundException JavaDoc;
22 import java.io.InputStream JavaDoc;
23 import java.io.PrintWriter JavaDoc;
24 import java.io.StringWriter JavaDoc;
25 import java.net.JarURLConnection JavaDoc;
26 import java.net.URL JavaDoc;
27 import java.util.Collection JavaDoc;
28 import java.util.Enumeration JavaDoc;
29 import java.util.Hashtable JavaDoc;
30 import java.util.Iterator JavaDoc;
31 import java.util.Map JavaDoc;
32 import java.util.Vector JavaDoc;
33 import java.util.jar.JarFile JavaDoc;
34 import java.util.zip.ZipEntry JavaDoc;
35
36 import javax.servlet.jsp.tagext.FunctionInfo JavaDoc;
37 import javax.servlet.jsp.tagext.PageData JavaDoc;
38 import javax.servlet.jsp.tagext.TagAttributeInfo JavaDoc;
39 import javax.servlet.jsp.tagext.TagExtraInfo JavaDoc;
40 import javax.servlet.jsp.tagext.TagFileInfo JavaDoc;
41 import javax.servlet.jsp.tagext.TagInfo JavaDoc;
42 import javax.servlet.jsp.tagext.TagLibraryInfo JavaDoc;
43 import javax.servlet.jsp.tagext.TagLibraryValidator JavaDoc;
44 import javax.servlet.jsp.tagext.TagVariableInfo JavaDoc;
45 import javax.servlet.jsp.tagext.ValidationMessage JavaDoc;
46 import javax.servlet.jsp.tagext.VariableInfo JavaDoc;
47
48 import org.apache.commons.logging.Log;
49 import org.apache.commons.logging.LogFactory;
50 import org.apache.jasper.JasperException;
51 import org.apache.jasper.JspCompilationContext;
52 import org.apache.jasper.xmlparser.ParserUtils;
53 import org.apache.jasper.xmlparser.TreeNode;
54
55 /**
56  * Implementation of the TagLibraryInfo class from the JSP spec.
57  *
58  * @author Anil K. Vijendran
59  * @author Mandar Raje
60  * @author Pierre Delisle
61  * @author Kin-man Chung
62  * @author Jan Luehe
63  */

64 class TagLibraryInfoImpl extends TagLibraryInfo JavaDoc implements TagConstants {
65
66     // Logger
67
private Log log = LogFactory.getLog(TagLibraryInfoImpl.class);
68
69     private JspCompilationContext ctxt;
70     
71     private PageInfo pi;
72
73     private ErrorDispatcher err;
74
75     private ParserController parserController;
76
77     private final void print(String JavaDoc name, String JavaDoc value, PrintWriter JavaDoc w) {
78         if (value != null) {
79             w.print(name + " = {\n\t");
80             w.print(value);
81             w.print("\n}\n");
82         }
83     }
84
85     public String JavaDoc toString() {
86         StringWriter JavaDoc sw = new StringWriter JavaDoc();
87         PrintWriter JavaDoc out = new PrintWriter JavaDoc(sw);
88         print("tlibversion", tlibversion, out);
89         print("jspversion", jspversion, out);
90         print("shortname", shortname, out);
91         print("urn", urn, out);
92         print("info", info, out);
93         print("uri", uri, out);
94         print("tagLibraryValidator", "" + tagLibraryValidator, out);
95
96         for (int i = 0; i < tags.length; i++)
97             out.println(tags[i].toString());
98
99         for (int i = 0; i < tagFiles.length; i++)
100             out.println(tagFiles[i].toString());
101
102         for (int i = 0; i < functions.length; i++)
103             out.println(functions[i].toString());
104
105         return sw.toString();
106     }
107
108     // XXX FIXME
109
// resolveRelativeUri and/or getResourceAsStream don't seem to properly
110
// handle relative paths when dealing when home and getDocBase are set
111
// the following is a workaround until these problems are resolved.
112
private InputStream JavaDoc getResourceAsStream(String JavaDoc uri)
113             throws FileNotFoundException JavaDoc {
114         try {
115             // see if file exists on the filesystem first
116
String JavaDoc real = ctxt.getRealPath(uri);
117             if (real == null) {
118                 return ctxt.getResourceAsStream(uri);
119             } else {
120                 return new FileInputStream JavaDoc(real);
121             }
122         } catch (FileNotFoundException JavaDoc ex) {
123             // if file not found on filesystem, get the resource through
124
// the context
125
return ctxt.getResourceAsStream(uri);
126         }
127
128     }
129
130     /**
131      * Constructor.
132      */

133     public TagLibraryInfoImpl(JspCompilationContext ctxt, ParserController pc, PageInfo pi,
134             String JavaDoc prefix, String JavaDoc uriIn, String JavaDoc[] location, ErrorDispatcher err)
135             throws JasperException {
136         super(prefix, uriIn);
137
138         this.ctxt = ctxt;
139         this.parserController = pc;
140         this.pi = pi;
141         this.err = err;
142         InputStream JavaDoc in = null;
143         JarFile JavaDoc jarFile = null;
144
145         if (location == null) {
146             // The URI points to the TLD itself or to a JAR file in which the
147
// TLD is stored
148
location = generateTLDLocation(uri, ctxt);
149         }
150
151         try {
152             if (!location[0].endsWith("jar")) {
153                 // Location points to TLD file
154
try {
155                     in = getResourceAsStream(location[0]);
156                     if (in == null) {
157                         throw new FileNotFoundException JavaDoc(location[0]);
158                     }
159                 } catch (FileNotFoundException JavaDoc ex) {
160                     err.jspError("jsp.error.file.not.found", location[0]);
161                 }
162
163                 parseTLD(ctxt, location[0], in, null);
164                 // Add TLD to dependency list
165
PageInfo pageInfo = ctxt.createCompiler().getPageInfo();
166                 if (pageInfo != null) {
167                     pageInfo.addDependant(location[0]);
168                 }
169             } else {
170                 // Tag library is packaged in JAR file
171
try {
172                     URL JavaDoc jarFileUrl = new URL JavaDoc("jar:" + location[0] + "!/");
173                     JarURLConnection JavaDoc conn = (JarURLConnection JavaDoc) jarFileUrl
174                             .openConnection();
175                     conn.setUseCaches(false);
176                     conn.connect();
177                     jarFile = conn.getJarFile();
178                     ZipEntry JavaDoc jarEntry = jarFile.getEntry(location[1]);
179                     in = jarFile.getInputStream(jarEntry);
180                     parseTLD(ctxt, location[0], in, jarFileUrl);
181                 } catch (Exception JavaDoc ex) {
182                     err.jspError("jsp.error.tld.unable_to_read", location[0],
183                             location[1], ex.toString());
184                 }
185             }
186         } finally {
187             if (in != null) {
188                 try {
189                     in.close();
190                 } catch (Throwable JavaDoc t) {
191                 }
192             }
193             if (jarFile != null) {
194                 try {
195                     jarFile.close();
196                 } catch (Throwable JavaDoc t) {
197                 }
198             }
199         }
200
201     }
202
203     public TagLibraryInfo JavaDoc[] getTagLibraryInfos() {
204         Collection JavaDoc coll = pi.getTaglibs();
205         return (TagLibraryInfo JavaDoc[]) coll.toArray(new TagLibraryInfo JavaDoc[0]);
206     }
207     
208     /*
209      * @param ctxt The JSP compilation context @param uri The TLD's uri @param
210      * in The TLD's input stream @param jarFileUrl The JAR file containing the
211      * TLD, or null if the tag library is not packaged in a JAR
212      */

213     private void parseTLD(JspCompilationContext ctxt, String JavaDoc uri,
214             InputStream JavaDoc in, URL JavaDoc jarFileUrl) throws JasperException {
215         Vector JavaDoc tagVector = new Vector JavaDoc();
216         Vector JavaDoc tagFileVector = new Vector JavaDoc();
217         Hashtable JavaDoc functionTable = new Hashtable JavaDoc();
218
219         // Create an iterator over the child elements of our <taglib> element
220
ParserUtils pu = new ParserUtils();
221         TreeNode tld = pu.parseXMLDocument(uri, in);
222
223         // Check to see if the <taglib> root element contains a 'version'
224
// attribute, which was added in JSP 2.0 to replace the <jsp-version>
225
// subelement
226
this.jspversion = tld.findAttribute("version");
227
228         // Process each child element of our <taglib> element
229
Iterator JavaDoc list = tld.findChildren();
230
231         while (list.hasNext()) {
232             TreeNode element = (TreeNode) list.next();
233             String JavaDoc tname = element.getName();
234
235             if ("tlibversion".equals(tname) // JSP 1.1
236
|| "tlib-version".equals(tname)) { // JSP 1.2
237
this.tlibversion = element.getBody();
238             } else if ("jspversion".equals(tname)
239                     || "jsp-version".equals(tname)) {
240                 this.jspversion = element.getBody();
241             } else if ("shortname".equals(tname) || "short-name".equals(tname))
242                 this.shortname = element.getBody();
243             else if ("uri".equals(tname))
244                 this.urn = element.getBody();
245             else if ("info".equals(tname) || "description".equals(tname))
246                 this.info = element.getBody();
247             else if ("validator".equals(tname))
248                 this.tagLibraryValidator = createValidator(element);
249             else if ("tag".equals(tname))
250                 tagVector.addElement(createTagInfo(element, jspversion));
251             else if ("tag-file".equals(tname)) {
252                 TagFileInfo JavaDoc tagFileInfo = createTagFileInfo(element, uri,
253                         jarFileUrl);
254                 tagFileVector.addElement(tagFileInfo);
255             } else if ("function".equals(tname)) { // JSP2.0
256
FunctionInfo JavaDoc funcInfo = createFunctionInfo(element);
257                 String JavaDoc funcName = funcInfo.getName();
258                 if (functionTable.containsKey(funcName)) {
259                     err.jspError("jsp.error.tld.fn.duplicate.name", funcName,
260                             uri);
261
262                 }
263                 functionTable.put(funcName, funcInfo);
264             } else if ("display-name".equals(tname) || // Ignored elements
265
"small-icon".equals(tname) || "large-icon".equals(tname)
266                     || "listener".equals(tname)) {
267                 ;
268             } else if ("taglib-extension".equals(tname)) {
269                 // Recognized but ignored
270
} else {
271                 if (log.isWarnEnabled()) {
272                     log.warn(Localizer.getMessage(
273                             "jsp.warning.unknown.element.in.taglib", tname));
274                 }
275             }
276
277         }
278
279         if (tlibversion == null) {
280             err.jspError("jsp.error.tld.mandatory.element.missing",
281                     "tlib-version");
282         }
283         if (jspversion == null) {
284             err.jspError("jsp.error.tld.mandatory.element.missing",
285                     "jsp-version");
286         }
287
288         this.tags = new TagInfo JavaDoc[tagVector.size()];
289         tagVector.copyInto(this.tags);
290
291         this.tagFiles = new TagFileInfo JavaDoc[tagFileVector.size()];
292         tagFileVector.copyInto(this.tagFiles);
293
294         this.functions = new FunctionInfo JavaDoc[functionTable.size()];
295         int i = 0;
296         Enumeration JavaDoc enumeration = functionTable.elements();
297         while (enumeration.hasMoreElements()) {
298             this.functions[i++] = (FunctionInfo JavaDoc) enumeration.nextElement();
299         }
300     }
301
302     /*
303      * @param uri The uri of the TLD @param ctxt The compilation context
304      *
305      * @return String array whose first element denotes the path to the TLD. If
306      * the path to the TLD points to a jar file, then the second element denotes
307      * the name of the TLD entry in the jar file, which is hardcoded to
308      * META-INF/taglib.tld.
309      */

310     private String JavaDoc[] generateTLDLocation(String JavaDoc uri, JspCompilationContext ctxt)
311             throws JasperException {
312
313         int uriType = TldLocationsCache.uriType(uri);
314         if (uriType == TldLocationsCache.ABS_URI) {
315             err.jspError("jsp.error.taglibDirective.absUriCannotBeResolved",
316                     uri);
317         } else if (uriType == TldLocationsCache.NOROOT_REL_URI) {
318             uri = ctxt.resolveRelativeUri(uri);
319         }
320
321         String JavaDoc[] location = new String JavaDoc[2];
322         location[0] = uri;
323         if (location[0].endsWith("jar")) {
324             URL JavaDoc url = null;
325             try {
326                 url = ctxt.getResource(location[0]);
327             } catch (Exception JavaDoc ex) {
328                 err.jspError("jsp.error.tld.unable_to_get_jar", location[0], ex
329                         .toString());
330             }
331             if (url == null) {
332                 err.jspError("jsp.error.tld.missing_jar", location[0]);
333             }
334             location[0] = url.toString();
335             location[1] = "META-INF/taglib.tld";
336         }
337
338         return location;
339     }
340
341     private TagInfo JavaDoc createTagInfo(TreeNode elem, String JavaDoc jspVersion)
342             throws JasperException {
343
344         String JavaDoc tagName = null;
345         String JavaDoc tagClassName = null;
346         String JavaDoc teiClassName = null;
347
348         /*
349          * Default body content for JSP 1.2 tag handlers (<body-content> has
350          * become mandatory in JSP 2.0, because the default would be invalid for
351          * simple tag handlers)
352          */

353         String JavaDoc bodycontent = "JSP";
354
355         String JavaDoc info = null;
356         String JavaDoc displayName = null;
357         String JavaDoc smallIcon = null;
358         String JavaDoc largeIcon = null;
359         boolean dynamicAttributes = false;
360
361         Vector JavaDoc attributeVector = new Vector JavaDoc();
362         Vector JavaDoc variableVector = new Vector JavaDoc();
363         Iterator JavaDoc list = elem.findChildren();
364         while (list.hasNext()) {
365             TreeNode element = (TreeNode) list.next();
366             String JavaDoc tname = element.getName();
367
368             if ("name".equals(tname)) {
369                 tagName = element.getBody();
370             } else if ("tagclass".equals(tname) || "tag-class".equals(tname)) {
371                 tagClassName = element.getBody();
372             } else if ("teiclass".equals(tname) || "tei-class".equals(tname)) {
373                 teiClassName = element.getBody();
374             } else if ("bodycontent".equals(tname)
375                     || "body-content".equals(tname)) {
376                 bodycontent = element.getBody();
377             } else if ("display-name".equals(tname)) {
378                 displayName = element.getBody();
379             } else if ("small-icon".equals(tname)) {
380                 smallIcon = element.getBody();
381             } else if ("large-icon".equals(tname)) {
382                 largeIcon = element.getBody();
383             } else if ("icon".equals(tname)) {
384                 TreeNode icon = element.findChild("small-icon");
385                 if (icon != null) {
386                     smallIcon = icon.getBody();
387                 }
388                 icon = element.findChild("large-icon");
389                 if (icon != null) {
390                     largeIcon = icon.getBody();
391                 }
392             } else if ("info".equals(tname) || "description".equals(tname)) {
393                 info = element.getBody();
394             } else if ("variable".equals(tname)) {
395                 variableVector.addElement(createVariable(element));
396             } else if ("attribute".equals(tname)) {
397                 attributeVector
398                         .addElement(createAttribute(element, jspVersion));
399             } else if ("dynamic-attributes".equals(tname)) {
400                 dynamicAttributes = JspUtil.booleanValue(element.getBody());
401             } else if ("example".equals(tname)) {
402                 // Ignored elements
403
} else if ("tag-extension".equals(tname)) {
404                 // Ignored
405
} else {
406                 if (log.isWarnEnabled()) {
407                     log.warn(Localizer.getMessage(
408                             "jsp.warning.unknown.element.in.tag", tname));
409                 }
410             }
411         }
412
413         TagExtraInfo JavaDoc tei = null;
414         if (teiClassName != null && !teiClassName.equals("")) {
415             try {
416                 Class JavaDoc teiClass = ctxt.getClassLoader().loadClass(teiClassName);
417                 tei = (TagExtraInfo JavaDoc) teiClass.newInstance();
418             } catch (Exception JavaDoc e) {
419                 err.jspError("jsp.error.teiclass.instantiation", teiClassName,
420                         e);
421             }
422         }
423
424         TagAttributeInfo JavaDoc[] tagAttributeInfo = new TagAttributeInfo JavaDoc[attributeVector
425                 .size()];
426         attributeVector.copyInto(tagAttributeInfo);
427
428         TagVariableInfo JavaDoc[] tagVariableInfos = new TagVariableInfo JavaDoc[variableVector
429                 .size()];
430         variableVector.copyInto(tagVariableInfos);
431
432         TagInfo JavaDoc taginfo = new TagInfo JavaDoc(tagName, tagClassName, bodycontent, info,
433                 this, tei, tagAttributeInfo, displayName, smallIcon, largeIcon,
434                 tagVariableInfos, dynamicAttributes);
435         return taginfo;
436     }
437
438     /*
439      * Parses the tag file directives of the given TagFile and turns them into a
440      * TagInfo.
441      *
442      * @param elem The <tag-file> element in the TLD @param uri The location of
443      * the TLD, in case the tag file is specified relative to it @param jarFile
444      * The JAR file, in case the tag file is packaged in a JAR
445      *
446      * @return TagInfo correspoding to tag file directives
447      */

448     private TagFileInfo JavaDoc createTagFileInfo(TreeNode elem, String JavaDoc uri,
449             URL JavaDoc jarFileUrl) throws JasperException {
450
451         String JavaDoc name = null;
452         String JavaDoc path = null;
453
454         Iterator JavaDoc list = elem.findChildren();
455         while (list.hasNext()) {
456             TreeNode child = (TreeNode) list.next();
457             String JavaDoc tname = child.getName();
458             if ("name".equals(tname)) {
459                 name = child.getBody();
460             } else if ("path".equals(tname)) {
461                 path = child.getBody();
462             } else if ("example".equals(tname)) {
463                 // Ignore <example> element: Bugzilla 33538
464
} else if ("tag-extension".equals(tname)) {
465                 // Ignore <tag-extension> element: Bugzilla 33538
466
} else if ("icon".equals(tname)
467                     || "display-name".equals(tname)
468                     || "description".equals(tname)) {
469                 // Ignore these elements: Bugzilla 38015
470
} else {
471                 if (log.isWarnEnabled()) {
472                     log.warn(Localizer.getMessage(
473                             "jsp.warning.unknown.element.in.tagfile", tname));
474                 }
475             }
476         }
477
478         if (path.startsWith("/META-INF/tags")) {
479             // Tag file packaged in JAR
480
ctxt.setTagFileJarUrl(path, jarFileUrl);
481         } else if (!path.startsWith("/WEB-INF/tags")) {
482             err.jspError("jsp.error.tagfile.illegalPath", path);
483         }
484
485         TagInfo JavaDoc tagInfo = TagFileProcessor.parseTagFileDirectives(
486                 parserController, name, path, this);
487         return new TagFileInfo JavaDoc(name, path, tagInfo);
488     }
489
490     TagAttributeInfo JavaDoc createAttribute(TreeNode elem, String JavaDoc jspVersion) {
491         String JavaDoc name = null;
492         String JavaDoc type = null;
493         String JavaDoc expectedType = null;
494         String JavaDoc methodSignature = null;
495         boolean required = false, rtexprvalue = false, reqTime = false, isFragment = false, deferredValue = false, deferredMethod = false;
496
497         Iterator JavaDoc list = elem.findChildren();
498         while (list.hasNext()) {
499             TreeNode element = (TreeNode) list.next();
500             String JavaDoc tname = element.getName();
501
502             if ("name".equals(tname)) {
503                 name = element.getBody();
504             } else if ("required".equals(tname)) {
505                 String JavaDoc s = element.getBody();
506                 if (s != null)
507                     required = JspUtil.booleanValue(s);
508             } else if ("rtexprvalue".equals(tname)) {
509                 String JavaDoc s = element.getBody();
510                 if (s != null)
511                     rtexprvalue = JspUtil.booleanValue(s);
512             } else if ("type".equals(tname)) {
513                 type = element.getBody();
514                 if ("1.2".equals(jspVersion)
515                         && (type.equals("Boolean") || type.equals("Byte")
516                                 || type.equals("Character")
517                                 || type.equals("Double")
518                                 || type.equals("Float")
519                                 || type.equals("Integer")
520                                 || type.equals("Long") || type.equals("Object")
521                                 || type.equals("Short") || type
522                                 .equals("String"))) {
523                     type = "java.lang." + type;
524                 }
525             } else if ("fragment".equals(tname)) {
526                 String JavaDoc s = element.getBody();
527                 if (s != null) {
528                     isFragment = JspUtil.booleanValue(s);
529                 }
530             } else if ("deferred-value".equals(tname)) {
531                 deferredValue = true;
532                 type = "javax.el.ValueExpression";
533                 TreeNode child = element.findChild("type");
534                 if (child != null) {
535                     expectedType = child.getBody();
536                     if (expectedType != null) {
537                         expectedType = expectedType.trim();
538                     }
539                 } else {
540                     expectedType = "java.lang.Object";
541                 }
542             } else if ("deferred-method".equals(tname)) {
543                 deferredMethod = true;
544                 type = "javax.el.MethodExpression";
545                 TreeNode child = element.findChild("method-signature");
546                 if (child != null) {
547                     methodSignature = child.getBody();
548                     if (methodSignature != null) {
549                         methodSignature = methodSignature.trim();
550                     }
551                 } else {
552                     methodSignature = "java.lang.Object method()";
553                 }
554             } else if ("description".equals(tname) || // Ignored elements
555
false) {
556                 ;
557             } else {
558                 if (log.isWarnEnabled()) {
559                     log.warn(Localizer.getMessage(
560                             "jsp.warning.unknown.element.in.attribute", tname));
561                 }
562             }
563         }
564
565         if (isFragment) {
566             /*
567              * According to JSP.C-3 ("TLD Schema Element Structure - tag"),
568              * 'type' and 'rtexprvalue' must not be specified if 'fragment' has
569              * been specified (this will be enforced by validating parser).
570              * Also, if 'fragment' is TRUE, 'type' is fixed at
571              * javax.servlet.jsp.tagext.JspFragment, and 'rtexprvalue' is fixed
572              * at true. See also JSP.8.5.2.
573              */

574             type = "javax.servlet.jsp.tagext.JspFragment";
575             rtexprvalue = true;
576         }
577
578         if (!rtexprvalue && type == null) {
579             // According to JSP spec, for static values (those determined at
580
// translation time) the type is fixed at java.lang.String.
581
type = "java.lang.String";
582         }
583         
584         return new TagAttributeInfo JavaDoc(name, required, type, rtexprvalue,
585                 isFragment, null, deferredValue, deferredMethod, expectedType,
586                 methodSignature);
587     }
588
589     TagVariableInfo JavaDoc createVariable(TreeNode elem) {
590         String JavaDoc nameGiven = null;
591         String JavaDoc nameFromAttribute = null;
592         String JavaDoc className = "java.lang.String";
593         boolean declare = true;
594         int scope = VariableInfo.NESTED;
595
596         Iterator JavaDoc list = elem.findChildren();
597         while (list.hasNext()) {
598             TreeNode element = (TreeNode) list.next();
599             String JavaDoc tname = element.getName();
600             if ("name-given".equals(tname))
601                 nameGiven = element.getBody();
602             else if ("name-from-attribute".equals(tname))
603                 nameFromAttribute = element.getBody();
604             else if ("variable-class".equals(tname))
605                 className = element.getBody();
606             else if ("declare".equals(tname)) {
607                 String JavaDoc s = element.getBody();
608                 if (s != null)
609                     declare = JspUtil.booleanValue(s);
610             } else if ("scope".equals(tname)) {
611                 String JavaDoc s = element.getBody();
612                 if (s != null) {
613                     if ("NESTED".equals(s)) {
614                         scope = VariableInfo.NESTED;
615                     } else if ("AT_BEGIN".equals(s)) {
616                         scope = VariableInfo.AT_BEGIN;
617                     } else if ("AT_END".equals(s)) {
618                         scope = VariableInfo.AT_END;
619                     }
620                 }
621             } else if ("description".equals(tname) || // Ignored elements
622
false) {
623             } else {
624                 if (log.isWarnEnabled()) {
625                     log.warn(Localizer.getMessage(
626                             "jsp.warning.unknown.element.in.variable", tname));
627                 }
628             }
629         }
630         return new TagVariableInfo JavaDoc(nameGiven, nameFromAttribute, className,
631                 declare, scope);
632     }
633
634     private TagLibraryValidator JavaDoc createValidator(TreeNode elem)
635             throws JasperException {
636
637         String JavaDoc validatorClass = null;
638         Map JavaDoc initParams = new Hashtable JavaDoc();
639
640         Iterator JavaDoc list = elem.findChildren();
641         while (list.hasNext()) {
642             TreeNode element = (TreeNode) list.next();
643             String JavaDoc tname = element.getName();
644             if ("validator-class".equals(tname))
645                 validatorClass = element.getBody();
646             else if ("init-param".equals(tname)) {
647                 String JavaDoc[] initParam = createInitParam(element);
648                 initParams.put(initParam[0], initParam[1]);
649             } else if ("description".equals(tname) || // Ignored elements
650
false) {
651             } else {
652                 if (log.isWarnEnabled()) {
653                     log.warn(Localizer.getMessage(
654                             "jsp.warning.unknown.element.in.validator", tname));
655                 }
656             }
657         }
658
659         TagLibraryValidator JavaDoc tlv = null;
660         if (validatorClass != null && !validatorClass.equals("")) {
661             try {
662                 Class JavaDoc tlvClass = ctxt.getClassLoader()
663                         .loadClass(validatorClass);
664                 tlv = (TagLibraryValidator JavaDoc) tlvClass.newInstance();
665             } catch (Exception JavaDoc e) {
666                 err.jspError("jsp.error.tlvclass.instantiation",
667                         validatorClass, e);
668             }
669         }
670         if (tlv != null) {
671             tlv.setInitParameters(initParams);
672         }
673         return tlv;
674     }
675
676     String JavaDoc[] createInitParam(TreeNode elem) {
677         String JavaDoc[] initParam = new String JavaDoc[2];
678
679         Iterator JavaDoc list = elem.findChildren();
680         while (list.hasNext()) {
681             TreeNode element = (TreeNode) list.next();
682             String JavaDoc tname = element.getName();
683             if ("param-name".equals(tname)) {
684                 initParam[0] = element.getBody();
685             } else if ("param-value".equals(tname)) {
686                 initParam[1] = element.getBody();
687             } else if ("description".equals(tname)) {
688                 ; // Do nothing
689
} else {
690                 if (log.isWarnEnabled()) {
691                     log.warn(Localizer.getMessage(
692                             "jsp.warning.unknown.element.in.initParam", tname));
693                 }
694             }
695         }
696         return initParam;
697     }
698
699     FunctionInfo JavaDoc createFunctionInfo(TreeNode elem) {
700
701         String JavaDoc name = null;
702         String JavaDoc klass = null;
703         String JavaDoc signature = null;
704
705         Iterator JavaDoc list = elem.findChildren();
706         while (list.hasNext()) {
707             TreeNode element = (TreeNode) list.next();
708             String JavaDoc tname = element.getName();
709
710             if ("name".equals(tname)) {
711                 name = element.getBody();
712             } else if ("function-class".equals(tname)) {
713                 klass = element.getBody();
714             } else if ("function-signature".equals(tname)) {
715                 signature = element.getBody();
716             } else if ("display-name".equals(tname) || // Ignored elements
717
"small-icon".equals(tname) || "large-icon".equals(tname)
718                     || "description".equals(tname) || "example".equals(tname)) {
719             } else {
720                 if (log.isWarnEnabled()) {
721                     log.warn(Localizer.getMessage(
722                             "jsp.warning.unknown.element.in.function", tname));
723                 }
724             }
725         }
726
727         return new FunctionInfo JavaDoc(name, klass, signature);
728     }
729
730     // *********************************************************************
731
// Until javax.servlet.jsp.tagext.TagLibraryInfo is fixed
732

733     /**
734      * The instance (if any) for the TagLibraryValidator class.
735      *
736      * @return The TagLibraryValidator instance, if any.
737      */

738     public TagLibraryValidator JavaDoc getTagLibraryValidator() {
739         return tagLibraryValidator;
740     }
741
742     /**
743      * Translation-time validation of the XML document associated with the JSP
744      * page. This is a convenience method on the associated TagLibraryValidator
745      * class.
746      *
747      * @param thePage
748      * The JSP page object
749      * @return A string indicating whether the page is valid or not.
750      */

751     public ValidationMessage JavaDoc[] validate(PageData JavaDoc thePage) {
752         TagLibraryValidator JavaDoc tlv = getTagLibraryValidator();
753         if (tlv == null)
754             return null;
755
756         String JavaDoc uri = getURI();
757         if (uri.startsWith("/")) {
758             uri = URN_JSPTLD + uri;
759         }
760
761         return tlv.validate(getPrefixString(), uri, thePage);
762     }
763
764     protected TagLibraryValidator JavaDoc tagLibraryValidator;
765 }
766
Popular Tags