KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > j2ee > sun > ws7 > j2ee > jsp > JSPServletFinder


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.ws7.j2ee.jsp;
21
22 import java.io.File JavaDoc;
23 import java.lang.reflect.Method JavaDoc;
24 import javax.enterprise.deploy.spi.DeploymentManager JavaDoc;
25 import javax.enterprise.deploy.spi.Target JavaDoc;
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 /**
32  *
33  * @author Petr Jiricka, adapted by Mukesh Garg for WS70
34  */

35 public class JSPServletFinder implements FindJSPServlet {
36
37     private WS70SunDeploymentManager manager;
38     
39     /**
40      * Creates a new instance of JSPServletFinder
41      */

42     public JSPServletFinder(DeploymentManager JavaDoc dm) {
43         
44         String JavaDoc uri = ((WS70SunDeploymentManager)dm).getUri();
45         manager = WS70SunDeploymentFactory.getConnectedCachedDeploymentManager(uri);
46     }
47     
48     public File JavaDoc getServletTempDirectory(String JavaDoc moduleContextPath) {
49         Target JavaDoc defaultTarget = manager.getDefaultTarget();
50         
51         if(defaultTarget == null){
52             // could not find target information
53
return null;
54         }
55         String JavaDoc configName = null;
56         String JavaDoc vsName = null;
57         try{
58             Method JavaDoc getConfigName = defaultTarget.getClass().getDeclaredMethod("getConfigName", new Class JavaDoc[]{});
59             configName = (String JavaDoc)getConfigName.invoke(defaultTarget, new Object JavaDoc[]{});
60             Method JavaDoc getVSName = defaultTarget.getClass().getDeclaredMethod("getVSName", new Class JavaDoc[]{});
61             vsName = (String JavaDoc)getVSName.invoke(defaultTarget, new Object JavaDoc[]{});
62         }catch(Exception JavaDoc e){
63             // could not find location
64
return null;
65         }
66                    
67         String JavaDoc location = manager.getServerLocation()+File.separator+"https-"+configName+
68                            File.separator+"ClassCache"+File.separator+vsName+File.separator;
69         File JavaDoc workDir = new File JavaDoc(location, getContextRootString(moduleContextPath));
70         return workDir;
71     }
72     
73     private String JavaDoc getContextRootString(String JavaDoc moduleContextPath) {
74         String JavaDoc contextRootPath = moduleContextPath;
75         if (contextRootPath.startsWith("/")) {
76             contextRootPath = contextRootPath.substring(1);
77         }
78         return contextRootPath;
79
80     }
81     
82     public String JavaDoc getServletResourcePath(String JavaDoc moduleContextPath, String JavaDoc jspResourcePath) {
83         String JavaDoc path= getServletPackageName(jspResourcePath).replace('.', '/') + '/' +
84         getServletClassName(jspResourcePath) + ".java";
85         return path;
86     }
87     public String JavaDoc getServletEncoding(String JavaDoc moduleContextPath, String JavaDoc jspResourcePath) {
88         return "UTF8"; // NOI18N
89
}
90     // copied from org.apache.jasper.JspCompilationContext
91
private String JavaDoc getServletPackageName(String JavaDoc jspUri) {
92         String JavaDoc 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     // copied from org.apache.jasper.JspCompilationContext
100
private String JavaDoc getDerivedPackageName(String JavaDoc jspUri) {
101         int iSep = jspUri.lastIndexOf('/');
102         return (iSep > 0) ? JspNameUtil.makeJavaPackage(jspUri.substring(0,iSep)) : "";
103     }
104     
105     // copied from org.apache.jasper.JspCompilationContext
106
private String JavaDoc getServletClassName(String JavaDoc jspUri) {
107         int iSep = jspUri.lastIndexOf('/') + 1;
108         return JspNameUtil.makeJavaIdentifier(jspUri.substring(iSep));
109     }
110 }
111
Popular Tags