incubator-sling-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jus...@apache.org
Subject svn commit: r1096843 - in /sling/trunk/bundles/scripting/jsp/src/main/java/org/apache/sling/scripting/jsp/jasper: compiler/ runtime/
Date Tue, 26 Apr 2011 18:42:05 GMT
Author: justin
Date: Tue Apr 26 18:42:05 2011
New Revision: 1096843

URL: http://svn.apache.org/viewvc?rev=1096843&view=rev
Log:
SLING-2057 - wrapping the servlet context / request dispatcher for other contexts to use the
original JspFactory when doing forwards or includes on a different context.

Added:
    sling/trunk/bundles/scripting/jsp/src/main/java/org/apache/sling/scripting/jsp/jasper/runtime/ExternalServletContextWrapper.java
    sling/trunk/bundles/scripting/jsp/src/main/java/org/apache/sling/scripting/jsp/jasper/runtime/InternalServletConfigWrapper.java
Modified:
    sling/trunk/bundles/scripting/jsp/src/main/java/org/apache/sling/scripting/jsp/jasper/compiler/JspRuntimeContext.java
    sling/trunk/bundles/scripting/jsp/src/main/java/org/apache/sling/scripting/jsp/jasper/runtime/PageContextImpl.java

Modified: sling/trunk/bundles/scripting/jsp/src/main/java/org/apache/sling/scripting/jsp/jasper/compiler/JspRuntimeContext.java
URL: http://svn.apache.org/viewvc/sling/trunk/bundles/scripting/jsp/src/main/java/org/apache/sling/scripting/jsp/jasper/compiler/JspRuntimeContext.java?rev=1096843&r1=1096842&r2=1096843&view=diff
==============================================================================
--- sling/trunk/bundles/scripting/jsp/src/main/java/org/apache/sling/scripting/jsp/jasper/compiler/JspRuntimeContext.java
(original)
+++ sling/trunk/bundles/scripting/jsp/src/main/java/org/apache/sling/scripting/jsp/jasper/compiler/JspRuntimeContext.java
Tue Apr 26 18:42:05 2011
@@ -149,6 +149,10 @@ public final class JspRuntimeContext {
             final Integer count = JspRuntimeContext.USE_OWN_FACTORY.get();
             JspRuntimeContext.USE_OWN_FACTORY.set(count - 1);
         }
