KickJava   Java API By Example, From Geeks To Geeks.

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


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 java.io.*;
26
27 import com.sun.enterprise.deployment.*;
28 import com.sun.enterprise.deployment.io.WebDeploymentDescriptorFile;
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  * Web PUBLIC identifier test
37  * The Web deployment descriptor has PUBLIC identifier with a PubidLiteral
38  * of "-//Sun Microsystems, Inc.//DTD Web Application 2.2//EN"
39  */

40 public class WebPublicID extends WebTest implements WebCheck {
41
42
43     /**
44      * Web PUBLIC identifier test
45      * The Web deployment descriptor has PUBLIC identifier with a PubidLiteral
46      * of "-//Sun Microsystems, Inc.//DTD Web Application 2.2//EN"
47      *
48      * @param descriptor the Web deployment descriptor
49      *
50      * @return <code>Result</code> the results for this assertion
51      */

52     public Result check(WebBundleDescriptor descriptor) {
53
54     Result result = getInitializedResult();
55     ComponentNameConstructor compName = getVerifierContext().getComponentNameConstructor();
56         String JavaDoc acceptablePubidLiterals[] = {
57             "-//Sun Microsystems, Inc.//DTD Web Application 2.2//EN" ,
58             "-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN" };
59
60     String JavaDoc acceptableURLs[] = {"http://java.sun.com/j2ee/dtds/web-app_2_2.dtd",
61                    "http://java.sun.com/dtd/web-app_2_3.dtd"};
62
63                                            
64     // open the jar and read the XML deployment descriptor
65
if (descriptor.getSpecVersion().compareTo("2.4") < 0){
66             
67             InputStream deploymentEntry=null;
68             try {
69                      String JavaDoc uri = getAbstractArchiveUri(descriptor);
70                          FileArchive arch = new FileArchive();
71                          arch.open(uri);
72                          deploymentEntry = arch.getEntry(
73                          WebDeploymentDescriptorFile.DESC_PATH);
74                  if (deploymentEntry != null) {
75                      BufferedReader in = new BufferedReader(new InputStreamReader(deploymentEntry));
76                      String JavaDoc s = in.readLine();
77                      boolean foundDOCTYPE = false, foundPubid = false, foundURL = false;
78                      while (s != null) {
79                          // did we find the DOCTYPE entry?
80
if (s.indexOf("DOCTYPE") > -1)
81                              foundDOCTYPE = true;
82                          if (foundDOCTYPE) {
83                              for (int i=0;i<acceptablePubidLiterals.length;i++) {
84                                  if (s.indexOf(acceptablePubidLiterals[i]) > -1) {
85                                      foundPubid = true;
86                                         result.addGoodDetails(smh.getLocalString
87                                             ("tests.componentNameConstructor",
88                                             "For [ {0} ]",
89                                             new Object JavaDoc[] {compName.toString()}));
90                                         result.addGoodDetails
91                                              (smh.getLocalString
92                                              (getClass().getName() + ".passed",
93                                              "The deployment descriptor has the proper PubidLiteral: {0}",
94                                              new Object JavaDoc[] {acceptablePubidLiterals[i]}));
95                                  }
96                                  if (s.indexOf(acceptableURLs[i]) > -1) {
97                                      foundURL = true;
98                                      result.addGoodDetails(smh.getLocalString
99                                           ("tests.componentNameConstructor",
100                                            "For [ {0} ]",
101                                             new Object JavaDoc[] {compName.toString()}));
102                                       result.addGoodDetails
103                                             (smh.getLocalString
104                                             (getClass().getName() + ".passed1",
105                                             "The deployment descriptor has the proper URL corresponding the the PubIdLiteral: {0}",
106                                             new Object JavaDoc[] {acceptableURLs[i]}));
107                                  }
108             }
109             }
110             if (foundPubid && foundURL) {
111             result.setStatus(Result.PASSED);
112             break;
113             } else if(foundDOCTYPE && s.endsWith(">")) break; // DOCTYPE doesn't have any more lines to check
114
s = in.readLine();
115         }
116         
117         if (!foundDOCTYPE){
118             result.addErrorDetails(smh.getLocalString
119                        ("tests.componentNameConstructor",
120                         "For [ {0} ]",
121                         new Object JavaDoc[] {compName.toString()}));
122             result.failed
123             (smh.getLocalString
124              (getClass().getName() + ".failed1",
125               "No document type declaration found in the deployment descriptor for {0}",
126               new Object JavaDoc[] {descriptor.getName()}));
127         } else if (!foundPubid) {
128             result.addErrorDetails(smh.getLocalString
129                        ("tests.componentNameConstructor",
130                     "For [ {0} ]",
131                     new Object JavaDoc[] {compName.toString()}));
132             result.failed
133             (smh.getLocalString
134              (getClass().getName() + ".failed2",
135               "The deployment descriptor for {0} does not have an expected PubidLiteral ",
136               new Object JavaDoc[] {descriptor.getName()}));
137         }else if (!foundURL) {
138             result.addErrorDetails(smh.getLocalString
139                        ("tests.componentNameConstructor",
140                     "For [ {0} ]",
141                     new Object JavaDoc[] {compName.toString()}));
142         result.failed(smh.getLocalString
143                        (getClass().getName() + ".failed",
144                         "The deployment descriptor {0} doesnot have the right URL corresponding to the PubIdLiteral",
145                         new Object JavaDoc[] {descriptor.getName()}));
146         }
147         }
148         
149     } catch (IOException e) {
150         result.addErrorDetails(smh.getLocalString
151                        ("tests.componentNameConstructor",
152                     "For [ {0} ]",
153                     new Object JavaDoc[] {compName.toString()}));
154         result.failed(smh.getLocalString
155               (getClass().getName() + ".IOException",
156                "I/O error trying to open {0}", new Object JavaDoc[] {getAbstractArchiveUri(descriptor)}));
157     } finally {
158         try {
159               if (deploymentEntry != null)
160                  deploymentEntry.close();
161         } catch (Exception JavaDoc x) {}
162     }
163         }else{
164                 //NOT APPLICABLE
165
result.addNaDetails(smh.getLocalString
166                        ("tests.componentNameConstructor",
167                     "For [ {0} ]",
168                     new Object JavaDoc[] {compName.toString()}));
169                 result.notApplicable(smh.getLocalString
170                     (getClass().getName() + ".notApplicable",
171             "NOT-APPLICABLE: No DOCTYPE found for [ {0} ]",
172              new Object JavaDoc[] {descriptor.getName()}));
173             }
174     return result;
175     }
176 }
177
Popular Tags