KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > xml > catalog > CatalogEntry


1 /*
2  * The contents of this file are subject to the terms of the Common Development
3  * and Distribution License (the License). You may not use this file except in
4  * compliance with the License.
5  *
6  * You can obtain a copy of the License at http://www.netbeans.org/cddl.html
7  * or http://www.netbeans.org/cddl.txt.
8  *
9  * When distributing Covered Code, include this CDDL Header Notice in each file
10  * and include the License file at http://www.netbeans.org/cddl.txt.
11  * If applicable, add the following below the CDDL Header, with the fields
12  * enclosed by brackets [] replaced by your own identifying information:
13  * "Portions Copyrighted [year] [name of copyright owner]"
14  *
15  * The Original Software is NetBeans. The Initial Developer of the Original
16  * Software is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun
17  * Microsystems, Inc. All Rights Reserved.
18  */

19 package org.netbeans.modules.xml.catalog;
20
21 import org.xml.sax.*;
22
23 import org.netbeans.modules.xml.catalog.spi.CatalogReader;
24
25 /**
26  * Represents catalog entry keyed by a public ID.
27  * The implementation is not cached it queries underlaying catalog.
28  *
29  * @author Petr Kuzel
30  * @version 1.0
31  */

32 public final class CatalogEntry extends Object JavaDoc {
33
34     private final String JavaDoc publicID;
35     private final CatalogReader catalog;
36
37     /** Creates new CatalogEntry */
38     public CatalogEntry(String JavaDoc publicID, CatalogReader catalog) {
39         this.publicID = publicID;
40         this.catalog = catalog;
41     }
42     
43     CatalogReader getCatalog() {
44         return catalog;
45     }
46
47     /**
48      * Use CatalogReader or alternatively EntityResolver interface to resolve the PID.
49      */

50     public String JavaDoc getSystemID() {
51         String JavaDoc sid = catalog.getSystemID(publicID);
52         if (sid == null) {
53             if (catalog instanceof EntityResolver) {
54                 try {
55                     InputSource in = ((EntityResolver) catalog).resolveEntity(publicID, null);
56                     if (in != null) {
57                         sid = in.getSystemId();
58                     }
59                 } catch (Exception JavaDoc ex) {
60                     // return null;
61
}
62             }
63         }
64
65         //#53710 URL space canonization (%20 form works in most cases)
66
String JavaDoc patchedSystemId = sid;
67         if (patchedSystemId != null) {
68             patchedSystemId = patchedSystemId.replaceAll("\\+", "%20"); // NOI18N
69
patchedSystemId = patchedSystemId.replaceAll("\\ ", "%20"); // NOI18N
70
return patchedSystemId;
71         }
72
73         return null;
74     }
75     
76     public String JavaDoc getPublicID() {
77         return publicID;
78     }
79     
80     public String JavaDoc getPublicIDValue() {
81         String JavaDoc id = getPublicID();
82         if (id.startsWith("PUBLIC:")) return id.substring(7); //NOI18N
83
if (id.startsWith("URI:")) return id.substring(4); //NOI18N
84
if (id.startsWith("SYSTEM:")) return ""; //NOI18N
85
if (id.startsWith("SCHEMA:")) return ""; //NOI18N
86
return id;
87     }
88     
89     public String JavaDoc getSystemIDValue() {
90         String JavaDoc id = getPublicID();
91         if (id.startsWith("SYSTEM:")) return id.substring(7); //NOI18N
92
if (id.startsWith("SCHEMA:")) return id.substring(7); //NOI18N
93
return "";
94     }
95     
96     public String JavaDoc getUriValue() {
97         return getSystemID();
98     }
99     
100     public String JavaDoc getName() {
101         String JavaDoc id = getPublicID();
102         if (id.startsWith("PUBLIC:")) return Util.THIS.getString("TXT_publicEntry",id.substring(7)); //NOI18N
103
if (id.startsWith("SYSTEM:")) return Util.THIS.getString("TXT_systemEntry",id.substring(7)); //NOI18N
104
if (id.startsWith("URI:")) return Util.THIS.getString("TXT_publicEntry",id.substring(4)); //NOI18N
105
if (id.startsWith("SCHEMA:")) return Util.THIS.getString("TXT_systemEntry",id.substring(7)); //NOI18N
106
return Util.THIS.getString("TXT_publicEntry",id);
107     }
108     
109     public String JavaDoc toString() {
110         return publicID + " => " + getSystemID(); // NOI18N
111
}
112 }
113
Popular Tags