KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > sun > enterprise > tools > guiframework > view > ViewXMLEntityResolver


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.guiframework.view;
31
32 import com.iplanet.jato.RequestManager;
33
34 import java.io.InputStream JavaDoc;
35 import org.xml.sax.EntityResolver JavaDoc;
36 import org.xml.sax.InputSource JavaDoc;
37 import java.io.File JavaDoc;
38 import javax.servlet.ServletContext JavaDoc;
39
40 /* This entity reolver looks for xml & dtd files that are included as SYSTEM entities
41  * in the java class-path. If the xml file is not found in the class path the
42  * resolver returns null, allowing default mechanism to search for the file
43  * on the file system
44  */

45
46 public class ViewXMLEntityResolver implements EntityResolver JavaDoc {
47     public InputSource JavaDoc resolveEntity (String JavaDoc publicId, String JavaDoc systemId) {
48         if (systemId != null && (systemId.endsWith(".xml") || systemId.endsWith(".dtd"))) {
49             /*
50             System.out.println("(1)publicId = " + publicId + " systemId = " + systemId);
51             int lastIndex = systemId.lastIndexOf("/");
52             System.out.println("lastIndex = " + lastIndex);
53             if (lastIndex >= 0) {
54                 systemId = systemId.substring(lastIndex, systemId.length());
55             }
56             System.out.println("(2)publicId = " + publicId + " systemId = " + systemId);
57              */

58             if (systemId.startsWith("file:///")) {
59                 systemId = systemId.substring(8); // remove file:/// from systemid
60
}
61             InputStream JavaDoc resourceStream = getClass().getClassLoader().getResourceAsStream(systemId);
62             if (resourceStream != null) {
63                 return new InputSource JavaDoc(resourceStream);
64             }
65         }
66       // use the default behaviour
67
return null;
68     }
69 }
Popular Tags