KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > j2ee > ddloaders > web > DDCatalog


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
20 package org.netbeans.modules.j2ee.ddloaders.web;
21
22 import org.netbeans.modules.xml.catalog.spi.*;
23 import org.openide.util.NbBundle;
24 import org.openide.util.Utilities;
25
26 /** Catalog for web app DTDs that enables completion support in editor.
27  *
28  * @author Milan Kuchtiak
29  */

30 public class DDCatalog implements CatalogReader, CatalogDescriptor,org.xml.sax.EntityResolver JavaDoc {
31     private static final String JavaDoc WEB_APP_2_2="-//Sun Microsystems, Inc.//DTD Web Application 2.2//EN"; // NOI18N
32
private static final String JavaDoc WEB_APP_2_3="-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN"; // NOI18N
33
public static final String JavaDoc J2EE_NS = "http://java.sun.com/xml/ns/j2ee"; // NOI18N
34
private static final String JavaDoc WEB_APP_2_4_XSD="web-app_2_4.xsd"; // NOI18N
35
private static final String JavaDoc WEB_APP_2_4=J2EE_NS+"/"+WEB_APP_2_4_XSD; // NOI18N
36
public static final String JavaDoc WEB_APP_2_4_ID="SCHEMA:"+WEB_APP_2_4; // NOI18N
37
private static final String JavaDoc URL_WEB_APP_2_2="nbres:/org/netbeans/modules/j2ee/ddloaders/web/resources/web-app_2_2.dtd"; // NOI18N
38
private static final String JavaDoc URL_WEB_APP_2_3="nbres:/org/netbeans/modules/j2ee/ddloaders/web/resources/web-app_2_3.dtd"; // NOI18N
39
private static final String JavaDoc URL_WEB_APP_2_4="nbres:/org/netbeans/modules/j2ee/ddloaders/web/resources/web-app_2_4.xsd"; // NOI18N
40
private static final String JavaDoc URL_WEB_APP_2_4_DTD="nbres:/org/netbeans/modules/j2ee/ddloaders/web/resources/web-app_2_4.dtd"; // NOI18N
41
private static final String JavaDoc XML_XSD="http://www.w3.org/2001/xml.xsd"; // NOI18N
42
private static final String JavaDoc XML_XSD_DEF="<?xml version='1.0'?><xs:schema targetNamespace=\"http://www.w3.org/XML/1998/namespace\" xmlns:xs=\"http://www.w3.org/2001/XMLSchema\" xml:lang=\"en\"><xs:attribute name=\"lang\" type=\"xs:language\"><xs:annotation><xs:documentation>In due course, we should install the relevant ISO 2- and 3-letter codes as the enumerated possible values . . .</xs:documentation></xs:annotation></xs:attribute></xs:schema>"; // NOI18N
43

44     public static final String JavaDoc JAVAEE_NS = "http://java.sun.com/xml/ns/javaee"; // NOI18N
45
private static final String JavaDoc WEB_APP_2_5_XSD="web-app_2_5.xsd"; // NOI18N
46
private static final String JavaDoc WEB_APP_2_5=JAVAEE_NS+"/"+WEB_APP_2_5_XSD; // NOI18N
47
public static final String JavaDoc WEB_APP_2_5_ID="SCHEMA:"+WEB_APP_2_5; // NOI18N
48
private static final String JavaDoc URL_WEB_APP_2_5="nbres:/org/netbeans/modules/j2ee/ddloaders/web/resources/web-app_2_5.xsd"; // NOI18N
49
private static final String JavaDoc URL_WEB_APP_2_5_DTD="nbres:/org/netbeans/modules/j2ee/ddloaders/web/resources/web-app_2_5.dtd"; // NOI18N
50

51     /** Creates a new instance of DDCatalog */
52     public DDCatalog() {
53     }
54     
55     /**
56      * Get String iterator representing all public IDs registered in catalog.
57      * @return null if cannot proceed, try later.
58      */

59     public java.util.Iterator JavaDoc getPublicIDs() {
60         java.util.List JavaDoc list = new java.util.ArrayList JavaDoc();
61         list.add(WEB_APP_2_2);
62         list.add(WEB_APP_2_3);
63         list.add(WEB_APP_2_4_ID);
64         list.add(WEB_APP_2_5_ID);
65         return list.listIterator();
66     }
67     
68     /**
69      * Get registered systemid for given public Id or null if not registered.
70      * @return null if not registered
71      */

72     public String JavaDoc getSystemID(String JavaDoc publicId) {
73         if (WEB_APP_2_2.equals(publicId))
74             return URL_WEB_APP_2_2;
75         else if (WEB_APP_2_3.equals(publicId))
76             return URL_WEB_APP_2_3;
77         else if (WEB_APP_2_4_ID.equals(publicId))
78             return URL_WEB_APP_2_4_DTD;
79         else if (WEB_APP_2_5_ID.equals(publicId))
80             return URL_WEB_APP_2_5_DTD;
81         else return null;
82     }
83     
84     /**
85      * Refresh content according to content of mounted catalog.
86      */

87     public void refresh() {
88     }
89     
90     /**
91      * Optional operation allowing to listen at catalog for changes.
92      * @throws UnsupportedOpertaionException if not supported by the implementation.
93      */

94     public void addCatalogListener(CatalogListener l) {
95     }
96     
97     /**
98      * Optional operation couled with addCatalogListener.
99      * @throws UnsupportedOpertaionException if not supported by the implementation.
100      */

101     public void removeCatalogListener(CatalogListener l) {
102     }
103     
104     /** Registers new listener. */
105     public void addPropertyChangeListener(java.beans.PropertyChangeListener JavaDoc l) {
106     }
107     
108     /**
109      * @return I18N display name
110      */

111     public String JavaDoc getDisplayName() {
112         return NbBundle.getMessage (DDCatalog.class, "LBL_DDCatalog");
113     }
114     
115     /**
116      * Return visuaized state of given catalog.
117      * @param type of icon defined by JavaBeans specs
118      * @return icon representing current state or null
119      */

120     public java.awt.Image JavaDoc getIcon(int type) {
121         return Utilities.loadImage("org/netbeans/modules/j2ee/ddloaders/web/resources/DDCatalog.gif"); // NOI18N
122
}
123     
124     /**
125      * @return I18N short description
126      */

127     public String JavaDoc getShortDescription() {
128         return NbBundle.getMessage (DDCatalog.class, "DESC_DDCatalog");
129     }
130     
131     /** Unregister the listener. */
132     public void removePropertyChangeListener(java.beans.PropertyChangeListener JavaDoc l) {
133     }
134     
135     /**
136      * Resolves schema definition file for deployment descriptor (spec.2_4 and spec. 2_5)
137      * @param publicId publicId for resolved entity (null in our case)
138      * @param systemId systemId for resolved entity
139      * @return InputSource for
140      */

141     public org.xml.sax.InputSource JavaDoc resolveEntity(String JavaDoc publicId, String JavaDoc systemId) throws org.xml.sax.SAXException JavaDoc, java.io.IOException JavaDoc {
142         if (WEB_APP_2_4.equals(systemId)) {
143             return new org.xml.sax.InputSource JavaDoc(URL_WEB_APP_2_4);
144         } else if (systemId!=null && systemId.endsWith(WEB_APP_2_4_XSD)) {
145             return new org.xml.sax.InputSource JavaDoc(URL_WEB_APP_2_4);
146         } else if (WEB_APP_2_5.equals(systemId)) {
147             return new org.xml.sax.InputSource JavaDoc(URL_WEB_APP_2_5);
148         } else if (systemId!=null && systemId.endsWith(WEB_APP_2_5_XSD)) {
149             return new org.xml.sax.InputSource JavaDoc(URL_WEB_APP_2_5);
150         } else if (XML_XSD.equals(systemId)) {
151             return new org.xml.sax.InputSource JavaDoc(new java.io.StringReader JavaDoc(XML_XSD_DEF));
152         } else {
153             return null;
154         }
155     }
156     
157     /**
158      * Get registered URI for the given name or null if not registered.
159      * @return null if not registered
160      */

161     public String JavaDoc resolveURI(String JavaDoc name) {
162         return null;
163     }
164     /**
165      * Get registered URI for the given publicId or null if not registered.
166      * @return null if not registered
167      */

168     public String JavaDoc resolvePublic(String JavaDoc publicId) {
169         return null;
170     }
171     
172 }
173
Popular Tags