KickJava   Java API By Example, From Geeks To Geeks.

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


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 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.*;
30 import com.sun.enterprise.tools.verifier.tests.*;
31 import com.sun.enterprise.deployment.deploy.shared.FileArchive;
32
33
34 /**
35  * Location element contains the location of the resource in the web
36  * application
37  */

38 public class Location extends WebTest implements WebCheck {
39
40     
41     /**
42      * Location element contains the location of the resource in the web
43      * application
44      *
45      * @param descriptor the Web deployment descriptor
46      *
47      * @return <code>Result</code> the results for this assertion
48      */

49     public Result check(WebBundleDescriptor descriptor) {
50
51     Result result = getInitializedResult();
52     ComponentNameConstructor compName = getVerifierContext().getComponentNameConstructor();
53
54     if (descriptor.getErrorPageDescriptors().hasMoreElements()) {
55         boolean oneFailed = false;
56         boolean foundIt = false;
57 // ZipEntry ze = null;
58
// JarFile jar =null;
59
FileArchive arch=null;
60         // get the errorpage's in this .war
61
for (Enumeration e = descriptor.getErrorPageDescriptors() ; e.hasMoreElements() ;) {
62         foundIt = false;
63         ErrorPageDescriptorImpl errorpage = (ErrorPageDescriptorImpl) e.nextElement();
64         String JavaDoc location = errorpage.getLocation();
65             String JavaDoc uri = null;
66                 try{
67 // File f = Verifier.getArchiveFile(descriptor.getModuleDescriptor().getArchiveUri());
68
// if(f==null){
69
uri=getAbstractArchiveUri(descriptor);
70                         try{
71                             arch = new FileArchive();
72                             arch.open(uri);
73                         }catch(IOException ioe){throw ioe;}
74 // }else{
75
// jar = new JarFile(f);
76
// }
77
if (location.startsWith("/"))
78                         location = location.substring(1);
79 // if (f!=null){
80
// ze = jar.getEntry(location);
81
// foundIt = (ze != null);
82
// }
83
// else{
84
File loc = new File(arch.getArchiveUri()+File.separator+location);
85                         if(loc.exists())
86                             foundIt=true;
87                         loc = null;
88 // }
89
// if (jar!=null)
90
// jar.close();
91
}catch (Exception JavaDoc ex) {
92             if (!oneFailed){
93                         oneFailed = true;
94                     }
95             }
96                 if (foundIt) {
97             result.addGoodDetails(smh.getLocalString
98                        ("tests.componentNameConstructor",
99                     "For [ {0} ]",
100                     new Object JavaDoc[] {compName.toString()}));
101             result.addGoodDetails(smh.getLocalString
102                       (getClass().getName() + ".passed",
103                        "Location [ {0} ] contains the location of the resource within web application [ {1} ]",
104                        new Object JavaDoc[] {location, descriptor.getName()}));
105         } else {
106             if (!oneFailed) {
107             oneFailed = true;
108             }
109             result.addErrorDetails(smh.getLocalString
110                        ("tests.componentNameConstructor",
111                     "For [ {0} ]",
112                     new Object JavaDoc[] {compName.toString()}));
113             result.addErrorDetails(smh.getLocalString
114                        (getClass().getName() + ".failed",
115                         "Error: Location [ {0} ] is not found within [ {1} ] or does not contain the location of the resource within web application [ {2} ]",
116                         new Object JavaDoc[] {location, uri, descriptor.getName()}));
117         }
118         }
119         if (oneFailed) {
120         result.setStatus(Result.FAILED);
121         } else {
122         result.setStatus(Result.PASSED);
123         }
124     } else {
125         result.addNaDetails(smh.getLocalString
126                        ("tests.componentNameConstructor",
127                     "For [ {0} ]",
128                     new Object JavaDoc[] {compName.toString()}));
129         result.notApplicable(smh.getLocalString
130                  (getClass().getName() + ".notApplicable",
131                   "There are no location elements within the web archive [ {0} ]",
132                   new Object JavaDoc[] {descriptor.getName()}));
133     }
134
135     return result;
136     }
137 }
138
Popular Tags