gatein SVN: r3837 - components/wsrp/trunk/wsrp-producer-war/src/test/java/org/gatein/wsrp/support.
by do-not-reply@jboss.org
Author: mwringe
Date: 2010-08-16 18:44:50 -0400 (Mon, 16 Aug 2010)
New Revision: 3837
Added:
components/wsrp/trunk/wsrp-producer-war/src/test/java/org/gatein/wsrp/support/TestMockExportPersistenceManager.java
Log:
GTNWSRP-55: add missing classes from last commit
Added: components/wsrp/trunk/wsrp-producer-war/src/test/java/org/gatein/wsrp/support/TestMockExportPersistenceManager.java
===================================================================
--- components/wsrp/trunk/wsrp-producer-war/src/test/java/org/gatein/wsrp/support/TestMockExportPersistenceManager.java (rev 0)
+++ components/wsrp/trunk/wsrp-producer-war/src/test/java/org/gatein/wsrp/support/TestMockExportPersistenceManager.java 2010-08-16 22:44:50 UTC (rev 3837)
@@ -0,0 +1,159 @@
+/******************************************************************************
+ * JBoss, a division of Red Hat *
+ * Copyright 2010, Red Hat Middleware, LLC, and individual *
+ * contributors as indicated by the @authors tag. See the *
+ * copyright.txt in the distribution for a full listing of *
+ * individual contributors. *
+ * *
+ * This is free software; you can redistribute it and/or modify it *
+ * under the terms of the GNU Lesser General Public License as *
+ * published by the Free Software Foundation; either version 2.1 of *
+ * the License, or (at your option) any later version. *
+ * *
+ * This software is distributed in the hope that it will be useful, *
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of *
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU *
+ * Lesser General Public License for more details. *
+ * *
+ * You should have received a copy of the GNU Lesser General Public *
+ * License along with this software; if not, write to the Free *
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA *
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org. *
+ ******************************************************************************/
+package org.gatein.wsrp.support;
+
+import java.io.IOException;
+import java.io.UnsupportedEncodingException;
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.UUID;
+
+import org.gatein.exports.ExportPersistenceManager;
+import org.gatein.exports.data.ExportContext;
+import org.gatein.exports.data.ExportPortletData;
+import org.gatein.exports.data.PersistedExportData;
+import org.jboss.messaging.util.NotYetImplementedException;
+import org.oasis.wsrp.v2.Lifetime;
+
+/**
+ * @author <a href="mailto:mwringe@redhat.com">Matt Wringe</a>
+ * @version $Revision$
+ */
+public class TestMockExportPersistenceManager implements ExportPersistenceManager
+{
+
+ public static final String PEC_TYPE = "P_EC";
+ public static final double PEC_VERSION = 1.0;
+
+ Map<String,ExportContext> exportContexts = new HashMap<String,ExportContext>();
+
+ //For testing purposes only
+ public Map<String, ExportContext> getExportContexts()
+ {
+ return exportContexts;
+ }
+
+ public ExportContext getExportContext(String type, double version, byte[] bytes) throws UnsupportedEncodingException
+ {
+ if (supports(type, version))
+ {
+ PersistedExportData persistedExportData = PersistedExportData.create(bytes);
+ String refId = persistedExportData.getRefId();
+ return exportContexts.get(refId);
+ }
+ else
+ {
+ return null;
+ }
+ }
+
+ public void releaseExport(byte[] bytes)
+ {
+ try
+ {
+ PersistedExportData persistedExportData = PersistedExportData.create(bytes);
+ String refId = persistedExportData.getRefId();
+ if (exportContexts.containsKey(refId))
+ {
+ exportContexts.remove(refId);
+ }
+ }
+ catch (Exception e)
+ {
+ System.out.println("ERROR When trying to release exports");
+ e.printStackTrace();
+ }
+ }
+
+ public ExportContext retrieveExportContextData(String refid)
+ {
+ if (exportContexts.containsKey(refid))
+ {
+ return exportContexts.get(refid);
+ }
+ else
+ {
+ return null;
+ }
+ }
+
+ public ExportPortletData retrieveExportPortletData(String refid)
+ {
+ throw new NotYetImplementedException();
+ }
+
+ public String storeExportContextData(ExportContext exportContextData)
+ {
+ if (exportContextData != null)
+ {
+ String refId = UUID.randomUUID().toString();
+ exportContexts.put(refId, exportContextData);
+ return refId;
+ }
+ else
+ {
+ return null;
+ }
+ }
+
+ public String storeExportPortletData(ExportPortletData exportPortletData)
+ {
+ throw new NotYetImplementedException();
+ }
+
+ public boolean supports(String type, double version)
+ {
+ if (type.equals(PEC_TYPE) && (version == PEC_VERSION))
+ {
+ return true;
+ }
+ else
+ {
+ return false;
+ }
+ }
+
+ @Override
+ public Lifetime updateExportLifetime(ExportContext exportContext, Lifetime lifetime)
+ {
+ throw new NotYetImplementedException();
+ }
+
+ @Override
+ public byte[] encodeExportContextData(ExportContext exportContext) throws IOException
+ {
+ String refId = storeExportContextData(exportContext);
+ PersistedExportData persistedExportData = new PersistedExportData(this.PEC_TYPE, refId);
+ return persistedExportData.encodeAsBytes();
+ }
+
+ @Override
+ public byte[] encodeExportPortletData(ExportContext exportContext, ExportPortletData exportPortlet)
+ {
+ // FIXME encodeExportPortletData
+ return null;
+ }
+}
+
14 years, 5 months
gatein SVN: r3836 - in components/wsrp/trunk: producer/src/main/java/org/gatein/exports/data and 7 other directories.
by do-not-reply@jboss.org
Author: mwringe
Date: 2010-08-16 18:42:41 -0400 (Mon, 16 Aug 2010)
New Revision: 3836
Added:
components/wsrp/trunk/wsrp-producer-war/src/test/java/org/gatein/wsrp/support/
Modified:
components/wsrp/trunk/producer/src/main/java/org/gatein/exports/ExportManager.java
components/wsrp/trunk/producer/src/main/java/org/gatein/exports/ExportPersistenceManager.java
components/wsrp/trunk/producer/src/main/java/org/gatein/exports/data/PersistedExportData.java
components/wsrp/trunk/producer/src/main/java/org/gatein/exports/impl/ExportManagerImpl.java
components/wsrp/trunk/producer/src/main/java/org/gatein/wsrp/producer/handlers/PortletManagementHandler.java
components/wsrp/trunk/producer/src/main/java/org/gatein/wsrp/producer/v2/WSRP2Producer.java
components/wsrp/trunk/wsrp-producer-war/src/test/java/org/gatein/wsrp/portlet/StatePortlet.java
components/wsrp/trunk/wsrp-producer-war/src/test/java/org/gatein/wsrp/protocol/v1/ReleaseSessionTestCase.java
components/wsrp/trunk/wsrp-producer-war/src/test/java/org/gatein/wsrp/protocol/v2/PortletManagementTestCase.java
Log:
GTNPC-26: Add tests for the persistence export manager, fix issues with exporting by value.
Modified: components/wsrp/trunk/producer/src/main/java/org/gatein/exports/ExportManager.java
===================================================================
--- components/wsrp/trunk/producer/src/main/java/org/gatein/exports/ExportManager.java 2010-08-16 17:09:43 UTC (rev 3835)
+++ components/wsrp/trunk/producer/src/main/java/org/gatein/exports/ExportManager.java 2010-08-16 22:42:41 UTC (rev 3836)
@@ -26,6 +26,7 @@
import java.io.UnsupportedEncodingException;
import org.gatein.exports.data.ExportContext;
+import org.gatein.exports.data.ExportData;
import org.gatein.exports.data.ExportPortletData;
import org.oasis.wsrp.v2.Lifetime;
import org.oasis.wsrp.v2.OperationFailed;
@@ -57,6 +58,6 @@
Lifetime setExportLifetime(ExportContext exportContext, Lifetime lifetime) throws OperationFailed, OperationNotSupported;
- void releaseExport(ExportContext exportContext);
+ void releaseExport(byte[] bytes) throws IOException;
}
Modified: components/wsrp/trunk/producer/src/main/java/org/gatein/exports/ExportPersistenceManager.java
===================================================================
--- components/wsrp/trunk/producer/src/main/java/org/gatein/exports/ExportPersistenceManager.java 2010-08-16 17:09:43 UTC (rev 3835)
+++ components/wsrp/trunk/producer/src/main/java/org/gatein/exports/ExportPersistenceManager.java 2010-08-16 22:42:41 UTC (rev 3836)
@@ -22,6 +22,9 @@
******************************************************************************/
package org.gatein.exports;
+import java.io.IOException;
+import java.io.UnsupportedEncodingException;
+
import org.gatein.exports.data.ExportContext;
import org.gatein.exports.data.ExportPortletData;
import org.oasis.wsrp.v2.Lifetime;
@@ -31,8 +34,7 @@
* @version $Revision$
*/
public interface ExportPersistenceManager
-{
-
+{
String storeExportContextData(ExportContext exportContextData);
String storeExportPortletData(ExportPortletData exportPortletData);
@@ -43,6 +45,32 @@
Lifetime updateExportLifetime(ExportContext exportContext, Lifetime lifetime);
- void releaseExport(ExportContext exportContext);
+ void releaseExport(byte[] bytes);
+
+ /**
+ * Returns true if the PersistenceManager knows how to decode a byte array with
+ * the specified type and version.
+ *
+ * @param type The type of export
+ * @param version The version of the export
+ * @return True if the persistence manager can support the specified type and version.
+ */
+ boolean supports(String type, double version);
+
+ /**
+ * Based on the specified type and version, the bytes will be
+ * decoded into an ExportContext.
+ *
+ * @param type The type
+ * @param version The version
+ * @param bytes The bytes to decode
+ * @return
+ * @throws UnsupportedEncodingException
+ */
+ ExportContext getExportContext(String type, double version, byte[] bytes) throws UnsupportedEncodingException;
+
+ byte[] encodeExportPortletData(ExportContext exportContext, ExportPortletData exportPortlet);
+
+ byte[] encodeExportContextData(ExportContext exportContext) throws IOException;
}
Modified: components/wsrp/trunk/producer/src/main/java/org/gatein/exports/data/PersistedExportData.java
===================================================================
--- components/wsrp/trunk/producer/src/main/java/org/gatein/exports/data/PersistedExportData.java 2010-08-16 17:09:43 UTC (rev 3835)
+++ components/wsrp/trunk/producer/src/main/java/org/gatein/exports/data/PersistedExportData.java 2010-08-16 22:42:41 UTC (rev 3836)
@@ -36,11 +36,12 @@
{
protected final String type;
protected final String refID;
- protected static final double VERSION = 1.0;
protected static final String REFIDKEY = "rID";
protected static final String TYPEKEY = "type";
+ protected double version = 1.0;
+
public PersistedExportData(String type, String refID)
{
this.type = type;
@@ -54,14 +55,24 @@
public double getVersion()
{
- return VERSION;
+ return version;
}
+
+ public String getRefId()
+ {
+ return refID;
+ }
+
+ public void setVersion(double version)
+ {
+ this.version = version;
+ }
protected byte[] internalEncodeAsBytes() throws UnsupportedEncodingException
{
ParametersStateString parameterStateString = ParametersStateString.create();
- parameterStateString.setValue(REFIDKEY, REFIDKEY);
+ parameterStateString.setValue(REFIDKEY, refID);
parameterStateString.setValue(TYPEKEY, type);
String stateString = parameterStateString.getStringValue();
Modified: components/wsrp/trunk/producer/src/main/java/org/gatein/exports/impl/ExportManagerImpl.java
===================================================================
--- components/wsrp/trunk/producer/src/main/java/org/gatein/exports/impl/ExportManagerImpl.java 2010-08-16 17:09:43 UTC (rev 3835)
+++ components/wsrp/trunk/producer/src/main/java/org/gatein/exports/impl/ExportManagerImpl.java 2010-08-16 22:42:41 UTC (rev 3836)
@@ -31,6 +31,7 @@
import org.gatein.exports.data.ExportContext;
import org.gatein.exports.data.ExportData;
import org.gatein.exports.data.ExportPortletData;
+import org.gatein.exports.data.PersistedExportData;
import org.gatein.wsrp.WSRPExceptionFactory;
import org.oasis.wsrp.v2.Lifetime;
import org.oasis.wsrp.v2.OperationFailed;
@@ -78,6 +79,11 @@
return supportExportByValue;
}
+ public void setPreferExportByValue(boolean preferExportByValue)
+ {
+ this.preferExportByValue = preferExportByValue;
+ }
+
public ExportContext createExportContext(byte[] bytes) throws OperationFailed
{
try
@@ -89,6 +95,10 @@
byte[] internalBytes = ExportData.getInternalBytes(bytes);
return ExportContext.create(internalBytes);
}
+ else if (exportPersistenceManager != null && exportPersistenceManager.supports(type, version))
+ {
+ return exportPersistenceManager.getExportContext(type, version, ExportData.getInternalBytes(bytes));
+ }
else
{
throw WSRPExceptionFactory.createWSException(OperationFailed.class, "Byte array format not compatible.", null);
@@ -144,7 +154,7 @@
}
else
{
- throw new NotYetImplemented();
+ return exportPersistenceManager.encodeExportPortletData(exportContextData, exportPortletData);
}
}
@@ -156,30 +166,35 @@
}
else
{
- throw new NotYetImplemented();
+ return exportPersistenceManager.encodeExportContextData(exportContextData);
}
}
public Lifetime setExportLifetime(ExportContext exportContext, Lifetime lifetime) throws OperationFailed, OperationNotSupported
{
- if (exportContext.isExportByValue())
- {
- WSRPExceptionFactory.throwWSException(OperationFailed.class, "Cannot set the lifetime for an export that was exported by value.", null);
- }
if (getPersistenceManager() == null)
{
WSRPExceptionFactory.throwWSException(OperationNotSupported.class, "The producer only supports export by value. Cannot call setExportLifetime on this producer", null);
}
-
+ else if (exportContext.isExportByValue())
+ {
+ WSRPExceptionFactory.throwWSException(OperationFailed.class, "Cannot set the lifetime for an export that was exported by value.", null);
+ }
+
return getPersistenceManager().updateExportLifetime(exportContext, lifetime);
}
- public void releaseExport(ExportContext exportContext)
+ public void releaseExport(byte[] bytes) throws IOException
{
//TODO: since we can't return any errors, we should at least log messages if this method is called and it can't be completed for some reason.
- if (exportContext != null && !exportContext.isExportByValue() && exportPersistenceManager!= null)
+ if (bytes != null && bytes.length > 0 && exportPersistenceManager!= null)
{
- exportPersistenceManager.releaseExport(exportContext);
+ String type = ExportData.getType(bytes);
+ double version = ExportData.getVersion(bytes);
+ if (exportPersistenceManager.supports(type, version))
+ {
+ exportPersistenceManager.releaseExport(ExportData.getInternalBytes(bytes));
+ }
}
}
Modified: components/wsrp/trunk/producer/src/main/java/org/gatein/wsrp/producer/handlers/PortletManagementHandler.java
===================================================================
--- components/wsrp/trunk/producer/src/main/java/org/gatein/wsrp/producer/handlers/PortletManagementHandler.java 2010-08-16 17:09:43 UTC (rev 3835)
+++ components/wsrp/trunk/producer/src/main/java/org/gatein/wsrp/producer/handlers/PortletManagementHandler.java 2010-08-16 22:42:41 UTC (rev 3836)
@@ -550,6 +550,7 @@
ExportPortletData exportPortletData = producer.getExportManager().createExportPortletData(exportContext, portletHandle, portletState);
//Create the exportedPortlet
+ byte[] exportPortletBytes = producer.getExportManager().encodeExportPortletData(exportContext, exportPortletData);
ExportedPortlet exportedPortlet = WSRPTypeFactory.createExportedPortlet(portletHandle, exportPortletData.encodeAsBytes());
exportedPortlets.add(exportedPortlet);
}
@@ -593,12 +594,13 @@
//TODO: handle resourceLists better (should be using for things like errors)
ResourceList resourceList = null;
- return WSRPTypeFactory.createExportPortletsResponse(exportContext.encodeAsBytes(), exportedPortlets, new ArrayList<FailedPortlets>(failedPortletsMap.values()), exportContext.getLifeTime(), resourceList);
+ byte[] exportContextBytes = producer.getExportManager().encodeExportContextData(exportContext);
+
+ return WSRPTypeFactory.createExportPortletsResponse(exportContextBytes, exportedPortlets, new ArrayList<FailedPortlets>(failedPortletsMap.values()), exportContext.getLifeTime(), resourceList);
}
- catch (Exception e)//TODO ADD PROPER EXCEPTION HANDLING
+ catch (Exception e)
{
- e.printStackTrace();
- throw new OperationFailed("TODO: add proper error handling", new OperationFailedFault());
+ throw new OperationFailed("Operation Failed while trying to ExportPortlets.", new OperationFailedFault());
}
finally
{
@@ -721,10 +723,9 @@
{
try
{
- if (releaseExport != null)
+ if (releaseExport != null && releaseExport.getExportContext() != null)
{
- ExportContext exportContext = producer.getExportManager().createExportContext(releaseExport.getExportContext());
- producer.getExportManager().releaseExport(exportContext);
+ producer.getExportManager().releaseExport(releaseExport.getExportContext());
}
}
catch (Exception e)
@@ -739,8 +740,14 @@
return new ReturnAny().getExtensions();
}
- public Lifetime setExportLifetime(SetExportLifetime setExportLifetime) throws OperationFailed, InvalidRegistration
+ public Lifetime setExportLifetime(SetExportLifetime setExportLifetime) throws OperationFailed, InvalidRegistration, OperationNotSupported
{
+ //this method is only valid if the producer can handle exporting by reference.
+ if (producer.getExportManager().getPersistenceManager() == null)
+ {
+ WSRP2ExceptionFactory.throwWSException(OperationNotSupported.class, "This producer does not support export by reference.", null);
+ }
+
WSRP2ExceptionFactory.throwOperationFailedIfValueIsMissing(setExportLifetime, "setExportLifetimePortlets");
byte[] exportContextBytes = setExportLifetime.getExportContext();
Modified: components/wsrp/trunk/producer/src/main/java/org/gatein/wsrp/producer/v2/WSRP2Producer.java
===================================================================
--- components/wsrp/trunk/producer/src/main/java/org/gatein/wsrp/producer/v2/WSRP2Producer.java 2010-08-16 17:09:43 UTC (rev 3835)
+++ components/wsrp/trunk/producer/src/main/java/org/gatein/wsrp/producer/v2/WSRP2Producer.java 2010-08-16 22:42:41 UTC (rev 3836)
@@ -23,6 +23,7 @@
package org.gatein.wsrp.producer.v2;
+import org.gatein.exports.ExportManager;
import org.gatein.wsrp.producer.MarkupInterface;
import org.gatein.wsrp.producer.PortletManagementInterface;
import org.gatein.wsrp.producer.RegistrationInterface;
@@ -36,4 +37,17 @@
public interface WSRP2Producer extends WSRPProducer, MarkupInterface, PortletManagementInterface,
RegistrationInterface, ServiceDescriptionInterface
{
+ /**
+ * Retrieves the ExportManager used by this WSRPProducer.
+ *
+ * @return The ExportManager used by this WSRPProducer to manage exports
+ */
+ ExportManager getExportManager();
+
+ /**
+ * Sets the ExportManager used by this WSRPProducer
+ *
+ * @param The ExportManager to be used by this WSRPProducer
+ */
+ void setExportManager(ExportManager exportManager);
}
Modified: components/wsrp/trunk/wsrp-producer-war/src/test/java/org/gatein/wsrp/portlet/StatePortlet.java
===================================================================
--- components/wsrp/trunk/wsrp-producer-war/src/test/java/org/gatein/wsrp/portlet/StatePortlet.java 2010-08-16 17:09:43 UTC (rev 3835)
+++ components/wsrp/trunk/wsrp-producer-war/src/test/java/org/gatein/wsrp/portlet/StatePortlet.java 2010-08-16 22:42:41 UTC (rev 3836)
@@ -44,7 +44,6 @@
public void processAction(ActionRequest request, ActionResponse response) throws PortletException, PortletSecurityException, IOException
{
- System.out.println("PROCESSACTION");
String value = request.getParameter("value");
if (value == null)
{
@@ -58,34 +57,10 @@
protected void doView(RenderRequest req, RenderResponse resp) throws PortletException, PortletSecurityException, IOException
{
- System.out.println("DOVIEW");
resp.setContentType("text/html");
PortletPreferences pp = req.getPreferences();
String value = pp.getValue("name", "default");
resp.getWriter().write(value);
}
-
-
-// protected void doView(RenderRequest req, RenderResponse resp) throws PortletException, PortletSecurityException, IOException
-// {
-// resp.setContentType("text/html");
-// PrintWriter writer = resp.getWriter();
-//
-// PortletPreferences pp = req.getPreferences();
-// int count = 0;
-//
-// if (!pp.getValue(COUNT, "0").equals("0"))
-// {
-// count = Integer.parseInt(pp.getValue(COUNT, "0")) + 1;
-// }
-//
-// pp.setValue(COUNT, "" + count);
-// pp.store();
-//
-// writer.write("<p>count = " + count + "</p>");
-//
-// //
-// writer.close();
-// }
}
Modified: components/wsrp/trunk/wsrp-producer-war/src/test/java/org/gatein/wsrp/protocol/v1/ReleaseSessionTestCase.java
===================================================================
--- components/wsrp/trunk/wsrp-producer-war/src/test/java/org/gatein/wsrp/protocol/v1/ReleaseSessionTestCase.java 2010-08-16 17:09:43 UTC (rev 3835)
+++ components/wsrp/trunk/wsrp-producer-war/src/test/java/org/gatein/wsrp/protocol/v1/ReleaseSessionTestCase.java 2010-08-16 22:42:41 UTC (rev 3836)
@@ -147,7 +147,6 @@
// so we need to wait for the proper case to init the registration context... Hackish! :(
if (index == 0)
{
- System.out.println("REGISTRATIONCONTEXT : " + releaseSessions.getRegistrationContext());
releaseSessions.setRegistrationContext(registerConsumer());
}
}
Modified: components/wsrp/trunk/wsrp-producer-war/src/test/java/org/gatein/wsrp/protocol/v2/PortletManagementTestCase.java
===================================================================
--- components/wsrp/trunk/wsrp-producer-war/src/test/java/org/gatein/wsrp/protocol/v2/PortletManagementTestCase.java 2010-08-16 17:09:43 UTC (rev 3835)
+++ components/wsrp/trunk/wsrp-producer-war/src/test/java/org/gatein/wsrp/protocol/v2/PortletManagementTestCase.java 2010-08-16 22:42:41 UTC (rev 3836)
@@ -23,8 +23,6 @@
package org.gatein.wsrp.protocol.v2;
import java.io.IOException;
-import java.io.UnsupportedEncodingException;
-import java.rmi.RemoteException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
@@ -32,20 +30,18 @@
import org.gatein.exports.ExportManager;
import org.gatein.exports.data.ExportContext;
-import org.gatein.exports.data.ExportData;
import org.gatein.exports.data.ExportPortletData;
+import org.gatein.exports.data.PersistedExportData;
import org.gatein.exports.impl.ExportManagerImpl;
-import org.gatein.pc.api.Portlet;
import org.gatein.pc.api.PortletStateType;
import org.gatein.pc.api.state.PropertyMap;
import org.gatein.pc.portlet.state.SimplePropertyMap;
import org.gatein.pc.portlet.state.producer.PortletState;
import org.gatein.pc.portlet.state.producer.ProducerPortletInvoker;
import org.gatein.wsrp.WSRPTypeFactory;
-import org.gatein.wsrp.WSRPUtils;
import org.gatein.wsrp.producer.WSRPProducerBaseTest;
import org.gatein.wsrp.servlet.ServletAccess;
-import org.gatein.wsrp.spec.v2.WSRP2RewritingConstants;
+import org.gatein.wsrp.support.TestMockExportPersistenceManager;
import org.gatein.wsrp.test.ExtendedAssert;
import org.gatein.wsrp.test.support.MockHttpServletRequest;
import org.gatein.wsrp.test.support.MockHttpServletResponse;
@@ -57,7 +53,6 @@
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
-import org.oasis.wsrp.v2.AccessDenied;
import org.oasis.wsrp.v2.BlockingInteractionResponse;
import org.oasis.wsrp.v2.ExportPortlets;
import org.oasis.wsrp.v2.ExportPortletsResponse;
@@ -68,30 +63,20 @@
import org.oasis.wsrp.v2.ImportPortlets;
import org.oasis.wsrp.v2.ImportPortletsResponse;
import org.oasis.wsrp.v2.ImportedPortlet;
-import org.oasis.wsrp.v2.InconsistentParameters;
-import org.oasis.wsrp.v2.InvalidCookie;
-import org.oasis.wsrp.v2.InvalidHandle;
import org.oasis.wsrp.v2.InvalidRegistration;
-import org.oasis.wsrp.v2.InvalidSession;
-import org.oasis.wsrp.v2.InvalidUserCategory;
import org.oasis.wsrp.v2.Lifetime;
-import org.oasis.wsrp.v2.MarkupContext;
-import org.oasis.wsrp.v2.MarkupParams;
import org.oasis.wsrp.v2.MarkupResponse;
import org.oasis.wsrp.v2.MissingParameters;
-import org.oasis.wsrp.v2.ModifyRegistrationRequired;
import org.oasis.wsrp.v2.NamedString;
import org.oasis.wsrp.v2.OperationFailed;
+import org.oasis.wsrp.v2.OperationNotSupported;
import org.oasis.wsrp.v2.PerformBlockingInteraction;
import org.oasis.wsrp.v2.PortletContext;
import org.oasis.wsrp.v2.RegistrationContext;
import org.oasis.wsrp.v2.RegistrationData;
-import org.oasis.wsrp.v2.ResourceSuspended;
+import org.oasis.wsrp.v2.ReleaseExport;
+import org.oasis.wsrp.v2.SetExportLifetime;
import org.oasis.wsrp.v2.StateChange;
-import org.oasis.wsrp.v2.UnsupportedLocale;
-import org.oasis.wsrp.v2.UnsupportedMimeType;
-import org.oasis.wsrp.v2.UnsupportedMode;
-import org.oasis.wsrp.v2.UnsupportedWindowState;
import org.oasis.wsrp.v2.UserContext;
/**
@@ -115,6 +100,7 @@
jar.addClass(NeedPortletHandleTest.class);
jar.addClass(V2ProducerBaseTest.class);
jar.addClass(WSRPProducerBaseTest.class);
+ jar.addClass(TestMockExportPersistenceManager.class);
return jar;
}
@@ -127,6 +113,8 @@
//hack to get around having to have a httpservletrequest when accessing the producer services
//I don't know why its really needed, seems to be a dependency where wsrp connects with the pc module
ServletAccess.setRequestAndResponse(MockHttpServletRequest.createMockRequest(null), MockHttpServletResponse.createMockResponse());
+ producer.getExportManager().setPersistanceManager(null);
+ ((ExportManagerImpl)(producer.getExportManager())).setPreferExportByValue(true);
}
}
@@ -152,18 +140,9 @@
ExportPortlets exportPortlets = createSimpleExportPortlets(portletContexts);
ExportPortletsResponse response = producer.exportPortlets(exportPortlets);
- assertNotNull(response.getExportContext());
- assertNull(response.getLifetime());
- assertTrue(response.getFailedPortlets().isEmpty());
+ checkValidHandle(response, handle);
+ }
- assertEquals(1, response.getExportedPortlet().size());
-
- ExportedPortlet exportPortlet = response.getExportedPortlet().get(0);
-
- assertEquals(handle, exportPortlet.getPortletHandle());
- }
-
-
@Test
public void testExportNonExistantHandle() throws Exception
{
@@ -171,19 +150,9 @@
List<PortletContext> portletContexts = createPortletContextList(nonExistantHandle);
ExportPortlets exportPortlets = createSimpleExportPortlets(portletContexts);
-
ExportPortletsResponse response = producer.exportPortlets(exportPortlets);
- assertNotNull(response.getExportContext());
- assertNull(response.getLifetime());
- assertTrue(response.getExportedPortlet().isEmpty());
-
- assertEquals(1, response.getFailedPortlets().size());
-
- FailedPortlets failedPortlet = response.getFailedPortlets().get(0);
-
- assertTrue(failedPortlet.getPortletHandles().contains(nonExistantHandle));
- assertEquals("InvalidHandle",failedPortlet.getErrorCode().getLocalPart());
+ checkInvalidHandle(response, nonExistantHandle);
}
@Test
@@ -196,47 +165,10 @@
ExportPortletsResponse response = producer.exportPortlets(exportPortlets);
- assertNotNull(response.getExportContext());
- assertNull(response.getLifetime());
- assertTrue(response.getExportedPortlet().isEmpty());
-
- assertEquals(1, response.getFailedPortlets().size());
-
- FailedPortlets failedPortlet = response.getFailedPortlets().get(0);
- assertTrue(failedPortlet.getPortletHandles().contains(nullHandle));
- assertEquals("InvalidHandle",failedPortlet.getErrorCode().getLocalPart());
+ checkInvalidHandle(response, nullHandle);
}
@Test
- public void testExportNullExportContext() throws Exception
- {
- ExportPortlets exportPortlets = new ExportPortlets();
- try
- {
- ExportPortletsResponse response = producer.exportPortlets(exportPortlets);
- ExtendedAssert.fail("Should have thrown a MissingParameters fault if no portlets passed for export.");
- }
- catch (MissingParameters e)
- {
- //expected
- }
- }
-
- @Test
- public void testExportNullExportPortlets() throws Exception
- {
- try
- {
- ExportPortletsResponse response = producer.exportPortlets(null);
- ExtendedAssert.fail("Should have failed if sending a null exportPortlet object");
- }
- catch (MissingParameters e)
- {
- //expected
- }
- }
-
- @Test
public void testExportNoRegistrationWhenRequired() throws Exception
{
producer.getConfigurationService().getConfiguration().getRegistrationRequirements().setRegistrationRequired(true);
@@ -256,7 +188,7 @@
//expected
}
}
-
+
@Test
public void testExportBadRegistrationHandle() throws Exception
{
@@ -269,7 +201,6 @@
boolean exportByValueRequired = true;
Lifetime lifetime = null;
UserContext userContext = null;
-
ExportPortlets exportPortlets = WSRPTypeFactory.createExportPortlets(registrationContext, portletContexts, userContext, lifetime, exportByValueRequired);
try
@@ -282,7 +213,7 @@
//expected
}
}
-
+
@Test
public void testExportRegistrationRequired() throws Exception
{
@@ -291,29 +222,48 @@
RegistrationData registrationData = WSRPTypeFactory.createRegistrationData("CONSUMER", true);
RegistrationContext registrationContext = producer.register(registrationData);
-
List<PortletContext> portletContexts = createPortletContextList(getDefaultHandle());
boolean exportByValueRequired = true;
Lifetime lifetime = null;
UserContext userContext = null;
-
ExportPortlets exportPortlets = WSRPTypeFactory.createExportPortlets(registrationContext, portletContexts, userContext, lifetime, exportByValueRequired);
ExportPortletsResponse response = producer.exportPortlets(exportPortlets);
- assertNotNull(response.getExportContext());
- assertNull(response.getLifetime());
- assertTrue(response.getFailedPortlets().isEmpty());
-
- assertEquals(1, response.getExportedPortlet().size());
-
- ExportedPortlet exportPortlet = response.getExportedPortlet().get(0);
-
- assertEquals(getDefaultHandle(), exportPortlet.getPortletHandle());
+ checkValidHandle(response, getDefaultHandle());
}
+
+ @Test
+ public void testExportNullExportContext() throws Exception
+ {
+ ExportPortlets exportPortlets = new ExportPortlets();
+ try
+ {
+ ExportPortletsResponse response = producer.exportPortlets(exportPortlets);
+ ExtendedAssert.fail("Should have thrown a MissingParameters fault if no portlets passed for export.");
+ }
+ catch (MissingParameters e)
+ {
+ //expected
+ }
+ }
@Test
+ public void testExportNullExportPortlets() throws Exception
+ {
+ try
+ {
+ ExportPortletsResponse response = producer.exportPortlets(null);
+ ExtendedAssert.fail("Should have failed if sending a null exportPortlet object");
+ }
+ catch (MissingParameters e)
+ {
+ //expected
+ }
+ }
+
+ @Test
public void testExports() throws Exception
{
String nullHandle = null;
@@ -345,6 +295,27 @@
assertTrue(failedPortlets.getPortletHandles().contains(nonExistantHandle));
}
+ protected void checkInvalidHandle(ExportPortletsResponse response, String handle) throws Exception
+ {
+ assertNotNull(response.getExportContext());
+ assertNull(response.getLifetime());
+ assertTrue(response.getExportedPortlet().isEmpty());
+ assertEquals(1, response.getFailedPortlets().size());
+ FailedPortlets failedPortlet = response.getFailedPortlets().get(0);
+ assertTrue(failedPortlet.getPortletHandles().contains(handle));
+ assertEquals("InvalidHandle",failedPortlet.getErrorCode().getLocalPart());
+ }
+
+ protected void checkValidHandle(ExportPortletsResponse response, String handle) throws Exception
+ {
+ assertNotNull(response.getExportContext());
+ assertNull(response.getLifetime());
+ assertTrue(response.getFailedPortlets().isEmpty());
+ assertEquals(1, response.getExportedPortlet().size());
+ ExportedPortlet exportPortlet = response.getExportedPortlet().get(0);
+ assertEquals(handle, exportPortlet.getPortletHandle());
+ }
+
protected List<PortletContext> createPortletContextList(String... portletHandles)
{
List<PortletContext> portletContexts = new ArrayList<PortletContext>();
@@ -509,7 +480,7 @@
try
{
- ImportPortletsResponse response = producer.importPortlets(importPortlets);
+ producer.importPortlets(importPortlets);
ExtendedAssert.fail("Should have thrown an OperationFailedFault");
}
catch (OperationFailed e)
@@ -532,7 +503,7 @@
try
{
- ImportPortletsResponse response = producer.importPortlets(importPortlets);
+ producer.importPortlets(importPortlets);
ExtendedAssert.fail("Should have thrown an OperationFailedFault");
}
catch (OperationFailed e)
@@ -823,6 +794,158 @@
}
}
+ @Test
+ public void testReleaseExportsThrowsNoErrors() throws Exception
+ {
+ //NOTE: this test should never cause any errors
+ //TODO: once the export by reference is done, we need to write tests that this works
+
+ //null releaseExport
+ producer.releaseExport(null);
+
+ //empty releaseExport
+ ReleaseExport releaseExport = new ReleaseExport();
+ producer.releaseExport(releaseExport);
+
+ //empty releaseExport with a bad export context
+ releaseExport = new ReleaseExport();
+ releaseExport.setExportContext(new byte[]{-12, 12, 25, 21, 53});
+ producer.releaseExport(releaseExport);
+
+ //bad registration handle
+ releaseExport = new ReleaseExport();
+ RegistrationContext registrationContext = new RegistrationContext();
+ registrationContext.setRegistrationHandle("badRegistrationHandle");
+ releaseExport.setRegistrationContext(registrationContext);
+ producer.releaseExport(releaseExport);
+
+ //bad user context
+ releaseExport = new ReleaseExport();
+ UserContext userContext = new UserContext();
+ userContext.setUserContextKey("baduckey");
+ releaseExport.setUserContext(userContext);
+ producer.releaseExport(releaseExport);
+ }
+
+ @Test
+ public void testReleaseExportsNoErrorsRequiresRegistraion() throws Exception
+ {
+ producer.getConfigurationService().getConfiguration().getRegistrationRequirements().setRegistrationRequired(true);
+ this.testReleaseExportsThrowsNoErrors();
+ }
+
+ @Test
+ public void testExportPortletPM() throws Exception
+ {
+ exportPortletToPM();
+ }
+
+ @Test
+ public void testReleaseExportPM() throws Exception
+ {
+ ExportPortletsResponse response = exportPortletToPM();
+
+ ReleaseExport releaseExport = WSRPTypeFactory.createReleaseExport(null, response.getExportContext(), null);
+ producer.releaseExport(releaseExport);
+
+ //Test that doing a release export actually removed the stored RefId
+ TestMockExportPersistenceManager persistenceManager = (TestMockExportPersistenceManager)producer.getExportManager().getPersistenceManager();
+ ExtendedAssert.assertEquals(0, persistenceManager.getExportContexts().keySet().size());
+ }
+
+ @Test
+ public void testImportPortletPM() throws Exception
+ {
+ ExportPortletsResponse response = exportPortletToPM();
+
+ String importID = "foo";
+ ImportPortlet importPortlet = WSRPTypeFactory.createImportPortlet(importID, response.getExportedPortlet().get(0).getExportData());
+
+ List<ImportPortlet> importPortletsList = createImportPortletList(importPortlet);
+
+ ImportPortlets importPortlets = createSimpleImportPortlets(response.getExportContext(), importPortletsList);
+ ImportPortletsResponse importResponse = producer.importPortlets(importPortlets);
+
+ ExtendedAssert.assertEquals(1, importResponse.getImportedPortlets().size());
+ ExtendedAssert.assertEquals(importID, importResponse.getImportedPortlets().get(0).getImportID());
+ ExtendedAssert.assertNotNull(importResponse.getImportedPortlets().get(0).getNewPortletContext().getPortletHandle());
+ }
+
+ protected ExportPortletsResponse exportPortletToPM() throws Exception
+ {
+ TestMockExportPersistenceManager persistenceManager = new TestMockExportPersistenceManager();
+ producer.getExportManager().setPersistanceManager(persistenceManager);
+ ((ExportManagerImpl)producer.getExportManager()).setPreferExportByValue(false);
+
+ String handle = getDefaultHandle();
+ List<PortletContext> portletContexts = createPortletContextList(handle);
+
+ ExportPortlets exportPortlets = createSimpleExportPortlets(portletContexts);
+ exportPortlets.setExportByValueRequired(false);
+
+ //Test that we don't have anything in the PM before doing an export
+ ExtendedAssert.assertEquals(0, persistenceManager.getExportContexts().keySet().size());
+
+ ExportPortletsResponse response = producer.exportPortlets(exportPortlets);
+
+ //Test that we have an entry in the PM after doing an export
+ ExtendedAssert.assertEquals(1, persistenceManager.getExportContexts().keySet().size());
+
+ return response;
+ }
+
+ @Test
+ public void testSetExportLifetimeNull() throws Exception
+ {
+ try
+ {
+ producer.setExportLifetime(null);
+ ExtendedAssert.fail();
+ }
+ catch (OperationNotSupported e)
+ {
+ //expected
+ }
+ }
+
+ @Test
+ public void testSetExportLifetimeInvalidExportContext() throws Exception
+ {
+ try
+ {
+ SetExportLifetime setExportLifetime = WSRPTypeFactory.createSetExportLifetime(null, new byte[]{-10, 24, 24, 54, 'a', 'f', 'g'}, null, null);
+ producer.setExportLifetime(setExportLifetime);
+ ExtendedAssert.fail();
+ }
+ catch (OperationNotSupported e)
+ {
+ //expected
+ }
+ }
+
+ @Test
+ public void testSetExport() throws Exception
+ {
+ String handle = getDefaultHandle();
+ List<PortletContext> portletContexts = createPortletContextList(handle);
+
+ ExportPortlets exportPortlets = createSimpleExportPortlets(portletContexts);
+ ExportPortletsResponse response = producer.exportPortlets(exportPortlets);
+
+ try
+ {
+ PersistedExportData exportData = new PersistedExportData("foo", "bar");
+
+ SetExportLifetime setExportLifetime = WSRPTypeFactory.createSetExportLifetime(null,exportData.encodeAsBytes(), null, null);
+ producer.setExportLifetime(setExportLifetime);
+ ExtendedAssert.fail();
+ }
+ catch (OperationNotSupported e)
+ {
+ //expected
+ }
+ }
+
protected List<PortletContext> getPortletContext(ExportPortletsResponse exportPortletsResponse) throws Exception
{
List<PortletContext> portletContexts = new ArrayList<PortletContext>();
14 years, 5 months
gatein SVN: r3835 - in components/wsrp/trunk/consumer/src: main/java/org/gatein/wsrp/consumer and 6 other directories.
by do-not-reply@jboss.org
Author: chris.laprun(a)jboss.com
Date: 2010-08-16 13:09:43 -0400 (Mon, 16 Aug 2010)
New Revision: 3835
Added:
components/wsrp/trunk/consumer/src/main/java/org/gatein/wsrp/consumer/handlers/InvocationHandler.java
components/wsrp/trunk/consumer/src/main/java/org/gatein/wsrp/consumer/handlers/ProducerSessionInformation.java
components/wsrp/trunk/consumer/src/main/java/org/gatein/wsrp/consumer/handlers/SessionHandler.java
Removed:
components/wsrp/trunk/consumer/src/main/java/org/gatein/wsrp/consumer/InvocationHandler.java
components/wsrp/trunk/consumer/src/main/java/org/gatein/wsrp/consumer/ProducerSessionInformation.java
components/wsrp/trunk/consumer/src/main/java/org/gatein/wsrp/consumer/SessionHandler.java
Modified:
components/wsrp/trunk/consumer/src/main/java/org/gatein/wsrp/WSRPConsumer.java
components/wsrp/trunk/consumer/src/main/java/org/gatein/wsrp/consumer/WSRPConsumerImpl.java
components/wsrp/trunk/consumer/src/main/java/org/gatein/wsrp/consumer/handlers/EventHandler.java
components/wsrp/trunk/consumer/src/main/java/org/gatein/wsrp/consumer/handlers/InvocationDispatcher.java
components/wsrp/trunk/consumer/src/main/java/org/gatein/wsrp/consumer/handlers/MimeResponseHandler.java
components/wsrp/trunk/consumer/src/main/java/org/gatein/wsrp/consumer/handlers/NavigationalStateUpdatingHandler.java
components/wsrp/trunk/consumer/src/main/java/org/gatein/wsrp/handler/RequestHeaderClientHandler.java
components/wsrp/trunk/consumer/src/test/java/org/gatein/wsrp/consumer/ProducerSessionInformationTestCase.java
components/wsrp/trunk/consumer/src/test/java/org/gatein/wsrp/handler/RequestHeaderClientHandlerTestCase.java
components/wsrp/trunk/consumer/src/test/java/org/gatein/wsrp/protocol/v1/MarkupTestCase.java
components/wsrp/trunk/consumer/src/test/java/org/gatein/wsrp/test/support/MockWSRPConsumer.java
Log:
- GTNWSRP-57: Moved InvocationHandler, SessionHandler and ProducerSessionInformation to handlers package.
Modified: components/wsrp/trunk/consumer/src/main/java/org/gatein/wsrp/WSRPConsumer.java
===================================================================
--- components/wsrp/trunk/consumer/src/main/java/org/gatein/wsrp/WSRPConsumer.java 2010-08-16 10:06:08 UTC (rev 3834)
+++ components/wsrp/trunk/consumer/src/main/java/org/gatein/wsrp/WSRPConsumer.java 2010-08-16 17:09:43 UTC (rev 3835)
@@ -1,6 +1,6 @@
/*
* JBoss, a division of Red Hat
- * Copyright 2009, Red Hat Middleware, LLC, and individual
+ * Copyright 2010, Red Hat Middleware, LLC, and individual
* contributors as indicated by the @authors tag. See the
* copyright.txt in the distribution for a full listing of
* individual contributors.
@@ -28,8 +28,8 @@
import org.gatein.pc.api.invocation.PortletInvocation;
import org.gatein.wsrp.api.SessionEventListener;
import org.gatein.wsrp.consumer.ProducerInfo;
-import org.gatein.wsrp.consumer.ProducerSessionInformation;
import org.gatein.wsrp.consumer.RefreshResult;
+import org.gatein.wsrp.consumer.handlers.ProducerSessionInformation;
import javax.servlet.http.HttpSession;
@@ -53,7 +53,7 @@
*
* @param invocation a portlet invocation from which the session information should be extracted.
* @return the session information for the producer associated with this consumer.
- * @see ProducerSessionInformation
+ * @see org.gatein.wsrp.consumer.handlers.ProducerSessionInformation
*/
ProducerSessionInformation getProducerSessionInformationFrom(PortletInvocation invocation);
@@ -62,7 +62,7 @@
*
* @param session the session from the information should be extracted.
* @return the session information for the producer associated with this consumer.
- * @see ProducerSessionInformation
+ * @see org.gatein.wsrp.consumer.handlers.ProducerSessionInformation
*/
ProducerSessionInformation getProducerSessionInformationFrom(HttpSession session);
Deleted: components/wsrp/trunk/consumer/src/main/java/org/gatein/wsrp/consumer/InvocationHandler.java
===================================================================
--- components/wsrp/trunk/consumer/src/main/java/org/gatein/wsrp/consumer/InvocationHandler.java 2010-08-16 10:06:08 UTC (rev 3834)
+++ components/wsrp/trunk/consumer/src/main/java/org/gatein/wsrp/consumer/InvocationHandler.java 2010-08-16 17:09:43 UTC (rev 3835)
@@ -1,415 +0,0 @@
-/*
- * JBoss, a division of Red Hat
- * Copyright 2010, Red Hat Middleware, LLC, and individual
- * contributors as indicated by the @authors tag. See the
- * copyright.txt in the distribution for a full listing of
- * individual contributors.
- *
- * This is free software; you can redistribute it and/or modify it
- * under the terms of the GNU Lesser General Public License as
- * published by the Free Software Foundation; either version 2.1 of
- * the License, or (at your option) any later version.
- *
- * This software is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this software; if not, write to the Free
- * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
- * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
- */
-
-package org.gatein.wsrp.consumer;
-
-import org.gatein.common.util.ContentInfo;
-import org.gatein.common.util.ParameterValidation;
-import org.gatein.pc.api.PortletInvokerException;
-import org.gatein.pc.api.StateString;
-import org.gatein.pc.api.invocation.PortletInvocation;
-import org.gatein.pc.api.invocation.response.ErrorResponse;
-import org.gatein.pc.api.invocation.response.PortletInvocationResponse;
-import org.gatein.pc.api.spi.InstanceContext;
-import org.gatein.pc.api.spi.PortletInvocationContext;
-import org.gatein.pc.api.spi.SecurityContext;
-import org.gatein.pc.api.spi.WindowContext;
-import org.gatein.pc.portlet.impl.jsr168.PortletUtils;
-import org.gatein.wsrp.WSRPConstants;
-import org.gatein.wsrp.WSRPTypeFactory;
-import org.gatein.wsrp.WSRPUtils;
-import org.oasis.wsrp.v2.InvalidCookie;
-import org.oasis.wsrp.v2.InvalidRegistration;
-import org.oasis.wsrp.v2.InvalidSession;
-import org.oasis.wsrp.v2.MarkupParams;
-import org.oasis.wsrp.v2.NavigationalContext;
-import org.oasis.wsrp.v2.OperationFailed;
-import org.oasis.wsrp.v2.PortletContext;
-import org.oasis.wsrp.v2.RuntimeContext;
-import org.oasis.wsrp.v2.UserContext;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
-import java.rmi.RemoteException;
-import java.util.Collections;
-import java.util.Map;
-
-/**
- * @author <a href="mailto:chris.laprun@jboss.com">Chris Laprun</a>
- * @version $Revision: 13121 $
- * @since 2.4 (May 31, 2006)
- */
-public abstract class InvocationHandler<Invocation extends PortletInvocation, Request, Response>
-{
- protected final WSRPConsumerImpl consumer;
-
- protected static Logger log = LoggerFactory.getLogger(InvocationHandler.class);
- protected static boolean debug = log.isDebugEnabled();
- protected static boolean trace = log.isTraceEnabled();
-
- /**
- * Value indicating that we should not try further (unrecoverable error) for getMarkup and
- * processBlockingInteraction
- */
- private static final int DO_NOT_RETRY = -1;
-
- /** Maximum number of tries before giving up. */
- private static final int MAXIMUM_RETRY_NUMBER = 3;
-
- protected InvocationHandler(WSRPConsumerImpl consumer)
- {
- this.consumer = consumer;
- }
-
- public PortletInvocationResponse handle(Invocation invocation) throws PortletInvokerException
- {
- // Extracts basic required information from invocation
- RequestPrecursor<Invocation> requestPrecursor = new RequestPrecursor<Invocation>(consumer, invocation);
-
- // create the specific request
- Request request = prepareRequest(requestPrecursor, invocation);
-
- // Perform the request
- try
- {
- Response response = performRequest(request, invocation);
- return processResponse(response, invocation, requestPrecursor);
- }
- catch (Exception e)
- {
- if (!(e instanceof PortletInvokerException))
- {
- ErrorResponse errorResponse = dealWithError(e, invocation, getRuntimeContextFrom(request));
- if (errorResponse != null)
- {
- return unwrapWSRPError(errorResponse);
- }
- else
- {
- return new ErrorResponse(e);
- }
- }
- else
- {
- throw (PortletInvokerException)e;
- }
- }
- /*if (response instanceof ErrorResponse)
- {
- return unwrapWSRPError((ErrorResponse)response);
- }*/
- }
-
- protected Response performRequest(Request request, PortletInvocation invocation) throws Exception
- {
- int retryCount = 0;
- Response response = null;
-
- // as long as we don't get a non-null response and we're allowed to try again, try to perform the request
- while (response == null && retryCount++ <= MAXIMUM_RETRY_NUMBER)
- {
- if (debug)
- {
- log.debug("performRequest: " + retryCount + " attempt(s) out of " + MAXIMUM_RETRY_NUMBER + " possible");
- }
- SessionHandler sessionHandler = consumer.getSessionHandler();
-
- // prepare everything for the request
- updateRegistrationContext(request);
- RuntimeContext runtimeContext = getRuntimeContextFrom(request);
-
- if (runtimeContext != null)
- {
- WindowContext windowContext = invocation.getWindowContext();
- runtimeContext.setNamespacePrefix(getNamespaceFrom(windowContext));
-
- InstanceContext instanceContext = invocation.getInstanceContext();
- runtimeContext.setPortletInstanceKey(instanceContext == null ? null : instanceContext.getId());
-
- updateUserContext(request, consumer.getUserContextFrom(invocation, runtimeContext));
- consumer.setTemplatesIfNeeded(invocation, runtimeContext);
- }
-
- try
- {
- sessionHandler.initCookieIfNeeded(invocation);
-
- // if we need cookies, set the current group id
- sessionHandler.initProducerSessionInformation(invocation);
-
- response = performRequest(request);
-
- sessionHandler.updateCookiesIfNeeded(invocation);
- }
- /*catch (Exception e)
- {
- ErrorResponse errorResponse = dealWithError(e, invocation, runtimeContext);
- if (errorResponse != null)
- {
- return errorResponse;
- }
- }*/
- finally
- {
- // we're done: reset currently held information
- sessionHandler.resetCurrentlyHeldInformation();
- }
- }
-
- if (retryCount >= MAXIMUM_RETRY_NUMBER)
- {
- /*return new ErrorResponse(new RuntimeException("Tried to perform request " + MAXIMUM_RETRY_NUMBER
- + " times before giving up. This usually happens if an error in the WS stack prevented the messages to be " +
- "properly transmitted. Look at server.log for clues as to what happened..."));*/
- throw new RuntimeException("Tried to perform request " + MAXIMUM_RETRY_NUMBER
- + " times before giving up. This usually happens if an error in the WS stack prevented the messages to be " +
- "properly transmitted. Look at server.log for clues as to what happened...");
- }
-
- if (debug)
- {
- log.debug("performRequest finished. Response is " + (response != null ? response.getClass().getName() : null));
- }
- return response;
- }
-
- protected static String getNamespaceFrom(WindowContext windowContext)
- {
- if (windowContext != null)
- {
- // MUST match namespace generation used in PortletResponseImpl.getNamespace in portlet module...
- return PortletUtils.generateNamespaceFrom(windowContext.getId());
- }
-
- return null;
- }
-
- /**
- * Deals with common error conditions.
- *
- * @param error the error that is to be dealt with
- * @param invocation the invocation that caused the error to occur
- * @param runtimeContext the current WSRP RuntimeContext
- * @return an ErrorResponse if the error couldn't be dealt with or <code>null</code> if the error was correctly
- * handled
- */
- private ErrorResponse dealWithError(Exception error, Invocation invocation, RuntimeContext runtimeContext)
- throws PortletInvokerException
- {
- log.error("The portlet threw an exception", error);
-
- SessionHandler sessionHandler = consumer.getSessionHandler();
-
- // recoverable errors
- if (error instanceof InvalidCookie)
- {
- // we need to re-init the cookies
- log.debug("Re-initializing cookies after InvalidCookieFault.");
- // force a producer info refresh because the invalid cookie might be due to a change of cookie policy on the producer
- consumer.refreshProducerInfo();
- try
- {
- sessionHandler.initCookieIfNeeded(invocation);
- }
- catch (Exception e)
- {
- log.debug("Couldn't init cookie: " + e.getLocalizedMessage());
- return new ErrorResponse(e);
- }
- }
- else if (error instanceof InvalidSession)
- {
- log.debug("Session invalidated after InvalidSessionFault, will re-send session-stored information.");
- sessionHandler.handleInvalidSessionFault(invocation, runtimeContext);
- }
- else if (error instanceof InvalidRegistration)
- {
- log.debug("Invalid registration");
- consumer.handleInvalidRegistrationFault();
- }
- else
- {
- // other errors cannot be dealt with: we have an error condition
- return new ErrorResponse(error);
- }
- return null;
- }
-
- protected ErrorResponse unwrapWSRPError(ErrorResponse errorResponse)
- {
- Throwable cause = errorResponse.getCause();
- if (cause != null)
- {
- // unwrap original exception...
- if (cause instanceof OperationFailed && cause.getCause() != null)
- {
- cause = cause.getCause();
- }
- else if (cause instanceof RemoteException)
- {
- cause = ((RemoteException)cause).detail;
- }
- log.debug("Invocation of action failed: " + cause.getMessage(), cause); // fix-me?
- return new ErrorResponse(cause);
- }
- else
- {
- log.debug("Invocation of action failed: " + errorResponse.getMessage());
- return errorResponse;
- }
- }
-
- protected abstract void updateUserContext(Request request, UserContext userContext);
-
- protected abstract void updateRegistrationContext(Request request) throws PortletInvokerException;
-
- protected abstract RuntimeContext getRuntimeContextFrom(Request request);
-
- protected abstract Response performRequest(Request request) throws Exception;
-
- protected abstract Request prepareRequest(RequestPrecursor<Invocation> requestPrecursor, Invocation invocation);
-
- protected abstract PortletInvocationResponse processResponse(Response response, Invocation invocation, RequestPrecursor<Invocation> requestPrecursor) throws PortletInvokerException;
-
- /**
- * Extracts basic required elements for all invocation requests.
- *
- * @author <a href="mailto:chris.laprun@jboss.com">Chris Laprun</a>
- * @version $Revision: 13121 $
- * @since 2.4
- */
- protected static class RequestPrecursor<Invocation extends PortletInvocation>
- {
- private final static Logger log = LoggerFactory.getLogger(RequestPrecursor.class);
-
- private PortletContext portletContext;
- private RuntimeContext runtimeContext;
- private MarkupParams markupParams;
- private static final String PORTLET_HANDLE = "portlet handle";
- private static final String SECURITY_CONTEXT = "security context";
- private static final String USER_CONTEXT = "user context";
- private static final String INVOCATION_CONTEXT = "invocation context";
- private static final String STREAM_INFO = "stream info in invocation context";
- private static final String USER_AGENT = "User-Agent";
-
- public RequestPrecursor(WSRPConsumerImpl wsrpConsumer, Invocation invocation) throws PortletInvokerException
- {
- // retrieve handle
- portletContext = WSRPUtils.convertToWSRPPortletContext(WSRPConsumerImpl.getPortletContext(invocation));
- ParameterValidation.throwIllegalArgExceptionIfNullOrEmpty(getPortletHandle(), PORTLET_HANDLE, null);
- if (log.isDebugEnabled())
- {
- log.debug("About to invoke on portlet: " + getPortletHandle());
- }
-
- // create runtime context
- SecurityContext securityContext = invocation.getSecurityContext();
- ParameterValidation.throwIllegalArgExceptionIfNull(securityContext, SECURITY_CONTEXT);
- String authType = WSRPUtils.convertRequestAuthTypeToWSRPAuthType(securityContext.getAuthType());
- setRuntimeContext(WSRPTypeFactory.createRuntimeContext(authType));
-
- // set the session id if needed
- wsrpConsumer.getSessionHandler().setSessionIdIfNeeded(invocation, getRuntimeContext(), getPortletHandle());
-
- wsrpConsumer.setTemplatesIfNeeded(invocation, getRuntimeContext());
-
- // create markup params
- org.gatein.pc.api.spi.UserContext userContext = invocation.getUserContext();
- ParameterValidation.throwIllegalArgExceptionIfNull(userContext, USER_CONTEXT);
- PortletInvocationContext context = invocation.getContext();
- ParameterValidation.throwIllegalArgExceptionIfNull(context, INVOCATION_CONTEXT);
- ContentInfo streamInfo = context.getMarkupInfo();
- ParameterValidation.throwIllegalArgExceptionIfNull(streamInfo, STREAM_INFO);
-
- String mode;
- try
- {
- mode = WSRPUtils.getWSRPNameFromJSR168PortletMode(invocation.getMode());
- }
- catch (Exception e)
- {
- log.debug("Mode was null in context.");
- mode = WSRPConstants.VIEW_MODE;
- }
-
- String windowState;
- try
- {
- windowState = WSRPUtils.getWSRPNameFromJSR168WindowState(invocation.getWindowState());
- }
- catch (Exception e)
- {
- log.debug("WindowState was null in context.");
- windowState = WSRPConstants.NORMAL_WINDOW_STATE;
- }
-
- setMarkupParams(WSRPTypeFactory.createMarkupParams(securityContext.isSecure(),
- WSRPUtils.convertLocalesToRFC3066LanguageTags(userContext.getLocales()),
- Collections.singletonList(streamInfo.getMediaType().getValue()), mode, windowState));
- String userAgent = WSRPConsumerImpl.getHttpRequest(invocation).getHeader(USER_AGENT);
- getMarkupParams().setClientData(WSRPTypeFactory.createClientData(userAgent));
-
- // navigational state
- StateString navigationalState = invocation.getNavigationalState();
- Map<String, String[]> publicNavigationalState = invocation.getPublicNavigationalState();
- NavigationalContext navigationalContext = WSRPTypeFactory.createNavigationalContextOrNull(navigationalState, publicNavigationalState);
- getMarkupParams().setNavigationalContext(navigationalContext);
-
- if (log.isDebugEnabled())
- {
- log.debug(WSRPUtils.toString(getMarkupParams()));
- }
- }
-
- public String getPortletHandle()
- {
- return portletContext.getPortletHandle();
- }
-
-
- public PortletContext getPortletContext()
- {
- return portletContext;
- }
-
- public RuntimeContext getRuntimeContext()
- {
- return runtimeContext;
- }
-
- private void setRuntimeContext(RuntimeContext runtimeContext)
- {
- this.runtimeContext = runtimeContext;
- }
-
- public MarkupParams getMarkupParams()
- {
- return markupParams;
- }
-
- private void setMarkupParams(MarkupParams markupParams)
- {
- this.markupParams = markupParams;
- }
- }
-}
Deleted: components/wsrp/trunk/consumer/src/main/java/org/gatein/wsrp/consumer/ProducerSessionInformation.java
===================================================================
--- components/wsrp/trunk/consumer/src/main/java/org/gatein/wsrp/consumer/ProducerSessionInformation.java 2010-08-16 10:06:08 UTC (rev 3834)
+++ components/wsrp/trunk/consumer/src/main/java/org/gatein/wsrp/consumer/ProducerSessionInformation.java 2010-08-16 17:09:43 UTC (rev 3835)
@@ -1,531 +0,0 @@
-/*
- * JBoss, a division of Red Hat
- * Copyright 2010, Red Hat Middleware, LLC, and individual
- * contributors as indicated by the @authors tag. See the
- * copyright.txt in the distribution for a full listing of
- * individual contributors.
- *
- * This is free software; you can redistribute it and/or modify it
- * under the terms of the GNU Lesser General Public License as
- * published by the Free Software Foundation; either version 2.1 of
- * the License, or (at your option) any later version.
- *
- * This software is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this software; if not, write to the Free
- * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
- * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
- */
-
-package org.gatein.wsrp.consumer;
-
-import org.apache.commons.httpclient.Cookie;
-import org.gatein.common.util.ParameterValidation;
-import org.gatein.common.util.Tools;
-import org.gatein.wsrp.WSRPConstants;
-import org.oasis.wsrp.v2.SessionContext;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
-import java.io.Serializable;
-import java.util.ArrayList;
-import java.util.Collection;
-import java.util.HashMap;
-import java.util.List;
-import java.util.Map;
-
-/**
- * Records session and cookie information for a producer.
- *
- * @author <a href="mailto:chris.laprun@jboss.com">Chris Laprun</a>
- * @version $Revision: 12736 $
- * @since 2.4 (May 30, 2006)
- */
-public class ProducerSessionInformation implements Serializable
-{
- private static Logger log = LoggerFactory.getLogger(ProducerSessionInformation.class);
-
- private boolean initCookieDone = false;
- private boolean perGroupCookies = false;
-
- /** group id -> Cookie[] */
- private Map<String, Cookie[]> groupCookies;
-
- /** portlet handle -> SessionInfo */
- private Map<String, SessionInfo> portletSessions;
-
- /** session id -> portlet handle */
- private Map<String, String> sessionId2PortletHandle;
-
- /** Cookies sent by the remote producer */
- private Cookie[] userCookie;
-
- /** Parent SessionHandler so that session mappings can be updated */
- private transient SessionHandler parent;
-
- /** The identifier of the Session containing this ProducerSessionInformation */
- private String parentSessionId;
-
- /**
- * public only for tests
- *
- * @return
- * @since 2.6
- */
- public String getParentSessionId()
- {
- return parentSessionId;
- }
-
- /**
- * public only for tests
- *
- * @param parentSessionId
- * @throws IllegalStateException if an attempt is made to set the parent session id to a different one when it has
- * already been set.
- * @since 2.6
- */
- public void setParentSessionId(String parentSessionId)
- {
- if (this.parentSessionId != null && !this.parentSessionId.equals(parentSessionId))
- {
- throw new IllegalStateException("Cannot modify Parent Session id once it has been set!");
- }
-
- this.parentSessionId = parentSessionId;
- }
-
- public String getUserCookie()
- {
- if (userCookie == null)
- {
- return null;
- }
-
- userCookie = purgeExpiredCookies(userCookie);
- if (userCookie.length == 0)
- {
- setInitCookieDone(false);
- }
- return outputToExternalForm(userCookie);
- }
-
- public void setUserCookie(Cookie[] userCookie)
- {
- ParameterValidation.throwIllegalArgExceptionIfNullOrEmpty(userCookie, "cookies");
-
- this.userCookie = userCookie;
- }
-
- public boolean isInitCookieDone()
- {
- return initCookieDone;
- }
-
- public void setInitCookieDone(boolean initCookieDone)
- {
- this.initCookieDone = initCookieDone;
- }
-
- public boolean isPerGroupCookies()
- {
- return perGroupCookies;
- }
-
- public void setPerGroupCookies(boolean perGroupCookies)
- {
- this.perGroupCookies = perGroupCookies;
- }
-
- public void setGroupCookieFor(String groupId, Cookie[] cookies)
- {
- if (!isPerGroupCookies())
- {
- throw new IllegalStateException("Cannot add group cookie when cookie protocol is perUser.");
- }
-
- if (groupId == null)
- {
- throw new IllegalArgumentException("Cannot set cookie for a null portlet group id!");
- }
-
- ParameterValidation.throwIllegalArgExceptionIfNullOrEmpty(cookies, "cookies");
-
- if (groupCookies == null)
- {
- groupCookies = new HashMap<String, Cookie[]>();
- }
-
- if (groupCookies.containsKey(groupId))
- {
- log.debug("Trying to set a cookie for an existing group: " + groupId);
- }
-
- groupCookies.put(groupId, cookies);
- }
-
- public String getGroupCookieFor(String groupId)
- {
- if (groupCookies == null)
- {
- return null;
- }
-
- // purge expired cookies
- Cookie[] cookies = groupCookies.get(groupId);
- if (cookies != null)
- {
- cookies = purgeExpiredCookies(cookies);
-
- // if there are no non-expired cookies left, we will need to re-init them
- if (cookies.length == 0)
- {
- setInitCookieDone(false);
- }
-
- // update cookies for the considered group id
- groupCookies.put(groupId, cookies);
-
- return outputToExternalForm(cookies);
- }
- else
- {
- return null;
- }
- }
-
- public void clearGroupCookies()
- {
- groupCookies = null;
- }
-
- public void addSessionForPortlet(String portletHandle, SessionContext sessionContext)
- {
- // sessionContext is validated in SessionInfo constructor
- SessionInfo info = new SessionInfo(sessionContext, portletHandle);
-
- if (portletSessions == null)
- {
- portletSessions = new HashMap<String, SessionInfo>();
- sessionId2PortletHandle = new HashMap<String, String>();
- }
-
- portletSessions.put(portletHandle, info);
- sessionId2PortletHandle.put(sessionContext.getSessionID(), portletHandle);
-
- if (parent != null)
- {
- parent.addSessionMapping(sessionContext.getSessionID(), this);
- }
- }
-
- /**
- * Retrieves the session id for the portlet with the specified handle. Note that this will "touch" the session, hence
- * resetting the time since the last use of the session.
- *
- * @param portletHandle the handle of the portlet for which the session id is to be retrieved
- * @return the session id for the specified portlet, <code>null</code> if there is no session associated with the
- * portlet or if the session has expired.
- */
- public String getSessionIdForPortlet(String portletHandle)
- {
- ProducerSessionInformation.SessionIdResult idResult = internalGetSessionIdForPortlet(portletHandle);
- if (idResult.expired)
- {
- return null;
- }
-
- return idResult.id;
- }
-
- public int getNumberOfSessions()
- {
- if (portletSessions != null)
- {
- return portletSessions.size();
- }
- else
- {
- return 0;
- }
- }
-
- /**
- * @param sessionId
- * @return the id of the removed session or <code>null</code> if the session had already expired
- */
- public String removeSession(String sessionId)
- {
- ParameterValidation.throwIllegalArgExceptionIfNull(sessionId, "session id");
-
- String portletHandle = sessionId2PortletHandle.get(sessionId);
- if (portletHandle == null)
- {
- throw new IllegalArgumentException("No such session id: '" + sessionId + "'");
- }
-
- return removeSessionForPortlet(portletHandle);
- }
-
- /**
- * @return a list containing the session ids that were still valid when they were removed and would need to be
- * released
- */
- public List<String> removeSessions()
- {
- List<String> idsToRelease = new ArrayList<String>(getNumberOfSessions());
-
- // copy to avoid ConcurrentModificationException
- List<String> handlesCopy = new ArrayList<String>(portletSessions.keySet());
-
- for (String handle : handlesCopy)
- {
- SessionIdResult result = removeSessionIdForPortlet(handle);
-
- // only release sessions that are still valid
- if (!result.expired)
- {
- idsToRelease.add(result.id);
- }
- }
-
- return idsToRelease;
- }
-
- /**
- * @param portletHandle
- * @return the id of the removed session or <code>null</code> if the session had already expired
- */
- public String removeSessionForPortlet(String portletHandle)
- {
- SessionIdResult result = removeSessionIdForPortlet(portletHandle);
-
- return result.expired ? null : result.id;
- }
-
- private SessionIdResult removeSessionIdForPortlet(String portletHandle)
- {
- ProducerSessionInformation.SessionIdResult result = internalGetSessionIdForPortlet(portletHandle);
- final String id = result.id;
-
- if (id == null)
- {
- throw new IllegalArgumentException("There is no Session associated with portlet '" + portletHandle + "'");
- }
-
- // if the session is still valid, release it and remove the associated mappings
- if (!result.expired)
- {
- portletSessions.remove(portletHandle);
- sessionId2PortletHandle.remove(id);
- if (parent != null)
- {
- parent.removeSessionId(id);
- }
- }
-
- return result;
- }
-
- public void replaceUserCookiesWith(ProducerSessionInformation currentSessionInfo)
- {
- if (currentSessionInfo != null && currentSessionInfo.userCookie != null && currentSessionInfo.userCookie.length > 0)
- {
- this.userCookie = currentSessionInfo.userCookie;
- }
- }
-
- /**
- * Create a String representation of the specified array of Cookies.
- *
- * @param cookies the cookies to be output to external form
- * @return a String representation of the cookies, ready to be sent over the wire.
- */
- private String outputToExternalForm(Cookie[] cookies)
- {
- if (cookies != null && cookies.length != 0)
- {
- int cookieNumber = cookies.length;
- StringBuffer sb = new StringBuffer(128 * cookieNumber);
- for (int i = 0; i < cookieNumber; i++)
- {
- sb.append(cookies[i].toExternalForm());
- if (i != cookieNumber - 1)
- {
- sb.append(","); // multiple cookies are separated by commas: http://www.ietf.org/rfc/rfc2109.txt, 4.2.2
- }
- }
- return sb.toString();
- }
- return null;
- }
-
- /**
- * Purges the expired cookies in the specified array.
- *
- * @param cookies the cookies to be purged
- * @return an array of Cookies containing only still valid cookies
- */
- private Cookie[] purgeExpiredCookies(Cookie[] cookies)
- {
- ParameterValidation.throwIllegalArgExceptionIfNullOrEmpty(cookies, "cookies");
-
- List<Cookie> cleanCookies = Tools.toList(cookies);
-
- for (Cookie cookie : cookies)
- {
- if (cookie.isExpired())
- {
- cleanCookies.remove(cookie);
- }
- }
- return cleanCookies.toArray(new Cookie[cleanCookies.size()]);
- }
-
- private SessionIdResult internalGetSessionIdForPortlet(String portletHandle)
- {
- SessionInfo session = getSessionInfoFor(portletHandle);
- if (session != null)
- {
- String id = session.getSessionId();
- if (!session.isStillValid())
- {
- portletSessions.remove(session.getPortletHandle());
- sessionId2PortletHandle.remove(session.getSessionId());
- if (parent != null)
- {
- parent.removeSessionId(session.getSessionId());
- }
- return new SessionIdResult(id, true);
- }
- else
- {
- return new SessionIdResult(id, false);
- }
- }
- return new SessionIdResult(null, false);
- }
-
- private SessionInfo getSessionInfoFor(String portletHandle)
- {
- ParameterValidation.throwIllegalArgExceptionIfNullOrEmpty(portletHandle, "portlet handle", null);
-
- if (portletSessions == null)
- {
- return null;
- }
-
- return portletSessions.get(portletHandle);
- }
-
- /**
- * @return the known session id
- * @since 2.6
- */
- Collection<String> getSessionIds()
- {
- return sessionId2PortletHandle.keySet();
- }
-
- /**
- * @param sessionHandler
- * @since 2.6
- */
- void setParent(SessionHandler sessionHandler)
- {
- parent = sessionHandler;
- }
-
- /**
- * Update the mappings that were associated with the specified original portlet handle after it has been modified as
- * a result of a clone operation to the specified new handle.
- *
- * @param originalHandle
- * @param newHandle
- * @since 2.6
- */
- public void updateHandleAssociatedInfo(String originalHandle, String newHandle)
- {
- ParameterValidation.throwIllegalArgExceptionIfNullOrEmpty(originalHandle, "original handle",
- "Updating information associated with a portlet handle");
- ParameterValidation.throwIllegalArgExceptionIfNullOrEmpty(newHandle, "new handle",
- "Updating information associated with a portlet handle");
-
- String sessionId = getSessionIdForPortlet(originalHandle);
- ProducerSessionInformation.SessionInfo info = getSessionInfoFor(originalHandle);
- if (sessionId != null && info != null)
- {
- portletSessions.put(newHandle, info);
- portletSessions.remove(originalHandle);
- sessionId2PortletHandle.put(sessionId, newHandle);
- log.debug("Updated mapping information for '" + originalHandle + "' to reference '" + newHandle + "' instead.");
- }
- }
-
- private class SessionInfo implements Serializable
- {
- private SessionContext sessionContext;
- private long lastInvocationTime;
- private String portletHandle;
-
- public SessionInfo(SessionContext sessionContext, String portletHandle)
- {
- ParameterValidation.throwIllegalArgExceptionIfNull(sessionContext, "SessionContext");
- ParameterValidation.throwIllegalArgExceptionIfNullOrEmpty(sessionContext.getSessionID(), "session id", "SessionContext");
- ParameterValidation.throwIllegalArgExceptionIfNullOrEmpty(portletHandle, "portlet handle", "SessionInfo");
-
- this.sessionContext = sessionContext;
- this.portletHandle = portletHandle;
- lastInvocationTime = System.currentTimeMillis();
- }
-
- /**
- * Checks that the session associated with the session context hasn't expired and update the last invocation time
- *
- * @return
- */
- private boolean isStillValid()
- {
- int expires = sessionContext.getExpires();
- if (expires == WSRPConstants.SESSION_NEVER_EXPIRES)
- {
- return true;
- }
-
- long now = System.currentTimeMillis();
- long secondsSinceLastInvocation = (now - lastInvocationTime) / 1000;
- lastInvocationTime = now;
-
- long diff = expires - secondsSinceLastInvocation;
- log.debug("Session ID '" + sessionContext.getSessionID() + "' is " + ((diff > 0) ? "" : "not")
- + " valid (time since last invocation: " + diff + ")");
- return diff > 0;
- }
-
- private String getSessionId()
- {
- return sessionContext.getSessionID();
- }
-
- private String getPortletHandle()
- {
- return portletHandle;
- }
- }
-
- private class SessionIdResult
- {
- private String id;
- private boolean expired;
-
- public SessionIdResult(String id, boolean expired)
- {
- this.id = id;
- this.expired = expired;
- }
- }
-}
Deleted: components/wsrp/trunk/consumer/src/main/java/org/gatein/wsrp/consumer/SessionHandler.java
===================================================================
--- components/wsrp/trunk/consumer/src/main/java/org/gatein/wsrp/consumer/SessionHandler.java 2010-08-16 10:06:08 UTC (rev 3834)
+++ components/wsrp/trunk/consumer/src/main/java/org/gatein/wsrp/consumer/SessionHandler.java 2010-08-16 17:09:43 UTC (rev 3835)
@@ -1,447 +0,0 @@
-/*
- * JBoss, a division of Red Hat
- * Copyright 2010, Red Hat Middleware, LLC, and individual
- * contributors as indicated by the @authors tag. See the
- * copyright.txt in the distribution for a full listing of
- * individual contributors.
- *
- * This is free software; you can redistribute it and/or modify it
- * under the terms of the GNU Lesser General Public License as
- * published by the Free Software Foundation; either version 2.1 of
- * the License, or (at your option) any later version.
- *
- * This software is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this software; if not, write to the Free
- * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
- * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
- */
-
-package org.gatein.wsrp.consumer;
-
-import org.gatein.common.util.ParameterValidation;
-import org.gatein.pc.api.InvokerUnavailableException;
-import org.gatein.pc.api.Portlet;
-import org.gatein.pc.api.PortletInvokerException;
-import org.gatein.pc.api.invocation.PortletInvocation;
-import org.gatein.wsrp.api.SessionEvent;
-import org.gatein.wsrp.api.SessionEventListener;
-import org.gatein.wsrp.consumer.portlet.info.WSRPPortletInfo;
-import org.gatein.wsrp.handler.RequestHeaderClientHandler;
-import org.gatein.wsrp.servlet.UserAccess;
-import org.oasis.wsrp.v2.CookieProtocol;
-import org.oasis.wsrp.v2.InvalidRegistration;
-import org.oasis.wsrp.v2.RuntimeContext;
-import org.oasis.wsrp.v2.SessionContext;
-import org.oasis.wsrp.v2.SessionParams;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
-import javax.servlet.http.HttpSession;
-import java.util.ArrayList;
-import java.util.HashSet;
-import java.util.List;
-import java.util.Map;
-import java.util.Set;
-import java.util.concurrent.ConcurrentHashMap;
-
-/**
- * Manages session informations on behalf of a consumer.
- *
- * @author <a href="mailto:chris.laprun@jboss.com">Chris Laprun</a>
- * @version $Revision: 9360 $
- * @since 2.4 (May 31, 2006)
- */
-public class SessionHandler implements SessionEventListener
-{
- protected WSRPConsumerImpl consumer;
- private static Logger log = LoggerFactory.getLogger(SessionHandler.class);
-
- /** Cookie protocol required by the producer with the consumer */
- private CookieProtocol requiresInitCookie;
-
- /** The prefix used to isolate WSRP-related session information in the actual session object. */
- private static final String SESSION_ID_PREFIX = "org.gatein.wsrp.session.";
-
- /** session id -> ProducerSessionInformation */
- private Map<String, ProducerSessionInformation> sessionInfos = new ConcurrentHashMap<String, ProducerSessionInformation>(); // todo: thread-safe?
-
- /**
- * Constructs a new SessionHandler.
- *
- * @param consumer the consumer this SessionHandler is associated with.
- */
- public SessionHandler(WSRPConsumerImpl consumer)
- {
- this.consumer = consumer;
- }
-
- public boolean isPerUserCookieInit()
- {
- return CookieProtocol.PER_USER.equals(requiresInitCookie);
- }
-
- public boolean requiresInitCookie()
- {
- return requiresInitCookie != null && !CookieProtocol.NONE.equals(requiresInitCookie);
- }
-
- public void setRequiresInitCookie(CookieProtocol requiresInitCookie)
- {
- this.requiresInitCookie = requiresInitCookie;
- }
-
- void initProducerSessionInformation(PortletInvocation invocation) throws PortletInvokerException
- {
- // if we need cookies, set the current group id
- String groupId;
- if (requiresGroupInitCookie())
- {
- WSRPPortletInfo info = consumer.getPortletInfo(invocation);
- groupId = info.getGroupId();
- }
- else
- {
- groupId = null;
- }
-
- RequestHeaderClientHandler.setCurrentInfo(groupId, getProducerSessionInformation(invocation, true));
- }
-
- private boolean requiresGroupInitCookie()
- {
- return requiresInitCookie() && CookieProtocol.PER_GROUP.equals(requiresInitCookie);
- }
-
- /** Resets the information held by RequestHeaderClientHandler for the current interaction. */
- public void resetCurrentlyHeldInformation()
- {
- RequestHeaderClientHandler.resetCurrentInfo();
- }
-
- public void initCookieIfNeeded(PortletInvocation invocation) throws PortletInvokerException
- {
- initCookieIfNeeded(invocation, true);
- }
-
- private void initCookieIfNeeded(PortletInvocation invocation, boolean retryIfFails) throws PortletInvokerException
- {
- // check if the cookie protocol requires cookie initialization
- if (!requiresInitCookie())
- {
- return;
- }
-
- // check if we have already initialized cookies for this user
- ProducerSessionInformation sessionInformation = getProducerSessionInformation(invocation);
- if (sessionInformation.isInitCookieDone())
- {
- return;
- }
- RequestHeaderClientHandler.setCurrentInfo(null, sessionInformation);
-
- if (isPerUserCookieInit())
- {
- log.debug("Cookie initialization per user requested.");
- sessionInformation.setPerGroupCookies(false);
- initCookie(invocation, retryIfFails);
- }
- else
- {
- log.debug("Cookie initialization per group requested.");
- sessionInformation.setPerGroupCookies(true);
- Map<String, Set<Portlet>> groups = consumer.getPortletGroupMap();
-
- try
- {
- for (String groupId : groups.keySet())
- {
- RequestHeaderClientHandler.setCurrentGroupId(groupId);
- log.debug("Initializing cookie for group '" + groupId + "'.");
- initCookie(invocation, retryIfFails);
- }
- }
- finally
- {
- resetCurrentlyHeldInformation();
- }
- }
-
- sessionInformation.setInitCookieDone(true);
- }
-
- private void initCookie(PortletInvocation invocation, boolean retryIfFails) throws PortletInvokerException
- {
- try
- {
- consumer.getMarkupService().initCookie(consumer.getRegistrationContext(), UserAccess.getUserContext());
- }
- catch (InvalidRegistration invalidRegistration)
- {
- consumer.handleInvalidRegistrationFault();
- if (retryIfFails)
- {
- initCookieIfNeeded(invocation, false);
- }
- }
- catch (Exception e)
- {
- throw new InvokerUnavailableException("Couldn't init cookies!", e);
- }
- }
-
- void setSessionIdIfNeeded(PortletInvocation invocation, RuntimeContext runtimeContext, String portletHandle)
- {
- ProducerSessionInformation producerSessionInfo = getProducerSessionInformation(invocation, false);
- if (producerSessionInfo != null)
- {
- String sessionId = producerSessionInfo.getSessionIdForPortlet(portletHandle);
- SessionParams sessionParams = runtimeContext.getSessionParams();
- if (sessionParams == null)
- {
- sessionParams = new SessionParams();
- runtimeContext.setSessionParams(sessionParams);
- }
- sessionParams.setSessionID(sessionId);
- }
- }
-
- public void updateSessionIfNeeded(SessionContext sessionContext, PortletInvocation invocation, String portletHandle)
- {
- if (sessionContext != null)
- {
- log.debug("Portlet '" + portletHandle + "' created session with id '" + sessionContext.getSessionID() + "'");
- ProducerSessionInformation sessionInfo = getProducerSessionInformation(invocation);
- sessionInfo.addSessionForPortlet(portletHandle, sessionContext);
- }
- }
-
- void updateCookiesIfNeeded(PortletInvocation invocation)
- {
- ProducerSessionInformation sessionInfo = getProducerSessionInformation(invocation, true);
- ProducerSessionInformation currentSessionInfo = RequestHeaderClientHandler.getCurrentProducerSessionInformation();
- if (sessionInfo != currentSessionInfo)
- {
- sessionInfo.replaceUserCookiesWith(currentSessionInfo);
- }
- }
-
- ProducerSessionInformation getProducerSessionInformation(PortletInvocation invocation)
- {
- return getProducerSessionInformation(invocation, true);
- }
-
- private ProducerSessionInformation getProducerSessionInformation(PortletInvocation invocation, boolean create)
- {
- HttpSession session = WSRPConsumerImpl.getHttpSession(invocation);
- return getProducerSessionInformation(session, create);
- }
-
- ProducerSessionInformation getProducerSessionInformation(HttpSession session)
- {
- return getProducerSessionInformation(session, false);
- }
-
- private ProducerSessionInformation getProducerSessionInformation(HttpSession session, boolean create)
- {
- ParameterValidation.throwIllegalArgExceptionIfNull(session, "Session");
- String producerSessionKey = getProducerSessionInformationKey();
- ProducerSessionInformation sessionInformation = (ProducerSessionInformation)session.getAttribute(producerSessionKey);
-
- if (sessionInformation != null)
- {
- sessionInformation.setParent(this);
- sessionInformation.setParentSessionId(session.getId());
- }
- else
- {
- if (create)
- {
- sessionInformation = new ProducerSessionInformation();
- sessionInformation.setParentSessionId(session.getId());
- session.setAttribute(producerSessionKey, sessionInformation);
- sessionInformation.setParent(this);
- }
- }
-
- return sessionInformation;
- }
-
- private String getProducerSessionInformationKey()
- {
- return SESSION_ID_PREFIX + consumer.getProducerId();
- }
-
- void handleInvalidSessionFault(PortletInvocation invocation, RuntimeContext runtimeContext)
- {
- log.info("Resending information after InvalidSessionFault");
- // invalidate current session
- invalidateSession(invocation);
-
- // set the session id to null
- if (runtimeContext != null)
- {
- runtimeContext.setSessionParams(null);
- }
- }
-
- private void invalidateSession(PortletInvocation invocation)
- {
- HttpSession session = WSRPConsumerImpl.getHttpSession(invocation);
-
- // remove the associated info from the known producer session informations
-
- ProducerSessionInformation info = getProducerSessionInformation(session, false);
- if (info != null)
- {
- try
- {
- internalReleaseSessions(info.removeSessions());
- }
- catch (PortletInvokerException e)
- {
- // ignore since it's logged by internalReleaseSessions already
- }
- }
-
-
- session.removeAttribute(getProducerSessionInformationKey());
- RequestHeaderClientHandler.resetCurrentInfo();
- }
-
- /** @since 2.6 */
- void releaseSessions() throws PortletInvokerException
- {
- List<String> idsToRelease = new ArrayList<String>();
-
- Set<ProducerSessionInformation> uniqueInfos = new HashSet<ProducerSessionInformation>(sessionInfos.values());
-
- for (ProducerSessionInformation info : uniqueInfos)
- {
- idsToRelease.addAll(info.removeSessions());
- }
-
- internalReleaseSessions(idsToRelease);
- }
-
- /**
- * @param sessionIds
- * @throws PortletInvokerException
- * @since 2.6
- */
- void releaseSessions(String[] sessionIds) throws PortletInvokerException
- {
- if (sessionIds != null)
- {
- List<String> idsToRelease = new ArrayList<String>();
-
- for (String sessionId : sessionIds)
- {
- ProducerSessionInformation info = sessionInfos.get(sessionId);
- sessionId = info.removeSession(sessionId);
- if (sessionId != null)
- {
- idsToRelease.add(sessionId);
- }
- }
-
- internalReleaseSessions(idsToRelease);
- }
- }
-
- private void internalReleaseSessions(List<String> idsToRelease) throws PortletInvokerException
- {
- if (idsToRelease != null && !idsToRelease.isEmpty())
- {
- try
- {
- consumer.getMarkupService().releaseSessions(consumer.getRegistrationContext(), idsToRelease, UserAccess.getUserContext());
- }
- catch (InvalidRegistration invalidRegistration)
- {
- log.debug("Invalid Registration");
- consumer.handleInvalidRegistrationFault();
- }
- catch (Exception e)
- {
- String message = "Couldn't release sessions " + idsToRelease;
- log.debug(message, e);
- throw new PortletInvokerException(message, e);
- }
- }
- }
-
- // ProducerSessionInformation callbacks
-
- /**
- * Update session mappings when a session has expired
- *
- * @param id
- * @since 2.6
- */
- void removeSessionId(String id)
- {
- sessionInfos.remove(id);
- }
-
- /**
- * Update session mappings when a new session id is added to the specified ProducerSessionInformation
- *
- * @param sessionID
- * @param producerSessionInformation
- * @since 2.6
- */
- void addSessionMapping(String sessionID, ProducerSessionInformation producerSessionInformation)
- {
- sessionInfos.put(sessionID, producerSessionInformation);
- }
-
- // End ProducerSessionInformation callbacks
-
- // SessionEventListener implementation
-
- public void onSessionEvent(SessionEvent event)
- {
- if (SessionEvent.SessionEventType.SESSION_DESTROYED.equals(event.getType()))
- {
- String id = event.getSession().getId();
-
- // check if the session being destroyed is the one associated with this thread
- ProducerSessionInformation info = RequestHeaderClientHandler.getCurrentProducerSessionInformation();
- if (info != null)
- {
- if (id != null && id.equals(info.getParentSessionId()))
- {
- try
- {
- internalReleaseSessions(info.removeSessions());
- }
- catch (PortletInvokerException e)
- {
- // already logged...
- }
- log.debug("Released session '" + id + "' after session was destroyed by Portal.");
- }
- }
- }
- }
-
- /**
- * @param originalHandle
- * @param newHandle
- * @param invocation
- * @since 2.6
- */
- public void updateSessionInfoFor(String originalHandle, String newHandle, PortletInvocation invocation)
- {
- ProducerSessionInformation info = getProducerSessionInformation(invocation, false);
- if (info != null)
- {
- info.updateHandleAssociatedInfo(originalHandle, newHandle);
- }
- }
-}
Modified: components/wsrp/trunk/consumer/src/main/java/org/gatein/wsrp/consumer/WSRPConsumerImpl.java
===================================================================
--- components/wsrp/trunk/consumer/src/main/java/org/gatein/wsrp/consumer/WSRPConsumerImpl.java 2010-08-16 10:06:08 UTC (rev 3834)
+++ components/wsrp/trunk/consumer/src/main/java/org/gatein/wsrp/consumer/WSRPConsumerImpl.java 2010-08-16 17:09:43 UTC (rev 3835)
@@ -46,6 +46,8 @@
import org.gatein.wsrp.WSRPUtils;
import org.gatein.wsrp.api.SessionEvent;
import org.gatein.wsrp.consumer.handlers.InvocationDispatcher;
+import org.gatein.wsrp.consumer.handlers.ProducerSessionInformation;
+import org.gatein.wsrp.consumer.handlers.SessionHandler;
import org.gatein.wsrp.consumer.portlet.WSRPPortlet;
import org.gatein.wsrp.consumer.portlet.info.WSRPPortletInfo;
import org.gatein.wsrp.services.MarkupService;
@@ -392,19 +394,19 @@
}
public PortletContext exportPortlet(PortletStateType stateType, PortletContext originalPortletContext)
- throws PortletInvokerException
+ throws PortletInvokerException
{
throw new NotYetImplemented();
}
-
+
public PortletContext importPortlet(PortletStateType stateType, PortletContext originalPortletContext)
- throws PortletInvokerException
+ throws PortletInvokerException
{
throw new NotYetImplemented();
}
// Accessors ********************************************************************************************************
-
+
public String getProducerId()
{
return producerInfo.getId();
@@ -427,12 +429,12 @@
* @return
* @since 2.6
*/
- static PortletContext getPortletContext(PortletInvocation invocation)
+ public static PortletContext getPortletContext(PortletInvocation invocation)
{
return invocation.getTarget();
}
- WSRPPortletInfo getPortletInfo(PortletInvocation invocation) throws PortletInvokerException
+ public WSRPPortletInfo getPortletInfo(PortletInvocation invocation) throws PortletInvokerException
{
return (WSRPPortletInfo)getWSRPPortlet(getPortletContext(invocation)).getInfo();
}
@@ -460,7 +462,7 @@
// Registration *****************************************************************************************************
- void handleInvalidRegistrationFault() throws PortletInvokerException
+ public void handleInvalidRegistrationFault() throws PortletInvokerException
{
// reset registration data and try again
producerInfo.resetRegistration();
@@ -625,7 +627,7 @@
// fix-me!
- org.oasis.wsrp.v2.UserContext getUserContextFrom(PortletInvocation invocation, RuntimeContext runtimeContext) throws PortletInvokerException
+ public org.oasis.wsrp.v2.UserContext getUserContextFrom(PortletInvocation invocation, RuntimeContext runtimeContext) throws PortletInvokerException
{
// first decide if we need to pass the user context...
WSRPPortletInfo info = getPortletInfo(invocation);
@@ -651,7 +653,7 @@
return null;
}
- void setTemplatesIfNeeded(PortletInvocation invocation, RuntimeContext runtimeContext) throws PortletInvokerException
+ public void setTemplatesIfNeeded(PortletInvocation invocation, RuntimeContext runtimeContext) throws PortletInvokerException
{
// todo: could store templates in producer session info to avoid to re-generate them all the time?
WSRPPortletInfo info = getPortletInfo(invocation);
@@ -666,13 +668,13 @@
}
}
- static HttpServletRequest getHttpRequest(PortletInvocation invocation)
+ public static HttpServletRequest getHttpRequest(PortletInvocation invocation)
{
AbstractPortletInvocationContext invocationContext = (AbstractPortletInvocationContext)invocation.getContext();
return invocationContext.getClientRequest();
}
- static HttpSession getHttpSession(PortletInvocation invocation)
+ public static HttpSession getHttpSession(PortletInvocation invocation)
{
return getHttpRequest(invocation).getSession();
}
Modified: components/wsrp/trunk/consumer/src/main/java/org/gatein/wsrp/consumer/handlers/EventHandler.java
===================================================================
--- components/wsrp/trunk/consumer/src/main/java/org/gatein/wsrp/consumer/handlers/EventHandler.java 2010-08-16 10:06:08 UTC (rev 3834)
+++ components/wsrp/trunk/consumer/src/main/java/org/gatein/wsrp/consumer/handlers/EventHandler.java 2010-08-16 17:09:43 UTC (rev 3835)
@@ -32,7 +32,6 @@
import org.gatein.pc.api.state.AccessMode;
import org.gatein.wsrp.WSRPTypeFactory;
import org.gatein.wsrp.WSRPUtils;
-import org.gatein.wsrp.consumer.InvocationHandler;
import org.gatein.wsrp.consumer.WSRPConsumerImpl;
import org.oasis.wsrp.v2.Event;
import org.oasis.wsrp.v2.EventParams;
Modified: components/wsrp/trunk/consumer/src/main/java/org/gatein/wsrp/consumer/handlers/InvocationDispatcher.java
===================================================================
--- components/wsrp/trunk/consumer/src/main/java/org/gatein/wsrp/consumer/handlers/InvocationDispatcher.java 2010-08-16 10:06:08 UTC (rev 3834)
+++ components/wsrp/trunk/consumer/src/main/java/org/gatein/wsrp/consumer/handlers/InvocationDispatcher.java 2010-08-16 17:09:43 UTC (rev 3835)
@@ -42,7 +42,6 @@
import org.gatein.pc.api.invocation.response.ResponseProperties;
import org.gatein.wsrp.WSRPResourceURL;
import org.gatein.wsrp.WSRPRewritingConstants;
-import org.gatein.wsrp.consumer.InvocationHandler;
import org.gatein.wsrp.consumer.WSRPConsumerImpl;
import org.gatein.wsrp.handler.CookieUtil;
import org.gatein.wsrp.spec.v2.WSRP2RewritingConstants;
Copied: components/wsrp/trunk/consumer/src/main/java/org/gatein/wsrp/consumer/handlers/InvocationHandler.java (from rev 3834, components/wsrp/trunk/consumer/src/main/java/org/gatein/wsrp/consumer/InvocationHandler.java)
===================================================================
--- components/wsrp/trunk/consumer/src/main/java/org/gatein/wsrp/consumer/handlers/InvocationHandler.java (rev 0)
+++ components/wsrp/trunk/consumer/src/main/java/org/gatein/wsrp/consumer/handlers/InvocationHandler.java 2010-08-16 17:09:43 UTC (rev 3835)
@@ -0,0 +1,416 @@
+/*
+ * JBoss, a division of Red Hat
+ * Copyright 2010, Red Hat Middleware, LLC, and individual
+ * contributors as indicated by the @authors tag. See the
+ * copyright.txt in the distribution for a full listing of
+ * individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+
+package org.gatein.wsrp.consumer.handlers;
+
+import org.gatein.common.util.ContentInfo;
+import org.gatein.common.util.ParameterValidation;
+import org.gatein.pc.api.PortletInvokerException;
+import org.gatein.pc.api.StateString;
+import org.gatein.pc.api.invocation.PortletInvocation;
+import org.gatein.pc.api.invocation.response.ErrorResponse;
+import org.gatein.pc.api.invocation.response.PortletInvocationResponse;
+import org.gatein.pc.api.spi.InstanceContext;
+import org.gatein.pc.api.spi.PortletInvocationContext;
+import org.gatein.pc.api.spi.SecurityContext;
+import org.gatein.pc.api.spi.WindowContext;
+import org.gatein.pc.portlet.impl.jsr168.PortletUtils;
+import org.gatein.wsrp.WSRPConstants;
+import org.gatein.wsrp.WSRPTypeFactory;
+import org.gatein.wsrp.WSRPUtils;
+import org.gatein.wsrp.consumer.WSRPConsumerImpl;
+import org.oasis.wsrp.v2.InvalidCookie;
+import org.oasis.wsrp.v2.InvalidRegistration;
+import org.oasis.wsrp.v2.InvalidSession;
+import org.oasis.wsrp.v2.MarkupParams;
+import org.oasis.wsrp.v2.NavigationalContext;
+import org.oasis.wsrp.v2.OperationFailed;
+import org.oasis.wsrp.v2.PortletContext;
+import org.oasis.wsrp.v2.RuntimeContext;
+import org.oasis.wsrp.v2.UserContext;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import java.rmi.RemoteException;
+import java.util.Collections;
+import java.util.Map;
+
+/**
+ * @author <a href="mailto:chris.laprun@jboss.com">Chris Laprun</a>
+ * @version $Revision: 13121 $
+ * @since 2.4 (May 31, 2006)
+ */
+public abstract class InvocationHandler<Invocation extends PortletInvocation, Request, Response>
+{
+ protected final WSRPConsumerImpl consumer;
+
+ protected static Logger log = LoggerFactory.getLogger(InvocationHandler.class);
+ protected static boolean debug = log.isDebugEnabled();
+ protected static boolean trace = log.isTraceEnabled();
+
+ /**
+ * Value indicating that we should not try further (unrecoverable error) for getMarkup and
+ * processBlockingInteraction
+ */
+ private static final int DO_NOT_RETRY = -1;
+
+ /** Maximum number of tries before giving up. */
+ private static final int MAXIMUM_RETRY_NUMBER = 3;
+
+ protected InvocationHandler(WSRPConsumerImpl consumer)
+ {
+ this.consumer = consumer;
+ }
+
+ public PortletInvocationResponse handle(Invocation invocation) throws PortletInvokerException
+ {
+ // Extracts basic required information from invocation
+ RequestPrecursor<Invocation> requestPrecursor = new RequestPrecursor<Invocation>(consumer, invocation);
+
+ // create the specific request
+ Request request = prepareRequest(requestPrecursor, invocation);
+
+ // Perform the request
+ try
+ {
+ Response response = performRequest(request, invocation);
+ return processResponse(response, invocation, requestPrecursor);
+ }
+ catch (Exception e)
+ {
+ if (!(e instanceof PortletInvokerException))
+ {
+ ErrorResponse errorResponse = dealWithError(e, invocation, getRuntimeContextFrom(request));
+ if (errorResponse != null)
+ {
+ return unwrapWSRPError(errorResponse);
+ }
+ else
+ {
+ return new ErrorResponse(e);
+ }
+ }
+ else
+ {
+ throw (PortletInvokerException)e;
+ }
+ }
+ /*if (response instanceof ErrorResponse)
+ {
+ return unwrapWSRPError((ErrorResponse)response);
+ }*/
+ }
+
+ protected Response performRequest(Request request, PortletInvocation invocation) throws Exception
+ {
+ int retryCount = 0;
+ Response response = null;
+
+ // as long as we don't get a non-null response and we're allowed to try again, try to perform the request
+ while (response == null && retryCount++ <= MAXIMUM_RETRY_NUMBER)
+ {
+ if (debug)
+ {
+ log.debug("performRequest: " + retryCount + " attempt(s) out of " + MAXIMUM_RETRY_NUMBER + " possible");
+ }
+ SessionHandler sessionHandler = consumer.getSessionHandler();
+
+ // prepare everything for the request
+ updateRegistrationContext(request);
+ RuntimeContext runtimeContext = getRuntimeContextFrom(request);
+
+ if (runtimeContext != null)
+ {
+ WindowContext windowContext = invocation.getWindowContext();
+ runtimeContext.setNamespacePrefix(getNamespaceFrom(windowContext));
+
+ InstanceContext instanceContext = invocation.getInstanceContext();
+ runtimeContext.setPortletInstanceKey(instanceContext == null ? null : instanceContext.getId());
+
+ updateUserContext(request, consumer.getUserContextFrom(invocation, runtimeContext));
+ consumer.setTemplatesIfNeeded(invocation, runtimeContext);
+ }
+
+ try
+ {
+ sessionHandler.initCookieIfNeeded(invocation);
+
+ // if we need cookies, set the current group id
+ sessionHandler.initProducerSessionInformation(invocation);
+
+ response = performRequest(request);
+
+ sessionHandler.updateCookiesIfNeeded(invocation);
+ }
+ /*catch (Exception e)
+ {
+ ErrorResponse errorResponse = dealWithError(e, invocation, runtimeContext);
+ if (errorResponse != null)
+ {
+ return errorResponse;
+ }
+ }*/
+ finally
+ {
+ // we're done: reset currently held information
+ sessionHandler.resetCurrentlyHeldInformation();
+ }
+ }
+
+ if (retryCount >= MAXIMUM_RETRY_NUMBER)
+ {
+ /*return new ErrorResponse(new RuntimeException("Tried to perform request " + MAXIMUM_RETRY_NUMBER
+ + " times before giving up. This usually happens if an error in the WS stack prevented the messages to be " +
+ "properly transmitted. Look at server.log for clues as to what happened..."));*/
+ throw new RuntimeException("Tried to perform request " + MAXIMUM_RETRY_NUMBER
+ + " times before giving up. This usually happens if an error in the WS stack prevented the messages to be " +
+ "properly transmitted. Look at server.log for clues as to what happened...");
+ }
+
+ if (debug)
+ {
+ log.debug("performRequest finished. Response is " + (response != null ? response.getClass().getName() : null));
+ }
+ return response;
+ }
+
+ protected static String getNamespaceFrom(WindowContext windowContext)
+ {
+ if (windowContext != null)
+ {
+ // MUST match namespace generation used in PortletResponseImpl.getNamespace in portlet module...
+ return PortletUtils.generateNamespaceFrom(windowContext.getId());
+ }
+
+ return null;
+ }
+
+ /**
+ * Deals with common error conditions.
+ *
+ * @param error the error that is to be dealt with
+ * @param invocation the invocation that caused the error to occur
+ * @param runtimeContext the current WSRP RuntimeContext
+ * @return an ErrorResponse if the error couldn't be dealt with or <code>null</code> if the error was correctly
+ * handled
+ */
+ private ErrorResponse dealWithError(Exception error, Invocation invocation, RuntimeContext runtimeContext)
+ throws PortletInvokerException
+ {
+ log.error("The portlet threw an exception", error);
+
+ SessionHandler sessionHandler = consumer.getSessionHandler();
+
+ // recoverable errors
+ if (error instanceof InvalidCookie)
+ {
+ // we need to re-init the cookies
+ log.debug("Re-initializing cookies after InvalidCookieFault.");
+ // force a producer info refresh because the invalid cookie might be due to a change of cookie policy on the producer
+ consumer.refreshProducerInfo();
+ try
+ {
+ sessionHandler.initCookieIfNeeded(invocation);
+ }
+ catch (Exception e)
+ {
+ log.debug("Couldn't init cookie: " + e.getLocalizedMessage());
+ return new ErrorResponse(e);
+ }
+ }
+ else if (error instanceof InvalidSession)
+ {
+ log.debug("Session invalidated after InvalidSessionFault, will re-send session-stored information.");
+ sessionHandler.handleInvalidSessionFault(invocation, runtimeContext);
+ }
+ else if (error instanceof InvalidRegistration)
+ {
+ log.debug("Invalid registration");
+ consumer.handleInvalidRegistrationFault();
+ }
+ else
+ {
+ // other errors cannot be dealt with: we have an error condition
+ return new ErrorResponse(error);
+ }
+ return null;
+ }
+
+ protected ErrorResponse unwrapWSRPError(ErrorResponse errorResponse)
+ {
+ Throwable cause = errorResponse.getCause();
+ if (cause != null)
+ {
+ // unwrap original exception...
+ if (cause instanceof OperationFailed && cause.getCause() != null)
+ {
+ cause = cause.getCause();
+ }
+ else if (cause instanceof RemoteException)
+ {
+ cause = ((RemoteException)cause).detail;
+ }
+ log.debug("Invocation of action failed: " + cause.getMessage(), cause); // fix-me?
+ return new ErrorResponse(cause);
+ }
+ else
+ {
+ log.debug("Invocation of action failed: " + errorResponse.getMessage());
+ return errorResponse;
+ }
+ }
+
+ protected abstract void updateUserContext(Request request, UserContext userContext);
+
+ protected abstract void updateRegistrationContext(Request request) throws PortletInvokerException;
+
+ protected abstract RuntimeContext getRuntimeContextFrom(Request request);
+
+ protected abstract Response performRequest(Request request) throws Exception;
+
+ protected abstract Request prepareRequest(RequestPrecursor<Invocation> requestPrecursor, Invocation invocation);
+
+ protected abstract PortletInvocationResponse processResponse(Response response, Invocation invocation, RequestPrecursor<Invocation> requestPrecursor) throws PortletInvokerException;
+
+ /**
+ * Extracts basic required elements for all invocation requests.
+ *
+ * @author <a href="mailto:chris.laprun@jboss.com">Chris Laprun</a>
+ * @version $Revision: 13121 $
+ * @since 2.4
+ */
+ protected static class RequestPrecursor<Invocation extends PortletInvocation>
+ {
+ private final static Logger log = LoggerFactory.getLogger(RequestPrecursor.class);
+
+ private PortletContext portletContext;
+ private RuntimeContext runtimeContext;
+ private MarkupParams markupParams;
+ private static final String PORTLET_HANDLE = "portlet handle";
+ private static final String SECURITY_CONTEXT = "security context";
+ private static final String USER_CONTEXT = "user context";
+ private static final String INVOCATION_CONTEXT = "invocation context";
+ private static final String STREAM_INFO = "stream info in invocation context";
+ private static final String USER_AGENT = "User-Agent";
+
+ public RequestPrecursor(WSRPConsumerImpl wsrpConsumer, Invocation invocation) throws PortletInvokerException
+ {
+ // retrieve handle
+ portletContext = WSRPUtils.convertToWSRPPortletContext(WSRPConsumerImpl.getPortletContext(invocation));
+ ParameterValidation.throwIllegalArgExceptionIfNullOrEmpty(getPortletHandle(), PORTLET_HANDLE, null);
+ if (log.isDebugEnabled())
+ {
+ log.debug("About to invoke on portlet: " + getPortletHandle());
+ }
+
+ // create runtime context
+ SecurityContext securityContext = invocation.getSecurityContext();
+ ParameterValidation.throwIllegalArgExceptionIfNull(securityContext, SECURITY_CONTEXT);
+ String authType = WSRPUtils.convertRequestAuthTypeToWSRPAuthType(securityContext.getAuthType());
+ setRuntimeContext(WSRPTypeFactory.createRuntimeContext(authType));
+
+ // set the session id if needed
+ wsrpConsumer.getSessionHandler().setSessionIdIfNeeded(invocation, getRuntimeContext(), getPortletHandle());
+
+ wsrpConsumer.setTemplatesIfNeeded(invocation, getRuntimeContext());
+
+ // create markup params
+ org.gatein.pc.api.spi.UserContext userContext = invocation.getUserContext();
+ ParameterValidation.throwIllegalArgExceptionIfNull(userContext, USER_CONTEXT);
+ PortletInvocationContext context = invocation.getContext();
+ ParameterValidation.throwIllegalArgExceptionIfNull(context, INVOCATION_CONTEXT);
+ ContentInfo streamInfo = context.getMarkupInfo();
+ ParameterValidation.throwIllegalArgExceptionIfNull(streamInfo, STREAM_INFO);
+
+ String mode;
+ try
+ {
+ mode = WSRPUtils.getWSRPNameFromJSR168PortletMode(invocation.getMode());
+ }
+ catch (Exception e)
+ {
+ log.debug("Mode was null in context.");
+ mode = WSRPConstants.VIEW_MODE;
+ }
+
+ String windowState;
+ try
+ {
+ windowState = WSRPUtils.getWSRPNameFromJSR168WindowState(invocation.getWindowState());
+ }
+ catch (Exception e)
+ {
+ log.debug("WindowState was null in context.");
+ windowState = WSRPConstants.NORMAL_WINDOW_STATE;
+ }
+
+ setMarkupParams(WSRPTypeFactory.createMarkupParams(securityContext.isSecure(),
+ WSRPUtils.convertLocalesToRFC3066LanguageTags(userContext.getLocales()),
+ Collections.singletonList(streamInfo.getMediaType().getValue()), mode, windowState));
+ String userAgent = WSRPConsumerImpl.getHttpRequest(invocation).getHeader(USER_AGENT);
+ getMarkupParams().setClientData(WSRPTypeFactory.createClientData(userAgent));
+
+ // navigational state
+ StateString navigationalState = invocation.getNavigationalState();
+ Map<String, String[]> publicNavigationalState = invocation.getPublicNavigationalState();
+ NavigationalContext navigationalContext = WSRPTypeFactory.createNavigationalContextOrNull(navigationalState, publicNavigationalState);
+ getMarkupParams().setNavigationalContext(navigationalContext);
+
+ if (log.isDebugEnabled())
+ {
+ log.debug(WSRPUtils.toString(getMarkupParams()));
+ }
+ }
+
+ public String getPortletHandle()
+ {
+ return portletContext.getPortletHandle();
+ }
+
+
+ public PortletContext getPortletContext()
+ {
+ return portletContext;
+ }
+
+ public RuntimeContext getRuntimeContext()
+ {
+ return runtimeContext;
+ }
+
+ private void setRuntimeContext(RuntimeContext runtimeContext)
+ {
+ this.runtimeContext = runtimeContext;
+ }
+
+ public MarkupParams getMarkupParams()
+ {
+ return markupParams;
+ }
+
+ private void setMarkupParams(MarkupParams markupParams)
+ {
+ this.markupParams = markupParams;
+ }
+ }
+}
Modified: components/wsrp/trunk/consumer/src/main/java/org/gatein/wsrp/consumer/handlers/MimeResponseHandler.java
===================================================================
--- components/wsrp/trunk/consumer/src/main/java/org/gatein/wsrp/consumer/handlers/MimeResponseHandler.java 2010-08-16 10:06:08 UTC (rev 3834)
+++ components/wsrp/trunk/consumer/src/main/java/org/gatein/wsrp/consumer/handlers/MimeResponseHandler.java 2010-08-16 17:09:43 UTC (rev 3835)
@@ -38,7 +38,6 @@
import org.gatein.wsrp.WSRPPortletURL;
import org.gatein.wsrp.WSRPResourceURL;
import org.gatein.wsrp.WSRPRewritingConstants;
-import org.gatein.wsrp.consumer.InvocationHandler;
import org.gatein.wsrp.consumer.ProducerInfo;
import org.gatein.wsrp.consumer.WSRPConsumerImpl;
import org.oasis.wsrp.v2.CacheControl;
Modified: components/wsrp/trunk/consumer/src/main/java/org/gatein/wsrp/consumer/handlers/NavigationalStateUpdatingHandler.java
===================================================================
--- components/wsrp/trunk/consumer/src/main/java/org/gatein/wsrp/consumer/handlers/NavigationalStateUpdatingHandler.java 2010-08-16 10:06:08 UTC (rev 3834)
+++ components/wsrp/trunk/consumer/src/main/java/org/gatein/wsrp/consumer/handlers/NavigationalStateUpdatingHandler.java 2010-08-16 17:09:43 UTC (rev 3835)
@@ -30,7 +30,6 @@
import org.gatein.pc.api.invocation.response.UpdateNavigationalStateResponse;
import org.gatein.pc.api.spi.InstanceContext;
import org.gatein.wsrp.WSRPUtils;
-import org.gatein.wsrp.consumer.InvocationHandler;
import org.gatein.wsrp.consumer.WSRPConsumerImpl;
import org.gatein.wsrp.payload.PayloadUtils;
import org.oasis.wsrp.v2.Event;
Copied: components/wsrp/trunk/consumer/src/main/java/org/gatein/wsrp/consumer/handlers/ProducerSessionInformation.java (from rev 3834, components/wsrp/trunk/consumer/src/main/java/org/gatein/wsrp/consumer/ProducerSessionInformation.java)
===================================================================
--- components/wsrp/trunk/consumer/src/main/java/org/gatein/wsrp/consumer/handlers/ProducerSessionInformation.java (rev 0)
+++ components/wsrp/trunk/consumer/src/main/java/org/gatein/wsrp/consumer/handlers/ProducerSessionInformation.java 2010-08-16 17:09:43 UTC (rev 3835)
@@ -0,0 +1,531 @@
+/*
+ * JBoss, a division of Red Hat
+ * Copyright 2010, Red Hat Middleware, LLC, and individual
+ * contributors as indicated by the @authors tag. See the
+ * copyright.txt in the distribution for a full listing of
+ * individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+
+package org.gatein.wsrp.consumer.handlers;
+
+import org.apache.commons.httpclient.Cookie;
+import org.gatein.common.util.ParameterValidation;
+import org.gatein.common.util.Tools;
+import org.gatein.wsrp.WSRPConstants;
+import org.oasis.wsrp.v2.SessionContext;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import java.io.Serializable;
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+/**
+ * Records session and cookie information for a producer.
+ *
+ * @author <a href="mailto:chris.laprun@jboss.com">Chris Laprun</a>
+ * @version $Revision: 12736 $
+ * @since 2.4 (May 30, 2006)
+ */
+public class ProducerSessionInformation implements Serializable
+{
+ private static Logger log = LoggerFactory.getLogger(ProducerSessionInformation.class);
+
+ private boolean initCookieDone = false;
+ private boolean perGroupCookies = false;
+
+ /** group id -> Cookie[] */
+ private Map<String, Cookie[]> groupCookies;
+
+ /** portlet handle -> SessionInfo */
+ private Map<String, SessionInfo> portletSessions;
+
+ /** session id -> portlet handle */
+ private Map<String, String> sessionId2PortletHandle;
+
+ /** Cookies sent by the remote producer */
+ private Cookie[] userCookie;
+
+ /** Parent SessionHandler so that session mappings can be updated */
+ private transient SessionHandler parent;
+
+ /** The identifier of the Session containing this ProducerSessionInformation */
+ private String parentSessionId;
+
+ /**
+ * public only for tests
+ *
+ * @return
+ * @since 2.6
+ */
+ public String getParentSessionId()
+ {
+ return parentSessionId;
+ }
+
+ /**
+ * public only for tests
+ *
+ * @param parentSessionId
+ * @throws IllegalStateException if an attempt is made to set the parent session id to a different one when it has
+ * already been set.
+ * @since 2.6
+ */
+ public void setParentSessionId(String parentSessionId)
+ {
+ if (this.parentSessionId != null && !this.parentSessionId.equals(parentSessionId))
+ {
+ throw new IllegalStateException("Cannot modify Parent Session id once it has been set!");
+ }
+
+ this.parentSessionId = parentSessionId;
+ }
+
+ public String getUserCookie()
+ {
+ if (userCookie == null)
+ {
+ return null;
+ }
+
+ userCookie = purgeExpiredCookies(userCookie);
+ if (userCookie.length == 0)
+ {
+ setInitCookieDone(false);
+ }
+ return outputToExternalForm(userCookie);
+ }
+
+ public void setUserCookie(Cookie[] userCookie)
+ {
+ ParameterValidation.throwIllegalArgExceptionIfNullOrEmpty(userCookie, "cookies");
+
+ this.userCookie = userCookie;
+ }
+
+ public boolean isInitCookieDone()
+ {
+ return initCookieDone;
+ }
+
+ public void setInitCookieDone(boolean initCookieDone)
+ {
+ this.initCookieDone = initCookieDone;
+ }
+
+ public boolean isPerGroupCookies()
+ {
+ return perGroupCookies;
+ }
+
+ public void setPerGroupCookies(boolean perGroupCookies)
+ {
+ this.perGroupCookies = perGroupCookies;
+ }
+
+ public void setGroupCookieFor(String groupId, Cookie[] cookies)
+ {
+ if (!isPerGroupCookies())
+ {
+ throw new IllegalStateException("Cannot add group cookie when cookie protocol is perUser.");
+ }
+
+ if (groupId == null)
+ {
+ throw new IllegalArgumentException("Cannot set cookie for a null portlet group id!");
+ }
+
+ ParameterValidation.throwIllegalArgExceptionIfNullOrEmpty(cookies, "cookies");
+
+ if (groupCookies == null)
+ {
+ groupCookies = new HashMap<String, Cookie[]>();
+ }
+
+ if (groupCookies.containsKey(groupId))
+ {
+ log.debug("Trying to set a cookie for an existing group: " + groupId);
+ }
+
+ groupCookies.put(groupId, cookies);
+ }
+
+ public String getGroupCookieFor(String groupId)
+ {
+ if (groupCookies == null)
+ {
+ return null;
+ }
+
+ // purge expired cookies
+ Cookie[] cookies = groupCookies.get(groupId);
+ if (cookies != null)
+ {
+ cookies = purgeExpiredCookies(cookies);
+
+ // if there are no non-expired cookies left, we will need to re-init them
+ if (cookies.length == 0)
+ {
+ setInitCookieDone(false);
+ }
+
+ // update cookies for the considered group id
+ groupCookies.put(groupId, cookies);
+
+ return outputToExternalForm(cookies);
+ }
+ else
+ {
+ return null;
+ }
+ }
+
+ public void clearGroupCookies()
+ {
+ groupCookies = null;
+ }
+
+ public void addSessionForPortlet(String portletHandle, SessionContext sessionContext)
+ {
+ // sessionContext is validated in SessionInfo constructor
+ SessionInfo info = new SessionInfo(sessionContext, portletHandle);
+
+ if (portletSessions == null)
+ {
+ portletSessions = new HashMap<String, SessionInfo>();
+ sessionId2PortletHandle = new HashMap<String, String>();
+ }
+
+ portletSessions.put(portletHandle, info);
+ sessionId2PortletHandle.put(sessionContext.getSessionID(), portletHandle);
+
+ if (parent != null)
+ {
+ parent.addSessionMapping(sessionContext.getSessionID(), this);
+ }
+ }
+
+ /**
+ * Retrieves the session id for the portlet with the specified handle. Note that this will "touch" the session, hence
+ * resetting the time since the last use of the session.
+ *
+ * @param portletHandle the handle of the portlet for which the session id is to be retrieved
+ * @return the session id for the specified portlet, <code>null</code> if there is no session associated with the
+ * portlet or if the session has expired.
+ */
+ public String getSessionIdForPortlet(String portletHandle)
+ {
+ ProducerSessionInformation.SessionIdResult idResult = internalGetSessionIdForPortlet(portletHandle);
+ if (idResult.expired)
+ {
+ return null;
+ }
+
+ return idResult.id;
+ }
+
+ public int getNumberOfSessions()
+ {
+ if (portletSessions != null)
+ {
+ return portletSessions.size();
+ }
+ else
+ {
+ return 0;
+ }
+ }
+
+ /**
+ * @param sessionId
+ * @return the id of the removed session or <code>null</code> if the session had already expired
+ */
+ public String removeSession(String sessionId)
+ {
+ ParameterValidation.throwIllegalArgExceptionIfNull(sessionId, "session id");
+
+ String portletHandle = sessionId2PortletHandle.get(sessionId);
+ if (portletHandle == null)
+ {
+ throw new IllegalArgumentException("No such session id: '" + sessionId + "'");
+ }
+
+ return removeSessionForPortlet(portletHandle);
+ }
+
+ /**
+ * @return a list containing the session ids that were still valid when they were removed and would need to be
+ * released
+ */
+ public List<String> removeSessions()
+ {
+ List<String> idsToRelease = new ArrayList<String>(getNumberOfSessions());
+
+ // copy to avoid ConcurrentModificationException
+ List<String> handlesCopy = new ArrayList<String>(portletSessions.keySet());
+
+ for (String handle : handlesCopy)
+ {
+ SessionIdResult result = removeSessionIdForPortlet(handle);
+
+ // only release sessions that are still valid
+ if (!result.expired)
+ {
+ idsToRelease.add(result.id);
+ }
+ }
+
+ return idsToRelease;
+ }
+
+ /**
+ * @param portletHandle
+ * @return the id of the removed session or <code>null</code> if the session had already expired
+ */
+ public String removeSessionForPortlet(String portletHandle)
+ {
+ SessionIdResult result = removeSessionIdForPortlet(portletHandle);
+
+ return result.expired ? null : result.id;
+ }
+
+ private SessionIdResult removeSessionIdForPortlet(String portletHandle)
+ {
+ ProducerSessionInformation.SessionIdResult result = internalGetSessionIdForPortlet(portletHandle);
+ final String id = result.id;
+
+ if (id == null)
+ {
+ throw new IllegalArgumentException("There is no Session associated with portlet '" + portletHandle + "'");
+ }
+
+ // if the session is still valid, release it and remove the associated mappings
+ if (!result.expired)
+ {
+ portletSessions.remove(portletHandle);
+ sessionId2PortletHandle.remove(id);
+ if (parent != null)
+ {
+ parent.removeSessionId(id);
+ }
+ }
+
+ return result;
+ }
+
+ public void replaceUserCookiesWith(ProducerSessionInformation currentSessionInfo)
+ {
+ if (currentSessionInfo != null && currentSessionInfo.userCookie != null && currentSessionInfo.userCookie.length > 0)
+ {
+ this.userCookie = currentSessionInfo.userCookie;
+ }
+ }
+
+ /**
+ * Create a String representation of the specified array of Cookies.
+ *
+ * @param cookies the cookies to be output to external form
+ * @return a String representation of the cookies, ready to be sent over the wire.
+ */
+ private String outputToExternalForm(Cookie[] cookies)
+ {
+ if (cookies != null && cookies.length != 0)
+ {
+ int cookieNumber = cookies.length;
+ StringBuffer sb = new StringBuffer(128 * cookieNumber);
+ for (int i = 0; i < cookieNumber; i++)
+ {
+ sb.append(cookies[i].toExternalForm());
+ if (i != cookieNumber - 1)
+ {
+ sb.append(","); // multiple cookies are separated by commas: http://www.ietf.org/rfc/rfc2109.txt, 4.2.2
+ }
+ }
+ return sb.toString();
+ }
+ return null;
+ }
+
+ /**
+ * Purges the expired cookies in the specified array.
+ *
+ * @param cookies the cookies to be purged
+ * @return an array of Cookies containing only still valid cookies
+ */
+ private Cookie[] purgeExpiredCookies(Cookie[] cookies)
+ {
+ ParameterValidation.throwIllegalArgExceptionIfNullOrEmpty(cookies, "cookies");
+
+ List<Cookie> cleanCookies = Tools.toList(cookies);
+
+ for (Cookie cookie : cookies)
+ {
+ if (cookie.isExpired())
+ {
+ cleanCookies.remove(cookie);
+ }
+ }
+ return cleanCookies.toArray(new Cookie[cleanCookies.size()]);
+ }
+
+ private SessionIdResult internalGetSessionIdForPortlet(String portletHandle)
+ {
+ SessionInfo session = getSessionInfoFor(portletHandle);
+ if (session != null)
+ {
+ String id = session.getSessionId();
+ if (!session.isStillValid())
+ {
+ portletSessions.remove(session.getPortletHandle());
+ sessionId2PortletHandle.remove(session.getSessionId());
+ if (parent != null)
+ {
+ parent.removeSessionId(session.getSessionId());
+ }
+ return new SessionIdResult(id, true);
+ }
+ else
+ {
+ return new SessionIdResult(id, false);
+ }
+ }
+ return new SessionIdResult(null, false);
+ }
+
+ private SessionInfo getSessionInfoFor(String portletHandle)
+ {
+ ParameterValidation.throwIllegalArgExceptionIfNullOrEmpty(portletHandle, "portlet handle", null);
+
+ if (portletSessions == null)
+ {
+ return null;
+ }
+
+ return portletSessions.get(portletHandle);
+ }
+
+ /**
+ * @return the known session id
+ * @since 2.6
+ */
+ Collection<String> getSessionIds()
+ {
+ return sessionId2PortletHandle.keySet();
+ }
+
+ /**
+ * @param sessionHandler
+ * @since 2.6
+ */
+ void setParent(SessionHandler sessionHandler)
+ {
+ parent = sessionHandler;
+ }
+
+ /**
+ * Update the mappings that were associated with the specified original portlet handle after it has been modified as
+ * a result of a clone operation to the specified new handle.
+ *
+ * @param originalHandle
+ * @param newHandle
+ * @since 2.6
+ */
+ public void updateHandleAssociatedInfo(String originalHandle, String newHandle)
+ {
+ ParameterValidation.throwIllegalArgExceptionIfNullOrEmpty(originalHandle, "original handle",
+ "Updating information associated with a portlet handle");
+ ParameterValidation.throwIllegalArgExceptionIfNullOrEmpty(newHandle, "new handle",
+ "Updating information associated with a portlet handle");
+
+ String sessionId = getSessionIdForPortlet(originalHandle);
+ ProducerSessionInformation.SessionInfo info = getSessionInfoFor(originalHandle);
+ if (sessionId != null && info != null)
+ {
+ portletSessions.put(newHandle, info);
+ portletSessions.remove(originalHandle);
+ sessionId2PortletHandle.put(sessionId, newHandle);
+ log.debug("Updated mapping information for '" + originalHandle + "' to reference '" + newHandle + "' instead.");
+ }
+ }
+
+ private class SessionInfo implements Serializable
+ {
+ private SessionContext sessionContext;
+ private long lastInvocationTime;
+ private String portletHandle;
+
+ public SessionInfo(SessionContext sessionContext, String portletHandle)
+ {
+ ParameterValidation.throwIllegalArgExceptionIfNull(sessionContext, "SessionContext");
+ ParameterValidation.throwIllegalArgExceptionIfNullOrEmpty(sessionContext.getSessionID(), "session id", "SessionContext");
+ ParameterValidation.throwIllegalArgExceptionIfNullOrEmpty(portletHandle, "portlet handle", "SessionInfo");
+
+ this.sessionContext = sessionContext;
+ this.portletHandle = portletHandle;
+ lastInvocationTime = System.currentTimeMillis();
+ }
+
+ /**
+ * Checks that the session associated with the session context hasn't expired and update the last invocation time
+ *
+ * @return
+ */
+ private boolean isStillValid()
+ {
+ int expires = sessionContext.getExpires();
+ if (expires == WSRPConstants.SESSION_NEVER_EXPIRES)
+ {
+ return true;
+ }
+
+ long now = System.currentTimeMillis();
+ long secondsSinceLastInvocation = (now - lastInvocationTime) / 1000;
+ lastInvocationTime = now;
+
+ long diff = expires - secondsSinceLastInvocation;
+ log.debug("Session ID '" + sessionContext.getSessionID() + "' is " + ((diff > 0) ? "" : "not")
+ + " valid (time since last invocation: " + diff + ")");
+ return diff > 0;
+ }
+
+ private String getSessionId()
+ {
+ return sessionContext.getSessionID();
+ }
+
+ private String getPortletHandle()
+ {
+ return portletHandle;
+ }
+ }
+
+ private class SessionIdResult
+ {
+ private String id;
+ private boolean expired;
+
+ public SessionIdResult(String id, boolean expired)
+ {
+ this.id = id;
+ this.expired = expired;
+ }
+ }
+}
Copied: components/wsrp/trunk/consumer/src/main/java/org/gatein/wsrp/consumer/handlers/SessionHandler.java (from rev 3834, components/wsrp/trunk/consumer/src/main/java/org/gatein/wsrp/consumer/SessionHandler.java)
===================================================================
--- components/wsrp/trunk/consumer/src/main/java/org/gatein/wsrp/consumer/handlers/SessionHandler.java (rev 0)
+++ components/wsrp/trunk/consumer/src/main/java/org/gatein/wsrp/consumer/handlers/SessionHandler.java 2010-08-16 17:09:43 UTC (rev 3835)
@@ -0,0 +1,448 @@
+/*
+ * JBoss, a division of Red Hat
+ * Copyright 2010, Red Hat Middleware, LLC, and individual
+ * contributors as indicated by the @authors tag. See the
+ * copyright.txt in the distribution for a full listing of
+ * individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+
+package org.gatein.wsrp.consumer.handlers;
+
+import org.gatein.common.util.ParameterValidation;
+import org.gatein.pc.api.InvokerUnavailableException;
+import org.gatein.pc.api.Portlet;
+import org.gatein.pc.api.PortletInvokerException;
+import org.gatein.pc.api.invocation.PortletInvocation;
+import org.gatein.wsrp.api.SessionEvent;
+import org.gatein.wsrp.api.SessionEventListener;
+import org.gatein.wsrp.consumer.WSRPConsumerImpl;
+import org.gatein.wsrp.consumer.portlet.info.WSRPPortletInfo;
+import org.gatein.wsrp.handler.RequestHeaderClientHandler;
+import org.gatein.wsrp.servlet.UserAccess;
+import org.oasis.wsrp.v2.CookieProtocol;
+import org.oasis.wsrp.v2.InvalidRegistration;
+import org.oasis.wsrp.v2.RuntimeContext;
+import org.oasis.wsrp.v2.SessionContext;
+import org.oasis.wsrp.v2.SessionParams;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import javax.servlet.http.HttpSession;
+import java.util.ArrayList;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+import java.util.concurrent.ConcurrentHashMap;
+
+/**
+ * Manages session informations on behalf of a consumer.
+ *
+ * @author <a href="mailto:chris.laprun@jboss.com">Chris Laprun</a>
+ * @version $Revision: 9360 $
+ * @since 2.4 (May 31, 2006)
+ */
+public class SessionHandler implements SessionEventListener
+{
+ protected WSRPConsumerImpl consumer;
+ private static Logger log = LoggerFactory.getLogger(SessionHandler.class);
+
+ /** Cookie protocol required by the producer with the consumer */
+ private CookieProtocol requiresInitCookie;
+
+ /** The prefix used to isolate WSRP-related session information in the actual session object. */
+ private static final String SESSION_ID_PREFIX = "org.gatein.wsrp.session.";
+
+ /** session id -> ProducerSessionInformation */
+ private Map<String, ProducerSessionInformation> sessionInfos = new ConcurrentHashMap<String, ProducerSessionInformation>(); // todo: thread-safe?
+
+ /**
+ * Constructs a new SessionHandler.
+ *
+ * @param consumer the consumer this SessionHandler is associated with.
+ */
+ public SessionHandler(WSRPConsumerImpl consumer)
+ {
+ this.consumer = consumer;
+ }
+
+ public boolean isPerUserCookieInit()
+ {
+ return CookieProtocol.PER_USER.equals(requiresInitCookie);
+ }
+
+ public boolean requiresInitCookie()
+ {
+ return requiresInitCookie != null && !CookieProtocol.NONE.equals(requiresInitCookie);
+ }
+
+ public void setRequiresInitCookie(CookieProtocol requiresInitCookie)
+ {
+ this.requiresInitCookie = requiresInitCookie;
+ }
+
+ void initProducerSessionInformation(PortletInvocation invocation) throws PortletInvokerException
+ {
+ // if we need cookies, set the current group id
+ String groupId;
+ if (requiresGroupInitCookie())
+ {
+ WSRPPortletInfo info = consumer.getPortletInfo(invocation);
+ groupId = info.getGroupId();
+ }
+ else
+ {
+ groupId = null;
+ }
+
+ RequestHeaderClientHandler.setCurrentInfo(groupId, getProducerSessionInformation(invocation, true));
+ }
+
+ private boolean requiresGroupInitCookie()
+ {
+ return requiresInitCookie() && CookieProtocol.PER_GROUP.equals(requiresInitCookie);
+ }
+
+ /** Resets the information held by RequestHeaderClientHandler for the current interaction. */
+ public void resetCurrentlyHeldInformation()
+ {
+ RequestHeaderClientHandler.resetCurrentInfo();
+ }
+
+ public void initCookieIfNeeded(PortletInvocation invocation) throws PortletInvokerException
+ {
+ initCookieIfNeeded(invocation, true);
+ }
+
+ private void initCookieIfNeeded(PortletInvocation invocation, boolean retryIfFails) throws PortletInvokerException
+ {
+ // check if the cookie protocol requires cookie initialization
+ if (!requiresInitCookie())
+ {
+ return;
+ }
+
+ // check if we have already initialized cookies for this user
+ ProducerSessionInformation sessionInformation = getProducerSessionInformation(invocation);
+ if (sessionInformation.isInitCookieDone())
+ {
+ return;
+ }
+ RequestHeaderClientHandler.setCurrentInfo(null, sessionInformation);
+
+ if (isPerUserCookieInit())
+ {
+ log.debug("Cookie initialization per user requested.");
+ sessionInformation.setPerGroupCookies(false);
+ initCookie(invocation, retryIfFails);
+ }
+ else
+ {
+ log.debug("Cookie initialization per group requested.");
+ sessionInformation.setPerGroupCookies(true);
+ Map<String, Set<Portlet>> groups = consumer.getPortletGroupMap();
+
+ try
+ {
+ for (String groupId : groups.keySet())
+ {
+ RequestHeaderClientHandler.setCurrentGroupId(groupId);
+ log.debug("Initializing cookie for group '" + groupId + "'.");
+ initCookie(invocation, retryIfFails);
+ }
+ }
+ finally
+ {
+ resetCurrentlyHeldInformation();
+ }
+ }
+
+ sessionInformation.setInitCookieDone(true);
+ }
+
+ private void initCookie(PortletInvocation invocation, boolean retryIfFails) throws PortletInvokerException
+ {
+ try
+ {
+ consumer.getMarkupService().initCookie(consumer.getRegistrationContext(), UserAccess.getUserContext());
+ }
+ catch (InvalidRegistration invalidRegistration)
+ {
+ consumer.handleInvalidRegistrationFault();
+ if (retryIfFails)
+ {
+ initCookieIfNeeded(invocation, false);
+ }
+ }
+ catch (Exception e)
+ {
+ throw new InvokerUnavailableException("Couldn't init cookies!", e);
+ }
+ }
+
+ void setSessionIdIfNeeded(PortletInvocation invocation, RuntimeContext runtimeContext, String portletHandle)
+ {
+ ProducerSessionInformation producerSessionInfo = getProducerSessionInformation(invocation, false);
+ if (producerSessionInfo != null)
+ {
+ String sessionId = producerSessionInfo.getSessionIdForPortlet(portletHandle);
+ SessionParams sessionParams = runtimeContext.getSessionParams();
+ if (sessionParams == null)
+ {
+ sessionParams = new SessionParams();
+ runtimeContext.setSessionParams(sessionParams);
+ }
+ sessionParams.setSessionID(sessionId);
+ }
+ }
+
+ public void updateSessionIfNeeded(SessionContext sessionContext, PortletInvocation invocation, String portletHandle)
+ {
+ if (sessionContext != null)
+ {
+ log.debug("Portlet '" + portletHandle + "' created session with id '" + sessionContext.getSessionID() + "'");
+ ProducerSessionInformation sessionInfo = getProducerSessionInformation(invocation);
+ sessionInfo.addSessionForPortlet(portletHandle, sessionContext);
+ }
+ }
+
+ void updateCookiesIfNeeded(PortletInvocation invocation)
+ {
+ ProducerSessionInformation sessionInfo = getProducerSessionInformation(invocation, true);
+ ProducerSessionInformation currentSessionInfo = RequestHeaderClientHandler.getCurrentProducerSessionInformation();
+ if (sessionInfo != currentSessionInfo)
+ {
+ sessionInfo.replaceUserCookiesWith(currentSessionInfo);
+ }
+ }
+
+ public ProducerSessionInformation getProducerSessionInformation(PortletInvocation invocation)
+ {
+ return getProducerSessionInformation(invocation, true);
+ }
+
+ private ProducerSessionInformation getProducerSessionInformation(PortletInvocation invocation, boolean create)
+ {
+ HttpSession session = WSRPConsumerImpl.getHttpSession(invocation);
+ return getProducerSessionInformation(session, create);
+ }
+
+ public ProducerSessionInformation getProducerSessionInformation(HttpSession session)
+ {
+ return getProducerSessionInformation(session, false);
+ }
+
+ private ProducerSessionInformation getProducerSessionInformation(HttpSession session, boolean create)
+ {
+ ParameterValidation.throwIllegalArgExceptionIfNull(session, "Session");
+ String producerSessionKey = getProducerSessionInformationKey();
+ ProducerSessionInformation sessionInformation = (ProducerSessionInformation)session.getAttribute(producerSessionKey);
+
+ if (sessionInformation != null)
+ {
+ sessionInformation.setParent(this);
+ sessionInformation.setParentSessionId(session.getId());
+ }
+ else
+ {
+ if (create)
+ {
+ sessionInformation = new ProducerSessionInformation();
+ sessionInformation.setParentSessionId(session.getId());
+ session.setAttribute(producerSessionKey, sessionInformation);
+ sessionInformation.setParent(this);
+ }
+ }
+
+ return sessionInformation;
+ }
+
+ private String getProducerSessionInformationKey()
+ {
+ return SESSION_ID_PREFIX + consumer.getProducerId();
+ }
+
+ void handleInvalidSessionFault(PortletInvocation invocation, RuntimeContext runtimeContext)
+ {
+ log.info("Resending information after InvalidSessionFault");
+ // invalidate current session
+ invalidateSession(invocation);
+
+ // set the session id to null
+ if (runtimeContext != null)
+ {
+ runtimeContext.setSessionParams(null);
+ }
+ }
+
+ private void invalidateSession(PortletInvocation invocation)
+ {
+ HttpSession session = WSRPConsumerImpl.getHttpSession(invocation);
+
+ // remove the associated info from the known producer session informations
+
+ ProducerSessionInformation info = getProducerSessionInformation(session, false);
+ if (info != null)
+ {
+ try
+ {
+ internalReleaseSessions(info.removeSessions());
+ }
+ catch (PortletInvokerException e)
+ {
+ // ignore since it's logged by internalReleaseSessions already
+ }
+ }
+
+
+ session.removeAttribute(getProducerSessionInformationKey());
+ RequestHeaderClientHandler.resetCurrentInfo();
+ }
+
+ /** @since 2.6 */
+ public void releaseSessions() throws PortletInvokerException
+ {
+ List<String> idsToRelease = new ArrayList<String>();
+
+ Set<ProducerSessionInformation> uniqueInfos = new HashSet<ProducerSessionInformation>(sessionInfos.values());
+
+ for (ProducerSessionInformation info : uniqueInfos)
+ {
+ idsToRelease.addAll(info.removeSessions());
+ }
+
+ internalReleaseSessions(idsToRelease);
+ }
+
+ /**
+ * @param sessionIds
+ * @throws PortletInvokerException
+ * @since 2.6
+ */
+ void releaseSessions(String[] sessionIds) throws PortletInvokerException
+ {
+ if (sessionIds != null)
+ {
+ List<String> idsToRelease = new ArrayList<String>();
+
+ for (String sessionId : sessionIds)
+ {
+ ProducerSessionInformation info = sessionInfos.get(sessionId);
+ sessionId = info.removeSession(sessionId);
+ if (sessionId != null)
+ {
+ idsToRelease.add(sessionId);
+ }
+ }
+
+ internalReleaseSessions(idsToRelease);
+ }
+ }
+
+ private void internalReleaseSessions(List<String> idsToRelease) throws PortletInvokerException
+ {
+ if (idsToRelease != null && !idsToRelease.isEmpty())
+ {
+ try
+ {
+ consumer.getMarkupService().releaseSessions(consumer.getRegistrationContext(), idsToRelease, UserAccess.getUserContext());
+ }
+ catch (InvalidRegistration invalidRegistration)
+ {
+ log.debug("Invalid Registration");
+ consumer.handleInvalidRegistrationFault();
+ }
+ catch (Exception e)
+ {
+ String message = "Couldn't release sessions " + idsToRelease;
+ log.debug(message, e);
+ throw new PortletInvokerException(message, e);
+ }
+ }
+ }
+
+ // ProducerSessionInformation callbacks
+
+ /**
+ * Update session mappings when a session has expired
+ *
+ * @param id
+ * @since 2.6
+ */
+ void removeSessionId(String id)
+ {
+ sessionInfos.remove(id);
+ }
+
+ /**
+ * Update session mappings when a new session id is added to the specified ProducerSessionInformation
+ *
+ * @param sessionID
+ * @param producerSessionInformation
+ * @since 2.6
+ */
+ void addSessionMapping(String sessionID, ProducerSessionInformation producerSessionInformation)
+ {
+ sessionInfos.put(sessionID, producerSessionInformation);
+ }
+
+ // End ProducerSessionInformation callbacks
+
+ // SessionEventListener implementation
+
+ public void onSessionEvent(SessionEvent event)
+ {
+ if (SessionEvent.SessionEventType.SESSION_DESTROYED.equals(event.getType()))
+ {
+ String id = event.getSession().getId();
+
+ // check if the session being destroyed is the one associated with this thread
+ ProducerSessionInformation info = RequestHeaderClientHandler.getCurrentProducerSessionInformation();
+ if (info != null)
+ {
+ if (id != null && id.equals(info.getParentSessionId()))
+ {
+ try
+ {
+ internalReleaseSessions(info.removeSessions());
+ }
+ catch (PortletInvokerException e)
+ {
+ // already logged...
+ }
+ log.debug("Released session '" + id + "' after session was destroyed by Portal.");
+ }
+ }
+ }
+ }
+
+ /**
+ * @param originalHandle
+ * @param newHandle
+ * @param invocation
+ * @since 2.6
+ */
+ public void updateSessionInfoFor(String originalHandle, String newHandle, PortletInvocation invocation)
+ {
+ ProducerSessionInformation info = getProducerSessionInformation(invocation, false);
+ if (info != null)
+ {
+ info.updateHandleAssociatedInfo(originalHandle, newHandle);
+ }
+ }
+}
Modified: components/wsrp/trunk/consumer/src/main/java/org/gatein/wsrp/handler/RequestHeaderClientHandler.java
===================================================================
--- components/wsrp/trunk/consumer/src/main/java/org/gatein/wsrp/handler/RequestHeaderClientHandler.java 2010-08-16 10:06:08 UTC (rev 3834)
+++ components/wsrp/trunk/consumer/src/main/java/org/gatein/wsrp/handler/RequestHeaderClientHandler.java 2010-08-16 17:09:43 UTC (rev 3835)
@@ -24,7 +24,7 @@
package org.gatein.wsrp.handler;
import org.apache.commons.httpclient.Cookie;
-import org.gatein.wsrp.consumer.ProducerSessionInformation;
+import org.gatein.wsrp.consumer.handlers.ProducerSessionInformation;
import javax.xml.namespace.QName;
import javax.xml.soap.MimeHeaders;
Modified: components/wsrp/trunk/consumer/src/test/java/org/gatein/wsrp/consumer/ProducerSessionInformationTestCase.java
===================================================================
--- components/wsrp/trunk/consumer/src/test/java/org/gatein/wsrp/consumer/ProducerSessionInformationTestCase.java 2010-08-16 10:06:08 UTC (rev 3834)
+++ components/wsrp/trunk/consumer/src/test/java/org/gatein/wsrp/consumer/ProducerSessionInformationTestCase.java 2010-08-16 17:09:43 UTC (rev 3835)
@@ -27,6 +27,7 @@
import org.apache.commons.httpclient.Cookie;
import org.gatein.wsrp.WSRPConstants;
import org.gatein.wsrp.WSRPTypeFactory;
+import org.gatein.wsrp.consumer.handlers.ProducerSessionInformation;
/**
* @author <a href="mailto:chris.laprun@jboss.com?subject=org.gatein.wsrp.consumer.ProducerSessionInformationTestCase">Chris
Modified: components/wsrp/trunk/consumer/src/test/java/org/gatein/wsrp/handler/RequestHeaderClientHandlerTestCase.java
===================================================================
--- components/wsrp/trunk/consumer/src/test/java/org/gatein/wsrp/handler/RequestHeaderClientHandlerTestCase.java 2010-08-16 10:06:08 UTC (rev 3834)
+++ components/wsrp/trunk/consumer/src/test/java/org/gatein/wsrp/handler/RequestHeaderClientHandlerTestCase.java 2010-08-16 17:09:43 UTC (rev 3835)
@@ -1,31 +1,31 @@
-/******************************************************************************
- * JBoss, a division of Red Hat *
- * Copyright 2006, Red Hat Middleware, LLC, and individual *
- * contributors as indicated by the @authors tag. See the *
- * copyright.txt in the distribution for a full listing of *
- * individual contributors. *
- * *
- * This is free software; you can redistribute it and/or modify it *
- * under the terms of the GNU Lesser General Public License as *
- * published by the Free Software Foundation; either version 2.1 of *
- * the License, or (at your option) any later version. *
- * *
- * This software is distributed in the hope that it will be useful, *
- * but WITHOUT ANY WARRANTY; without even the implied warranty of *
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU *
- * Lesser General Public License for more details. *
- * *
- * You should have received a copy of the GNU Lesser General Public *
- * License along with this software; if not, write to the Free *
- * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA *
- * 02110-1301 USA, or see the FSF site: http://www.fsf.org. *
- ******************************************************************************/
+/*
+ * JBoss, a division of Red Hat
+ * Copyright 2010, Red Hat Middleware, LLC, and individual
+ * contributors as indicated by the @authors tag. See the
+ * copyright.txt in the distribution for a full listing of
+ * individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
package org.gatein.wsrp.handler;
import junit.framework.TestCase;
import org.apache.commons.httpclient.Cookie;
-import org.gatein.wsrp.consumer.ProducerSessionInformation;
+import org.gatein.wsrp.consumer.handlers.ProducerSessionInformation;
import org.gatein.wsrp.test.handler.MockSOAPMessage;
import org.gatein.wsrp.test.handler.MockSOAPMessageContext;
Modified: components/wsrp/trunk/consumer/src/test/java/org/gatein/wsrp/protocol/v1/MarkupTestCase.java
===================================================================
--- components/wsrp/trunk/consumer/src/test/java/org/gatein/wsrp/protocol/v1/MarkupTestCase.java 2010-08-16 10:06:08 UTC (rev 3834)
+++ components/wsrp/trunk/consumer/src/test/java/org/gatein/wsrp/protocol/v1/MarkupTestCase.java 2010-08-16 17:09:43 UTC (rev 3835)
@@ -40,7 +40,7 @@
import org.gatein.pc.portlet.impl.spi.AbstractUserContext;
import org.gatein.pc.portlet.impl.spi.AbstractWindowContext;
import org.gatein.wsrp.WSRPResourceURL;
-import org.gatein.wsrp.consumer.ProducerSessionInformation;
+import org.gatein.wsrp.consumer.handlers.ProducerSessionInformation;
import org.gatein.wsrp.test.ExtendedAssert;
import org.gatein.wsrp.test.protocol.v1.BehaviorRegistry;
import org.gatein.wsrp.test.protocol.v1.behaviors.BasicMarkupBehavior;
@@ -67,7 +67,6 @@
import javax.servlet.http.HttpSession;
import javax.xml.ws.Holder;
-
import java.net.MalformedURLException;
import java.net.URL;
import java.util.Collections;
@@ -182,7 +181,7 @@
ExtendedAssert.assertFalse(sessionInfo.isPerGroupCookies());
ExtendedAssert.assertTrue(sessionInfo.isInitCookieDone());
-
+
ExtendedAssert.assertNotNull(sessionInfo.getUserCookie());
ExtendedAssert.assertEquals(1, behavior.getInitCookieCallCount());
@@ -219,7 +218,7 @@
String resourceID = WSRPResourceURL.encodeResource(null, new URL("http://localhost:8080/test-resource-portlet/gif/logo.gif"), false);
String expectedResult = "<img src='Resource id=" + resourceID + " ns=null ws=null m=null'/>";
-
+
//NOTE: the value we get back is from the TestPortletInvocationContext, not what we would normally receive
checkRenderResult(response, expectedResult);
}
Modified: components/wsrp/trunk/consumer/src/test/java/org/gatein/wsrp/test/support/MockWSRPConsumer.java
===================================================================
--- components/wsrp/trunk/consumer/src/test/java/org/gatein/wsrp/test/support/MockWSRPConsumer.java 2010-08-16 10:06:08 UTC (rev 3834)
+++ components/wsrp/trunk/consumer/src/test/java/org/gatein/wsrp/test/support/MockWSRPConsumer.java 2010-08-16 17:09:43 UTC (rev 3835)
@@ -30,14 +30,13 @@
import org.gatein.pc.api.PortletStateType;
import org.gatein.pc.api.invocation.PortletInvocation;
import org.gatein.pc.api.invocation.response.PortletInvocationResponse;
-import org.gatein.pc.api.state.DestroyCloneFailure;
import org.gatein.pc.api.state.PropertyChange;
import org.gatein.pc.api.state.PropertyMap;
import org.gatein.wsrp.WSRPConsumer;
import org.gatein.wsrp.api.SessionEvent;
import org.gatein.wsrp.consumer.ProducerInfo;
-import org.gatein.wsrp.consumer.ProducerSessionInformation;
import org.gatein.wsrp.consumer.RefreshResult;
+import org.gatein.wsrp.consumer.handlers.ProducerSessionInformation;
import javax.servlet.http.HttpSession;
import java.util.List;
@@ -171,13 +170,13 @@
}
public PortletContext exportPortlet(PortletStateType stateType, PortletContext originalPortletContext)
- throws PortletInvokerException
+ throws PortletInvokerException
{
throw new NotYetImplemented();
}
-
+
public PortletContext importPortlet(PortletStateType stateType, PortletContext originalPortletContext)
- throws PortletInvokerException
+ throws PortletInvokerException
{
throw new NotYetImplemented();
}
14 years, 5 months
gatein SVN: r3834 - portal/branches.
by do-not-reply@jboss.org
Author: hoang_to
Date: 2010-08-16 06:06:08 -0400 (Mon, 16 Aug 2010)
New Revision: 3834
Removed:
portal/branches/branched-r3776/
Log:
Delete no longer needed testing branch
14 years, 5 months
gatein SVN: r3833 - portal/branches.
by do-not-reply@jboss.org
Author: trong.tran
Date: 2010-08-16 05:49:11 -0400 (Mon, 16 Aug 2010)
New Revision: 3833
Added:
portal/branches/navcontroller/
Log:
create a navcontroller branch from gatein trunk at revision 3832 for committing URL controller works
Copied: portal/branches/navcontroller (from rev 3832, portal/trunk)
14 years, 5 months
gatein SVN: r3832 - portal/trunk/gadgets/eXoGadgets/src/main/webapp/gadgets/rssAggregator.
by do-not-reply@jboss.org
Author: hoang_to
Date: 2010-08-16 00:08:47 -0400 (Mon, 16 Aug 2010)
New Revision: 3832
Modified:
portal/trunk/gadgets/eXoGadgets/src/main/webapp/gadgets/rssAggregator/script.js
Log:
GTNPORTAL-1413: Apply patch of the issue to trunk
Modified: portal/trunk/gadgets/eXoGadgets/src/main/webapp/gadgets/rssAggregator/script.js
===================================================================
--- portal/trunk/gadgets/eXoGadgets/src/main/webapp/gadgets/rssAggregator/script.js 2010-08-16 03:58:50 UTC (rev 3831)
+++ portal/trunk/gadgets/eXoGadgets/src/main/webapp/gadgets/rssAggregator/script.js 2010-08-16 04:08:47 UTC (rev 3832)
@@ -83,16 +83,20 @@
}
}
-RssAggregator.prototype.renderFeed = function(feed) {
- this.feed = feed;
- gadgets.window.setTitle("RSS: " + feed.Title);
+RssAggregator.prototype.renderFeed = function(feedObj) {
+ if(feedObj.rc != 200 && feedObj.data == undefined) {
+ document.write("the url: " + feedurl + " is down or invalid");
+ return;
+ }
+ this.feed = feedObj.data;
+ gadgets.window.setTitle("RSS: " + this.feed.Title);
var feedEl = _gel("feedContainer");
var bullet = "<img src='" + this.getFavicon(feedurl) + "' alt='' border=0 align='absmiddle' style='height:16;width:16;' onerror='this.style.visibility=\"hidden\";'> ";
- if (feed != null) {
+ if (this.feed != null) {
// Access the data for a given entry
- if (feed.Entry) {
- for (var i = 0; i < feed.Entry.length; i++) {
+ if (this.feed.Entry) {
+ for (var i = 0; i < this.feed.Entry.length; i++) {
var itemEl = document.createElement('div');
var item_title = document.createElement('div');
var item_more = document.createElement('div');
@@ -116,10 +120,10 @@
item_date.className = 'date';
item_link.className = 'link';
- item_title.innerHTML = bullet + "<a id='link_title_"+i+"' class='titlelink' href='" + feed.Entry[i].Link + "' onclick='rssAggregator.toggleDescription("+i+");return false;'>" + feed.Entry[i].Title + "</a>";
- item_date.innerHTML = this.timeToPrettyString(feed.Entry[i].Date);
+ item_title.innerHTML = bullet + "<a id='link_title_"+i+"' class='titlelink' href='" + this.feed.Entry[i].Link + "' onclick='rssAggregator.toggleDescription("+i+");return false;'>" + this.feed.Entry[i].Title + "</a>";
+ item_date.innerHTML = this.timeToPrettyString(this.feed.Entry[i].Date);
- item_desc.innerHTML = feed.Entry[i].Summary;
+ item_desc.innerHTML = this.feed.Entry[i].Summary;
item_link.innerHTML = this.generateLinkContent(i);
@@ -146,6 +150,10 @@
}
RssAggregator.prototype.refreshFeed = function() {
- _IG_FetchFeedAsJSON(prefs.getString("rssurl"), function(feed) {rssAggregator.renderFeed(feed);}, entries, true);
+ var params = {};
+ params[gadgets.io.RequestParameters.CONTENT_TYPE] = gadgets.io.ContentType.FEED;
+ params[gadgets.io.RequestParameters.NUM_ENTRIES] = entries;
+ params[gadgets.io.RequestParameters.GET_SUMMARIES] = true;
+ gadgets.io.makeRequest(prefs.getString("rssurl"), function(feedObj) {rssAggregator.renderFeed(feedObj);}, params);
}
14 years, 5 months
gatein SVN: r3831 - portal/trunk/docs/reference-guide/en/modules/PortalDevelopment.
by do-not-reply@jboss.org
Author: hoang_to
Date: 2010-08-15 23:58:50 -0400 (Sun, 15 Aug 2010)
New Revision: 3831
Modified:
portal/trunk/docs/reference-guide/en/modules/PortalDevelopment/DefaultPortalNavigationConfiguration.xml
Log:
GTNPORTAL-1414: Document GateIn object XSD
Modified: portal/trunk/docs/reference-guide/en/modules/PortalDevelopment/DefaultPortalNavigationConfiguration.xml
===================================================================
--- portal/trunk/docs/reference-guide/en/modules/PortalDevelopment/DefaultPortalNavigationConfiguration.xml 2010-08-16 03:50:59 UTC (rev 3830)
+++ portal/trunk/docs/reference-guide/en/modules/PortalDevelopment/DefaultPortalNavigationConfiguration.xml 2010-08-16 03:58:50 UTC (rev 3831)
@@ -181,28 +181,36 @@
When <literal>#{...}</literal> syntax is used, the enclosed property name serves as a key that is automatically passed to internationalization mechanism
so the literal property name is replaced by a localized value taken from the associated properties file matching the current locale.
</para>
+
+<programlisting role="XML">
+ <![CDATA[
+<?xml version="1.0" encoding="ISO-8859-1"?>
+<node-navigation
+ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="http://www.gatein.org/xml/ns/gatein_objects_1_0 http://www.gatein.org/xml/ns/gatein_objects_1_0"
+ xmlns="http://www.gatein.org/xml/ns/gatein_objects_1_0">
+ <priority>1</priority>
+ <page-nodes>
+ <node>
+ <uri>home</uri>
+ <name>home</name>
+ <label>#{portal.classic.home}</label>
+ <page-reference>portal::classic::homepage</page-reference>
+ </node>
+ <node>
+ <uri>sitemap</uri>
+ <name>sitemap</name>
+ <label>#{portal.classic.sitemap}</label>
+ <visibility>DISPLAYED</visibility>
+ <page-reference>portal::classic::sitemap</page-reference>
+ </node>
+ </page-nodes>
+</node-navigation>
+
+ ]]>
+</programlisting>
+
-<programlisting role="XML"><?xml version="1.0" encoding="UTF-8"?>
-<node-navigation>
- <owner-type>portal</owner-type>
- <owner-id>classic</owner-id>
- <priority>1</priority>
- <page-nodes>
- <node>
- <uri>home</uri>
- <name>home</name>
- <label>#{portal.classic.home}</label>
- <page-reference>portal::classic::homepage</page-reference>
- </node>
- <node>
- <uri>webexplorer</uri>
- <name>webexplorer</name>
- <label>#{portal.classic.webexplorer}</label>
- <page-reference>portal::classic::webexplorer</page-reference>
- </node>
- </page-nodes>
-</node-navigation>
-</programlisting>
<para>
This navigation tree can have multiple views inside portlets (such as the breadcrumbs portlet) that render the current view node, the site map or the menu portlets.
</para>
@@ -221,42 +229,58 @@
This configuration file structure is very similar to <filename>portal.xml</filename> and it can also contain container tags.
Each application can decide whether to render the portlet border, the window state, the icons or portlet's mode.
</para>
+
+<programlisting role="XML">
+ <![CDATA[
+<?xml version="1.0" encoding="ISO-8859-1"?>
+<page-set
+ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="http://www.gatein.org/xml/ns/gatein_objects_1_0 http://www.gatein.org/xml/ns/gatein_objects_1_0"
+ xmlns="http://www.gatein.org/xml/ns/gatein_objects_1_0">
+
+ <page>
+ <name>homepage</name>
+ <title>Home Page</title>
+ <access-permissions>Everyone</access-permissions>
+ <edit-permission>*:/platform/administrators</edit-permission>
+ <portlet-application>
+ <portlet>
+ <application-ref>web</application-ref>
+ <portlet-ref>HomePagePortlet</portlet-ref>
+ <preferences>
+ <preference>
+ <name>template</name>
+ <value>system:/templates/groovy/webui/component/UIHomePagePortlet.gtmpl</value>
+ <read-only>false</read-only>
+ </preference>
+ </preferences>
+ </portlet>
+ <title>Home Page portlet</title>
+ <access-permissions>Everyone</access-permissions>
+ <show-info-bar>false</show-info-bar>
+ <show-application-state>false</show-application-state>
+ <show-application-mode>false</show-application-mode>
+ </portlet-application>
+ </page>
+ <page>
+ <name>sitemap</name>
+ <title>Site Map</title>
+ <access-permissions>Everyone</access-permissions>
+ <edit-permission>*:/platform/administrators</edit-permission>
+ <portlet-application>
+ <portlet>
+ <application-ref>web</application-ref>
+ <portlet-ref>SiteMapPortlet</portlet-ref>
+ </portlet>
+ <title>SiteMap</title>
+ <access-permissions>Everyone</access-permissions>
+ <show-info-bar>false</show-info-bar>
+ </portlet-application>
+ </page>
+</page-set>
+]]>
+</programlisting>
-<programlisting role="XML"><?xml version="1.0" encoding="ISO-8859-1"?>
-<page-set>
- <page>
- <page-id>portal::classic::homepage</page-id>
- <owner-type>portal</owner-type>
- <owner-id>classic</owner-id>
- <name>homepage</name>
- <title>Home Page</title>
- <access-permissions>Everyone</access-permissions>
- <edit-permission>*:/platform/administrators</edit-permission>
- <application>
- <instance-id>portal#classic:/web/HomePagePortlet/homepageportlet</instance-id>
- <title>Home Page portlet</title>
- <show-info-bar>false</show-info-bar>
- <show-application-state>false</show-application-state>
- <show-application-mode>false</show-application-mode>
- </application>
- </page>
-
- <page>
- <page-id>portal::classic::webexplorer</page-id>
- <owner-type>portal</owner-type>
- <owner-id>classic</owner-id>
- <name>webexplorer</name>
- <title>Web Explorer</title>
- <access-permissions>*:/platform/users</access-permissions>
- <edit-permission>*:/platform/administrators</edit-permission>
- <application>
- <instance-id>group#platform/users:/web/BrowserPortlet/WebExplorer</instance-id>
- <title>Web Explorer</title>
- <show-info-bar>false</show-info-bar>
- </application>
- </page>
-</page-set>
-</programlisting>
</listitem>
</varlistentry>
<varlistentry>
14 years, 5 months
gatein SVN: r3830 - in portal/trunk: component/application-registry/src/main/java/org/exoplatform/application/gadget/impl and 23 other directories.
by do-not-reply@jboss.org
Author: hoang_to
Date: 2010-08-15 23:50:59 -0400 (Sun, 15 Aug 2010)
New Revision: 3830
Added:
portal/trunk/component/resources/src/main/java/org/exoplatform/services/resources/LocaleContextInfo.java
portal/trunk/component/resources/src/main/java/org/exoplatform/services/resources/LocalePolicy.java
portal/trunk/component/web/controller/src/main/java/org/exoplatform/web/application/ApplicationRequestPhaseLifecycle.java
portal/trunk/component/web/controller/src/main/java/org/exoplatform/web/application/Phase.java
portal/trunk/web/eXoResources/src/main/webapp/skin/DefaultSkin/webui/component/UITree/background/NullItemIcon.gif
portal/trunk/webui/portal/src/main/java/org/exoplatform/portal/application/localization/
portal/trunk/webui/portal/src/main/java/org/exoplatform/portal/application/localization/DefaultLocalePolicyService.java
portal/trunk/webui/portal/src/main/java/org/exoplatform/portal/application/localization/HttpRequestWrapper.java
portal/trunk/webui/portal/src/main/java/org/exoplatform/portal/application/localization/LocalizationFilter.java
portal/trunk/webui/portal/src/main/java/org/exoplatform/portal/application/localization/LocalizationLifecycle.java
portal/trunk/webui/portal/src/main/java/org/exoplatform/portal/application/localization/NoBrowserLocalePolicyService.java
Removed:
portal/trunk/webui/portal/src/main/java/org/exoplatform/portal/application/localization/DefaultLocalePolicyService.java
portal/trunk/webui/portal/src/main/java/org/exoplatform/portal/application/localization/HttpRequestWrapper.java
portal/trunk/webui/portal/src/main/java/org/exoplatform/portal/application/localization/LocalizationFilter.java
portal/trunk/webui/portal/src/main/java/org/exoplatform/portal/application/localization/LocalizationLifecycle.java
portal/trunk/webui/portal/src/main/java/org/exoplatform/portal/application/localization/NoBrowserLocalePolicyService.java
Modified:
portal/trunk/component/application-registry/src/main/java/org/exoplatform/application/gadget/impl/GadgetRegistryServiceImpl.java
portal/trunk/component/management/src/main/java/org/exoplatform/management/data/RestResource.java
portal/trunk/component/resources/src/main/java/org/exoplatform/services/resources/ExoResourceBundle.java
portal/trunk/component/web/resources/src/main/java/org/exoplatform/portal/resource/GateInSkinConfigRemoval.java
portal/trunk/component/web/resources/src/main/java/org/exoplatform/portal/resource/MainResourceResolver.java
portal/trunk/component/web/resources/src/main/java/org/exoplatform/portal/resource/SkinService.java
portal/trunk/pom.xml
portal/trunk/portlet/dashboard/src/main/java/org/exoplatform/dashboard/webui/component/UIDashboardPortlet.java
portal/trunk/portlet/exoadmin/src/main/java/org/exoplatform/applicationregistry/webui/component/UIPortletManagement.java
portal/trunk/portlet/exoadmin/src/main/java/org/exoplatform/organization/webui/component/UIUserInfo.java
portal/trunk/web/eXoResources/src/main/webapp/javascript/eXo/portal/PortalDragDrop.js
portal/trunk/web/eXoResources/src/main/webapp/javascript/eXo/portal/UIPortal.js
portal/trunk/web/eXoResources/src/main/webapp/javascript/eXo/portal/UIPortalControl.js
portal/trunk/web/eXoResources/src/main/webapp/skin/DefaultSkin/webui/component/UITree/Stylesheet.css
portal/trunk/web/eXoResources/src/main/webapp/skin/DefaultSkin/webui/component/UITree/background/Dotted.gif
portal/trunk/web/portal/src/main/webapp/WEB-INF/web.xml
portal/trunk/web/portal/src/main/webapp/WEB-INF/webui-configuration.xml
portal/trunk/web/portal/src/main/webapp/groovy/portal/webui/application/UIPortlet.gtmpl
portal/trunk/web/portal/src/main/webapp/groovy/webui/form/UISearchForm.gtmpl
portal/trunk/webui/core/src/main/java/org/exoplatform/webui/core/UITree.java
portal/trunk/webui/core/src/main/java/org/exoplatform/webui/form/validator/DateTimeValidator.java
portal/trunk/webui/dashboard/src/main/java/org/exoplatform/dashboard/webui/component/DashboardParent.java
portal/trunk/webui/dashboard/src/main/java/org/exoplatform/dashboard/webui/component/UIDashboardEditForm.java
portal/trunk/webui/portal/src/main/java/conf/portal/configuration.xml
portal/trunk/webui/portal/src/main/java/org/exoplatform/portal/application/PortalRequestContext.java
portal/trunk/webui/portal/src/main/java/org/exoplatform/portal/application/PortalRequestHandler.java
portal/trunk/webui/portal/src/main/java/org/exoplatform/portal/application/PortalStateManager.java
portal/trunk/webui/portal/src/main/java/org/exoplatform/portal/application/UserProfileLifecycle.java
portal/trunk/webui/portal/src/main/java/org/exoplatform/portal/webui/application/ExoPortletInvocationContext.java
portal/trunk/webui/portal/src/main/java/org/exoplatform/portal/webui/application/ExoUserContext.java
portal/trunk/webui/portal/src/main/java/org/exoplatform/portal/webui/application/UIGadget.java
portal/trunk/webui/portal/src/main/java/org/exoplatform/portal/webui/application/UIPortletLifecycle.java
portal/trunk/webui/portal/src/main/java/org/exoplatform/portal/webui/portal/UILanguageSelector.java
portal/trunk/webui/portal/src/main/java/org/exoplatform/portal/webui/portal/UIPortal.java
portal/trunk/webui/portal/src/main/java/org/exoplatform/portal/webui/portal/UIPortalComposer.java
portal/trunk/webui/portal/src/main/java/org/exoplatform/portal/webui/workspace/UIPortalApplication.java
portal/trunk/webui/portlet/src/main/java/org/exoplatform/webui/core/UIPortletApplication.java
Log:
Merge changes from branch r3776 into trunk
Modified: portal/trunk/component/application-registry/src/main/java/org/exoplatform/application/gadget/impl/GadgetRegistryServiceImpl.java
===================================================================
--- portal/trunk/component/application-registry/src/main/java/org/exoplatform/application/gadget/impl/GadgetRegistryServiceImpl.java 2010-08-13 17:09:39 UTC (rev 3829)
+++ portal/trunk/component/application-registry/src/main/java/org/exoplatform/application/gadget/impl/GadgetRegistryServiceImpl.java 2010-08-16 03:50:59 UTC (rev 3830)
@@ -26,6 +26,7 @@
import org.exoplatform.application.registry.impl.ApplicationRegistryChromatticLifeCycle;
import org.exoplatform.commons.chromattic.ChromatticLifeCycle;
import org.exoplatform.commons.chromattic.ChromatticManager;
+import org.exoplatform.commons.utils.PropertyManager;
import org.exoplatform.container.xml.InitParams;
import org.exoplatform.container.xml.PropertiesParam;
import org.exoplatform.container.xml.ValueParam;
@@ -260,7 +261,9 @@
public boolean isGadgetDeveloper(String username)
{
- return true;
+ if(PropertyManager.isDevelopping())
+ return true;
+ return false;
}
public String getCountry()
Modified: portal/trunk/component/management/src/main/java/org/exoplatform/management/data/RestResource.java
===================================================================
--- portal/trunk/component/management/src/main/java/org/exoplatform/management/data/RestResource.java 2010-08-13 17:09:39 UTC (rev 3829)
+++ portal/trunk/component/management/src/main/java/org/exoplatform/management/data/RestResource.java 2010-08-16 03:50:59 UTC (rev 3830)
@@ -26,6 +26,8 @@
import org.exoplatform.management.spi.ManagedPropertyMetaData;
import org.exoplatform.management.spi.ManagedResource;
import org.exoplatform.management.spi.ManagedTypeMetaData;
+import org.exoplatform.services.rest.impl.ApplicationContextImpl;
+import org.exoplatform.services.rest.impl.MultivaluedMapImpl;
import javax.ws.rs.GET;
import javax.ws.rs.POST;
@@ -38,6 +40,10 @@
import javax.ws.rs.core.MultivaluedMap;
import javax.ws.rs.core.Response;
import javax.ws.rs.core.UriInfo;
+import javax.ws.rs.ext.MessageBodyReader;
+
+import java.lang.reflect.ParameterizedType;
+import java.lang.reflect.Type;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
@@ -126,6 +132,8 @@
@Produces(MediaType.APPLICATION_JSON)
public Object get(@Context UriInfo info, @PathParam("name") String name)
{
+ MultivaluedMap<String, String> parameters = info.getQueryParameters();
+
// Try first to get a property
RestResourceProperty property = properties.get(name);
if (property != null)
@@ -133,12 +141,12 @@
MethodInvoker getter = property.getGetterInvoker();
if (getter != null)
{
- return safeInvoke(getter, info.getQueryParameters());
+ return safeInvoke(getter, parameters);
}
}
//
- return tryInvoke(name, info, ImpactType.READ);
+ return tryInvoke(name, parameters, ImpactType.READ);
}
@PUT
@@ -146,6 +154,7 @@
@Produces(MediaType.APPLICATION_JSON)
public Object put(@Context UriInfo info, @PathParam("name") String name)
{
+ MultivaluedMap<String, String> parameters = getParameters(info);
// Try first to get a property
RestResourceProperty property = properties.get(name);
if (property != null)
@@ -153,12 +162,12 @@
MethodInvoker setter = property.getSetterInvoker();
if (setter != null)
{
- return safeInvoke(setter, info.getQueryParameters());
+ return safeInvoke(setter, parameters);
}
}
//
- return tryInvoke(name, info, ImpactType.IDEMPOTENT_WRITE);
+ return tryInvoke(name, parameters, ImpactType.IDEMPOTENT_WRITE);
}
@POST
@@ -166,7 +175,7 @@
@Produces(MediaType.APPLICATION_JSON)
public Object post(@Context UriInfo info, @PathParam("name") String name)
{
- return tryInvoke(name, info, ImpactType.WRITE);
+ return tryInvoke(name, getParameters(info), ImpactType.WRITE);
}
/**
@@ -177,10 +186,8 @@
* @param impact the expected impact
* @return a suitable response
*/
- private Object tryInvoke(String methodName, UriInfo info, ImpactType impact)
+ private Object tryInvoke(String methodName, MultivaluedMap<String, String> parameters, ImpactType impact)
{
- MultivaluedMap<String, String> parameters = info.getQueryParameters();
-
//
RestResourceMethod method = lookupMethod(methodName, parameters.keySet(), impact);
@@ -237,4 +244,32 @@
managedResource.afterInvoke(resource);
}
}
+
+ @SuppressWarnings("unchecked")
+ private MultivaluedMap<String, String> getParameters(UriInfo info)
+ {
+ MultivaluedMap<String, String> parameters = info.getQueryParameters();
+ ApplicationContextImpl context = (ApplicationContextImpl)info;
+
+ Type formType = (ParameterizedType)MultivaluedMapImpl.class.getGenericInterfaces()[0];
+ MediaType contentType = context.getHttpHeaders().getMediaType();
+ if (contentType == null) {
+ contentType = MediaType.APPLICATION_FORM_URLENCODED_TYPE;
+ }
+
+ MultivaluedMap<String, String> form = new MultivaluedMapImpl();
+ try {
+ MessageBodyReader reader =
+ context.getProviders().getMessageBodyReader(MultivaluedMap.class, formType, null, contentType);
+ if (reader != null) {
+ form = (MultivaluedMap<String, String>)reader.readFrom(MultivaluedMap.class, formType, null, contentType, context
+ .getHttpHeaders().getRequestHeaders(), context.getContainerRequest().getEntityStream());
+ }
+ } catch (Exception e) {
+ }
+
+ parameters.putAll(form);
+ return parameters;
+ }
+
}
Modified: portal/trunk/component/resources/src/main/java/org/exoplatform/services/resources/ExoResourceBundle.java
===================================================================
--- portal/trunk/component/resources/src/main/java/org/exoplatform/services/resources/ExoResourceBundle.java 2010-08-13 17:09:39 UTC (rev 3829)
+++ portal/trunk/component/resources/src/main/java/org/exoplatform/services/resources/ExoResourceBundle.java 2010-08-16 03:50:59 UTC (rev 3830)
@@ -20,14 +20,10 @@
package org.exoplatform.services.resources;
import java.io.Serializable;
-import java.util.ArrayList;
import java.util.Enumeration;
-import java.util.List;
import java.util.ListResourceBundle;
import java.util.Map;
import java.util.ResourceBundle;
-import java.util.regex.Matcher;
-import java.util.regex.Pattern;
/**
* May 7, 2004
@@ -78,7 +74,7 @@
String key = keys.nextElement();
if (key != null)
{
- map.put(key, getString(key));
+ map.put(key.trim(), getString(key));
}
}
}
Copied: portal/trunk/component/resources/src/main/java/org/exoplatform/services/resources/LocaleContextInfo.java (from rev 3829, portal/branches/branched-r3776/component/resources/src/main/java/org/exoplatform/services/resources/LocaleContextInfo.java)
===================================================================
--- portal/trunk/component/resources/src/main/java/org/exoplatform/services/resources/LocaleContextInfo.java (rev 0)
+++ portal/trunk/component/resources/src/main/java/org/exoplatform/services/resources/LocaleContextInfo.java 2010-08-16 03:50:59 UTC (rev 3830)
@@ -0,0 +1,190 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2010, Red Hat, Inc., and individual contributors
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.exoplatform.services.resources;
+
+import java.util.List;
+import java.util.Locale;
+import java.util.Set;
+
+/**
+ * Data structure that holds the inputs for {@link LocalePolicy} pluggable policies mechanism.
+ *
+ * @author <a href="mailto:mstrukel@redhat.com">Marko Strukelj</a>
+ */
+public class LocaleContextInfo
+{
+ private Set<Locale> supportedLocales;
+ private List<Locale> browserLocales;
+ private List<Locale> cookieLocales;
+ private Locale userProfileLocale;
+ private String remoteUser;
+ private Locale portalLocale;
+
+ /**
+ * Setter for supportedLocales
+ * @param supportedLocales locales supported by portal
+ */
+ public void setSupportedLocales(Set<Locale> supportedLocales)
+ {
+ this.supportedLocales = supportedLocales;
+ }
+
+ /**
+ * Getter for supportedLocales
+ * @return supportedLocales
+ */
+ public Set<Locale> getSupportedLocales()
+ {
+ return supportedLocales;
+ }
+
+ /**
+ * Setter for browserLocales
+ * @param browserLocales list of locales as preferred by client's browser
+ */
+ public void setBrowserLocales(List<Locale> browserLocales)
+ {
+ this.browserLocales = browserLocales;
+ }
+
+ /**
+ * Getter for browserLocales
+ * @return browserLocales
+ */
+ public List<Locale> getBrowserLocales()
+ {
+ return browserLocales;
+ }
+
+ /**
+ * Setter for cookieLocales
+ * @param cookieLocales locales stored in user's browser cookie
+ */
+ public void setCookieLocales(List<Locale> cookieLocales)
+ {
+ this.cookieLocales = cookieLocales;
+ }
+
+ /**
+ * Getter for cookieLocales
+ * @return cookieLocales
+ */
+ public List<Locale> getCookieLocales()
+ {
+ return cookieLocales;
+ }
+
+ /**
+ * Setter for userProfileLocale
+ * @param userProfileLocale locale loaded from user's profile
+ */
+ public void setUserProfileLocale(Locale userProfileLocale)
+ {
+ this.userProfileLocale = userProfileLocale;
+ }
+
+ /**
+ * Getter for userProfileLocale
+ * @return userProfileLocale
+ */
+ public Locale getUserProfileLocale()
+ {
+ return userProfileLocale;
+ }
+
+ /**
+ * Setter for remoteUser
+ * @param remoteUser username of the currently logged in user. Null for anonymous users.
+ */
+ public void setRemoteUser(String remoteUser)
+ {
+ this.remoteUser = remoteUser;
+ }
+
+ /**
+ * Getter for remoteUser
+ * @return remoteUser
+ */
+ public String getRemoteUser()
+ {
+ return remoteUser;
+ }
+
+ /**
+ * Setter for portalLocale
+ * @param portalLocale default locale configured for the portal
+ */
+ public void setPortalLocale(Locale portalLocale)
+ {
+ this.portalLocale = portalLocale;
+ }
+
+ /**
+ * Getter for portalLocale
+ * @return portalLocale
+ */
+ public Locale getPortalLocale()
+ {
+ return portalLocale;
+ }
+
+ /**
+ * Helper method that returns the locale only if it's supported by portal.
+ * Otherwise it returns null.
+ *
+ * @param locale locale to check
+ * @return locale if supported, null otherwise
+ */
+ public Locale getLocaleIfSupported(Locale locale)
+ {
+ if (supportedLocales.contains(locale))
+ return locale;
+ return null;
+ }
+
+ /**
+ * Helper method to convert String representation of Locale into Locale object.
+ * @param portalLocaleName String representation of Locale
+ * @return locale
+ */
+ public static Locale getLocale(String portalLocaleName)
+ {
+ int pos = portalLocaleName.indexOf("_");
+ if (pos < 0)
+ return new Locale(portalLocaleName);
+
+ return new Locale(portalLocaleName.substring(0, pos), portalLocaleName.substring(pos+1));
+ }
+
+ /**
+ * Helper method to get a String representation of the Locale
+ * @param locale
+ * @return String representation of the locale
+ */
+ public static String getLocaleAsString(Locale locale)
+ {
+ if (locale.getCountry().length() == 0)
+ return locale.getLanguage();
+
+ return locale.getLanguage() + "_" + locale.getCountry();
+ }
+}
Copied: portal/trunk/component/resources/src/main/java/org/exoplatform/services/resources/LocalePolicy.java (from rev 3829, portal/branches/branched-r3776/component/resources/src/main/java/org/exoplatform/services/resources/LocalePolicy.java)
===================================================================
--- portal/trunk/component/resources/src/main/java/org/exoplatform/services/resources/LocalePolicy.java (rev 0)
+++ portal/trunk/component/resources/src/main/java/org/exoplatform/services/resources/LocalePolicy.java 2010-08-16 03:50:59 UTC (rev 3830)
@@ -0,0 +1,41 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2010, Red Hat, Inc., and individual contributors
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.exoplatform.services.resources;
+
+import java.util.Locale;
+
+/**
+ * This interface represents a pluggable mechanism for different locale determining algorithms
+ *
+ * @author <a href="mailto:mstrukel@redhat.com">Marko Strukelj</a>
+ */
+public interface LocalePolicy
+{
+ /**
+ * Determine the Locale to be used for current request
+ *
+ * @param localeContext locale context info available to implementations
+ * as inputs to use when determining appropriate Locale
+ * @return Locale to be used for current user's request
+ */
+ public Locale determineLocale(LocaleContextInfo localeContext);
+}
Copied: portal/trunk/component/web/controller/src/main/java/org/exoplatform/web/application/ApplicationRequestPhaseLifecycle.java (from rev 3829, portal/branches/branched-r3776/component/web/controller/src/main/java/org/exoplatform/web/application/ApplicationRequestPhaseLifecycle.java)
===================================================================
--- portal/trunk/component/web/controller/src/main/java/org/exoplatform/web/application/ApplicationRequestPhaseLifecycle.java (rev 0)
+++ portal/trunk/component/web/controller/src/main/java/org/exoplatform/web/application/ApplicationRequestPhaseLifecycle.java 2010-08-16 03:50:59 UTC (rev 3830)
@@ -0,0 +1,47 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2010, Red Hat, Inc., and individual contributors
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.exoplatform.web.application;
+
+/**
+ * Interface that extends {@link ApplicationLifecycle} with request phase methods that allow interception of
+ * before/after ACTION phase, and before/after RENDER phase of request processing.
+ *
+ * @author <a href="mailto:mstrukel@redhat.com">Marko Strukelj</a>
+ */
+public interface ApplicationRequestPhaseLifecycle<E extends RequestContext> extends ApplicationLifecycle<E>
+{
+ /**
+ * Perform any processing required at the beginning of {@link Phase#ACTION} or {@link Phase#RENDER} phase.
+ * @param app Application
+ * @param context current RequestContext
+ * @param phase starting phase
+ */
+ public void onStartRequestPhase(Application app, E context, Phase phase);
+
+ /**
+ * Perform any processing required at the end of {@link Phase#ACTION} or {@link Phase#RENDER} phase.
+ * @param app Application
+ * @param context current RequestContext
+ * @param phase ending phase
+ */
+ public void onEndRequestPhase(Application app, E context, Phase phase);
+}
Copied: portal/trunk/component/web/controller/src/main/java/org/exoplatform/web/application/Phase.java (from rev 3829, portal/branches/branched-r3776/component/web/controller/src/main/java/org/exoplatform/web/application/Phase.java)
===================================================================
--- portal/trunk/component/web/controller/src/main/java/org/exoplatform/web/application/Phase.java (rev 0)
+++ portal/trunk/component/web/controller/src/main/java/org/exoplatform/web/application/Phase.java 2010-08-16 03:50:59 UTC (rev 3830)
@@ -0,0 +1,33 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2010, Red Hat, Inc., and individual contributors
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.exoplatform.web.application;
+
+/**
+ * Enum representing request processing phases.
+ *
+ * @author <a href="mailto:mstrukel@redhat.com">Marko Strukelj</a>
+ */
+public enum Phase
+{
+ ACTION,
+ RENDER
+}
Modified: portal/trunk/component/web/resources/src/main/java/org/exoplatform/portal/resource/GateInSkinConfigRemoval.java
===================================================================
--- portal/trunk/component/web/resources/src/main/java/org/exoplatform/portal/resource/GateInSkinConfigRemoval.java 2010-08-13 17:09:39 UTC (rev 3829)
+++ portal/trunk/component/web/resources/src/main/java/org/exoplatform/portal/resource/GateInSkinConfigRemoval.java 2010-08-16 03:50:59 UTC (rev 3830)
@@ -21,6 +21,8 @@
import java.util.List;
import java.util.Set;
+import javax.servlet.ServletContext;
+
import org.gatein.wci.WebAppEvent;
import org.gatein.wci.WebAppLifeCycleEvent;
@@ -56,6 +58,7 @@
{
String webApp = event.getWebApp().getServletContext().getContextPath();
removeWebAppSkin(webApp);
+ removeContextAppSkin(event.getWebApp().getServletContext());
}
}
}
@@ -77,6 +80,11 @@
}
}
+ private void removeContextAppSkin(ServletContext servletContext)
+ {
+ service.unregisterServletContext(servletContext);
+ }
+
private void removePortalSkins(String webApp) throws Exception
{
List<SkinKey> portalSkins = SkinDependentManager.getPortalSkins(webApp);
Modified: portal/trunk/component/web/resources/src/main/java/org/exoplatform/portal/resource/MainResourceResolver.java
===================================================================
--- portal/trunk/component/web/resources/src/main/java/org/exoplatform/portal/resource/MainResourceResolver.java 2010-08-13 17:09:39 UTC (rev 3829)
+++ portal/trunk/component/web/resources/src/main/java/org/exoplatform/portal/resource/MainResourceResolver.java 2010-08-16 03:50:59 UTC (rev 3830)
@@ -57,6 +57,13 @@
resolvers.add(new CompositeResourceResolver(portalContainerName, skins));
}
+ /**
+ * Register a servlet request context
+ * <p>Append a servlet context to the map of contexts if servlet context name is not existing
+ *
+ * @param servletContext servlet context which want to append
+ * @return
+ */
SimpleResourceContext registerContext(ServletContext servletContext)
{
String key = "/" + servletContext.getServletContextName();
@@ -68,6 +75,25 @@
}
return ctx;
}
+
+ /**
+ * Remove a servlet context from map of contexts
+ *
+ * @param servletContext
+ */
+ public void removeServletContext(ServletContext servletContext)
+ {
+ String key = "/" + servletContext.getServletContextName();
+ SimpleResourceContext ctx = contexts.get(key);
+ if (ctx != null)
+ {
+ contexts.remove(ctx.getContextPath());
+ }
+ else {
+ log.warn("Cannot find servlet context module");
+ return;
+ }
+ }
public Resource resolve(String path)
{
Modified: portal/trunk/component/web/resources/src/main/java/org/exoplatform/portal/resource/SkinService.java
===================================================================
--- portal/trunk/component/web/resources/src/main/java/org/exoplatform/portal/resource/SkinService.java 2010-08-13 17:09:39 UTC (rev 3829)
+++ portal/trunk/component/web/resources/src/main/java/org/exoplatform/portal/resource/SkinService.java 2010-08-16 03:50:59 UTC (rev 3830)
@@ -799,6 +799,16 @@
{
mainResolver.registerContext(sContext);
}
+
+ /**
+ * unregister a {@link ServletContext} into {@link MainResourceResolver} of {@link SkinService}
+ *
+ * @param servletContext ServletContext will unregistered
+ */
+ public void unregisterServletContext(ServletContext servletContext)
+ {
+ mainResolver.removeServletContext(servletContext);
+ }
/**
* Clean cache, reload all Skins
Modified: portal/trunk/pom.xml
===================================================================
--- portal/trunk/pom.xml 2010-08-13 17:09:39 UTC (rev 3829)
+++ portal/trunk/pom.xml 2010-08-16 03:50:59 UTC (rev 3830)
@@ -47,7 +47,7 @@
<org.gatein.common.version>2.0.2-GA</org.gatein.common.version>
<org.gatein.wci.version>2.0.1-GA</org.gatein.wci.version>
<org.gatein.pc.version>2.1.1-GA</org.gatein.pc.version>
- <org.picketlink.idm>1.1.5.CR02</org.picketlink.idm>
+ <org.picketlink.idm>1.1.5.CR01</org.picketlink.idm>
<org.gatein.wsrp.version>1.1.1-GA</org.gatein.wsrp.version>
<org.gatein.mop.version>1.0.3-GA</org.gatein.mop.version>
<org.slf4j.version>1.5.6</org.slf4j.version>
Modified: portal/trunk/portlet/dashboard/src/main/java/org/exoplatform/dashboard/webui/component/UIDashboardPortlet.java
===================================================================
--- portal/trunk/portlet/dashboard/src/main/java/org/exoplatform/dashboard/webui/component/UIDashboardPortlet.java 2010-08-13 17:09:39 UTC (rev 3829)
+++ portal/trunk/portlet/dashboard/src/main/java/org/exoplatform/dashboard/webui/component/UIDashboardPortlet.java 2010-08-16 03:50:59 UTC (rev 3830)
@@ -98,12 +98,4 @@
return false;
}
- /**
- * For now returns null.
- */
- public String getDashboardOwner()
- {
- return null;
- }
-
}
Modified: portal/trunk/portlet/exoadmin/src/main/java/org/exoplatform/applicationregistry/webui/component/UIPortletManagement.java
===================================================================
--- portal/trunk/portlet/exoadmin/src/main/java/org/exoplatform/applicationregistry/webui/component/UIPortletManagement.java 2010-08-13 17:09:39 UTC (rev 3829)
+++ portal/trunk/portlet/exoadmin/src/main/java/org/exoplatform/applicationregistry/webui/component/UIPortletManagement.java 2010-08-16 03:50:59 UTC (rev 3830)
@@ -313,17 +313,38 @@
public String getDisplayName()
{
- return getMetaValue(MetaInfo.DISPLAY_NAME, name_);
+ try
+ {
+ return getMetaValue(MetaInfo.DISPLAY_NAME, name_);
+ }
+ catch (Exception ex)
+ {
+ return "COULD NOT GET DISPLAY NAME OF THE PORTLET";
+ }
}
public String getDescription()
{
- return getMetaValue(MetaInfo.DESCRIPTION, name_);
+ try
+ {
+ return getMetaValue(MetaInfo.DESCRIPTION, name_);
+ }
+ catch (Exception ex)
+ {
+ return "COULD NOT GET DESCRIPTION OF THE PORTLET";
+ }
}
public PreferencesInfo getPortletPreferences()
{
- return portletInfo_.getPreferences();
+ try
+ {
+ return portletInfo_.getPreferences();
+ }
+ catch (Exception ex)
+ {
+ return null;
+ }
}
private String getMetaValue(String metaKey, String defaultValue)
Modified: portal/trunk/portlet/exoadmin/src/main/java/org/exoplatform/organization/webui/component/UIUserInfo.java
===================================================================
--- portal/trunk/portlet/exoadmin/src/main/java/org/exoplatform/organization/webui/component/UIUserInfo.java 2010-08-13 17:09:39 UTC (rev 3829)
+++ portal/trunk/portlet/exoadmin/src/main/java/org/exoplatform/organization/webui/component/UIUserInfo.java 2010-08-16 03:50:59 UTC (rev 3830)
@@ -21,6 +21,7 @@
import org.exoplatform.commons.serialization.api.annotations.Serialized;
import org.exoplatform.portal.Constants;
+import org.exoplatform.portal.application.PortalRequestContext;
import org.exoplatform.portal.webui.util.Util;
import org.exoplatform.portal.webui.workspace.UIPortalApplication;
import org.exoplatform.portal.webui.workspace.UIWorkingWorkspace;
@@ -134,7 +135,8 @@
LocaleConfig localeConfig = localeConfigService.getLocaleConfig(language);
if (localeConfig == null)
localeConfig = localeConfigService.getDefaultLocaleConfig();
- uiApp.setLocale(localeConfig.getLocale());
+ PortalRequestContext prqCtx = PortalRequestContext.getCurrentInstance();
+ prqCtx.setLocale(localeConfig.getLocale());
uiApp.setOrientation(localeConfig.getOrientation());
uiApp.localizeNavigations();
Modified: portal/trunk/web/eXoResources/src/main/webapp/javascript/eXo/portal/PortalDragDrop.js
===================================================================
--- portal/trunk/web/eXoResources/src/main/webapp/javascript/eXo/portal/PortalDragDrop.js 2010-08-13 17:09:39 UTC (rev 3829)
+++ portal/trunk/web/eXoResources/src/main/webapp/javascript/eXo/portal/PortalDragDrop.js 2010-08-16 03:50:59 UTC (rev 3830)
@@ -32,6 +32,10 @@
*/
PortalDragDrop.prototype.init = function(e) {
+ if (eXo.core.DragDrop.dndEvent && eXo.core.DragDrop.dndEvent.clickObject == this){
+ return;
+ }
+
if (!e) e = window.event;
if(((e.which) && (e.which == 2 || e.which == 3)) || ((e.button) && (e.button == 2))) return;
@@ -194,7 +198,9 @@
this.origDragObjectStyle.setProperties(dndEvent.dragObject.style, false) ;
if(dndEvent.foundTargetObject != null || (dndEvent.backupMouseEvent && dndEvent.backupMouseEvent.keyCode != 27)) {
- eXo.portal.PortalDragDrop.doDropCallback(dndEvent) ;
+ if (dndEvent.foundTargetObject.foundIndex != null) {
+ eXo.portal.PortalDragDrop.doDropCallback(dndEvent) ;
+ }
} else {
if(dndEvent.dragObject.parentNode.nodeName.toLowerCase() == "td") {
dndEvent.dragObject.parentNode.style.width = "auto";
@@ -220,12 +226,6 @@
dndEvent.dragObject.style.width = "auto" ;
};
- DragDrop.cancelCallback = function(dndEvent) {
- if(Browser.browserType == "ie" && Browser.findMouseYInClient(dndEvent.backupMouseEvent) < 0) {
- DragDrop.onDrop(dndEvent.backupMouseEvent);
- }
- };
-
var clickObject = this;
var componentBlock = DOMUtil.findAncestorByClass(clickObject, "UIComponentBlock") ;
@@ -284,7 +284,7 @@
] ;
try {
- dndEvent.lastFoundTargetObject.foundIndex = -1;
+ dndEvent.lastFoundTargetObject.foundIndex = null;
} catch(err) {
}
Modified: portal/trunk/web/eXoResources/src/main/webapp/javascript/eXo/portal/UIPortal.js
===================================================================
--- portal/trunk/web/eXoResources/src/main/webapp/javascript/eXo/portal/UIPortal.js 2010-08-13 17:09:39 UTC (rev 3829)
+++ portal/trunk/web/eXoResources/src/main/webapp/javascript/eXo/portal/UIPortal.js 2010-08-16 03:50:59 UTC (rev 3830)
@@ -98,6 +98,56 @@
}
newLayer.parentNode.style.top = -height + "px";
editBlock.style.display = "block";
+
+ //resize width of portlet/container control if IE + LTR align BEGIN
+
+ var uiInfoBar = DOMUtil.findFirstDescendantByClass(editBlock, "div", "UIInfoBar");
+
+ if( uiInfoBar && (eXo.core.Browser.isIE6() || (eXo.core.Browser.isIE7() && eXo.core.I18n.isRT()))){
+ //resize width of portlet/container only one time
+ if(uiInfoBar.style.width == ""){
+ var dragControlArea = DOMUtil.findFirstDescendantByClass(uiInfoBar, "div", "DragControlArea");
+
+ var portletIcon = DOMUtil.findFirstDescendantByClass(uiInfoBar, "div", "PortletIcon");
+ var editPortletPropertiesIcon = DOMUtil.findFirstDescendantByClass(uiInfoBar, "a", "EditPortletPropertiesIcon");
+ var deletePortletIcon = DOMUtil.findFirstDescendantByClass(uiInfoBar, "a", "DeletePortletIcon");
+
+ var contarnerIcon = DOMUtil.findFirstDescendantByClass(uiInfoBar, "div", "ContainerIcon");
+ var editContainerIcon = DOMUtil.findFirstDescendantByClass(uiInfoBar, "a", "EditContainerIcon");
+ var deleteContainerIcon = DOMUtil.findFirstDescendantByClass(uiInfoBar, "a", "DeleteContainerIcon");
+
+ var uiInfoBarWidth = dragControlArea.offsetWidth;
+
+ if(DOMUtil.hasClass(portlet, "UIPortlet")){
+ uiInfoBarWidth += portletIcon.offsetWidth;
+
+ if(editPortletPropertiesIcon){
+ uiInfoBarWidth += editPortletPropertiesIcon.offsetWidth;
+ }
+
+ if(deletePortletIcon){
+ uiInfoBarWidth += deletePortletIcon.offsetWidth;
+ }
+ }
+
+ if(DOMUtil.hasClass(portlet, "UIContainer")){
+ uiInfoBarWidth += contarnerIcon.offsetWidth
+
+ if(editContainerIcon){
+ uiInfoBarWidth += editContainerIcon.offsetWidth;
+ }
+
+ if(deleteContainerIcon){
+ uiInfoBarWidth += deleteContainerIcon.offsetWidth;
+ }
+ }
+
+ uiInfoBar.style.width= uiInfoBarWidth + 35 + "px";
+ }
+
+ }
+ //resize width of portlet/container control if IE + LTR align END
+
} else {
editBlock.style.display = "none";
if(!DOMUtil.hasClass(portlet, "UIPortlet")) {
Modified: portal/trunk/web/eXoResources/src/main/webapp/javascript/eXo/portal/UIPortalControl.js
===================================================================
--- portal/trunk/web/eXoResources/src/main/webapp/javascript/eXo/portal/UIPortalControl.js 2010-08-13 17:09:39 UTC (rev 3829)
+++ portal/trunk/web/eXoResources/src/main/webapp/javascript/eXo/portal/UIPortalControl.js 2010-08-16 03:50:59 UTC (rev 3830)
@@ -58,21 +58,31 @@
}
};
-UIPortalControl.prototype.onEnterPress = function(e) {
- var e = window.event || e;
- var uiPortalLoginFormAction = document.getElementById("UIPortalLoginFormAction");
- if(uiPortalLoginFormAction) {
- var code;
- if(!e) e = window.event;
- if(e.keyCode) code = e.keyCode;
- else if (e.which) code = e.which;
- if(code ==13) {
- if(this.t != 13) {
- uiPortalLoginFormAction.onclick() ;
- }
- this.t = code;
- }
- }
+/**
+ * Process enter key press
+ * @param {Event} e this event
+ * @param {String} executeScript javascript command to execute if enter key was pressed
+ */
+UIPortalControl.prototype.onEnterPress = function(e, executeScript) {
+ var e = window.event || e;
+ var code;
+ if(!e) e = window.event;
+ if(e.keyCode) code = e.keyCode;
+ else if (e.which) code = e.which;
+ if(code ==13) {
+ if(this.t != 13) {
+ var uiPortalLoginFormAction = document.getElementById("UIPortalLoginFormAction");
+ if(uiPortalLoginFormAction) {
+ uiPortalLoginFormAction.onclick() ;
+ }
+ else
+ {
+ if(executeScript)
+ eval(executeScript);
+ }
+ }
+ this.t = code;
+ }
};
/*********** Scroll Manager *************/
Modified: portal/trunk/web/eXoResources/src/main/webapp/skin/DefaultSkin/webui/component/UITree/Stylesheet.css
===================================================================
--- portal/trunk/web/eXoResources/src/main/webapp/skin/DefaultSkin/webui/component/UITree/Stylesheet.css 2010-08-13 17:09:39 UTC (rev 3829)
+++ portal/trunk/web/eXoResources/src/main/webapp/skin/DefaultSkin/webui/component/UITree/Stylesheet.css 2010-08-16 03:50:59 UTC (rev 3830)
@@ -52,7 +52,7 @@
}
.UITrees .Node {
- line-height: 18px;
+ line-height: 19px;
padding-top: 7px;
margin-left: 15px; /* orientation=lt */
margin-right: 15px; /* orientation=rt */
@@ -97,6 +97,15 @@
font-weight: bold;
color: #058ee6;
cursor: pointer;
+}
+
+.UITrees .Node .NullItemIcon {
+ padding-left: 18px; /* orientation=lt */
+ padding-right: 18px; /* orientation=rt */
+ background: url('background/NullItemIcon.gif') no-repeat 6px top; /* orientation=lt */
+ background: url('background/NullItemIcon-rt.gif') no-repeat 98.5% top; /* orientation=rt */
+ -webkit-background: url('background/NullItemIcon-rt.gif') no-repeat 98.2% top; /* orientation=rt */
+ width: 100%; height: auto;
}
/** ################# Icons ###################*/
Modified: portal/trunk/web/eXoResources/src/main/webapp/skin/DefaultSkin/webui/component/UITree/background/Dotted.gif
===================================================================
(Binary files differ)
Copied: portal/trunk/web/eXoResources/src/main/webapp/skin/DefaultSkin/webui/component/UITree/background/NullItemIcon.gif (from rev 3829, portal/branches/branched-r3776/web/eXoResources/src/main/webapp/skin/DefaultSkin/webui/component/UITree/background/NullItemIcon.gif)
===================================================================
(Binary files differ)
Modified: portal/trunk/web/portal/src/main/webapp/WEB-INF/web.xml
===================================================================
--- portal/trunk/web/portal/src/main/webapp/WEB-INF/web.xml 2010-08-13 17:09:39 UTC (rev 3829)
+++ portal/trunk/web/portal/src/main/webapp/WEB-INF/web.xml 2010-08-16 03:50:59 UTC (rev 3830)
@@ -1,19 +1,19 @@
-<?xml version="1.0" encoding="ISO-8859-1" ?>
+<?xml version="1.0" encoding="ISO-8859-1" ?>
<!--
Copyright (C) 2009 eXo Platform SAS.
-
+
This is free software; you can redistribute it and/or modify it
under the terms of the GNU Lesser General Public License as
published by the Free Software Foundation; either version 2.1 of
the License, or (at your option) any later version.
-
+
This software is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
-
+
You should have received a copy of the GNU Lesser General Public
License along with this software; if not, write to the Free
Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
@@ -21,9 +21,11 @@
-->
-<!DOCTYPE web-app PUBLIC "-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN"
- "http://java.sun.com/dtd/web-app_2_3.dtd">
-<web-app>
+<web-app xmlns="http://java.sun.com/xml/ns/j2ee"
+ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee
+ http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd"
+ version="2.4">
<display-name>portal</display-name>
<!--Uncomment for clustered setup-->
@@ -34,31 +36,33 @@
<context-param>
<param-name>org.exoplatform.frameworks.jcr.command.web.fckeditor.digitalAssetsWorkspace</param-name>
<param-value>portal</param-value>
- <description>Binary assets workspace name</description>
</context-param>
<context-param>
<param-name>org.exoplatform.frameworks.jcr.command.web.fckeditor.digitalAssetsPath</param-name>
<param-value>/</param-value>
- <description>Binary assets path</description>
</context-param>
-
+
<!-- ================================================================== -->
<!-- RESOURCE FILTER TO CACHE MERGED JAVASCRIPT AND CSS -->
<!-- ================================================================== -->
+ <filter>
+ <filter-name>LocalizationFilter</filter-name>
+ <filter-class>org.exoplatform.portal.application.localization.LocalizationFilter</filter-class>
+ </filter>
<filter>
<filter-name>GenericFilter</filter-name>
<filter-class>org.exoplatform.web.filter.GenericFilter</filter-class>
</filter>
<filter>
- <filter-name>ResourceRequestFilter</filter-name>
- <filter-class>org.exoplatform.portal.application.ResourceRequestFilter</filter-class>
+ <filter-name>ResourceRequestFilter</filter-name>
+ <filter-class>org.exoplatform.portal.application.ResourceRequestFilter</filter-class>
</filter>
-
+
<filter>
<filter-name>ThreadLocalSessionProviderInitializedFilter</filter-name>
<filter-class>org.exoplatform.frameworks.jcr.web.ThreadLocalSessionProviderInitializedFilter</filter-class>
- </filter>
+ </filter>
<filter>
<filter-name>SetCurrentIdentityFilter</filter-name>
@@ -66,17 +70,17 @@
</filter>
-
- <filter>
- <filter-name>RestEncodingFilter</filter-name>
- <filter-class>org.exoplatform.services.rest.servlet.RestEncodingFilter</filter-class>
- <init-param>
- <param-name>REQUEST_ENCODING</param-name>
- <param-value>UTF-8</param-value>
- </init-param>
- </filter>
<filter>
+ <filter-name>RestEncodingFilter</filter-name>
+ <filter-class>org.exoplatform.services.rest.servlet.RestEncodingFilter</filter-class>
+ <init-param>
+ <param-name>REQUEST_ENCODING</param-name>
+ <param-value>UTF-8</param-value>
+ </init-param>
+ </filter>
+
+ <filter>
<filter-name>CacheUserProfileFilter</filter-name>
<filter-class>org.exoplatform.web.CacheUserProfileFilter</filter-class>
</filter>
@@ -101,6 +105,15 @@
<url-pattern>/*</url-pattern>
</filter-mapping>
+ <filter-mapping>
+ <filter-name>LocalizationFilter</filter-name>
+ <url-pattern>/*</url-pattern>
+ <dispatcher>INCLUDE</dispatcher>
+ <dispatcher>FORWARD</dispatcher>
+ <dispatcher>REQUEST</dispatcher>
+ <dispatcher>ERROR</dispatcher>
+ </filter-mapping>
+
<filter-mapping>
<filter-name>GenericFilter</filter-name>
<url-pattern>/*</url-pattern>
@@ -108,29 +121,29 @@
<filter-mapping>
<filter-name>ResourceRequestFilter</filter-name>
- <url-pattern>*.css</url-pattern>
+ <url-pattern>*.css</url-pattern>
</filter-mapping>
-
+
<filter-mapping>
<filter-name>ResourceRequestFilter</filter-name>
- <url-pattern>*.gif</url-pattern>
+ <url-pattern>*.gif</url-pattern>
</filter-mapping>
<filter-mapping>
<filter-name>ResourceRequestFilter</filter-name>
- <url-pattern>*.png</url-pattern>
+ <url-pattern>*.png</url-pattern>
</filter-mapping>
<filter-mapping>
<filter-name>ResourceRequestFilter</filter-name>
- <url-pattern>*.jpg</url-pattern>
+ <url-pattern>*.jpg</url-pattern>
</filter-mapping>
<filter-mapping>
- <filter-name>ResourceRequestFilter</filter-name>
- <url-pattern>/javascript/*</url-pattern>
+ <filter-name>ResourceRequestFilter</filter-name>
+ <url-pattern>/javascript/*</url-pattern>
</filter-mapping>
-
+
<filter-mapping>
<filter-name>SetCurrentIdentityFilter</filter-name>
<url-pattern>/*</url-pattern>
@@ -140,12 +153,12 @@
<filter-name>ThreadLocalSessionProviderInitializedFilter</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
-
+
<filter-mapping>
<filter-name>CacheUserProfileFilter</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
-
+
<filter-mapping>
<filter-name>RestEncodingFilter</filter-name>
<url-pattern>/rest/*</url-pattern>
@@ -158,36 +171,35 @@
<listener-class>org.exoplatform.web.GenericHttpListener</listener-class>
</listener>
<listener>
- <listener-class>org.exoplatform.portal.application.PortalSessionListener</listener-class>
+ <listener-class>org.exoplatform.portal.application.PortalSessionListener</listener-class>
</listener>
<listener>
<listener-class>org.exoplatform.services.security.web.JAASConversationStateListener</listener-class>
- </listener>
+ </listener>
<!-- ================================================================== -->
<!-- SERVLET -->
- <!-- ================================================================== -->
+ <!-- ================================================================== -->
<servlet>
- <servlet-name>portal</servlet-name>
- <servlet-class>org.exoplatform.portal.application.PortalController</servlet-class>
+ <servlet-name>portal</servlet-name>
+ <servlet-class>org.exoplatform.portal.application.PortalController</servlet-class>
<init-param>
- <param-name>webui.configuration</param-name>
- <param-value>app:/WEB-INF/webui-configuration.xml</param-value>
+ <param-name>webui.configuration</param-name>
+ <param-value>app:/WEB-INF/webui-configuration.xml</param-value>
</init-param>
- <load-on-startup>1</load-on-startup>
+ <load-on-startup>1</load-on-startup>
</servlet>
-
+
<servlet>
<servlet-name>RestServer</servlet-name>
- <description>eXo - Platform REST Server</description>
<servlet-class>org.exoplatform.services.rest.servlet.RestServlet</servlet-class>
<load-on-startup>4</load-on-startup>
</servlet>
-
+
<servlet>
- <servlet-name>javascript</servlet-name>
- <servlet-class>org.exoplatform.portal.webui.javascript.JavascriptServlet</servlet-class>
+ <servlet-name>javascript</servlet-name>
+ <servlet-class>org.exoplatform.portal.webui.javascript.JavascriptServlet</servlet-class>
</servlet>
-
+
<servlet>
<servlet-name>Controller</servlet-name>
<servlet-class>org.exoplatform.frameworks.jcr.web.CommandControllerServlet</servlet-class>
@@ -232,114 +244,114 @@
</servlet-mapping>
- <!-- ================================================================= -->
+ <!-- ================================================================= -->
<servlet-mapping>
- <servlet-name>InitiateLoginServlet</servlet-name>
- <url-pattern>/initiatelogin</url-pattern>
+ <servlet-name>InitiateLoginServlet</servlet-name>
+ <url-pattern>/initiatelogin</url-pattern>
</servlet-mapping>
<servlet-mapping>
<servlet-name>ErrorLoginServlet</servlet-name>
<url-pattern>/errorlogin</url-pattern>
</servlet-mapping>
<servlet-mapping>
- <servlet-name>PortalLoginController</servlet-name>
- <url-pattern>/login</url-pattern>
+ <servlet-name>PortalLoginController</servlet-name>
+ <url-pattern>/login</url-pattern>
</servlet-mapping>
<servlet-mapping>
- <servlet-name>javascript</servlet-name>
- <url-pattern>/javascript/*</url-pattern>
+ <servlet-name>javascript</servlet-name>
+ <url-pattern>/javascript/*</url-pattern>
</servlet-mapping>
<servlet-mapping>
- <servlet-name>portal</servlet-name>
- <url-pattern>/private/*</url-pattern>
+ <servlet-name>portal</servlet-name>
+ <url-pattern>/private/*</url-pattern>
</servlet-mapping>
<servlet-mapping>
- <servlet-name>portal</servlet-name>
- <url-pattern>/public/*</url-pattern>
+ <servlet-name>portal</servlet-name>
+ <url-pattern>/public/*</url-pattern>
</servlet-mapping>
<servlet-mapping>
- <servlet-name>portal</servlet-name>
- <url-pattern>/admin/*</url-pattern>
+ <servlet-name>portal</servlet-name>
+ <url-pattern>/admin/*</url-pattern>
</servlet-mapping>
<servlet-mapping>
- <servlet-name>portal</servlet-name>
- <url-pattern>/service</url-pattern>
+ <servlet-name>portal</servlet-name>
+ <url-pattern>/service</url-pattern>
</servlet-mapping>
<servlet-mapping>
- <servlet-name>portal</servlet-name>
- <url-pattern>/upload/*</url-pattern>
+ <servlet-name>portal</servlet-name>
+ <url-pattern>/upload/*</url-pattern>
</servlet-mapping>
<servlet-mapping>
- <servlet-name>portal</servlet-name>
- <url-pattern>/download/*</url-pattern>
+ <servlet-name>portal</servlet-name>
+ <url-pattern>/download/*</url-pattern>
</servlet-mapping>
<servlet-mapping>
<servlet-name>RestServer</servlet-name>
<url-pattern>/rest/*</url-pattern>
</servlet-mapping>
-
+
<servlet-mapping>
<servlet-name>Controller</servlet-name>
<url-pattern>/connector</url-pattern>
- </servlet-mapping>
-
+ </servlet-mapping>
+
<servlet-mapping>
<servlet-name>GateInServlet</servlet-name>
<url-pattern>/gateinservlet</url-pattern>
</servlet-mapping>
<session-config>
- <session-timeout>30</session-timeout>
+ <session-timeout>30</session-timeout>
</session-config>
<!-- The Welcome File List for IBM WebSphere -->
-
+
<welcome-file-list>
<welcome-file>/index.jsp</welcome-file>
</welcome-file-list>
-
+
<security-constraint>
<web-resource-collection>
- <web-resource-name>user authentication</web-resource-name>
- <url-pattern>/private/*</url-pattern>
- <http-method>POST</http-method>
- <http-method>GET</http-method>
+ <web-resource-name>user authentication</web-resource-name>
+ <url-pattern>/private/*</url-pattern>
+ <http-method>POST</http-method>
+ <http-method>GET</http-method>
</web-resource-collection>
<auth-constraint>
- <role-name>users</role-name>
+ <role-name>users</role-name>
</auth-constraint>
<user-data-constraint>
- <transport-guarantee>NONE</transport-guarantee>
+ <transport-guarantee>NONE</transport-guarantee>
</user-data-constraint>
</security-constraint>
<security-constraint>
<web-resource-collection>
- <web-resource-name>admin authentication</web-resource-name>
- <url-pattern>/admin/*</url-pattern>
- <http-method>POST</http-method>
- <http-method>GET</http-method>
+ <web-resource-name>admin authentication</web-resource-name>
+ <url-pattern>/admin/*</url-pattern>
+ <http-method>POST</http-method>
+ <http-method>GET</http-method>
</web-resource-collection>
<auth-constraint>
- <role-name>admin</role-name>
+ <role-name>admin</role-name>
</auth-constraint>
<user-data-constraint>
- <transport-guarantee>NONE</transport-guarantee>
+ <transport-guarantee>NONE</transport-guarantee>
</user-data-constraint>
</security-constraint>
<login-config>
- <auth-method>FORM</auth-method>
- <realm-name>gatein-domain</realm-name>
+ <auth-method>FORM</auth-method>
+ <realm-name>gatein-domain</realm-name>
<form-login-config>
- <form-login-page>/initiatelogin</form-login-page>
+ <form-login-page>/initiatelogin</form-login-page>
<form-error-page>/errorlogin</form-error-page>
</form-login-config>
</login-config>
<security-role>
- <description>a simple user role</description>
- <role-name>users</role-name>
+ <description>a simple user role</description>
+ <role-name>users</role-name>
</security-role>
<security-role>
<description>the admin role</description>
- <role-name>admin</role-name>
+ <role-name>admin</role-name>
</security-role>
</web-app>
Modified: portal/trunk/web/portal/src/main/webapp/WEB-INF/webui-configuration.xml
===================================================================
--- portal/trunk/web/portal/src/main/webapp/WEB-INF/webui-configuration.xml 2010-08-13 17:09:39 UTC (rev 3829)
+++ portal/trunk/web/portal/src/main/webapp/WEB-INF/webui-configuration.xml 2010-08-16 03:50:59 UTC (rev 3830)
@@ -38,6 +38,7 @@
<listener>org.exoplatform.webui.application.MonitorApplicationLifecycle</listener>
<listener>org.exoplatform.portal.application.UserProfileLifecycle</listener>
<listener>org.exoplatform.portal.application.concurrent.PortalConcurrencyMonitorLifecycle</listener>
+ <listener>org.exoplatform.portal.application.localization.LocalizationLifecycle</listener>
</application-lifecycle-listeners>
<events>
Modified: portal/trunk/web/portal/src/main/webapp/groovy/portal/webui/application/UIPortlet.gtmpl
===================================================================
--- portal/trunk/web/portal/src/main/webapp/groovy/portal/webui/application/UIPortlet.gtmpl 2010-08-13 17:09:39 UTC (rev 3829)
+++ portal/trunk/web/portal/src/main/webapp/groovy/portal/webui/application/UIPortlet.gtmpl 2010-08-16 03:50:59 UTC (rev 3830)
@@ -37,12 +37,14 @@
<div class="FixHeight">
<%
if(hasPermission) {
- try {
- String portletName = uicomponent.getProducedOfferedPortlet().getInfo().getName();
- print _ctx.getRequestContext().getApplicationResourceBundle().getString("UIPortlet.description." + portletName);
- } catch(Exception e){
- print uicomponent.getDisplayName();
- }
+ if(portletTitle == null || portletTitle.trim().length() < 1) {
+ try {
+ String portletName = uicomponent.getProducedOfferedPortlet().getInfo().getName();
+ print _ctx.getRequestContext().getApplicationResourceBundle().getString("UIPortlet.description." + portletName);
+ } catch(Exception e){
+ print uicomponent.getDisplayName();
+ }
+ } else print portletTitle;
} else print "<div class='ProtectedContent'>"+_ctx.appRes("UIPortlet.label.protectedContent")+"</div>";
%>
</div>
@@ -60,10 +62,12 @@
if(portalMode != uiPortalApp.CONTAINER_BLOCK_EDIT_MODE && portalMode != uiPortalApp.APP_BLOCK_EDIT_MODE) {
if(uicomponent.getShowInfoBar()) {
- String title = uicomponent.getTitle();
- if(title == null || title.trim().length() < 1)
+ String title = portletTitle;
+ if(title == null || title.trim().length() < 1)
+ title = uicomponent.getTitle();
+ if(title == null || title.trim().length() < 1)
title = uicomponent.getDisplayName();
- if(title == null || title.trim().length() < 1)
+ if(title == null || title.trim().length() < 1)
title = portletId;
/*Begin Window Portlet Bar*/
String visibility = "visible";
@@ -288,7 +292,9 @@
String portletIcon = uicomponent.getIcon();
if(portletIcon == null) portletIcon = "PortletIcon";
- String title = uicomponent.getDisplayTitle();
+ String title = portletTitle;
+ if(title == null || title.trim().length() < 1)
+ title = uicomponent.getDisplayTitle();
if(title.length() > 30) title = title.substring(0,27) + "...";
%>
<div class="PortletIcon $portletIcon"><%=hasPermission ? title : _ctx.appRes("UIPortlet.label.protectedContent")%></div>
Modified: portal/trunk/web/portal/src/main/webapp/groovy/webui/form/UISearchForm.gtmpl
===================================================================
--- portal/trunk/web/portal/src/main/webapp/groovy/webui/form/UISearchForm.gtmpl 2010-08-13 17:09:39 UTC (rev 3829)
+++ portal/trunk/web/portal/src/main/webapp/groovy/webui/form/UISearchForm.gtmpl 2010-08-16 03:50:59 UTC (rev 3830)
@@ -6,19 +6,21 @@
<div class="MiddleBar">
<div class="UISearchForm">
<%uiform.begin()%>
- <div class="QuickSet">
+ <%String quickSearchlink = uicomponent.event("QuickSearch") ;%>
+ <script type="text/javascript">
+ var executeScript = "<%=quickSearchlink%>";
+ </script>
+ <div class="QuickSet" onkeypress="eXo.portal.UIPortalControl.onEnterPress(event, executeScript)">
<div class="SearchTitle"><%=_ctx.appRes("UISearch.label.Search")%>:</div>
<%
QuickSearchInputSet = uiform.getQuickSearchInputSet();
for(field in QuickSearchInputSet.getChildren()) {
uiform.renderField(field)
}
- String quickSearchlink = uicomponent.event("QuickSearch");
%>
<a class="SimpleSearchIcon" href="$quickSearchlink" title="<%= _ctx.appRes("UISearch.label.QuickSearch") %>">
<span></span>
</a>
-
</div>
<%uiform.end()%>
</div>
Modified: portal/trunk/webui/core/src/main/java/org/exoplatform/webui/core/UITree.java
===================================================================
--- portal/trunk/webui/core/src/main/java/org/exoplatform/webui/core/UITree.java 2010-08-13 17:09:39 UTC (rev 3829)
+++ portal/trunk/webui/core/src/main/java/org/exoplatform/webui/core/UITree.java 2010-08-16 03:50:59 UTC (rev 3830)
@@ -19,6 +19,7 @@
package org.exoplatform.webui.core;
+import org.exoplatform.portal.config.model.PageNode;
import org.exoplatform.util.ReflectionUtil;
import org.exoplatform.webui.application.WebuiRequestContext;
import org.exoplatform.commons.serialization.api.annotations.Serialized;
@@ -53,6 +54,11 @@
* The css class name to show the collapse icon
*/
private String colapseIcon = "CollapseIcon";
+
+ /**
+ * The css class name to show the null icon (item has no child)
+ */
+ private String nullItemIcon = "NullItemIcon";
/**
* The css class name to show the selected icon
@@ -265,6 +271,9 @@
iconGroup = selectedIcon;
note = " NodeSelected";
}
+ if(obj instanceof PageNode && ((PageNode)obj).getChildren().size() == 0) {
+ nodeIcon = nullItemIcon;
+ }
if (beanIconField_ != null && beanIconField_.length() > 0)
{
if (getFieldValue(obj, beanIconField_) != null)
@@ -284,11 +293,14 @@
{
builder.append(" <div class=\"").append(nodeIcon).append("\" onclick=\"").append(actionLink).append("\">");
}
- else
+ else if (nodeIcon.equals(colapseIcon))
{
builder.append(" <div class=\"").append(nodeIcon).append(
"\" onclick=\"eXo.portal.UIPortalControl.collapseTree(this)").append("\">");
}
+ else {//Null item
+ builder.append(" <div class=\"").append(nodeIcon).append("\">");
+ }
if (uiPopupMenu_ == null)
{
builder.append(" <a href=\"javascript:void(0);\" class=\"NodeIcon ").append(iconGroup).append(note).append(
Modified: portal/trunk/webui/core/src/main/java/org/exoplatform/webui/form/validator/DateTimeValidator.java
===================================================================
--- portal/trunk/webui/core/src/main/java/org/exoplatform/webui/form/validator/DateTimeValidator.java 2010-08-13 17:09:39 UTC (rev 3829)
+++ portal/trunk/webui/core/src/main/java/org/exoplatform/webui/form/validator/DateTimeValidator.java 2010-08-16 03:50:59 UTC (rev 3830)
@@ -73,17 +73,16 @@
{
// Specify whether or not date/time parsing is to be lenient.
sdf.setLenient(false);
- Date stDate = sdf.parse(s);
- s = stFormat.format(stDate);
+ sdf.parse(s);
}
catch (Exception e)
{
- throw new MessageException(new ApplicationMessage("DateTimeValidator.msg.Invalid-input", args));
+ throw new MessageException(new ApplicationMessage("DateTimeValidator.msg.Invalid-input", args, ApplicationMessage.WARNING));
}
if (s.matches(DATETIME_REGEX) && isValidDateTime(s))
return;
- throw new MessageException(new ApplicationMessage("DateTimeValidator.msg.Invalid-input", args));
+ throw new MessageException(new ApplicationMessage("DateTimeValidator.msg.Invalid-input", args, ApplicationMessage.WARNING));
}
private boolean isValidDateTime(String dateTime)
Modified: portal/trunk/webui/dashboard/src/main/java/org/exoplatform/dashboard/webui/component/DashboardParent.java
===================================================================
--- portal/trunk/webui/dashboard/src/main/java/org/exoplatform/dashboard/webui/component/DashboardParent.java 2010-08-13 17:09:39 UTC (rev 3829)
+++ portal/trunk/webui/dashboard/src/main/java/org/exoplatform/dashboard/webui/component/DashboardParent.java 2010-08-16 03:50:59 UTC (rev 3830)
@@ -21,11 +21,5 @@
public interface DashboardParent
{
- public static final String ISPRIVATE = "isPrivate";
-
- public static final String OWNER = "owner";
-
- String getDashboardOwner();
-
boolean canEdit();
}
Modified: portal/trunk/webui/dashboard/src/main/java/org/exoplatform/dashboard/webui/component/UIDashboardEditForm.java
===================================================================
--- portal/trunk/webui/dashboard/src/main/java/org/exoplatform/dashboard/webui/component/UIDashboardEditForm.java 2010-08-13 17:09:39 UTC (rev 3829)
+++ portal/trunk/webui/dashboard/src/main/java/org/exoplatform/dashboard/webui/component/UIDashboardEditForm.java 2010-08-16 03:50:59 UTC (rev 3830)
@@ -49,20 +49,13 @@
public UIDashboardEditForm() throws Exception
{
- PortletRequestContext pcontext = (PortletRequestContext)WebuiRequestContext.getCurrentInstance();
- PortletPreferences pref = pcontext.getRequest().getPreferences();
addUIFormInput(new UIFormStringInput(TOTAL_COLUMNS, TOTAL_COLUMNS, null));
- addUIFormInput(new UIFormStringInput(DashboardParent.OWNER, DashboardParent.OWNER, pref.getValue(
- DashboardParent.OWNER, null)));
- addUIFormInput(new UIFormStringInput(DashboardParent.ISPRIVATE, DashboardParent.ISPRIVATE, pref.getValue(
- DashboardParent.ISPRIVATE, null)));
}
public static class SaveActionListener extends EventListener<UIDashboardEditForm>
{
public final void execute(final Event<UIDashboardEditForm> event) throws Exception
{
-
UIDashboardEditForm uiForm = event.getSource();
UIFormStringInput uiInput = uiForm.getUIStringInput(TOTAL_COLUMNS);
@@ -101,12 +94,6 @@
throw new MessageException(new ApplicationMessage("NumberFormatValidator.msg.Invalid-number", args));
}
- uiInput = uiForm.getUIStringInput(DashboardParent.ISPRIVATE);
- pref.setValue(DashboardParent.ISPRIVATE, uiInput.getValue());
-
- uiInput = uiForm.getUIStringInput(DashboardParent.OWNER);
- pref.setValue(DashboardParent.OWNER, uiInput.getValue());
-
UIDashboardContainer uiDashboardContainer =
((UIContainer)uiForm.getParent()).getChild(UIDashboard.class).getChild(UIDashboardContainer.class);
uiDashboardContainer.setColumns(totalCols);
Modified: portal/trunk/webui/portal/src/main/java/conf/portal/configuration.xml
===================================================================
--- portal/trunk/webui/portal/src/main/java/conf/portal/configuration.xml 2010-08-13 17:09:39 UTC (rev 3829)
+++ portal/trunk/webui/portal/src/main/java/conf/portal/configuration.xml 2010-08-16 03:50:59 UTC (rev 3830)
@@ -30,5 +30,11 @@
<component>
<type>org.exoplatform.portal.application.PortalStatisticService</type>
- </component>
+ </component>
+
+ <component>
+ <key>org.exoplatform.services.resources.LocalePolicy</key>
+ <!--type>org.exoplatform.portal.application.NoBrowserLocalePolicyService</type-->
+ <type>org.exoplatform.portal.application.localization.DefaultLocalePolicyService</type>
+ </component>
</configuration>
Modified: portal/trunk/webui/portal/src/main/java/org/exoplatform/portal/application/PortalRequestContext.java
===================================================================
--- portal/trunk/webui/portal/src/main/java/org/exoplatform/portal/application/PortalRequestContext.java 2010-08-13 17:09:39 UTC (rev 3829)
+++ portal/trunk/webui/portal/src/main/java/org/exoplatform/portal/application/PortalRequestContext.java 2010-08-16 03:50:59 UTC (rev 3830)
@@ -116,6 +116,8 @@
private Map<String, String[]> parameterMap;
+ private Locale locale = Locale.ENGLISH;
+
public JavascriptManager getJavascriptManager()
{
return jsmanager_;
@@ -169,12 +171,10 @@
// Reconstructing the getPathInfo from the non server decoded values.
String servletPath = URLDecoder.decode(req.getServletPath(), "UTF-8");
String contextPath = URLDecoder.decode(req.getContextPath(), "UTF-8");
- String pathInfo = requestURI_.substring((servletPath + contextPath).length());
+ String pathInfo = "/";
+ if (requestURI_.length() > servletPath.length() + contextPath.length())
+ pathInfo = requestURI_.substring(servletPath.length() + contextPath.length());
- if (pathInfo == null || pathInfo.length() == 0)
- {
- pathInfo = "/";
- }
int colonIndex = pathInfo.indexOf("/", 1);
if (colonIndex < 0)
{
@@ -241,9 +241,14 @@
return ((UIPortalApplication)uiApplication_).getOrientation();
}
+ public void setLocale(Locale locale)
+ {
+ this.locale = locale;
+ }
+
public Locale getLocale()
{
- return ((UIPortalApplication)uiApplication_).getLocale();
+ return locale;
}
@SuppressWarnings("unchecked")
Modified: portal/trunk/webui/portal/src/main/java/org/exoplatform/portal/application/PortalRequestHandler.java
===================================================================
--- portal/trunk/webui/portal/src/main/java/org/exoplatform/portal/application/PortalRequestHandler.java 2010-08-13 17:09:39 UTC (rev 3829)
+++ portal/trunk/webui/portal/src/main/java/org/exoplatform/portal/application/PortalRequestHandler.java 2010-08-16 03:50:59 UTC (rev 3830)
@@ -26,6 +26,8 @@
import org.exoplatform.web.WebAppController;
import org.exoplatform.web.WebRequestHandler;
import org.exoplatform.web.application.ApplicationLifecycle;
+import org.exoplatform.web.application.ApplicationRequestPhaseLifecycle;
+import org.exoplatform.web.application.Phase;
import org.exoplatform.web.application.RequestFailure;
import org.exoplatform.webui.application.WebuiRequestContext;
import org.exoplatform.webui.core.UIApplication;
@@ -104,11 +106,17 @@
if (!context.isResponseComplete() && !context.getProcessRender())
{
+ startRequestPhaseLifecycle(app, context, lifecycles, Phase.ACTION);
uiApp.processAction(context);
+ endRequestPhaseLifecycle(app, context, lifecycles, Phase.ACTION);
}
if (!context.isResponseComplete())
+ {
+ startRequestPhaseLifecycle(app, context, lifecycles, Phase.RENDER);
uiApp.processRender(context);
+ endRequestPhaseLifecycle(app, context, lifecycles, Phase.RENDER);
+ }
if (uiApp != null)
uiApp.setLastAccessApplication(System.currentTimeMillis());
@@ -149,4 +157,25 @@
WebuiRequestContext.setCurrentInstance(null);
}
}
+
+ private void startRequestPhaseLifecycle(PortalApplication app, PortalRequestContext context,
+ List<ApplicationLifecycle> lifecycles, Phase phase)
+ {
+ for (ApplicationLifecycle lifecycle : lifecycles)
+ {
+ if (lifecycle instanceof ApplicationRequestPhaseLifecycle)
+ ((ApplicationRequestPhaseLifecycle) lifecycle).onStartRequestPhase(app, context, phase);
+ }
+ }
+
+ private void endRequestPhaseLifecycle(PortalApplication app, PortalRequestContext context,
+ List<ApplicationLifecycle> lifecycles, Phase phase)
+ {
+ for (ApplicationLifecycle lifecycle : lifecycles)
+ {
+ if (lifecycle instanceof ApplicationRequestPhaseLifecycle)
+ ((ApplicationRequestPhaseLifecycle) lifecycle).onEndRequestPhase(app, context, phase);
+ }
+ }
+
}
Modified: portal/trunk/webui/portal/src/main/java/org/exoplatform/portal/application/PortalStateManager.java
===================================================================
--- portal/trunk/webui/portal/src/main/java/org/exoplatform/portal/application/PortalStateManager.java 2010-08-13 17:09:39 UTC (rev 3829)
+++ portal/trunk/webui/portal/src/main/java/org/exoplatform/portal/application/PortalStateManager.java 2010-08-16 03:50:59 UTC (rev 3830)
@@ -141,7 +141,7 @@
// For now do nothing....
}
- private UserPortalConfig getUserPortalConfig(PortalRequestContext context) throws Exception
+ public static UserPortalConfig getUserPortalConfig(PortalRequestContext context) throws Exception
{
ExoContainer appContainer = context.getApplication().getApplicationServiceContainer();
UserPortalConfigService service_ = (UserPortalConfigService)appContainer.getComponentInstanceOfType(UserPortalConfigService.class);
Modified: portal/trunk/webui/portal/src/main/java/org/exoplatform/portal/application/UserProfileLifecycle.java
===================================================================
--- portal/trunk/webui/portal/src/main/java/org/exoplatform/portal/application/UserProfileLifecycle.java 2010-08-13 17:09:39 UTC (rev 3829)
+++ portal/trunk/webui/portal/src/main/java/org/exoplatform/portal/application/UserProfileLifecycle.java 2010-08-16 03:50:59 UTC (rev 3830)
@@ -31,7 +31,7 @@
{
public static final String USER_PROFILE_ATTRIBUTE_NAME = "PortalUserProfile";
- private final ThreadLocal<UserProfile> currentUserProfile = new ThreadLocal<UserProfile>();
+ private final static ThreadLocal<UserProfile> currentUserProfile = new ThreadLocal<UserProfile>();
@SuppressWarnings("unused")
public void onInit(Application app)
@@ -55,15 +55,15 @@
}
}
-
+
currentUserProfile.set(userProfile);
context.setAttribute(this.USER_PROFILE_ATTRIBUTE_NAME, userProfile);
}
-
+
@SuppressWarnings("unused")
public void onFailRequest(Application app, WebuiRequestContext context, RequestFailure failureType) throws Exception
{
-
+
}
@SuppressWarnings("unused")
Copied: portal/trunk/webui/portal/src/main/java/org/exoplatform/portal/application/localization (from rev 3829, portal/branches/branched-r3776/webui/portal/src/main/java/org/exoplatform/portal/application/localization)
Deleted: portal/trunk/webui/portal/src/main/java/org/exoplatform/portal/application/localization/DefaultLocalePolicyService.java
===================================================================
--- portal/branches/branched-r3776/webui/portal/src/main/java/org/exoplatform/portal/application/localization/DefaultLocalePolicyService.java 2010-08-13 17:09:39 UTC (rev 3829)
+++ portal/trunk/webui/portal/src/main/java/org/exoplatform/portal/application/localization/DefaultLocalePolicyService.java 2010-08-16 03:50:59 UTC (rev 3830)
@@ -1,142 +0,0 @@
-/*
- * JBoss, Home of Professional Open Source
- * Copyright 2010, Red Hat, Inc., and individual contributors
- * by the @authors tag. See the copyright.txt in the distribution for a
- * full listing of individual contributors.
- *
- * This is free software; you can redistribute it and/or modify it
- * under the terms of the GNU Lesser General Public License as
- * published by the Free Software Foundation; either version 2.1 of
- * the License, or (at your option) any later version.
- *
- * This software is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this software; if not, write to the Free
- * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
- * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
- */
-package org.exoplatform.portal.application.localization;
-
-import org.exoplatform.services.resources.LocaleContextInfo;
-import org.exoplatform.services.resources.LocalePolicy;
-import org.picocontainer.Startable;
-
-import java.util.List;
-import java.util.Locale;
-
-/**
- * This service represents a default policy for determining LocaleConfig to be used for user's session.
- * This service is registered through portal services configuration file: conf/portal/configuration.xml
- * Custom locale determination policy can be implemented by overriding or completely replacing this class,
- * and registering an alternative implementation.
- *
- * @see NoBrowserLocalePolicyService
- *
- * @author <a href="mailto:mstrukel@redhat.com">Marko Strukelj</a>
- */
-public class DefaultLocalePolicyService implements LocalePolicy, Startable
-{
- /**
- * @see LocalePolicy#determineLocale(LocaleContextInfo)
- */
- public Locale determineLocale(LocaleContextInfo context)
- {
- Locale locale = null;
- if (context.getRemoteUser() == null)
- locale = getLocaleConfigForAnonymous(context);
- else
- locale = getLocaleConfigForRegistered(context);
-
- if (locale == null)
- locale = context.getPortalLocale();
-
- return locale;
- }
-
- /**
- * Override this method to change the LocaleConfig determination for registered users.
- * Default is: use user's profile language, if not available fall back to LOCALE cookie,
- * and finally if that is not available either fall back to browser language preference.
- *
- * @param context locale context info available to implementations in order to determine appropriate Locale
- * @return Locale representing a language to use, or null
- */
- protected Locale getLocaleConfigForRegistered(LocaleContextInfo context)
- {
- Locale locale = context.getLocaleIfSupported(context.getUserProfileLocale());
- if (locale == null)
- locale = getLocaleConfigFromCookie(context);
- if (locale == null)
- locale = getLocaleConfigFromBrowser(context);
-
- return locale;
- }
-
- /**
- * Override this method to change the Locale determination based on browser language preferences.
- * If you want to disable the use of browser language preferences simply return null.
- *
- * @param context locale context info available to implementations in order to determine appropriate Locale
- * @return Locale representing a language to use, or null
- */
- protected Locale getLocaleConfigFromBrowser(LocaleContextInfo context)
- {
- List<Locale> locales = context.getBrowserLocales();
- for (Locale loc: locales)
- return context.getLocaleIfSupported(loc);
-
- return null;
- }
-
- /**
- * Override this method to change Locale determination for users that aren't logged in.
- * By default the request's LOCALE cookie is used, if that is not available the browser
- * language preferences are used.
- *
- * @param context locale context info available to implementations in order to determine appropriate Locale
- * @return Locale representing a language to use, or null
- */
- protected Locale getLocaleConfigForAnonymous(LocaleContextInfo context)
- {
- Locale locale = getLocaleConfigFromCookie(context);
- if (locale == null)
- locale = getLocaleConfigFromBrowser(context);
-
- return locale;
- }
-
- /**
- * Override this method to change the Locale determination based on browser cookie.
- * If you want to disable the use of browser cookies simply return null.
- *
- * @param context locale context info available to implementations in order to determine appropriate Locale
- * @return Locale representing a language to use, or null
- */
- protected Locale getLocaleConfigFromCookie(LocaleContextInfo context)
- {
- List<Locale> locales = context.getCookieLocales();
- for (Locale locale: locales)
- return context.getLocaleIfSupported(locale);
-
- return null;
- }
-
- /**
- * Starter interface method
- */
- public void start()
- {
- }
-
- /**
- * Starter interface method
- */
- public void stop()
- {
- }
-
-}
Copied: portal/trunk/webui/portal/src/main/java/org/exoplatform/portal/application/localization/DefaultLocalePolicyService.java (from rev 3829, portal/branches/branched-r3776/webui/portal/src/main/java/org/exoplatform/portal/application/localization/DefaultLocalePolicyService.java)
===================================================================
--- portal/trunk/webui/portal/src/main/java/org/exoplatform/portal/application/localization/DefaultLocalePolicyService.java (rev 0)
+++ portal/trunk/webui/portal/src/main/java/org/exoplatform/portal/application/localization/DefaultLocalePolicyService.java 2010-08-16 03:50:59 UTC (rev 3830)
@@ -0,0 +1,142 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2010, Red Hat, Inc., and individual contributors
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.exoplatform.portal.application.localization;
+
+import org.exoplatform.services.resources.LocaleContextInfo;
+import org.exoplatform.services.resources.LocalePolicy;
+import org.picocontainer.Startable;
+
+import java.util.List;
+import java.util.Locale;
+
+/**
+ * This service represents a default policy for determining LocaleConfig to be used for user's session.
+ * This service is registered through portal services configuration file: conf/portal/configuration.xml
+ * Custom locale determination policy can be implemented by overriding or completely replacing this class,
+ * and registering an alternative implementation.
+ *
+ * @see NoBrowserLocalePolicyService
+ *
+ * @author <a href="mailto:mstrukel@redhat.com">Marko Strukelj</a>
+ */
+public class DefaultLocalePolicyService implements LocalePolicy, Startable
+{
+ /**
+ * @see LocalePolicy#determineLocale(LocaleContextInfo)
+ */
+ public Locale determineLocale(LocaleContextInfo context)
+ {
+ Locale locale = null;
+ if (context.getRemoteUser() == null)
+ locale = getLocaleConfigForAnonymous(context);
+ else
+ locale = getLocaleConfigForRegistered(context);
+
+ if (locale == null)
+ locale = context.getPortalLocale();
+
+ return locale;
+ }
+
+ /**
+ * Override this method to change the LocaleConfig determination for registered users.
+ * Default is: use user's profile language, if not available fall back to LOCALE cookie,
+ * and finally if that is not available either fall back to browser language preference.
+ *
+ * @param context locale context info available to implementations in order to determine appropriate Locale
+ * @return Locale representing a language to use, or null
+ */
+ protected Locale getLocaleConfigForRegistered(LocaleContextInfo context)
+ {
+ Locale locale = context.getLocaleIfSupported(context.getUserProfileLocale());
+ if (locale == null)
+ locale = getLocaleConfigFromCookie(context);
+ if (locale == null)
+ locale = getLocaleConfigFromBrowser(context);
+
+ return locale;
+ }
+
+ /**
+ * Override this method to change the Locale determination based on browser language preferences.
+ * If you want to disable the use of browser language preferences simply return null.
+ *
+ * @param context locale context info available to implementations in order to determine appropriate Locale
+ * @return Locale representing a language to use, or null
+ */
+ protected Locale getLocaleConfigFromBrowser(LocaleContextInfo context)
+ {
+ List<Locale> locales = context.getBrowserLocales();
+ for (Locale loc: locales)
+ return context.getLocaleIfSupported(loc);
+
+ return null;
+ }
+
+ /**
+ * Override this method to change Locale determination for users that aren't logged in.
+ * By default the request's LOCALE cookie is used, if that is not available the browser
+ * language preferences are used.
+ *
+ * @param context locale context info available to implementations in order to determine appropriate Locale
+ * @return Locale representing a language to use, or null
+ */
+ protected Locale getLocaleConfigForAnonymous(LocaleContextInfo context)
+ {
+ Locale locale = getLocaleConfigFromCookie(context);
+ if (locale == null)
+ locale = getLocaleConfigFromBrowser(context);
+
+ return locale;
+ }
+
+ /**
+ * Override this method to change the Locale determination based on browser cookie.
+ * If you want to disable the use of browser cookies simply return null.
+ *
+ * @param context locale context info available to implementations in order to determine appropriate Locale
+ * @return Locale representing a language to use, or null
+ */
+ protected Locale getLocaleConfigFromCookie(LocaleContextInfo context)
+ {
+ List<Locale> locales = context.getCookieLocales();
+ for (Locale locale: locales)
+ return context.getLocaleIfSupported(locale);
+
+ return null;
+ }
+
+ /**
+ * Starter interface method
+ */
+ public void start()
+ {
+ }
+
+ /**
+ * Starter interface method
+ */
+ public void stop()
+ {
+ }
+
+}
Deleted: portal/trunk/webui/portal/src/main/java/org/exoplatform/portal/application/localization/HttpRequestWrapper.java
===================================================================
--- portal/branches/branched-r3776/webui/portal/src/main/java/org/exoplatform/portal/application/localization/HttpRequestWrapper.java 2010-08-13 17:09:39 UTC (rev 3829)
+++ portal/trunk/webui/portal/src/main/java/org/exoplatform/portal/application/localization/HttpRequestWrapper.java 2010-08-16 03:50:59 UTC (rev 3830)
@@ -1,97 +0,0 @@
-/*
- * JBoss, Home of Professional Open Source
- * Copyright 2010, Red Hat, Inc., and individual contributors
- * by the @authors tag. See the copyright.txt in the distribution for a
- * full listing of individual contributors.
- *
- * This is free software; you can redistribute it and/or modify it
- * under the terms of the GNU Lesser General Public License as
- * published by the Free Software Foundation; either version 2.1 of
- * the License, or (at your option) any later version.
- *
- * This software is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this software; if not, write to the Free
- * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
- * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
- */
-package org.exoplatform.portal.application.localization;
-
-import org.exoplatform.portal.application.PortalRequestContext;
-
-import javax.servlet.http.HttpServletRequest;
-import javax.servlet.http.HttpServletRequestWrapper;
-import java.util.Collections;
-import java.util.Enumeration;
-import java.util.LinkedList;
-import java.util.List;
-import java.util.Locale;
-
-/**
- * @author <a href="mailto:mstrukel@redhat.com">Marko Strukelj</a>
- */
-public class HttpRequestWrapper extends HttpServletRequestWrapper
-{
- private static final List<Locale> EMPTY_LOCALE_LIST = Collections.emptyList();
-
- /**
- * Constructs a request object wrapping the given request.
- *
- * @throws IllegalArgumentException if the request is null
- */
- public HttpRequestWrapper(HttpServletRequest request)
- {
- super(request);
- }
-
- /**
- * Note: Keep the implementation here in sync with {@link org.exoplatform.portal.webui.application.ExoUserContext#getLocale}
- * @return
- */
- @Override
- public Locale getLocale()
- {
- if (PortalRequestContext.getCurrentInstance() != null)
- return getRequest().getLocale();
-
- Locale current = LocalizationFilter.getCurrentLocale();
- if (current != null)
- return current;
-
- return getRequest().getLocale();
- }
-
- @Override
- public Enumeration getLocales()
- {
- Locale current = LocalizationFilter.getCurrentLocale();
- if (PortalRequestContext.getCurrentInstance() != null || current == null)
- return getRequest().getLocales();
-
- Locale loc = getLocale();
- if (loc == null)
- {
- return Collections.enumeration(EMPTY_LOCALE_LIST);
- }
- else
- {
- LinkedList<Locale> locs = new LinkedList<Locale>();
- locs.add(loc);
-
- Enumeration<Locale> clientLocs = (Enumeration<Locale>) getRequest().getLocales();
- while (clientLocs.hasMoreElements())
- {
- current = clientLocs.nextElement();
- if (current.getLanguage().equals(loc.getLanguage()) && current.getCountry().equals(loc.getCountry()))
- continue;
- locs.add(current);
- }
-
- return Collections.enumeration(locs);
- }
- }
-}
Copied: portal/trunk/webui/portal/src/main/java/org/exoplatform/portal/application/localization/HttpRequestWrapper.java (from rev 3829, portal/branches/branched-r3776/webui/portal/src/main/java/org/exoplatform/portal/application/localization/HttpRequestWrapper.java)
===================================================================
--- portal/trunk/webui/portal/src/main/java/org/exoplatform/portal/application/localization/HttpRequestWrapper.java (rev 0)
+++ portal/trunk/webui/portal/src/main/java/org/exoplatform/portal/application/localization/HttpRequestWrapper.java 2010-08-16 03:50:59 UTC (rev 3830)
@@ -0,0 +1,97 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2010, Red Hat, Inc., and individual contributors
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.exoplatform.portal.application.localization;
+
+import org.exoplatform.portal.application.PortalRequestContext;
+
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletRequestWrapper;
+import java.util.Collections;
+import java.util.Enumeration;
+import java.util.LinkedList;
+import java.util.List;
+import java.util.Locale;
+
+/**
+ * @author <a href="mailto:mstrukel@redhat.com">Marko Strukelj</a>
+ */
+public class HttpRequestWrapper extends HttpServletRequestWrapper
+{
+ private static final List<Locale> EMPTY_LOCALE_LIST = Collections.emptyList();
+
+ /**
+ * Constructs a request object wrapping the given request.
+ *
+ * @throws IllegalArgumentException if the request is null
+ */
+ public HttpRequestWrapper(HttpServletRequest request)
+ {
+ super(request);
+ }
+
+ /**
+ * Note: Keep the implementation here in sync with {@link org.exoplatform.portal.webui.application.ExoUserContext#getLocale}
+ * @return
+ */
+ @Override
+ public Locale getLocale()
+ {
+ if (PortalRequestContext.getCurrentInstance() != null)
+ return getRequest().getLocale();
+
+ Locale current = LocalizationFilter.getCurrentLocale();
+ if (current != null)
+ return current;
+
+ return getRequest().getLocale();
+ }
+
+ @Override
+ public Enumeration getLocales()
+ {
+ Locale current = LocalizationFilter.getCurrentLocale();
+ if (PortalRequestContext.getCurrentInstance() != null || current == null)
+ return getRequest().getLocales();
+
+ Locale loc = getLocale();
+ if (loc == null)
+ {
+ return Collections.enumeration(EMPTY_LOCALE_LIST);
+ }
+ else
+ {
+ LinkedList<Locale> locs = new LinkedList<Locale>();
+ locs.add(loc);
+
+ Enumeration<Locale> clientLocs = (Enumeration<Locale>) getRequest().getLocales();
+ while (clientLocs.hasMoreElements())
+ {
+ current = clientLocs.nextElement();
+ if (current.getLanguage().equals(loc.getLanguage()) && current.getCountry().equals(loc.getCountry()))
+ continue;
+ locs.add(current);
+ }
+
+ return Collections.enumeration(locs);
+ }
+ }
+}
Deleted: portal/trunk/webui/portal/src/main/java/org/exoplatform/portal/application/localization/LocalizationFilter.java
===================================================================
--- portal/branches/branched-r3776/webui/portal/src/main/java/org/exoplatform/portal/application/localization/LocalizationFilter.java 2010-08-13 17:09:39 UTC (rev 3829)
+++ portal/trunk/webui/portal/src/main/java/org/exoplatform/portal/application/localization/LocalizationFilter.java 2010-08-16 03:50:59 UTC (rev 3830)
@@ -1,195 +0,0 @@
-/*
- * JBoss, Home of Professional Open Source
- * Copyright 2010, Red Hat, Inc., and individual contributors
- * by the @authors tag. See the copyright.txt in the distribution for a
- * full listing of individual contributors.
- *
- * This is free software; you can redistribute it and/or modify it
- * under the terms of the GNU Lesser General Public License as
- * published by the Free Software Foundation; either version 2.1 of
- * the License, or (at your option) any later version.
- *
- * This software is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this software; if not, write to the Free
- * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
- * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
- */
-package org.exoplatform.portal.application.localization;
-
-import org.exoplatform.container.ExoContainer;
-import org.exoplatform.container.ExoContainerContext;
-import org.exoplatform.container.RootContainer;
-import org.exoplatform.portal.Constants;
-import org.exoplatform.portal.application.PortalRequestContext;
-import org.exoplatform.services.log.ExoLogger;
-import org.exoplatform.services.log.Log;
-import org.exoplatform.services.organization.OrganizationService;
-import org.exoplatform.services.organization.UserProfile;
-import org.exoplatform.services.resources.LocaleConfig;
-import org.exoplatform.services.resources.LocaleConfigService;
-import org.exoplatform.services.resources.LocaleContextInfo;
-import org.exoplatform.services.resources.LocalePolicy;
-
-import javax.servlet.Filter;
-import javax.servlet.FilterChain;
-import javax.servlet.FilterConfig;
-import javax.servlet.ServletException;
-import javax.servlet.ServletRequest;
-import javax.servlet.ServletResponse;
-import javax.servlet.http.HttpServletRequest;
-import javax.servlet.http.HttpServletResponse;
-import java.io.IOException;
-import java.util.Collections;
-import java.util.HashSet;
-import java.util.Locale;
-import java.util.Set;
-
-/**
- * This filter provides {@link HttpServletRequest#getLocale()} and {@link HttpServletRequest#getLocales()}
- * override for extra-portlet requests (i.e. unbridged .jsp). Thanks to this dynamic resources can be localized
- * to keep in synch with the rest of the portal.
- *
- * A concrete example for this is login/jsp/login.jsp used when authentication fails at portal login.
- *
- * By default {@link HttpServletRequest#getLocale()} and {@link HttpServletRequest#getLocales()} reflect
- * browser language preference. When using this filter these two calls employ the same Locale determination algorithm
- * that LocalizationLifecycle uses.
- *
- * This filter can be activated / deactivated via portal module's web.xml
- *
- * @author <a href="mailto:mstrukel@redhat.com">Marko Strukelj</a>
- */
-public class LocalizationFilter implements Filter
-{
- private static Log log = ExoLogger.getLogger("portal:LocalizationFilter");
-
- private static ThreadLocal<Locale> currentLocale = new ThreadLocal<Locale>();
-
- public void init(FilterConfig filterConfig) throws ServletException
- {
- }
-
- public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException
- {
-
- HttpServletRequest req = (HttpServletRequest) request;
- HttpServletResponse res = (HttpServletResponse) response;
-
- try
- {
- // Due to forwards, and includes the filter might be reentered
- // If current requestContext exists use its Locale
- PortalRequestContext context = PortalRequestContext.getCurrentInstance();
- if (context != null && context.getLocale() != null)
- {
- // No need to wrap if reentered
- boolean skipWrapping = currentLocale.get() != null;
- // overwrite any already set currentLocale
- currentLocale.set(context.getLocale());
- if (!skipWrapping)
- {
- req = new HttpRequestWrapper(req);
- }
- chain.doFilter(req, res);
- return;
- }
-
- // If reentered we don't need to wrap
- if (currentLocale.get() != null)
- {
- chain.doFilter(request, response);
- return;
- }
-
-
- // Initialize currentLocale
- ExoContainer container = ExoContainerContext.getCurrentContainerIfPresent();
- if (container == null)
- {
- // Nothing we can do, move on
- chain.doFilter(req, res);
- return;
- }
-
- if (container instanceof RootContainer)
- container = (ExoContainer) container.getComponentInstance("portal");
-
- LocaleConfigService localeConfigService = (LocaleConfigService)
- container.getComponentInstanceOfType(LocaleConfigService.class);
- LocalePolicy localePolicy = (LocalePolicy) container.getComponentInstanceOfType(LocalePolicy.class);
-
- LocaleContextInfo localeCtx = new LocaleContextInfo();
-
- Set<Locale> supportedLocales = new HashSet();
- for (LocaleConfig lc: localeConfigService.getLocalConfigs())
- {
- supportedLocales.add(lc.getLocale());
- }
- localeCtx.setSupportedLocales(supportedLocales);
-
- localeCtx.setBrowserLocales(Collections.list(request.getLocales()));
- localeCtx.setCookieLocales(LocalizationLifecycle.getCookieLocales(req));
- localeCtx.setUserProfileLocale(getUserProfileLocale(container, req.getRemoteUser()));
- localeCtx.setRemoteUser(req.getRemoteUser());
-
- localeCtx.setPortalLocale(Locale.ENGLISH);
- Locale locale = localePolicy.determineLocale(localeCtx);
- if (!supportedLocales.contains(locale))
- {
- if (log.isWarnEnabled())
- log.warn("Unsupported locale returned by LocalePolicy: " + localePolicy + ". Falling back to 'en'.");
- locale = Locale.ENGLISH;
- }
-
- currentLocale.set(locale);
- chain.doFilter(new HttpRequestWrapper(req), res);
- }
- catch(Exception e)
- {
- throw new RuntimeException("LocalizationFilter exception: ", e);
- }
- finally
- {
- currentLocale.remove();
- }
- }
-
- private Locale getUserProfileLocale(ExoContainer container, String user)
- {
- UserProfile userProfile = null;
- OrganizationService svc = (OrganizationService)
- container.getComponentInstanceOfType(OrganizationService.class);
-
- if (user != null)
- {
- try
- {
- userProfile = svc.getUserProfileHandler().findUserProfileByName(user);
- }
- catch (Exception ignored)
- {
- log.error("IGNORED: Failed to load UserProfile for username: " + user, ignored);
- }
-
- if (userProfile == null && log.isWarnEnabled())
- log.warn("Could not load user profile for " + user + ". Using default portal locale.");
- }
-
- String lang = userProfile == null ? null : userProfile.getUserInfoMap().get(Constants.USER_LANGUAGE);
- return (lang != null) ? new Locale(lang) : null;
- }
-
- public void destroy()
- {
- }
-
- public static Locale getCurrentLocale()
- {
- return currentLocale.get();
- }
-}
Copied: portal/trunk/webui/portal/src/main/java/org/exoplatform/portal/application/localization/LocalizationFilter.java (from rev 3829, portal/branches/branched-r3776/webui/portal/src/main/java/org/exoplatform/portal/application/localization/LocalizationFilter.java)
===================================================================
--- portal/trunk/webui/portal/src/main/java/org/exoplatform/portal/application/localization/LocalizationFilter.java (rev 0)
+++ portal/trunk/webui/portal/src/main/java/org/exoplatform/portal/application/localization/LocalizationFilter.java 2010-08-16 03:50:59 UTC (rev 3830)
@@ -0,0 +1,195 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2010, Red Hat, Inc., and individual contributors
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.exoplatform.portal.application.localization;
+
+import org.exoplatform.container.ExoContainer;
+import org.exoplatform.container.ExoContainerContext;
+import org.exoplatform.container.RootContainer;
+import org.exoplatform.portal.Constants;
+import org.exoplatform.portal.application.PortalRequestContext;
+import org.exoplatform.services.log.ExoLogger;
+import org.exoplatform.services.log.Log;
+import org.exoplatform.services.organization.OrganizationService;
+import org.exoplatform.services.organization.UserProfile;
+import org.exoplatform.services.resources.LocaleConfig;
+import org.exoplatform.services.resources.LocaleConfigService;
+import org.exoplatform.services.resources.LocaleContextInfo;
+import org.exoplatform.services.resources.LocalePolicy;
+
+import javax.servlet.Filter;
+import javax.servlet.FilterChain;
+import javax.servlet.FilterConfig;
+import javax.servlet.ServletException;
+import javax.servlet.ServletRequest;
+import javax.servlet.ServletResponse;
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+import java.io.IOException;
+import java.util.Collections;
+import java.util.HashSet;
+import java.util.Locale;
+import java.util.Set;
+
+/**
+ * This filter provides {@link HttpServletRequest#getLocale()} and {@link HttpServletRequest#getLocales()}
+ * override for extra-portlet requests (i.e. unbridged .jsp). Thanks to this dynamic resources can be localized
+ * to keep in synch with the rest of the portal.
+ *
+ * A concrete example for this is login/jsp/login.jsp used when authentication fails at portal login.
+ *
+ * By default {@link HttpServletRequest#getLocale()} and {@link HttpServletRequest#getLocales()} reflect
+ * browser language preference. When using this filter these two calls employ the same Locale determination algorithm
+ * that LocalizationLifecycle uses.
+ *
+ * This filter can be activated / deactivated via portal module's web.xml
+ *
+ * @author <a href="mailto:mstrukel@redhat.com">Marko Strukelj</a>
+ */
+public class LocalizationFilter implements Filter
+{
+ private static Log log = ExoLogger.getLogger("portal:LocalizationFilter");
+
+ private static ThreadLocal<Locale> currentLocale = new ThreadLocal<Locale>();
+
+ public void init(FilterConfig filterConfig) throws ServletException
+ {
+ }
+
+ public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException
+ {
+
+ HttpServletRequest req = (HttpServletRequest) request;
+ HttpServletResponse res = (HttpServletResponse) response;
+
+ try
+ {
+ // Due to forwards, and includes the filter might be reentered
+ // If current requestContext exists use its Locale
+ PortalRequestContext context = PortalRequestContext.getCurrentInstance();
+ if (context != null && context.getLocale() != null)
+ {
+ // No need to wrap if reentered
+ boolean skipWrapping = currentLocale.get() != null;
+ // overwrite any already set currentLocale
+ currentLocale.set(context.getLocale());
+ if (!skipWrapping)
+ {
+ req = new HttpRequestWrapper(req);
+ }
+ chain.doFilter(req, res);
+ return;
+ }
+
+ // If reentered we don't need to wrap
+ if (currentLocale.get() != null)
+ {
+ chain.doFilter(request, response);
+ return;
+ }
+
+
+ // Initialize currentLocale
+ ExoContainer container = ExoContainerContext.getCurrentContainerIfPresent();
+ if (container == null)
+ {
+ // Nothing we can do, move on
+ chain.doFilter(req, res);
+ return;
+ }
+
+ if (container instanceof RootContainer)
+ container = (ExoContainer) container.getComponentInstance("portal");
+
+ LocaleConfigService localeConfigService = (LocaleConfigService)
+ container.getComponentInstanceOfType(LocaleConfigService.class);
+ LocalePolicy localePolicy = (LocalePolicy) container.getComponentInstanceOfType(LocalePolicy.class);
+
+ LocaleContextInfo localeCtx = new LocaleContextInfo();
+
+ Set<Locale> supportedLocales = new HashSet();
+ for (LocaleConfig lc: localeConfigService.getLocalConfigs())
+ {
+ supportedLocales.add(lc.getLocale());
+ }
+ localeCtx.setSupportedLocales(supportedLocales);
+
+ localeCtx.setBrowserLocales(Collections.list(request.getLocales()));
+ localeCtx.setCookieLocales(LocalizationLifecycle.getCookieLocales(req));
+ localeCtx.setUserProfileLocale(getUserProfileLocale(container, req.getRemoteUser()));
+ localeCtx.setRemoteUser(req.getRemoteUser());
+
+ localeCtx.setPortalLocale(Locale.ENGLISH);
+ Locale locale = localePolicy.determineLocale(localeCtx);
+ if (!supportedLocales.contains(locale))
+ {
+ if (log.isWarnEnabled())
+ log.warn("Unsupported locale returned by LocalePolicy: " + localePolicy + ". Falling back to 'en'.");
+ locale = Locale.ENGLISH;
+ }
+
+ currentLocale.set(locale);
+ chain.doFilter(new HttpRequestWrapper(req), res);
+ }
+ catch(Exception e)
+ {
+ throw new RuntimeException("LocalizationFilter exception: ", e);
+ }
+ finally
+ {
+ currentLocale.remove();
+ }
+ }
+
+ private Locale getUserProfileLocale(ExoContainer container, String user)
+ {
+ UserProfile userProfile = null;
+ OrganizationService svc = (OrganizationService)
+ container.getComponentInstanceOfType(OrganizationService.class);
+
+ if (user != null)
+ {
+ try
+ {
+ userProfile = svc.getUserProfileHandler().findUserProfileByName(user);
+ }
+ catch (Exception ignored)
+ {
+ log.error("IGNORED: Failed to load UserProfile for username: " + user, ignored);
+ }
+
+ if (userProfile == null && log.isWarnEnabled())
+ log.warn("Could not load user profile for " + user + ". Using default portal locale.");
+ }
+
+ String lang = userProfile == null ? null : userProfile.getUserInfoMap().get(Constants.USER_LANGUAGE);
+ return (lang != null) ? new Locale(lang) : null;
+ }
+
+ public void destroy()
+ {
+ }
+
+ public static Locale getCurrentLocale()
+ {
+ return currentLocale.get();
+ }
+}
Deleted: portal/trunk/webui/portal/src/main/java/org/exoplatform/portal/application/localization/LocalizationLifecycle.java
===================================================================
--- portal/branches/branched-r3776/webui/portal/src/main/java/org/exoplatform/portal/application/localization/LocalizationLifecycle.java 2010-08-13 17:09:39 UTC (rev 3829)
+++ portal/trunk/webui/portal/src/main/java/org/exoplatform/portal/application/localization/LocalizationLifecycle.java 2010-08-16 03:50:59 UTC (rev 3830)
@@ -1,314 +0,0 @@
-/*
- * JBoss, Home of Professional Open Source
- * Copyright 2010, Red Hat, Inc., and individual contributors
- * by the @authors tag. See the copyright.txt in the distribution for a
- * full listing of individual contributors.
- *
- * This is free software; you can redistribute it and/or modify it
- * under the terms of the GNU Lesser General Public License as
- * published by the Free Software Foundation; either version 2.1 of
- * the License, or (at your option) any later version.
- *
- * This software is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this software; if not, write to the Free
- * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
- * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
- */
-package org.exoplatform.portal.application.localization;
-
-import org.exoplatform.container.ExoContainer;
-import org.exoplatform.portal.Constants;
-import org.exoplatform.portal.application.PortalRequestContext;
-import org.exoplatform.portal.application.PortalStateManager;
-import org.exoplatform.portal.application.UserProfileLifecycle;
-import org.exoplatform.portal.config.UserPortalConfig;
-import org.exoplatform.services.log.ExoLogger;
-import org.exoplatform.services.log.Log;
-import org.exoplatform.services.organization.OrganizationService;
-import org.exoplatform.services.organization.UserProfile;
-import org.exoplatform.services.resources.LocaleConfig;
-import org.exoplatform.services.resources.LocaleConfigService;
-import org.exoplatform.services.resources.LocaleContextInfo;
-import org.exoplatform.services.resources.LocalePolicy;
-import org.exoplatform.web.application.Application;
-import org.exoplatform.web.application.ApplicationRequestPhaseLifecycle;
-import org.exoplatform.web.application.Phase;
-import org.exoplatform.web.application.RequestFailure;
-import org.exoplatform.webui.application.WebuiRequestContext;
-
-import javax.servlet.http.Cookie;
-import javax.servlet.http.HttpServletRequest;
-import javax.servlet.http.HttpServletResponse;
-import java.util.ArrayList;
-import java.util.Collections;
-import java.util.HashSet;
-import java.util.List;
-import java.util.Locale;
-import java.util.Set;
-
-/**
- * This class takes care of loading / initializing / saving the current Locale.
- * Current Locale is used to create properly localized response to current request.
- *
- * At the beginning of request {@link LocalePolicy} is used to determine the
- * initial Locale to be used for processing the request.
- *
- * This Locale is then set on current {@link org.exoplatform.portal.application.PortalRequestContext} (it's presumed that current
- * {@link org.exoplatform.web.application.RequestContext} is of type PortalRequestContext) by calling
- * {@link org.exoplatform.portal.application.PortalRequestContext#setLocale}.
- *
- * During request processing {@link org.exoplatform.portal.application.PortalRequestContext#getLocale} is the ultimate reference consulted by any
- * rendering code that needs to know about current Locale.
- *
- * When this Locale is changed during action processing, the new Locale choice is saved
- * into user's profile or into browser's cookie in order to be used by future requests.
- *
- * This Lifecycle depends on UserProfileLifecycle being registered before this one, as it relies on it
- * for loading the user profile. See WEB-INF/webui-configuration.xml in web/portal module.
- *
- * @author <a href="mailto:mstrukel@redhat.com">Marko Strukelj</a>
- */
-public class LocalizationLifecycle implements ApplicationRequestPhaseLifecycle<WebuiRequestContext>
-{
- private static final String COOKIE_NAME = "LOCALE";
-
- private static final ThreadLocal<Locale> calculatedLocale = new ThreadLocal<Locale>();
-
- private static Log log = ExoLogger.getLogger("portal:LocalizationLifecycle");
-
- /**
- * @see org.exoplatform.web.application.ApplicationLifecycle#onInit
- */
- public void onInit(Application app) throws Exception
- {
- }
-
- /**
- * Initialize Locale to be used for the processing of current request
- *
- * @see org.exoplatform.web.application.ApplicationLifecycle#onStartRequest
- */
- public void onStartRequest(Application app, WebuiRequestContext context) throws Exception
- {
- if (context instanceof PortalRequestContext == false)
- throw new IllegalArgumentException("Expected PortalRequestContext, but got: " + context);
-
- PortalRequestContext reqCtx = (PortalRequestContext) context;
- ExoContainer container = app.getApplicationServiceContainer();
-
- LocaleConfigService localeConfigService = (LocaleConfigService)
- container.getComponentInstanceOfType(LocaleConfigService.class);
- LocalePolicy localePolicy = (LocalePolicy) container.getComponentInstanceOfType(LocalePolicy.class);
-
- LocaleContextInfo localeCtx = new LocaleContextInfo();
-
- Set<Locale> supportedLocales = new HashSet();
- for (LocaleConfig lc: localeConfigService.getLocalConfigs())
- {
- supportedLocales.add(lc.getLocale());
- }
- localeCtx.setSupportedLocales(supportedLocales);
-
- HttpServletRequest request = HttpServletRequest.class.cast(context.getRequest());
- localeCtx.setBrowserLocales(Collections.list(request.getLocales()));
-
- localeCtx.setCookieLocales(getCookieLocales(request));
- localeCtx.setUserProfileLocale(getUserProfileLocale(reqCtx));
- localeCtx.setRemoteUser(reqCtx.getRemoteUser());
-
- UserPortalConfig userPortalConfig = null;
- try
- {
- userPortalConfig = PortalStateManager.getUserPortalConfig(reqCtx);
- if (userPortalConfig == null)
- log.warn("No UserPortalConfig available! Portal locale set to 'en'");
- }
- catch(Exception ignored)
- {
- if (log.isDebugEnabled())
- log.debug("IGNORED: Failed to load UserPortalConfig: ", ignored);
- }
-
- String portalLocaleName = "en";
- if (userPortalConfig != null)
- portalLocaleName = userPortalConfig.getPortalConfig().getLocale();
-
- Locale portalLocale = LocaleContextInfo.getLocale(portalLocaleName);
- localeCtx.setPortalLocale(portalLocale);
-
- Locale locale = localePolicy.determineLocale(localeCtx);
- if (!supportedLocales.contains(locale))
- {
- if (log.isWarnEnabled())
- log.warn("Unsupported locale returned by LocalePolicy: " + localePolicy + ". Falling back to 'en'.");
- locale = Locale.ENGLISH;
- }
- reqCtx.setLocale(locale);
- calculatedLocale.set(locale);
- }
-
- /**
- * @see org.exoplatform.web.application.ApplicationRequestPhaseLifecycle#onStartRequestPhase
- */
- public void onStartRequestPhase(Application app, WebuiRequestContext context, Phase phase)
- {
- }
-
- /**
- * Save any locale change - to cookie for anonymous users, to profile for logged-in users
- *
- * @see org.exoplatform.web.application.ApplicationRequestPhaseLifecycle#onEndRequestPhase
- */
- public void onEndRequestPhase(Application app, WebuiRequestContext context, Phase phase)
- {
- if (phase == Phase.ACTION)
- {
- // if onStartRequest survived the cast, this one should as well - no check necessary
- PortalRequestContext reqCtx = (PortalRequestContext) context;
- Locale loc = reqCtx.getLocale();
- Locale remembered = calculatedLocale.get();
- calculatedLocale.remove();
- if (loc != null && (remembered == null || !loc.equals(remembered)))
- saveLocale(reqCtx, loc);
- }
- }
-
- /**
- * @see org.exoplatform.web.application.ApplicationLifecycle#onEndRequest
- */
- public void onEndRequest(Application app, WebuiRequestContext context) throws Exception
- {
- }
-
- /**
- * @see org.exoplatform.web.application.ApplicationLifecycle#onFailRequest
- */
- public void onFailRequest(Application app, WebuiRequestContext context, RequestFailure failureType) throws Exception
- {
- }
-
- /**
- * @see org.exoplatform.web.application.ApplicationLifecycle#onDestroy
- */
- public void onDestroy(Application app) throws Exception
- {
- }
-
- /**
- * Use {@link UserProfile} already loaded by {@link org.exoplatform.portal.application.UserProfileLifecycle} or load one ourselves.
- * @param context current PortalRequestContext
- * @return Locale from user's profile or null
- */
- private Locale getUserProfileLocale(PortalRequestContext context)
- {
- String lang = null;
-
- UserProfile userProfile = getLoadedProfile(context);
- lang = userProfile == null ? null : userProfile.getUserInfoMap().get(Constants.USER_LANGUAGE);
- return (lang != null) ? new Locale(lang) : null;
- }
-
- private UserProfile loadUserProfile(ExoContainer container, PortalRequestContext context)
- {
- UserProfile userProfile = null;
- OrganizationService svc = (OrganizationService)
- container.getComponentInstanceOfType(OrganizationService.class);
-
- String user = context.getRemoteUser();
- if (user != null)
- {
- try
- {
- userProfile = svc.getUserProfileHandler().findUserProfileByName(user);
- }
- catch (Exception ignored)
- {
- log.error("IGNORED: Failed to load UserProfile for username: " + user, ignored);
- }
-
- if (userProfile == null && log.isWarnEnabled())
- log.warn("Could not load user profile for " + user + ". Using default portal locale.");
- }
- return userProfile;
- }
-
- private UserProfile getLoadedProfile(PortalRequestContext context)
- {
- return (UserProfile) context.getAttribute(UserProfileLifecycle.USER_PROFILE_ATTRIBUTE_NAME);
- }
-
- public static List<Locale> getCookieLocales(HttpServletRequest request)
- {
- Cookie [] cookies = request.getCookies();
- if (cookies != null)
- {
- for (Cookie cookie: cookies)
- {
- if (COOKIE_NAME.equals(cookie.getName()))
- {
- List<Locale> locales = new ArrayList<Locale>();
- locales.add(LocaleContextInfo.getLocale(cookie.getValue()));
- return locales;
- }
- }
- }
- return Collections.emptyList();
- }
-
- private void saveLocale(PortalRequestContext context, Locale loc)
- {
- String user = context.getRemoteUser();
- if (user != null)
- {
- saveLocaleToUserProfile(context, loc, user);
- }
- else
- {
- saveLocaleToCookie(context, loc);
- }
- }
-
- private void saveLocaleToCookie(PortalRequestContext context, Locale loc)
- {
- HttpServletResponse res = context.getResponse();
- Cookie cookie = new Cookie(COOKIE_NAME, LocaleContextInfo.getLocaleAsString(loc));
- cookie.setMaxAge(Integer.MAX_VALUE);
- cookie.setPath("/");
- res.addCookie(cookie);
- }
-
- private void saveLocaleToUserProfile(PortalRequestContext context, Locale loc, String user)
- {
- ExoContainer container = context.getApplication().getApplicationServiceContainer();
- OrganizationService svc = (OrganizationService)
- container.getComponentInstanceOfType(OrganizationService.class);
-
- // Don't rely on UserProfileLifecycle loaded UserProfile when doing
- // an update to avoid a potential overwrite of other changes
- UserProfile userProfile = loadUserProfile(container, context);
- if (userProfile != null)
- {
- userProfile.getUserInfoMap().put(Constants.USER_LANGUAGE, loc.getLanguage());
- try
- {
- svc.getUserProfileHandler().saveUserProfile(userProfile, false);
- }
- catch (Exception ignored)
- {
- log.error("IGNORED: Failed to save profile for user: " + user, ignored);
- userProfile = null;
- }
- }
-
- if (userProfile == null)
- {
- if (log.isWarnEnabled())
- log.warn("Unable to save locale into profile for user: " + user);
- }
- }
-}
Copied: portal/trunk/webui/portal/src/main/java/org/exoplatform/portal/application/localization/LocalizationLifecycle.java (from rev 3829, portal/branches/branched-r3776/webui/portal/src/main/java/org/exoplatform/portal/application/localization/LocalizationLifecycle.java)
===================================================================
--- portal/trunk/webui/portal/src/main/java/org/exoplatform/portal/application/localization/LocalizationLifecycle.java (rev 0)
+++ portal/trunk/webui/portal/src/main/java/org/exoplatform/portal/application/localization/LocalizationLifecycle.java 2010-08-16 03:50:59 UTC (rev 3830)
@@ -0,0 +1,314 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2010, Red Hat, Inc., and individual contributors
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.exoplatform.portal.application.localization;
+
+import org.exoplatform.container.ExoContainer;
+import org.exoplatform.portal.Constants;
+import org.exoplatform.portal.application.PortalRequestContext;
+import org.exoplatform.portal.application.PortalStateManager;
+import org.exoplatform.portal.application.UserProfileLifecycle;
+import org.exoplatform.portal.config.UserPortalConfig;
+import org.exoplatform.services.log.ExoLogger;
+import org.exoplatform.services.log.Log;
+import org.exoplatform.services.organization.OrganizationService;
+import org.exoplatform.services.organization.UserProfile;
+import org.exoplatform.services.resources.LocaleConfig;
+import org.exoplatform.services.resources.LocaleConfigService;
+import org.exoplatform.services.resources.LocaleContextInfo;
+import org.exoplatform.services.resources.LocalePolicy;
+import org.exoplatform.web.application.Application;
+import org.exoplatform.web.application.ApplicationRequestPhaseLifecycle;
+import org.exoplatform.web.application.Phase;
+import org.exoplatform.web.application.RequestFailure;
+import org.exoplatform.webui.application.WebuiRequestContext;
+
+import javax.servlet.http.Cookie;
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Locale;
+import java.util.Set;
+
+/**
+ * This class takes care of loading / initializing / saving the current Locale.
+ * Current Locale is used to create properly localized response to current request.
+ *
+ * At the beginning of request {@link LocalePolicy} is used to determine the
+ * initial Locale to be used for processing the request.
+ *
+ * This Locale is then set on current {@link org.exoplatform.portal.application.PortalRequestContext} (it's presumed that current
+ * {@link org.exoplatform.web.application.RequestContext} is of type PortalRequestContext) by calling
+ * {@link org.exoplatform.portal.application.PortalRequestContext#setLocale}.
+ *
+ * During request processing {@link org.exoplatform.portal.application.PortalRequestContext#getLocale} is the ultimate reference consulted by any
+ * rendering code that needs to know about current Locale.
+ *
+ * When this Locale is changed during action processing, the new Locale choice is saved
+ * into user's profile or into browser's cookie in order to be used by future requests.
+ *
+ * This Lifecycle depends on UserProfileLifecycle being registered before this one, as it relies on it
+ * for loading the user profile. See WEB-INF/webui-configuration.xml in web/portal module.
+ *
+ * @author <a href="mailto:mstrukel@redhat.com">Marko Strukelj</a>
+ */
+public class LocalizationLifecycle implements ApplicationRequestPhaseLifecycle<WebuiRequestContext>
+{
+ private static final String COOKIE_NAME = "LOCALE";
+
+ private static final ThreadLocal<Locale> calculatedLocale = new ThreadLocal<Locale>();
+
+ private static Log log = ExoLogger.getLogger("portal:LocalizationLifecycle");
+
+ /**
+ * @see org.exoplatform.web.application.ApplicationLifecycle#onInit
+ */
+ public void onInit(Application app) throws Exception
+ {
+ }
+
+ /**
+ * Initialize Locale to be used for the processing of current request
+ *
+ * @see org.exoplatform.web.application.ApplicationLifecycle#onStartRequest
+ */
+ public void onStartRequest(Application app, WebuiRequestContext context) throws Exception
+ {
+ if (context instanceof PortalRequestContext == false)
+ throw new IllegalArgumentException("Expected PortalRequestContext, but got: " + context);
+
+ PortalRequestContext reqCtx = (PortalRequestContext) context;
+ ExoContainer container = app.getApplicationServiceContainer();
+
+ LocaleConfigService localeConfigService = (LocaleConfigService)
+ container.getComponentInstanceOfType(LocaleConfigService.class);
+ LocalePolicy localePolicy = (LocalePolicy) container.getComponentInstanceOfType(LocalePolicy.class);
+
+ LocaleContextInfo localeCtx = new LocaleContextInfo();
+
+ Set<Locale> supportedLocales = new HashSet();
+ for (LocaleConfig lc: localeConfigService.getLocalConfigs())
+ {
+ supportedLocales.add(lc.getLocale());
+ }
+ localeCtx.setSupportedLocales(supportedLocales);
+
+ HttpServletRequest request = HttpServletRequest.class.cast(context.getRequest());
+ localeCtx.setBrowserLocales(Collections.list(request.getLocales()));
+
+ localeCtx.setCookieLocales(getCookieLocales(request));
+ localeCtx.setUserProfileLocale(getUserProfileLocale(reqCtx));
+ localeCtx.setRemoteUser(reqCtx.getRemoteUser());
+
+ UserPortalConfig userPortalConfig = null;
+ try
+ {
+ userPortalConfig = PortalStateManager.getUserPortalConfig(reqCtx);
+ if (userPortalConfig == null)
+ log.warn("No UserPortalConfig available! Portal locale set to 'en'");
+ }
+ catch(Exception ignored)
+ {
+ if (log.isDebugEnabled())
+ log.debug("IGNORED: Failed to load UserPortalConfig: ", ignored);
+ }
+
+ String portalLocaleName = "en";
+ if (userPortalConfig != null)
+ portalLocaleName = userPortalConfig.getPortalConfig().getLocale();
+
+ Locale portalLocale = LocaleContextInfo.getLocale(portalLocaleName);
+ localeCtx.setPortalLocale(portalLocale);
+
+ Locale locale = localePolicy.determineLocale(localeCtx);
+ if (!supportedLocales.contains(locale))
+ {
+ if (log.isWarnEnabled())
+ log.warn("Unsupported locale returned by LocalePolicy: " + localePolicy + ". Falling back to 'en'.");
+ locale = Locale.ENGLISH;
+ }
+ reqCtx.setLocale(locale);
+ calculatedLocale.set(locale);
+ }
+
+ /**
+ * @see org.exoplatform.web.application.ApplicationRequestPhaseLifecycle#onStartRequestPhase
+ */
+ public void onStartRequestPhase(Application app, WebuiRequestContext context, Phase phase)
+ {
+ }
+
+ /**
+ * Save any locale change - to cookie for anonymous users, to profile for logged-in users
+ *
+ * @see org.exoplatform.web.application.ApplicationRequestPhaseLifecycle#onEndRequestPhase
+ */
+ public void onEndRequestPhase(Application app, WebuiRequestContext context, Phase phase)
+ {
+ if (phase == Phase.ACTION)
+ {
+ // if onStartRequest survived the cast, this one should as well - no check necessary
+ PortalRequestContext reqCtx = (PortalRequestContext) context;
+ Locale loc = reqCtx.getLocale();
+ Locale remembered = calculatedLocale.get();
+ calculatedLocale.remove();
+ if (loc != null && (remembered == null || !loc.equals(remembered)))
+ saveLocale(reqCtx, loc);
+ }
+ }
+
+ /**
+ * @see org.exoplatform.web.application.ApplicationLifecycle#onEndRequest
+ */
+ public void onEndRequest(Application app, WebuiRequestContext context) throws Exception
+ {
+ }
+
+ /**
+ * @see org.exoplatform.web.application.ApplicationLifecycle#onFailRequest
+ */
+ public void onFailRequest(Application app, WebuiRequestContext context, RequestFailure failureType) throws Exception
+ {
+ }
+
+ /**
+ * @see org.exoplatform.web.application.ApplicationLifecycle#onDestroy
+ */
+ public void onDestroy(Application app) throws Exception
+ {
+ }
+
+ /**
+ * Use {@link UserProfile} already loaded by {@link org.exoplatform.portal.application.UserProfileLifecycle} or load one ourselves.
+ * @param context current PortalRequestContext
+ * @return Locale from user's profile or null
+ */
+ private Locale getUserProfileLocale(PortalRequestContext context)
+ {
+ String lang = null;
+
+ UserProfile userProfile = getLoadedProfile(context);
+ lang = userProfile == null ? null : userProfile.getUserInfoMap().get(Constants.USER_LANGUAGE);
+ return (lang != null) ? new Locale(lang) : null;
+ }
+
+ private UserProfile loadUserProfile(ExoContainer container, PortalRequestContext context)
+ {
+ UserProfile userProfile = null;
+ OrganizationService svc = (OrganizationService)
+ container.getComponentInstanceOfType(OrganizationService.class);
+
+ String user = context.getRemoteUser();
+ if (user != null)
+ {
+ try
+ {
+ userProfile = svc.getUserProfileHandler().findUserProfileByName(user);
+ }
+ catch (Exception ignored)
+ {
+ log.error("IGNORED: Failed to load UserProfile for username: " + user, ignored);
+ }
+
+ if (userProfile == null && log.isWarnEnabled())
+ log.warn("Could not load user profile for " + user + ". Using default portal locale.");
+ }
+ return userProfile;
+ }
+
+ private UserProfile getLoadedProfile(PortalRequestContext context)
+ {
+ return (UserProfile) context.getAttribute(UserProfileLifecycle.USER_PROFILE_ATTRIBUTE_NAME);
+ }
+
+ public static List<Locale> getCookieLocales(HttpServletRequest request)
+ {
+ Cookie [] cookies = request.getCookies();
+ if (cookies != null)
+ {
+ for (Cookie cookie: cookies)
+ {
+ if (COOKIE_NAME.equals(cookie.getName()))
+ {
+ List<Locale> locales = new ArrayList<Locale>();
+ locales.add(LocaleContextInfo.getLocale(cookie.getValue()));
+ return locales;
+ }
+ }
+ }
+ return Collections.emptyList();
+ }
+
+ private void saveLocale(PortalRequestContext context, Locale loc)
+ {
+ String user = context.getRemoteUser();
+ if (user != null)
+ {
+ saveLocaleToUserProfile(context, loc, user);
+ }
+ else
+ {
+ saveLocaleToCookie(context, loc);
+ }
+ }
+
+ private void saveLocaleToCookie(PortalRequestContext context, Locale loc)
+ {
+ HttpServletResponse res = context.getResponse();
+ Cookie cookie = new Cookie(COOKIE_NAME, LocaleContextInfo.getLocaleAsString(loc));
+ cookie.setMaxAge(Integer.MAX_VALUE);
+ cookie.setPath("/");
+ res.addCookie(cookie);
+ }
+
+ private void saveLocaleToUserProfile(PortalRequestContext context, Locale loc, String user)
+ {
+ ExoContainer container = context.getApplication().getApplicationServiceContainer();
+ OrganizationService svc = (OrganizationService)
+ container.getComponentInstanceOfType(OrganizationService.class);
+
+ // Don't rely on UserProfileLifecycle loaded UserProfile when doing
+ // an update to avoid a potential overwrite of other changes
+ UserProfile userProfile = loadUserProfile(container, context);
+ if (userProfile != null)
+ {
+ userProfile.getUserInfoMap().put(Constants.USER_LANGUAGE, loc.getLanguage());
+ try
+ {
+ svc.getUserProfileHandler().saveUserProfile(userProfile, false);
+ }
+ catch (Exception ignored)
+ {
+ log.error("IGNORED: Failed to save profile for user: " + user, ignored);
+ userProfile = null;
+ }
+ }
+
+ if (userProfile == null)
+ {
+ if (log.isWarnEnabled())
+ log.warn("Unable to save locale into profile for user: " + user);
+ }
+ }
+}
Deleted: portal/trunk/webui/portal/src/main/java/org/exoplatform/portal/application/localization/NoBrowserLocalePolicyService.java
===================================================================
--- portal/branches/branched-r3776/webui/portal/src/main/java/org/exoplatform/portal/application/localization/NoBrowserLocalePolicyService.java 2010-08-13 17:09:39 UTC (rev 3829)
+++ portal/trunk/webui/portal/src/main/java/org/exoplatform/portal/application/localization/NoBrowserLocalePolicyService.java 2010-08-16 03:50:59 UTC (rev 3830)
@@ -1,47 +0,0 @@
-/*
- * JBoss, Home of Professional Open Source
- * Copyright 2010, Red Hat, Inc., and individual contributors
- * by the @authors tag. See the copyright.txt in the distribution for a
- * full listing of individual contributors.
- *
- * This is free software; you can redistribute it and/or modify it
- * under the terms of the GNU Lesser General Public License as
- * published by the Free Software Foundation; either version 2.1 of
- * the License, or (at your option) any later version.
- *
- * This software is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this software; if not, write to the Free
- * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
- * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
- */
-package org.exoplatform.portal.application.localization;
-
-import org.exoplatform.services.resources.LocaleContextInfo;
-
-import java.util.Locale;
-
-/**
- * This implementation of {@link org.exoplatform.services.resources.LocalePolicy} disregards client browser language preference.
- * Localization will therefore not be affected by different OS or browser language settings.
- *
- * @author <a href="mailto:mstrukel@redhat.com">Marko Strukelj</a>
- */
-public class NoBrowserLocalePolicyService extends DefaultLocalePolicyService
-{
- /**
- * Override super method with no-op.
- *
- * @param context locale context info available to implementations in order to determine appropriate Locale
- * @return null
- */
- @Override
- protected Locale getLocaleConfigFromBrowser(LocaleContextInfo context)
- {
- return null;
- }
-}
Copied: portal/trunk/webui/portal/src/main/java/org/exoplatform/portal/application/localization/NoBrowserLocalePolicyService.java (from rev 3829, portal/branches/branched-r3776/webui/portal/src/main/java/org/exoplatform/portal/application/localization/NoBrowserLocalePolicyService.java)
===================================================================
--- portal/trunk/webui/portal/src/main/java/org/exoplatform/portal/application/localization/NoBrowserLocalePolicyService.java (rev 0)
+++ portal/trunk/webui/portal/src/main/java/org/exoplatform/portal/application/localization/NoBrowserLocalePolicyService.java 2010-08-16 03:50:59 UTC (rev 3830)
@@ -0,0 +1,47 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2010, Red Hat, Inc., and individual contributors
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.exoplatform.portal.application.localization;
+
+import org.exoplatform.services.resources.LocaleContextInfo;
+
+import java.util.Locale;
+
+/**
+ * This implementation of {@link org.exoplatform.services.resources.LocalePolicy} disregards client browser language preference.
+ * Localization will therefore not be affected by different OS or browser language settings.
+ *
+ * @author <a href="mailto:mstrukel@redhat.com">Marko Strukelj</a>
+ */
+public class NoBrowserLocalePolicyService extends DefaultLocalePolicyService
+{
+ /**
+ * Override super method with no-op.
+ *
+ * @param context locale context info available to implementations in order to determine appropriate Locale
+ * @return null
+ */
+ @Override
+ protected Locale getLocaleConfigFromBrowser(LocaleContextInfo context)
+ {
+ return null;
+ }
+}
Modified: portal/trunk/webui/portal/src/main/java/org/exoplatform/portal/webui/application/ExoPortletInvocationContext.java
===================================================================
--- portal/trunk/webui/portal/src/main/java/org/exoplatform/portal/webui/application/ExoPortletInvocationContext.java 2010-08-13 17:09:39 UTC (rev 3829)
+++ portal/trunk/webui/portal/src/main/java/org/exoplatform/portal/webui/application/ExoPortletInvocationContext.java 2010-08-16 03:50:59 UTC (rev 3830)
@@ -199,7 +199,7 @@
}
Mode mode = renderURL.getMode();
- if (mode != null && !mode.equals(Mode.VIEW))
+ if (mode != null)
{
appendParameter(baseURL, Constants.PORTLET_MODE_PARAMETER, mode.toString());
}
Modified: portal/trunk/webui/portal/src/main/java/org/exoplatform/portal/webui/application/ExoUserContext.java
===================================================================
--- portal/trunk/webui/portal/src/main/java/org/exoplatform/portal/webui/application/ExoUserContext.java 2010-08-13 17:09:39 UTC (rev 3829)
+++ portal/trunk/webui/portal/src/main/java/org/exoplatform/portal/webui/application/ExoUserContext.java 2010-08-16 03:50:59 UTC (rev 3830)
@@ -19,8 +19,8 @@
package org.exoplatform.portal.webui.application;
+import org.exoplatform.portal.application.PortalRequestContext;
import org.exoplatform.services.organization.UserProfile;
-import org.gatein.common.util.Tools;
import org.gatein.pc.api.invocation.resolver.AttributeResolver;
import org.gatein.pc.api.invocation.resolver.PrincipalAttributeResolver;
import org.gatein.pc.api.spi.UserContext;
@@ -29,6 +29,7 @@
import java.util.Enumeration;
import java.util.HashMap;
import java.util.HashSet;
+import java.util.LinkedList;
import java.util.List;
import java.util.Locale;
import java.util.Map;
@@ -119,23 +120,52 @@
return Collections.unmodifiableMap(filteredMap);
}
- /** Returns the client request locale or <code>Locale.ENGLISH</code> if no request was provided. */
+ /**
+ * Returns current PortalRequestContext's locale. It falls back to
+ * clientRequest locale ({@link HttpServletRequest#getLocale}), or <code>Locale.ENGLISH</code>
+ * if clientRequest object is not available.
+ */
public Locale getLocale()
{
+ PortalRequestContext context = PortalRequestContext.getCurrentInstance();
+
+ if(context != null) {
+ Locale loc = context.getLocale();
+ if (loc != null)
+ return loc;
+ }
+
return clientRequest != null ? clientRequest.getLocale() : Locale.ENGLISH;
}
- /** Returns the client request locales or an empty list if no request was provided. */
+ /**
+ * Returns the list of client request locales, making sure the first one in the List
+ * is the same as what getLocale() method returns.
+ */
@SuppressWarnings("unchecked")
public List<Locale> getLocales()
{
- if (clientRequest == null)
+ Locale loc = getLocale();
+ if (loc == null)
{
return EMPTY_LOCALE_LIST;
}
else
{
- return Tools.toList((Enumeration<Locale>)clientRequest.getLocales());
+ LinkedList<Locale> locs = new LinkedList<Locale>();
+ locs.add(loc);
+ if (clientRequest != null)
+ {
+ Enumeration<Locale> clientLocs = (Enumeration<Locale>) clientRequest.getLocales();
+ while (clientLocs.hasMoreElements())
+ {
+ Locale current = clientLocs.nextElement();
+ if (current.getLanguage().equals(loc.getLanguage()) && current.getCountry().equals(loc.getCountry()))
+ continue;
+ locs.add(current);
+ }
+ }
+ return Collections.unmodifiableList(locs);
}
}
Modified: portal/trunk/webui/portal/src/main/java/org/exoplatform/portal/webui/application/UIGadget.java
===================================================================
--- portal/trunk/webui/portal/src/main/java/org/exoplatform/portal/webui/application/UIGadget.java 2010-08-13 17:09:39 UTC (rev 3829)
+++ portal/trunk/webui/portal/src/main/java/org/exoplatform/portal/webui/application/UIGadget.java 2010-08-16 03:50:59 UTC (rev 3830)
@@ -21,6 +21,7 @@
import org.exoplatform.application.gadget.Gadget;
import org.exoplatform.application.gadget.GadgetRegistryService;
+import org.exoplatform.commons.utils.PropertyManager;
import org.exoplatform.container.ExoContainerContext;
import org.exoplatform.portal.config.DataStorage;
import org.exoplatform.portal.config.model.ApplicationState;
@@ -298,50 +299,24 @@
public boolean isNoCache()
{
- /*
- * try { UserGadgetStorage userGadgetStorage = getGadgetStorage(); String
- * username = Util.getPortalRequestContext().getRemoteUser(); if(username !=
- * null) { String prefs = userGadgetStorage.get(username,
- * getApplicationName(), getApplicationInstanceUniqueId(), PREF_NO_CACHE);
- * return prefs.equals("1"); } } catch (Exception e) {} return false;
- */
- return true;
+ if(PropertyManager.isDevelopping())
+ return true;
+ return false;
}
public void setNoCache(boolean value)
{
- /*
- * try { UserGadgetStorage userGadgetStorage = getGadgetStorage(); String
- * username = Util.getPortalRequestContext().getRemoteUser(); if(username !=
- * null && getGadgetRegistryService().isGadgetDeveloper(username)) {
- * userGadgetStorage.save(username, getApplicationName(),
- * getApplicationInstanceUniqueId(), PREF_NO_CACHE, value ? "1" : "0"); } }
- * catch (Exception e) {}
- */
}
public boolean isDebug()
{
- /*
- * try { UserGadgetStorage userGadgetStorage = getGadgetStorage(); String
- * username = Util.getPortalRequestContext().getRemoteUser(); if(username !=
- * null) { String prefs = userGadgetStorage.get(username,
- * getApplicationName(), getApplicationInstanceUniqueId(), PREF_DEBUG);
- * return prefs.equals("1"); } } catch (Exception e) {} return false;
- */
- return true;
+ if(PropertyManager.isDevelopping())
+ return true;
+ return false;
}
public void setDebug(boolean value)
{
- /*
- * try { UserGadgetStorage userGadgetStorage = getGadgetStorage(); String
- * username = Util.getPortalRequestContext().getRemoteUser(); if(username !=
- * null && getGadgetRegistryService().isGadgetDeveloper(username)) {
- * userGadgetStorage.save(username, getApplicationName(),
- * getApplicationInstanceUniqueId(), PREF_DEBUG, value ? "1" : "0"); } }
- * catch (Exception e) {}
- */
}
public boolean isGadgetDeveloper()
@@ -377,11 +352,7 @@
public void addUserPref(String addedUserPref) throws Exception
{
DataStorage service = getApplicationComponent(DataStorage.class);
- org.exoplatform.portal.pom.spi.gadget.Gadget gadget = service.load(state, ApplicationType.GADGET);
- if (gadget == null)
- {
- gadget = new org.exoplatform.portal.pom.spi.gadget.Gadget();
- }
+ org.exoplatform.portal.pom.spi.gadget.Gadget gadget = new org.exoplatform.portal.pom.spi.gadget.Gadget();
//
gadget.addUserPref(addedUserPref);
Modified: portal/trunk/webui/portal/src/main/java/org/exoplatform/portal/webui/application/UIPortletLifecycle.java
===================================================================
--- portal/trunk/webui/portal/src/main/java/org/exoplatform/portal/webui/application/UIPortletLifecycle.java 2010-08-13 17:09:39 UTC (rev 3829)
+++ portal/trunk/webui/portal/src/main/java/org/exoplatform/portal/webui/application/UIPortletLifecycle.java 2010-08-16 03:50:59 UTC (rev 3830)
@@ -186,94 +186,93 @@
RenderInvocation renderInvocation = uicomponent.create(RenderInvocation.class, prcontext);
- if (uicomponent.getCurrentWindowState() != WindowState.MINIMIZED)
+ String appStatus = uicomponent.getProperties().get("appStatus");
+ if ("Window".equals(uicomponent.getPortletStyle()) && !("SHOW".equals(appStatus) || "HIDE".equals(appStatus)))
{
- String appStatus = uicomponent.getProperties().get("appStatus");
- if ("Window".equals(uicomponent.getPortletStyle())
- && !("SHOW".equals(appStatus) || "HIDE".equals(appStatus)))
+ markup = Text.create("<span></span>");
+ }
+ else
+ {
+ int portalMode = Util.getUIPortalApplication().getModeState();
+
+ //Check mode of portal, portlet and permission for viewable
+ if ((portalMode == UIPortalApplication.NORMAL_MODE || portalMode == UIPortalApplication.APP_VIEW_EDIT_MODE
+ || portalMode == UIPortalApplication.CONTAINER_VIEW_EDIT_MODE || uicomponent.getCurrentPortletMode()
+ .equals(PortletMode.EDIT))
+ && uicomponent.hasPermission())
{
- markup = Text.create("<span></span>");
- }
- else
- {
- int portalMode = Util.getUIPortalApplication().getModeState();
-
- //Check mode of portal, portlet and permission for viewable
- if ((portalMode == UIPortalApplication.NORMAL_MODE || portalMode == UIPortalApplication.APP_VIEW_EDIT_MODE
- || portalMode == UIPortalApplication.CONTAINER_VIEW_EDIT_MODE || uicomponent.getCurrentPortletMode().equals(PortletMode.EDIT))
- && uicomponent.hasPermission())
+ PortletInvocationResponse response = uicomponent.invoke(renderInvocation);
+ if (response instanceof FragmentResponse)
{
- PortletInvocationResponse response = uicomponent.invoke(renderInvocation);
- if (response instanceof FragmentResponse)
+ FragmentResponse fragmentResponse = (FragmentResponse) response;
+ switch (fragmentResponse.getType())
{
- FragmentResponse fragmentResponse = (FragmentResponse)response;
- switch (fragmentResponse.getType())
- {
- case FragmentResponse.TYPE_CHARS:
- markup = Text.create(fragmentResponse.getContent());
- break;
- case FragmentResponse.TYPE_BYTES:
- markup = Text.create(fragmentResponse.getBytes(), Charset.forName("UTF-8"));
- break;
- case FragmentResponse.TYPE_EMPTY:
- markup = Text.create("");
- break;
- }
- portletTitle = fragmentResponse.getTitle();
+ case FragmentResponse.TYPE_CHARS :
+ markup = Text.create(fragmentResponse.getContent());
+ break;
+ case FragmentResponse.TYPE_BYTES :
+ markup = Text.create(fragmentResponse.getBytes(), Charset.forName("UTF-8"));
+ break;
+ case FragmentResponse.TYPE_EMPTY :
+ markup = Text.create("");
+ break;
+ }
+ portletTitle = fragmentResponse.getTitle();
- // setup portlet properties
- if (fragmentResponse.getProperties() != null)
- {
- //setup transport headers
- if (fragmentResponse.getProperties().getTransportHeaders() != null)
- {
- MultiValuedPropertyMap<String> transportHeaders =
- fragmentResponse.getProperties().getTransportHeaders();
- for (String key : transportHeaders.keySet())
- {
- for (String value : transportHeaders.getValues(key))
- {
- prcontext.getResponse().setHeader(key, value);
- }
- }
- }
-
- //setup up portlet cookies
- if (fragmentResponse.getProperties().getCookies() != null)
- {
- List<Cookie> cookies = fragmentResponse.getProperties().getCookies();
- for (Cookie cookie : cookies)
- {
- prcontext.getResponse().addCookie(cookie);
- }
- }
+ // setup portlet properties
+ if (fragmentResponse.getProperties() != null)
+ {
+ //setup transport headers
+ if (fragmentResponse.getProperties().getTransportHeaders() != null)
+ {
+ MultiValuedPropertyMap<String> transportHeaders = fragmentResponse.getProperties()
+ .getTransportHeaders();
+ for (String key : transportHeaders.keySet())
+ {
+ for (String value : transportHeaders.getValues(key))
+ {
+ prcontext.getResponse().setHeader(key, value);
+ }
+ }
+ }
- //setup markup headers
- if (fragmentResponse.getProperties().getMarkupHeaders() != null)
- {
- MultiValuedPropertyMap<Element> markupHeaders =
- fragmentResponse.getProperties().getMarkupHeaders();
+ //setup up portlet cookies
+ if (fragmentResponse.getProperties().getCookies() != null)
+ {
+ List<Cookie> cookies = fragmentResponse.getProperties().getCookies();
+ for (Cookie cookie : cookies)
+ {
+ prcontext.getResponse().addCookie(cookie);
+ }
+ }
- List<Element> markupElements = markupHeaders.getValues(MimeResponse.MARKUP_HEAD_ELEMENT);
- if (markupElements != null)
- {
- for (Element element : markupElements)
- {
- if ("title".equals(element.getNodeName().toLowerCase()) && element.getFirstChild() != null)
- {
- String title = element.getFirstChild().getTextContent();
- prcontext.getRequest().setAttribute(PortalRequestContext.REQUEST_TITLE, title);
- }
- else
- {
- prcontext.addExtraMarkupHeader(element);
- }
- }
- }
- }
- }
+ //setup markup headers
+ if (fragmentResponse.getProperties().getMarkupHeaders() != null)
+ {
+ MultiValuedPropertyMap<Element> markupHeaders = fragmentResponse.getProperties()
+ .getMarkupHeaders();
+ List<Element> markupElements = markupHeaders.getValues(MimeResponse.MARKUP_HEAD_ELEMENT);
+ if (markupElements != null)
+ {
+ for (Element element : markupElements)
+ {
+ if ("title".equals(element.getNodeName().toLowerCase())
+ && element.getFirstChild() != null)
+ {
+ String title = element.getFirstChild().getTextContent();
+ prcontext.getRequest().setAttribute(PortalRequestContext.REQUEST_TITLE, title);
+ }
+ else
+ {
+ prcontext.addExtraMarkupHeader(element);
+ }
+ }
+ }
+ }
}
+
+ }
else
{
@@ -306,8 +305,7 @@
}
}
}
- }
- }
+ }
catch (Exception e)
{
PortletContainerException pcException = new PortletContainerException(e);
@@ -325,12 +323,6 @@
}
//
- if (portletTitle == null)
- {
- portletTitle = "Portlet";
- }
-
- //
if (context.useAjax() && !prcontext.getFullRender())
{
if (markup != null)
Modified: portal/trunk/webui/portal/src/main/java/org/exoplatform/portal/webui/portal/UILanguageSelector.java
===================================================================
--- portal/trunk/webui/portal/src/main/java/org/exoplatform/portal/webui/portal/UILanguageSelector.java 2010-08-13 17:09:39 UTC (rev 3829)
+++ portal/trunk/webui/portal/src/main/java/org/exoplatform/portal/webui/portal/UILanguageSelector.java 2010-08-16 03:50:59 UTC (rev 3830)
@@ -21,21 +21,13 @@
import org.exoplatform.container.ExoContainer;
import org.exoplatform.container.ExoContainerContext;
-import org.exoplatform.portal.Constants;
-import org.exoplatform.portal.config.model.PageNavigation;
-import org.exoplatform.portal.config.model.PageNode;
-import org.exoplatform.portal.config.model.PortalConfig;
+import org.exoplatform.portal.application.PortalRequestContext;
import org.exoplatform.portal.webui.util.Util;
import org.exoplatform.portal.webui.workspace.UIMaskWorkspace;
import org.exoplatform.portal.webui.workspace.UIPortalApplication;
-import org.exoplatform.services.organization.OrganizationService;
-import org.exoplatform.services.organization.UserProfile;
-import org.exoplatform.services.organization.UserProfileHandler;
import org.exoplatform.services.resources.LocaleConfig;
import org.exoplatform.services.resources.LocaleConfigService;
-import org.exoplatform.services.resources.ResourceBundleManager;
import org.exoplatform.services.resources.ResourceBundleService;
-import org.exoplatform.webui.application.WebuiRequestContext;
import org.exoplatform.webui.config.annotation.ComponentConfig;
import org.exoplatform.webui.config.annotation.EventConfig;
import org.exoplatform.webui.core.UIContainer;
@@ -180,18 +172,10 @@
LocaleConfig localeConfig = localeConfigService.getLocaleConfig(language);
if (localeConfig == null)
localeConfig = localeConfigService.getDefaultLocaleConfig();
- uiApp.setLocale(localeConfig.getLocale());
+ PortalRequestContext prqCtx = PortalRequestContext.getCurrentInstance();
+ prqCtx.setLocale(localeConfig.getLocale());
uiApp.setOrientation(localeConfig.getOrientation());
uiApp.localizeNavigations();
- OrganizationService orgService = event.getSource().getApplicationComponent(OrganizationService.class);
- String remoteUser = event.getRequestContext().getRemoteUser();
- if (remoteUser != null)
- {
- UserProfile userProfile = orgService.getUserProfileHandler().findUserProfileByName(remoteUser);
- userProfile.getUserInfoMap().put(Constants.USER_LANGUAGE, language);
- UserProfileHandler hanlder = orgService.getUserProfileHandler();
- hanlder.saveUserProfile(userProfile, true);
- }
}
}
Modified: portal/trunk/webui/portal/src/main/java/org/exoplatform/portal/webui/portal/UIPortal.java
===================================================================
--- portal/trunk/webui/portal/src/main/java/org/exoplatform/portal/webui/portal/UIPortal.java 2010-08-13 17:09:39 UTC (rev 3829)
+++ portal/trunk/webui/portal/src/main/java/org/exoplatform/portal/webui/portal/UIPortal.java 2010-08-16 03:50:59 UTC (rev 3830)
@@ -238,7 +238,7 @@
uiPageBody.setPageBody(selectedNode_, this);
//Refresh locale
- Locale locale = Util.getUIPortalApplication().getLocale();
+ Locale locale = Util.getPortalRequestContext().getLocale();
localizePageNavigation(navigation, locale);
}
Modified: portal/trunk/webui/portal/src/main/java/org/exoplatform/portal/webui/portal/UIPortalComposer.java
===================================================================
--- portal/trunk/webui/portal/src/main/java/org/exoplatform/portal/webui/portal/UIPortalComposer.java 2010-08-13 17:09:39 UTC (rev 3829)
+++ portal/trunk/webui/portal/src/main/java/org/exoplatform/portal/webui/portal/UIPortalComposer.java 2010-08-16 03:50:59 UTC (rev 3830)
@@ -220,7 +220,7 @@
// TODO dang.tung - change layout when portal get language from UIPortal
// (user and browser not support)
// ----------------------------------------------------------------------------------------------------
- String portalAppLanguage = uiPortalApp.getLocale().getLanguage();
+ String portalAppLanguage = prContext.getLocale().getLanguage();
OrganizationService orgService = getApplicationComponent(OrganizationService.class);
UserProfile userProfile = orgService.getUserProfileHandler().findUserProfileByName(remoteUser);
String userLanguage = userProfile.getUserInfoMap().get(Constants.USER_LANGUAGE);
@@ -231,7 +231,7 @@
{
if (!portalAppLanguage.equals(userLanguage) && !portalAppLanguage.equals(browserLanguage))
{
- uiPortalApp.setLocale(localeConfig.getLocale());
+ prContext.setLocale(localeConfig.getLocale());
//editPortal.refreshNavigation(localeConfig.getLocale());
uiPortalApp.localizeNavigations();
}
Modified: portal/trunk/webui/portal/src/main/java/org/exoplatform/portal/webui/workspace/UIPortalApplication.java
===================================================================
--- portal/trunk/webui/portal/src/main/java/org/exoplatform/portal/webui/workspace/UIPortalApplication.java 2010-08-13 17:09:39 UTC (rev 3829)
+++ portal/trunk/webui/portal/src/main/java/org/exoplatform/portal/webui/workspace/UIPortalApplication.java 2010-08-16 03:50:59 UTC (rev 3830)
@@ -46,6 +46,7 @@
import org.exoplatform.services.organization.UserProfile;
import org.exoplatform.services.resources.LocaleConfig;
import org.exoplatform.services.resources.LocaleConfigService;
+import org.exoplatform.services.resources.LocaleContextInfo;
import org.exoplatform.services.resources.Orientation;
import org.exoplatform.services.resources.ResourceBundleManager;
import org.exoplatform.web.application.javascript.JavascriptConfigService;
@@ -94,8 +95,6 @@
private String nodePath_;
- private Locale locale_ = Locale.ENGLISH;
-
private Orientation orientation_ = Orientation.LT;
final static public String UI_WORKING_WS_ID = "UIWorkingWorkspace";
@@ -144,10 +143,9 @@
// dang.tung - set portal language by user preference -> browser ->
// default
// ------------------------------------------------------------------------------
- String portalLanguage = null;
LocaleConfigService localeConfigService = getApplicationComponent(LocaleConfigService.class);
OrganizationService orgService = getApplicationComponent(OrganizationService.class);
- LocaleConfig localeConfig = localeConfigService.getLocaleConfig(userPortalConfig_.getPortalConfig().getLocale());
+
String user = context.getRemoteUser();
String portalSkin = null;
@@ -156,7 +154,6 @@
UserProfile userProfile = orgService.getUserProfileHandler().findUserProfileByName(user);
if (userProfile != null)
{
- portalLanguage = userProfile.getUserInfoMap().get(Constants.USER_LANGUAGE);
portalSkin = userProfile.getUserInfoMap().get(Constants.USER_SKIN);
}
else
@@ -165,24 +162,25 @@
log.warn("Could not load user profile for " + user + ". Using default portal locale.");
}
}
- localeConfig = localeConfigService.getLocaleConfig(portalLanguage);
- String localeLanguage = (localeConfig.getLocale().getCountry().length() > 0) ? localeConfig.getLocale()
- .getLanguage()
- + "_" + localeConfig.getLocale().getCountry() : localeConfig.getLocale().getLanguage();
- if (portalLanguage == null || !portalLanguage.equals(localeLanguage))
+
+ Locale locale = context.getLocale();
+ if (locale == null)
{
- // if user language no support by portal -> get browser language if no
- // ->
- // get portal
- portalLanguage = context.getRequest().getLocale().getLanguage();
- localeConfig = localeConfigService.getLocaleConfig(portalLanguage);
- if (!portalLanguage.equals(localeConfig.getLanguage()))
- {
- localeConfig = localeConfigService.getLocaleConfig(userPortalConfig_.getPortalConfig().getLocale());
- }
+ if (log.isWarnEnabled())
+ log.warn("No locale set on PortalRequestContext! Falling back to 'en'.");
+ locale = Locale.ENGLISH;
}
- setLocale(localeConfig.getLocale());
+
+ String localeName = LocaleContextInfo.getLocaleAsString(locale);
+ LocaleConfig localeConfig = localeConfigService.getLocaleConfig(localeName);
+ if (localeConfig == null)
+ {
+ if (log.isWarnEnabled())
+ log.warn("Unsupported locale set on PortalRequestContext: " + localeName + "! Falling back to 'en'.");
+ localeConfig = localeConfigService.getLocaleConfig(Locale.ENGLISH.getLanguage());
+ }
setOrientation(localeConfig.getOrientation());
+
// -------------------------------------------------------------------------------
context.setUIApplication(this);
@@ -305,14 +303,9 @@
public Locale getLocale()
{
- return locale_;
+ return Util.getPortalRequestContext().getLocale();
}
- public void setLocale(Locale locale)
- {
- locale_ = locale;
- }
-
public void setModeState(int mode)
{
this.modeState = mode;
Modified: portal/trunk/webui/portlet/src/main/java/org/exoplatform/webui/core/UIPortletApplication.java
===================================================================
--- portal/trunk/webui/portlet/src/main/java/org/exoplatform/webui/core/UIPortletApplication.java 2010-08-13 17:09:39 UTC (rev 3829)
+++ portal/trunk/webui/portlet/src/main/java/org/exoplatform/webui/core/UIPortletApplication.java 2010-08-16 03:50:59 UTC (rev 3830)
@@ -21,11 +21,14 @@
import org.exoplatform.webui.application.WebuiApplication;
import org.exoplatform.webui.application.WebuiRequestContext;
+import org.exoplatform.webui.application.portlet.PortletRequestContext;
import org.exoplatform.commons.serialization.api.annotations.Serialized;
import java.io.Writer;
import java.util.Set;
+import javax.portlet.WindowState;
+
@Serialized
abstract public class UIPortletApplication extends UIApplication
{
@@ -70,7 +73,8 @@
}
/**
- * The default processRender for an UIPortletApplication handles two cases:
+ * The default processRender for an UIPortletApplication does nothing if the current WindowState in the
+ * render request is MINIMIZED. Otherwise, it handles two cases:
*
* A. Ajax is used
* ---------------
@@ -86,7 +90,15 @@
*/
public void processRender(WebuiApplication app, WebuiRequestContext context) throws Exception
{
+ //Do nothing if WindowState in the render request is MINIMIZED
+ WindowState currentWindowState = ((PortletRequestContext)context).getRequest().getWindowState();
+ if(currentWindowState == WindowState.MINIMIZED)
+ {
+ return;
+ }
+
WebuiRequestContext pContext = (WebuiRequestContext)context.getParentAppRequestContext();
+
if (context.useAjax() && !pContext.getFullRender())
{
Writer w = context.getWriter();
14 years, 5 months
gatein SVN: r3829 - in components/wsrp/trunk/producer/src/main/java/org/gatein/wsrp/producer/handlers: processors and 1 other directory.
by do-not-reply@jboss.org
Author: chris.laprun(a)jboss.com
Date: 2010-08-13 13:09:39 -0400 (Fri, 13 Aug 2010)
New Revision: 3829
Modified:
components/wsrp/trunk/producer/src/main/java/org/gatein/wsrp/producer/handlers/MarkupHandler.java
components/wsrp/trunk/producer/src/main/java/org/gatein/wsrp/producer/handlers/processors/ActionRequestProcessor.java
components/wsrp/trunk/producer/src/main/java/org/gatein/wsrp/producer/handlers/processors/EventRequestProcessor.java
components/wsrp/trunk/producer/src/main/java/org/gatein/wsrp/producer/handlers/processors/MimeResponseProcessor.java
components/wsrp/trunk/producer/src/main/java/org/gatein/wsrp/producer/handlers/processors/RenderRequestProcessor.java
components/wsrp/trunk/producer/src/main/java/org/gatein/wsrp/producer/handlers/processors/RequestProcessor.java
components/wsrp/trunk/producer/src/main/java/org/gatein/wsrp/producer/handlers/processors/ResourceRequestProcessor.java
components/wsrp/trunk/producer/src/main/java/org/gatein/wsrp/producer/handlers/processors/UpdateNavigationalStateResponseProcessor.java
Log:
- GTNWSRP-58: Added some generification of classes, not as much win as I had hoped due to lack of reified generics mostly, again. :/
Modified: components/wsrp/trunk/producer/src/main/java/org/gatein/wsrp/producer/handlers/MarkupHandler.java
===================================================================
--- components/wsrp/trunk/producer/src/main/java/org/gatein/wsrp/producer/handlers/MarkupHandler.java 2010-08-13 17:02:50 UTC (rev 3828)
+++ components/wsrp/trunk/producer/src/main/java/org/gatein/wsrp/producer/handlers/MarkupHandler.java 2010-08-13 17:09:39 UTC (rev 3829)
@@ -100,7 +100,7 @@
{
WSRP2ExceptionFactory.throwOperationFailedIfValueIsMissing(getMarkup, GET_MARKUP);
- RequestProcessor requestProcessor = ProcessorFactory.getProcessorFor(producer, getMarkup);
+ RequestProcessor<MarkupResponse> requestProcessor = ProcessorFactory.getProcessorFor(producer, getMarkup);
String handle = requestProcessor.getPortletContext().getPortletHandle();
PortletInvocationResponse response;
@@ -117,7 +117,7 @@
checkForError(response);
- return (MarkupResponse)requestProcessor.processResponse(response);
+ return requestProcessor.processResponse(response);
}
public ResourceResponse getResource(GetResource getResource)
@@ -127,7 +127,7 @@
{
WSRP2ExceptionFactory.throwOperationFailedIfValueIsMissing(getResource, GET_RESOURCE);
- RequestProcessor requestProcessor = ProcessorFactory.getProcessorFor(producer, getResource);
+ RequestProcessor<ResourceResponse> requestProcessor = ProcessorFactory.getProcessorFor(producer, getResource);
String handle = requestProcessor.getPortletContext().getPortletHandle();
PortletInvocationResponse response;
@@ -144,7 +144,7 @@
checkForError(response);
- return (ResourceResponse)requestProcessor.processResponse(response);
+ return requestProcessor.processResponse(response);
}
public BlockingInteractionResponse performBlockingInteraction(PerformBlockingInteraction performBlockingInteraction)
@@ -156,7 +156,7 @@
final InteractionParams interactionParams = performBlockingInteraction.getInteractionParams();
WSRP2ExceptionFactory.throwMissingParametersIfValueIsMissing(interactionParams, "InteractionParams", PBI);
- RequestProcessor requestProcessor = ProcessorFactory.getProcessorFor(producer, performBlockingInteraction);
+ RequestProcessor<BlockingInteractionResponse> requestProcessor = ProcessorFactory.getProcessorFor(producer, performBlockingInteraction);
PortletInvocationResponse response;
String handle = requestProcessor.getPortletContext().getPortletHandle();
@@ -177,7 +177,7 @@
checkForError(response);
- return (BlockingInteractionResponse)requestProcessor.processResponse(response);
+ return requestProcessor.processResponse(response);
}
public List<Extension> releaseSessions(ReleaseSessions releaseSessions)
@@ -210,7 +210,7 @@
PortletStateChangeRequired, ResourceSuspended, UnsupportedLocale, UnsupportedMimeType, UnsupportedMode,
UnsupportedWindowState
{
- RequestProcessor requestProcessor = ProcessorFactory.getProcessorFor(producer, handleEvents);
+ RequestProcessor<HandleEventsResponse> requestProcessor = ProcessorFactory.getProcessorFor(producer, handleEvents);
PortletInvocationResponse response;
String handle = requestProcessor.getPortletContext().getPortletHandle();
@@ -232,7 +232,7 @@
checkForError(response);
- return (HandleEventsResponse)requestProcessor.processResponse(response);
+ return requestProcessor.processResponse(response);
}
private void checkForError(PortletInvocationResponse response)
Modified: components/wsrp/trunk/producer/src/main/java/org/gatein/wsrp/producer/handlers/processors/ActionRequestProcessor.java
===================================================================
--- components/wsrp/trunk/producer/src/main/java/org/gatein/wsrp/producer/handlers/processors/ActionRequestProcessor.java 2010-08-13 17:02:50 UTC (rev 3828)
+++ components/wsrp/trunk/producer/src/main/java/org/gatein/wsrp/producer/handlers/processors/ActionRequestProcessor.java 2010-08-13 17:09:39 UTC (rev 3829)
@@ -35,6 +35,7 @@
import org.gatein.wsrp.producer.WSRPProducerImpl;
import org.gatein.wsrp.producer.handlers.MarkupHandler;
import org.gatein.wsrp.spec.v2.WSRP2ExceptionFactory;
+import org.oasis.wsrp.v2.BlockingInteractionResponse;
import org.oasis.wsrp.v2.InteractionParams;
import org.oasis.wsrp.v2.InvalidHandle;
import org.oasis.wsrp.v2.InvalidRegistration;
@@ -56,7 +57,7 @@
* @version $Revision: 13121 $
* @since 2.6
*/
-class ActionRequestProcessor extends UpdateNavigationalStateResponseProcessor
+class ActionRequestProcessor extends UpdateNavigationalStateResponseProcessor<BlockingInteractionResponse>
{
private final PerformBlockingInteraction performBlockingInteraction;
@@ -125,7 +126,7 @@
return invocation;
}
- public Object processResponse(PortletInvocationResponse response)
+ public BlockingInteractionResponse processResponse(PortletInvocationResponse response)
{
if (response instanceof UpdateNavigationalStateResponse)
{
Modified: components/wsrp/trunk/producer/src/main/java/org/gatein/wsrp/producer/handlers/processors/EventRequestProcessor.java
===================================================================
--- components/wsrp/trunk/producer/src/main/java/org/gatein/wsrp/producer/handlers/processors/EventRequestProcessor.java 2010-08-13 17:02:50 UTC (rev 3828)
+++ components/wsrp/trunk/producer/src/main/java/org/gatein/wsrp/producer/handlers/processors/EventRequestProcessor.java 2010-08-13 17:09:39 UTC (rev 3829)
@@ -63,7 +63,7 @@
* @author <a href="mailto:chris.laprun@jboss.com">Chris Laprun</a>
* @version $Revision$
*/
-class EventRequestProcessor extends UpdateNavigationalStateResponseProcessor
+class EventRequestProcessor extends UpdateNavigationalStateResponseProcessor<HandleEventsResponse>
{
private HandleEvents handleEvents;
@@ -159,7 +159,7 @@
}
@Override
- public Object processResponse(PortletInvocationResponse response)
+ public HandleEventsResponse processResponse(PortletInvocationResponse response)
{
if (response instanceof UpdateNavigationalStateResponse)
{
Modified: components/wsrp/trunk/producer/src/main/java/org/gatein/wsrp/producer/handlers/processors/MimeResponseProcessor.java
===================================================================
--- components/wsrp/trunk/producer/src/main/java/org/gatein/wsrp/producer/handlers/processors/MimeResponseProcessor.java 2010-08-13 17:02:50 UTC (rev 3828)
+++ components/wsrp/trunk/producer/src/main/java/org/gatein/wsrp/producer/handlers/processors/MimeResponseProcessor.java 2010-08-13 17:09:39 UTC (rev 3829)
@@ -38,7 +38,7 @@
* @author <a href="mailto:chris.laprun@jboss.com">Chris Laprun</a>
* @version $Revision$
*/
-abstract class MimeResponseProcessor<LocalMimeResponse extends MimeResponse> extends RequestProcessor
+abstract class MimeResponseProcessor<LocalMimeResponse extends MimeResponse, Response> extends RequestProcessor<Response>
{
protected String namespace;
private static final String EMPTY = "";
@@ -63,7 +63,7 @@
return result;
}
- public Object processResponse(PortletInvocationResponse response)
+ public Response processResponse(PortletInvocationResponse response)
{
ContentResponse content = (ContentResponse)response;
String itemString = null;
@@ -116,7 +116,7 @@
return createResponse(mimeResponse);
}
- protected abstract Object createResponse(LocalMimeResponse mimeResponse);
+ protected abstract Response createResponse(LocalMimeResponse mimeResponse);
protected abstract Class<LocalMimeResponse> getReifiedClass();
Modified: components/wsrp/trunk/producer/src/main/java/org/gatein/wsrp/producer/handlers/processors/RenderRequestProcessor.java
===================================================================
--- components/wsrp/trunk/producer/src/main/java/org/gatein/wsrp/producer/handlers/processors/RenderRequestProcessor.java 2010-08-13 17:02:50 UTC (rev 3828)
+++ components/wsrp/trunk/producer/src/main/java/org/gatein/wsrp/producer/handlers/processors/RenderRequestProcessor.java 2010-08-13 17:09:39 UTC (rev 3829)
@@ -35,6 +35,7 @@
import org.oasis.wsrp.v2.InvalidHandle;
import org.oasis.wsrp.v2.InvalidRegistration;
import org.oasis.wsrp.v2.MarkupContext;
+import org.oasis.wsrp.v2.MarkupResponse;
import org.oasis.wsrp.v2.MimeRequest;
import org.oasis.wsrp.v2.MissingParameters;
import org.oasis.wsrp.v2.OperationFailed;
@@ -50,7 +51,7 @@
* @version $Revision: 13121 $
* @since 2.6
*/
-class RenderRequestProcessor extends MimeResponseProcessor<MarkupContext>
+class RenderRequestProcessor extends MimeResponseProcessor<MarkupContext, MarkupResponse>
{
private final GetMarkup getMarkup;
@@ -107,7 +108,7 @@
}
@Override
- protected Object createResponse(MarkupContext mimeResponse)
+ protected MarkupResponse createResponse(MarkupContext mimeResponse)
{
return WSRPTypeFactory.createMarkupResponse(mimeResponse);
}
Modified: components/wsrp/trunk/producer/src/main/java/org/gatein/wsrp/producer/handlers/processors/RequestProcessor.java
===================================================================
--- components/wsrp/trunk/producer/src/main/java/org/gatein/wsrp/producer/handlers/processors/RequestProcessor.java 2010-08-13 17:02:50 UTC (rev 3828)
+++ components/wsrp/trunk/producer/src/main/java/org/gatein/wsrp/producer/handlers/processors/RequestProcessor.java 2010-08-13 17:09:39 UTC (rev 3829)
@@ -75,7 +75,7 @@
* @version $Revision: 13121 $
* @since 2.6
*/
-public abstract class RequestProcessor
+public abstract class RequestProcessor<Response>
{
private static final String WINDOW_STATE = "window state";
private static final String PORTLET_MODE = "portlet mode";
@@ -190,7 +190,7 @@
abstract PortletInvocation initInvocation(WSRPPortletInvocationContext context);
- public abstract Object processResponse(PortletInvocationResponse response);
+ public abstract Response processResponse(PortletInvocationResponse response);
/**
Modified: components/wsrp/trunk/producer/src/main/java/org/gatein/wsrp/producer/handlers/processors/ResourceRequestProcessor.java
===================================================================
--- components/wsrp/trunk/producer/src/main/java/org/gatein/wsrp/producer/handlers/processors/ResourceRequestProcessor.java 2010-08-13 17:02:50 UTC (rev 3828)
+++ components/wsrp/trunk/producer/src/main/java/org/gatein/wsrp/producer/handlers/processors/ResourceRequestProcessor.java 2010-08-13 17:09:39 UTC (rev 3829)
@@ -42,6 +42,7 @@
import org.oasis.wsrp.v2.RegistrationContext;
import org.oasis.wsrp.v2.ResourceContext;
import org.oasis.wsrp.v2.ResourceParams;
+import org.oasis.wsrp.v2.ResourceResponse;
import org.oasis.wsrp.v2.RuntimeContext;
import org.oasis.wsrp.v2.UnsupportedMimeType;
import org.oasis.wsrp.v2.UnsupportedMode;
@@ -52,7 +53,7 @@
* @author <a href="mailto:mwringe@redhat.com">Matt Wringe</a>
* @version $Revision$
*/
-class ResourceRequestProcessor extends MimeResponseProcessor<ResourceContext>
+class ResourceRequestProcessor extends MimeResponseProcessor<ResourceContext, ResourceResponse>
{
private final GetResource getResource;
@@ -146,7 +147,7 @@
}
@Override
- protected Object createResponse(ResourceContext resourceContext)
+ protected ResourceResponse createResponse(ResourceContext resourceContext)
{
return WSRPTypeFactory.createResourceResponse(resourceContext);
}
Modified: components/wsrp/trunk/producer/src/main/java/org/gatein/wsrp/producer/handlers/processors/UpdateNavigationalStateResponseProcessor.java
===================================================================
--- components/wsrp/trunk/producer/src/main/java/org/gatein/wsrp/producer/handlers/processors/UpdateNavigationalStateResponseProcessor.java 2010-08-13 17:02:50 UTC (rev 3828)
+++ components/wsrp/trunk/producer/src/main/java/org/gatein/wsrp/producer/handlers/processors/UpdateNavigationalStateResponseProcessor.java 2010-08-13 17:09:39 UTC (rev 3829)
@@ -38,7 +38,7 @@
* @author <a href="mailto:chris.laprun@jboss.com">Chris Laprun</a>
* @version $Revision$
*/
-abstract class UpdateNavigationalStateResponseProcessor extends RequestProcessor
+abstract class UpdateNavigationalStateResponseProcessor<Response> extends RequestProcessor<Response>
{
public UpdateNavigationalStateResponseProcessor(WSRPProducerImpl producer)
{
14 years, 5 months
gatein SVN: r3828 - in components/wsrp/trunk: consumer/src/test/java/org/gatein/wsrp/test/support and 4 other directories.
by do-not-reply@jboss.org
Author: mwringe
Date: 2010-08-13 13:02:50 -0400 (Fri, 13 Aug 2010)
New Revision: 3828
Added:
components/wsrp/trunk/wsrp-producer-war/src/test/test-portlets/test-portletstate-portlet-war/WEB-INF/
components/wsrp/trunk/wsrp-producer-war/src/test/test-portlets/test-portletstate-portlet-war/WEB-INF/portlet.xml
components/wsrp/trunk/wsrp-producer-war/src/test/test-portlets/test-portletstate-portlet-war/WEB-INF/web.xml
Modified:
components/wsrp/trunk/consumer/src/main/java/org/gatein/wsrp/consumer/WSRPConsumerImpl.java
components/wsrp/trunk/consumer/src/test/java/org/gatein/wsrp/test/support/MockWSRPConsumer.java
components/wsrp/trunk/producer/src/main/java/org/gatein/wsrp/producer/handlers/PortletManagementHandler.java
components/wsrp/trunk/wsrp-producer-war/src/test/java/org/gatein/wsrp/protocol/v2/PortletManagementTestCase.java
Log:
GTNWSRP-55: Updated for import/export changes added to the PC portlet invoker.
Modified: components/wsrp/trunk/consumer/src/main/java/org/gatein/wsrp/consumer/WSRPConsumerImpl.java
===================================================================
--- components/wsrp/trunk/consumer/src/main/java/org/gatein/wsrp/consumer/WSRPConsumerImpl.java 2010-08-13 14:41:57 UTC (rev 3827)
+++ components/wsrp/trunk/consumer/src/main/java/org/gatein/wsrp/consumer/WSRPConsumerImpl.java 2010-08-13 17:02:50 UTC (rev 3828)
@@ -391,13 +391,13 @@
}
}
- public PortletContext exportPortletContext(PortletStateType stateType, PortletContext originalPortletContext)
+ public PortletContext exportPortlet(PortletStateType stateType, PortletContext originalPortletContext)
throws PortletInvokerException
{
throw new NotYetImplemented();
}
- public PortletContext importPortletContext(PortletStateType stateType, PortletContext originalPortletContext)
+ public PortletContext importPortlet(PortletStateType stateType, PortletContext originalPortletContext)
throws PortletInvokerException
{
throw new NotYetImplemented();
Modified: components/wsrp/trunk/consumer/src/test/java/org/gatein/wsrp/test/support/MockWSRPConsumer.java
===================================================================
--- components/wsrp/trunk/consumer/src/test/java/org/gatein/wsrp/test/support/MockWSRPConsumer.java 2010-08-13 14:41:57 UTC (rev 3827)
+++ components/wsrp/trunk/consumer/src/test/java/org/gatein/wsrp/test/support/MockWSRPConsumer.java 2010-08-13 17:02:50 UTC (rev 3828)
@@ -170,13 +170,13 @@
{
}
- public PortletContext exportPortletContext(PortletStateType stateType, PortletContext originalPortletContext)
+ public PortletContext exportPortlet(PortletStateType stateType, PortletContext originalPortletContext)
throws PortletInvokerException
{
throw new NotYetImplemented();
}
- public PortletContext importPortletContext(PortletStateType stateType, PortletContext originalPortletContext)
+ public PortletContext importPortlet(PortletStateType stateType, PortletContext originalPortletContext)
throws PortletInvokerException
{
throw new NotYetImplemented();
Modified: components/wsrp/trunk/producer/src/main/java/org/gatein/wsrp/producer/handlers/PortletManagementHandler.java
===================================================================
--- components/wsrp/trunk/producer/src/main/java/org/gatein/wsrp/producer/handlers/PortletManagementHandler.java 2010-08-13 14:41:57 UTC (rev 3827)
+++ components/wsrp/trunk/producer/src/main/java/org/gatein/wsrp/producer/handlers/PortletManagementHandler.java 2010-08-13 17:02:50 UTC (rev 3828)
@@ -530,7 +530,7 @@
producer.getPortletInvoker().getPortlet(portalPC);
- org.gatein.pc.api.PortletContext exportedPortalPC = producer.getPortletInvoker().exportPortletContext(PortletStateType.OPAQUE, portalPC);
+ org.gatein.pc.api.PortletContext exportedPortalPC = producer.getPortletInvoker().exportPortlet(PortletStateType.OPAQUE, portalPC);
PortletContext exportedPortalContext = WSRPUtils.convertToWSRPPortletContext(exportedPortalPC);
portletHandle = exportedPortalContext.getPortletHandle();
@@ -654,7 +654,7 @@
PortletContext pc = WSRPTypeFactory.createPortletContext(portletHandle, portletState);
org.gatein.pc.api.PortletContext pcPortletContext = WSRPUtils.convertToPortalPortletContext(pc);
- org.gatein.pc.api.PortletContext cpc = producer.getPortletInvoker().importPortletContext(PortletStateType.OPAQUE, pcPortletContext);
+ org.gatein.pc.api.PortletContext cpc = producer.getPortletInvoker().importPortlet(PortletStateType.OPAQUE, pcPortletContext);
PortletContext wpc = WSRPUtils.convertToWSRPPortletContext(cpc);
ImportedPortlet importedPortlet = WSRPTypeFactory.createImportedPortlet(importPortlet.getImportID(), wpc);
Modified: components/wsrp/trunk/wsrp-producer-war/src/test/java/org/gatein/wsrp/protocol/v2/PortletManagementTestCase.java
===================================================================
--- components/wsrp/trunk/wsrp-producer-war/src/test/java/org/gatein/wsrp/protocol/v2/PortletManagementTestCase.java 2010-08-13 14:41:57 UTC (rev 3827)
+++ components/wsrp/trunk/wsrp-producer-war/src/test/java/org/gatein/wsrp/protocol/v2/PortletManagementTestCase.java 2010-08-13 17:02:50 UTC (rev 3828)
@@ -816,7 +816,6 @@
PortletContext portletContextFromExport = portletContextsFromExport.get(0);
assertEquals(originalHandle, portletContextFromExport.getPortletHandle());
- assertNull(portletContextFromExport.getPortletState());
}
finally
{
Added: components/wsrp/trunk/wsrp-producer-war/src/test/test-portlets/test-portletstate-portlet-war/WEB-INF/portlet.xml
===================================================================
--- components/wsrp/trunk/wsrp-producer-war/src/test/test-portlets/test-portletstate-portlet-war/WEB-INF/portlet.xml (rev 0)
+++ components/wsrp/trunk/wsrp-producer-war/src/test/test-portlets/test-portletstate-portlet-war/WEB-INF/portlet.xml 2010-08-13 17:02:50 UTC (rev 3828)
@@ -0,0 +1,52 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ ~ JBoss, a division of Red Hat ~
+ ~ Copyright 2008, Red Hat Middleware, LLC, and individual ~
+ ~ contributors as indicated by the @authors tag. See the ~
+ ~ copyright.txt in the distribution for a full listing of ~
+ ~ individual contributors. ~
+ ~ ~
+ ~ This is free software; you can redistribute it and/or modify it ~
+ ~ under the terms of the GNU Lesser General Public License as ~
+ ~ published by the Free Software Foundation; either version 2.1 of ~
+ ~ the License, or (at your option) any later version. ~
+ ~ ~
+ ~ This software is distributed in the hope that it will be useful, ~
+ ~ but WITHOUT ANY WARRANTY; without even the implied warranty of ~
+ ~ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU ~
+ ~ Lesser General Public License for more details. ~
+ ~ ~
+ ~ You should have received a copy of the GNU Lesser General Public ~
+ ~ License along with this software; if not, write to the Free ~
+ ~ Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA ~
+ ~ 02110-1301 USA, or see the FSF site: http://www.fsf.org. ~
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~-->
+<portlet-app xmlns='http://java.sun.com/xml/ns/portlet/portlet-app_2_0.xsd' xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance' xsi:schemaLocation='http://java.sun.com/xml/ns/portlet/portlet-app_2_0.xsd http://java.sun.com/xml/ns/portlet/portlet-app_2_0.xsd' version='2.0'>
+ <portlet>
+ <portlet-name>Implicit Cloning Test Portlet</portlet-name>
+ <portlet-class>org.gatein.wsrp.portlet.StatePortlet</portlet-class>
+
+ <supports>
+ <mime-type>text/html</mime-type>
+ <portlet-mode>view</portlet-mode>
+ </supports>
+
+ <supported-locale>en</supported-locale>
+
+ <portlet-info>
+ <title>title</title>
+ </portlet-info>
+
+ <portlet-preferences>
+ <preference>
+ <name>name</name>
+ <value>initial</value>
+ </preference>
+ </portlet-preferences>
+ </portlet>
+
+ <container-runtime-option>
+ <name>org.gatein.pc.remotable</name>
+ <value>true</value>
+ </container-runtime-option>
+</portlet-app>
Added: components/wsrp/trunk/wsrp-producer-war/src/test/test-portlets/test-portletstate-portlet-war/WEB-INF/web.xml
===================================================================
--- components/wsrp/trunk/wsrp-producer-war/src/test/test-portlets/test-portletstate-portlet-war/WEB-INF/web.xml (rev 0)
+++ components/wsrp/trunk/wsrp-producer-war/src/test/test-portlets/test-portletstate-portlet-war/WEB-INF/web.xml 2010-08-13 17:02:50 UTC (rev 3828)
@@ -0,0 +1,30 @@
+<?xml version="1.0" encoding="UTF-8"?>
+
+<!--~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ ~ JBoss, a division of Red Hat ~
+ ~ Copyright 2007, Red Hat Middleware, LLC, and individual ~
+ ~ contributors as indicated by the @authors tag. See the ~
+ ~ copyright.txt in the distribution for a full listing of ~
+ ~ individual contributors. ~
+ ~ ~
+ ~ This is free software; you can redistribute it and/or modify it ~
+ ~ under the terms of the GNU Lesser General Public License as ~
+ ~ published by the Free Software Foundation; either version 2.1 of ~
+ ~ the License, or (at your option) any later version. ~
+ ~ ~
+ ~ This software is distributed in the hope that it will be useful, ~
+ ~ but WITHOUT ANY WARRANTY; without even the implied warranty of ~
+ ~ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU ~
+ ~ Lesser General Public License for more details. ~
+ ~ ~
+ ~ You should have received a copy of the GNU Lesser General Public ~
+ ~ License along with this software; if not, write to the Free ~
+ ~ Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA ~
+ ~ 02110-1301 USA, or see the FSF site: http://www.fsf.org. ~
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~-->
+
+<web-app version="2.4"
+ xmlns="http://java.sun.com/xml/ns/j2ee"
+ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd">
+</web-app>
\ No newline at end of file
14 years, 5 months