1 19 20 package org.netbeans.modules.j2ee.sun.ws7.j2ee.jsp; 21 22 import java.io.File ; 23 import java.lang.reflect.Method ; 24 import javax.enterprise.deploy.spi.DeploymentManager ; 25 import javax.enterprise.deploy.spi.Target ; 26 import org.netbeans.modules.j2ee.deployment.plugins.api.FindJSPServlet; 27 28 import org.netbeans.modules.j2ee.sun.ws7.dm.WS70SunDeploymentManager; 29 import org.netbeans.modules.j2ee.sun.ws7.dm.WS70SunDeploymentFactory; 30 31 35 public class JSPServletFinder implements FindJSPServlet { 36 37 private WS70SunDeploymentManager manager; 38 39 42 public JSPServletFinder(DeploymentManager dm) { 43 44 String uri = ((WS70SunDeploymentManager)dm).getUri(); 45 manager = WS70SunDeploymentFactory.getConnectedCachedDeploymentManager(uri); 46 } 47 48 public File getServletTempDirectory(String moduleContextPath) { 49 Target defaultTarget = manager.getDefaultTarget(); 50 51 if(defaultTarget == null){ 52 return null; 54 } 55 String configName = null; 56 String vsName = null; 57 try{ 58 Method getConfigName = defaultTarget.getClass().getDeclaredMethod("getConfigName", new Class []{}); 59 configName = (String )getConfigName.invoke(defaultTarget, new Object []{}); 60 Method getVSName = defaultTarget.getClass().getDeclaredMethod("getVSName", new Class []{}); 61 vsName = (String )getVSName.invoke(defaultTarget, new Object []{}); 62 }catch(Exception e){ 63 return null; 65 } 66 67 String location = manager.getServerLocation()+File.separator+"https-"+configName+ 68 File.separator+"ClassCache"+File.separator+vsName+File.separator; 69 File workDir = new File (location, getContextRootString(moduleContextPath)); 70 return workDir; 71 } 72 73 private String getContextRootString(String moduleContextPath) { 74 String contextRootPath = moduleContextPath; 75 if (contextRootPath.startsWith("/")) { 76 contextRootPath = contextRootPath.substring(1); 77 } 78 return contextRootPath; 79 80 } 81 82 public String getServletResourcePath(String moduleContextPath, String jspResourcePath) { 83 String path= getServletPackageName(jspResourcePath).replace('.', '/') + '/' + 84 getServletClassName(jspResourcePath) + ".java"; 85 return path; 86 } 87 public String getServletEncoding(String moduleContextPath, String jspResourcePath) { 88 return "UTF8"; } 90 private String getServletPackageName(String jspUri) { 92 String dPackageName = getDerivedPackageName(jspUri); 93 if (dPackageName.length() == 0) { 94 return JspNameUtil.JSP_PACKAGE_NAME; 95 } 96 return JspNameUtil.JSP_PACKAGE_NAME + '.' + getDerivedPackageName(jspUri); 97 } 98 99 private String getDerivedPackageName(String jspUri) { 101 int iSep = jspUri.lastIndexOf('/'); 102 return (iSep > 0) ? JspNameUtil.makeJavaPackage(jspUri.substring(0,iSep)) : ""; 103 } 104 105 private String getServletClassName(String jspUri) { 107 int iSep = jspUri.lastIndexOf('/') + 1; 108 return JspNameUtil.makeJavaIdentifier(jspUri.substring(iSep)); 109 } 110 } 111 | Popular Tags |