KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > sun > enterprise > tools > verifier > TagLibDescriptor


1 /*
2  * The contents of this file are subject to the terms
3  * of the Common Development and Distribution License
4  * (the License). You may not use this file except in
5  * compliance with the License.
6  *
7  * You can obtain a copy of the license at
8  * https://glassfish.dev.java.net/public/CDDLv1.0.html or
9  * glassfish/bootstrap/legal/CDDLv1.0.txt.
10  * See the License for the specific language governing
11  * permissions and limitations under the License.
12  *
13  * When distributing Covered Code, include this CDDL
14  * Header Notice in each file and include the License file
15  * at glassfish/bootstrap/legal/CDDLv1.0.txt.
16  * If applicable, add the following below the CDDL Header,
17  * with the fields enclosed by brackets [] replaced by
18  * you own identifying information:
19  * "Portions Copyrighted [year] [name of copyright owner]"
20  *
21  * Copyright 2006 Sun Microsystems, Inc. All rights reserved.
22  */

23
24 package com.sun.enterprise.tools.verifier;
25
26 import java.util.ArrayList JavaDoc;
27 import java.util.List JavaDoc;
28
29 import org.w3c.dom.Document JavaDoc;
30 import org.w3c.dom.DocumentType JavaDoc;
31 import org.w3c.dom.NodeList JavaDoc;
32 import com.sun.enterprise.tools.verifier.web.TagDescriptor;
33 import com.sun.enterprise.tools.verifier.web.FunctionDescriptor;
34
35 /**
36  * class which defines methods required for implementing tests based
37  * out of jsp tag library files.
38  *
39  * @author Sudipto Ghosh
40  */

41 public class TagLibDescriptor {
42     public static final String JavaDoc TAG = "tag"; // NOI18N
43
public static final String JavaDoc LISTENER_CLASS = "listener-class"; // NOI18N
44
public static final String JavaDoc FUNCTION = "function"; // NOI18N
45

46     private Document JavaDoc doc = null;
47     private String JavaDoc version = null;
48     private String JavaDoc uri = null;
49
50     public TagLibDescriptor(Document JavaDoc doc, String JavaDoc version, String JavaDoc uri) {
51         this.doc = doc;
52         this.version = version;
53         this.uri = uri;
54     }
55     /**
56      * @return spec version of tld file
57      */

58     public String JavaDoc getSpecVersion() {
59         return this.version;
60     }
61
62     /**
63      * @return location of the tld file
64      */

65     public String JavaDoc getUri() {
66         return this.uri;
67     }
68
69     public String JavaDoc getPublicID() {
70         DocumentType JavaDoc docType = doc.getDoctype();
71         return ((docType == null) ? null : docType.getPublicId());
72     }
73
74     /**
75      * @return system-id of the tld file.
76      */

77     public String JavaDoc getSystemID() {
78         DocumentType JavaDoc docType = doc.getDoctype();
79         return ((docType == null) ? null : docType.getSystemId());
80     }
81
82     public String JavaDoc[] getListenerClasses(){
83         NodeList JavaDoc nl = doc.getElementsByTagName(LISTENER_CLASS);
84         String JavaDoc[] classes = null;
85         if (nl != null) {
86             int size = nl.getLength();
87             classes = new String JavaDoc[size];
88             for (int i = 0; i < size; i++) {
89                 classes[i] = nl.item(i).getFirstChild().getNodeValue();
90             }
91         }
92         return classes;
93     }
94
95     /**
96      * for each tag in the tag lib descriptor create a TagDescriptor and return
97      * the array of TagDescriptors present in the tag lib.
98      * @return
99      */

100     public TagDescriptor[] getTagDescriptors() {
101         NodeList JavaDoc nl = doc.getElementsByTagName(TAG);
102         TagDescriptor[] tagdescriptor = null;
103         if (nl != null) {
104             int size = nl.getLength();
105             tagdescriptor = new TagDescriptor[size];
106             for (int i = 0; i < size; i++) {
107                 tagdescriptor[i] = new TagDescriptor(nl.item(i));
108             }
109         }
110         return tagdescriptor;
111     }
112
113     /**
114      * for each functions in tag lib descriptor creates a function descritor and
115      * return the array of FunctionDescriptors
116      * @return array of function descriptor.
117      */

118     public FunctionDescriptor[] getFunctionDescriptors() {
119         NodeList JavaDoc nl = doc.getElementsByTagName(FUNCTION);
120         List JavaDoc<FunctionDescriptor> list = new ArrayList JavaDoc<FunctionDescriptor>();
121         if (nl != null) {
122             int size = nl.getLength();
123             for (int i = 0; i < size; i++) {
124                 list.add(new FunctionDescriptor(nl.item(i)));
125             }
126         }
127         return list.toArray(new FunctionDescriptor[0]);
128     }
129 }
130
Popular Tags