KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > j2ee > jboss4 > ide > JBFindJSPServlet


1 /*
2  * The contents of this file are subject to the terms of the Common Development
3  * and Distribution License (the License). You may not use this file except in
4  * compliance with the License.
5  *
6  * You can obtain a copy of the License at http://www.netbeans.org/cddl.html
7  * or http://www.netbeans.org/cddl.txt.
8  *
9  * When distributing Covered Code, include this CDDL Header Notice in each file
10  * and include the License file at http://www.netbeans.org/cddl.txt.
11  * If applicable, add the following below the CDDL Header, with the fields
12  * enclosed by brackets [] replaced by your own identifying information:
13  * "Portions Copyrighted [year] [name of copyright owner]"
14  *
15  * The Original Software is NetBeans. The Initial Developer of the Original
16  * Software is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun
17  * Microsystems, Inc. All Rights Reserved.
18  */

19
20 package org.netbeans.modules.j2ee.jboss4.ide;
21
22 import java.io.File JavaDoc;
23 import org.netbeans.modules.j2ee.deployment.plugins.api.FindJSPServlet;
24 import org.netbeans.modules.j2ee.deployment.plugins.api.InstanceProperties;
25 import org.netbeans.modules.j2ee.jboss4.JBDeploymentManager;
26 import org.netbeans.modules.j2ee.jboss4.ide.ui.JBPluginProperties;
27
28 /**
29  *
30  * @author Libor Kotouc
31  */

32 public class JBFindJSPServlet implements FindJSPServlet {
33     
34     JBDeploymentManager dm;
35     
36     public JBFindJSPServlet(JBDeploymentManager manager) {
37         dm = manager;
38     }
39
40     public File JavaDoc getServletTempDirectory(String JavaDoc moduleContextPath) {
41         InstanceProperties ip = dm.getInstanceProperties();
42         String JavaDoc domainPath = ip.getProperty(JBPluginProperties.PROPERTY_SERVER_DIR);
43         File JavaDoc servletRoot = new File JavaDoc(domainPath, "work/jboss.web/localhost".replace('/', File.separatorChar)); // NOI18N
44
String JavaDoc contextRootPath = getContextRootPath(moduleContextPath);
45         File JavaDoc workDir = new File JavaDoc(servletRoot, contextRootPath);
46         return workDir;
47     }
48
49     private String JavaDoc getContextRootPath(String JavaDoc moduleContextPath) {
50         if (moduleContextPath.startsWith("/")) {
51             moduleContextPath = moduleContextPath.substring(1);
52         }
53         if (moduleContextPath.length() == 0) {
54             moduleContextPath = "/";
55         }
56         
57         return moduleContextPath.replace('/', '_');
58     }
59     
60     public String JavaDoc getServletResourcePath(String JavaDoc moduleContextPath, String JavaDoc jspResourcePath) {
61
62         String JavaDoc path = null;
63         
64         String JavaDoc extension = jspResourcePath.substring(jspResourcePath.lastIndexOf("."));
65         if (".jsp".equals(extension)) { // NOI18N
66
String JavaDoc pkgName = getServletPackageName(jspResourcePath);
67             String JavaDoc pkgPath = pkgName.replace('.', '/');
68             String JavaDoc clzName = getServletClassName(jspResourcePath);
69             path = pkgPath + '/' + clzName + ".java"; // NOI18N
70
}
71         
72         return path;
73     }
74
75     // copied from org.apache.jasper.JspCompilationContext
76
public String JavaDoc getServletPackageName(String JavaDoc jspUri) {
77         String JavaDoc dPackageName = getDerivedPackageName(jspUri);
78         if (dPackageName.length() == 0) {
79             return JspNameUtil.JSP_PACKAGE_NAME;
80         }
81         return JspNameUtil.JSP_PACKAGE_NAME + '.' + getDerivedPackageName(jspUri);
82     }
83     
84     // copied from org.apache.jasper.JspCompilationContext
85
private String JavaDoc getDerivedPackageName(String JavaDoc jspUri) {
86         int iSep = jspUri.lastIndexOf('/');
87         return (iSep > 0) ? JspNameUtil.makeJavaPackage(jspUri.substring(0,iSep)) : "";
88     }
89     
90     // copied from org.apache.jasper.JspCompilationContext
91
public String JavaDoc getServletClassName(String JavaDoc jspUri) {
92         int iSep = jspUri.lastIndexOf('/') + 1;
93         return JspNameUtil.makeJavaIdentifier(jspUri.substring(iSep));
94     }
95     
96     public String JavaDoc getServletEncoding(String JavaDoc moduleContextPath, String JavaDoc jspResourcePath) {
97         return "UTF8"; // NOI18N
98
}
99     
100     
101     
102 }
103
Popular Tags