Author: cziegeler
Date: Fri Nov 23 13:08:48 2012
New Revision: 1412868
URL: http://svn.apache.org/viewvc?rev=1412868&view=rev
Log:
Support portals bridge
Added:
sling/whiteboard/portal/container-api/src/main/java/org/apache/sling/portal/container/bridge/
sling/whiteboard/portal/container-api/src/main/java/org/apache/sling/portal/container/bridge/impl/
sling/whiteboard/portal/container-api/src/main/java/org/apache/sling/portal/container/bridge/impl/ServletContextProviderImpl.java
(with props)
Modified:
sling/whiteboard/portal/container-api/pom.xml
sling/whiteboard/portal/container-api/src/main/java/org/apache/sling/portal/container/api/SlingRequestDispatcher.java
Modified: sling/whiteboard/portal/container-api/pom.xml
URL:
http://svn.apache.org/viewvc/sling/whiteboard/portal/container-api/pom.xml?rev=1412868&r1=1412867&r2=1412868&view=diff
==============================================================================
--- sling/whiteboard/portal/container-api/pom.xml (original)
+++ sling/whiteboard/portal/container-api/pom.xml Fri Nov 23 13:08:48 2012
@@ -69,5 +69,12 @@
<version>2.0</version>
<scope>provided</scope>
</dependency>
+
+ <dependency>
+ <groupId>org.apache.portals.bridges</groupId>
+ <artifactId>portals-bridges-common</artifactId>
+ <version>2.0</version>
+ <scope>provided</scope>
+ </dependency>
</dependencies>
</project>
Modified:
sling/whiteboard/portal/container-api/src/main/java/org/apache/sling/portal/container/api/SlingRequestDispatcher.java
URL:
http://svn.apache.org/viewvc/sling/whiteboard/portal/container-api/src/main/java/org/apache/sling/portal/container/api/SlingRequestDispatcher.java?rev=1412868&r1=1412867&r2=1412868&view=diff
==============================================================================
---
sling/whiteboard/portal/container-api/src/main/java/org/apache/sling/portal/container/api/SlingRequestDispatcher.java
(original)
+++
sling/whiteboard/portal/container-api/src/main/java/org/apache/sling/portal/container/api/SlingRequestDispatcher.java
Fri Nov 23 13:08:48 2012
@@ -32,15 +32,30 @@ public interface SlingRequestDispatcher
String REQ_ATTR = SlingRequestDispatcher.class.getName();
- String OPTION_RELATIVE_PATH = "relativePath";
-
+ /**
+ * The full path of the resource to use.
+ */
String OPTION_PATH = "path";
- String OPTION_RESOURCE_TYPE = "resourceType";
-
- String OPTION_EXTENSION = "extension";
+ /**
+ * Relative path of the resource to use.
+ * This is only used if {@link #OPTION_PATH} is not specified.
+ */
+ String OPTION_RELATIVE_PATH = "relativePath";
- String OPTION_SELECTOR = "selector";
+ /**
+ * Resource type if the specified resource does not exist! Otherwise
+ * the resource type of the existing resource is used.
+ */
+ String OPTION_RESOURCE_TYPE = "resourceType";
+ /**
+ * Include the resource with the options
+ * @param writer The writer to write the rendered resource to
+ * @param options The options - must not be null
+ * @throws IOException
+ * @throws ServletException
+ * @throws NullPointerException If writer or options us null.
+ */
void include(PrintWriter writer, Map<String, Object> options) throws
IOException, ServletException;
}
Added:
sling/whiteboard/portal/container-api/src/main/java/org/apache/sling/portal/container/bridge/impl/ServletContextProviderImpl.java
URL:
http://svn.apache.org/viewvc/sling/whiteboard/portal/container-api/src/main/java/org/apache/sling/portal/container/bridge/impl/ServletContextProviderImpl.java?rev=1412868&view=auto
==============================================================================
---
sling/whiteboard/portal/container-api/src/main/java/org/apache/sling/portal/container/bridge/impl/ServletContextProviderImpl.java
(added)
+++
sling/whiteboard/portal/container-api/src/main/java/org/apache/sling/portal/container/bridge/impl/ServletContextProviderImpl.java
Fri Nov 23 13:08:48 2012
@@ -0,0 +1,137 @@
+/*
+ * 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.portal.container.bridge.impl;
+
+import java.lang.reflect.InvocationTargetException;
+import java.lang.reflect.Method;
+
+import javax.portlet.GenericPortlet;
+import javax.portlet.PortletContext;
+import javax.portlet.PortletRequest;
+import javax.portlet.PortletResponse;
+import javax.portlet.filter.PortletRequestWrapper;
+import javax.portlet.filter.PortletResponseWrapper;
+import javax.servlet.ServletContext;
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+
+import org.apache.pluto.container.PortletRequestContext;
+import org.apache.pluto.container.PortletResponseContext;
+import org.apache.portals.bridges.common.ServletContextProvider;
+
+/**
+ * Implementation of the portal bridge servlet context provider
+ */
+public class ServletContextProviderImpl implements ServletContextProvider {
+
+ private Method getRequestContext;
+ private Method getResponseContext;
+ private Method getServletContext;
+ private Method getWrappedRequest;
+
+ private Method searchMethod(final Class<?> clazz, final String name) {
+ final Method m = findMethod(clazz, name);
+ if ( m == null ) {
+ throw new RuntimeException("NoSuchMethodException Object of type "
+ clazz + " does not have method named " + name);
+ }
+ return m;
+ }
+
+ private Method findMethod(final Class<?> clazz, final String name) {
+ try {
+ final Method m = clazz.getDeclaredMethod(name, null);
+ m.setAccessible(true);
+ return m;
+ } catch (final SecurityException e) {
+ // ignore
+ } catch (final NoSuchMethodException e) {
+ // ignore
+ } catch (final IllegalArgumentException e) {
+ // ignore
+ }
+ if ( clazz.getSuperclass() != null ) {
+ return findMethod(clazz.getSuperclass(), name);
+ }
+ return null;
+ }
+
+ private Object invoke(final Object obj, final Method m) {
+ if ( m != null ) {
+ try {
+ return m.invoke(obj, null);
+ } catch (final IllegalAccessException e) {
+ // ignore
+ } catch (final InvocationTargetException e) {
+ // ignore
+ }
+ }
+ return null;
+ }
+
+ private PortletRequest unwrap(PortletRequest req) {
+ while ( req instanceof PortletRequestWrapper ) {
+ req = ((PortletRequestWrapper)req).getRequest();
+ }
+ return req;
+ }
+
+ private PortletResponse unwrap(PortletResponse res) {
+ while ( res instanceof PortletResponseWrapper ) {
+ res = ((PortletResponseWrapper)res).getResponse();
+ }
+ return res;
+ }
+
+ public HttpServletRequest getHttpServletRequest(final GenericPortlet
portlet,
+ final PortletRequest r) {
+ final PortletRequest req = unwrap(r);
+ if ( getRequestContext == null ) {
+ getRequestContext = searchMethod(req.getClass(),
"getRequestContext");
+ }
+ final PortletRequestContext context = (PortletRequestContext)
invoke(req, getRequestContext);
+ if ( context != null ) {
+ if ( getWrappedRequest == null ) {
+ getWrappedRequest = searchMethod(context.getClass(),
"getWrappedRequest");
+ }
+ return (HttpServletRequest) invoke(context, getWrappedRequest);
+ }
+
+ return null;
+ }
+
+ public HttpServletResponse getHttpServletResponse(final GenericPortlet
portlet,
+ final PortletResponse r) {
+ final PortletResponse res = unwrap(r);
+ if ( getResponseContext == null ) {
+ getResponseContext = searchMethod(res.getClass(),
"getResponseContext");
+ }
+ final PortletResponseContext context = (PortletResponseContext)
invoke(res, getResponseContext);
+ if ( context != null ) {
+ return context.getServletResponse();
+ }
+
+ return null;
+ }
+
+ public ServletContext getServletContext(final GenericPortlet portlet) {
+ final PortletContext context = portlet.getPortletContext();
+ if ( getServletContext == null ) {
+ getServletContext = searchMethod(context.getClass(),
"getServletContext");
+ }
+ return (ServletContext)invoke(context, getServletContext);
+ }
+}
Propchange:
sling/whiteboard/portal/container-api/src/main/java/org/apache/sling/portal/container/bridge/impl/ServletContextProviderImpl.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange:
sling/whiteboard/portal/container-api/src/main/java/org/apache/sling/portal/container/bridge/impl/ServletContextProviderImpl.java
------------------------------------------------------------------------------
svn:keywords = author date id revision rev url
Propchange:
sling/whiteboard/portal/container-api/src/main/java/org/apache/sling/portal/container/bridge/impl/ServletContextProviderImpl.java
------------------------------------------------------------------------------
svn:mime-type = text/plain