+
+        public JspFactory getOriginal() {
+            return original;
+        }
     }
 
     /**

Added: sling/trunk/bundles/scripting/jsp/src/main/java/org/apache/sling/scripting/jsp/jasper/runtime/ExternalServletContextWrapper.java
URL: http://svn.apache.org/viewvc/sling/trunk/bundles/scripting/jsp/src/main/java/org/apache/sling/scripting/jsp/jasper/runtime/ExternalServletContextWrapper.java?rev=1096843&view=auto
==============================================================================
--- sling/trunk/bundles/scripting/jsp/src/main/java/org/apache/sling/scripting/jsp/jasper/runtime/ExternalServletContextWrapper.java
(added)
+++ sling/trunk/bundles/scripting/jsp/src/main/java/org/apache/sling/scripting/jsp/jasper/runtime/ExternalServletContextWrapper.java
Tue Apr 26 18:42:05 2011
@@ -0,0 +1,190 @@
+/*
+ * 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.jasper.runtime;
+
+import java.io.IOException;
+import java.io.InputStream;
+import java.net.MalformedURLException;
+import java.net.URL;
+import java.util.Enumeration;
+import java.util.Set;
+
+import javax.servlet.RequestDispatcher;
+import javax.servlet.Servlet;
+import javax.servlet.ServletContext;
+import javax.servlet.ServletException;
+import javax.servlet.ServletRequest;
+import javax.servlet.ServletResponse;
+import javax.servlet.jsp.JspFactory;
+import javax.servlet.jsp.PageContext;
+
+import org.apache.sling.scripting.jsp.jasper.compiler.JspRuntimeContext.JspFactoryHandler;
+
+/**
+ * Wrapper around a ServletContext for an external servlet context, i.e. one
+ * returned by servletContext.getContext(String)
+ */
+class ExternalServletContextWrapper implements ServletContext {
+    
+    private final ServletContext delegate;
+    private final PageContext pageContext;
+    
+    public ExternalServletContextWrapper(ServletContext sc, PageContext pageContext) {
+        this.delegate = sc;
+        this.pageContext = pageContext;
+    }
+
+    public ServletContext getContext(String s) {
+        return delegate.getContext(s);
+    }
+
+    public String getContextPath() {
+        return delegate.getContextPath();
+    }
+
+    public int getMajorVersion() {
+        return delegate.getMajorVersion();
+    }
+
+    public int getMinorVersion() {
+        return delegate.getMinorVersion();
+    }
+
+    public String getMimeType(String s) {
+        return delegate.getMimeType(s);
+    }
+
+    public Set getResourcePaths(String s) {
+        return delegate.getResourcePaths(s);
+    }
+
+    public URL getResource(String s) throws MalformedURLException {
+        return delegate.getResource(s);
+    }
+
+    public InputStream getResourceAsStream(String s) {
+        return delegate.getResourceAsStream(s);
+    }
+
+    public RequestDispatcher getRequestDispatcher(String s) {
+        return new RequestDispatcherWrapper(delegate.getRequestDispatcher(s));
+    }
+
+    public RequestDispatcher getNamedDispatcher(String s) {
+        return new RequestDispatcherWrapper(delegate.getNamedDispatcher(s));
+    }
+
+    public Servlet getServlet(String s) throws ServletException {
+        return delegate.getServlet(s);
+    }
+
+    public Enumeration getServlets() {
+        return delegate.getServlets();
+    }
+
+    public Enumeration getServletNames() {
+        return delegate.getServletNames();
+    }
+
+    public void log(String s) {
+        delegate.log(s);
+    }
+
+    public void log(Exception exception, String s) {
+        delegate.log(exception, s);
+    }
+
+    public void log(String s, Throwable throwable) {
+        delegate.log(s, throwable);
+    }
+
+    public String getRealPath(String s) {
+        return delegate.getRealPath(s);
+    }
+
+    public String getServerInfo() {
+        return delegate.getServerInfo();
+    }
+
+    public String getInitParameter(String s) {
+        return delegate.getInitParameter(s);
+    }
+
+    public Enumeration getInitParameterNames() {
+        return delegate.getInitParameterNames();
+    }
+
+    public Object getAttribute(String s) {
+        return delegate.getAttribute(s);
+    }
+
+    public Enumeration getAttributeNames() {
+        return delegate.getAttributeNames();
+    }
+
+    public void setAttribute(String s, Object obj) {
+        delegate.setAttribute(s, obj);
+    }
+
+    public void removeAttribute(String s) {
+        delegate.removeAttribute(s);
+    }
+
+    public String getServletContextName() {
+        return delegate.getServletContextName();
+    }
+
+    class RequestDispatcherWrapper implements RequestDispatcher {
+        
+        private final RequestDispatcher delegate;
+        
+        public RequestDispatcherWrapper(RequestDispatcher rd) {
+            this.delegate = rd;
+        }
+
+        public void forward(ServletRequest request, ServletResponse response) throws ServletException,
+                IOException {
+            JspFactory saveDefaultFactory = JspFactory.getDefaultFactory();
+            if (saveDefaultFactory instanceof JspFactoryHandler) {
+                pageContext.getOut().flush();
+                JspFactory.setDefaultFactory(((JspFactoryHandler)saveDefaultFactory).getOriginal());
+                try {
+                    delegate.forward(request, response);
+                } finally {
+                    JspFactory.setDefaultFactory(saveDefaultFactory);
+                }
+            }
+        }
+
+        public void include(ServletRequest request, ServletResponse response) throws ServletException,
+                IOException {
+            JspFactory saveDefaultFactory = JspFactory.getDefaultFactory();
+            if (saveDefaultFactory instanceof JspFactoryHandler) {
+                pageContext.getOut().flush();
+                JspFactory.setDefaultFactory(((JspFactoryHandler)saveDefaultFactory).getOriginal());
+                try {
+                    delegate.include(request, response);
+                } finally {
+                    JspFactory.setDefaultFactory(saveDefaultFactory);
+                }
+            }
+
+        }
+
+    }
+
+}

