KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > sun > enterprise > tools > admingui > handlers > CCEntityResolver


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
24 /*
25  * ViewXMLEntityResolver.java
26  *
27  * Created on December 9, 2003, 11:08 AM
28  */

29
30 package com.sun.enterprise.tools.admingui.handlers;
31
32 import com.iplanet.jato.RequestManager;
33 //import com.sun.web.ui.model.CCDefaultEntityResolver;
34

35 import org.xml.sax.EntityResolver JavaDoc;
36 import org.xml.sax.InputSource JavaDoc;
37 import java.io.File JavaDoc;
38 import java.io.InputStream JavaDoc;
39 import java.net.URL JavaDoc;
40 import javax.servlet.ServletContext JavaDoc;
41
42 /* This entity reolver looks for xml & dtd files that are included as SYSTEM entities
43  * in the java class-path. If the xml file is not found in the class path the
44  * resolver returns null, allowing default mechanism to search for the file
45  * on the file system
46  */

47
48 public class CCEntityResolver implements EntityResolver JavaDoc { //CCDefaultEntityResolver {
49
public InputSource JavaDoc resolveEntity (String JavaDoc publicId, String JavaDoc systemId) {
50         //System.out.print("CCEntityResolver: "+systemId);
51
// Let Lockhart look for the entity first.
52
// InputSource is = super.resolveEntity(publicId, systemId);
53
// if (is != null) {
54
// //System.out.println("BASE CLASS FOUND IT!!!!!);");
55
// return is;
56
// }
57
if (systemId != null && (systemId.startsWith("http")==false) &&
58             (systemId.endsWith(".xml") || systemId.endsWith(".dtd"))) {
59             InputStream JavaDoc resourceStream = null;
60             int i = systemId.indexOf("dtd/");
61             if (i >= 0) {
62                 systemId = "xml/" + systemId.substring(i);
63                 //System.out.println("systemID: " + systemId);
64
// First look in the classpath, the file maybe in a JAR
65
resourceStream = getClass().getClassLoader()
66                     .getResourceAsStream(systemId);
67                 if (resourceStream == null) {
68                     // Next look in the app directory.
69
String JavaDoc sURL = "file:///" +
70                         RequestManager.getRequestContext().getServletContext()
71                         .getRealPath(systemId);
72                     //System.out.println("sURL: " + sURL);
73
try {
74                         resourceStream = new URL JavaDoc(sURL).openStream();
75                     } catch (Exception JavaDoc ex) {
76                         //System.out.println(":::::::::::"+ex.getMessage());
77
}
78                 }
79             }
80             if (resourceStream != null) {
81                 return new InputSource JavaDoc(resourceStream);
82             }
83         }
84         // use the default behaviour
85
//System.out.println("CCEntityResolver: returning NULL");
86
return null;
87     }
88 }
89
Popular Tags