Author: julien(a)jboss.com
Date: 2007-03-08 20:12:42 -0500 (Thu, 08 Mar 2007)
New Revision: 6606
Added:
trunk/portlet/src/main/org/jboss/portal/test/portlet/PortletRequestEncoderTestCase.java
Modified:
trunk/core-admin/src/main/org/jboss/portal/core/admin/ui/portlet/PortletContentEditorPortlet.java
trunk/core-admin/src/resources/portal-admin-war/WEB-INF/jsf/editPageLayout.xhtml
trunk/core-admin/src/resources/portal-admin-war/WEB-INF/jsf/editWindow.xhtml
trunk/core-cms/src/main/org/jboss/portal/core/cms/ui/CMSPortlet.java
trunk/core-cms/src/main/org/jboss/portal/core/cms/ui/admin/CMSContentEditorPortlet.java
trunk/core/src/main/org/jboss/portal/core/impl/model/portal/content/GenericPortletContentRenderer.java
trunk/portlet/build.xml
trunk/portlet/src/main/org/jboss/portal/portlet/impl/PortletRequestEncoder.java
trunk/widget/src/main/org/jboss/portal/widget/WidgetPortlet.java
Log:
- removed the edit_content and view_content, just use edit and view as it was not trivial
to really interpret those modes into the portal
- fixed bugs in PortletRequestEncoder which was causing the portlet external navigation
(click on maximize for example) to reset the render parameters
- added test case for PortletRequestEncoder
Modified:
trunk/core/src/main/org/jboss/portal/core/impl/model/portal/content/GenericPortletContentRenderer.java
===================================================================
---
trunk/core/src/main/org/jboss/portal/core/impl/model/portal/content/GenericPortletContentRenderer.java 2007-03-08
21:55:40 UTC (rev 6605)
+++
trunk/core/src/main/org/jboss/portal/core/impl/model/portal/content/GenericPortletContentRenderer.java 2007-03-09
01:12:42 UTC (rev 6606)
@@ -32,9 +32,7 @@
import org.jboss.portal.core.controller.ControllerContext;
import org.jboss.portal.core.impl.model.content.ContentEditorRegistry;
import org.jboss.portal.portlet.PortletParametersStateString;
-import org.jboss.portal.Mode;
import org.jboss.portal.theme.page.WindowResult;
-import org.jboss.portal.theme.navigation.WindowNavigationalState;
import java.util.Map;
import java.util.HashMap;
@@ -48,9 +46,6 @@
{
/** . */
- public static final Mode VIEW_CONTENT_MODE = new Mode("view_content");
-
- /** . */
private String instanceName;
/** . */
@@ -136,16 +131,6 @@
context.setAttribute(RenderWindowCommand.NAVIGATIONAL_STATE_SCOPE, windowId,
navigationalState);
}
- // Set the view content mode
- String navStateKey = windowId + "_window";
- WindowNavigationalState windowNavState =
(WindowNavigationalState)context.getAttribute(RenderWindowCommand.NAVIGATIONAL_STATE_SCOPE,
navStateKey);
- if (windowNavState == null)
- {
- windowNavState = new WindowNavigationalState();
- context.setAttribute(RenderWindowCommand.NAVIGATIONAL_STATE_SCOPE, navStateKey,
windowNavState);
- }
- windowNavState.setMode(VIEW_CONTENT_MODE);
-
//
Object o = super.renderWindow(cmd);
Modified:
trunk/core-admin/src/main/org/jboss/portal/core/admin/ui/portlet/PortletContentEditorPortlet.java
===================================================================
---
trunk/core-admin/src/main/org/jboss/portal/core/admin/ui/portlet/PortletContentEditorPortlet.java 2007-03-08
21:55:40 UTC (rev 6605)
+++
trunk/core-admin/src/main/org/jboss/portal/core/admin/ui/portlet/PortletContentEditorPortlet.java 2007-03-09
01:12:42 UTC (rev 6606)
@@ -51,9 +51,6 @@
{
/** . */
- private static final PortletMode EDIT_CONTENT = new
PortletMode("edit_content");
-
- /** . */
private InstanceContainer instanceContainer;
public void init() throws PortletException
@@ -64,119 +61,84 @@
public void processAction(ActionRequest req, ActionResponse resp) throws
PortletException, PortletSecurityException, IOException
{
- if (req.getPortletMode().equals(EDIT_CONTENT))
+ if (req.getPortletMode().equals(PortletMode.EDIT))
{
String uri = req.getParameter("uri");
- String from = req.getParameter("from");
if (uri != null)
{
resp.setRenderParameter("uri", uri);
}
- if (from != null)
- {
- resp.setRenderParameter("from", from);
- }
}
}
- public void render(RenderRequest req, RenderResponse resp) throws PortletException,
PortletSecurityException, IOException
+ protected void doEdit(RenderRequest req, RenderResponse resp) throws PortletException,
PortletSecurityException, IOException
{
- if (req.getPortletMode().equals(EDIT_CONTENT))
- {
- String selectedURI = req.getParameter("uri");
- String selectedFrom = req.getParameter("from");
- int pagination = 10;
- int from = 0;
- if (selectedFrom != null)
- {
- from = new Integer(selectedFrom).intValue();
- }
-
- //
- resp.setContentType("text/html");
- PrintWriter writer = resp.getWriter();
+ String selectedURI = req.getParameter("uri");
- // load insances this user has access to.
- List available_instances = (List)instanceContainer.getDefinitions();
+ //
+ PortletURL actionURL = resp.createActionURL();
+ actionURL.setParameter("meta_action", "select");
- writer.println("<script>");
- writer.println("function togglediv(nr) {");
- writer.println(" if (document.getElementById)");
- writer.println(" {");
- writer.println(" vista = (document.getElementById(nr).style.display ==
'none') ? 'block' : 'none';");
- writer.println(" document.getElementById(nr).style.display =
vista;");
- writer.println(" }");
- writer.println("}");
- writer.println("</script>");
+ //
+ resp.setContentType("text/html");
+ PrintWriter writer = resp.getWriter();
+ // load insances this user has access to.
+ List available_instances = (List)instanceContainer.getDefinitions();
+ Instance selectedInstance = null;
+ writer.print("<form action=\"");
+ writer.print(actionURL);
+ writer.print("\" method=\"post\">\n");
+ writer.println("<select
name=\"uri\"size=\"20\">\n");
+ for (int i = 0; i < available_instances.size(); i++)
+ {
+ Instance instance = (Instance)available_instances.get(i);
- writer.println("<br /><br /><table
id=\"instancesTable2\">");
- writer.println("<thead
class=\"portlet-section-header\">");
- writer.println(" <tr>");
- writer.println(" <th>Portlet instances</th>");
- writer.println(" </tr>");
- writer.println("</thead>");
- writer.println("<tbody>");
- for (int i = from; i < Math.min(available_instances.size(), from +
pagination); i++)
- {
- Instance instance = (Instance)available_instances.get(i);
+ //
+ writer.print("<option value=\"");
+ writer.print(instance.getId());
+ writer.print("\"");
- PortletURL actionURL = resp.createActionURL();
- actionURL.setParameter("meta_action", "select");
- actionURL.setParameter("uri", instance.getId());
- actionURL.setParameter("from", "" + from);
-
- String trClass = instance.getId().equals(selectedURI) ?
"portlet-section-selected" : (i % 2 == 0 ? "portlet-section-body" :
"portlet-section-alternate");
-
- writer.println(" <tr class=\" " + trClass +
"\">");
- writer.println(" <td>");
- writer.println(" <a
onmouseout=\"togglediv('menu"+ i + "');\"
onmouseover=\"togglediv('menu"+ i + "');\" href=\""
+ actionURL + "\">");
- writer.println(instance.getId());
- writer.println("</a>");
- writer.println(" </td>");
- writer.println(" </tr>");
- }
- writer.println(" </tbody>");
- writer.println(" </table>");
- writer.println(" <ul class=\"pagination\">");
- for (int i=0; i<available_instances.size(); i += pagination)
+ //
+ if (instance.getId().equals(selectedURI))
{
- String liClass = i == from ? "selected" : "";
- PortletURL renderURL = resp.createRenderURL();
- if (selectedURI != null)
- {
- renderURL.setParameter("uri", selectedURI);
- }
- renderURL.setParameter("from", "" + i);
- writer.println(" <li class=\"" + liClass +
"\">");
- writer.println(" <a href=\"" + renderURL +
"\">" + i + "</a>");
- writer.println(" </li>");
+ selectedInstance = instance;
+ writer.print(" selected=\"selected\"");
}
- writer.println(" </ul>");
- for (int i = from; i < Math.min(available_instances.size(), from +
pagination); i++)
- {
- Instance instance = (Instance)available_instances.get(i);
+ //
+ writer.print(">");
+ writer.print(instance.getId());
+ writer.println("</option>\n");
+ }
+ writer.println("</select>");
+ writer.println("<input name=\"select\" value=\"Select\"
type=\"submit\"/>");
+ writer.print("</form>");
- writer.print("<div style=\"display:none;\"
id=\"menu" + i + "\">");
- try
+ //
+ if (selectedInstance != null)
+ {
+ writer.print("<div class=\"portlet-font\"
style=\"float:left\">");
+ writer.print("<div><span
class=\"portlet-form-field-label\">Portlet instance:</span>" +
selectedURI + "</div>");
+ try
+ {
+ Portlet portlet = selectedInstance.getPortlet();
+ if (portlet != null)
{
- Portlet portlet = instance.getPortlet();
MetaInfo metaInfo = portlet.getInfo().getMeta();
writer.print("<div><span
class=\"portlet-form-field-label\">Portlet name:</span>" +
metaInfo.getMetaValue(MetaInfo.DISPLAY_NAME).getDefaultString() +
"</div>");
writer.print("<div><span
class=\"portlet-form-field-label\">Portlet description:</span>" +
metaInfo.getMetaValue(MetaInfo.DESCRIPTION).getDefaultString() +
"</div>");
writer.print("<div><span
class=\"portlet-form-field-label\">Portlet title:</span>" +
metaInfo.getMetaValue(MetaInfo.TITLE).getDefaultString() + "</div>");
writer.print("<div><span
class=\"portlet-form-field-label\">Portlet keywords:</span>" +
metaInfo.getMetaValue(MetaInfo.KEYWORDS).getDefaultString() + "</div>");
}
- catch (PortletInvokerException e)
- {
- e.printStackTrace();
- }
- writer.print("</div>");
}
-
- //
- writer.close();
+ catch (PortletInvokerException e)
+ {
+ e.printStackTrace();
+ }
}
+
+ //
+ writer.close();
}
}
Modified:
trunk/core-admin/src/resources/portal-admin-war/WEB-INF/jsf/editPageLayout.xhtml
===================================================================
---
trunk/core-admin/src/resources/portal-admin-war/WEB-INF/jsf/editPageLayout.xhtml 2007-03-08
21:55:40 UTC (rev 6605)
+++
trunk/core-admin/src/resources/portal-admin-war/WEB-INF/jsf/editPageLayout.xhtml 2007-03-09
01:12:42 UTC (rev 6606)
@@ -96,9 +96,9 @@
<jbp:portlet
instanceId="#{portalobjectmgr.selectedContentEditorInstance}"
actionListener="#{portalobjectmgr.processEvent}"
- supportedModes="edit_content"
+ supportedModes="edit"
supportedWindowStates="normal"
- initialMode="edit_content"
+ initialMode="edit"
initialWindowState="normal"/>
</div>
Modified: trunk/core-admin/src/resources/portal-admin-war/WEB-INF/jsf/editWindow.xhtml
===================================================================
---
trunk/core-admin/src/resources/portal-admin-war/WEB-INF/jsf/editWindow.xhtml 2007-03-08
21:55:40 UTC (rev 6605)
+++
trunk/core-admin/src/resources/portal-admin-war/WEB-INF/jsf/editWindow.xhtml 2007-03-09
01:12:42 UTC (rev 6606)
@@ -15,9 +15,9 @@
actionListener="#{portalobjectmgr.processEvent}"
instanceId="#{portalobjectmgr.selectedContentEditorInstance}"
renderParameters="#{portalobjectmgr.renderParameters}"
- supportedModes="edit_content"
+ supportedModes="edit"
supportedWindowStates="normal"
- initialMode="edit_content"
+ initialMode="edit"
initialWindowState="normal"/>
</div>
Modified: trunk/core-cms/src/main/org/jboss/portal/core/cms/ui/CMSPortlet.java
===================================================================
--- trunk/core-cms/src/main/org/jboss/portal/core/cms/ui/CMSPortlet.java 2007-03-08
21:55:40 UTC (rev 6605)
+++ trunk/core-cms/src/main/org/jboss/portal/core/cms/ui/CMSPortlet.java 2007-03-09
01:12:42 UTC (rev 6606)
@@ -37,7 +37,6 @@
import javax.portlet.PortletURL;
import javax.portlet.RenderRequest;
import javax.portlet.RenderResponse;
-import javax.portlet.PortletMode;
import javax.portlet.PortletConfig;
import javax.portlet.ActionRequest;
import javax.portlet.ActionResponse;
@@ -196,50 +195,16 @@
hack.processAction(request, response);
}
- protected void doDispatch(RenderRequest req, RenderResponse resp) throws
PortletException, PortletSecurityException, IOException
+ protected void doView(RenderRequest req, RenderResponse resp) throws PortletException,
PortletSecurityException, IOException
{
- PortletMode portletMode = req.getPortletMode();
- if ("view_content".equals(portletMode.toString()))
- {
- doViewContent(req, resp);
- }
- else if ("edit_content".equals(portletMode.toString()))
- {
- hack.render(req, resp);
- }
- else
- {
- super.doDispatch(req, resp);
- }
- }
-
- protected void doViewContent(RenderRequest req, RenderResponse resp) throws
PortletException, PortletSecurityException, IOException
- {
String path = req.getParameter(RENDER_PARAMETER_PATH);
- if (path != null)
+ if (path == null)
{
- display(req, resp, path);
+ PortletPreferences prefs = req.getPreferences();
+ path = prefs.getValue("indexpage", "/default/index.html");
}
- else
- {
- doView(req, resp);
- }
- }
- protected void doEditContent(RenderRequest req, RenderResponse resp) throws
PortletException, PortletSecurityException, IOException
- {
- hack.render(req, resp);
- }
-
- protected void doView(RenderRequest req, RenderResponse resp) throws PortletException,
PortletSecurityException, IOException
- {
- PortletPreferences prefs = req.getPreferences();
- String indexpage = prefs.getValue("indexpage",
"/default/index.html");
- display(req, resp, indexpage);
- }
-
- private void display(RenderRequest req, RenderResponse resp, String path) throws
PortletException, PortletSecurityException, IOException
- {
+ //
String useGlobalURLs = req.getProperty(REQUEST_PROPERTY_USE_GLOBAL_URLS);
URLFactory textURLFactory = null;
if ("true".equals(useGlobalURLs))
@@ -251,6 +216,7 @@
textURLFactory = new LocalURLFactory(resp.createRenderURL());
}
+ //
URLFactory resourceURLFactory = new
GlobalURLFactory(((JBossRenderRequest)req).getControllerContext());
//
@@ -345,11 +311,12 @@
public void doEdit(RenderRequest req, RenderResponse resp) throws IOException,
PortletException
{
- resp.setContentType("text/html");
- resp.setTitle("Edit");
- // TODO: Allow users to modify start page preferences.
- PortletRequestDispatcher prd =
getPortletContext().getRequestDispatcher(CMS_JSP_PATH + "/edit.jsp");
- prd.include(req, resp);
+// resp.setContentType("text/html");
+// resp.setTitle("Edit");
+// // TODO: Allow users to modify start page preferences.
+// PortletRequestDispatcher prd =
getPortletContext().getRequestDispatcher(CMS_JSP_PATH + "/edit.jsp");
+// prd.include(req, resp);
+ hack.render(req, resp);
}
/**
Modified:
trunk/core-cms/src/main/org/jboss/portal/core/cms/ui/admin/CMSContentEditorPortlet.java
===================================================================
---
trunk/core-cms/src/main/org/jboss/portal/core/cms/ui/admin/CMSContentEditorPortlet.java 2007-03-08
21:55:40 UTC (rev 6605)
+++
trunk/core-cms/src/main/org/jboss/portal/core/cms/ui/admin/CMSContentEditorPortlet.java 2007-03-09
01:12:42 UTC (rev 6606)
@@ -44,9 +44,8 @@
*/
public class CMSContentEditorPortlet extends GenericPortlet
{
- /** . */
- private static final PortletMode EDIT_CONTENT = new
PortletMode("edit_content");
+ /** . */
private CMS cmsService;
public void init() throws PortletException
@@ -56,7 +55,7 @@
public void processAction(ActionRequest req, ActionResponse resp) throws
PortletException, PortletSecurityException, IOException
{
- if (req.getPortletMode().equals(EDIT_CONTENT))
+ if (req.getPortletMode().equals(PortletMode.EDIT))
{
String uri = req.getParameter("uri");
String path = req.getParameter("path");
@@ -71,34 +70,29 @@
resp.setRenderParameter("meta_action", "blah");
}
}
-
- public void render(RenderRequest req, RenderResponse resp) throws PortletException,
PortletSecurityException, IOException
+
+ protected void doEdit(RenderRequest req, RenderResponse resp) throws PortletException,
PortletSecurityException, IOException
{
- if (req.getPortletMode().equals(EDIT_CONTENT))
+ resp.setContentType("text/html");
+
+ String sPath = req.getParameter("path");
+ if (sPath == null)
{
- resp.setContentType("text/html");
+ sPath = "/";
+ }
- String sPath = req.getParameter("path");
- if (sPath == null)
- {
- sPath = "/";
- }
+ Command listCMD =
cmsService.getCommandFactory().createFolderGetListCommand(sPath);
+ Folder mainFolder = (Folder)cmsService.execute(listCMD);
+ List folders = mainFolder.getFolders();
+ List files = mainFolder.getFiles();
- Command listCMD =
cmsService.getCommandFactory().createFolderGetListCommand(sPath);
- Folder mainFolder = (Folder)cmsService.execute(listCMD);
- List folders = mainFolder.getFolders();
- List files = mainFolder.getFiles();
+ resp.setContentType("text/html");
+ req.setAttribute("folders", folders);
+ req.setAttribute("files", files);
+ req.setAttribute("currpath", sPath);
- resp.setContentType("text/html");
- req.setAttribute("folders", folders);
- req.setAttribute("files", files);
- req.setAttribute("currpath", sPath);
-
- javax.portlet.PortletRequestDispatcher prd =
getPortletContext().getRequestDispatcher(CMSEditorConstants.CMS_EDITOR_JSP_PATH +
"/main.jsp");
- prd.include(req, resp);
- }
+ javax.portlet.PortletRequestDispatcher prd =
getPortletContext().getRequestDispatcher(CMSEditorConstants.CMS_EDITOR_JSP_PATH +
"/main.jsp");
+ prd.include(req, resp);
}
-
-
}
Modified: trunk/portlet/build.xml
===================================================================
--- trunk/portlet/build.xml 2007-03-08 21:55:40 UTC (rev 6605)
+++ trunk/portlet/build.xml 2007-03-09 01:12:42 UTC (rev 6606)
@@ -553,12 +553,15 @@
<test todir="${test.reports}"
name="org.jboss.portal.test.portlet.state.RemoteStoreConsumerStatefulPortletInvokerTestCase"/>
<test todir="${test.reports}"
name="org.jboss.portal.test.portlet.state.StateConverterV0TestCase"/>
<test todir="${test.reports}"
name="org.jboss.portal.test.portlet.PortletRequestDecoderTestCase"/>
+ <test todir="${test.reports}"
name="org.jboss.portal.test.portlet.PortletRequestEncoderTestCase"/>
<test todir="${test.reports}"
name="org.jboss.portal.test.portlet.ParametersTestCase"/>
<test todir="${test.reports}"
name="org.jboss.portal.test.portlet.PropertiesTestCase"/>
</x-test>
<x-sysproperty>
+<!--
<sysproperty key="test.root"
value="${build.lib}"/>
<sysproperty key="test.uri"
value="/test/redirect/"/>
+-->
<!--
<jvmarg value="-Xdebug"/>
<jvmarg
value="-Xrunjdwp:transport=dt_socket,address=8787,server=y,suspend=y"/>
Modified: trunk/portlet/src/main/org/jboss/portal/portlet/impl/PortletRequestEncoder.java
===================================================================
---
trunk/portlet/src/main/org/jboss/portal/portlet/impl/PortletRequestEncoder.java 2007-03-08
21:55:40 UTC (rev 6605)
+++
trunk/portlet/src/main/org/jboss/portal/portlet/impl/PortletRequestEncoder.java 2007-03-09
01:12:42 UTC (rev 6606)
@@ -139,11 +139,11 @@
queryParameters.clear();
//
- int meta = PortletRequestDecoder.RENDER_MASK;
-
- //
if (navigationalState != null)
{
+ int meta = PortletRequestDecoder.RENDER_MASK;
+
+ //
if (navigationalState instanceof PortletParametersStateString)
{
// Add the parameters
@@ -157,10 +157,23 @@
//
queryParameters.setValue(PortletRequestDecoder.NAVIGATIONAL_STATE_PARAMETER,
navigationalState.getStringValue());
}
+
+ //
+ configure(meta, mode, windowState);
}
+ else
+ {
+ if (mode != null)
+ {
+ queryParameters.setValue(PortletRequestDecoder.MODE_PARAMETER,
mode.toString());
+ }
- //
- configure(meta, mode, windowState);
+ //
+ if (windowState != null)
+ {
+ queryParameters.setValue(PortletRequestDecoder.WINDOW_STATE_PARAMETER,
windowState.toString());
+ }
+ }
}
public ParameterMap getQueryParameters()
Added:
trunk/portlet/src/main/org/jboss/portal/test/portlet/PortletRequestEncoderTestCase.java
===================================================================
---
trunk/portlet/src/main/org/jboss/portal/test/portlet/PortletRequestEncoderTestCase.java
(rev 0)
+++
trunk/portlet/src/main/org/jboss/portal/test/portlet/PortletRequestEncoderTestCase.java 2007-03-09
01:12:42 UTC (rev 6606)
@@ -0,0 +1,217 @@
+/******************************************************************************
+ * 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.test.portlet;
+
+import junit.framework.TestCase;
+import org.jboss.portal.portlet.impl.PortletRequestEncoder;
+import org.jboss.portal.portlet.impl.PortletRequestDecoder;
+import org.jboss.portal.portlet.PortletParameters;
+import org.jboss.portal.portlet.PortletParametersStateString;
+import org.jboss.portal.common.util.ParameterMap;
+import org.jboss.portal.common.junit.ExtendedAssert;
+import org.jboss.portal.Mode;
+import org.jboss.portal.WindowState;
+
+/**
+ * @author <a href="mailto:julien@jboss.org">Julien Viet</a>
+ * @version $Revision: 1.1 $
+ */
+public class PortletRequestEncoderTestCase extends TestCase
+{
+
+ /** . */
+ public static final int RENDER = 0;
+
+ /** . */
+ public static final int ACTION = 1;
+
+ /** . */
+ private ParameterMap params;
+
+ /** . */
+ private PortletRequestEncoder encoder;
+
+ protected void setUp() throws Exception
+ {
+ params = new PortletParameters();
+ encoder = new PortletRequestEncoder(params);
+ }
+
+ protected void tearDown() throws Exception
+ {
+ params = null;
+ encoder = null;
+ }
+
+ public void testEncodeRender()
+ {
+ _testEncodeRender(RENDER, PortletRequestDecoder.RENDER_MASK);
+ }
+
+ public void testEncodeAction()
+ {
+ _testEncodeRender(ACTION, PortletRequestDecoder.ACTION_MASK);
+ }
+
+ public void _testEncodeRender(int lifecycle, int lifecycleMask)
+ {
+ PortletParametersStateString pp = new PortletParametersStateString();
+ encode(pp, null, null, lifecycle);
+ assertEquals(1, params.size());
+ assertEquals(lifecycleMask,
params.getValues(PortletRequestDecoder.META_PARAMETER));
+
+ //
+ pp = new PortletParametersStateString();
+ pp.setValue(PortletRequestDecoder.META_PARAMETER, "foo");
+ encode(pp, null, null, lifecycle);
+ assertEquals(1, params.size());
+ assertEquals(new String[]{Integer.toHexString(lifecycleMask),"foo"},
params.getValues(PortletRequestDecoder.META_PARAMETER));
+
+ //
+ pp = new PortletParametersStateString();
+ pp.setValue("foo", "bar");
+ encode(pp, null, null, lifecycle);
+ assertEquals(2, params.size());
+ assertEquals(lifecycleMask,
params.getValues(PortletRequestDecoder.META_PARAMETER));
+ assertEquals("bar", params.getValues("foo"));
+
+ //
+ pp = new PortletParametersStateString();
+ encode(pp, Mode.VIEW, null, lifecycle);
+ assertEquals(2, params.size());
+ assertEquals(lifecycleMask | PortletRequestDecoder.MODE_MASK,
params.getValues(PortletRequestDecoder.META_PARAMETER));
+ assertEquals(Mode.VIEW, params.getValues(PortletRequestDecoder.MODE_PARAMETER));
+
+ //
+ pp = new PortletParametersStateString();
+ pp.setValue(PortletRequestDecoder.MODE_PARAMETER, "foo");
+ encode(pp, Mode.VIEW, null, lifecycle);
+ assertEquals(2, params.size());
+ assertEquals(lifecycleMask | PortletRequestDecoder.MODE_MASK,
params.getValues(PortletRequestDecoder.META_PARAMETER));
+ assertEquals(new String[]{Mode.VIEW.toString(),"foo"},
params.getValues(PortletRequestDecoder.MODE_PARAMETER));
+
+ //
+ pp = new PortletParametersStateString();
+ pp.setValue("foo", "bar");
+ encode(pp, Mode.VIEW, null, lifecycle);
+ assertEquals(3, params.size());
+ assertEquals(lifecycleMask | PortletRequestDecoder.MODE_MASK,
params.getValues(PortletRequestDecoder.META_PARAMETER));
+ assertEquals(Mode.VIEW, params.getValues(PortletRequestDecoder.MODE_PARAMETER));
+ assertEquals("bar", params.getValues("foo"));
+
+ //
+ pp = new PortletParametersStateString();
+ encode(pp, null, WindowState.NORMAL, lifecycle);
+ assertEquals(2, params.size());
+ assertEquals(lifecycleMask | PortletRequestDecoder.WINDOW_STATE_MASK,
params.getValues(PortletRequestDecoder.META_PARAMETER));
+ assertEquals(WindowState.NORMAL,
params.getValues(PortletRequestDecoder.WINDOW_STATE_PARAMETER));
+
+ //
+ pp = new PortletParametersStateString();
+ pp.setValue(PortletRequestDecoder.WINDOW_STATE_PARAMETER, "foo");
+ encode(pp, null, WindowState.NORMAL, lifecycle);
+ assertEquals(2, params.size());
+ assertEquals(lifecycleMask | PortletRequestDecoder.WINDOW_STATE_MASK,
params.getValues(PortletRequestDecoder.META_PARAMETER));
+ assertEquals(new String[]{WindowState.NORMAL.toString(),"foo"},
params.getValues(PortletRequestDecoder.WINDOW_STATE_PARAMETER));
+
+ //
+ pp = new PortletParametersStateString();
+ pp.setValue("foo", "bar");
+ encode(pp, null, WindowState.NORMAL, lifecycle);
+ assertEquals(3, params.size());
+ assertEquals(lifecycleMask | PortletRequestDecoder.WINDOW_STATE_MASK,
params.getValues(PortletRequestDecoder.META_PARAMETER));
+ assertEquals(WindowState.NORMAL,
params.getValues(PortletRequestDecoder.WINDOW_STATE_PARAMETER));
+ assertEquals("bar", params.getValues("foo"));
+
+ //
+ pp = new PortletParametersStateString();
+ encode(pp, Mode.VIEW, WindowState.NORMAL, lifecycle);
+ assertEquals(3, params.size());
+ assertEquals(lifecycleMask | PortletRequestDecoder.MODE_MASK |
PortletRequestDecoder.WINDOW_STATE_MASK,
params.getValues(PortletRequestDecoder.META_PARAMETER));
+ assertEquals(Mode.VIEW, params.getValues(PortletRequestDecoder.MODE_PARAMETER));
+ assertEquals(WindowState.NORMAL,
params.getValues(PortletRequestDecoder.WINDOW_STATE_PARAMETER));
+
+ //
+ pp = new PortletParametersStateString();
+ pp.setValue("foo", "bar");
+ encode(pp, Mode.VIEW, WindowState.NORMAL, lifecycle);
+ assertEquals(4, params.size());
+ assertEquals(lifecycleMask | PortletRequestDecoder.MODE_MASK |
PortletRequestDecoder.WINDOW_STATE_MASK,
params.getValues(PortletRequestDecoder.META_PARAMETER));
+ assertEquals(Mode.VIEW, params.getValues(PortletRequestDecoder.MODE_PARAMETER));
+ assertEquals(WindowState.NORMAL,
params.getValues(PortletRequestDecoder.WINDOW_STATE_PARAMETER));
+ assertEquals("bar", params.getValues("foo"));
+ }
+
+ public void testEncodeNav()
+ {
+ encode(null, null, null, RENDER);
+ assertEquals(0, params.size());
+
+ //
+ encode(null, Mode.VIEW, null, RENDER);
+ assertEquals(1, params.size());
+ assertEquals(Mode.VIEW, params.getValues(PortletRequestDecoder.MODE_PARAMETER));
+
+ //
+ encode(null, null, WindowState.NORMAL, RENDER);
+ assertEquals(1, params.size());
+ assertEquals(WindowState.NORMAL,
params.getValues(PortletRequestDecoder.WINDOW_STATE_PARAMETER));
+
+ //
+ encode(null, Mode.VIEW, WindowState.NORMAL, RENDER);
+ assertEquals(2, params.size());
+ assertEquals(Mode.VIEW, params.getValues(PortletRequestDecoder.MODE_PARAMETER));
+ assertEquals(WindowState.NORMAL,
params.getValues(PortletRequestDecoder.WINDOW_STATE_PARAMETER));
+ }
+
+ private void encode(PortletParametersStateString params, Mode view, WindowState
normal, int lifecycle)
+ {
+ if (lifecycle == RENDER)
+ {
+ encoder.encodeRender(params, view, normal);
+ }
+ else if (lifecycle == ACTION)
+ {
+ encoder.encodeAction(null, params, view, normal);
+ }
+ else
+ {
+ fail();
+ }
+ }
+
+ void assertEquals(int expected, String[] actual)
+ {
+ ExtendedAssert.assertEquals(new String[]{Integer.toHexString(expected)}, actual);
+ }
+
+ void assertEquals(Object expected, String[] actual)
+ {
+ ExtendedAssert.assertEquals(new String[]{"" + expected}, actual);
+ }
+
+ void assertEquals(String[] expected, String[] actual)
+ {
+ ExtendedAssert.assertEquals(expected, actual);
+ }
+}
Modified: trunk/widget/src/main/org/jboss/portal/widget/WidgetPortlet.java
===================================================================
--- trunk/widget/src/main/org/jboss/portal/widget/WidgetPortlet.java 2007-03-08 21:55:40
UTC (rev 6605)
+++ trunk/widget/src/main/org/jboss/portal/widget/WidgetPortlet.java 2007-03-09 01:12:42
UTC (rev 6606)
@@ -33,7 +33,6 @@
import javax.portlet.PortletException;
import javax.portlet.PortletSecurityException;
import javax.portlet.PortletURL;
-import javax.portlet.PortletMode;
import javax.portlet.ActionRequest;
import javax.portlet.ActionResponse;
import java.io.IOException;
@@ -49,12 +48,6 @@
{
/** . */
- private static final PortletMode VIEW_CONTENT_MODE = new
PortletMode("view_content");
-
- /** . */
- private static final PortletMode EDIT_CONTENT_MODE = new
PortletMode("edit_content");
-
- /** . */
private GGWidgetProvider provider = new GGWidgetProvider();
public void init() throws PortletException
@@ -67,83 +60,82 @@
{
}
- public void render(RenderRequest req, RenderResponse resp) throws PortletException,
PortletSecurityException, IOException
+ protected void doView(RenderRequest req, RenderResponse resp) throws PortletException,
PortletSecurityException, IOException
{
- if (VIEW_CONTENT_MODE.equals(req.getPortletMode()))
+ resp.setContentType("text/html");
+ PrintWriter writer = resp.getWriter();
+ String uri = req.getParameter("uri");
+ Widget widget = provider.getWidget(uri);
+ if (widget != null)
{
- resp.setContentType("text/html");
- PrintWriter writer = resp.getWriter();
- String uri = req.getParameter("uri");
- Widget widget = provider.getWidget(uri);
- if (widget != null)
- {
- writer.print(widget.render(req.getParameterMap()));
- }
- else
- {
- writer.print("Widget is not available");
- }
- writer.close();
+ writer.print(widget.render(req.getParameterMap()));
}
- else if (EDIT_CONTENT_MODE.equals(req.getPortletMode()))
+ else
{
- resp.setContentType("text/html");
- PrintWriter writer = resp.getWriter();
+ writer.print("Widget is not available");
+ }
+ writer.close();
+ }
- //
- String op = req.getParameter("op");
- if ("select".equals(op))
+
+ protected void doEdit(RenderRequest req, RenderResponse resp) throws PortletException,
PortletSecurityException, IOException
+ {
+ resp.setContentType("text/html");
+ PrintWriter writer = resp.getWriter();
+
+ //
+ String op = req.getParameter("op");
+ if ("select".equals(op))
+ {
+ String uri = req.getParameter("uri");
+ GGWidget widget = (GGWidget)provider.getWidget(uri);
+ if (widget != null)
{
- String uri = req.getParameter("uri");
- GGWidget widget = (GGWidget)provider.getWidget(uri);
- if (widget != null)
- {
- PortletURL selectURL = resp.createActionURL();
- selectURL.setParameter("meta_action", "select");
- selectURL.setParameter("uri", uri);
- writer.println("<p>You selected widget " +
widget.getTitle() + "</p>");
- writer.println("<p><a href=\"" + selectURL +
"\">Select</a> widget</p>");
+ PortletURL selectURL = resp.createActionURL();
+ selectURL.setParameter("meta_action", "select");
+ selectURL.setParameter("uri", uri);
+ writer.println("<p>You selected widget " + widget.getTitle()
+ "</p>");
+ writer.println("<p><a href=\"" + selectURL +
"\">Select</a> widget</p>");
- // Prefs
- writer.println("<form action=\"" + selectURL +
"\" method=\"post\">");
- for (Iterator i =
widget.getPreferencesInfo().getPreferencesInfo().iterator();i.hasNext();)
+ // Prefs
+ writer.println("<form action=\"" + selectURL +
"\" method=\"post\">");
+ for (Iterator i =
widget.getPreferencesInfo().getPreferencesInfo().iterator();i.hasNext();)
+ {
+ GGPreferenceInfo prefInfo = (GGPreferenceInfo)i.next();
+ switch (prefInfo.getType().getOrdinal())
{
- GGPreferenceInfo prefInfo = (GGPreferenceInfo)i.next();
- switch (prefInfo.getType().getOrdinal())
- {
- case DataType.ENUM:
- // Todo
- break;
- default:
- writer.println("<div>" + prefInfo.getName() +
": <input type=\"text\" name=\"param." + prefInfo.getName() +
"\"" +
- (prefInfo.getDefaultValue() != null ? ("
value=\"" + prefInfo.getDefaultValue() + "\"") : "") +
"/></div>");
- }
+ case DataType.ENUM:
+ // Todo
+ break;
+ default:
+ writer.println("<div>" + prefInfo.getName() +
": <input type=\"text\" name=\"param." + prefInfo.getName() +
"\"" +
+ (prefInfo.getDefaultValue() != null ? (" value=\""
+ prefInfo.getDefaultValue() + "\"") : "") +
"/></div>");
}
- writer.println("<input type=\"submit\"/>");
- writer.println("</form>");
}
+ writer.println("<input type=\"submit\"/>");
+ writer.println("</form>");
}
+ }
- //
- Collection widgets = provider.getKeys();
- writer.print("<ul>");
- int size = 0;
- for (Iterator i = widgets.iterator();i.hasNext() && size < 9;size++)
+ //
+ Collection widgets = provider.getKeys();
+ writer.print("<ul>");
+ int size = 0;
+ for (Iterator i = widgets.iterator();i.hasNext() && size < 9;size++)
+ {
+ String key = (String)i.next();
+ Widget widget = provider.getWidget(key);
+ if (widget != null)
{
- String key = (String)i.next();
- Widget widget = provider.getWidget(key);
- if (widget != null)
- {
- PortletURL url = resp.createRenderURL();
- url.setParameter("op", "select");
- url.setParameter("uri", widget.getId());
- writer.print("<li><a href=\"" + url +
"\">" + widget.getTitle().getDefaultString() +
"</a></li>");
- }
+ PortletURL url = resp.createRenderURL();
+ url.setParameter("op", "select");
+ url.setParameter("uri", widget.getId());
+ writer.print("<li><a href=\"" + url +
"\">" + widget.getTitle().getDefaultString() +
"</a></li>");
}
-
- writer.print("/<ul>");
- writer.close();
}
+
+ writer.print("/<ul>");
+ writer.close();
}
public void destroy()