KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > sun > enterprise > tools > verifier > tests > app > AppPublicID


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.app;
24
25 import java.io.*;
26
27 import com.sun.enterprise.deployment.io.ApplicationDeploymentDescriptorFile;
28 import com.sun.enterprise.deployment.Application;
29 import com.sun.enterprise.tools.verifier.*;
30
31 import com.sun.enterprise.deployment.deploy.shared.FileArchive;
32
33 /**
34  * Application PUBLIC identifier test
35  * The application deployment descriptor has PUBLIC identifier with
36  * a PubidLiteral of "-//Sun Microsystems, Inc.//DTD J2EE Application 1.2//EN"
37  */

38 public class AppPublicID extends ApplicationTest implements AppCheck {
39
40     
41     String JavaDoc acceptablePubidLiterals[] = {
42             "-//Sun Microsystems, Inc.//DTD J2EE Application 1.2//EN",
43             "-//Sun Microsystems, Inc.//DTD J2EE Application 1.3//EN" };
44
45     String JavaDoc acceptableURLs[] = {"http://java.sun.com/j2ee/dtds/application_1_2.dtd",
46                    "http://java.sun.com/dtd/application_1_3.dtd"};
47
48     /**
49      * Application PUBLIC identifier test
50      * The application deployment descriptor has PUBLIC identifier with
51      * a PubidLiteral of "-//Sun Microsystems, Inc.//DTD J2EE Application 1.2//EN"
52      *
53      * @param descriptor the Application deployment descriptor
54      *
55      * @return <code>Result</code> the results for this assertion
56      */

57     public Result check(Application descriptor) {
58
59     Result result = getInitializedResult();
60       
61     // open the jar and read the XML deployment descriptor
62
if (descriptor.getSpecVersion().compareTo("1.4") < 0){
63         InputStream deploymentEntry=null;
64
65         String JavaDoc uri = null;
66     try {
67                 uri = getAbstractArchiveUri(descriptor);
68                  FileArchive arch = new FileArchive();
69                  arch.open(uri);
70                  deploymentEntry = arch.getEntry(
71             ApplicationDeploymentDescriptorFile.DESC_PATH);
72
73         if (deploymentEntry != null) {
74         BufferedReader in = new BufferedReader(new InputStreamReader(deploymentEntry));
75         String JavaDoc s = in.readLine();
76         boolean foundDOCTYPE = false, foundPubid = false, foundURL = false;
77
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
87                     (smh.getLocalString
88                     (getClass().getName() + ".passed",
89                     "The deployment descriptor has the proper PubidLiteral: {0}",
90                     new Object JavaDoc[] {acceptablePubidLiterals[i]}));
91                 }
92                 //check if the URLs match as well
93
if (s.indexOf(acceptableURLs[i]) > -1) {
94                 foundURL = true;
95                 result.addGoodDetails
96                     (smh.getLocalString
97                      (getClass().getName() + ".passed1",
98                       "The deployment descriptor has the proper URL corresponding the the PubIdLiteral: {0}",
99                       new Object JavaDoc[] {acceptableURLs[i]}));
100                 }
101                }
102             }
103             if(foundPubid && foundURL) {
104             result.setStatus(Result.PASSED);
105             break;
106             } else if(foundDOCTYPE && s.endsWith(">")) break; // DOCTYPE doesn't have any more lines to check
107
s = in.readLine();
108         }
109
110         if(!foundDOCTYPE){
111             
112         result.failed
113             (smh.getLocalString
114              (getClass().getName() + ".failed1",
115               "No document type declaration found in the deployment descriptor for {0}",
116               new Object JavaDoc[] {descriptor.getName()}));
117         } else if(!foundPubid) {
118             
119         result.failed
120             (smh.getLocalString
121              (getClass().getName() + ".failed2",
122               "The deployment descriptor for {0} does not have the expected PubidLiteral ",
123               new Object JavaDoc[] {descriptor.getName()}));
124         }else if (!foundURL){
125             
126         result.failed(smh.getLocalString
127                        (getClass().getName() + ".failed",
128                             "The deployment descriptor {0} doesnot have the right URL corresponding to the PubIdLiteral",
129                         new Object JavaDoc[] {descriptor.getName()}));
130         }
131         }
132
133     } catch (IOException e) {
134         
135         result.failed(smh.getLocalString
136               (getClass().getName() + ".IOException",
137                "I/O error trying to open {0}", new Object JavaDoc[] {uri}));
138     } finally {
139             try {
140               if (deploymentEntry != null)
141                  deploymentEntry.close();
142             } catch (Exception JavaDoc x) {}
143         }
144          }else{
145                 //NOT APPLICABLE
146
/*result.addNaDetails(smh.getLocalString
147                        ("tests.componentNameConstructor",
148                     "For [ {0} ]",
149                     new Object[] {compName.toString()}));*/

150                 result.notApplicable(smh.getLocalString
151                     (getClass().getName() + ".notApplicable",
152             "NOT-APPLICABLE: No DOCTYPE found for [ {0} ]",
153              new Object JavaDoc[] {descriptor.getName()}));
154             }
155     return result;
156     }
157 }
158
Popular Tags