Author: julien(a)jboss.com
Date: 2008-06-29 09:37:07 -0400 (Sun, 29 Jun 2008)
New Revision: 11190
Added:
modules/presentation/trunk/ajax/src/main/java/org/jboss/portal/presentation/ajax/client/utils/Tools.java
modules/presentation/trunk/presentation/src/main/java/org/jboss/portal/presentation/impl/state/navigational/AbstractNavigationalStateContext.java
modules/presentation/trunk/presentation/src/main/java/org/jboss/portal/presentation/impl/state/navigational/SessionNavigationalStateContext.java
modules/presentation/trunk/presentation/src/main/java/org/jboss/portal/presentation/impl/state/navigational/SimpleNavigationalStateContext.java
Removed:
modules/presentation/trunk/ajax/src/main/java/org/jboss/portal/presentation/ajax/client/utils/DOMTools.java
Modified:
modules/presentation/trunk/ajax/src/main/java/org/jboss/portal/presentation/ajax/client/model/AjaxWindow.java
modules/presentation/trunk/ajax/src/main/java/org/jboss/portal/presentation/ajax/client/protocol/OpaqueWindowAction.java
modules/presentation/trunk/ajax/src/main/java/org/jboss/portal/presentation/ajax/server/PresentationClientImpl.java
modules/presentation/trunk/ajax/src/main/java/org/jboss/portal/presentation/ajax/server/PresentationClientServlet.java
modules/presentation/trunk/portal/src/main/java/org/jboss/portal/presentation/portal/content/portlet/controller/PresentationPortletPageNavigationalState.java
modules/presentation/trunk/presentation/src/main/java/org/jboss/portal/presentation/impl/state/navigational/DelegatingNavigationalStateContext.java
modules/presentation/trunk/presentation/src/main/java/org/jboss/portal/presentation/impl/state/navigational/NavigationalStateContextImpl.java
modules/presentation/trunk/presentation/src/main/java/org/jboss/portal/presentation/state/navigational/NavigationalStateContext.java
Log:
almost public render parameter change working
Modified:
modules/presentation/trunk/ajax/src/main/java/org/jboss/portal/presentation/ajax/client/model/AjaxWindow.java
===================================================================
---
modules/presentation/trunk/ajax/src/main/java/org/jboss/portal/presentation/ajax/client/model/AjaxWindow.java 2008-06-29
11:22:39 UTC (rev 11189)
+++
modules/presentation/trunk/ajax/src/main/java/org/jboss/portal/presentation/ajax/client/model/AjaxWindow.java 2008-06-29
13:37:07 UTC (rev 11190)
@@ -29,7 +29,6 @@
import com.google.gwt.user.client.ui.VerticalPanel;
import com.google.gwt.user.client.rpc.ServiceDefTarget;
import com.google.gwt.user.client.rpc.AsyncCallback;
-import com.google.gwt.user.client.Window;
import com.google.gwt.user.client.DOM;
import com.google.gwt.user.client.Event;
import com.google.gwt.user.client.Element;
@@ -39,9 +38,12 @@
import org.jboss.portal.presentation.ajax.client.protocol.OpaqueWindowAction;
import org.jboss.portal.presentation.ajax.client.protocol.AjaxRequest;
import org.jboss.portal.presentation.ajax.client.protocol.AjaxResponse;
-import org.jboss.portal.presentation.ajax.client.utils.DOMTools;
+import org.jboss.portal.presentation.ajax.client.utils.Tools;
import org.jboss.portal.presentation.ajax.client.utils.Logger;
+import java.util.Map;
+import java.util.HashMap;
+
/**
* @author <a href="mailto:julien@jboss-portal.org">Julien
Viet</a>
* @version $Revision: 630 $
@@ -85,26 +87,99 @@
Event event = DOM.eventGetCurrentEvent();
//
- Element target = DOM.eventGetTarget(event);
+ Element source = DOM.eventGetTarget(event);
+ String sourceName = Tools.getTagName(source);
+ String sourceType = DOM.getElementProperty(source, "type");
//
- String tagName = DOMTools.getTagName(target);
+ OpaqueWindowAction windowAction = null;
//
- if (tagName.equals("A"))
+ if (sourceName.equals("A"))
{
DOM.eventPreventDefault(event);
//
- String uri = DOM.getElementAttribute(target, "href");
+ String uri = DOM.getElementAttribute(source, "href");
// This is a get
- log.info("This is link click " + uri);
+ log.info("Link clicked " + uri);
//
- OpaqueWindowAction windowAction = new OpaqueWindowAction(uri);
+ windowAction = new OpaqueWindowAction(uri, null);
+ }
+ else if (sourceName.equals("INPUT") &&
sourceType.equals("submit"))
+ {
+ DOM.eventPreventDefault(event);
+ // This is maybe a form submit
+ log.info("This is maybe a form submit, need to find the enclosing
form");
+
//
+ Element current = source;
+ String currentName;
+
+ //
+ while (true)
+ {
+ currentName = Tools.getTagName(current);
+
+ //
+ if ("FORM".equals(currentName) ||
"BODY".equals(currentName))
+ {
+ break;
+ }
+
+ //
+ current = DOM.getParent(current);
+ }
+
+ //
+
+ //
+ if (currentName.equals("FORM"))
+ {
+ log.info("Form found");
+ String uri = DOM.getElementAttribute(current, "action");
+ Map form = new HashMap();
+ Tools.serialize(current, form);
+ windowAction = new OpaqueWindowAction(uri, form);
+
+
+ /*
+ var enctype = current.enctype
+
+ // We don't handle file upload for now
+ if (enctype != "multipart/form-data") {
+
+ // Check it is a POST
+ if (current.method.toLowerCase() == "post") {
+
+ // Check we can handle this URL
+ if (isURLAccepted(current.action)) {
+
+ // Set URL
+ url = current.action;
+
+ // Set the specified enctype
+ options.enctype = enctype;
+ options.asynchronous = false;
+ options.method = "post"
+ options.postBody = Form.serialize(current);
+ }
+ }
+ }
+ }
+ */
+ }
+ }
+
+ //
+ if (windowAction != null)
+ {
+ log.info("About to execute window action " + windowAction);
+
+ //
final PresentationClientRemoteAsync remote =
(PresentationClientRemoteAsync)GWT.create(PresentationClientRemote.class);
ServiceDefTarget endpoint = (ServiceDefTarget)remote;
String moduleRelativeURL = GWT.getModuleBaseURL() + "remote";
@@ -115,7 +190,6 @@
request.setAction(windowAction);
//
- //
remote.process(request, new AsyncCallback()
{
public void onFailure(Throwable throwable)
@@ -147,13 +221,6 @@
}
});
}
- else if (tagName.equals("INPUT"))
- {
- DOM.eventPreventDefault(event);
-
- // This is maybe a form submit
- log.info("This is maybe a form submit");
- }
}
});
}
Modified:
modules/presentation/trunk/ajax/src/main/java/org/jboss/portal/presentation/ajax/client/protocol/OpaqueWindowAction.java
===================================================================
---
modules/presentation/trunk/ajax/src/main/java/org/jboss/portal/presentation/ajax/client/protocol/OpaqueWindowAction.java 2008-06-29
11:22:39 UTC (rev 11189)
+++
modules/presentation/trunk/ajax/src/main/java/org/jboss/portal/presentation/ajax/client/protocol/OpaqueWindowAction.java 2008-06-29
13:37:07 UTC (rev 11190)
@@ -22,6 +22,8 @@
******************************************************************************/
package org.jboss.portal.presentation.ajax.client.protocol;
+import java.util.Map;
+
/**
* @author <a href="mailto:julien@jboss-portal.org">Julien
Viet</a>
* @version $Revision: 630 $
@@ -32,13 +34,17 @@
/** . */
private String uri;
+ /** . */
+ private Map form;
+
public OpaqueWindowAction()
{
}
- public OpaqueWindowAction(String uri)
+ public OpaqueWindowAction(String uri, Map form)
{
this.uri = uri;
+ this.form = form;
}
public String getURI()
@@ -51,6 +57,16 @@
this.uri = uri;
}
+ public Map getForm()
+ {
+ return form;
+ }
+
+ public void setForm(Map form)
+ {
+ this.form = form;
+ }
+
public String toString()
{
return "OpaqueWindowAction[uri=" + uri + "]";
Deleted:
modules/presentation/trunk/ajax/src/main/java/org/jboss/portal/presentation/ajax/client/utils/DOMTools.java
===================================================================
---
modules/presentation/trunk/ajax/src/main/java/org/jboss/portal/presentation/ajax/client/utils/DOMTools.java 2008-06-29
11:22:39 UTC (rev 11189)
+++
modules/presentation/trunk/ajax/src/main/java/org/jboss/portal/presentation/ajax/client/utils/DOMTools.java 2008-06-29
13:37:07 UTC (rev 11190)
@@ -1,44 +0,0 @@
-/******************************************************************************
- * 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. *
- ******************************************************************************/
-package org.jboss.portal.presentation.ajax.client.utils;
-
-import com.google.gwt.user.client.Element;
-
-/**
- * @author <a href="mailto:julien@jboss-portal.org">Julien
Viet</a>
- * @version $Revision: 630 $
- */
-public class DOMTools
-{
-
- /**
- * Returns an element tag name.
- *
- * @param element the element to obtain the tag name from
- * @return the tag name value
- */
- public static native String getTagName(Element element)
- /*-{
- return element.nodeName;
- }-*/;
-}
Copied:
modules/presentation/trunk/ajax/src/main/java/org/jboss/portal/presentation/ajax/client/utils/Tools.java
(from rev 11157,
modules/presentation/trunk/ajax/src/main/java/org/jboss/portal/presentation/ajax/client/utils/DOMTools.java)
===================================================================
---
modules/presentation/trunk/ajax/src/main/java/org/jboss/portal/presentation/ajax/client/utils/Tools.java
(rev 0)
+++
modules/presentation/trunk/ajax/src/main/java/org/jboss/portal/presentation/ajax/client/utils/Tools.java 2008-06-29
13:37:07 UTC (rev 11190)
@@ -0,0 +1,120 @@
+/******************************************************************************
+ * 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. *
+ ******************************************************************************/
+package org.jboss.portal.presentation.ajax.client.utils;
+
+import com.google.gwt.user.client.Element;
+import com.google.gwt.user.client.DOM;
+import com.google.gwt.user.client.Window;
+
+import java.util.Map;
+
+/**
+ * A collection of various utility methods.
+ *
+ * @author <a href="mailto:julien@jboss-portal.org">Julien
Viet</a>
+ * @version $Revision: 630 $
+ */
+public class Tools
+{
+
+ /**
+ * Returns an element tag name.
+ *
+ * @param element the element to obtain the tag name from
+ * @return the tag name value
+ */
+ public static native String getTagName(Element element)
+ /*-{
+ return element.nodeName;
+ }-*/;
+
+ /**
+ * Serialize a form.
+ */
+ public static void serialize(Element element, Map map)
+ {
+ String tag = getTagName(element);
+
+ //
+ String value = null;
+ if ("INPUT".equals(tag))
+ {
+ String type = DOM.getElementAttribute(element, "type").toLowerCase();
+
+ //
+ if ("checkbox".equals(type))
+ {
+ throw new UnsupportedOperationException("todo");
+ }
+ else if ("radio".equals(type))
+ {
+ throw new UnsupportedOperationException("todo");
+ }
+ else
+ {
+ value = DOM.getElementProperty(element, "value");
+ }
+ }
+ else
+ {
+ for (int i = DOM.getChildCount(element) - 1;i >= 0;i--)
+ {
+ serialize(DOM.getChild(element, i), map);
+ }
+ }
+
+ //
+ if (value != null)
+ {
+ String name = DOM.getElementAttribute(element, "name");
+
+ //
+ if (name != null)
+ {
+ String disabled = DOM.getElementProperty(element, "disabled");
+
+ //
+ if (disabled == null ||
!disabled.trim().toCharArray().equals("true"))
+ {
+ String[] values = (String[])map.get(name);
+
+ //
+ if (values == null)
+ {
+ map.put(name, new String[]{value});
+ }
+ else
+ {
+ String[] tmp = new String[values.length + 1];
+ for (int i = 0;i < values.length;i++)
+ {
+ tmp[i] = values[i];
+ }
+ tmp[values.length] = value;
+ values = tmp;
+ }
+ }
+ }
+ }
+ }
+}
Modified:
modules/presentation/trunk/ajax/src/main/java/org/jboss/portal/presentation/ajax/server/PresentationClientImpl.java
===================================================================
---
modules/presentation/trunk/ajax/src/main/java/org/jboss/portal/presentation/ajax/server/PresentationClientImpl.java 2008-06-29
11:22:39 UTC (rev 11189)
+++
modules/presentation/trunk/ajax/src/main/java/org/jboss/portal/presentation/ajax/server/PresentationClientImpl.java 2008-06-29
13:37:07 UTC (rev 11190)
@@ -27,10 +27,13 @@
import org.jboss.portal.presentation.protocol.ProtocolAction;
import org.jboss.portal.presentation.protocol.codec.ActionEncoder;
import
org.jboss.portal.presentation.impl.state.navigational.NavigationalStateContextImpl;
+import
org.jboss.portal.presentation.impl.state.navigational.DelegatingNavigationalStateContext;
+import
org.jboss.portal.presentation.impl.state.navigational.SessionNavigationalStateContext;
import org.jboss.portal.presentation.ajax.server.protocol.AjaxActionEncoderContext;
import org.jboss.portal.web.ServletContextDispatcher;
import org.jboss.portal.common.servlet.URLFormat;
+import javax.servlet.http.HttpServletRequest;
import java.io.Writer;
import java.io.IOException;
@@ -50,13 +53,18 @@
/** . */
private ActionEncoder encoder;
+ /** . */
+ private DelegatingNavigationalStateContext navigationalStateContext;
+
public PresentationClientImpl(
+ HttpServletRequest req,
ServletContextDispatcher dispatcher,
ActionEncoder encoder)
{
this.dispatcher = dispatcher;
this.encoder = encoder;
this.actionEncoderContext = new AjaxActionEncoderContext();
+ this.navigationalStateContext = new DelegatingNavigationalStateContext(new
SessionNavigationalStateContext(req));
}
public ServletContextDispatcher getDispatcher()
@@ -64,9 +72,9 @@
return dispatcher;
}
- public NavigationalStateContext getNavigationalStateContext()
+ public DelegatingNavigationalStateContext getNavigationalStateContext()
{
- return new NavigationalStateContextImpl();
+ return navigationalStateContext;
}
public void renderURL(Writer writer, ProtocolAction action, URLFormat format) throws
IOException
Modified:
modules/presentation/trunk/ajax/src/main/java/org/jboss/portal/presentation/ajax/server/PresentationClientServlet.java
===================================================================
---
modules/presentation/trunk/ajax/src/main/java/org/jboss/portal/presentation/ajax/server/PresentationClientServlet.java 2008-06-29
11:22:39 UTC (rev 11189)
+++
modules/presentation/trunk/ajax/src/main/java/org/jboss/portal/presentation/ajax/server/PresentationClientServlet.java 2008-06-29
13:37:07 UTC (rev 11190)
@@ -43,6 +43,7 @@
import org.jboss.portal.presentation.impl.model.UIModelImpl;
import org.jboss.portal.presentation.impl.model.pull.DetachedViewPortContext;
import
org.jboss.portal.presentation.impl.state.navigational.NavigationalStateContextImpl;
+import
org.jboss.portal.presentation.impl.state.navigational.DelegatingNavigationalStateContext;
import org.jboss.portal.presentation.view.DefaultPageViewPortScope;
import org.jboss.portal.presentation.view.PageViewPortScope;
import org.jboss.portal.presentation.state.structural.StructuralStateContext;
@@ -53,6 +54,7 @@
import org.jboss.portal.web.ServletContextDispatcher;
import org.jboss.portal.web.ServletContainer;
import org.jboss.portal.web.WebRequest;
+import org.jboss.portal.web.Body;
import org.jboss.portal.web.impl.DefaultServletContainerFactory;
import org.jboss.portal.common.http.QueryStringParser;
@@ -61,6 +63,8 @@
import javax.servlet.ServletException;
import java.util.Map;
import java.util.Collections;
+import java.util.Set;
+import java.util.HashSet;
/**
* @author <a href="mailto:julien@jboss-portal.org">Julien
Viet</a>
@@ -124,7 +128,7 @@
ServletContainer container =
DefaultServletContainerFactory.getInstance().getServletContainer();
ServletContextDispatcher dispatcher = new ServletContextDispatcher(req, resp,
container);
ActionEncoder encoder =
(ActionEncoder)getServletContext().getAttribute("ActionEncoder");
- return new PresentationClientImpl(dispatcher, encoder);
+ return new PresentationClientImpl(req, dispatcher, encoder);
}
public String render(String windowId)
@@ -156,13 +160,16 @@
if (action instanceof OpaqueWindowAction)
{
- String uri = ((OpaqueWindowAction)action).getURI();
+ OpaqueWindowAction windowAction = (OpaqueWindowAction)action;
+ //
String path;
Map<String, String[]> queryParameterMap;
+ Body body;
//
+ String uri = windowAction.getURI();
int index = uri.indexOf('?');
if (index > -1)
{
@@ -175,14 +182,25 @@
queryParameterMap = Collections.emptyMap();
}
- ProtocolAction protocolAction = decoder.decode(new
AjaxActionDecoderContext(WebRequest.Verb.GET, path, queryParameterMap, null));
+ //
+ Map form = windowAction.getForm();
+ if (form != null)
+ {
+ body = new Body.Form("UTF8", form);
+ }
+ else
+ {
+ body = null;
+ }
+ ProtocolAction protocolAction = decoder.decode(new
AjaxActionDecoderContext(WebRequest.Verb.GET, path, queryParameterMap, body));
+
System.out.println("decoded protocolAction = " + protocolAction);
// Now we execute
PresentationServer server = getPresentationServer();
- PresentationClient client = createPresentationClient();
+ PresentationClientImpl client = createPresentationClient();
PresentationRequest prequest = new PresentationRequest(protocolAction);
@@ -191,10 +209,20 @@
PresentationResponse response = server.process(client, prequest);
System.out.println("response = " + response);
- System.out.println("Stale windows " + response.getStaleObjects());
+ System.out.println("Stale objects " + response.getStaleObjects());
+ DelegatingNavigationalStateContext nsc =
client.getNavigationalStateContext();
+
//
- return new AjaxResponse(response.getStaleObjects().toArray(new
String[response.getStaleObjects().size()]));
+ Set<String> blahIds = nsc.flush();
+ System.out.println("Stale objects = " + blahIds);
+
+ //
+ Set<String> tmp = new
HashSet<String>(response.getStaleObjects());
+ tmp.addAll(blahIds);
+
+ //
+ return new AjaxResponse(tmp.toArray(new String[tmp.size()]));
}
catch (PresentationServerException e)
{
Modified:
modules/presentation/trunk/portal/src/main/java/org/jboss/portal/presentation/portal/content/portlet/controller/PresentationPortletPageNavigationalState.java
===================================================================
---
modules/presentation/trunk/portal/src/main/java/org/jboss/portal/presentation/portal/content/portlet/controller/PresentationPortletPageNavigationalState.java 2008-06-29
11:22:39 UTC (rev 11189)
+++
modules/presentation/trunk/portal/src/main/java/org/jboss/portal/presentation/portal/content/portlet/controller/PresentationPortletPageNavigationalState.java 2008-06-29
13:37:07 UTC (rev 11190)
@@ -122,7 +122,7 @@
{
if (navigationalStateContext instanceof DelegatingNavigationalStateContext)
{
- ((DelegatingNavigationalStateContext)navigationalStateContext).flush(true);
+ ((DelegatingNavigationalStateContext)navigationalStateContext).flush();
}
}
Added:
modules/presentation/trunk/presentation/src/main/java/org/jboss/portal/presentation/impl/state/navigational/AbstractNavigationalStateContext.java
===================================================================
---
modules/presentation/trunk/presentation/src/main/java/org/jboss/portal/presentation/impl/state/navigational/AbstractNavigationalStateContext.java
(rev 0)
+++
modules/presentation/trunk/presentation/src/main/java/org/jboss/portal/presentation/impl/state/navigational/AbstractNavigationalStateContext.java 2008-06-29
13:37:07 UTC (rev 11190)
@@ -0,0 +1,84 @@
+/******************************************************************************
+ * 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. *
+ ******************************************************************************/
+package org.jboss.portal.presentation.impl.state.navigational;
+
+import org.jboss.portal.presentation.state.navigational.NavigationalStateContext;
+import org.jboss.portal.presentation.state.StateException;
+
+import java.util.Set;
+import java.io.Serializable;
+
+/**
+ * @author <a href="mailto:julien@jboss-portal.org">Julien
Viet</a>
+ * @version $Revision: 630 $
+ */
+public abstract class AbstractNavigationalStateContext implements
NavigationalStateContext
+{
+
+ public final Set<String> getPropertyNames(String objectId) throws
IllegalArgumentException
+ {
+ if (objectId == null)
+ {
+ throw new IllegalArgumentException();
+ }
+
+ //
+ return safeGetPropertyNames(objectId);
+ }
+
+ public final Serializable getProperty(String objectId, String key) throws
IllegalArgumentException
+ {
+ if (objectId == null)
+ {
+ throw new IllegalArgumentException();
+ }
+ if (key == null)
+ {
+ throw new IllegalArgumentException();
+ }
+
+ //
+ return safeGetProperty(objectId, key);
+ }
+
+ public final void setProperty(String objectId, String key, Serializable
navigationalState) throws StateException, IllegalArgumentException
+ {
+ if (objectId == null)
+ {
+ throw new IllegalArgumentException();
+ }
+ if (key == null)
+ {
+ throw new IllegalArgumentException();
+ }
+
+ safeSetProperty(objectId, key, navigationalState);
+ }
+
+ protected abstract Set<String> safeGetPropertyNames(String objectId);
+
+ protected abstract Serializable safeGetProperty(String objectId, String key);
+
+ protected abstract void safeSetProperty(String objectId, String key, Serializable
navigationalState) throws StateException;
+
+}
Modified:
modules/presentation/trunk/presentation/src/main/java/org/jboss/portal/presentation/impl/state/navigational/DelegatingNavigationalStateContext.java
===================================================================
---
modules/presentation/trunk/presentation/src/main/java/org/jboss/portal/presentation/impl/state/navigational/DelegatingNavigationalStateContext.java 2008-06-29
11:22:39 UTC (rev 11189)
+++
modules/presentation/trunk/presentation/src/main/java/org/jboss/portal/presentation/impl/state/navigational/DelegatingNavigationalStateContext.java 2008-06-29
13:37:07 UTC (rev 11190)
@@ -28,13 +28,15 @@
import java.util.Set;
import java.util.Map;
import java.util.HashMap;
+import java.util.HashSet;
+import java.util.Collections;
import java.io.Serializable;
/**
* @author <a href="mailto:julien@jboss-portal.org">Julien
Viet</a>
* @version $Revision: 630 $
*/
-public class DelegatingNavigationalStateContext implements NavigationalStateContext
+public class DelegatingNavigationalStateContext extends AbstractNavigationalStateContext
implements NavigationalStateContext
{
/** . */
@@ -54,7 +56,7 @@
this.delegate = delegate;
}
- public Set<String> getPropertyNames(String objectId)
+ public Set<String> safeGetPropertyNames(String objectId)
{
Map<String, Serializable> properties = getProperties(objectId, false);
@@ -69,7 +71,7 @@
}
}
- public Serializable getProperty(String objectId, String key) throws
IllegalArgumentException
+ public Serializable safeGetProperty(String objectId, String key) throws
IllegalArgumentException
{
Map<String, Serializable> properties = getProperties(objectId, false);
@@ -84,7 +86,7 @@
}
}
- public void setProperty(String objectId, String key, Serializable navigationalState)
throws StateException, IllegalArgumentException
+ public void safeSetProperty(String objectId, String key, Serializable
navigationalState) throws StateException, IllegalArgumentException
{
Map<String, Serializable> properties = getProperties(objectId, true);
@@ -97,39 +99,82 @@
return delegate;
}
- public void flush(boolean deep)
+ public Set<String> flush()
{
+ Set<String> staleIds = null;
+
+ //
if (updates != null)
{
for (Map.Entry<String, Map<String, Serializable>> update :
updates.entrySet())
{
- String objectId = update.getKey();
+ String id = update.getKey();
+
+ //
+ if (staleIds == null)
+ {
+ staleIds = new HashSet<String>();
+ }
+
+ //
+ staleIds.add(id);
+
+ //
Map<String, Serializable> properties = update.getValue();
//
for (Map.Entry<String, Serializable> property : properties.entrySet())
{
- delegate.setProperty(objectId, property.getKey(), property.getValue());
+ delegate.setProperty(id, property.getKey(), property.getValue());
}
}
//
- if (deep && delegate instanceof DelegatingNavigationalStateContext)
+ updates.clear();
+ }
+
+ //
+/*
+ if (cascadeUpdateSensitive && delegate instanceof
DelegatingNavigationalStateContext)
+ {
+ Set<String> tmp = ((DelegatingNavigationalStateContext)delegate).flush();
+
+ //
+ if (tmp.size() > 0)
{
- ((DelegatingNavigationalStateContext)delegate).flush(true);
+ if (staleIds == null)
+ {
+ staleIds = new HashSet<String>(tmp);
+ }
+ else
+ {
+ staleIds.addAll(tmp);
+ }
}
}
+*/
+
+ //
+ if (staleIds == null)
+ {
+ staleIds = Collections.emptySet();
+ }
+
+ //
+ return staleIds;
}
- public void clear(boolean deep)
+ public void clear()
{
updates.clear();
//
- if (deep && delegate instanceof DelegatingNavigationalStateContext)
+/*
+ if (cascadeUpdateSensitive && delegate instanceof
DelegatingNavigationalStateContext)
{
- ((DelegatingNavigationalStateContext)delegate).clear(true);
+ ((DelegatingNavigationalStateContext)delegate).clear();
}
+*/
}
private Map<String, Serializable> getProperties(String objectId, boolean
create)
Modified:
modules/presentation/trunk/presentation/src/main/java/org/jboss/portal/presentation/impl/state/navigational/NavigationalStateContextImpl.java
===================================================================
---
modules/presentation/trunk/presentation/src/main/java/org/jboss/portal/presentation/impl/state/navigational/NavigationalStateContextImpl.java 2008-06-29
11:22:39 UTC (rev 11189)
+++
modules/presentation/trunk/presentation/src/main/java/org/jboss/portal/presentation/impl/state/navigational/NavigationalStateContextImpl.java 2008-06-29
13:37:07 UTC (rev 11190)
@@ -38,7 +38,7 @@
* @author <a href="mailto:julien@jboss.org">Julien Viet</a>
* @version $Revision: 630 $
*/
-public class NavigationalStateContextImpl implements NavigationalStateContext,
Serializable
+public class NavigationalStateContextImpl extends SimpleNavigationalStateContext
implements Serializable
{
/** . */
@@ -60,83 +60,23 @@
this(new HashMap<String, Map<String, Serializable>>());
}
- public Set<String> getPropertyNames(String objectId)
+ protected Map<String, Serializable> getMap(String objectId, boolean create)
{
- if (objectId == null)
- {
- throw new IllegalArgumentException();
- }
-
- //
Map<String, Serializable> properties = map.get(objectId);
//
- return properties != null ? properties.keySet() : null;
- }
-
- public void setProperty(String objectId, String key, Serializable navigationalState)
throws StateChangeVetoException, StateException, IllegalArgumentException
- {
- if (objectId == null)
+ if (properties == null && create)
{
- throw new IllegalArgumentException();
+ properties = new HashMap<String, Serializable>();
+ map.put(objectId, properties);
}
- if (key == null)
- {
- throw new IllegalArgumentException();
- }
//
- Map<String, Serializable> properties = map.get(objectId);
-
- //
- if (navigationalState != null)
- {
- if (properties == null)
- {
- properties = new HashMap<String, Serializable>();
- map.put(objectId, properties);
- }
-
- //
- properties.put(key, navigationalState);
- }
- else
- {
- if (properties != null)
- {
- properties.remove(key);
-
- //
- if (properties.isEmpty())
- {
- map.remove(objectId);
- }
- }
- }
+ return properties;
}
- public Serializable getProperty(String objectId, String key) throws
IllegalArgumentException
+ protected void destroyMap(String objectId)
{
- if (objectId == null)
- {
- throw new IllegalArgumentException();
- }
- if (key == null)
- {
- throw new IllegalArgumentException();
- }
-
- //
- Map<String, Serializable> properties = map.get(objectId);
-
- //
- if (properties != null)
- {
- return properties.get(key);
- }
- else
- {
- return null;
- }
+ map.remove(objectId);
}
}
\ No newline at end of file
Added:
modules/presentation/trunk/presentation/src/main/java/org/jboss/portal/presentation/impl/state/navigational/SessionNavigationalStateContext.java
===================================================================
---
modules/presentation/trunk/presentation/src/main/java/org/jboss/portal/presentation/impl/state/navigational/SessionNavigationalStateContext.java
(rev 0)
+++
modules/presentation/trunk/presentation/src/main/java/org/jboss/portal/presentation/impl/state/navigational/SessionNavigationalStateContext.java 2008-06-29
13:37:07 UTC (rev 11190)
@@ -0,0 +1,80 @@
+/******************************************************************************
+ * 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. *
+ ******************************************************************************/
+package org.jboss.portal.presentation.impl.state.navigational;
+
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpSession;
+import java.io.Serializable;
+import java.util.Map;
+import java.util.HashMap;
+
+/**
+ * @author <a href="mailto:julien@jboss-portal.org">Julien
Viet</a>
+ * @version $Revision: 630 $
+ */
+public class SessionNavigationalStateContext extends SimpleNavigationalStateContext
+{
+
+ /** . */
+ private final HttpServletRequest request;
+
+ public SessionNavigationalStateContext(HttpServletRequest request)
+ {
+ this.request = request;
+ }
+
+ protected Map<String, Serializable> getMap(String objectId, boolean create)
+ {
+ HttpSession session = request.getSession(create);
+
+ //
+ Map<String, Serializable> properties = null;
+ if (session != null)
+ {
+ properties = (Map<String, Serializable>)session.getAttribute(objectId);
+
+ //
+ if (properties == null)
+ {
+ properties = new HashMap<String, Serializable>();
+
+ //
+ session.setAttribute(objectId, properties);
+ }
+ }
+
+ //
+ return properties;
+ }
+
+ protected void destroyMap(String objectId)
+ {
+ HttpSession session = request.getSession(false);
+
+ //
+ if (session != null)
+ {
+ session.removeAttribute(objectId);
+ }
+ }
+}
Added:
modules/presentation/trunk/presentation/src/main/java/org/jboss/portal/presentation/impl/state/navigational/SimpleNavigationalStateContext.java
===================================================================
---
modules/presentation/trunk/presentation/src/main/java/org/jboss/portal/presentation/impl/state/navigational/SimpleNavigationalStateContext.java
(rev 0)
+++
modules/presentation/trunk/presentation/src/main/java/org/jboss/portal/presentation/impl/state/navigational/SimpleNavigationalStateContext.java 2008-06-29
13:37:07 UTC (rev 11190)
@@ -0,0 +1,99 @@
+/******************************************************************************
+ * 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. *
+ ******************************************************************************/
+package org.jboss.portal.presentation.impl.state.navigational;
+
+import org.jboss.portal.presentation.state.StateChangeVetoException;
+import org.jboss.portal.presentation.state.StateException;
+
+import java.util.HashMap;
+import java.util.Map;
+import java.util.Set;
+import java.io.Serializable;
+
+/**
+ * An implementation of the {@link
org.jboss.portal.presentation.state.navigational.NavigationalStateContext} interface
+ * that is serializable.
+ *
+ * @author <a href="mailto:julien@jboss.org">Julien Viet</a>
+ * @version $Revision: 630 $
+ */
+public abstract class SimpleNavigationalStateContext extends
AbstractNavigationalStateContext implements Serializable
+{
+
+ abstract protected Map<String, Serializable> getMap(String objectId, boolean
create);
+
+ abstract protected void destroyMap(String objectId);
+
+ public final Set<String> safeGetPropertyNames(String objectId)
+ {
+ Map<String, Serializable> properties = getMap(objectId, false);
+
+ //
+ return properties != null ? properties.keySet() : null;
+ }
+
+ public final void safeSetProperty(String objectId, String key, Serializable
navigationalState) throws StateChangeVetoException, StateException,
IllegalArgumentException
+ {
+ Map<String, Serializable> properties = getMap(objectId, false);
+
+ //
+ if (navigationalState != null)
+ {
+ if (properties == null)
+ {
+ properties = getMap(objectId, true);
+ }
+
+ //
+ properties.put(key, navigationalState);
+ }
+ else
+ {
+ if (properties != null)
+ {
+ properties.remove(key);
+
+ //
+ if (properties.isEmpty())
+ {
+ destroyMap(objectId);
+ }
+ }
+ }
+ }
+
+ public final Serializable safeGetProperty(String objectId, String key) throws
IllegalArgumentException
+ {
+ Map<String, Serializable> properties = getMap(objectId, false);
+
+ //
+ if (properties != null)
+ {
+ return properties.get(key);
+ }
+ else
+ {
+ return null;
+ }
+ }
+}
\ No newline at end of file
Modified:
modules/presentation/trunk/presentation/src/main/java/org/jboss/portal/presentation/state/navigational/NavigationalStateContext.java
===================================================================
---
modules/presentation/trunk/presentation/src/main/java/org/jboss/portal/presentation/state/navigational/NavigationalStateContext.java 2008-06-29
11:22:39 UTC (rev 11189)
+++
modules/presentation/trunk/presentation/src/main/java/org/jboss/portal/presentation/state/navigational/NavigationalStateContext.java 2008-06-29
13:37:07 UTC (rev 11190)
@@ -41,8 +41,9 @@
*
* @param objectId the object id
* @return the set of property names
+ * @throws IllegalArgumentException if any argument is null
*/
- Set<String> getPropertyNames(String objectId);
+ Set<String> getPropertyNames(String objectId) throws IllegalArgumentException;
/**
* Returns the property value for the specified object id and key.