KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > sun > enterprise > tools > verifier > tests > web > TaglibUri


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 package com.sun.enterprise.tools.verifier.tests.web;
24
25 import java.util.*;
26 import com.sun.enterprise.deployment.*;
27 import com.sun.enterprise.tools.verifier.*;
28 import com.sun.enterprise.tools.verifier.tests.*;
29
30
31 /**
32  * Must check for the existence of the tag library relative to the web.xml.
33  * @author Arun Jain
34  */

35 public class TaglibUri extends Taglib implements WebCheck {
36     
37
38      /**
39      * Tag library existence test.
40      *
41      * @param descriptor the Web deployment descriptor
42      *
43      * @return <code>Result</code> the results for this assertion
44      */

45     public Result check(WebBundleDescriptor descriptor) {
46
47     Result result = getInitializedResult();
48     ComponentNameConstructor compName = getVerifierContext().getComponentNameConstructor();
49         boolean failed = false;
50         TagLibConfigurationDescriptor taglibDescriptor;
51         String JavaDoc taglibUri;
52         Enumeration taglibConfig = (new Vector()).elements();
53         if (descriptor.getJspConfigDescriptor() != null) {
54             taglibConfig = descriptor.getJspConfigDescriptor().getTagLibs();
55         }
56
57
58         if (taglibConfig.hasMoreElements()){
59             while (taglibConfig.hasMoreElements()) {
60                 // test all the Tag lib descriptors.
61
taglibDescriptor = (TagLibConfigurationDescriptor) taglibConfig.nextElement();
62                 taglibUri = taglibDescriptor.getTagLibURI();
63         if (taglibUri.equals("")) {
64             failed = true;
65             result.addErrorDetails(smh.getLocalString
66                        ("tests.componentNameConstructor",
67                     "For [ {0} ]",
68                     new Object JavaDoc[] {compName.toString()}));
69             result.addErrorDetails(smh.getLocalString
70                        (getClass().getName() + ".failed",
71                         "Error: taglib-uri should not be an empty string."));
72             result.setStatus(Result.FAILED);
73             return result;
74         }
75             }
76         if (failed == false) {
77         result.addGoodDetails(smh.getLocalString
78                        ("tests.componentNameConstructor",
79                     "For [ {0} ]",
80                     new Object JavaDoc[] {compName.toString()}));
81         result.addGoodDetails(smh.getLocalString
82                                       (getClass().getName() + ".passed",
83                                        "taglib-uri element is a non-empty string."));
84         result.setStatus(Result.PASSED);
85         } else {
86         result.setStatus(Result.FAILED);
87         }
88         return result;
89             
90         } else {
91         result.addNaDetails(smh.getLocalString
92                        ("tests.componentNameConstructor",
93                     "For [ {0} ]",
94                     new Object JavaDoc[] {compName.toString()}));
95             result.notApplicable(smh.getLocalString
96                                  (getClass().getName() + ".notApplicable",
97                                   "There are no TagLibConfigurationDescriptors within the web archive [ {0} ]",
98                                   new Object JavaDoc[] {descriptor.getName()}));
99             result.setStatus(Result.NOT_APPLICABLE);
100             return result;
101                 
102         }
103         
104         
105     }
106 }
107
Popular Tags