Author: woonsan
Date: Wed May 19 16:04:06 2010
New Revision: 946249
URL: http://svn.apache.org/viewvc?rev=946249&view=rev
Log:
Adding content editing feature in NewsItemPortlet in edit mode.
Added:
portals/applications/sandbox/content/trunk/apa-content-webapp/src/main/webapp/WEB-INF/view/news-item-edit.jsp
(with props)
Modified:
portals/applications/sandbox/content/trunk/apa-content-portlet/src/main/java/org/apache/portals/applications/content/GenericContentPortlet.java
portals/applications/sandbox/content/trunk/apa-content-portlet/src/main/java/org/apache/portals/applications/content/GenericSearchQueryContentPortlet.java
portals/applications/sandbox/content/trunk/apa-content-webapp/src/main/webapp/WEB-INF/portlet.xml
portals/applications/sandbox/content/trunk/apa-content-webapp/src/main/webapp/WEB-INF/view/generic-content-edit.jsp
portals/applications/sandbox/content/trunk/apa-content-webapp/src/main/webapp/WEB-INF/view/generic-query-content-edit.jsp
portals/applications/sandbox/content/trunk/apa-content-webapp/src/main/webapp/WEB-INF/view/generic-search-query-content-edit.jsp
portals/applications/sandbox/content/trunk/apa-content-webapp/src/main/webapp/WEB-INF/view/news-item-view.jsp
portals/applications/sandbox/content/trunk/apa-content-webapp/src/main/webapp/WEB-INF/view/simple-search-query-content-edit.jsp
Modified:
portals/applications/sandbox/content/trunk/apa-content-portlet/src/main/java/org/apache/portals/applications/content/GenericContentPortlet.java
URL:
http://svn.apache.org/viewvc/portals/applications/sandbox/content/trunk/apa-content-portlet/src/main/java/org/apache/portals/applications/content/GenericContentPortlet.java?rev=946249&r1=946248&r2=946249&view=diff
==============================================================================
---
portals/applications/sandbox/content/trunk/apa-content-portlet/src/main/java/org/apache/portals/applications/content/GenericContentPortlet.java
(original)
+++
portals/applications/sandbox/content/trunk/apa-content-portlet/src/main/java/org/apache/portals/applications/content/GenericContentPortlet.java
Wed May 19 16:04:06 2010
@@ -17,7 +17,9 @@
package org.apache.portals.applications.content;
import java.io.IOException;
+import java.util.HashSet;
import java.util.Map;
+import java.util.Set;
import javax.jcr.Credentials;
import javax.jcr.Repository;
@@ -34,6 +36,7 @@ import javax.portlet.PortletPreferences;
import javax.portlet.PortletRequest;
import javax.portlet.RenderRequest;
import javax.portlet.RenderResponse;
+import javax.portlet.WindowState;
import org.apache.commons.beanutils.PropertyUtils;
import org.apache.commons.lang.StringUtils;
@@ -66,6 +69,10 @@ public class GenericContentPortlet exten
private String preferenceRequestParamPrefix = "preference.";
+ private String contentRequestParamPrefix = "content.";
+
+ private Set<PortletMode> portletModesWithContentBean = new
HashSet<PortletMode>();
+
@Override
public void init(PortletConfig config) throws PortletException
{
@@ -120,60 +127,95 @@ public class GenericContentPortlet exten
contentBeanAttributeName = param;
}
- param = StringUtils.trim(getInitParameterFromConfigOrContext(config,
"contentBeanAttributeName", null));
+ param = StringUtils.trim(getInitParameterFromConfigOrContext(config,
"preferenceRequestParamPrefix", null));
if (param != null)
{
preferenceRequestParamPrefix = param;
}
- }
-
- @Override
- public void doView(RenderRequest request, RenderResponse response) throws
PortletException, IOException
- {
- String contentPath = getContentPath(request);
- Session session = null;
- ObjectContentManager ocm = null;
+ param = StringUtils.trim(getInitParameterFromConfigOrContext(config,
"contentRequestParamPrefix", null));
- try
+ if (param != null)
+ {
+ contentRequestParamPrefix = param;
+ }
+
+ param = StringUtils.trim(getInitParameterFromConfigOrContext(config,
"portletModesWithContentBean", null));
+
+ if (StringUtils.isBlank(param))
+ {
+ portletModesWithContentBean.add(PortletMode.VIEW);
+ }
+ else
{
- if (contentPath != null)
+ for (String portletModeName : StringUtils.split(param, " ,\t\r\n"))
{
- session = getSession(request);
- ocm =
getObjectContentManagerProvider().getObjectContentManager(session);
-
- Object contentBean = getContentBean(request, ocm, contentPath);
-
- if (contentBean != null)
- {
- request.setAttribute(contentBeanAttributeName,
contentBean);
- }
+ portletModesWithContentBean.add(new
PortletMode(portletModeName));
}
-
- super.doView(request, response);
-
}
- finally
+ }
+
+ @Override
+ protected void doDispatch(RenderRequest request, RenderResponse response)
throws PortletException, IOException
+ {
+ WindowState state = request.getWindowState();
+
+ if (!state.equals(WindowState.MINIMIZED))
{
- if (ocm != null)
+ PortletMode mode = request.getPortletMode();
+
+ if (!portletModesWithContentBean.contains(mode))
{
- try
- {
- ocm.logout();
- }
- catch (Exception ignore)
- {
- }
+ super.doDispatch(request, response);
}
- if (session != null)
+ else
{
+ String contentPath = getContentPath(request);
+
+ Session session = null;
+ ObjectContentManager ocm = null;
+
try
{
- session.logout();
+ if (contentPath != null)
+ {
+ session = getSession(request);
+ ocm =
getObjectContentManagerProvider().getObjectContentManager(session);
+
+ Object contentBean = getContentBean(request, ocm,
contentPath);
+
+ if (contentBean != null)
+ {
+ request.setAttribute(contentBeanAttributeName,
contentBean);
+ }
+ }
+
+ super.doDispatch(request, response);
+
}
- catch (Exception ignore)
+ finally
{
+ if (ocm != null)
+ {
+ try
+ {
+ ocm.logout();
+ }
+ catch (Exception ignore)
+ {
+ }
+ }
+ if (session != null)
+ {
+ try
+ {
+ session.logout();
+ }
+ catch (Exception ignore)
+ {
+ }
+ }
}
}
}
@@ -182,10 +224,14 @@ public class GenericContentPortlet exten
@Override
public void processAction(ActionRequest request, ActionResponse response)
throws PortletException, IOException
{
- if (isPreferencesStoringAction(request))
+ if (isPreferencesAction(request))
{
processPreferencesAction(request, response);
}
+ else if (isContentsAction(request))
+ {
+ processContentsAction(request, response);
+ }
else
{
super.processAction(request, response);
@@ -333,10 +379,10 @@ public class GenericContentPortlet exten
return (value != null ? value.trim() : defaultValue);
}
- protected boolean isPreferencesStoringAction(ActionRequest request)
+ protected boolean isPreferencesAction(ActionRequest request)
{
String preferenceActionParamName = StringUtils.join(new Object [] {
preferenceRequestParamPrefix, "action" });
- return
("store".equals(request.getParameter(preferenceActionParamName)));
+ return
("save".equals(request.getParameter(preferenceActionParamName)));
}
@Override
@@ -349,6 +395,7 @@ public class GenericContentPortlet exten
try
{
boolean preferenceRequestParamsPrefixed =
!StringUtils.isEmpty(preferenceRequestParamPrefix);
+ boolean updated = false;
for (Map.Entry<String, String []> entry : params.entrySet())
{
@@ -376,9 +423,13 @@ public class GenericContentPortlet exten
}
prefs.setValue(prefName, values[0]);
+ updated = true;
}
- prefs.store();
+ if (updated)
+ {
+ prefs.store();
+ }
response.setPortletMode(PortletMode.VIEW);
}
@@ -388,4 +439,106 @@ public class GenericContentPortlet exten
}
}
+ protected boolean isContentsAction(ActionRequest request)
+ {
+ String contentActionParamName = StringUtils.join(new Object [] {
contentRequestParamPrefix, "action" });
+ return ("save".equals(request.getParameter(contentActionParamName)));
+ }
+
+ public void processContentsAction(ActionRequest request, ActionResponse
response) throws PortletException, IOException
+ {
+ Map<String, String []> params = request.getParameterMap();
+
+ Session session = null;
+ ObjectContentManager ocm = null;
+
+ try
+ {
+ String contentPath = getContentPath(request);
+
+ if (contentPath == null)
+ {
+ throw new PortletException("contentPath is not found");
+ }
+
+ session = getSession(request);
+ ocm =
getObjectContentManagerProvider().getObjectContentManager(session);
+
+ Object contentBean = getContentBean(request, ocm, contentPath);
+
+ if (contentBean == null)
+ {
+ throw new PortletException("contentBean is not found in the
request by " + contentBeanAttributeName);
+ }
+
+ boolean contentRequestParamsPrefixed =
!StringUtils.isEmpty(contentRequestParamPrefix);
+ boolean updated = false;
+
+ for (Map.Entry<String, String []> entry : params.entrySet())
+ {
+ String paramName = entry.getKey();
+ String [] values = entry.getValue();
+ String propName = null;
+
+ if (!contentRequestParamsPrefixed)
+ {
+ propName = paramName;
+ }
+ else
+ {
+ if (!paramName.startsWith(contentRequestParamPrefix))
+ {
+ continue;
+ }
+
+ propName =
paramName.substring(contentRequestParamPrefix.length());
+ }
+
+
+ if (!PropertyUtils.isWriteable(contentBean, propName))
+ {
+ continue;
+ }
+
+ PropertyUtils.setProperty(contentBean, propName, values[0]);
+ updated = true;
+ }
+
+ if (updated)
+ {
+ ocm.update(contentBean);
+ ocm.save();
+ }
+
+ response.setPortletMode(PortletMode.VIEW);
+ }
+ catch (Exception e)
+ {
+ throw new PortletException("Exception mapping request Params to
contentBean: ", e);
+ }
+ finally
+ {
+ if (ocm != null)
+ {
+ try
+ {
+ ocm.logout();
+ }
+ catch (Exception ignore)
+ {
+ }
+ }
+ if (session != null)
+ {
+ try
+ {
+ session.logout();
+ }
+ catch (Exception ignore)
+ {
+ }
+ }
+ }
+ }
+
}
Modified:
portals/applications/sandbox/content/trunk/apa-content-portlet/src/main/java/org/apache/portals/applications/content/GenericSearchQueryContentPortlet.java
URL:
http://svn.apache.org/viewvc/portals/applications/sandbox/content/trunk/apa-content-portlet/src/main/java/org/apache/portals/applications/content/GenericSearchQueryContentPortlet.java?rev=946249&r1=946248&r2=946249&view=diff
==============================================================================
---
portals/applications/sandbox/content/trunk/apa-content-portlet/src/main/java/org/apache/portals/applications/content/GenericSearchQueryContentPortlet.java
(original)
+++
portals/applications/sandbox/content/trunk/apa-content-portlet/src/main/java/org/apache/portals/applications/content/GenericSearchQueryContentPortlet.java
Wed May 19 16:04:06 2010
@@ -37,7 +37,7 @@ public class GenericSearchQueryContentPo
@Override
public void processAction(ActionRequest request, ActionResponse response)
throws PortletException, IOException
{
- if (isPreferencesStoringAction(request))
+ if (isPreferencesAction(request))
{
processPreferencesAction(request, response);
return;
@@ -73,8 +73,6 @@ public class GenericSearchQueryContentPo
{
response.setRenderParameter("fullQueryJcrExpression",
fullQueryJcrExpression.trim());
}
-
- super.processAction(request, response);
}
@Override
Modified:
portals/applications/sandbox/content/trunk/apa-content-webapp/src/main/webapp/WEB-INF/portlet.xml
URL:
http://svn.apache.org/viewvc/portals/applications/sandbox/content/trunk/apa-content-webapp/src/main/webapp/WEB-INF/portlet.xml?rev=946249&r1=946248&r2=946249&view=diff
==============================================================================
---
portals/applications/sandbox/content/trunk/apa-content-webapp/src/main/webapp/WEB-INF/portlet.xml
(original)
+++
portals/applications/sandbox/content/trunk/apa-content-webapp/src/main/webapp/WEB-INF/portlet.xml
Wed May 19 16:04:06 2010
@@ -39,8 +39,8 @@
<expiration-cache>0</expiration-cache>
<supports>
<mime-type>text/html</mime-type>
- <portlet-mode>EDIT</portlet-mode>
<portlet-mode>VIEW</portlet-mode>
+ <portlet-mode>EDIT</portlet-mode>
<portlet-mode>HELP</portlet-mode>
</supports>
<supported-locale>en</supported-locale>
@@ -78,8 +78,8 @@
<expiration-cache>0</expiration-cache>
<supports>
<mime-type>text/html</mime-type>
- <portlet-mode>EDIT</portlet-mode>
<portlet-mode>VIEW</portlet-mode>
+ <portlet-mode>EDIT</portlet-mode>
<portlet-mode>HELP</portlet-mode>
</supports>
<supported-locale>en</supported-locale>
@@ -133,8 +133,8 @@
<expiration-cache>0</expiration-cache>
<supports>
<mime-type>text/html</mime-type>
- <portlet-mode>EDIT</portlet-mode>
<portlet-mode>VIEW</portlet-mode>
+ <portlet-mode>EDIT</portlet-mode>
<portlet-mode>HELP</portlet-mode>
</supports>
<supported-locale>en</supported-locale>
@@ -188,8 +188,8 @@
<expiration-cache>0</expiration-cache>
<supports>
<mime-type>text/html</mime-type>
- <portlet-mode>EDIT</portlet-mode>
<portlet-mode>VIEW</portlet-mode>
+ <portlet-mode>EDIT</portlet-mode>
<portlet-mode>HELP</portlet-mode>
</supports>
<supported-locale>en</supported-locale>
@@ -238,7 +238,7 @@
</init-param>
<init-param>
<name>EditPage</name>
- <value>/WEB-INF/view/generic-content-edit.jsp</value>
+ <value>/WEB-INF/view/news-item-edit.jsp</value>
</init-param>
<init-param>
<name>HelpPage</name>
@@ -252,11 +252,15 @@
<name>hstPortletRequestDispatcherPathProvider.propertyPath</name>
<value>pipeline.name</value>
</init-param>
+ <init-param>
+ <name>portletModesWithContentBean</name>
+ <value>VIEW,EDIT</value>
+ </init-param>
<expiration-cache>0</expiration-cache>
<supports>
<mime-type>text/html</mime-type>
- <portlet-mode>EDIT</portlet-mode>
<portlet-mode>VIEW</portlet-mode>
+ <portlet-mode>EDIT</portlet-mode>
<portlet-mode>HELP</portlet-mode>
</supports>
<supported-locale>en</supported-locale>
@@ -294,8 +298,8 @@
<expiration-cache>0</expiration-cache>
<supports>
<mime-type>text/html</mime-type>
- <portlet-mode>EDIT</portlet-mode>
<portlet-mode>VIEW</portlet-mode>
+ <portlet-mode>EDIT</portlet-mode>
<portlet-mode>HELP</portlet-mode>
</supports>
<supported-locale>en</supported-locale>
Modified:
portals/applications/sandbox/content/trunk/apa-content-webapp/src/main/webapp/WEB-INF/view/generic-content-edit.jsp
URL:
http://svn.apache.org/viewvc/portals/applications/sandbox/content/trunk/apa-content-webapp/src/main/webapp/WEB-INF/view/generic-content-edit.jsp?rev=946249&r1=946248&r2=946249&view=diff
==============================================================================
---
portals/applications/sandbox/content/trunk/apa-content-webapp/src/main/webapp/WEB-INF/view/generic-content-edit.jsp
(original)
+++
portals/applications/sandbox/content/trunk/apa-content-webapp/src/main/webapp/WEB-INF/view/generic-content-edit.jsp
Wed May 19 16:04:06 2010
@@ -29,7 +29,7 @@ limitations under the License.
</tr>
<tr>
<td colspan="2" class="portlet-section-body">
- <input type="hidden" name="preference.action" value="store" />
+ <input type="hidden" name="preference.action" value="save" />
<input type="submit" value="Save" />
<input type="reset" value="Reset" />
</td>
Modified:
portals/applications/sandbox/content/trunk/apa-content-webapp/src/main/webapp/WEB-INF/view/generic-query-content-edit.jsp
URL:
http://svn.apache.org/viewvc/portals/applications/sandbox/content/trunk/apa-content-webapp/src/main/webapp/WEB-INF/view/generic-query-content-edit.jsp?rev=946249&r1=946248&r2=946249&view=diff
==============================================================================
---
portals/applications/sandbox/content/trunk/apa-content-webapp/src/main/webapp/WEB-INF/view/generic-query-content-edit.jsp
(original)
+++
portals/applications/sandbox/content/trunk/apa-content-webapp/src/main/webapp/WEB-INF/view/generic-query-content-edit.jsp
Wed May 19 16:04:06 2010
@@ -45,7 +45,7 @@ limitations under the License.
</tr>
<tr>
<td colspan="2" class="portlet-section-body">
- <input type="hidden" name="preference.action" value="store" />
+ <input type="hidden" name="preference.action" value="save" />
<input type="submit" value="Save" />
<input type="reset" value="Reset" />
</td>
Modified:
portals/applications/sandbox/content/trunk/apa-content-webapp/src/main/webapp/WEB-INF/view/generic-search-query-content-edit.jsp
URL:
http://svn.apache.org/viewvc/portals/applications/sandbox/content/trunk/apa-content-webapp/src/main/webapp/WEB-INF/view/generic-search-query-content-edit.jsp?rev=946249&r1=946248&r2=946249&view=diff
==============================================================================
---
portals/applications/sandbox/content/trunk/apa-content-webapp/src/main/webapp/WEB-INF/view/generic-search-query-content-edit.jsp
(original)
+++
portals/applications/sandbox/content/trunk/apa-content-webapp/src/main/webapp/WEB-INF/view/generic-search-query-content-edit.jsp
Wed May 19 16:04:06 2010
@@ -45,7 +45,7 @@ limitations under the License.
</tr>
<tr>
<td colspan="2" class="portlet-section-body">
- <input type="hidden" name="preference.action" value="store" />
+ <input type="hidden" name="preference.action" value="save" />
<input type="submit" value="Save" />
<input type="reset" value="Reset" />
</td>
Added:
portals/applications/sandbox/content/trunk/apa-content-webapp/src/main/webapp/WEB-INF/view/news-item-edit.jsp
URL:
http://svn.apache.org/viewvc/portals/applications/sandbox/content/trunk/apa-content-webapp/src/main/webapp/WEB-INF/view/news-item-edit.jsp?rev=946249&view=auto
==============================================================================
---
portals/applications/sandbox/content/trunk/apa-content-webapp/src/main/webapp/WEB-INF/view/news-item-edit.jsp
(added)
+++
portals/applications/sandbox/content/trunk/apa-content-webapp/src/main/webapp/WEB-INF/view/news-item-edit.jsp
Wed May 19 16:04:06 2010
@@ -0,0 +1,49 @@
+<%--
+Licensed to the Apache Software Foundation (ASF) under one or more
+contributor license agreements. See the NOTICE file distributed with
+this work for additional information regarding copyright ownership.
+The ASF licenses this file to You under the Apache License, Version 2.0
+(the "License"); you may not use this file except in compliance with
+the License. You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+Unless required by applicable law or agreed to in writing, software
+distributed under the License is distributed on an "AS IS" BASIS,
+WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+See the License for the specific language governing permissions and
+limitations under the License.
+--%>
+<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
+<%@ taglib prefix="fmt-portlet"
uri="http://portals.apache.org/applications/gems/fmt-portlet" %>
+<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %>
+<%@ taglib uri="http://java.sun.com/portlet" prefix="portlet"%>
+<portlet:defineObjects/>
+<fmt-portlet:setBundle/>
+
+<form method="POST" action="<portlet:actionURL/>">
+<table>
+ <tr>
+ <td>Title:</td>
+ <td><input name="content.title" type="text" size="80"
value="${contentBean.title}"/></td>
+ </tr>
+ <tr>
+ <td colspan="2">
+ Introduction:<br/>
+ <textarea name="content.introduction" rows="4"
cols="80">${contentBean.introduction}</textarea>
+ </td>
+ </tr>
+ <tr>
+ <td colspan="2">
+ <textarea name="content.body.content" rows="20"
cols="80">${contentBean.body.content}</textarea>
+ </td>
+ </tr>
+ <tr>
+ <td colspan="2">
+ <input type="hidden" name="content.action" value="save" />
+ <input type="submit" value="Save" />
+ <input type="reset" value="Reset" />
+ </td>
+ </tr>
+</table>
+</form>
Propchange:
portals/applications/sandbox/content/trunk/apa-content-webapp/src/main/webapp/WEB-INF/view/news-item-edit.jsp
------------------------------------------------------------------------------
svn:eol-style = native
Propchange:
portals/applications/sandbox/content/trunk/apa-content-webapp/src/main/webapp/WEB-INF/view/news-item-edit.jsp
------------------------------------------------------------------------------
svn:keywords = Id
Propchange:
portals/applications/sandbox/content/trunk/apa-content-webapp/src/main/webapp/WEB-INF/view/news-item-edit.jsp
------------------------------------------------------------------------------
svn:mime-type = text/plain
Modified:
portals/applications/sandbox/content/trunk/apa-content-webapp/src/main/webapp/WEB-INF/view/news-item-view.jsp
URL:
http://svn.apache.org/viewvc/portals/applications/sandbox/content/trunk/apa-content-webapp/src/main/webapp/WEB-INF/view/news-item-view.jsp?rev=946249&r1=946248&r2=946249&view=diff
==============================================================================
---
portals/applications/sandbox/content/trunk/apa-content-webapp/src/main/webapp/WEB-INF/view/news-item-view.jsp
(original)
+++
portals/applications/sandbox/content/trunk/apa-content-webapp/src/main/webapp/WEB-INF/view/news-item-view.jsp
Wed May 19 16:04:06 2010
@@ -21,23 +21,19 @@ limitations under the License.
<portlet:defineObjects/>
<fmt-portlet:setBundle/>
-<h1>News Item</h1>
-<hr/>
+<h2>${contentBean.title}</h2>
+<div align="right">${contentBean.documentDate}</div>
+
+<p> </p>
+
<table>
<tr>
- <th>Title:</th>
- <td>${contentBean.title}</td>
- </tr>
- <tr>
- <th>Date:</th>
- <td>${contentBean.documentDate}</td>
- </tr>
- <tr>
- <th>Introduction:</th>
- <td>${contentBean.introduction}</td>
+ <td class="portlet-section-body">
+ <div>${contentBean.introduction}</div>
+ </td>
</tr>
</table>
-<hr/>
+<p> </p>
-${contentBean.body.content}
+<div>${contentBean.body.content}</div>
Modified:
portals/applications/sandbox/content/trunk/apa-content-webapp/src/main/webapp/WEB-INF/view/simple-search-query-content-edit.jsp
URL:
http://svn.apache.org/viewvc/portals/applications/sandbox/content/trunk/apa-content-webapp/src/main/webapp/WEB-INF/view/simple-search-query-content-edit.jsp?rev=946249&r1=946248&r2=946249&view=diff
==============================================================================
---
portals/applications/sandbox/content/trunk/apa-content-webapp/src/main/webapp/WEB-INF/view/simple-search-query-content-edit.jsp
(original)
+++
portals/applications/sandbox/content/trunk/apa-content-webapp/src/main/webapp/WEB-INF/view/simple-search-query-content-edit.jsp
Wed May 19 16:04:06 2010
@@ -45,7 +45,7 @@ limitations under the License.
</tr>
<tr>
<td colspan="2" class="portlet-section-body">
- <input type="hidden" name="preference.action" value="store" />
+ <input type="hidden" name="preference.action" value="save" />
<input type="submit" value="Save" />
<input type="reset" value="Reset" />
</td>