Added: sling/trunk/bundles/scripting/jsp/src/main/java/org/apache/sling/scripting/jsp/jasper/runtime/InternalServletConfigWrapper.java
URL: http://svn.apache.org/viewvc/sling/trunk/bundles/scripting/jsp/src/main/java/org/apache/sling/scripting/jsp/jasper/runtime/InternalServletConfigWrapper.java?rev=1096843&view=auto
==============================================================================
--- sling/trunk/bundles/scripting/jsp/src/main/java/org/apache/sling/scripting/jsp/jasper/runtime/InternalServletConfigWrapper.java
(added)
+++ sling/trunk/bundles/scripting/jsp/src/main/java/org/apache/sling/scripting/jsp/jasper/runtime/InternalServletConfigWrapper.java
Tue Apr 26 18:42:05 2011
@@ -0,0 +1,181 @@
+/*
+ * 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.jasper.runtime;
+
+import java.io.InputStream;
+import java.net.MalformedURLException;
+import java.net.URL;
+import java.util.Enumeration;
+import java.util.Set;
+
+import javax.servlet.RequestDispatcher;
+import javax.servlet.Servlet;
+import javax.servlet.ServletConfig;
+import javax.servlet.ServletContext;
+import javax.servlet.ServletException;
+import javax.servlet.jsp.PageContext;
+
+/**
+ * Wrapper around the Sling servlet config in order to return a wrapped servlet context
+ * for other servlet contexts.
+ */
+class InternalServletConfigWrapper implements ServletConfig {
+    
+    private final ServletConfig delegate;
+    
+    private final PageContext pageContext;
+    
+    public InternalServletConfigWrapper(ServletConfig sc, PageContext pageContext) {
+        this.delegate = sc;
+        this.pageContext = pageContext;
+    }
+
+    public String getServletName() {
+        return delegate.getServletName();
+    }
+
+    public ServletContext getServletContext() {
+        return new InternalServletContextWrapper(delegate.getServletContext());
+    }
+
+    public String getInitParameter(String s) {
+        return delegate.getInitParameter(s);
+    }
+
+    public Enumeration getInitParameterNames() {
+        return delegate.getInitParameterNames();
+    }
+    
+    class InternalServletContextWrapper implements ServletContext {
+        
+        private final ServletContext delegate;
+        
+        public InternalServletContextWrapper(ServletContext sc) {
+            this.delegate = sc;
+        }
+
+        public ServletContext getContext(String s) {
+            ServletContext sc = delegate.getContext(s);
+            if (sc == delegate) {
+                return this;
+            } else {
+                return new ExternalServletContextWrapper(sc, pageContext);
+            }
+        }
+
+        public String getContextPath() {
+            return delegate.getContextPath();
+        }
+
+        public int getMajorVersion() {
+            return delegate.getMajorVersion();
+        }
+
+        public int getMinorVersion() {
+            return delegate.getMinorVersion();
+        }
+
+        public String getMimeType(String s) {
+            return delegate.getMimeType(s);
+        }
+
+        public Set getResourcePaths(String s) {
+            return delegate.getResourcePaths(s);
+        }
+
+        public URL getResource(String s) throws MalformedURLException {
+            return delegate.getResource(s);
+        }
+
+        public InputStream getResourceAsStream(String s) {
+            return delegate.getResourceAsStream(s);
+        }
+
+        public RequestDispatcher getRequestDispatcher(String s) {
+            return delegate.getRequestDispatcher(s);
+        }
+
+        public RequestDispatcher getNamedDispatcher(String s) {
+            return delegate.getNamedDispatcher(s);
+        }
+
+        public Servlet getServlet(String s) throws ServletException {
+            return delegate.getServlet(s);
+        }
+
+        public Enumeration getServlets() {
+            return delegate.getServlets();
+        }
+
+        public Enumeration getServletNames() {
+            return delegate.getServletNames();
+        }
+
+        public void log(String s) {
+            delegate.log(s);
+        }
+
+        public void log(Exception exception, String s) {
+            delegate.log(exception, s);
+        }
+
+        public void log(String s, Throwable throwable) {
+            delegate.log(s, throwable);
+        }
+
+        public String getRealPath(String s) {
+            return delegate.getRealPath(s);
+        }
+
+        public String getServerInfo() {
+            return delegate.getServerInfo();
+        }
+
+        public String getInitParameter(String s) {
+            return delegate.getInitParameter(s);
+        }
+
+        public Enumeration getInitParameterNames() {
+            return delegate.getInitParameterNames();
+        }
+
+        public Object getAttribute(String s) {
+            return delegate.getAttribute(s);
+        }
+
+        public Enumeration getAttributeNames() {
+            return delegate.getAttributeNames();
+        }
+
+        public void setAttribute(String s, Object obj) {
+            delegate.setAttribute(s, obj);
+        }
+
+        public void removeAttribute(String s) {
+            delegate.removeAttribute(s);
+        }
+
+        public String getServletContextName() {
+            return delegate.getServletContextName();
+        }
+        
+        
+    }
+    
+    
+
+}

Modified: sling/trunk/bundles/scripting/jsp/src/main/java/org/apache/sling/scripting/jsp/jasper/runtime/PageContextImpl.java
URL: http://svn.apache.org/viewvc/sling/trunk/bundles/scripting/jsp/src/main/java/org/apache/sling/scripting/jsp/jasper/runtime/PageContextImpl.java?rev=1096843&r1=1096842&r2=1096843&view=diff
==============================================================================
--- sling/trunk/bundles/scripting/jsp/src/main/java/org/apache/sling/scripting/jsp/jasper/runtime/PageContextImpl.java
(original)
+++ sling/trunk/bundles/scripting/jsp/src/main/java/org/apache/sling/scripting/jsp/jasper/runtime/PageContextImpl.java
Tue Apr 26 18:42:05 2011
@@ -130,7 +130,7 @@ public class PageContextImpl extends Pag
 
 		// initialize state
 		this.servlet = servlet;
-		this.config = servlet.getServletConfig();
+		this.config = new InternalServletConfigWrapper(servlet.getServletConfig(), this);
 		this.context = config.getServletContext();
 		this.errorPageURL = errorPageURL;
 		this.request = request;



Mime
View raw message