001: /*
002: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
003: *
004: * Copyright 1997-2007 Sun Microsystems, Inc. All rights reserved.
005: *
006: * The contents of this file are subject to the terms of either the GNU
007: * General Public License Version 2 only ("GPL") or the Common
008: * Development and Distribution License("CDDL") (collectively, the
009: * "License"). You may not use this file except in compliance with the
010: * License. You can obtain a copy of the License at
011: * http://www.netbeans.org/cddl-gplv2.html
012: * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
013: * specific language governing permissions and limitations under the
014: * License. When distributing the software, include this License Header
015: * Notice in each file and include the License file at
016: * nbbuild/licenses/CDDL-GPL-2-CP. Sun designates this
017: * particular file as subject to the "Classpath" exception as provided
018: * by Sun in the GPL Version 2 section of the License file that
019: * accompanied this code. If applicable, add the following below the
020: * License Header, with the fields enclosed by brackets [] replaced by
021: * your own identifying information:
022: * "Portions Copyrighted [year] [name of copyright owner]"
023: *
024: * Contributor(s):
025: *
026: * The Original Software is NetBeans. The Initial Developer of the Original
027: * Software is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun
028: * Microsystems, Inc. All Rights Reserved.
029: *
030: * If you wish your version of this file to be governed by only the CDDL
031: * or only the GPL Version 2, indicate your decision by adding
032: * "[Contributor] elects to include this software in this distribution
033: * under the [CDDL or GPL Version 2] license." If you do not indicate a
034: * single choice of license, a recipient has the option to distribute
035: * your version of this file under either the CDDL, the GPL Version 2 or
036: * to extend the choice of license to its licensees as provided above.
037: * However, if you add GPL Version 2 code and therefore, elected the GPL
038: * Version 2 license, then the option applies only if the new code is
039: * made subject to such option by the copyright holder.
040: */
041:
042: package org.netbeans.modules.web.jsf;
043:
044: import org.netbeans.modules.web.jsf.api.facesmodel.JSFVersion;
045: import org.netbeans.modules.xml.catalog.spi.*;
046: import org.openide.util.NbBundle;
047: import org.openide.util.Utilities;
048: import org.w3c.dom.Document;
049: import org.w3c.dom.DocumentType;
050:
051: /**
052: *
053: * @author Petr Pisl
054: */
055: public class JSFCatalog implements CatalogReader, CatalogDescriptor,
056: org.xml.sax.EntityResolver {
057:
058: private static final String JSF_ID_1_0 = "-//Sun Microsystems, Inc.//DTD JavaServer Faces Config 1.0//EN"; // NOI18N
059: private static final String JSF_ID_1_1 = "-//Sun Microsystems, Inc.//DTD JavaServer Faces Config 1.1//EN"; // NOI18N
060:
061: private static final String URL_JSF_1_0 = "nbres:/org/netbeans/modules/web/jsf/resources/web-facesconfig_1_0.dtd"; // NOI18N
062: private static final String URL_JSF_1_1 = "nbres:/org/netbeans/modules/web/jsf/resources/web-facesconfig_1_1.dtd"; // NOI18N
063:
064: public static final String JAVAEE_NS = "http://java.sun.com/xml/ns/javaee"; // NOI18N
065: private static final String JSF_1_2_XSD = "web-facesconfig_1_2.xsd"; // NOI18N
066: private static final String JSF_1_2 = JAVAEE_NS + "/" + JSF_1_2_XSD; // NOI18N
067: public static final String JSF_ID_1_2 = "SCHEMA:" + JSF_1_2; // NOI18N
068: private static final String URL_JSF_1_2 = "nbres:/org/netbeans/modules/web/jsf/resources/web-facesconfig_1_2.xsd"; // NOI18N
069:
070: /** Creates a new instance of StrutsCatalog */
071: public JSFCatalog() {
072: }
073:
074: /**
075: * Get String iterator representing all public IDs registered in catalog.
076: * @return null if cannot proceed, try later.
077: */
078: public java.util.Iterator getPublicIDs() {
079: java.util.List list = new java.util.ArrayList();
080: list.add(JSF_ID_1_0);
081: list.add(JSF_ID_1_1);
082: list.add(JSF_ID_1_2);
083: return list.listIterator();
084: }
085:
086: /**
087: * Get registered systemid for given public Id or null if not registered.
088: * @return null if not registered
089: */
090: public String getSystemID(String publicId) {
091: if (JSF_ID_1_0.equals(publicId))
092: return URL_JSF_1_0;
093: else if (JSF_ID_1_1.equals(publicId))
094: return URL_JSF_1_1;
095: else if (JSF_ID_1_2.equals(publicId))
096: return URL_JSF_1_2;
097: else
098: return null;
099: }
100:
101: /**
102: * Refresh content according to content of mounted catalog.
103: */
104: public void refresh() {
105: }
106:
107: /**
108: * Optional operation allowing to listen at catalog for changes.
109: * @throws UnsupportedOpertaionException if not supported by the implementation.
110: */
111: public void addCatalogListener(CatalogListener l) {
112: }
113:
114: /**
115: * Optional operation couled with addCatalogListener.
116: * @throws UnsupportedOpertaionException if not supported by the implementation.
117: */
118: public void removeCatalogListener(CatalogListener l) {
119: }
120:
121: /** Registers new listener. */
122: public void addPropertyChangeListener(
123: java.beans.PropertyChangeListener l) {
124: }
125:
126: /** Unregister the listener. */
127: public void removePropertyChangeListener(
128: java.beans.PropertyChangeListener l) {
129: }
130:
131: /**
132: * @return I18N display name
133: */
134: public String getDisplayName() {
135: return NbBundle.getMessage(JSFCatalog.class, "LBL_JSFCatalog");
136: }
137:
138: /**
139: * Return visuaized state of given catalog.
140: * @param type of icon defined by JavaBeans specs
141: * @return icon representing current state or null
142: */
143: public java.awt.Image getIcon(int type) {
144: return Utilities
145: .loadImage("org/netbeans/modules/web/jsf/resources/JSFCatalog.png"); // NOI18N
146: }
147:
148: /**
149: * @return I18N short description
150: */
151: public String getShortDescription() {
152: return NbBundle.getMessage(JSFCatalog.class, "DESC_JSFCatalog");
153: }
154:
155: /**
156: * Resolves schema definition file for taglib descriptor (spec.1_1, 1_2, 2_0)
157: * @param publicId publicId for resolved entity (null in our case)
158: * @param systemId systemId for resolved entity
159: * @return InputSource for publisId,
160: */
161: public org.xml.sax.InputSource resolveEntity(String publicId,
162: String systemId) throws org.xml.sax.SAXException,
163: java.io.IOException {
164: if (JSF_ID_1_0.equals(publicId)) {
165: return new org.xml.sax.InputSource(URL_JSF_1_0);
166: } else if (JSF_ID_1_1.equals(publicId)) {
167: return new org.xml.sax.InputSource(URL_JSF_1_1);
168: } else if (JSF_1_2.equals(systemId)) {
169: return new org.xml.sax.InputSource(URL_JSF_1_2);
170: } else if (systemId != null && systemId.endsWith(JSF_1_2_XSD)) {
171: return new org.xml.sax.InputSource(URL_JSF_1_2);
172: } else {
173: return null;
174: }
175: }
176:
177: /**
178: * Get registered URI for the given name or null if not registered.
179: * @return null if not registered
180: */
181: public String resolveURI(String name) {
182: return null;
183: }
184:
185: /**
186: * Get registered URI for the given publicId or null if not registered.
187: * @return null if not registered
188: */
189: public String resolvePublic(String publicId) {
190: return null;
191: }
192:
193: public static JSFVersion extractVersion(Document document) {
194: // first check the doc type to see if there is one
195: DocumentType dt = document.getDoctype();
196: JSFVersion value = JSFVersion.JSF_1_0;
197: // This is the default version
198: if (dt != null) {
199: if (JSF_ID_1_0.equals(dt.getPublicId())) {
200: value = JSFVersion.JSF_1_0;
201: }
202: if (JSF_ID_1_1.equals(dt.getPublicId())) {
203: value = JSFVersion.JSF_1_1;
204: }
205: if (JSF_ID_1_2.equals(dt.getPublicId())) {
206: value = JSFVersion.JSF_1_2;
207: }
208: }
209: return value;
210:
211: }
212:
213: }
|