KickJava   Java API By Example, From Geeks To Geeks.

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


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
32 import com.sun.enterprise.deployment.deploy.shared.FileArchive;
33
34
35 /**
36  * Jsp file element contains the full path to Jsp file within web application
37  * test.
38  */

39 public class JspFile extends WebTest implements WebCheck {
40
41     
42     /**
43      * Jsp file element contains the full path to Jsp file within web application
44      * test.
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.getJspDescriptors().isEmpty()) {
56         boolean oneFailed = false;
57         boolean foundIt = false;
58 // ZipEntry ze=null;
59
// JarFile jar=null;
60
FileArchive arch=null;
61         // get the jsps in this .war
62
Set jsps = descriptor.getJspDescriptors();
63         Iterator itr = jsps.iterator();
64         // test the jsps in this .war
65
while (itr.hasNext()) {
66         foundIt = false;
67         WebComponentDescriptor jsp = (WebComponentDescriptor)itr.next();
68         String JavaDoc jspFilename = jsp.getWebComponentImplementation();
69             String JavaDoc uri = null;
70                 try{
71 // File f = Verifier.getArchiveFile(descriptor.getModuleDescriptor().getArchiveUri());
72
// if(f==null){
73
uri=getAbstractArchiveUri(descriptor);
74                         try{
75                             arch = new FileArchive();
76                             arch.open(uri);
77                         }catch(IOException e){throw e;}
78 // }
79
// else{
80
// jar = new JarFile(f);
81
// }
82

83                     if (jspFilename.startsWith("/"))
84                         jspFilename = jspFilename.substring(1);
85 // if(f!=null){
86
// ze = jar.getEntry(jspFilename);
87
// foundIt=(ze !=null);
88
// }else{
89
File jspf = new File(arch.getArchiveUri()+File.separator+jspFilename);
90                         if(jspf.exists())
91                             foundIt=true;
92                         jspf = null;
93 // }
94
// if (jar!=null)
95
// jar.close();
96
}catch (Exception JavaDoc e){
97                     if (!oneFailed ) {
98                         oneFailed = true;
99                     }
100                 }
101                 
102                 if (foundIt) {
103             result.addGoodDetails(smh.getLocalString
104             ("tests.componentNameConstructor",
105             "For [ {0} ]",
106             new Object JavaDoc[] {compName.toString()}));
107             result.addGoodDetails(smh.getLocalString
108                       (getClass().getName() + ".passed",
109                        "Jsp file [ {0} ] contains the full path to Jsp file within web application [ {1} ]",
110                        new Object JavaDoc[] {jspFilename, descriptor.getName()}));
111         } else {
112             if (!oneFailed ) {
113             oneFailed = true;
114             }
115             result.addErrorDetails(smh.getLocalString
116             ("tests.componentNameConstructor",
117             "For [ {0} ]",
118             new Object JavaDoc[] {compName.toString()}));
119
120             result.addErrorDetails(smh.getLocalString
121                        (getClass().getName() + ".failed",
122                         "Error: Jsp file [ {0} ] is not found within [ {1} ] or does not contain the full path to Jsp file within web application [ {2} ]",
123                         new Object JavaDoc[] {jspFilename, uri, descriptor.getName()}));
124         }
125         }
126         if (oneFailed) {
127         result.setStatus(Result.FAILED);
128         } else {
129         result.setStatus(Result.PASSED);
130         }
131     } else {
132         result.addNaDetails(smh.getLocalString
133             ("tests.componentNameConstructor",
134             "For [ {0} ]",
135             new Object JavaDoc[] {compName.toString()}));
136
137         result.notApplicable(smh.getLocalString
138                  (getClass().getName() + ".notApplicable",
139                   "There are no Jsp components within the web archive [ {0} ]",
140                   new Object JavaDoc[] {descriptor.getName()}));
141     }
142     return result;
143     }
144 }
145
Popular Tags