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-2007 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.visualweb.designer.jsf;
043:
044: import java.util.Map;
045: import java.net.URI;
046: import java.net.URISyntaxException;
047: import java.net.URL;
048: import java.util.HashMap;
049: import java.util.Iterator;
050: import java.net.URL;
051:
052: import org.netbeans.modules.visualweb.api.designer.cssengine.CssProvider;
053: import org.openide.ErrorManager;
054: import org.openide.filesystems.FileObject;
055: import org.openide.filesystems.URLMapper;
056:
057: /**
058: * XXX Moved from designer/../DocumentCache
059: * Cache of external JsfForms, to avoid repeated loading and computing of the
060: * layout of external document resources included in our documents
061: * (via say <iframe>)
062: *
063: * @author Tor Norbye
064: */
065: class ExternalDomProviderCache {
066: // private Map<URL, WebForm> forms;
067: private final Map<URL, JsfForm> externals = new HashMap<URL, JsfForm>();
068:
069: /** Construct a new box cache */
070: public ExternalDomProviderCache() {
071: }
072:
073: /** Return number of entries in this cache */
074: public int size() {
075: // return (forms != null) ? forms.size() : 0;
076: return externals.size();
077: }
078:
079: // /** Get a box by a particular URL */
080: // public WebForm get(URL url) {
081: // if (forms == null) {
082: // return null;
083: // }
084: //
085: // WebForm result = forms.get(url);
086: //
087: //// if ((result != null) && (result.getModel() != null) &&
088: //// (result.getModel().isValid())) {
089: // if (result != null && result.isModelValid()) {
090: // forms.put(url, null);
091: // result = null;
092: // }
093: //
094: // return result;
095: // }
096: /** Get a box by a particular URL */
097: public JsfForm get(URL url) {
098: JsfForm result = externals.get(url);
099:
100: // if ((result != null) && (result.getModel() != null) &&
101: // (result.getModel().isValid())) {
102: if (result != null && result.isModelValid()) {
103: externals.put(url, null);
104: result = null;
105: }
106:
107: return result;
108: }
109:
110: // /** Put a box into the cache */
111: // public void put(URL url, WebForm page) {
112: // if (forms == null) {
113: // forms = new HashMap<URL, WebForm>(); // TODO - initial size?
114: // }
115: //
116: // forms.put(url, page);
117: // }
118: /** Put a box into the cache */
119: public void put(URL url, JsfForm page) {
120: externals.put(url, page);
121: }
122:
123: public void remove(URL url) {
124: externals.remove(url);
125: }
126:
127: // /** Clear out the cache */
128: // public void flush() {
129: // if (forms != null) {
130: // // Ensure that the files actually get reloaded from disk;
131: // // NetBeans may be hanging on to old bits in its filesystem
132: // // layer
133: // Iterator<URL> it = forms.keySet().iterator();
134: //
135: // while (it.hasNext()) {
136: // URL url = it.next();
137: // WebForm web = get(url);
138: //
139: // if ((web != null) && (web.getJspDom() != null)) {
140: // // Flush styles as well
141: //// CssLookup.refreshEffectiveStyles(web.getDom());
142: // CssProvider.getEngineService().refreshStylesForDocument(web.getJspDom());
143: // // XXX Should this be here too (or the above?).
144: // CssProvider.getEngineService().refreshStylesForDocument(web.getHtmlDom());
145: // }
146: //
147: // // XXX Lame validity check, missing nice NB API.
148: // try {
149: // new URI(url.toExternalForm());
150: // } catch(URISyntaxException ex) {
151: // // XXX #6368790 It means the url is not valid URI and URLMapper.findFileObject
152: // // would show an exception to the user. We just log it.
153: // ErrorManager.getDefault().notify(ErrorManager.INFORMATIONAL, ex);
154: // continue;
155: // }
156: //
157: // FileObject fo = URLMapper.findFileObject(url);
158: //
159: // if (fo != null) {
160: // fo.refresh(false);
161: // }
162: // }
163: //
164: // forms = null;
165: // }
166: // }
167: /** Clear out the cache */
168: public void flush() {
169: // Ensure that the files actually get reloaded from disk;
170: // NetBeans may be hanging on to old bits in its filesystem
171: // layer
172: Iterator<URL> it = externals.keySet().iterator();
173:
174: while (it.hasNext()) {
175: URL url = it.next();
176: JsfForm web = get(url);
177: // XXX #128283 Possible NPE.
178: // if ((web != null) && (web.getJspDom() != null)) {
179: if (web != null && web.isValid() && web.getJspDom() != null) {
180: // Flush styles as well
181: // CssLookup.refreshEffectiveStyles(web.getDom());
182: CssProvider.getEngineService()
183: .refreshStylesForDocument(web.getJspDom());
184: // XXX Should this be here too (or the above?).
185: CssProvider.getEngineService()
186: .refreshStylesForDocument(web.getHtmlDom());
187: }
188:
189: // XXX Lame validity check, missing nice NB API.
190: try {
191: new URI(url.toExternalForm());
192: } catch (URISyntaxException ex) {
193: // XXX #6368790 It means the url is not valid URI and URLMapper.findFileObject
194: // would show an exception to the user. We just log it.
195: ErrorManager.getDefault().notify(
196: ErrorManager.INFORMATIONAL, ex);
197: continue;
198: }
199:
200: FileObject fo = URLMapper.findFileObject(url);
201:
202: if (fo != null) {
203: fo.refresh(false);
204: }
205: }
206:
207: externals.clear();
208: }
209:
210: @Override
211: public String toString() {
212: return super .toString() + "[externals=" + externals + "]"; // NOI18N
213: }
214: }
|