You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@struts.apache.org by mu...@apache.org on 2009/07/31 20:12:51 UTC
svn commit: r799681 [1/24] - in /struts/sandbox/trunk/struts2-jsp-plugin: ./
src/main/java/org/apache/struts/ src/main/java/org/apache/struts2/
src/main/java/org/apache/struts2/compiler/
src/main/java/org/apache/struts2/jasper/ src/main/java/org/apache...
Author: musachy
Date: Fri Jul 31 18:12:48 2009
New Revision: 799681
URL: http://svn.apache.org/viewvc?rev=799681&view=rev
Log:
copy jasper code and modify it to compile drom classpath, add code to compile java in memory
Added:
struts/sandbox/trunk/struts2-jsp-plugin/src/main/java/org/apache/struts2/
struts/sandbox/trunk/struts2-jsp-plugin/src/main/java/org/apache/struts2/EmbeddedJSPResult.java
struts/sandbox/trunk/struts2-jsp-plugin/src/main/java/org/apache/struts2/JSPLoader.java
struts/sandbox/trunk/struts2-jsp-plugin/src/main/java/org/apache/struts2/JSPServletConfig.java
struts/sandbox/trunk/struts2-jsp-plugin/src/main/java/org/apache/struts2/ServletCache.java
struts/sandbox/trunk/struts2-jsp-plugin/src/main/java/org/apache/struts2/compiler/
struts/sandbox/trunk/struts2-jsp-plugin/src/main/java/org/apache/struts2/compiler/MemoryClassLoader.java
struts/sandbox/trunk/struts2-jsp-plugin/src/main/java/org/apache/struts2/compiler/MemoryJavaFileObject.java
struts/sandbox/trunk/struts2-jsp-plugin/src/main/java/org/apache/struts2/jasper/
struts/sandbox/trunk/struts2-jsp-plugin/src/main/java/org/apache/struts2/jasper/Constants.java
struts/sandbox/trunk/struts2-jsp-plugin/src/main/java/org/apache/struts2/jasper/CustomCompiler.java
struts/sandbox/trunk/struts2-jsp-plugin/src/main/java/org/apache/struts2/jasper/EmbeddedServletOptions.java
struts/sandbox/trunk/struts2-jsp-plugin/src/main/java/org/apache/struts2/jasper/JasperException.java
struts/sandbox/trunk/struts2-jsp-plugin/src/main/java/org/apache/struts2/jasper/JspC.java
struts/sandbox/trunk/struts2-jsp-plugin/src/main/java/org/apache/struts2/jasper/JspCompilationContext.java
struts/sandbox/trunk/struts2-jsp-plugin/src/main/java/org/apache/struts2/jasper/Options.java
struts/sandbox/trunk/struts2-jsp-plugin/src/main/java/org/apache/struts2/jasper/compiler/
struts/sandbox/trunk/struts2-jsp-plugin/src/main/java/org/apache/struts2/jasper/compiler/BeanRepository.java
struts/sandbox/trunk/struts2-jsp-plugin/src/main/java/org/apache/struts2/jasper/compiler/Collector.java
struts/sandbox/trunk/struts2-jsp-plugin/src/main/java/org/apache/struts2/jasper/compiler/Compiler.java
struts/sandbox/trunk/struts2-jsp-plugin/src/main/java/org/apache/struts2/jasper/compiler/DefaultErrorHandler.java
struts/sandbox/trunk/struts2-jsp-plugin/src/main/java/org/apache/struts2/jasper/compiler/Dumper.java
struts/sandbox/trunk/struts2-jsp-plugin/src/main/java/org/apache/struts2/jasper/compiler/ELFunctionMapper.java
struts/sandbox/trunk/struts2-jsp-plugin/src/main/java/org/apache/struts2/jasper/compiler/ELNode.java
struts/sandbox/trunk/struts2-jsp-plugin/src/main/java/org/apache/struts2/jasper/compiler/ELParser.java
struts/sandbox/trunk/struts2-jsp-plugin/src/main/java/org/apache/struts2/jasper/compiler/ErrorDispatcher.java
struts/sandbox/trunk/struts2-jsp-plugin/src/main/java/org/apache/struts2/jasper/compiler/ErrorHandler.java
struts/sandbox/trunk/struts2-jsp-plugin/src/main/java/org/apache/struts2/jasper/compiler/Generator.java
struts/sandbox/trunk/struts2-jsp-plugin/src/main/java/org/apache/struts2/jasper/compiler/ImplicitTagLibraryInfo.java
struts/sandbox/trunk/struts2-jsp-plugin/src/main/java/org/apache/struts2/jasper/compiler/JasperTagInfo.java
struts/sandbox/trunk/struts2-jsp-plugin/src/main/java/org/apache/struts2/jasper/compiler/JavacErrorDetail.java
struts/sandbox/trunk/struts2-jsp-plugin/src/main/java/org/apache/struts2/jasper/compiler/JspConfig.java
struts/sandbox/trunk/struts2-jsp-plugin/src/main/java/org/apache/struts2/jasper/compiler/JspDocumentParser.java
struts/sandbox/trunk/struts2-jsp-plugin/src/main/java/org/apache/struts2/jasper/compiler/JspReader.java
struts/sandbox/trunk/struts2-jsp-plugin/src/main/java/org/apache/struts2/jasper/compiler/JspRuntimeContext.java
struts/sandbox/trunk/struts2-jsp-plugin/src/main/java/org/apache/struts2/jasper/compiler/JspUtil.java
struts/sandbox/trunk/struts2-jsp-plugin/src/main/java/org/apache/struts2/jasper/compiler/Localizer.java
struts/sandbox/trunk/struts2-jsp-plugin/src/main/java/org/apache/struts2/jasper/compiler/Mark.java
struts/sandbox/trunk/struts2-jsp-plugin/src/main/java/org/apache/struts2/jasper/compiler/Node.java
struts/sandbox/trunk/struts2-jsp-plugin/src/main/java/org/apache/struts2/jasper/compiler/PageDataImpl.java
struts/sandbox/trunk/struts2-jsp-plugin/src/main/java/org/apache/struts2/jasper/compiler/PageInfo.java
struts/sandbox/trunk/struts2-jsp-plugin/src/main/java/org/apache/struts2/jasper/compiler/Parser.java
struts/sandbox/trunk/struts2-jsp-plugin/src/main/java/org/apache/struts2/jasper/compiler/ParserController.java
struts/sandbox/trunk/struts2-jsp-plugin/src/main/java/org/apache/struts2/jasper/compiler/ScriptingVariabler.java
struts/sandbox/trunk/struts2-jsp-plugin/src/main/java/org/apache/struts2/jasper/compiler/ServletWriter.java
struts/sandbox/trunk/struts2-jsp-plugin/src/main/java/org/apache/struts2/jasper/compiler/SmapGenerator.java
struts/sandbox/trunk/struts2-jsp-plugin/src/main/java/org/apache/struts2/jasper/compiler/SmapStratum.java
struts/sandbox/trunk/struts2-jsp-plugin/src/main/java/org/apache/struts2/jasper/compiler/SmapUtil.java
struts/sandbox/trunk/struts2-jsp-plugin/src/main/java/org/apache/struts2/jasper/compiler/TagConstants.java
struts/sandbox/trunk/struts2-jsp-plugin/src/main/java/org/apache/struts2/jasper/compiler/TagFileProcessor.java
struts/sandbox/trunk/struts2-jsp-plugin/src/main/java/org/apache/struts2/jasper/compiler/TagLibraryInfoImpl.java
struts/sandbox/trunk/struts2-jsp-plugin/src/main/java/org/apache/struts2/jasper/compiler/TagPluginManager.java
struts/sandbox/trunk/struts2-jsp-plugin/src/main/java/org/apache/struts2/jasper/compiler/TextOptimizer.java
struts/sandbox/trunk/struts2-jsp-plugin/src/main/java/org/apache/struts2/jasper/compiler/TldLocationsCache.java
struts/sandbox/trunk/struts2-jsp-plugin/src/main/java/org/apache/struts2/jasper/compiler/Validator.java
struts/sandbox/trunk/struts2-jsp-plugin/src/main/java/org/apache/struts2/jasper/compiler/tagplugin/
struts/sandbox/trunk/struts2-jsp-plugin/src/main/java/org/apache/struts2/jasper/compiler/tagplugin/TagPlugin.java
struts/sandbox/trunk/struts2-jsp-plugin/src/main/java/org/apache/struts2/jasper/compiler/tagplugin/TagPluginContext.java
struts/sandbox/trunk/struts2-jsp-plugin/src/main/java/org/apache/struts2/jasper/resources/
struts/sandbox/trunk/struts2-jsp-plugin/src/main/java/org/apache/struts2/jasper/resources/LocalStrings.properties
struts/sandbox/trunk/struts2-jsp-plugin/src/main/java/org/apache/struts2/jasper/resources/LocalStrings_es.properties
struts/sandbox/trunk/struts2-jsp-plugin/src/main/java/org/apache/struts2/jasper/resources/LocalStrings_fr.properties
struts/sandbox/trunk/struts2-jsp-plugin/src/main/java/org/apache/struts2/jasper/resources/LocalStrings_ja.properties
struts/sandbox/trunk/struts2-jsp-plugin/src/main/java/org/apache/struts2/jasper/runtime/
struts/sandbox/trunk/struts2-jsp-plugin/src/main/java/org/apache/struts2/jasper/runtime/BodyContentImpl.java
struts/sandbox/trunk/struts2-jsp-plugin/src/main/java/org/apache/struts2/jasper/runtime/HttpJspBase.java
struts/sandbox/trunk/struts2-jsp-plugin/src/main/java/org/apache/struts2/jasper/runtime/JspContextWrapper.java
struts/sandbox/trunk/struts2-jsp-plugin/src/main/java/org/apache/struts2/jasper/runtime/JspFactoryImpl.java
struts/sandbox/trunk/struts2-jsp-plugin/src/main/java/org/apache/struts2/jasper/runtime/JspFragmentHelper.java
struts/sandbox/trunk/struts2-jsp-plugin/src/main/java/org/apache/struts2/jasper/runtime/JspRuntimeLibrary.java
struts/sandbox/trunk/struts2-jsp-plugin/src/main/java/org/apache/struts2/jasper/runtime/JspSourceDependent.java
struts/sandbox/trunk/struts2-jsp-plugin/src/main/java/org/apache/struts2/jasper/runtime/JspWriterImpl.java
struts/sandbox/trunk/struts2-jsp-plugin/src/main/java/org/apache/struts2/jasper/runtime/PageContextImpl.java
struts/sandbox/trunk/struts2-jsp-plugin/src/main/java/org/apache/struts2/jasper/runtime/PerThreadTagHandlerPool.java
struts/sandbox/trunk/struts2-jsp-plugin/src/main/java/org/apache/struts2/jasper/runtime/ProtectedFunctionMapper.java
struts/sandbox/trunk/struts2-jsp-plugin/src/main/java/org/apache/struts2/jasper/runtime/ServletResponseWrapperInclude.java
struts/sandbox/trunk/struts2-jsp-plugin/src/main/java/org/apache/struts2/jasper/runtime/TagHandlerPool.java
struts/sandbox/trunk/struts2-jsp-plugin/src/main/java/org/apache/struts2/jasper/security/
struts/sandbox/trunk/struts2-jsp-plugin/src/main/java/org/apache/struts2/jasper/security/SecurityClassLoad.java
struts/sandbox/trunk/struts2-jsp-plugin/src/main/java/org/apache/struts2/jasper/security/SecurityUtil.java
struts/sandbox/trunk/struts2-jsp-plugin/src/main/java/org/apache/struts2/jasper/servlet/
struts/sandbox/trunk/struts2-jsp-plugin/src/main/java/org/apache/struts2/jasper/servlet/JasperLoader.java
struts/sandbox/trunk/struts2-jsp-plugin/src/main/java/org/apache/struts2/jasper/servlet/JspCServletContext.java
struts/sandbox/trunk/struts2-jsp-plugin/src/main/java/org/apache/struts2/jasper/servlet/JspServlet.java
struts/sandbox/trunk/struts2-jsp-plugin/src/main/java/org/apache/struts2/jasper/servlet/JspServletWrapper.java
struts/sandbox/trunk/struts2-jsp-plugin/src/main/java/org/apache/struts2/jasper/servlet/mbeans-descriptors.xml
struts/sandbox/trunk/struts2-jsp-plugin/src/main/java/org/apache/struts2/jasper/tagplugins/
struts/sandbox/trunk/struts2-jsp-plugin/src/main/java/org/apache/struts2/jasper/tagplugins/jstl/
struts/sandbox/trunk/struts2-jsp-plugin/src/main/java/org/apache/struts2/jasper/tagplugins/jstl/Util.java
struts/sandbox/trunk/struts2-jsp-plugin/src/main/java/org/apache/struts2/jasper/tagplugins/jstl/core/
struts/sandbox/trunk/struts2-jsp-plugin/src/main/java/org/apache/struts2/jasper/tagplugins/jstl/core/Catch.java
struts/sandbox/trunk/struts2-jsp-plugin/src/main/java/org/apache/struts2/jasper/tagplugins/jstl/core/Choose.java
struts/sandbox/trunk/struts2-jsp-plugin/src/main/java/org/apache/struts2/jasper/tagplugins/jstl/core/ForEach.java
struts/sandbox/trunk/struts2-jsp-plugin/src/main/java/org/apache/struts2/jasper/tagplugins/jstl/core/ForTokens.java
struts/sandbox/trunk/struts2-jsp-plugin/src/main/java/org/apache/struts2/jasper/tagplugins/jstl/core/If.java
struts/sandbox/trunk/struts2-jsp-plugin/src/main/java/org/apache/struts2/jasper/tagplugins/jstl/core/Import.java
struts/sandbox/trunk/struts2-jsp-plugin/src/main/java/org/apache/struts2/jasper/tagplugins/jstl/core/Otherwise.java
struts/sandbox/trunk/struts2-jsp-plugin/src/main/java/org/apache/struts2/jasper/tagplugins/jstl/core/Out.java
struts/sandbox/trunk/struts2-jsp-plugin/src/main/java/org/apache/struts2/jasper/tagplugins/jstl/core/Param.java
struts/sandbox/trunk/struts2-jsp-plugin/src/main/java/org/apache/struts2/jasper/tagplugins/jstl/core/Redirect.java
struts/sandbox/trunk/struts2-jsp-plugin/src/main/java/org/apache/struts2/jasper/tagplugins/jstl/core/Remove.java
struts/sandbox/trunk/struts2-jsp-plugin/src/main/java/org/apache/struts2/jasper/tagplugins/jstl/core/Set.java
struts/sandbox/trunk/struts2-jsp-plugin/src/main/java/org/apache/struts2/jasper/tagplugins/jstl/core/Url.java
struts/sandbox/trunk/struts2-jsp-plugin/src/main/java/org/apache/struts2/jasper/tagplugins/jstl/core/When.java
struts/sandbox/trunk/struts2-jsp-plugin/src/main/java/org/apache/struts2/jasper/tagplugins/jstl/tagPlugins.xml
struts/sandbox/trunk/struts2-jsp-plugin/src/main/java/org/apache/struts2/jasper/util/
struts/sandbox/trunk/struts2-jsp-plugin/src/main/java/org/apache/struts2/jasper/util/FastDateFormat.java
struts/sandbox/trunk/struts2-jsp-plugin/src/main/java/org/apache/struts2/jasper/util/Queue.java
struts/sandbox/trunk/struts2-jsp-plugin/src/main/java/org/apache/struts2/jasper/util/SimplePool.java
struts/sandbox/trunk/struts2-jsp-plugin/src/main/java/org/apache/struts2/jasper/util/SystemLogHandler.java
struts/sandbox/trunk/struts2-jsp-plugin/src/main/java/org/apache/struts2/jasper/xmlparser/
struts/sandbox/trunk/struts2-jsp-plugin/src/main/java/org/apache/struts2/jasper/xmlparser/ASCIIReader.java
struts/sandbox/trunk/struts2-jsp-plugin/src/main/java/org/apache/struts2/jasper/xmlparser/EncodingMap.java
struts/sandbox/trunk/struts2-jsp-plugin/src/main/java/org/apache/struts2/jasper/xmlparser/ParserUtils.java
struts/sandbox/trunk/struts2-jsp-plugin/src/main/java/org/apache/struts2/jasper/xmlparser/SymbolTable.java
struts/sandbox/trunk/struts2-jsp-plugin/src/main/java/org/apache/struts2/jasper/xmlparser/TreeNode.java
struts/sandbox/trunk/struts2-jsp-plugin/src/main/java/org/apache/struts2/jasper/xmlparser/UCSReader.java
struts/sandbox/trunk/struts2-jsp-plugin/src/main/java/org/apache/struts2/jasper/xmlparser/UTF8Reader.java
struts/sandbox/trunk/struts2-jsp-plugin/src/main/java/org/apache/struts2/jasper/xmlparser/XMLChar.java
struts/sandbox/trunk/struts2-jsp-plugin/src/main/java/org/apache/struts2/jasper/xmlparser/XMLEncodingDetector.java
struts/sandbox/trunk/struts2-jsp-plugin/src/main/java/org/apache/struts2/jasper/xmlparser/XMLString.java
struts/sandbox/trunk/struts2-jsp-plugin/src/main/java/org/apache/struts2/jasper/xmlparser/XMLStringBuffer.java
struts/sandbox/trunk/struts2-jsp-plugin/src/main/resources/
struts/sandbox/trunk/struts2-jsp-plugin/src/main/resources/struts-plugin.xml
Removed:
struts/sandbox/trunk/struts2-jsp-plugin/src/main/java/org/apache/struts/
Modified:
struts/sandbox/trunk/struts2-jsp-plugin/pom.xml
struts/sandbox/trunk/struts2-jsp-plugin/src/test/java/org/apache/struts2/EmbeddedJSPResultTest.java
Modified: struts/sandbox/trunk/struts2-jsp-plugin/pom.xml
URL: http://svn.apache.org/viewvc/struts/sandbox/trunk/struts2-jsp-plugin/pom.xml?rev=799681&r1=799680&r2=799681&view=diff
==============================================================================
--- struts/sandbox/trunk/struts2-jsp-plugin/pom.xml (original)
+++ struts/sandbox/trunk/struts2-jsp-plugin/pom.xml Fri Jul 31 18:12:48 2009
@@ -1,10 +1,15 @@
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
- <groupId>struts2-jsp-plugin</groupId>
+ <parent>
+ <groupId>org.apache.struts</groupId>
+ <artifactId>struts2-plugins</artifactId>
+ <version>2.1.8-SNAPSHOT</version>
+ </parent>
+
+ <groupId>org.apache.struts</groupId>
<artifactId>struts2-jsp-plugin</artifactId>
<packaging>jar</packaging>
- <version>1.0</version>
<name>struts2-jsp-plugin</name>
<url>http://maven.apache.org</url>
<dependencies>
@@ -44,13 +49,13 @@
</dependency>
<dependency>
<groupId>tomcat</groupId>
- <artifactId>jasper-compiler</artifactId>
+ <artifactId>jasper-runtime</artifactId>
<version>5.5.23</version>
</dependency>
<dependency>
- <groupId>tomcat</groupId>
- <artifactId>jasper-runtime</artifactId>
- <version>5.5.23</version>
+ <groupId>javax.servlet</groupId>
+ <artifactId>jsp-api</artifactId>
+ <version>2.0</version>
</dependency>
</dependencies>
</project>
Added: struts/sandbox/trunk/struts2-jsp-plugin/src/main/java/org/apache/struts2/EmbeddedJSPResult.java
URL: http://svn.apache.org/viewvc/struts/sandbox/trunk/struts2-jsp-plugin/src/main/java/org/apache/struts2/EmbeddedJSPResult.java?rev=799681&view=auto
==============================================================================
--- struts/sandbox/trunk/struts2-jsp-plugin/src/main/java/org/apache/struts2/EmbeddedJSPResult.java (added)
+++ struts/sandbox/trunk/struts2-jsp-plugin/src/main/java/org/apache/struts2/EmbeddedJSPResult.java Fri Jul 31 18:12:48 2009
@@ -0,0 +1,27 @@
+package org.apache.struts2;
+
+import org.apache.struts2.dispatcher.StrutsResultSupport;
+import org.apache.struts2.ServletActionContext;
+import org.apache.struts2.jasper.JasperException;
+import com.opensymphony.xwork2.ActionInvocation;
+import com.opensymphony.xwork2.util.logging.Logger;
+import com.opensymphony.xwork2.util.logging.LoggerFactory;
+
+import javax.servlet.jsp.JspPage;
+import javax.servlet.jsp.HttpJspPage;
+import javax.servlet.Servlet;
+
+
+public class EmbeddedJSPResult extends StrutsResultSupport {
+ private static final Logger LOG = LoggerFactory.getLogger(EmbeddedJSPResult.class);
+
+ //maps from jsp path -> pagelet
+ private static final ServletCache servletCache = new ServletCache(ServletActionContext.getServletContext());
+
+ protected void doExecute(String finalLocation, ActionInvocation invocation) throws Exception {
+ Servlet servlet = servletCache.get(finalLocation);
+ HttpJspPage page = (HttpJspPage) servlet;
+ page.jspInit();
+ page._jspService(ServletActionContext.getRequest(), ServletActionContext.getResponse());
+ }
+}
Added: struts/sandbox/trunk/struts2-jsp-plugin/src/main/java/org/apache/struts2/JSPLoader.java
URL: http://svn.apache.org/viewvc/struts/sandbox/trunk/struts2-jsp-plugin/src/main/java/org/apache/struts2/JSPLoader.java?rev=799681&view=auto
==============================================================================
--- struts/sandbox/trunk/struts2-jsp-plugin/src/main/java/org/apache/struts2/JSPLoader.java (added)
+++ struts/sandbox/trunk/struts2-jsp-plugin/src/main/java/org/apache/struts2/JSPLoader.java Fri Jul 31 18:12:48 2009
@@ -0,0 +1,138 @@
+/*
+ * $Id$
+ *
+ * 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.struts2;
+
+import com.opensymphony.xwork2.util.logging.Logger;
+import com.opensymphony.xwork2.util.logging.LoggerFactory;
+import com.opensymphony.xwork2.util.finder.ClassLoaderInterfaceDelegate;
+
+import javax.servlet.Servlet;
+import javax.servlet.ServletContext;
+import javax.servlet.ServletException;
+import javax.tools.*;
+import java.io.*;
+import java.net.*;
+import java.util.Arrays;
+
+import org.apache.struts2.jasper.JasperException;
+import org.apache.struts2.jasper.JspC;
+import org.apache.struts2.compiler.MemoryClassLoader;
+import org.apache.struts2.compiler.MemoryJavaFileObject;
+
+/**
+ * Uses jasper to extract a JSP from the classpath to a file and compile it
+ */
+public class JSPLoader {
+ private static final Logger LOG = LoggerFactory.getLogger(JSPLoader.class);
+ public static final File JSP_DIR = new File(System.getProperty("java.io.tmpdir"), "struts_jsps");
+
+ private static MemoryClassLoader classLoader = new MemoryClassLoader();
+ private static final String DEFAULT_PACKAGE = "org.apache.struts2.jsp";
+ private static final String DEFAULT_PATH = "org/apache/jsp";
+
+ public Servlet load(String location, ServletContext servletContext) throws Exception {
+ String source = compileJSP(location);
+ String className = toClassName(location);
+ compileJava(className, source);
+
+ Class clazz = Class.forName(className, false, classLoader);
+ return createServlet(clazz, servletContext);
+ }
+
+ private String toClassName(String location) {
+ String[] splitted = location.split("\\.|/");
+ return DEFAULT_PACKAGE + "." + splitted[splitted.length - 2] + "_jsp";
+ }
+
+ /**
+ * Creates and inits a servlet
+ */
+ private Servlet createServlet(Class clazz, ServletContext servletContext) throws IllegalAccessException, InstantiationException, ServletException {
+ Servlet servlet = (Servlet) clazz.newInstance();
+ JSPServletConfig config = new JSPServletConfig(servletContext);
+ servlet.init(config);
+
+ return servlet;
+ }
+
+ private void compileJava(String className, final String source) {
+ JavaCompiler compiler =
+ ToolProvider.getSystemJavaCompiler();
+
+ DiagnosticCollector<JavaFileObject> diagnostics =
+ new DiagnosticCollector<JavaFileObject>();
+
+ JavaFileManager jfm = new
+ ForwardingJavaFileManager<StandardJavaFileManager>(
+ compiler.getStandardFileManager(diagnostics, null, null)) {
+
+ @Override
+ public JavaFileObject getJavaFileForOutput(Location location,
+ String name,
+ JavaFileObject.Kind kind,
+ FileObject sibling) throws IOException {
+ MemoryJavaFileObject fileObject = new MemoryJavaFileObject(name, kind);
+ classLoader.addMemoryJavaFileObject(name, fileObject);
+ return fileObject;
+ }
+
+ };
+
+ String fileName = className.replace('.', '/') + ".java";
+ SimpleJavaFileObject sourceCodeObject = new SimpleJavaFileObject(toURI(fileName), JavaFileObject.Kind.SOURCE) {
+ @Override
+ public CharSequence getCharContent(boolean
+ ignoreEncodingErrors)
+ throws IOException, IllegalStateException,
+ UnsupportedOperationException {
+ return source;
+ }
+
+ };
+
+ JavaCompiler.CompilationTask task = compiler.getTask(
+ null, jfm, diagnostics, null, null,
+ Arrays.asList(sourceCodeObject));
+
+ if (!task.call()) {
+ throw new RuntimeException("Compilation failed:" + diagnostics.getDiagnostics().get(0).toString());
+ }
+ }
+
+ private String compileJSP(String location) throws JasperException {
+ JspC jspC = new JspC();
+ //TODO: get this from context so OSGI works
+ jspC.setClassLoaderInterface(new ClassLoaderInterfaceDelegate(Thread.currentThread().getContextClassLoader()));
+ jspC.setCompile(false);
+ jspC.setJspFiles(location);
+ jspC.setPackage(DEFAULT_PACKAGE);
+ jspC.execute();
+ return jspC.getSourceCode();
+ }
+
+ private static URI toURI(String name) {
+ try {
+ return new URI(name);
+ } catch (URISyntaxException e) {
+ throw new RuntimeException(e);
+ }
+ }
+}
Added: struts/sandbox/trunk/struts2-jsp-plugin/src/main/java/org/apache/struts2/JSPServletConfig.java
URL: http://svn.apache.org/viewvc/struts/sandbox/trunk/struts2-jsp-plugin/src/main/java/org/apache/struts2/JSPServletConfig.java?rev=799681&view=auto
==============================================================================
--- struts/sandbox/trunk/struts2-jsp-plugin/src/main/java/org/apache/struts2/JSPServletConfig.java (added)
+++ struts/sandbox/trunk/struts2-jsp-plugin/src/main/java/org/apache/struts2/JSPServletConfig.java Fri Jul 31 18:12:48 2009
@@ -0,0 +1,52 @@
+/*
+ * $Id$
+ *
+ * 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.struts2;
+
+import javax.servlet.ServletConfig;
+import javax.servlet.ServletContext;
+import java.util.Enumeration;
+import java.util.Collections;
+
+public class JSPServletConfig implements ServletConfig {
+ private final Enumeration EMPTY_ENUMERATION = Collections.enumeration(Collections.EMPTY_LIST);
+
+ private ServletContext servletContext;
+
+ public JSPServletConfig(ServletContext servletContext) {
+ this.servletContext = servletContext;
+ }
+
+ public String getInitParameter(String name) {
+ return null;
+ }
+
+ public Enumeration getInitParameterNames() {
+ return EMPTY_ENUMERATION;
+ }
+
+ public ServletContext getServletContext() {
+ return servletContext;
+ }
+
+ public String getServletName() {
+ return null;
+ }
+}
Added: struts/sandbox/trunk/struts2-jsp-plugin/src/main/java/org/apache/struts2/ServletCache.java
URL: http://svn.apache.org/viewvc/struts/sandbox/trunk/struts2-jsp-plugin/src/main/java/org/apache/struts2/ServletCache.java?rev=799681&view=auto
==============================================================================
--- struts/sandbox/trunk/struts2-jsp-plugin/src/main/java/org/apache/struts2/ServletCache.java (added)
+++ struts/sandbox/trunk/struts2-jsp-plugin/src/main/java/org/apache/struts2/ServletCache.java Fri Jul 31 18:12:48 2009
@@ -0,0 +1,78 @@
+/*
+ * $Id$
+ *
+ * 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.struts2;
+
+import javax.servlet.Servlet;
+import javax.servlet.ServletContext;
+import java.util.concurrent.*;
+
+/**
+ * Caches servlet instances by jsp location
+ */
+public class ServletCache {
+ private final ConcurrentMap<String, Future<Servlet>> cache
+ = new ConcurrentHashMap<String, Future<Servlet>>();
+
+ private final JSPLoader jspLoader = new JSPLoader();
+
+ private final ServletContext servletContext;
+
+ public ServletCache(ServletContext servletContext) {
+ this.servletContext = servletContext;
+ }
+
+ public Servlet get(final String location) throws InterruptedException {
+ while (true) {
+ Future<Servlet> future = cache.get(location);
+ if (future == null) {
+ Callable<Servlet> loadJSPCallable = new Callable<Servlet>() {
+ public Servlet call() throws Exception {
+ return jspLoader.load(location, servletContext);
+ }
+ };
+ FutureTask<Servlet> futureTask = new FutureTask<Servlet>(loadJSPCallable);
+ future = cache.putIfAbsent(location, futureTask);
+ if (future == null) {
+ future = futureTask;
+ futureTask.run();
+ }
+ }
+ try {
+ return future.get();
+ } catch (CancellationException e) {
+ cache.remove(location, future);
+ } catch (ExecutionException e) {
+ throw launderThrowable(e.getCause());
+ }
+ }
+ }
+
+ public static RuntimeException launderThrowable(Throwable t) {
+ if (t instanceof RuntimeException)
+ return (RuntimeException) t;
+ else if (t instanceof Error)
+ throw (Error) t;
+ else
+ throw new IllegalStateException("Not unchecked", t);
+ }
+
+}
+
Added: struts/sandbox/trunk/struts2-jsp-plugin/src/main/java/org/apache/struts2/compiler/MemoryClassLoader.java
URL: http://svn.apache.org/viewvc/struts/sandbox/trunk/struts2-jsp-plugin/src/main/java/org/apache/struts2/compiler/MemoryClassLoader.java?rev=799681&view=auto
==============================================================================
--- struts/sandbox/trunk/struts2-jsp-plugin/src/main/java/org/apache/struts2/compiler/MemoryClassLoader.java (added)
+++ struts/sandbox/trunk/struts2-jsp-plugin/src/main/java/org/apache/struts2/compiler/MemoryClassLoader.java Fri Jul 31 18:12:48 2009
@@ -0,0 +1,44 @@
+/*
+ * $Id$
+ *
+ * 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.struts2.compiler;
+
+import javax.tools.JavaFileObject;
+import java.util.Map;
+import java.util.concurrent.ConcurrentHashMap;
+
+public class MemoryClassLoader extends ClassLoader {
+ private Map<String, MemoryJavaFileObject> cachedObjects = new ConcurrentHashMap<String, MemoryJavaFileObject>();
+
+ @Override
+ protected Class<?> findClass(String name) throws
+ ClassNotFoundException {
+ MemoryJavaFileObject fileObject = cachedObjects.get(name);
+ if (fileObject != null) {
+ byte[] bytes = fileObject.toByteArray();
+ return defineClass(name, bytes, 0, bytes.length);
+ }
+ return super.findClass(name);
+ }
+
+ public void addMemoryJavaFileObject(String jsp, MemoryJavaFileObject memoryJavaFileObject) {
+ cachedObjects.put(jsp, memoryJavaFileObject);
+ }
+}
\ No newline at end of file
Added: struts/sandbox/trunk/struts2-jsp-plugin/src/main/java/org/apache/struts2/compiler/MemoryJavaFileObject.java
URL: http://svn.apache.org/viewvc/struts/sandbox/trunk/struts2-jsp-plugin/src/main/java/org/apache/struts2/compiler/MemoryJavaFileObject.java?rev=799681&view=auto
==============================================================================
--- struts/sandbox/trunk/struts2-jsp-plugin/src/main/java/org/apache/struts2/compiler/MemoryJavaFileObject.java (added)
+++ struts/sandbox/trunk/struts2-jsp-plugin/src/main/java/org/apache/struts2/compiler/MemoryJavaFileObject.java Fri Jul 31 18:12:48 2009
@@ -0,0 +1,64 @@
+/*
+ * $Id$
+ *
+ * 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.struts2.compiler;
+
+import javax.tools.JavaFileObject;
+import javax.tools.SimpleJavaFileObject;
+import java.io.*;
+import java.net.URISyntaxException;
+import java.net.URI;
+
+public class MemoryJavaFileObject extends SimpleJavaFileObject {
+
+ private ByteArrayOutputStream out;
+
+ public MemoryJavaFileObject(String name, JavaFileObject.Kind kind) {
+ super(toURI(name), kind);
+ }
+
+ public CharSequence getCharContent(boolean ignoreEncodingErrors)
+ throws IOException, IllegalStateException,
+ UnsupportedOperationException {
+ throw new UnsupportedOperationException();
+ }
+
+ public InputStream openInputStream() throws IOException,
+ IllegalStateException, UnsupportedOperationException {
+ return new ByteArrayInputStream(out.toByteArray());
+ }
+
+ public OutputStream openOutputStream() throws IOException,
+ IllegalStateException, UnsupportedOperationException {
+ return out = new ByteArrayOutputStream();
+ }
+
+ private static URI toURI(String name) {
+ try {
+ return new URI(name);
+ } catch (URISyntaxException e) {
+ throw new RuntimeException(e);
+ }
+ }
+
+ public byte[] toByteArray() {
+ return out.toByteArray();
+ }
+}
Added: struts/sandbox/trunk/struts2-jsp-plugin/src/main/java/org/apache/struts2/jasper/Constants.java
URL: http://svn.apache.org/viewvc/struts/sandbox/trunk/struts2-jsp-plugin/src/main/java/org/apache/struts2/jasper/Constants.java?rev=799681&view=auto
==============================================================================
--- struts/sandbox/trunk/struts2-jsp-plugin/src/main/java/org/apache/struts2/jasper/Constants.java (added)
+++ struts/sandbox/trunk/struts2-jsp-plugin/src/main/java/org/apache/struts2/jasper/Constants.java Fri Jul 31 18:12:48 2009
@@ -0,0 +1,215 @@
+/*
+ * 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.struts2.jasper;
+
+
+/**
+ * Some constants and other global data that are used by the compiler and the runtime.
+ *
+ * @author Anil K. Vijendran
+ * @author Harish Prabandham
+ * @author Shawn Bayern
+ * @author Mark Roth
+ */
+public class Constants {
+ /**
+ * The base class of the generated servlets.
+ */
+ public static final String JSP_SERVLET_BASE = "org.apache.struts2.jasper.runtime.HttpJspBase";
+
+ /**
+ * _jspService is the name of the method that is called by
+ * HttpJspBase.service(). This is where most of the code generated
+ * from JSPs go.
+ */
+ public static final String SERVICE_METHOD_NAME = "_jspService";
+
+ /**
+ * Default servlet content type.
+ */
+ public static final String SERVLET_CONTENT_TYPE = "text/html";
+
+ /**
+ * These classes/packages are automatically imported by the
+ * generated code.
+ */
+ public static final String[] STANDARD_IMPORTS = {
+ "javax.servlet.*",
+ "javax.servlet.http.*",
+ "javax.servlet.jsp.*"
+ };
+
+ /**
+ * FIXME
+ * ServletContext attribute for classpath. This is tomcat specific.
+ * Other servlet engines may choose to support this attribute if they
+ * want to have this JSP engine running on them.
+ */
+ public static final String SERVLET_CLASSPATH = "org.apache.catalina.jsp_classpath";
+
+ /**
+ * FIXME
+ * Request attribute for <code><jsp-file></code> element of a
+ * servlet definition. If present on a request, this overrides the
+ * value returned by <code>request.getServletPath()</code> to select
+ * the JSP page to be executed.
+ */
+ public static final String JSP_FILE = "org.apache.catalina.jsp_file";
+
+
+ /**
+ * FIXME
+ * ServletContext attribute for class loader. This is tomcat specific.
+ * Other servlet engines can choose to have this attribute if they
+ * want to have this JSP engine running on them.
+ */
+ //public static final String SERVLET_CLASS_LOADER = "org.apache.tomcat.classloader";
+ public static final String SERVLET_CLASS_LOADER = "org.apache.catalina.classloader";
+
+ /**
+ * Default size of the JSP buffer.
+ */
+ public static final int K = 1024;
+ public static final int DEFAULT_BUFFER_SIZE = 8*K;
+
+ /**
+ * Default size for the tag buffers.
+ */
+ public static final int DEFAULT_TAG_BUFFER_SIZE = 512;
+
+ /**
+ * Default tag handler pool size.
+ */
+ public static final int MAX_POOL_SIZE = 5;
+
+ /**
+ * The query parameter that causes the JSP engine to just
+ * pregenerated the servlet but not invoke it.
+ */
+ public static final String PRECOMPILE = "jsp_precompile";
+
+ /**
+ * The default package name for compiled jsp pages.
+ */
+ public static final String JSP_PACKAGE_NAME = "org.apache.jsp";
+
+ /**
+ * The default package name for tag handlers generated from tag files
+ */
+ public static final String TAG_FILE_PACKAGE_NAME = "org.apache.jsp.tag";
+
+ /**
+ * Servlet context and request attributes that the JSP engine
+ * uses.
+ */
+ public static final String INC_REQUEST_URI = "javax.servlet.include.request_uri";
+ public static final String INC_SERVLET_PATH = "javax.servlet.include.servlet_path";
+ public static final String TMP_DIR = "javax.servlet.context.tempdir";
+ public static final String FORWARD_SEEN = "javax.servlet.forward.seen";
+
+ // Must be kept in sync with org/apache/catalina/Globals.java
+ public static final String ALT_DD_ATTR = "org.apache.catalina.deploy.alt_dd";
+
+ /**
+ * Public Id and the Resource path (of the cached copy)
+ * of the DTDs for tag library descriptors.
+ */
+ public static final String TAGLIB_DTD_PUBLIC_ID_11 =
+ "-//Sun Microsystems, Inc.//DTD JSP Tag Library 1.1//EN";
+ public static final String TAGLIB_DTD_RESOURCE_PATH_11 =
+ "/javax/servlet/jsp/resources/web-jsptaglibrary_1_1.dtd";
+ public static final String TAGLIB_DTD_PUBLIC_ID_12 =
+ "-//Sun Microsystems, Inc.//DTD JSP Tag Library 1.2//EN";
+ public static final String TAGLIB_DTD_RESOURCE_PATH_12 =
+ "/javax/servlet/jsp/resources/web-jsptaglibrary_1_2.dtd";
+
+ /**
+ * Public Id and the Resource path (of the cached copy)
+ * of the DTDs for web application deployment descriptors
+ */
+ public static final String WEBAPP_DTD_PUBLIC_ID_22 =
+ "-//Sun Microsystems, Inc.//DTD Web Application 2.2//EN";
+ public static final String WEBAPP_DTD_RESOURCE_PATH_22 =
+ "/javax/servlet/resources/web-app_2_2.dtd";
+ public static final String WEBAPP_DTD_PUBLIC_ID_23 =
+ "-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN";
+ public static final String WEBAPP_DTD_RESOURCE_PATH_23 =
+ "/javax/servlet/resources/web-app_2_3.dtd";
+
+ /**
+ * List of the Public IDs that we cache, and their
+ * associated location. This is used by
+ * an EntityResolver to return the location of the
+ * cached copy of a DTD.
+ */
+ public static final String[] CACHED_DTD_PUBLIC_IDS = {
+ TAGLIB_DTD_PUBLIC_ID_11,
+ TAGLIB_DTD_PUBLIC_ID_12,
+ WEBAPP_DTD_PUBLIC_ID_22,
+ WEBAPP_DTD_PUBLIC_ID_23,
+ };
+ public static final String[] CACHED_DTD_RESOURCE_PATHS = {
+ TAGLIB_DTD_RESOURCE_PATH_11,
+ TAGLIB_DTD_RESOURCE_PATH_12,
+ WEBAPP_DTD_RESOURCE_PATH_22,
+ WEBAPP_DTD_RESOURCE_PATH_23,
+ };
+
+ /**
+ * Default URLs to download the pluging for Netscape and IE.
+ */
+ public static final String NS_PLUGIN_URL =
+ "http://java.sun.com/products/plugin/";
+
+ public static final String IE_PLUGIN_URL =
+ "http://java.sun.com/products/plugin/1.2.2/jinstall-1_2_2-win.cab#Version=1,2,2,0";
+
+ /**
+ * Prefix to use for generated temporary variable names
+ */
+ public static final String TEMP_VARIABLE_NAME_PREFIX =
+ "_jspx_temp";
+
+ /**
+ * Previous replacement char for "\$".
+ * @deprecated
+ */
+ public static final char ESC='\u001b';
+
+ /**
+ * Previous replacement char for "\$".
+ * @deprecated
+ */
+ public static final String ESCStr="'\\u001b'";
+
+ /**
+ * Replacement char for "\$". This is the first unicode character in the
+ * private use area.
+ * XXX This is a hack to avoid changing EL interpreter to recognize "\$"
+ */
+ public static final char HACK_CHAR = '\ue000';
+
+ /**
+ * Replacement string for "\$". This is the first unicode character in the
+ * private use area.
+ * XXX This is a hack to avoid changing EL interpreter to recognize "\$"
+ */
+ public static final String HACK_STR = "'\\ue000'";
+
+}
+
Added: struts/sandbox/trunk/struts2-jsp-plugin/src/main/java/org/apache/struts2/jasper/CustomCompiler.java
URL: http://svn.apache.org/viewvc/struts/sandbox/trunk/struts2-jsp-plugin/src/main/java/org/apache/struts2/jasper/CustomCompiler.java?rev=799681&view=auto
==============================================================================
--- struts/sandbox/trunk/struts2-jsp-plugin/src/main/java/org/apache/struts2/jasper/CustomCompiler.java (added)
+++ struts/sandbox/trunk/struts2-jsp-plugin/src/main/java/org/apache/struts2/jasper/CustomCompiler.java Fri Jul 31 18:12:48 2009
@@ -0,0 +1,40 @@
+/*
+ * $Id$
+ *
+ * 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.struts2.jasper;
+
+import org.apache.struts2.jasper.compiler.*;
+import org.apache.struts2.jasper.JasperException;
+
+import java.io.*;
+
+public class CustomCompiler extends org.apache.struts2.jasper.compiler.Compiler{
+
+ public boolean isOutDated() {
+ return true;
+ }
+
+ public boolean isOutDated(boolean checkClass) {
+ return true;
+ }
+
+ protected void generateClass(String[] smap) throws FileNotFoundException, JasperException, Exception {
+ }
+}
Added: struts/sandbox/trunk/struts2-jsp-plugin/src/main/java/org/apache/struts2/jasper/EmbeddedServletOptions.java
URL: http://svn.apache.org/viewvc/struts/sandbox/trunk/struts2-jsp-plugin/src/main/java/org/apache/struts2/jasper/EmbeddedServletOptions.java?rev=799681&view=auto
==============================================================================
--- struts/sandbox/trunk/struts2-jsp-plugin/src/main/java/org/apache/struts2/jasper/EmbeddedServletOptions.java (added)
+++ struts/sandbox/trunk/struts2-jsp-plugin/src/main/java/org/apache/struts2/jasper/EmbeddedServletOptions.java Fri Jul 31 18:12:48 2009
@@ -0,0 +1,646 @@
+/*
+ * 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.struts2.jasper;
+
+import java.io.File;
+import java.util.*;
+
+import javax.servlet.ServletConfig;
+import javax.servlet.ServletContext;
+
+import org.apache.struts2.jasper.compiler.TldLocationsCache;
+import org.apache.struts2.jasper.compiler.JspConfig;
+import org.apache.struts2.jasper.compiler.TagPluginManager;
+import org.apache.struts2.jasper.compiler.Localizer;
+import org.apache.struts2.jasper.xmlparser.ParserUtils;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+
+/**
+ * A class to hold all init parameters specific to the JSP engine.
+ *
+ * @author Anil K. Vijendran
+ * @author Hans Bergsten
+ * @author Pierre Delisle
+ */
+public final class EmbeddedServletOptions implements Options {
+
+ // Logger
+ private Log log = LogFactory.getLog(EmbeddedServletOptions.class);
+
+ private Properties settings = new Properties();
+
+ /**
+ * Is Jasper being used in development mode?
+ */
+ private boolean development = true;
+
+ /**
+ * Should Ant fork its java compiles of JSP pages.
+ */
+ public boolean fork = true;
+
+ /**
+ * Do you want to keep the generated Java files around?
+ */
+ private boolean keepGenerated = true;
+
+ /**
+ * Should white spaces between directives or actions be trimmed?
+ */
+ private boolean trimSpaces = false;
+
+ /**
+ * Determines whether tag handler pooling is enabled.
+ */
+ 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.
+ */
+ 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.
+ */
+ private boolean sendErrorToClient = false;
+
+ /**
+ * Do we want to include debugging information in the class file?
+ */
+ private boolean classDebugInfo = true;
+
+ /**
+ * Background compile thread check interval in seconds.
+ */
+ private int checkInterval = 0;
+
+ /**
+ * Is the generation of SMAP info for JSR45 debuggin suppressed?
+ */
+ private boolean isSmapSuppressed = false;
+
+ /**
+ * Should SMAP info for JSR45 debugging be dumped to a file?
+ */
+ private boolean isSmapDumped = false;
+
+ /**
+ * Are Text strings to be generated as char arrays?
+ */
+ private boolean genStringAsCharArray = false;
+
+ private boolean errorOnUseBeanInvalidClassAttribute = true;
+
+ /**
+ * I want to see my generated servlets. Which directory are they
+ * in?
+ */
+ 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>"
+ */
+ private String ieClassId = "clsid:8AD9C840-044E-11D1-B3E9-00805F499D93";
+
+ /**
+ * What classpath should I use while compiling generated servlets?
+ */
+ private String classpath = null;
+
+ /**
+ * Compiler to use.
+ */
+ private String compiler = null;
+
+ /**
+ * Compiler target VM.
+ */
+ private String compilerTargetVM = "1.5";
+
+ /**
+ * The compiler source VM.
+ */
+ private String compilerSourceVM = "1.5";
+
+ /**
+ * Cache for the TLD locations
+ */
+ private TldLocationsCache tldLocationsCache = null;
+
+ /**
+ * Jsp config information
+ */
+ private JspConfig jspConfig = null;
+
+ /**
+ * TagPluginManager
+ */
+ private TagPluginManager tagPluginManager = null;
+
+ /**
+ * Java platform encoding to generate the JSP
+ * page servlet.
+ */
+ private String javaEncoding = "UTF8";
+
+ /**
+ * Modification test interval.
+ */
+ private int modificationTestInterval = 4;
+
+ /**
+ * Is generation of X-Powered-By response header enabled/disabled?
+ */
+ private boolean xpoweredBy;
+
+ public String getProperty(String name ) {
+ return settings.getProperty( name );
+ }
+
+ public void setProperty(String name, String value ) {
+ if (name != null && value != null){
+ settings.setProperty( name, value );
+ }
+ }
+
+ /**
+ * Are we keeping generated code around?
+ */
+ public boolean getKeepGenerated() {
+ return keepGenerated;
+ }
+
+ /**
+ * Should white spaces between directives or actions be trimmed?
+ */
+ public boolean getTrimSpaces() {
+ return trimSpaces;
+ }
+
+ public boolean isPoolingEnabled() {
+ return isPoolingEnabled;
+ }
+
+ /**
+ * Are we supporting HTML mapped servlets?
+ */
+ public boolean getMappedFile() {
+ return mappedFile;
+ }
+
+ /**
+ * Should errors be sent to client or thrown into stderr?
+ */
+ public boolean getSendErrorToClient() {
+ return sendErrorToClient;
+ }
+
+ /**
+ * Should class files be compiled with debug information?
+ */
+ public boolean getClassDebugInfo() {
+ return classDebugInfo;
+ }
+
+ /**
+ * Background JSP compile thread check intervall
+ */
+ public int getCheckInterval() {
+ return checkInterval;
+ }
+
+ /**
+ * Modification test interval.
+ */
+ public int getModificationTestInterval() {
+ return modificationTestInterval;
+ }
+
+ /**
+ * Is Jasper being used in development mode?
+ */
+ public boolean getDevelopment() {
+ return development;
+ }
+
+ /**
+ * Is the generation of SMAP info for JSR45 debuggin suppressed?
+ */
+ public boolean isSmapSuppressed() {
+ return isSmapSuppressed;
+ }
+
+ /**
+ * Should SMAP info for JSR45 debugging be dumped to a file?
+ */
+ public boolean isSmapDumped() {
+ return isSmapDumped;
+ }
+
+ /**
+ * Are Text strings to be generated as char arrays?
+ */
+ public boolean genStringAsCharArray() {
+ return this.genStringAsCharArray;
+ }
+
+ /**
+ * Class ID for use in the plugin tag when the browser is IE.
+ */
+ public String getIeClassId() {
+ return ieClassId;
+ }
+
+ /**
+ * What is my scratch dir?
+ */
+ public File getScratchDir() {
+ return scratchDir;
+ }
+
+ /**
+ * What classpath should I use while compiling the servlets
+ * generated from JSP files?
+ */
+ public String getClassPath() {
+ return classpath;
+ }
+
+ /**
+ * Is generation of X-Powered-By response header enabled/disabled?
+ */
+ public boolean isXpoweredBy() {
+ return xpoweredBy;
+ }
+
+ /**
+ * Compiler to use.
+ */
+ public String getCompiler() {
+ return compiler;
+ }
+
+ /**
+ * @see Options#getCompilerTargetVM
+ */
+ public String getCompilerTargetVM() {
+ return compilerTargetVM;
+ }
+
+ /**
+ * @see Options#getCompilerSourceVM
+ */
+ public String getCompilerSourceVM() {
+ return compilerSourceVM;
+ }
+
+ public boolean getErrorOnUseBeanInvalidClassAttribute() {
+ return errorOnUseBeanInvalidClassAttribute;
+ }
+
+ public void setErrorOnUseBeanInvalidClassAttribute(boolean b) {
+ errorOnUseBeanInvalidClassAttribute = b;
+ }
+
+ public TldLocationsCache getTldLocationsCache() {
+ return tldLocationsCache;
+ }
+
+ public void setTldLocationsCache( TldLocationsCache tldC ) {
+ tldLocationsCache = tldC;
+ }
+
+ public String getJavaEncoding() {
+ return javaEncoding;
+ }
+
+ public boolean getFork() {
+ return fork;
+ }
+
+ public JspConfig getJspConfig() {
+ return jspConfig;
+ }
+
+ public TagPluginManager getTagPluginManager() {
+ return tagPluginManager;
+ }
+
+ public boolean isCaching() {
+ return false;
+ }
+
+ public Map getCache() {
+ return null;
+ }
+
+ /**
+ * Create an EmbeddedServletOptions object using data available from
+ * ServletConfig and ServletContext.
+ */
+ public EmbeddedServletOptions(ServletConfig config,
+ ServletContext context) {
+
+ // JVM version numbers
+ try {
+ if (Float.parseFloat(System.getProperty("java.specification.version")) > 1.4) {
+ compilerSourceVM = compilerTargetVM = "1.5";
+ } else {
+ compilerSourceVM = compilerTargetVM = "1.4";
+ }
+ } catch (NumberFormatException e) {
+ // Ignore
+ }
+
+ Enumeration enumeration=config.getInitParameterNames();
+ while( enumeration.hasMoreElements() ) {
+ String k=(String)enumeration.nextElement();
+ String v=config.getInitParameter( k );
+ setProperty( k, v);
+ }
+
+ // quick hack
+ String validating=config.getInitParameter( "validating");
+ if( "false".equals( validating )) ParserUtils.validating=false;
+
+ String keepgen = config.getInitParameter("keepgenerated");
+ if (keepgen != null) {
+ if (keepgen.equalsIgnoreCase("true")) {
+ this.keepGenerated = true;
+ } else if (keepgen.equalsIgnoreCase("false")) {
+ this.keepGenerated = false;
+ } else {
+ if (log.isWarnEnabled()) {
+ log.warn(Localizer.getMessage("jsp.warning.keepgen"));
+ }
+ }
+ }
+
+
+ String trimsp = config.getInitParameter("trimSpaces");
+ if (trimsp != null) {
+ if (trimsp.equalsIgnoreCase("true")) {
+ trimSpaces = true;
+ } else if (trimsp.equalsIgnoreCase("false")) {
+ trimSpaces = false;
+ } else {
+ if (log.isWarnEnabled()) {
+ log.warn(Localizer.getMessage("jsp.warning.trimspaces"));
+ }
+ }
+ }
+
+ this.isPoolingEnabled = true;
+ String poolingEnabledParam
+ = config.getInitParameter("enablePooling");
+ if (poolingEnabledParam != null
+ && !poolingEnabledParam.equalsIgnoreCase("true")) {
+ if (poolingEnabledParam.equalsIgnoreCase("false")) {
+ this.isPoolingEnabled = false;
+ } else {
+ if (log.isWarnEnabled()) {
+ log.warn(Localizer.getMessage("jsp.warning.enablePooling"));
+ }
+ }
+ }
+
+ String mapFile = config.getInitParameter("mappedfile");
+ if (mapFile != null) {
+ if (mapFile.equalsIgnoreCase("true")) {
+ this.mappedFile = true;
+ } else if (mapFile.equalsIgnoreCase("false")) {
+ this.mappedFile = false;
+ } else {
+ if (log.isWarnEnabled()) {
+ log.warn(Localizer.getMessage("jsp.warning.mappedFile"));
+ }
+ }
+ }
+
+ String senderr = config.getInitParameter("sendErrToClient");
+ if (senderr != null) {
+ if (senderr.equalsIgnoreCase("true")) {
+ this.sendErrorToClient = true;
+ } else if (senderr.equalsIgnoreCase("false")) {
+ this.sendErrorToClient = false;
+ } else {
+ if (log.isWarnEnabled()) {
+ log.warn(Localizer.getMessage("jsp.warning.sendErrToClient"));
+ }
+ }
+ }
+
+ String debugInfo = config.getInitParameter("classdebuginfo");
+ if (debugInfo != null) {
+ if (debugInfo.equalsIgnoreCase("true")) {
+ this.classDebugInfo = true;
+ } else if (debugInfo.equalsIgnoreCase("false")) {
+ this.classDebugInfo = false;
+ } else {
+ if (log.isWarnEnabled()) {
+ log.warn(Localizer.getMessage("jsp.warning.classDebugInfo"));
+ }
+ }
+ }
+
+ String checkInterval = config.getInitParameter("checkInterval");
+ if (checkInterval != null) {
+ try {
+ this.checkInterval = Integer.parseInt(checkInterval);
+ } catch(NumberFormatException ex) {
+ if (log.isWarnEnabled()) {
+ log.warn(Localizer.getMessage("jsp.warning.checkInterval"));
+ }
+ }
+ }
+
+ String modificationTestInterval = config.getInitParameter("modificationTestInterval");
+ if (modificationTestInterval != null) {
+ try {
+ this.modificationTestInterval = Integer.parseInt(modificationTestInterval);
+ } catch(NumberFormatException ex) {
+ if (log.isWarnEnabled()) {
+ log.warn(Localizer.getMessage("jsp.warning.modificationTestInterval"));
+ }
+ }
+ }
+
+ String development = config.getInitParameter("development");
+ if (development != null) {
+ if (development.equalsIgnoreCase("true")) {
+ this.development = true;
+ } else if (development.equalsIgnoreCase("false")) {
+ this.development = false;
+ } else {
+ if (log.isWarnEnabled()) {
+ log.warn(Localizer.getMessage("jsp.warning.development"));
+ }
+ }
+ }
+
+ String suppressSmap = config.getInitParameter("suppressSmap");
+ if (suppressSmap != null) {
+ if (suppressSmap.equalsIgnoreCase("true")) {
+ isSmapSuppressed = true;
+ } else if (suppressSmap.equalsIgnoreCase("false")) {
+ isSmapSuppressed = false;
+ } else {
+ if (log.isWarnEnabled()) {
+ log.warn(Localizer.getMessage("jsp.warning.suppressSmap"));
+ }
+ }
+ }
+
+ String dumpSmap = config.getInitParameter("dumpSmap");
+ if (dumpSmap != null) {
+ if (dumpSmap.equalsIgnoreCase("true")) {
+ isSmapDumped = true;
+ } else if (dumpSmap.equalsIgnoreCase("false")) {
+ isSmapDumped = false;
+ } else {
+ if (log.isWarnEnabled()) {
+ log.warn(Localizer.getMessage("jsp.warning.dumpSmap"));
+ }
+ }
+ }
+
+ String genCharArray = config.getInitParameter("genStrAsCharArray");
+ if (genCharArray != null) {
+ if (genCharArray.equalsIgnoreCase("true")) {
+ genStringAsCharArray = true;
+ } else if (genCharArray.equalsIgnoreCase("false")) {
+ genStringAsCharArray = false;
+ } else {
+ if (log.isWarnEnabled()) {
+ log.warn(Localizer.getMessage("jsp.warning.genchararray"));
+ }
+ }
+ }
+
+ String errBeanClass =
+ config.getInitParameter("errorOnUseBeanInvalidClassAttribute");
+ if (errBeanClass != null) {
+ if (errBeanClass.equalsIgnoreCase("true")) {
+ errorOnUseBeanInvalidClassAttribute = true;
+ } else if (errBeanClass.equalsIgnoreCase("false")) {
+ errorOnUseBeanInvalidClassAttribute = false;
+ } else {
+ if (log.isWarnEnabled()) {
+ log.warn(Localizer.getMessage("jsp.warning.errBean"));
+ }
+ }
+ }
+
+ String ieClassId = config.getInitParameter("ieClassId");
+ if (ieClassId != null)
+ this.ieClassId = ieClassId;
+
+ String classpath = config.getInitParameter("classpath");
+ if (classpath != null)
+ this.classpath = classpath;
+
+ /*
+ * scratchdir
+ */
+ String dir = config.getInitParameter("scratchdir");
+ if (dir != null) {
+ scratchDir = new File(dir);
+ } else {
+ // First try the Servlet 2.2 javax.servlet.context.tempdir property
+ scratchDir = (File) context.getAttribute(Constants.TMP_DIR);
+ if (scratchDir == null) {
+ // Not running in a Servlet 2.2 container.
+ // Try to get the JDK 1.2 java.io.tmpdir property
+ dir = System.getProperty("java.io.tmpdir");
+ if (dir != null)
+ scratchDir = new File(dir);
+ }
+ }
+ if (this.scratchDir == null) {
+ log.fatal(Localizer.getMessage("jsp.error.no.scratch.dir"));
+ return;
+ }
+
+ if (!(scratchDir.exists() && scratchDir.canRead() &&
+ scratchDir.canWrite() && scratchDir.isDirectory()))
+ log.fatal(Localizer.getMessage("jsp.error.bad.scratch.dir",
+ scratchDir.getAbsolutePath()));
+
+ this.compiler = config.getInitParameter("compiler");
+
+ String compilerTargetVM = config.getInitParameter("compilerTargetVM");
+ if(compilerTargetVM != null) {
+ this.compilerTargetVM = compilerTargetVM;
+ }
+
+ String compilerSourceVM = config.getInitParameter("compilerSourceVM");
+ if(compilerSourceVM != null) {
+ this.compilerSourceVM = compilerSourceVM;
+ }
+
+ String javaEncoding = config.getInitParameter("javaEncoding");
+ if (javaEncoding != null) {
+ this.javaEncoding = javaEncoding;
+ }
+
+ String fork = config.getInitParameter("fork");
+ if (fork != null) {
+ if (fork.equalsIgnoreCase("true")) {
+ this.fork = true;
+ } else if (fork.equalsIgnoreCase("false")) {
+ this.fork = false;
+ } else {
+ if (log.isWarnEnabled()) {
+ log.warn(Localizer.getMessage("jsp.warning.fork"));
+ }
+ }
+ }
+
+ String xpoweredBy = config.getInitParameter("xpoweredBy");
+ if (xpoweredBy != null) {
+ if (xpoweredBy.equalsIgnoreCase("true")) {
+ this.xpoweredBy = true;
+ } else if (xpoweredBy.equalsIgnoreCase("false")) {
+ this.xpoweredBy = false;
+ } else {
+ if (log.isWarnEnabled()) {
+ log.warn(Localizer.getMessage("jsp.warning.xpoweredBy"));
+ }
+ }
+ }
+
+ // Setup the global Tag Libraries location cache for this
+ // web-application.
+ tldLocationsCache = new TldLocationsCache(context);
+
+ // Setup the jsp config info for this web app.
+ jspConfig = new JspConfig(context);
+
+ // Create a Tag plugin instance
+ tagPluginManager = new TagPluginManager(context);
+ }
+
+}
+
Added: struts/sandbox/trunk/struts2-jsp-plugin/src/main/java/org/apache/struts2/jasper/JasperException.java
URL: http://svn.apache.org/viewvc/struts/sandbox/trunk/struts2-jsp-plugin/src/main/java/org/apache/struts2/jasper/JasperException.java?rev=799681&view=auto
==============================================================================
--- struts/sandbox/trunk/struts2-jsp-plugin/src/main/java/org/apache/struts2/jasper/JasperException.java (added)
+++ struts/sandbox/trunk/struts2-jsp-plugin/src/main/java/org/apache/struts2/jasper/JasperException.java Fri Jul 31 18:12:48 2009
@@ -0,0 +1,46 @@
+/*
+ * 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.struts2.jasper;
+
+/**
+ * Base class for all exceptions generated by the JSP engine. Makes it
+ * convienient to catch just this at the top-level.
+ *
+ * @author Anil K. Vijendran
+ */
+public class JasperException extends javax.servlet.ServletException {
+
+ public JasperException(String reason) {
+ super(reason);
+ }
+
+ /**
+ * Creates a JasperException with the embedded exception and the reason for
+ * throwing a JasperException
+ */
+ public JasperException (String reason, Throwable exception) {
+ super(reason, exception);
+ }
+
+ /**
+ * Creates a JasperException with the embedded exception
+ */
+ public JasperException (Throwable exception) {
+ super(exception);
+ }
+}