KickJava   Java API By Example, From Geeks To Geeks.

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


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.spec22;
24
25 import com.sun.enterprise.tools.verifier.tests.web.WebTest;
26 import java.util.zip.*;
27 import java.util.jar.*;
28 import java.util.*;
29 import java.io.*;
30 import com.sun.enterprise.tools.verifier.tests.web.WebCheck;
31 import com.sun.enterprise.deployment.*;
32 import com.sun.enterprise.tools.verifier.*;
33 import com.sun.enterprise.tools.verifier.tests.*;
34 import com.sun.enterprise.util.FileClassLoader;
35
36
37 /**
38  * Jsp file element contains the full path to Jsp file within web application
39  * test.
40  */

41 public class JspFileName extends WebTest implements WebCheck {
42
43     
44     /**
45      * Jsp file in Servlet 2.2 applications must start with a leading /
46      *
47      * @param descriptor the Web deployment descriptor
48      *
49      * @return <code>Result</code> the results for this assertion
50      */

51     public Result check(WebBundleDescriptor descriptor) {
52
53     Result result = getInitializedResult();
54     ComponentNameConstructor compName = getVerifierContext().getComponentNameConstructor();
55     String JavaDoc specVersion = descriptor.getSpecVersion();
56     Float JavaDoc specVer = new Float JavaDoc(specVersion);
57     if (!descriptor.getJspDescriptors().isEmpty()) {
58         boolean oneFailed = false;
59         int count = getNonRuntimeCountNodeSet("/web-app/servlet");
60         for(int i=1;i<=count;i++){
61             String JavaDoc jspFilename = getXPathValueForNonRuntime("/web-app/servlet["+i+"]/jsp-file");
62             if(jspFilename!=null){
63                 if (jspFilename.startsWith("/")){
64                     if(specVer.compareTo(new Float JavaDoc("2.3"))<0){
65                         result.addGoodDetails(smh.getLocalString
66                                 ("tests.componentNameConstructor",
67                                         "For [ {0} ]",
68                                         new Object JavaDoc[] {compName.toString()}));
69                         result.addGoodDetails(smh.getLocalString(getClass().getName() + ".passed",
70                                 " PASSED : Jsp Name [ {0} ] is valid",
71                                 new Object JavaDoc[] { jspFilename }));
72
73                     }else{
74                         result.addGoodDetails(smh.getLocalString("tests.componentNameConstructor",
75                                 "For [ {0} ]",
76                                 new Object JavaDoc[] {compName.toString()}));
77                         result.addGoodDetails(smh.getLocalString(getClass().getName() + ".passed1",
78                                 " Jsp Name [ {0} ] is valid and starts with a leading '/'",
79                                 new Object JavaDoc[] { jspFilename }));
80
81                     }
82                 }else{
83                     if(specVer.compareTo(new Float JavaDoc("2.3"))<0){
84                         result.addGoodDetails(smh.getLocalString("tests.componentNameConstructor",
85                                 "For [ {0} ]",
86                                 new Object JavaDoc[] {compName.toString()}));
87                         result.addGoodDetails(smh.getLocalString(getClass().getName() + ".passed",
88                                 " PASSED Jsp Name [ {0} ] is valid",
89                                 new Object JavaDoc[] { jspFilename }));
90
91                     }else{
92                         result.addErrorDetails(smh.getLocalString
93                                 ("tests.componentNameConstructor",
94                                         "For [ {0} ]",
95                                         new Object JavaDoc[] {compName.toString()}));
96                         result.addErrorDetails(smh.getLocalString(getClass().getName() + ".failed",
97                                 " Error : Jsp Name [ {0} ] in invalid as it does not start with a leading '/'",
98                                 new Object JavaDoc[] { jspFilename }));
99                         oneFailed=true;
100                     }
101                 }
102
103             }
104         }
105         if (oneFailed) {
106             result.setStatus(Result.FAILED);
107         } else {
108             result.setStatus(Result.PASSED);
109         }
110     } else {
111         result.addNaDetails(smh.getLocalString
112                 ("tests.componentNameConstructor",
113                         "For [ {0} ]",
114                         new Object JavaDoc[] {compName.toString()}));
115         result.notApplicable(smh.getLocalString
116                 (getClass().getName() + ".notApplicable",
117                         "There are no Jsp components within the web archive [ {0} ]",
118                         new Object JavaDoc[] {descriptor.getName()}));
119     }
120         return result;
121
122     }
123 }
124
Popular Tags