1 19 20 package org.netbeans.modules.tomcat5.jsps; 21 22 import java.io.File ; 23 import javax.enterprise.deploy.spi.DeploymentManager ; 24 import org.netbeans.modules.j2ee.deployment.plugins.api.FindJSPServlet; 25 import org.netbeans.modules.tomcat5.TomcatManager; 26 27 31 public class FindJSPServletImpl implements FindJSPServlet { 32 33 private static final String WEB_INF_TAGS = "WEB-INF/tags/"; 34 private static final String META_INF_TAGS = "META-INF/tags/"; 35 36 private TomcatManager tm; 37 38 39 public FindJSPServletImpl(DeploymentManager manager) { 40 tm = (TomcatManager)manager; 41 } 42 43 44 public File getServletTempDirectory(String moduleContextPath) { 45 File baseDir = tm.getTomcatProperties().getCatalinaDir(); 46 if ((baseDir == null) || !baseDir.exists()) { 47 return null; 48 } 49 File hostBase = new File (baseDir, "work/Catalina/localhost".replace('/', File.separatorChar)); 50 File workDir = new File (hostBase, getContextRootString(moduleContextPath)); 51 return workDir; 53 } 54 55 private String getContextRootString(String moduleContextPath) { 56 String contextRootPath = moduleContextPath; 57 if (contextRootPath.startsWith("/")) { 58 contextRootPath = contextRootPath.substring(1); 59 } 60 if (contextRootPath.equals("")) { 61 return "_"; 62 } 63 else { 64 return contextRootPath; 65 } 66 } 67 68 public String getServletResourcePath(String moduleContextPath, String jspResourcePath) { 69 71 String path = getTagHandlerClassName(jspResourcePath); 73 if (path != null) path = path.replace('.', '/') + ".java"; 75 else path = getServletPackageName(jspResourcePath).replace('.', '/') + '/' + 77 getServletClassName(jspResourcePath) + ".java"; 78 79 return path; 80 81 } 84 85 public String getServletPackageName(String jspUri) { 87 String dPackageName = getDerivedPackageName(jspUri); 88 if (dPackageName.length() == 0) { 89 return JspNameUtil.JSP_PACKAGE_NAME; 90 } 91 return JspNameUtil.JSP_PACKAGE_NAME + '.' + getDerivedPackageName(jspUri); 92 } 93 94 private String getDerivedPackageName(String jspUri) { 96 int iSep = jspUri.lastIndexOf('/'); 97 return (iSep > 0) ? JspNameUtil.makeJavaPackage(jspUri.substring(0,iSep)) : ""; 98 } 99 100 public String getServletClassName(String jspUri) { 102 int iSep = jspUri.lastIndexOf('/') + 1; 103 return JspNameUtil.makeJavaIdentifier(jspUri.substring(iSep)); 104 } 105 106 public String getServletEncoding(String moduleContextPath, String jspResourcePath) { 107 return "UTF8"; } 109 110 121 private String getTagHandlerClassName(String path) { 122 123 String className = null; 124 int begin = 0; 125 int index; 126 127 index = path.lastIndexOf(".tag"); 128 if (index == -1) { 129 return null; 130 } 131 132 index = path.indexOf(WEB_INF_TAGS); 133 if (index != -1) { 134 className = "org.apache.jsp.tag.web."; 135 begin = index + WEB_INF_TAGS.length(); 136 } else { 137 index = path.indexOf(META_INF_TAGS); 138 if (index != -1) { 139 className = "org.apache.jsp.tag.meta."; 140 begin = index + META_INF_TAGS.length(); 141 } else { 142 return null; 143 } 144 } 145 146 className += JspNameUtil.makeJavaPackage(path.substring(begin)); 147 148 return className; 149 } 150 151 } 152 | Popular Tags |