KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > web > jsf > JSFCatalog


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
21 package org.netbeans.modules.web.jsf;
22
23
24 import org.netbeans.modules.web.jsf.api.facesmodel.JSFVersion;
25 import org.netbeans.modules.xml.catalog.spi.*;
26 import org.openide.util.NbBundle;
27 import org.openide.util.Utilities;
28 import org.w3c.dom.Document JavaDoc;
29 import org.w3c.dom.DocumentType JavaDoc;
30
31 /**
32  *
33  * @author Petr Pisl
34  */

35 public class JSFCatalog implements CatalogReader, CatalogDescriptor, org.xml.sax.EntityResolver JavaDoc {
36
37     private static final String JavaDoc JSF_ID_1_0 = "-//Sun Microsystems, Inc.//DTD JavaServer Faces Config 1.0//EN"; // NOI18N
38
private static final String JavaDoc JSF_ID_1_1 = "-//Sun Microsystems, Inc.//DTD JavaServer Faces Config 1.1//EN"; // NOI18N
39

40     private static final String JavaDoc URL_JSF_1_0 ="nbres:/org/netbeans/modules/web/jsf/resources/web-facesconfig_1_0.dtd"; // NOI18N
41
private static final String JavaDoc URL_JSF_1_1 ="nbres:/org/netbeans/modules/web/jsf/resources/web-facesconfig_1_1.dtd"; // NOI18N
42

43     public static final String JavaDoc JAVAEE_NS = "http://java.sun.com/xml/ns/javaee"; // NOI18N
44
private static final String JavaDoc JSF_1_2_XSD="web-facesconfig_1_2.xsd"; // NOI18N
45
private static final String JavaDoc JSF_1_2=JAVAEE_NS+"/"+JSF_1_2_XSD; // NOI18N
46
public static final String JavaDoc JSF_ID_1_2="SCHEMA:"+JSF_1_2; // NOI18N
47
private static final String JavaDoc URL_JSF_1_2="nbres:/org/netbeans/modules/web/jsf/resources/web-facesconfig_1_2.xsd"; // NOI18N
48
private static final String JavaDoc URL_JSF_1_2_DTD="nbres:/org/netbeans/modules/web/jsf/resources/web-facesconfig_1_2.dtd"; // NOI18N
49

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

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

70     public String JavaDoc getSystemID(String JavaDoc publicId) {
71         if (JSF_ID_1_0.equals(publicId))
72             return URL_JSF_1_0;
73         else if (JSF_ID_1_1.equals(publicId))
74             return URL_JSF_1_1;
75         else if (JSF_ID_1_2.equals(publicId))
76             return URL_JSF_1_2_DTD;
77         else return null;
78     }
79     
80     /**
81      * Refresh content according to content of mounted catalog.
82      */

83     public void refresh() {
84     }
85     
86     /**
87      * Optional operation allowing to listen at catalog for changes.
88      * @throws UnsupportedOpertaionException if not supported by the implementation.
89      */

90     public void addCatalogListener(CatalogListener l) {
91     }
92     
93     /**
94      * Optional operation couled with addCatalogListener.
95      * @throws UnsupportedOpertaionException if not supported by the implementation.
96      */

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

111     public String JavaDoc getDisplayName() {
112         return NbBundle.getMessage (JSFCatalog.class, "LBL_JSFCatalog");
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/web/jsf/resources/JSFCatalog.png"); // NOI18N
122
}
123     
124     /**
125      * @return I18N short description
126      */

127     public String JavaDoc getShortDescription() {
128         return NbBundle.getMessage (JSFCatalog.class, "DESC_JSFCatalog");
129     }
130     
131    /**
132      * Resolves schema definition file for taglib descriptor (spec.1_1, 1_2, 2_0)
133      * @param publicId publicId for resolved entity (null in our case)
134      * @param systemId systemId for resolved entity
135      * @return InputSource for publisId,
136      */

137     public org.xml.sax.InputSource JavaDoc resolveEntity(String JavaDoc publicId, String JavaDoc systemId) throws org.xml.sax.SAXException JavaDoc, java.io.IOException JavaDoc {
138        if (JSF_ID_1_0.equals(publicId)) {
139             return new org.xml.sax.InputSource JavaDoc(URL_JSF_1_0);
140         } else if (JSF_ID_1_1.equals(publicId)) {
141             return new org.xml.sax.InputSource JavaDoc(URL_JSF_1_1);
142         } else if (JSF_1_2.equals(systemId)) {
143             return new org.xml.sax.InputSource JavaDoc(URL_JSF_1_2);
144         } else if (systemId!=null && systemId.endsWith(JSF_1_2_XSD)) {
145             return new org.xml.sax.InputSource JavaDoc(URL_JSF_1_2);
146         } else {
147             return null;
148         }
149     }
150     
151     /**
152      * Get registered URI for the given name or null if not registered.
153      * @return null if not registered
154      */

155     public String JavaDoc resolveURI(String JavaDoc name) {
156         return null;
157     }
158     /**
159      * Get registered URI for the given publicId or null if not registered.
160      * @return null if not registered
161      */

162     public String JavaDoc resolvePublic(String JavaDoc publicId) {
163         return null;
164     }
165     
166     public static JSFVersion extractVersion(Document JavaDoc document) {
167         // first check the doc type to see if there is one
168
DocumentType JavaDoc dt = document.getDoctype();
169         JSFVersion value = JSFVersion.JSF_1_0;
170         // This is the default version
171
if (dt != null) {
172             if (JSF_ID_1_0.equals(dt.getPublicId())) {
173                 value = JSFVersion.JSF_1_0;
174             }
175             if (JSF_ID_1_1.equals(dt.getPublicId())) {
176                 value = JSFVersion.JSF_1_1;
177             }
178             if (JSF_ID_1_2.equals(dt.getPublicId())) {
179                 value = JSFVersion.JSF_1_2;
180             }
181         }
182         return value;
183
184     }
185     
186 }
187
Popular Tags