1 19 20 21 package org.netbeans.modules.web.core.jsploader; 22 23 import java.beans.PropertyChangeListener ; 24 import java.beans.PropertyChangeSupport ; 25 import java.io.File ; 26 import java.io.IOException ; 27 import java.io.InputStream ; 28 import org.netbeans.api.java.classpath.ClassPath; 29 import org.netbeans.api.project.FileOwnerQuery; 30 import org.netbeans.api.project.Project; 31 import org.netbeans.modules.j2ee.deployment.devmodules.api.Deployment; 32 import org.netbeans.modules.j2ee.deployment.devmodules.api.J2eePlatform; 33 import org.netbeans.modules.j2ee.deployment.devmodules.spi.J2eeModuleProvider; 34 35 import org.netbeans.modules.web.jsps.parserapi.JspParserAPI; 36 import org.netbeans.modules.web.api.webmodule.WebModule; 37 import org.openide.ErrorManager; 38 import org.openide.cookies.EditorCookie; 39 import org.openide.filesystems.FileObject; 40 import org.openide.loaders.DataObject; 41 import org.openide.text.CloneableEditorSupport; 42 import org.openide.util.WeakListeners; 43 44 public class JspParserAccess { 45 46 public static synchronized JspParserAPI.WebModule getJspParserWM(WebModule webModule) { 47 return new WM(webModule); 48 } 49 50 53 private static final class WM extends JspParserAPI.WebModule implements PropertyChangeListener { 54 55 WebModule webModule; 56 PropertyChangeSupport pcs; 57 58 62 private WM(WebModule webModule) { 63 this.webModule = webModule; 64 pcs = new PropertyChangeSupport (this); 65 if(webModule != null) { 67 ClassPath cp = ClassPath.getClassPath(webModule.getDocumentBase(), ClassPath.EXECUTE); 68 cp.addPropertyChangeListener(WeakListeners.propertyChange(this, cp)); 69 } 70 } 71 72 public File [] getExtraClasspathEntries(){ 73 File [] entries = null; 74 if (webModule != null){ 75 Project p = FileOwnerQuery.getOwner(webModule.getDocumentBase()); 76 J2eeModuleProvider jprovider = (J2eeModuleProvider)p.getLookup().lookup(J2eeModuleProvider.class); 77 if (jprovider != null){ 78 String serverID = jprovider.getServerInstanceID(); 79 J2eePlatform platform = Deployment.getDefault().getJ2eePlatform(serverID); 80 if (platform != null) 82 entries = platform.getClasspathEntries(); 83 } 84 85 86 } 87 return entries; 88 } 89 90 public FileObject getDocumentBase() { 91 if (webModule != null) 92 return webModule.getDocumentBase(); 93 return null; 94 } 95 96 99 public java.io.InputStream getEditorInputStream(FileObject fo) { 100 InputStream result = null; 101 EditorCookie ec = null; 102 try { 103 104 ec = (EditorCookie)(DataObject.find(fo)).getCookie(EditorCookie.class); 105 } catch (org.openide.loaders.DataObjectNotFoundException e){ 106 ErrorManager.getDefault().notify(ErrorManager.INFORMATIONAL, e); 107 } 108 if (ec != null && (ec instanceof CloneableEditorSupport)) { 109 try { 110 111 result = ((CloneableEditorSupport)ec).getInputStream(); 112 } catch (IOException e) { 113 ErrorManager.getDefault().notify(ErrorManager.INFORMATIONAL, e); 114 } 115 } 116 return result; 117 } 118 119 120 private void fireLibraries() { 121 firePropertyChange(JspParserAPI.WebModule.PROP_LIBRARIES); 122 } 123 124 private void firePackageRoots() { 125 firePropertyChange(JspParserAPI.WebModule.PROP_PACKAGE_ROOTS); 126 } 127 128 private void firePropertyChange(String propertyName) { 129 pcs.firePropertyChange(propertyName, null, null); 130 } 131 132 143 144 161 162 public void removePropertyChangeListener(PropertyChangeListener l) { 163 pcs.removePropertyChangeListener(l); 164 } 165 166 public void addPropertyChangeListener(PropertyChangeListener l) { 167 pcs.addPropertyChangeListener(l); 168 } 169 170 public void propertyChange(java.beans.PropertyChangeEvent evt) { 171 if (ClassPath.PROP_ENTRIES.equals(evt.getPropertyName())){ 172 fireLibraries(); 173 } 174 if (ClassPath.PROP_ROOTS.equals(evt.getPropertyName())){ 175 firePackageRoots(); 176 } 177 } 178 179 } 180 } 181 | Popular Tags |