You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@sling.apache.org by fm...@apache.org on 2007/11/27 16:03:04 UTC
svn commit: r598658 - in /incubator/sling/trunk/scripting/jsp: ./
src/main/java/org/apache/jasper/
src/main/java/org/apache/sling/scripting/jsp/ src/main/resources/org/
Author: fmeschbe
Date: Tue Nov 27 07:03:03 2007
New Revision: 598658
URL: http://svn.apache.org/viewvc?rev=598658&view=rev
Log:
SLING-111 Remove Jasper source from the Sling SVN repository
Added:
incubator/sling/trunk/scripting/jsp/src/main/java/org/apache/sling/scripting/jsp/JspServletConfig.java
incubator/sling/trunk/scripting/jsp/src/main/java/org/apache/sling/scripting/jsp/SlingTldLocationsCache.java
- copied, changed from r598308, incubator/sling/trunk/scripting/jsp/src/main/java/org/apache/sling/scripting/jsp/TldLocationsCacheSupport.java
Removed:
incubator/sling/trunk/scripting/jsp/src/main/java/org/apache/jasper/
incubator/sling/trunk/scripting/jsp/src/main/java/org/apache/sling/scripting/jsp/Lock.java
incubator/sling/trunk/scripting/jsp/src/main/java/org/apache/sling/scripting/jsp/RepositoryOutputProvider.java
incubator/sling/trunk/scripting/jsp/src/main/java/org/apache/sling/scripting/jsp/TldLocationsCacheSupport.java
incubator/sling/trunk/scripting/jsp/src/main/resources/org/
Modified:
incubator/sling/trunk/scripting/jsp/pom.xml
incubator/sling/trunk/scripting/jsp/src/main/java/org/apache/sling/scripting/jsp/JspScriptHandler.java
incubator/sling/trunk/scripting/jsp/src/main/java/org/apache/sling/scripting/jsp/JspServletContext.java
incubator/sling/trunk/scripting/jsp/src/main/java/org/apache/sling/scripting/jsp/JspServletOptions.java
incubator/sling/trunk/scripting/jsp/src/main/java/org/apache/sling/scripting/jsp/JspServletWrapperAdapter.java
Modified: incubator/sling/trunk/scripting/jsp/pom.xml
URL: http://svn.apache.org/viewvc/incubator/sling/trunk/scripting/jsp/pom.xml?rev=598658&r1=598657&r2=598658&view=diff
==============================================================================
--- incubator/sling/trunk/scripting/jsp/pom.xml (original)
+++ incubator/sling/trunk/scripting/jsp/pom.xml Tue Nov 27 07:03:03 2007
@@ -64,17 +64,25 @@
<configuration>
<instructions>
<Export-Package>
- org.apache.sling.scripting.jsp.util
+ org.apache.sling.scripting.jsp.util,
+ javax.el; javax.servlet.jsp;
+ javax.servlet.jsp.el;
+ javax.servlet.jsp.tagext;version=2.1
</Export-Package>
<Private-Package>
- org.apache.sling.scripting.jsp.*,
- org.apache.commons.el.*,
- org.apache.jasper.*, org.eclipse.jdt.*
+ org.apache.sling.scripting.jsp.*
</Private-Package>
- <DynamicImport-Package>*</DynamicImport-Package>
+ <!-- <DynamicImport-Package>*</DynamicImport-Package> -->
+
<Import-Package>
- org.eclipse.*;resolution:=optional, *
+ !org.apache.tools.ant.*, !org.eclipse.*, *
</Import-Package>
+
+ <!-- Embed Jasper completely -->
+ <Embed-Dependency>
+ jasper*,juli,el-api,jsp-api
+ </Embed-Dependency>
+ <Embed-StripGroup>true</Embed-StripGroup>
</instructions>
</configuration>
</plugin>
@@ -109,16 +117,32 @@
</dependency>
<dependency>
- <groupId>org.eclipse.jdt</groupId>
- <artifactId>core</artifactId>
- <version>3.2.0.658</version>
+ <groupId>org.apache.tomcat</groupId>
+ <artifactId>jasper</artifactId>
+ <version>6.0.14</version>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.tomcat</groupId>
+ <artifactId>jasper-el</artifactId>
+ <version>6.0.14</version>
</dependency>
<dependency>
- <groupId>commons-el</groupId>
- <artifactId>commons-el</artifactId>
- <version>1.0</version>
+ <groupId>org.apache.tomcat</groupId>
+ <artifactId>jasper-jdt</artifactId>
+ <version>6.0.14</version>
</dependency>
<dependency>
+ <groupId>org.apache.tomcat</groupId>
+ <artifactId>juli</artifactId>
+ <version>6.0.14</version>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.tomcat</groupId>
+ <artifactId>el-api</artifactId>
+ <version>6.0.14</version>
+ </dependency>
+
+ <dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-io</artifactId>
</dependency>
@@ -130,14 +154,6 @@
<dependency>
<groupId>org.osgi</groupId>
<artifactId>osgi_R4_compendium</artifactId>
- </dependency>
- <dependency>
- <groupId>javax.servlet</groupId>
- <artifactId>servlet-api</artifactId>
- </dependency>
- <dependency>
- <groupId>javax.servlet</groupId>
- <artifactId>jsp-api</artifactId>
</dependency>
<dependency>
<groupId>commons-collections</groupId>
Modified: incubator/sling/trunk/scripting/jsp/src/main/java/org/apache/sling/scripting/jsp/JspScriptHandler.java
URL: http://svn.apache.org/viewvc/incubator/sling/trunk/scripting/jsp/src/main/java/org/apache/sling/scripting/jsp/JspScriptHandler.java?rev=598658&r1=598657&r2=598658&view=diff
==============================================================================
--- incubator/sling/trunk/scripting/jsp/src/main/java/org/apache/sling/scripting/jsp/JspScriptHandler.java (original)
+++ incubator/sling/trunk/scripting/jsp/src/main/java/org/apache/sling/scripting/jsp/JspScriptHandler.java Tue Nov 27 07:03:03 2007
@@ -17,27 +17,20 @@
package org.apache.sling.scripting.jsp;
import java.io.IOException;
-import java.net.MalformedURLException;
-import java.util.Collections;
-import java.util.Dictionary;
-import java.util.Enumeration;
-import java.util.HashMap;
import java.util.Map;
+
import javax.jcr.RepositoryException;
import javax.servlet.ServletConfig;
import javax.servlet.ServletContext;
+
import org.apache.jasper.JasperException;
import org.apache.jasper.Options;
import org.apache.jasper.compiler.JspRuntimeContext;
-import org.apache.jasper.compiler.TldLocationsCache;
import org.apache.sling.api.SlingException;
-import org.apache.sling.api.SlingHttpServletRequest;
import org.apache.sling.api.scripting.SlingScript;
import org.apache.sling.api.scripting.SlingScriptEngine;
import org.apache.sling.api.scripting.SlingScriptHelper;
-import org.apache.sling.jcr.api.SlingRepository;
import org.apache.sling.jcr.classloader.RepositoryClassLoaderProvider;
-import org.osgi.framework.Constants;
import org.osgi.service.component.ComponentContext;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -60,38 +53,37 @@
* @scr.property name="jasper.mappedfile" value="true" type="Boolean"
* @scr.property name="jasper.modificationTestInterval" value="4" type="Integer"
* @scr.property name="jasper.reloading" value="false" type="Boolean"
- * @scr.property name="jasper.scratchdir" value="/classes"
+ * @scr.property name="jasper.scratchdir" value="classes"
* @scr.property name="jasper.trimSpaces" value="false" type="Boolean"
+ * @scr.property name="jasper.displaySourceFragments" value="true"
+ * type="Boolean"
* @scr.service
*/
-public class JspScriptHandler implements SlingScriptEngine {
+public class JspScriptHandler implements SlingScriptEngine {
/** default log */
private static final Logger log = LoggerFactory.getLogger(JspScriptHandler.class);
- private ComponentContext componentContext;
-
- /**
- * @scr.reference
- */
- private SlingRepository repository;
+ ComponentContext componentContext;
- /**
- * @scr.reference
- */
+ /** @scr.reference */
private ServletContext slingServletContext;
/**
* @scr.reference name="RepositoryClassLoaderProvider"
- * interface="org.apache.sling.jcr.classloader.RepositoryClassLoaderProvider"
+ * interface="org.apache.sling.jcr.classloader.RepositoryClassLoaderProvider"
*/
private ClassLoader jspClassLoader;
- private RepositoryOutputProvider outputProvider;
+ private SlingTldLocationsCache tldLocationsCache;
+
+ private JspRuntimeContext jspRuntimeContext;
- private TldLocationsCacheSupport tldLocationsCache;
+ private Options options;
- private JspComponentContext jspComponentContext;
+ private JspServletContext jspServletContext;
+
+ private ServletConfig servletConfig;
public static final String SCRIPT_TYPE = "jsp";
@@ -101,7 +93,7 @@
public String[] getExtensions() {
// probably also jspx, jspf ?
- return new String[]{ SCRIPT_TYPE };
+ return new String[] { SCRIPT_TYPE };
}
public String getEngineName() {
@@ -116,18 +108,23 @@
throws SlingException, IOException {
SlingScriptHelper ssh = (SlingScriptHelper) props.get(SLING);
if (ssh != null) {
- JspServletWrapperAdapter jsp = getJspWrapperAdapter(ssh.getRequest(), "TODO");
- jsp.service(ssh);
+ jspServletContext.setRequestResourceResolver(ssh.getRequest().getResourceResolver());
+ try {
+ JspServletWrapperAdapter jsp = getJspWrapperAdapter(ssh);
+ jsp.service(ssh);
+ } finally {
+ jspServletContext.resetRequestResourceResolver();
+ }
}
}
private JspServletWrapperAdapter getJspWrapperAdapter(
- SlingHttpServletRequest component,
- String scriptName) {
+ SlingScriptHelper scriptHelper) throws SlingException {
- JspComponentContext jcc = getJspRuntimeContext();
- JspRuntimeContext rctxt = jcc.getRctxt();
+ JspRuntimeContext rctxt = jspRuntimeContext;
+ SlingScript script = scriptHelper.getScript();
+ String scriptName = script.getScriptResource().getURI();
JspServletWrapperAdapter wrapper = (JspServletWrapperAdapter) rctxt.getWrapper(scriptName);
if (wrapper != null) {
return wrapper;
@@ -139,29 +136,18 @@
return wrapper;
}
- // Check if the requested JSP page exists, to avoid creating
- // unnecessary directories and files.
try {
- if (jcc.getServletContext().getResource(scriptName) == null) {
- log.info("getJspWrapperAdapter: Script {} does not exist",
- scriptName);
- return null;
- }
- } catch (MalformedURLException mue) {
- log.error("getJspWrapperAdapter: Cannot check script {}",
- scriptName, mue);
- }
- try {
- wrapper = new JspServletWrapperAdapter(jcc.getServletConfig(),
- jcc.getOptions(), scriptName, false, rctxt);
+ wrapper = new JspServletWrapperAdapter(servletConfig, options,
+ scriptName, false, rctxt);
rctxt.addWrapper(scriptName, wrapper);
+
return wrapper;
} catch (JasperException je) {
- log.error(
- "getJspWrapperAdapter: Error creating adapter for script {}",
- scriptName, je);
- return null;
+ if (je.getCause() != null) {
+ throw new SlingException(je.getMessage(), je.getCause());
+ }
+ throw new SlingException("Cannot create JSP", je);
}
}
}
@@ -170,9 +156,42 @@
protected void activate(ComponentContext componentContext) {
this.componentContext = componentContext;
- this.tldLocationsCache = new TldLocationsCacheSupport(
- componentContext.getBundleContext());
- this.outputProvider = new RepositoryOutputProvider(repository);
+
+ // set the current class loader as the thread context loader for
+ // the setup of the JspRuntimeContext
+ ClassLoader old = Thread.currentThread().getContextClassLoader();
+ Thread.currentThread().setContextClassLoader(jspClassLoader);
+
+ try {
+ tldLocationsCache = new SlingTldLocationsCache(slingServletContext,
+ componentContext.getBundleContext());
+
+ // return options which use the jspClassLoader
+ options = new JspServletOptions(slingServletContext,
+ componentContext, jspClassLoader, tldLocationsCache);
+
+ // Initialize the JSP Runtime Context
+ jspRuntimeContext = new JspRuntimeContext(slingServletContext,
+ options);
+
+ jspServletContext = new JspServletContext(slingServletContext,
+ tldLocationsCache);
+
+ servletConfig = new JspServletConfig(jspServletContext,
+ componentContext.getProperties());
+
+ } finally {
+ // make sure the context loader is reset after setting up the
+ // JSP runtime context
+ Thread.currentThread().setContextClassLoader(old);
+ }
+
+ if (log.isDebugEnabled()) {
+ log.debug("Scratch dir for the JSP engine is: {}",
+ options.getScratchDir().toString());
+ log.debug("IMPORTANT: Do not modify the generated servlets");
+ }
+
}
protected void deactivate(ComponentContext componentContext) {
@@ -180,10 +199,9 @@
log.debug("JspScriptHandler.deactivate()");
}
- if (jspComponentContext != null) {
- jspComponentContext.getRctxt().setOutputProvider(null);
- jspComponentContext.getRctxt().destroy();
- jspComponentContext = null;
+ if (jspRuntimeContext != null) {
+ jspRuntimeContext.destroy();
+ jspRuntimeContext = null;
}
if (tldLocationsCache != null) {
@@ -191,7 +209,6 @@
tldLocationsCache = null;
}
- outputProvider.dispose();
this.componentContext = null;
}
@@ -214,118 +231,4 @@
// ---------- Internal -----------------------------------------------------
- private JspComponentContext getJspRuntimeContext() {
- if (jspComponentContext == null) {
- jspComponentContext = new JspComponentContext(slingServletContext);
- }
- return jspComponentContext;
- }
-
- private class JspComponentContext {
-
- private final ServletContext servletContext;
-
- private final ServletConfig servletConfig;
-
- private final Options options;
-
- private final JspRuntimeContext rctxt;
-
- JspComponentContext(ServletContext slingServletContext) {
- this.servletContext = new JspServletContext(slingServletContext,
- tldLocationsCache, outputProvider);
- this.servletConfig = new JspServletConfig(servletContext);
-
- // return options which use the jspClassLoader
- TldLocationsCache tlc = tldLocationsCache.getTldLocationsCache(servletContext);
- this.options = new JspServletOptions(servletConfig, outputProvider,
- jspClassLoader, tlc);
-
- // set the current class loader as the thread context loader for
- // the setup of the JspRuntimeContext
- ClassLoader old = Thread.currentThread().getContextClassLoader();
- Thread.currentThread().setContextClassLoader(jspClassLoader);
-
- try {
- // Initialize the JSP Runtime Context
- this.rctxt = new JspRuntimeContext(servletContext, options);
-
- } finally {
- // make sure the context loader is reset after setting up the
- // JSP runtime context
- Thread.currentThread().setContextClassLoader(old);
- }
-
- // by default access the repository
- rctxt.setOutputProvider(outputProvider);
-
- if (log.isDebugEnabled()) {
- log.debug("Scratch dir for the JSP engine is: {}",
- options.getScratchDir().toString());
- log.debug("IMPORTANT: Do not modify the generated servlets");
- }
- }
-
- public ServletConfig getServletConfig() {
- return servletConfig;
- }
-
- public ServletContext getServletContext() {
- return servletContext;
- }
-
- public Options getOptions() {
- return options;
- }
-
- public JspRuntimeContext getRctxt() {
- return rctxt;
- }
- }
-
- private class JspServletConfig implements ServletConfig {
- private final ServletContext servletContext;
-
- private String servletName;
- private Map<String, String> properties;
-
- JspServletConfig(ServletContext servletContext) {
- this.servletContext = servletContext;
-
- Dictionary<?, ?> props = componentContext.getProperties();
-
- // set the servlet name
- servletName = (String) props.get(Constants.SERVICE_DESCRIPTION);
- if (servletName == null) {
- servletName = "JSP Script Handler";
- }
-
- // copy the "jasper." properties
- properties = new HashMap<String, String>();
- for (Enumeration<?> ke = props.keys(); ke.hasMoreElements();) {
- String key = (String) ke.nextElement();
- if (key.startsWith("jasper.")) {
- properties.put(key.substring("jasper.".length()),
- String.valueOf(props.get(key)));
- }
- }
-
- }
-
- public String getInitParameter(String name) {
- return properties.get(name);
- }
-
- public Enumeration<String> getInitParameterNames() {
- return Collections.enumeration(properties.keySet());
- }
-
- public ServletContext getServletContext() {
- return servletContext;
- }
-
- public String getServletName() {
- return servletName;
- }
- }
}
Added: incubator/sling/trunk/scripting/jsp/src/main/java/org/apache/sling/scripting/jsp/JspServletConfig.java
URL: http://svn.apache.org/viewvc/incubator/sling/trunk/scripting/jsp/src/main/java/org/apache/sling/scripting/jsp/JspServletConfig.java?rev=598658&view=auto
==============================================================================
--- incubator/sling/trunk/scripting/jsp/src/main/java/org/apache/sling/scripting/jsp/JspServletConfig.java (added)
+++ incubator/sling/trunk/scripting/jsp/src/main/java/org/apache/sling/scripting/jsp/JspServletConfig.java Tue Nov 27 07:03:03 2007
@@ -0,0 +1,75 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.sling.scripting.jsp;
+
+import java.util.Collections;
+import java.util.Dictionary;
+import java.util.Enumeration;
+import java.util.HashMap;
+import java.util.Map;
+
+import javax.servlet.ServletConfig;
+import javax.servlet.ServletContext;
+
+import org.osgi.framework.Constants;
+
+class JspServletConfig implements ServletConfig {
+
+ private final ServletContext servletContext;
+
+ private String servletName;
+
+ private Map<String, String> properties;
+
+ JspServletConfig(ServletContext servletContext, Dictionary<?, ?> config) {
+ this.servletContext = servletContext;
+
+ // set the servlet name
+ servletName = (String) config.get(Constants.SERVICE_DESCRIPTION);
+ if (servletName == null) {
+ servletName = "JSP Script Handler";
+ }
+
+ // copy the "jasper." properties
+ properties = new HashMap<String, String>();
+ for (Enumeration<?> ke = config.keys(); ke.hasMoreElements();) {
+ String key = (String) ke.nextElement();
+ if (key.startsWith("jasper.")) {
+ properties.put(key.substring("jasper.".length()),
+ String.valueOf(config.get(key)));
+ }
+ }
+ }
+
+ public String getInitParameter(String name) {
+ return properties.get(name);
+ }
+
+ public Enumeration<String> getInitParameterNames() {
+ return Collections.enumeration(properties.keySet());
+ }
+
+ public ServletContext getServletContext() {
+ return servletContext;
+ }
+
+ public String getServletName() {
+ return servletName;
+ }
+}
\ No newline at end of file
Modified: incubator/sling/trunk/scripting/jsp/src/main/java/org/apache/sling/scripting/jsp/JspServletContext.java
URL: http://svn.apache.org/viewvc/incubator/sling/trunk/scripting/jsp/src/main/java/org/apache/sling/scripting/jsp/JspServletContext.java?rev=598658&r1=598657&r2=598658&view=diff
==============================================================================
--- incubator/sling/trunk/scripting/jsp/src/main/java/org/apache/sling/scripting/jsp/JspServletContext.java (original)
+++ incubator/sling/trunk/scripting/jsp/src/main/java/org/apache/sling/scripting/jsp/JspServletContext.java Tue Nov 27 07:03:03 2007
@@ -22,11 +22,16 @@
import java.util.Enumeration;
import java.util.Set;
+import javax.jcr.Node;
import javax.servlet.RequestDispatcher;
import javax.servlet.Servlet;
import javax.servlet.ServletContext;
import javax.servlet.ServletException;
+import org.apache.jackrabbit.net.URLFactory;
+import org.apache.sling.api.SlingException;
+import org.apache.sling.api.resource.Resource;
+import org.apache.sling.api.resource.ResourceResolver;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -39,13 +44,22 @@
private static final Logger log = LoggerFactory.getLogger(JspServletContext.class);
private final ServletContext delegatee;
- private final TldLocationsCacheSupport tcs;
- private final RepositoryOutputProvider outputProvider;
+ private final SlingTldLocationsCache tcs;
- JspServletContext(ServletContext componentContext, TldLocationsCacheSupport tcs, RepositoryOutputProvider outputProvider) {
+ private ThreadLocal<ResourceResolver> requestResourceResolver;
+
+ JspServletContext(ServletContext componentContext, SlingTldLocationsCache tcs) {
this.delegatee = componentContext;
this.tcs = tcs;
- this.outputProvider = outputProvider;
+ this.requestResourceResolver = new ThreadLocal<ResourceResolver>();
+ }
+
+ void setRequestResourceResolver(ResourceResolver resolver) {
+ requestResourceResolver.set(resolver);
+ }
+
+ void resetRequestResourceResolver() {
+ requestResourceResolver.remove();
}
//---------- implemented methods ------------------------------------------
@@ -54,13 +68,21 @@
* @see javax.servlet.ServletContext#getResource(java.lang.String)
*/
public URL getResource(String path) throws MalformedURLException {
- // path might be an URL, so only check repository in case of absolute
- // path - assuming URLs have no leading slash at all, we don't care
- // for the scheme separating colon here
+
if (path.startsWith("/")) {
- URL url = outputProvider.getURL(path);
- if (url != null) {
- return url;
+ try {
+ Resource res = getResourceInternal(path);
+ if (res != null && res.getRawData() instanceof Node) {
+ // TODO: if we would have the URLAdapter ....
+ Node node = (Node) res.getRawData();
+ return URLFactory.createURL(node.getSession(), node.getPath());
+ }
+
+ // TODO: is this correct or should we try another one ??
+ return null;
+ } catch (Exception ex) {
+ // SlingException or RepositoryException
+ log.error("getResource: Problem getting resource " + path, ex);
}
}
@@ -72,15 +94,18 @@
* @see javax.servlet.ServletContext#getResourceAsStream(java.lang.String)
*/
public InputStream getResourceAsStream(String path) {
- // path might be an URL, so only check repository in case of absolute
- // path - assuming URLs have no leading slash at all, we don't care
- // for the scheme separating colon here
if (path.startsWith("/")) {
try {
- return outputProvider.getInputStream(path);
- } catch (Exception e) {
- log.debug("getResourceAsStream: Cannot get resource {}: {}", path,
- e.getMessage());
+ Resource res = getResourceInternal(path);
+ if (res != null) {
+ return res.getInputStream();
+ }
+
+ // TODO: is this correct or should we try another one ??
+ return null;
+ } catch (Exception ex) {
+ // SlingException or IOException
+ log.error("getResource: Problem getting resource " + path, ex);
}
}
@@ -194,7 +219,21 @@
return delegatee.getServlets();
}
+ // Servlet API 2.5 method
+ public String getContextPath() {
+ return delegatee.getContextPath();
+ }
+
//---------- internal -----------------------------------------------------
+
+ private Resource getResourceInternal(String path) throws SlingException {
+ ResourceResolver resolver = requestResourceResolver.get();
+ if (resolver != null) {
+ return resolver.getResource(path);
+ }
+
+ return null;
+ }
private URL getUrlForResource(String path) {
int cs = path.indexOf(":/");
Modified: incubator/sling/trunk/scripting/jsp/src/main/java/org/apache/sling/scripting/jsp/JspServletOptions.java
URL: http://svn.apache.org/viewvc/incubator/sling/trunk/scripting/jsp/src/main/java/org/apache/sling/scripting/jsp/JspServletOptions.java?rev=598658&r1=598657&r2=598658&view=diff
==============================================================================
--- incubator/sling/trunk/scripting/jsp/src/main/java/org/apache/sling/scripting/jsp/JspServletOptions.java (original)
+++ incubator/sling/trunk/scripting/jsp/src/main/java/org/apache/sling/scripting/jsp/JspServletOptions.java Tue Nov 27 07:03:03 2007
@@ -16,18 +16,21 @@
*/
package org.apache.sling.scripting.jsp;
+import java.io.File;
+import java.util.Dictionary;
import java.util.Enumeration;
import java.util.Map;
import java.util.Properties;
-import javax.servlet.ServletConfig;
+import javax.servlet.ServletContext;
import org.apache.jasper.Options;
-import org.apache.jasper.OutputProvider;
import org.apache.jasper.compiler.JspConfig;
import org.apache.jasper.compiler.Localizer;
import org.apache.jasper.compiler.TagPluginManager;
import org.apache.jasper.compiler.TldLocationsCache;
+import org.apache.sling.core.CoreConstants;
+import org.osgi.service.component.ComponentContext;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -39,8 +42,8 @@
/** default log */
private static final Logger log = LoggerFactory.getLogger(JspServletOptions.class);
- /** Default source and target VM version (value is "1.4"). */
- private static final String DEFAULT_VM_VERSION = "1.4";
+ /** Default source and target VM version (value is "1.5"). */
+ private static final String DEFAULT_VM_VERSION = "1.5";
private Properties settings = new Properties();
@@ -70,16 +73,16 @@
private boolean isPoolingEnabled = true;
/**
- * Do you want support for "mapped" files? This will generate
- * servlet that has a print statement per line of the JSP file.
- * This seems like a really nice feature to have for debugging.
+ * Do you want support for "mapped" files? This will generate servlet that
+ * has a print statement per line of the JSP file. This seems like a really
+ * nice feature to have for debugging.
*/
private boolean mappedFile = true;
/**
- * Do you want stack traces and such displayed in the client's
- * browser? If this is false, such messages go to the standard
- * error or a log file if the standard error is redirected.
+ * Do you want stack traces and such displayed in the client's browser? If
+ * this is false, such messages go to the standard error or a log file if
+ * the standard error is redirected.
*/
private boolean sendErrorToClient = false;
@@ -111,15 +114,14 @@
private boolean errorOnUseBeanInvalidClassAttribute = true;
/**
- * I want to see my generated servlets. Which directory are they
- * in?
+ * I want to see my generated servlets. Which directory are they in?
*/
- private String scratchDir;
+ private File scratchDir;
/**
- * Need to have this as is for versions 4 and 5 of IE. Can be set from
- * the initParams so if it changes in the future all that is needed is
- * to have a jsp initParam of type ieClassId="<value>"
+ * Need to have this as is for versions 4 and 5 of IE. Can be set from the
+ * initParams so if it changes in the future all that is needed is to have a
+ * jsp initParam of type ieClassId="<value>"
*/
private String ieClassId = "clsid:8AD9C840-044E-11D1-B3E9-00805F499D93";
@@ -129,11 +131,6 @@
private String classpath = null;
/**
- * Compiler to use.
- */
- private String compiler = null;
-
- /**
* Compiler target VM.
*/
private String compilerTargetVM = DEFAULT_VM_VERSION;
@@ -159,8 +156,7 @@
private TagPluginManager tagPluginManager = null;
/**
- * Java platform encoding to generate the JSP
- * page servlet.
+ * Java platform encoding to generate the JSP page servlet.
*/
private String javaEncoding = "UTF8";
@@ -179,13 +175,19 @@
*/
private boolean xpoweredBy;
- public String getProperty(String name ) {
- return this.settings.getProperty( name );
+ /**
+ * Should we include a source fragment in exception messages, which could be
+ * displayed to the developer ?
+ */
+ private boolean displaySourceFragments = true;
+
+ public String getProperty(String name) {
+ return this.settings.getProperty(name);
}
- public void setProperty(String name, String value ) {
- if (name != null && value != null){
- this.settings.setProperty( name, value );
+ public void setProperty(String name, String value) {
+ if (name != null && value != null) {
+ this.settings.setProperty(name, value);
}
}
@@ -280,13 +282,13 @@
/**
* What is my scratch dir?
*/
- public String getScratchDir() {
+ public File getScratchDir() {
return this.scratchDir;
}
/**
- * What classpath should I use while compiling the servlets
- * generated from JSP files?
+ * What classpath should I use while compiling the servlets generated from
+ * JSP files?
*/
public String getClassPath() {
return this.classpath;
@@ -307,10 +309,11 @@
}
/**
- * Compiler to use.
+ * Allways return null for the compiler to use, assuming JDT is the default
+ * which we will never overwrite.
*/
public String getCompiler() {
- return this.compiler;
+ return null;
}
/**
@@ -339,7 +342,7 @@
return this.tldLocationsCache;
}
- public void setTldLocationsCache( TldLocationsCache tldC ) {
+ public void setTldLocationsCache(TldLocationsCache tldC) {
this.tldLocationsCache = tldC;
}
@@ -367,12 +370,24 @@
return null;
}
+ public boolean getDisplaySourceFragment() {
+ return displaySourceFragments;
+ }
+
+ /**
+ * Allways return null for the compiler to use, assuming JDT is the default
+ * which we will never overwrite.
+ */
+ public String getCompilerClassName() {
+ return null;
+ }
+
/**
* Create an JspServletOptions object using data available from
* ServletConfig and ServletContext.
*/
- public JspServletOptions(ServletConfig config,
- OutputProvider outputProvider, ClassLoader jspClassLoader,
+ public JspServletOptions(ServletContext servletContext,
+ ComponentContext componentContext, ClassLoader jspClassLoader,
TldLocationsCache tldLocationsCache) {
this.jspClassLoader = jspClassLoader;
@@ -381,18 +396,25 @@
this.compilerSourceVM = DEFAULT_VM_VERSION;
this.compilerTargetVM = DEFAULT_VM_VERSION;
- Enumeration enumeration=config.getInitParameterNames();
- while( enumeration.hasMoreElements() ) {
- String k=(String)enumeration.nextElement();
- String v=config.getInitParameter( k );
- this.setProperty( k, v);
+ Dictionary<?, ?> config = componentContext.getProperties();
+ Enumeration<?> enumeration = config.keys();
+ while (enumeration.hasMoreElements()) {
+ String key = (String) enumeration.nextElement();
+ if (key.startsWith("jasper.")) {
+ Object value = config.get(key);
+ if (value != null) {
+ setProperty(key.substring("jasper.".length()),
+ value.toString());
+ }
+ }
+
}
// quick hack
-// String validating=config.getInitParameter( "validating");
-// if( "false".equals( validating )) ParserUtils.validating=false;
+ // String validating=config.getInitParameter( "validating");
+ // if( "false".equals( validating )) ParserUtils.validating=false;
- String keepgen = config.getInitParameter("keepgenerated");
+ String keepgen = getProperty("keepgenerated");
if (keepgen != null) {
if (keepgen.equalsIgnoreCase("true")) {
this.keepGenerated = true;
@@ -405,8 +427,7 @@
}
}
-
- String trimsp = config.getInitParameter("trimSpaces");
+ String trimsp = getProperty("trimSpaces");
if (trimsp != null) {
if (trimsp.equalsIgnoreCase("true")) {
this.trimSpaces = true;
@@ -419,11 +440,23 @@
}
}
+ String dpsFrags = getProperty("displaySourceFragments");
+ if (dpsFrags != null) {
+ if (dpsFrags.equalsIgnoreCase("true")) {
+ this.displaySourceFragments = true;
+ } else if (dpsFrags.equalsIgnoreCase("false")) {
+ this.displaySourceFragments = false;
+ } else {
+ if (log.isWarnEnabled()) {
+ log.warn(Localizer.getMessage("jsp.warning.displaySourceFragment"));
+ }
+ }
+ }
+
this.isPoolingEnabled = true;
- String poolingEnabledParam
- = config.getInitParameter("enablePooling");
+ String poolingEnabledParam = getProperty("enablePooling");
if (poolingEnabledParam != null
- && !poolingEnabledParam.equalsIgnoreCase("true")) {
+ && !poolingEnabledParam.equalsIgnoreCase("true")) {
if (poolingEnabledParam.equalsIgnoreCase("false")) {
this.isPoolingEnabled = false;
} else {
@@ -433,7 +466,7 @@
}
}
- String mapFile = config.getInitParameter("mappedfile");
+ String mapFile = getProperty("mappedfile");
if (mapFile != null) {
if (mapFile.equalsIgnoreCase("true")) {
this.mappedFile = true;
@@ -446,7 +479,7 @@
}
}
- String senderr = config.getInitParameter("sendErrToClient");
+ String senderr = getProperty("sendErrToClient");
if (senderr != null) {
if (senderr.equalsIgnoreCase("true")) {
this.sendErrorToClient = true;
@@ -459,12 +492,12 @@
}
}
- String debugInfo = config.getInitParameter("classdebuginfo");
+ String debugInfo = getProperty("classdebuginfo");
if (debugInfo != null) {
if (debugInfo.equalsIgnoreCase("true")) {
- this.classDebugInfo = true;
+ this.classDebugInfo = true;
} else if (debugInfo.equalsIgnoreCase("false")) {
- this.classDebugInfo = false;
+ this.classDebugInfo = false;
} else {
if (log.isWarnEnabled()) {
log.warn(Localizer.getMessage("jsp.warning.classDebugInfo"));
@@ -472,7 +505,7 @@
}
}
- String checkInterval = config.getInitParameter("checkInterval");
+ String checkInterval = getProperty("checkInterval");
if (checkInterval != null) {
try {
this.checkInterval = Integer.parseInt(checkInterval);
@@ -482,25 +515,25 @@
log.warn(Localizer.getMessage("jsp.warning.checkInterval"));
}
}
- } catch(NumberFormatException ex) {
+ } catch (NumberFormatException ex) {
if (log.isWarnEnabled()) {
log.warn(Localizer.getMessage("jsp.warning.checkInterval"));
}
}
}
- String modificationTestInterval = config.getInitParameter("modificationTestInterval");
+ String modificationTestInterval = getProperty("modificationTestInterval");
if (modificationTestInterval != null) {
try {
this.modificationTestInterval = Integer.parseInt(modificationTestInterval);
- } catch(NumberFormatException ex) {
+ } catch (NumberFormatException ex) {
if (log.isWarnEnabled()) {
log.warn(Localizer.getMessage("jsp.warning.modificationTestInterval"));
}
}
}
- String development = config.getInitParameter("development");
+ String development = getProperty("development");
if (development != null) {
if (development.equalsIgnoreCase("true")) {
this.development = true;
@@ -513,7 +546,7 @@
}
}
- String suppressSmap = config.getInitParameter("suppressSmap");
+ String suppressSmap = getProperty("suppressSmap");
if (suppressSmap != null) {
if (suppressSmap.equalsIgnoreCase("true")) {
this.isSmapSuppressed = true;
@@ -526,7 +559,7 @@
}
}
- String dumpSmap = config.getInitParameter("dumpSmap");
+ String dumpSmap = getProperty("dumpSmap");
if (dumpSmap != null) {
if (dumpSmap.equalsIgnoreCase("true")) {
this.isSmapDumped = true;
@@ -539,7 +572,7 @@
}
}
- String genCharArray = config.getInitParameter("genStrAsCharArray");
+ String genCharArray = getProperty("genStrAsCharArray");
if (genCharArray != null) {
if (genCharArray.equalsIgnoreCase("true")) {
this.genStringAsCharArray = true;
@@ -552,8 +585,7 @@
}
}
- String errBeanClass =
- config.getInitParameter("errorOnUseBeanInvalidClassAttribute");
+ String errBeanClass = getProperty("errorOnUseBeanInvalidClassAttribute");
if (errBeanClass != null) {
if (errBeanClass.equalsIgnoreCase("true")) {
this.errorOnUseBeanInvalidClassAttribute = true;
@@ -566,36 +598,59 @@
}
}
- String ieClassId = config.getInitParameter("ieClassId");
- if (ieClassId != null)
+ String ieClassId = getProperty("ieClassId");
+ if (ieClassId != null) {
this.ieClassId = ieClassId;
+ }
- String classpath = config.getInitParameter("classpath");
- if (classpath != null)
+ String classpath = getProperty("classpath");
+ if (classpath != null) {
this.classpath = classpath;
+ }
- String dir = config.getInitParameter("scratchdir");
- this.scratchDir = (dir != null) ? dir : "/classes";
- outputProvider.mkdirs(this.scratchDir);
+ String dir = getProperty("scratchdir");
+ this.scratchDir = new File((dir != null) ? dir : "classes");
+ if (!scratchDir.isAbsolute()) {
+ String slingHome = componentContext.getBundleContext().getProperty(
+ CoreConstants.SLING_HOME);
+ if (slingHome != null) {
+ scratchDir = new File(slingHome, scratchDir.getPath());
+ } else {
+ File tmp = componentContext.getBundleContext().getDataFile(
+ scratchDir.getPath());
+ if (tmp != null) {
+ scratchDir = tmp;
+ }
+ }
+ scratchDir = scratchDir.getAbsoluteFile();
+ }
- this.compiler = config.getInitParameter("compiler");
+ if (scratchDir.exists()) {
+ if (!scratchDir.isDirectory()) {
+ // TODO ERROR
+ }
+ } else {
+ if (!scratchDir.mkdirs()) {
+ // TODO ERROR
+ }
+ }
- String compilerTargetVM = config.getInitParameter("compilerTargetVM");
- if(compilerTargetVM != null) {
+ String compilerTargetVM = getProperty("compilerTargetVM");
+ if (compilerTargetVM != null) {
this.compilerTargetVM = compilerTargetVM;
}
- String compilerSourceVM = config.getInitParameter("compilerSourceVM");
- if(compilerSourceVM != null) {
+ String compilerSourceVM = getProperty("compilerSourceVM");
+ if (compilerSourceVM != null) {
this.compilerSourceVM = compilerSourceVM;
}
- String javaEncoding = config.getInitParameter("javaEncoding");
+ String javaEncoding = getProperty("javaEncoding");
if (javaEncoding != null) {
this.javaEncoding = javaEncoding;
}
- String fork = config.getInitParameter("fork");
+ String fork = getProperty("fork");
if (fork != null) {
if (fork.equalsIgnoreCase("true")) {
this.fork = true;
@@ -608,7 +663,7 @@
}
}
- String xpoweredBy = config.getInitParameter("xpoweredBy");
+ String xpoweredBy = getProperty("xpoweredBy");
if (xpoweredBy != null) {
if (xpoweredBy.equalsIgnoreCase("true")) {
this.xpoweredBy = true;
@@ -623,16 +678,13 @@
// Setup the global Tag Libraries location cache for this
// web-application.
- this.tldLocationsCache = (tldLocationsCache != null)
- ? tldLocationsCache
- : new TldLocationsCache(config.getServletContext());
+ this.tldLocationsCache = tldLocationsCache;
// Setup the jsp config info for this web app.
- this.jspConfig = new JspConfig(config.getServletContext());
+ this.jspConfig = new JspConfig(servletContext);
// Create a Tag plugin instance
- this.tagPluginManager = new TagPluginManager(config.getServletContext());
+ this.tagPluginManager = new TagPluginManager(servletContext);
}
}
-
Modified: incubator/sling/trunk/scripting/jsp/src/main/java/org/apache/sling/scripting/jsp/JspServletWrapperAdapter.java
URL: http://svn.apache.org/viewvc/incubator/sling/trunk/scripting/jsp/src/main/java/org/apache/sling/scripting/jsp/JspServletWrapperAdapter.java?rev=598658&r1=598657&r2=598658&view=diff
==============================================================================
--- incubator/sling/trunk/scripting/jsp/src/main/java/org/apache/sling/scripting/jsp/JspServletWrapperAdapter.java (original)
+++ incubator/sling/trunk/scripting/jsp/src/main/java/org/apache/sling/scripting/jsp/JspServletWrapperAdapter.java Tue Nov 27 07:03:03 2007
@@ -33,9 +33,6 @@
/**
* The <code>JspServletWrapperAdapter</code> TODO
- *
- * @author fmeschbe
- * @version $Rev:23741 $, $Date:2006-12-01 16:24:05 +0100 (Fr, 01 Dez 2006) $
*/
public class JspServletWrapperAdapter extends JspServletWrapper {
Copied: incubator/sling/trunk/scripting/jsp/src/main/java/org/apache/sling/scripting/jsp/SlingTldLocationsCache.java (from r598308, incubator/sling/trunk/scripting/jsp/src/main/java/org/apache/sling/scripting/jsp/TldLocationsCacheSupport.java)
URL: http://svn.apache.org/viewvc/incubator/sling/trunk/scripting/jsp/src/main/java/org/apache/sling/scripting/jsp/SlingTldLocationsCache.java?p2=incubator/sling/trunk/scripting/jsp/src/main/java/org/apache/sling/scripting/jsp/SlingTldLocationsCache.java&p1=incubator/sling/trunk/scripting/jsp/src/main/java/org/apache/sling/scripting/jsp/TldLocationsCacheSupport.java&r1=598308&r2=598658&rev=598658&view=diff
==============================================================================
--- incubator/sling/trunk/scripting/jsp/src/main/java/org/apache/sling/scripting/jsp/TldLocationsCacheSupport.java (original)
+++ incubator/sling/trunk/scripting/jsp/src/main/java/org/apache/sling/scripting/jsp/SlingTldLocationsCache.java Tue Nov 27 07:03:03 2007
@@ -18,6 +18,7 @@
import java.io.InputStream;
import java.net.URL;
+import java.util.Enumeration;
import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;
@@ -34,24 +35,25 @@
import org.osgi.framework.BundleListener;
/**
- * The <code>TldLocationsCacheSupport</code> TODO
+ * The <code>SlingTldLocationsCache</code> TODO
*/
-public class TldLocationsCacheSupport implements BundleListener {
+public class SlingTldLocationsCache extends TldLocationsCache implements
+ BundleListener {
private static final String TLD_SCHEME = "tld:";
- private Map tldLocations = new HashMap();
+ private Map<String, TldLocationEntry> tldLocations = new HashMap<String, TldLocationEntry>();
+
+ public SlingTldLocationsCache(ServletContext servletContext,
+ BundleContext context) {
+ super(servletContext);
- /**
- * @param ctxt
- */
- public TldLocationsCacheSupport(BundleContext context) {
context.addBundleListener(this);
Bundle[] bundles = context.getBundles();
- for (int i=0; i < bundles.length; i++) {
+ for (int i = 0; i < bundles.length; i++) {
if (bundles[i].getState() == Bundle.ACTIVE) {
- this.addBundle(bundles[i]);
+ addBundle(bundles[i]);
}
}
}
@@ -59,8 +61,8 @@
void shutdown(BundleContext context) {
context.removeBundleListener(this);
- synchronized (this.tldLocations) {
- this.tldLocations.clear();
+ synchronized (tldLocations) {
+ tldLocations.clear();
}
}
@@ -71,8 +73,8 @@
tldLocation = tldLocation.substring(TLD_SCHEME.length());
TldLocationEntry tle;
- synchronized (this.tldLocations) {
- tle = (TldLocationEntry) this.tldLocations.get(tldLocation);
+ synchronized (tldLocations) {
+ tle = tldLocations.get(tldLocation);
}
if (tle != null) {
@@ -85,19 +87,16 @@
// ---------- TldLocationsCache support ------------------------------------
- TldLocationsCache getTldLocationsCache(ServletContext ctxt) {
- return new TldLocationsCache(ctxt) {
- public String[] getLocation(String uri) throws JasperException {
- synchronized (TldLocationsCacheSupport.this.tldLocations) {
- if (TldLocationsCacheSupport.this.tldLocations.containsKey(uri)) {
- return new String[]{ TLD_SCHEME + uri, null };
- }
- }
-
- // TODO: Should we fall back to the original implementation at all ??
- return super.getLocation(uri);
+ public String[] getLocation(String uri) throws JasperException {
+ synchronized (tldLocations) {
+ if (tldLocations.containsKey(uri)) {
+ return new String[] { TLD_SCHEME + uri, null };
}
- };
+ }
+
+ // TODO: Should we fall back to the original implementation at
+ // all ??
+ return super.getLocation(uri);
}
// ---------- BundleListener -----------------------------------------------
@@ -105,29 +104,30 @@
public void bundleChanged(BundleEvent event) {
if (event.getType() == BundleEvent.STARTED) {
// find and register new TLD
- this.addBundle(event.getBundle());
+ addBundle(event.getBundle());
} else if (event.getType() == BundleEvent.STOPPED) {
// unregister TLD
- this.removeBundle(event.getBundle());
+ removeBundle(event.getBundle());
}
}
// ---------- internal -----------------------------------------------------
private void addBundle(Bundle bundle) {
- // currently only META-INF/taglib.tld is supported, this should
+ // currently only META-INF/*.tld is supported, this should
// be extended for registration in a Bundle Manifest Header
- String[] tldEntries = { "META-INF/taglib.tld" };
- for (int i=0; i< tldEntries.length; i++) {
- URL taglib = bundle.getEntry(tldEntries[i]);
- if (taglib != null) {
- // Add map entry only if its uri is not already present in the map
- String uri = this.getUriFromTld(taglib);
- synchronized (this.tldLocations) {
- if (uri != null && !this.tldLocations.containsKey(uri)) {
- this.tldLocations.put(uri, new TldLocationEntry(bundle, tldEntries[i]));
+ Enumeration<?> entries = bundle.findEntries("META-INF", "*.tld", false);
+ if (entries != null) {
+ while (entries.hasMoreElements()) {
+ URL taglib = (URL) entries.nextElement();
+ String uri = getUriFromTld(taglib);
+
+ synchronized (tldLocations) {
+ if (uri != null && !tldLocations.containsKey(uri)) {
+ tldLocations.put(uri, new TldLocationEntry(bundle,
+ taglib.getPath()));
}
}
}
@@ -135,10 +135,11 @@
}
private void removeBundle(Bundle bundle) {
- synchronized (this.tldLocations) {
- for (Iterator li = this.tldLocations.values().iterator(); li.hasNext();) {
- TldLocationEntry tle = (TldLocationEntry) li.next();
- if (tle != null && tle.getBundle().getBundleId() == bundle.getBundleId()) {
+ synchronized (tldLocations) {
+ for (Iterator<TldLocationEntry> li = tldLocations.values().iterator(); li.hasNext();) {
+ TldLocationEntry tle = li.next();
+ if (tle != null
+ && tle.getBundle().getBundleId() == bundle.getBundleId()) {
li.remove();
}
}
@@ -181,6 +182,7 @@
private static class TldLocationEntry {
private Bundle bundle;
+
private String tldPath;
private TldLocationEntry(Bundle bundle, String tldPath) {
@@ -189,15 +191,15 @@
}
Bundle getBundle() {
- return this.bundle;
+ return bundle;
}
String getTldPath() {
- return this.tldPath;
+ return tldPath;
}
URL getTldURL() {
- return this.bundle.getEntry(this.tldPath);
+ return bundle.getEntry(tldPath);
}
}
}