KickJava   Java API By Example, From Geeks To Geeks.

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


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.deployment.*;
26 import com.sun.enterprise.deployment.deploy.shared.FileArchive;
27 import com.sun.enterprise.tools.verifier.*;
28 import com.sun.enterprise.tools.verifier.tests.*;
29 import com.sun.enterprise.tools.verifier.tests.web.WebTest;
30 import java.io.*;
31
32
33 /**
34  * The Web form-error-page value defines the location in the web application
35  * where the page can be used for error page can be found within web
36  * application test
37  */

38 public class FormErrorPage extends WebTest implements WebCheck {
39
40     
41     /**
42      * The Web form-error-page value defines the location in the web application
43      * where the page can be used for error page can be found within web
44      * application 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.getLoginConfiguration() != null) {
56         boolean foundIt = false;
57 // ZipEntry ze=null;
58
// JarFile jar=null;
59
FileArchive arch=null;
60             
61         String JavaDoc formErrorPage = descriptor.getLoginConfiguration().getFormErrorPage();
62             if (formErrorPage.length() > 0) {
63            
64                 try{
65                     
66 // File f = Verifier.getArchiveFile(descriptor.getModuleDescriptor().getArchiveUri());
67
// if(f==null){
68

69                         String JavaDoc uri=getAbstractArchiveUri(descriptor);
70                         
71                         try{
72                             arch = new FileArchive();
73                             arch.open(uri);
74                         }catch(IOException e){
75                             throw e;
76                         }
77 // }else{
78
// jar = new JarFile(f);
79
// }
80
if (formErrorPage.startsWith("/"))
81                         formErrorPage=formErrorPage.substring(1);
82 // if (f!=null){
83
// ze = jar.getEntry(formErrorPage);
84
// foundIt = (ze != null);
85
// }
86
// else{
87
File fep = new File(arch.getArchiveUri() + File.separator + formErrorPage);
88                         if(fep.exists())
89                             foundIt=true;
90                         fep = null;
91 // }
92
// if (jar!=null)
93
// jar.close();
94
}catch (Exception JavaDoc ex) {
95             //should be aldready set?
96
foundIt = false;
97             }
98             if (foundIt) {
99             result.addGoodDetails(smh.getLocalString
100             ("tests.componentNameConstructor",
101             "For [ {0} ]",
102             new Object JavaDoc[] {compName.toString()}));
103             result.passed(smh.getLocalString
104                       (getClass().getName() + ".passed",
105                        "The form-error-page [ {0} ] value defines the location in the web application where the error page that is displayed when login is not successful can be found within web application [ {1} ]",
106                        new Object JavaDoc[] {formErrorPage, descriptor.getName()}));
107             } else {
108             result.addErrorDetails(smh.getLocalString
109             ("tests.componentNameConstructor",
110             "For [ {0} ]",
111             new Object JavaDoc[] {compName.toString()}));
112                     result.failed(smh.getLocalString
113                   (getClass().getName() + ".failed",
114                    "Error: The form-error-page [ {0} ] value does not define the location in the web application where the error page that is displayed when login is not successful can be found within web application [ {1} ]",
115                    new Object JavaDoc[] {formErrorPage, descriptor.getName()}));
116             }
117         } else {
118         result.addNaDetails(smh.getLocalString
119             ("tests.componentNameConstructor",
120             "For [ {0} ]",
121             new Object JavaDoc[] {compName.toString()}));
122             result.notApplicable(smh.getLocalString
123                      (getClass().getName() + ".notApplicable",
124                       "There are no form-error-page elements within this web archive [ {0} ]",
125                       new Object JavaDoc[] {descriptor.getName()}));
126         }
127     } else {
128         result.addNaDetails(smh.getLocalString
129             ("tests.componentNameConstructor",
130             "For [ {0} ]",
131             new Object JavaDoc[] {compName.toString()}));
132         result.notApplicable(smh.getLocalString
133                  (getClass().getName() + ".notApplicable",
134                   "There are no form-error-page elements within this web archive [ {0} ]",
135                   new Object JavaDoc[] {descriptor.getName()}));
136     }
137
138     return result;
139     }
140 }
141
Popular Tags