1 19 20 package org.netbeans.modules.web.core.jsploader; 21 22 import java.io.File ; 23 import java.io.IOException ; 24 import java.net.URI ; 25 import java.util.*; 26 import org.netbeans.modules.j2ee.deployment.devmodules.api.JSPServletFinder; 27 import org.netbeans.modules.j2ee.deployment.devmodules.spi.J2eeModuleProvider; 28 import org.netbeans.modules.web.api.webmodule.WebModule; 29 30 import org.openide.ErrorManager; 31 32 import org.openide.filesystems.*; 33 34 43 public class CompileData { 44 45 private JspDataObject jspPage; 46 private FileObject docRoot; 47 private String servletEncoding; 49 50 private final static boolean debug = false; 51 52 private File servletJavaRoot; 53 private String servletResourceName; 54 55 56 57 public CompileData(JspDataObject jspPage) { 58 this.jspPage = jspPage; 59 WebModule wm = WebModule.getWebModule (jspPage.getPrimaryFile()); 60 if (wm != null) { 61 this.docRoot = wm.getDocumentBase (); 62 String jspResourcePath = JspCompileUtil.findRelativeContextPath(docRoot, jspPage.getPrimaryFile()); 63 JSPServletFinder finder = JSPServletFinder.findJSPServletFinder (docRoot); 64 servletJavaRoot = finder.getServletTempDirectory(); 65 servletResourceName = finder.getServletResourcePath(jspResourcePath); 66 servletEncoding = finder.getServletEncoding(jspResourcePath); 67 } 68 } 69 70 public FileObject getServletJavaRoot() { 71 if ((servletJavaRoot != null) && servletJavaRoot.exists()) { 72 return FileUtil.toFileObject(servletJavaRoot); 73 } 74 else { 75 return null; 76 } 77 } 78 79 83 84 public String getServletResourceName() { 85 return servletResourceName; 86 } 87 88 private File getServletFile() { 89 if (servletJavaRoot == null) { 90 return null; 91 } 92 URI rootURI = servletJavaRoot.toURI(); 93 URI servletURI = rootURI.resolve(servletResourceName); 94 return new File (servletURI); 95 } 96 97 public FileObject getServletFileObject() { 98 FileObject root = getServletJavaRoot(); 99 if (root == null) { 100 return null; 101 } 102 File servlet = getServletFile(); 103 if ((servlet == null) || !servlet.exists()) { 104 return null; 105 } 106 107 FileObject fo = FileUtil.toFileObject(FileUtil.normalizeFile(servlet)); 108 if (fo != null) { 109 return fo; 110 } 111 try { 112 FileSystem rootFs = root.getFileSystem(); 113 root.getFileSystem().refresh(false); 114 return root.getFileObject(getServletResourceName()); 115 } 116 catch (FileStateInvalidException e) { 117 ErrorManager.getDefault().notify(ErrorManager.INFORMATIONAL, e); 118 } 119 120 return null; 121 } 122 123 124 125 public String getServletEncoding() { 126 return servletEncoding; 127 } 128 129 public String toString() { 130 StringBuffer sb = new StringBuffer (); 131 sb.append("--COMPILE DATA--"); sb.append("\n"); sb.append("JSP page : " + FileUtil.getFileDisplayName(jspPage.getPrimaryFile())); sb.append("\n"); sb.append("servletJavaRoot : " + servletJavaRoot + ", exists= " + ((servletJavaRoot == null) ? "false" : "" + servletJavaRoot.exists())); sb.append("\n"); sb.append("servletResource : " + servletResourceName + ", fileobject exists= " + (getServletFileObject() != null)); sb.append("\n"); File sf = getServletFile(); 144 if (sf != null) { 145 sb.append("servletFile : " + sf.getAbsolutePath() + ", exists= " + getServletFile().exists()); } 148 else { 149 sb.append("servletFile : null"); } 151 sb.append("\n"); sb.append("--end COMPILE DATA--"); return sb.toString(); 154 } 155 156 } 157 | Popular Tags |