KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > j2ee > sun > ide > j2ee > jsps > FindJSPServletImpl


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.sun.ide.j2ee.jsps;
21
22 import java.io.File JavaDoc;
23 import javax.enterprise.deploy.spi.DeploymentManager JavaDoc;
24 import org.netbeans.modules.j2ee.deployment.plugins.api.FindJSPServlet;
25 import org.netbeans.modules.j2ee.sun.ide.dm.SunDeploymentManager;
26
27 import org.netbeans.modules.j2ee.sun.ide.j2ee.DeploymentManagerProperties;
28
29 /**
30  *
31  * @author Petr Jiricka, adapted by Ludo for 8PE (using tomcat5)
32  */

33 public class FindJSPServletImpl implements FindJSPServlet {
34
35     private DeploymentManager JavaDoc tm;
36
37     /** Creates a new instance of FindJSPServletImpl */
38     public FindJSPServletImpl(DeploymentManager JavaDoc dm) {
39         tm =dm;
40     }
41     
42     public File JavaDoc getServletTempDirectory(String JavaDoc moduleContextPath) {
43
44         DeploymentManagerProperties dmProps = new DeploymentManagerProperties(tm);
45         String JavaDoc domain = dmProps.getDomainName();
46         if (domain==null){
47             domain="domain1";// NOI18N
48
dmProps.setDomainName(domain);
49         }
50     String JavaDoc domainDir = dmProps.getLocation();
51         SunDeploymentManager sunDM = (SunDeploymentManager)tm;
52         String JavaDoc modName = sunDM.getManagement().getWebModuleName(moduleContextPath);
53         //modName may be null, but this does not impact to following logic: in this case, the file will not exist as well.
54
File JavaDoc workDir = new File JavaDoc(domainDir, "/"+domain+"/generated/jsp/j2ee-modules/" +modName);// NOI18N
55
if (!workDir.exists()){ //check for ear file gen area:
56
workDir = new File JavaDoc(domainDir, "/"+domain+"/generated/jsp/j2ee-apps/" +modName);// NOI18N
57

58         }
59        // System.out.println("returning servlet root " + workDir);
60
return workDir;
61     }
62     
63
64     
65     private String JavaDoc getContextRootString(String JavaDoc moduleContextPath) {
66         String JavaDoc contextRootPath = moduleContextPath;
67         if (contextRootPath.startsWith("/")) {// NOI18N
68
contextRootPath = contextRootPath.substring(1);
69         }
70
71             return contextRootPath;
72
73     }
74     
75     public String JavaDoc getServletResourcePath(String JavaDoc moduleContextPath, String JavaDoc jspResourcePath) {
76         //String path = module.getWebURL();
77
String JavaDoc s= getServletPackageName(jspResourcePath).replace('.', '/') + '/' +
78             getServletClassName(jspResourcePath) + ".java";// NOI18N
79
// System.out.println("in jsp "+s);
80
return s;
81         //int lastDot = jspResourcePath.lastIndexOf('.');
82
//return jspResourcePath.substring(0, lastDot) + "$jsp.java"; // NOI18N
83
}
84
85     // copied from org.apache.jasper.JspCompilationContext
86
public String JavaDoc getServletPackageName(String JavaDoc jspUri) {
87         String JavaDoc 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     // copied from org.apache.jasper.JspCompilationContext
95
private String JavaDoc getDerivedPackageName(String JavaDoc jspUri) {
96         int iSep = jspUri.lastIndexOf('/');
97         return (iSep > 0) ? JspNameUtil.makeJavaPackage(jspUri.substring(0,iSep)) : "";// NOI18N
98
}
99     
100     // copied from org.apache.jasper.JspCompilationContext
101
public String JavaDoc getServletClassName(String JavaDoc jspUri) {
102         int iSep = jspUri.lastIndexOf('/') + 1;
103         return JspNameUtil.makeJavaIdentifier(jspUri.substring(iSep));
104     }
105     
106     public String JavaDoc getServletEncoding(String JavaDoc moduleContextPath, String JavaDoc jspResourcePath) {
107         return "UTF8"; // NOI18N
108
}
109     
110     public void setDeploymentManager(DeploymentManager JavaDoc manager) {
111         tm = manager;
112     }
113     
114 }
115
Popular Tags