001: /*
002: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
003: *
004: * Copyright 1997-2007 Sun Microsystems, Inc. All rights reserved.
005: *
006: * The contents of this file are subject to the terms of either the GNU
007: * General Public License Version 2 only ("GPL") or the Common
008: * Development and Distribution License("CDDL") (collectively, the
009: * "License"). You may not use this file except in compliance with the
010: * License. You can obtain a copy of the License at
011: * http://www.netbeans.org/cddl-gplv2.html
012: * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
013: * specific language governing permissions and limitations under the
014: * License. When distributing the software, include this License Header
015: * Notice in each file and include the License file at
016: * nbbuild/licenses/CDDL-GPL-2-CP. Sun designates this
017: * particular file as subject to the "Classpath" exception as provided
018: * by Sun in the GPL Version 2 section of the License file that
019: * accompanied this code. If applicable, add the following below the
020: * License Header, with the fields enclosed by brackets [] replaced by
021: * your own identifying information:
022: * "Portions Copyrighted [year] [name of copyright owner]"
023: *
024: * Contributor(s):
025: *
026: * The Original Software is NetBeans. The Initial Developer of the Original
027: * Software is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun
028: * Microsystems, Inc. All Rights Reserved.
029: *
030: * If you wish your version of this file to be governed by only the CDDL
031: * or only the GPL Version 2, indicate your decision by adding
032: * "[Contributor] elects to include this software in this distribution
033: * under the [CDDL or GPL Version 2] license." If you do not indicate a
034: * single choice of license, a recipient has the option to distribute
035: * your version of this file under either the CDDL, the GPL Version 2 or
036: * to extend the choice of license to its licensees as provided above.
037: * However, if you add GPL Version 2 code and therefore, elected the GPL
038: * Version 2 license, then the option applies only if the new code is
039: * made subject to such option by the copyright holder.
040: */
041:
042: package org.netbeans.modules.tomcat5.jsps;
043:
044: import java.io.File;
045: import javax.enterprise.deploy.spi.DeploymentManager;
046: import org.netbeans.modules.j2ee.deployment.plugins.spi.FindJSPServlet;
047: import org.netbeans.modules.tomcat5.TomcatManager;
048:
049: /**
050: *
051: * @author Petr Jiricka
052: */
053: public class FindJSPServletImpl implements FindJSPServlet {
054:
055: private static final String WEB_INF_TAGS = "WEB-INF/tags/";
056: private static final String META_INF_TAGS = "META-INF/tags/";
057:
058: private TomcatManager tm;
059:
060: /** Creates a new instance of FindJSPServletImpl */
061: public FindJSPServletImpl(DeploymentManager manager) {
062: tm = (TomcatManager) manager;
063: }
064:
065: public File getServletTempDirectory(String moduleContextPath) {
066: File baseDir = tm.getTomcatProperties().getCatalinaDir();
067: if ((baseDir == null) || !baseDir.exists()) {
068: return null;
069: }
070: File hostBase = new File(baseDir, "work/Catalina/localhost"
071: .replace('/', File.separatorChar));
072: File workDir = new File(hostBase,
073: getContextRootString(moduleContextPath));
074: //System.out.println("returning servlet root " + workDir);
075: return workDir;
076: }
077:
078: private String getContextRootString(String moduleContextPath) {
079: String contextRootPath = moduleContextPath;
080: if (contextRootPath.startsWith("/")) {
081: contextRootPath = contextRootPath.substring(1);
082: }
083: if (contextRootPath.equals("")) {
084: return "_";
085: } else {
086: return contextRootPath;
087: }
088: }
089:
090: public String getServletResourcePath(String moduleContextPath,
091: String jspResourcePath) {
092: //String path = module.getWebURL();
093:
094: //we expect .tag file; in other case, we expect .jsp file
095: String path = getTagHandlerClassName(jspResourcePath);
096: if (path != null) //.tag
097: path = path.replace('.', '/') + ".java";
098: else
099: //.jsp
100: path = getServletPackageName(jspResourcePath).replace('.',
101: '/')
102: + '/'
103: + getServletClassName(jspResourcePath)
104: + ".java";
105:
106: return path;
107:
108: //int lastDot = jspResourcePath.lastIndexOf('.');
109: //return jspResourcePath.substring(0, lastDot) + "$jsp.java"; // NOI18N
110: }
111:
112: // copied from org.apache.jasper.JspCompilationContext
113: public String getServletPackageName(String jspUri) {
114: String dPackageName = getDerivedPackageName(jspUri);
115: if (dPackageName.length() == 0) {
116: return JspNameUtil.JSP_PACKAGE_NAME;
117: }
118: return JspNameUtil.JSP_PACKAGE_NAME + '.'
119: + getDerivedPackageName(jspUri);
120: }
121:
122: // copied from org.apache.jasper.JspCompilationContext
123: private String getDerivedPackageName(String jspUri) {
124: int iSep = jspUri.lastIndexOf('/');
125: return (iSep > 0) ? JspNameUtil.makeJavaPackage(jspUri
126: .substring(0, iSep)) : "";
127: }
128:
129: // copied from org.apache.jasper.JspCompilationContext
130: public String getServletClassName(String jspUri) {
131: int iSep = jspUri.lastIndexOf('/') + 1;
132: return JspNameUtil.makeJavaIdentifier(jspUri.substring(iSep));
133: }
134:
135: public String getServletEncoding(String moduleContextPath,
136: String jspResourcePath) {
137: return "UTF8"; // NOI18N
138: }
139:
140: /**
141: * Copied (and slightly modified) from org.apache.jasper.compiler.JspUtil
142: *
143: * Gets the fully-qualified class name of the tag handler corresponding to
144: * the given tag file path.
145: *
146: * @param path Tag file path
147: *
148: * @return Fully-qualified class name of the tag handler corresponding to
149: * the given tag file path
150: */
151: private String getTagHandlerClassName(String path) {
152:
153: String className = null;
154: int begin = 0;
155: int index;
156:
157: index = path.lastIndexOf(".tag");
158: if (index == -1) {
159: return null;
160: }
161:
162: index = path.indexOf(WEB_INF_TAGS);
163: if (index != -1) {
164: className = "org.apache.jsp.tag.web.";
165: begin = index + WEB_INF_TAGS.length();
166: } else {
167: index = path.indexOf(META_INF_TAGS);
168: if (index != -1) {
169: className = "org.apache.jsp.tag.meta.";
170: begin = index + META_INF_TAGS.length();
171: } else {
172: return null;
173: }
174: }
175:
176: className += JspNameUtil.makeJavaPackage(path.substring(begin));
177:
178: return className;
179: }
180:
181: }
|