Author: alexsmirnov
Date: 2007-05-22 20:24:00 -0400 (Tue, 22 May 2007)
New Revision: 210
Added:
trunk/a4j-portlet/src/main/java/org/ajax4jsf/portlet/application/PortletStateHolder.java
trunk/a4j-portlet/src/main/java/org/ajax4jsf/portlet/application/PortletWindowStates.java
Removed:
trunk/a4j-portlet/src/main/java/org/ajax4jsf/portlet/application/PortletStates.java
Modified:
trunk/a4j-portlet/src/main/java/org/ajax4jsf/portlet/AjaxFacesPortlet.java
trunk/a4j-portlet/src/main/java/org/ajax4jsf/portlet/PortletAjaxContext.java
trunk/a4j-portlet/src/main/java/org/ajax4jsf/portlet/application/PortletViewState.java
Log:
Work in progress for a
http://jira.jboss.com/jira/browse/RF-186 .
Fix AJSF-66 ( double // on resources URL ).
Modified: trunk/a4j-portlet/src/main/java/org/ajax4jsf/portlet/AjaxFacesPortlet.java
===================================================================
--- trunk/a4j-portlet/src/main/java/org/ajax4jsf/portlet/AjaxFacesPortlet.java 2007-05-22
19:28:25 UTC (rev 209)
+++ trunk/a4j-portlet/src/main/java/org/ajax4jsf/portlet/AjaxFacesPortlet.java 2007-05-23
00:24:00 UTC (rev 210)
@@ -22,6 +22,7 @@
import javax.portlet.GenericPortlet;
import javax.portlet.PortletConfig;
import javax.portlet.PortletException;
+import javax.portlet.PortletMode;
import javax.portlet.PortletRequest;
import javax.portlet.PortletResponse;
import javax.portlet.PortletSession;
@@ -41,8 +42,10 @@
private static final Log log = LogFactory.getLog(AjaxFacesPortlet.class);
/**
- * Stored portlet config.
- */
+ * <p>The key used to store/retrive the PortletConfig object.</p>
+ */
+ public static final String PORTLET_CONFIG = "javax.portlet.PortletConfig";
+
private Lifecycle lifecycle;
private FacesContextFactory facesContextFactory;
@@ -82,6 +85,7 @@
log.debug("Done portlet initialisation for "
+ config.getPortletName());
}
+ getPortletContext().setAttribute(PORTLET_CONFIG, config);
}
/*
@@ -304,7 +308,7 @@
* @param facesContext
* @return
*/
- public static String getPortletID(FacesContext facesContext) {
+ public static String getPortletNamespace(FacesContext facesContext) {
ExternalContext externalContext = facesContext.getExternalContext();
Object response = externalContext.getResponse();
String namespace = null;
@@ -317,4 +321,25 @@
}
return namespace;
}
+
+ /**
+ * @param facesContext
+ * @return
+ */
+ public static PortletMode getPortletMode(FacesContext facesContext) {
+ ExternalContext externalContext = facesContext.getExternalContext();
+ Object request = externalContext.getRequest();
+ PortletMode mode = null;
+ if (request instanceof PortletRequest) {
+ mode = ((PortletRequest) request).getPortletMode();
+ } else if (null != externalContext.getRequestParameterMap().get(
+ AbstractExternalContext.PORTLET_MODE_PARAMETER)) {
+ String modeName = (String) externalContext.getRequestParameterMap().get(
+ AbstractExternalContext.PORTLET_MODE_PARAMETER);
+ if(null != modeName){
+ mode = new PortletMode(modeName);
+ }
+ }
+ return mode;
+ }
}
Modified: trunk/a4j-portlet/src/main/java/org/ajax4jsf/portlet/PortletAjaxContext.java
===================================================================
---
trunk/a4j-portlet/src/main/java/org/ajax4jsf/portlet/PortletAjaxContext.java 2007-05-22
19:28:25 UTC (rev 209)
+++
trunk/a4j-portlet/src/main/java/org/ajax4jsf/portlet/PortletAjaxContext.java 2007-05-23
00:24:00 UTC (rev 210)
@@ -76,7 +76,7 @@
public Map getCommonAjaxParameters() {
Map map = super.getCommonAjaxParameters();
FacesContext facesContext = FacesContext.getCurrentInstance();
- String namespace = AjaxFacesPortlet.getPortletID(facesContext);
+ String namespace = AjaxFacesPortlet.getPortletNamespace(facesContext);
if (null != namespace) {
map.put(AbstractExternalContext.NAMESPACE_PARAMETER, namespace);
}
Copied:
trunk/a4j-portlet/src/main/java/org/ajax4jsf/portlet/application/PortletStateHolder.java
(from rev 208,
trunk/a4j-portlet/src/main/java/org/ajax4jsf/portlet/application/PortletStates.java)
===================================================================
---
trunk/a4j-portlet/src/main/java/org/ajax4jsf/portlet/application/PortletStateHolder.java
(rev 0)
+++
trunk/a4j-portlet/src/main/java/org/ajax4jsf/portlet/application/PortletStateHolder.java 2007-05-23
00:24:00 UTC (rev 210)
@@ -0,0 +1,145 @@
+/**
+ *
+ */
+package org.ajax4jsf.portlet.application;
+
+import java.io.Serializable;
+import java.util.HashMap;
+import java.util.Map;
+
+import javax.faces.context.ExternalContext;
+import javax.faces.context.FacesContext;
+import javax.portlet.PortletMode;
+import javax.portlet.PortletRequest;
+
+import org.apache.commons.collections.map.LRUMap;
+
+/**
+ * @author asmirnov
+ *
+ */
+public class PortletStateHolder implements Serializable {
+ private static final String STATE_HOLDER = PortletStateHolder.class
+ .getName();
+
+ private static final String[] modes = { PortletMode.VIEW.toString(),
+ PortletMode.EDIT.toString(), PortletMode.HELP.toString() };
+
+ private PortletMode lastMode = PortletMode.VIEW;
+
+ /**
+ * View states for a different portlet modes, Views and serial numbers.
+ */
+ private Map states = new LRUMap();
+
+
+ /**
+ * Private constructor - instance must be stored in the session, and
+ * created on nessesary by factory method.
+ *
+ * @param context
+ */
+ private PortletStateHolder(FacesContext context) {
+ ExternalContext externalContext = context.getExternalContext();
+ Object request = externalContext.getRequest();
+ if (request instanceof PortletRequest) {
+ PortletRequest portletRequest = (PortletRequest) request;
+ lastMode = portletRequest.getPortletMode();
+ }
+ }
+
+ /**
+ * Get instance of portlet states, stored in the session. If no
+ * previsious instance in session, create default value.
+ *
+ * @param context
+ * @return
+ */
+ public static PortletStateHolder getInstance(FacesContext context) {
+ ExternalContext externalContext = context.getExternalContext();
+ Object session = externalContext.getSession(true);
+ Map sessionMap = externalContext.getSessionMap();
+ PortletStateHolder instance = null;
+ synchronized (session) {
+ instance = (PortletStateHolder) sessionMap.get(STATE_HOLDER);
+ if (null == instance) {
+ // Create and store in session new state holder.
+ instance = new PortletStateHolder(context);
+
+ sessionMap.put(STATE_HOLDER, instance);
+ }
+ }
+ return instance;
+ }
+
+ public String getViewId(FacesContext context) {
+ String viewId = null;
+ // First - check for a existing viewId.
+ if(null != context.getViewRoot()){
+ viewId = context.getViewRoot().getViewId();
+ }
+ if(null == viewId){
+
+ }
+ return viewId;
+ }
+
+ public PortletWindowStates getWindowStates() {
+ return null;
+ }
+ /**
+ * @author asmirnov
+ *
+ */
+ private static class StateKey implements Serializable {
+ private PortletMode mode;
+
+ private String namespace;
+
+
+ /**
+ * @param mode
+ * @param namespace
+ */
+ public StateKey(PortletMode mode, String namespace) {
+ this.mode = mode;
+ this.namespace = namespace;
+ }
+
+ /* (non-Javadoc)
+ * @see java.lang.Object#hashCode()
+ */
+ public int hashCode() {
+ final int PRIME = 31;
+ int result = 1;
+ result = PRIME * result + ((mode == null) ? 0 : mode.hashCode());
+ result = PRIME * result + ((namespace == null) ? 0 : namespace.hashCode());
+ return result;
+ }
+
+ /* (non-Javadoc)
+ * @see java.lang.Object#equals(java.lang.Object)
+ */
+ public boolean equals(Object obj) {
+ if (this == obj)
+ return true;
+ if (obj == null)
+ return false;
+ if (getClass() != obj.getClass())
+ return false;
+ final StateKey other = (StateKey) obj;
+ if (mode == null) {
+ if (other.mode != null)
+ return false;
+ } else if (!mode.equals(other.mode))
+ return false;
+ if (namespace == null) {
+ if (other.namespace != null)
+ return false;
+ } else if (!namespace.equals(other.namespace))
+ return false;
+ return true;
+ }
+
+ }
+}
Deleted:
trunk/a4j-portlet/src/main/java/org/ajax4jsf/portlet/application/PortletStates.java
===================================================================
---
trunk/a4j-portlet/src/main/java/org/ajax4jsf/portlet/application/PortletStates.java 2007-05-22
19:28:25 UTC (rev 209)
+++
trunk/a4j-portlet/src/main/java/org/ajax4jsf/portlet/application/PortletStates.java 2007-05-23
00:24:00 UTC (rev 210)
@@ -1,18 +0,0 @@
-/**
- *
- */
-package org.ajax4jsf.portlet.application;
-
-import java.io.Serializable;
-import java.util.HashMap;
-import java.util.Map;
-import javax.portlet.PortletMode;
-
-/**
- * @author asmirnov
- *
- */
-public class PortletStates implements Serializable {
- private String lastMode;
- private Map states = new HashMap();
-}
Modified:
trunk/a4j-portlet/src/main/java/org/ajax4jsf/portlet/application/PortletViewState.java
===================================================================
---
trunk/a4j-portlet/src/main/java/org/ajax4jsf/portlet/application/PortletViewState.java 2007-05-22
19:28:25 UTC (rev 209)
+++
trunk/a4j-portlet/src/main/java/org/ajax4jsf/portlet/application/PortletViewState.java 2007-05-23
00:24:00 UTC (rev 210)
@@ -3,6 +3,7 @@
*/
package org.ajax4jsf.portlet.application;
+import java.io.Serializable;
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
@@ -17,7 +18,7 @@
* @author asmirnov
*
*/
-public class PortletViewState {
+public class PortletViewState implements Serializable {
public static final String SAVED_VIEW_ATTRIBUTE = PortletViewState.class.getName();
Added:
trunk/a4j-portlet/src/main/java/org/ajax4jsf/portlet/application/PortletWindowStates.java
===================================================================
---
trunk/a4j-portlet/src/main/java/org/ajax4jsf/portlet/application/PortletWindowStates.java
(rev 0)
+++
trunk/a4j-portlet/src/main/java/org/ajax4jsf/portlet/application/PortletWindowStates.java 2007-05-23
00:24:00 UTC (rev 210)
@@ -0,0 +1,46 @@
+/**
+ *
+ */
+package org.ajax4jsf.portlet.application;
+
+import java.io.Serializable;
+import java.util.Map;
+
+import org.apache.commons.collections.map.LRUMap;
+
+/**
+ * @author asmirnov
+ *
+ */
+public class PortletWindowStates implements Serializable {
+
+ private String viewId;
+
+ private Map viewStates;
+
+ public PortletWindowStates() {
+ viewStates = new LRUMap();
+ }
+
+ /**
+ * @return the viewId
+ */
+ public String getViewId() {
+ return viewId;
+ }
+
+ /**
+ * @param viewId the viewId to set
+ */
+ public void setViewId(String viewId) {
+ this.viewId = viewId;
+ }
+
+ public PortletViewState getState() {
+ PortletViewState state = (PortletViewState) viewStates.get(viewId);
+ if(null == state){
+ state = new PortletViewState();
+ }
+ return state;
+ }
+}