KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > sun > enterprise > tools > verifier > tests > appclient > AppClientPublicID


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.appclient;
24
25 import java.io.*;
26
27 import com.sun.enterprise.deployment.*;
28 import com.sun.enterprise.deployment.io.DescriptorConstants;
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  * Application Client PUBLIC identifier test
36  * The application client deployment descriptor has PUBLIC identifier with
37  * a PubidLiteral of
38  * "-//Sun Microsystems, Inc.//DTD J2EE Application Client 1.2//EN"
39  * "-//Sun Microsystems, Inc.//DTD J2EE Application Client 1.3//EN"
40  */

41 public class AppClientPublicID extends AppClientTest implements AppClientCheck {
42
43     String JavaDoc acceptablePubidLiterals[] = {
44             "-//Sun Microsystems, Inc.//DTD J2EE Application Client 1.2//EN",
45             "-//Sun Microsystems, Inc.//DTD J2EE Application Client 1.3//EN" };
46
47     String JavaDoc acceptableURLs[] = {"http://java.sun.com/j2ee/dtds/application-client_1_2.dtd",
48                    "http://java.sun.com/dtd/application-client_1_3.dtd"};
49
50
51     /**
52      * Application Client PUBLIC identifier test
53      * The application client deployment descriptor has PUBLIC identifier with
54      * a PubidLiteral of
55      * "-//Sun Microsystems, Inc.//DTD J2EE Application Client 1.2//EN"
56      *
57      * @param descriptor the app-client deployment descriptor
58      *
59      * @return <code>Result</code> the results for this assertion
60      */

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