KickJava   Java API By Example, From Geeks To Geeks.

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


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.elements;
24
25 import com.sun.enterprise.tools.verifier.tests.web.WebTest;
26 import java.util.*;
27 import java.io.*;
28 import com.sun.enterprise.deployment.*;
29 import com.sun.enterprise.tools.verifier.tests.web.WebCheck;
30 import com.sun.enterprise.tools.verifier.*;
31 import com.sun.enterprise.tools.verifier.tests.*;
32 import com.sun.enterprise.util.FileClassLoader;
33
34
35 /**
36  * Servlet url element defines a url location to a resource external to this
37  * web application.
38  */

39 public class UrlElement extends WebTest implements WebCheck {
40
41     
42     /**
43      * Servlet url element defines a url location to a resource external to this
44      * web application.
45      *
46      * @param descriptor the Web deployment descriptor
47      *
48      * @return <code>Result</code> the results for this assertion
49      */

50     public Result check(WebBundleDescriptor descriptor) {
51
52     Result result = getInitializedResult();
53     ComponentNameConstructor compName = getVerifierContext().getComponentNameConstructor();
54
55     if (descriptor.getLocalizedContentDescriptors().hasMoreElements()) {
56         boolean oneFailed = false;
57         boolean foundIt = false;
58         // get the url's in this .war
59
for (Enumeration e = descriptor.getLocalizedContentDescriptors() ; e.hasMoreElements() ;) {
60         foundIt = false;
61         LocalizedContentDescriptorImpl urls = (LocalizedContentDescriptorImpl)e.nextElement();
62         String JavaDoc url = urls.getUrl();
63         if (url.length() > 0) {
64             foundIt = true;
65         } else {
66             foundIt = false;
67         }
68    
69         if (foundIt) {
70             result.addGoodDetails(smh.getLocalString
71                        ("tests.componentNameConstructor",
72                     "For [ {0} ]",
73                     new Object JavaDoc[] {compName.toString()}));
74             result.addGoodDetails(smh.getLocalString
75                       (getClass().getName() + ".passed",
76                        "Servlet url [ {0} ] defines a url location to a resource external to this web application.",
77                        new Object JavaDoc[] {url}));
78         } else {
79             if (!oneFailed) {
80             oneFailed = true;
81             }
82             result.addErrorDetails(smh.getLocalString
83                        ("tests.componentNameConstructor",
84                     "For [ {0} ]",
85                     new Object JavaDoc[] {compName.toString()}));
86             result.addErrorDetails(smh.getLocalString
87                        (getClass().getName() + ".failed",
88                         "Error: Servlet url [ {0} ] does not define a url location to a resource external to this web application.",
89                         new Object JavaDoc[] {url}));
90         }
91         }
92         if (oneFailed) {
93         result.setStatus(Result.FAILED);
94         } else {
95         result.setStatus(Result.PASSED);
96         }
97     } else {
98         result.addNaDetails(smh.getLocalString
99                        ("tests.componentNameConstructor",
100                     "For [ {0} ]",
101                     new Object JavaDoc[] {compName.toString()}));
102         result.notApplicable(smh.getLocalString
103                  (getClass().getName() + ".notApplicable",
104                   "There are no url elements within the web archive [ {0} ]",
105                   new Object JavaDoc[] {descriptor.getName()}));
106     }
107     return result;
108     }
109 }
110
Popular Tags