KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > tomcat5 > 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.tomcat5.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.tomcat5.TomcatManager;
26
27 /**
28  *
29  * @author Petr Jiricka
30  */

31 public class FindJSPServletImpl implements FindJSPServlet {
32
33     private static final String JavaDoc WEB_INF_TAGS = "WEB-INF/tags/";
34     private static final String JavaDoc META_INF_TAGS = "META-INF/tags/";
35     
36     private TomcatManager tm;
37     
38     /** Creates a new instance of FindJSPServletImpl */
39     public FindJSPServletImpl(DeploymentManager JavaDoc manager) {
40         tm = (TomcatManager)manager;
41     }
42     
43     
44     public File JavaDoc getServletTempDirectory(String JavaDoc moduleContextPath) {
45         File JavaDoc baseDir = tm.getTomcatProperties().getCatalinaDir();
46         if ((baseDir == null) || !baseDir.exists()) {
47             return null;
48         }
49         File JavaDoc hostBase = new File JavaDoc(baseDir, "work/Catalina/localhost".replace('/', File.separatorChar));
50         File JavaDoc workDir = new File JavaDoc(hostBase, getContextRootString(moduleContextPath));
51         //System.out.println("returning servlet root " + workDir);
52
return workDir;
53     }
54     
55     private String JavaDoc getContextRootString(String JavaDoc moduleContextPath) {
56         String JavaDoc 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 JavaDoc getServletResourcePath(String JavaDoc moduleContextPath, String JavaDoc jspResourcePath) {
69         //String path = module.getWebURL();
70

71         //we expect .tag file; in other case, we expect .jsp file
72
String JavaDoc path = getTagHandlerClassName(jspResourcePath);
73         if (path != null) //.tag
74
path = path.replace('.', '/') + ".java";
75         else //.jsp
76
path = getServletPackageName(jspResourcePath).replace('.', '/') + '/' +
77                    getServletClassName(jspResourcePath) + ".java";
78             
79         return path;
80         
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)) : "";
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     /**
111      * Copied (and slightly modified) from org.apache.jasper.compiler.JspUtil
112      *
113      * Gets the fully-qualified class name of the tag handler corresponding to
114      * the given tag file path.
115      *
116      * @param path Tag file path
117      *
118      * @return Fully-qualified class name of the tag handler corresponding to
119      * the given tag file path
120      */

121     private String JavaDoc getTagHandlerClassName(String JavaDoc path) {
122
123         String JavaDoc 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