Author: ate
Date: Thu Jun 21 18:21:29 2007
New Revision: 549659
URL: http://svn.apache.org/viewvc?view=rev&rev=549659
Log:
Some bug fixes and improvements made while testing on Jetty
Added:
portals/bridges/trunk/common/src/java/org/apache/portals/bridges/util/NamespacedNamesEnumeration.java
(with props)
Modified:
portals/bridges/trunk/common/src/java/org/apache/portals/bridges/util/ServletPortletSessionProxy.java
Added:
portals/bridges/trunk/common/src/java/org/apache/portals/bridges/util/NamespacedNamesEnumeration.java
URL:
http://svn.apache.org/viewvc/portals/bridges/trunk/common/src/java/org/apache/portals/bridges/util/NamespacedNamesEnumeration.java?view=auto&rev=549659
==============================================================================
---
portals/bridges/trunk/common/src/java/org/apache/portals/bridges/util/NamespacedNamesEnumeration.java
(added)
+++
portals/bridges/trunk/common/src/java/org/apache/portals/bridges/util/NamespacedNamesEnumeration.java
Thu Jun 21 18:21:29 2007
@@ -0,0 +1,72 @@
+/*
+ * 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.portals.bridges.util;
+
+import java.util.Enumeration;
+import java.util.NoSuchElementException;
+
+/**
+ * @author <a href="mailto:[EMAIL PROTECTED]">Ate Douma</a>
+ * @version $Id$
+ */
+public class NamespacedNamesEnumeration implements Enumeration
+{
+ private Enumeration namesEnumeration;
+ private String namespace;
+
+ private String nextName;
+ private boolean done;
+
+ public NamespacedNamesEnumeration(Enumeration namesEnumeration, String
namespace)
+ {
+ this.namesEnumeration = namesEnumeration;
+ this.namespace = namespace;
+ hasMoreElements();
+ }
+
+ public boolean hasMoreElements()
+ {
+ if (!done)
+ {
+ if (nextName == null)
+ {
+ while (namesEnumeration.hasMoreElements())
+ {
+ String name = (String)namesEnumeration.nextElement();
+ if ( name.startsWith(namespace))
+ {
+ nextName = name.substring(namespace.length());
+ break;
+ }
+ }
+ done = nextName == null;
+ }
+ }
+ return !done;
+ }
+
+ public Object nextElement()
+ {
+ if (done)
+ {
+ throw new NoSuchElementException();
+ }
+ String name = nextName;
+ nextName = null;
+ return name;
+ }
+}
\ No newline at end of file
Propchange:
portals/bridges/trunk/common/src/java/org/apache/portals/bridges/util/NamespacedNamesEnumeration.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange:
portals/bridges/trunk/common/src/java/org/apache/portals/bridges/util/NamespacedNamesEnumeration.java
------------------------------------------------------------------------------
svn:keywords = Id
Modified:
portals/bridges/trunk/common/src/java/org/apache/portals/bridges/util/ServletPortletSessionProxy.java
URL:
http://svn.apache.org/viewvc/portals/bridges/trunk/common/src/java/org/apache/portals/bridges/util/ServletPortletSessionProxy.java?view=diff&rev=549659&r1=549658&r2=549659
==============================================================================
---
portals/bridges/trunk/common/src/java/org/apache/portals/bridges/util/ServletPortletSessionProxy.java
(original)
+++
portals/bridges/trunk/common/src/java/org/apache/portals/bridges/util/ServletPortletSessionProxy.java
Thu Jun 21 18:21:29 2007
@@ -19,8 +19,9 @@
import java.lang.reflect.InvocationHandler;
import java.lang.reflect.Method;
import java.lang.reflect.Proxy;
+import java.util.ArrayList;
import java.util.Enumeration;
-import java.util.NoSuchElementException;
+import java.util.HashSet;
import javax.portlet.PortletRequest;
import javax.portlet.PortletSession;
@@ -45,54 +46,6 @@
*/
public class ServletPortletSessionProxy implements InvocationHandler
{
- private static class PortletSessionAttributeNamesEnumeration implements
Enumeration
- {
- private Enumeration namesEnumeration;
- private String portletWindowPrefix;
-
- private String nextName;
- private boolean done;
-
- public PortletSessionAttributeNamesEnumeration(Enumeration
namesEnumeration, String portletWindowPrefix)
- {
- this.namesEnumeration = namesEnumeration;
- this.portletWindowPrefix = portletWindowPrefix;
- hasMoreElements();
- }
-
- public boolean hasMoreElements()
- {
- if (!done)
- {
- if (nextName == null)
- {
- while (namesEnumeration.hasMoreElements())
- {
- String name = (String)namesEnumeration.nextElement();
- if ( name.startsWith(portletWindowPrefix))
- {
- nextName =
name.substring(portletWindowPrefix.length());
- break;
- }
- }
- done = nextName == null;
- }
- }
- return !done;
- }
-
- public Object nextElement()
- {
- if (done)
- {
- throw new NoSuchElementException();
- }
- String name = nextName;
- nextName = null;
- return name;
- }
- }
-
HttpSession servletSession;
String portletWindowPrefix;
@@ -103,23 +56,43 @@
if (portletRequest != null)
{
PortletSession portletSession = portletRequest.getPortletSession();
- servletSession = (HttpSession)createProxy(request,
PortletWindowUtils.getPortletWindowId(portletSession));
+ servletSession = (HttpSession)createProxy(request,
"javax.portlet.p."+PortletWindowUtils.getPortletWindowId(portletSession));
}
return servletSession;
}
- public static HttpSession createProxy(HttpServletRequest request, String
portletWindowId)
+ public static HttpSession createProxy(HttpServletRequest request, String
portletWindowNamespace)
{
HttpSession servletSession = request.getSession();
- return (HttpSession)
Proxy.newProxyInstance(servletSession.getClass().getClassLoader(),
- servletSession.getClass().getInterfaces(), new
ServletPortletSessionProxy(request.getSession(),
- portletWindowId));
+ HashSet interfaces = new HashSet();
+ interfaces.add(HttpSession.class);
+ Class current = servletSession.getClass();
+ while (current != null)
+ {
+ try
+ {
+ Class[] currentInterfaces = current.getInterfaces();
+ for (int i = 0; i < currentInterfaces.length; i++)
+ {
+ interfaces.add(currentInterfaces[i]);
+ }
+ current = current.getSuperclass();
+ }
+ catch (Exception e)
+ {
+ current = null;
+ }
+ }
+ Object proxy =
Proxy.newProxyInstance(servletSession.getClass().getClassLoader(),
+ (Class[])interfaces.toArray(new Class[interfaces.size()]), new
ServletPortletSessionProxy(request.getSession(),
+ portletWindowNamespace));
+ return (HttpSession)proxy;
}
- private ServletPortletSessionProxy(HttpSession servletSession, String
portletWindowId)
+ private ServletPortletSessionProxy(HttpSession servletSession, String
portletWindowPrefix)
{
this.servletSession = servletSession;
- this.portletWindowPrefix =
PortletWindowUtils.getApplicationScopeSessionAttributeName(portletWindowId,"");
+ this.portletWindowPrefix = portletWindowPrefix;
}
/**
@@ -143,9 +116,19 @@
{
servletSession.removeAttribute(portletWindowPrefix+(String)args[0]);
}
- else if (("getAttributeNames".equals(m.getName()) ||
"getValueNames".equals(m.getName())) && args.length == 0)
+ else if ("getAttributeNames".equals(m.getName()) && args == null)
+ {
+ retval = new
NamespacedNamesEnumeration(servletSession.getAttributeNames(),
portletWindowPrefix);
+ }
+ else if ("getValueNames".equals(m.getName()) && args == null)
{
- retval = new
PortletSessionAttributeNamesEnumeration(servletSession.getAttributeNames(),
portletWindowPrefix);
+ ArrayList list = new ArrayList();
+ Enumeration e = new
NamespacedNamesEnumeration(servletSession.getAttributeNames(),
portletWindowPrefix);
+ while (e.hasMoreElements())
+ {
+ list.add(e.nextElement());
+ }
+ retval = list.toArray(new String[list.size()]);
}
else
{
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]