portals-portalapps-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From woon...@apache.org
Subject svn commit: r945055 - in /portals/applications/sandbox/content/trunk/src/main: java/org/apache/portals/applications/content/ java/org/apache/portals/applications/content/beans/ java/org/apache/portals/applications/content/demo/ java/org/apache/portals/...
Date Mon, 17 May 2010 09:58:28 GMT
Author: woonsan
Date: Mon May 17 09:58:27 2010
New Revision: 945055

URL: http://svn.apache.org/viewvc?rev=945055&view=rev
Log:
- Refining package structure for demo beans/portlets
- fixing order by problem
- adding simple pagination

Added:
    portals/applications/sandbox/content/trunk/src/main/java/org/apache/portals/applications/content/demo/
    portals/applications/sandbox/content/trunk/src/main/java/org/apache/portals/applications/content/demo/NewsItemPortlet.java
  (contents, props changed)
      - copied, changed from r945001, portals/applications/sandbox/content/trunk/src/main/java/org/apache/portals/applications/content/NewsItemPortlet.java
    portals/applications/sandbox/content/trunk/src/main/java/org/apache/portals/applications/content/demo/beans/
    portals/applications/sandbox/content/trunk/src/main/java/org/apache/portals/applications/content/demo/beans/HtmlBodyContent.java
  (contents, props changed)
      - copied, changed from r945001, portals/applications/sandbox/content/trunk/src/main/java/org/apache/portals/applications/content/beans/HtmlBodyContent.java
    portals/applications/sandbox/content/trunk/src/main/java/org/apache/portals/applications/content/demo/beans/NewsItem.java
  (contents, props changed)
      - copied, changed from r945001, portals/applications/sandbox/content/trunk/src/main/java/org/apache/portals/applications/content/beans/NewsItem.java
    portals/applications/sandbox/content/trunk/src/main/java/org/apache/portals/applications/content/demo/beans/TextPage.java
  (contents, props changed)
      - copied, changed from r945001, portals/applications/sandbox/content/trunk/src/main/java/org/apache/portals/applications/content/beans/TextPage.java
Removed:
    portals/applications/sandbox/content/trunk/src/main/java/org/apache/portals/applications/content/NewsItemPortlet.java
    portals/applications/sandbox/content/trunk/src/main/java/org/apache/portals/applications/content/beans/
    portals/applications/sandbox/content/trunk/src/main/java/org/apache/portals/applications/content/query/
Modified:
    portals/applications/sandbox/content/trunk/src/main/java/org/apache/portals/applications/content/GenericQueryContentPortlet.java
    portals/applications/sandbox/content/trunk/src/main/webapp/META-INF/context.xml
    portals/applications/sandbox/content/trunk/src/main/webapp/WEB-INF/portlet.xml
    portals/applications/sandbox/content/trunk/src/main/webapp/WEB-INF/view/generic-content-view.jsp
    portals/applications/sandbox/content/trunk/src/main/webapp/WEB-INF/view/generic-query-content-view.jsp
    portals/applications/sandbox/content/trunk/src/main/webapp/WEB-INF/view/news-item-view.jsp

Modified: portals/applications/sandbox/content/trunk/src/main/java/org/apache/portals/applications/content/GenericQueryContentPortlet.java
URL: http://svn.apache.org/viewvc/portals/applications/sandbox/content/trunk/src/main/java/org/apache/portals/applications/content/GenericQueryContentPortlet.java?rev=945055&r1=945054&r2=945055&view=diff
==============================================================================
--- portals/applications/sandbox/content/trunk/src/main/java/org/apache/portals/applications/content/GenericQueryContentPortlet.java
(original)
+++ portals/applications/sandbox/content/trunk/src/main/java/org/apache/portals/applications/content/GenericQueryContentPortlet.java
Mon May 17 09:58:27 2010
@@ -31,7 +31,8 @@ import org.apache.jackrabbit.ocm.manager
 import org.apache.jackrabbit.ocm.query.Filter;
 import org.apache.jackrabbit.ocm.query.Query;
 import org.apache.jackrabbit.ocm.query.QueryManager;
-import org.apache.portals.applications.content.query.DelegatingQueryManager;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
 
 
 /**
@@ -41,6 +42,8 @@ import org.apache.portals.applications.c
  */
 public class GenericQueryContentPortlet extends GenericContentPortlet 
 {
+    private static Logger log = LoggerFactory.getLogger(GenericQueryContentPortlet.class);
+    
     @Override
     public void doView(RenderRequest request, RenderResponse response) throws PortletException,
IOException
     {
@@ -58,44 +61,76 @@ public class GenericQueryContentPortlet 
     protected Object getContentBean(final PortletRequest request, final ObjectContentManager
ocm, final String contentPath) throws PortletException
     {
         String queryClassName = request.getPreferences().getValue("queryClass", null);
-        int beginIndex = Integer.parseInt(request.getPreferences().getValue("beginIndex",
"0"));
-        int pageSize = Integer.parseInt(request.getPreferences().getValue("pageSize", "0"));
         
         if (StringUtils.isBlank(queryClassName))
         {
             throw new PortletException("No query class provided.");
         }
         
+        int pageIndex = 1;
+        String param = request.getParameter("page");
+        
+        if (!StringUtils.isBlank(param))
+        {
+            try 
+            {
+                pageIndex = Math.max(1, Integer.parseInt(param)); 
+            }
+            catch (NumberFormatException e)
+            {
+            }
+        }
+        
+        int pageSize = Math.max(0, Integer.parseInt(request.getPreferences().getValue("pageSize",
"0")));
+        int pageCount = 1;
+        
         try
         {
-            final String queryOrderByClause = request.getPreferences().getValue("queryOrderByClause",
null);
             QueryManager queryManager = ocm.getQueryManager();
+            Class<?> queryClass = Thread.currentThread().getContextClassLoader().loadClass(queryClassName);
+            Filter filter = createFilter(request, queryManager, queryClass, contentPath);
+            Query query = queryManager.createQuery(filter);
             
+            String jcrExpression = queryManager.buildJCRExpression(query);
+            String queryOrderByClause = request.getPreferences().getValue("queryOrderByClause",
null);
             if (!StringUtils.isBlank(queryOrderByClause))
             {
-                queryManager = new DelegatingQueryManager(queryManager)
+                jcrExpression += " order by " + queryOrderByClause;
+            }
+            
+            if (log.isDebugEnabled())
+            {
+                log.debug("Executing jcr query: " + jcrExpression);
+            }
+            
+            Collection result = ocm.getObjects(jcrExpression, javax.jcr.query.Query.XPATH);
+            int itemCount = result.size();
+            
+            if (pageSize > 0)
+            {
+                pageCount = itemCount / pageSize;
+                
+                if (itemCount % pageSize != 0)
                 {
-                    @Override
-                    public String buildJCRExpression(Query query)
-                    {
-                        return super.buildJCRExpression(query) + " order by " + queryOrderByClause;
-                    }
-                };
+                    ++pageCount;
+                }
             }
             
-            Class<?> queryClass = Thread.currentThread().getContextClassLoader().loadClass(queryClassName);
-            Filter filter = createFilter(request, queryManager, queryClass, contentPath);
-            Query query = queryManager.createQuery(filter);
-            Collection result = ocm.getObjects(query);
+            request.setAttribute("itemCount", new Integer(itemCount));
+            request.setAttribute("pageCount", new Integer(pageCount));
+            request.setAttribute("pageIndex", new Integer(pageIndex));
+            
             Object contentBean = null;
             
-            if (beginIndex <= 0 && pageSize <= 0)
+            int beginIndex = (pageIndex - 1) * pageSize;
+            
+            if (beginIndex == 0 && pageSize == 0)
             {
                 contentBean = result;
             }
             else
             {
-                List<Object> list = new ArrayList<Object>();
+                List<Object> list = new ArrayList<Object>(pageSize > 0 ? pageSize
: 10);
                 int index = 0;
                 int count = 0;
                 
@@ -131,25 +166,34 @@ public class GenericQueryContentPortlet 
         Filter filter = queryManager.createFilter(queryClass);
         filter.setScope(scope);
         
-        String queryContains = request.getPreferences().getValue("queryContains", null);
-        String queryEqualTo = request.getPreferences().getValue("queryEqualTo", null);
-        String queryJCRExpression = request.getPreferences().getValue("queryJCRExpression",
null);
+        String query = getParameterOrPreference(request, "query", null);
+        String queryNode = getParameterOrPreference(request, "queryNode", ".");
+        String queryOperator = getParameterOrPreference(request, "queryOperator", "contains");
         
-        if (queryContains != null)
+        if (query != null)
         {
-            filter.addContains(".", queryContains);
+            if ("contains".equals(queryOperator))
+            {
+                filter.addContains(queryNode, query);
+            }
+            else if ("equalto".equals(queryOperator))
+            {
+                filter.addEqualTo(queryNode, query);
+            }
         }
         
-        if (queryEqualTo != null)
-        {
-            filter.addEqualTo(".", queryEqualTo);
-        }
+        return filter;
+    }
+    
+    private String getParameterOrPreference(final PortletRequest request, String name, String
defaultValue)
+    {
+        String value = request.getParameter(name);
         
-        if (queryJCRExpression != null)
+        if (value == null)
         {
-            filter.addJCRExpression(queryJCRExpression);
+            value = request.getPreferences().getValue(name, null);
         }
         
-        return filter;
+        return (value != null ? value : defaultValue);
     }
 }

Copied: portals/applications/sandbox/content/trunk/src/main/java/org/apache/portals/applications/content/demo/NewsItemPortlet.java
(from r945001, portals/applications/sandbox/content/trunk/src/main/java/org/apache/portals/applications/content/NewsItemPortlet.java)
URL: http://svn.apache.org/viewvc/portals/applications/sandbox/content/trunk/src/main/java/org/apache/portals/applications/content/demo/NewsItemPortlet.java?p2=portals/applications/sandbox/content/trunk/src/main/java/org/apache/portals/applications/content/demo/NewsItemPortlet.java&p1=portals/applications/sandbox/content/trunk/src/main/java/org/apache/portals/applications/content/NewsItemPortlet.java&r1=945001&r2=945055&rev=945055&view=diff
==============================================================================
--- portals/applications/sandbox/content/trunk/src/main/java/org/apache/portals/applications/content/NewsItemPortlet.java
(original)
+++ portals/applications/sandbox/content/trunk/src/main/java/org/apache/portals/applications/content/demo/NewsItemPortlet.java
Mon May 17 09:58:27 2010
@@ -14,7 +14,9 @@
  * See the License for the specific language governing permissions and
  * limitations under the License.
  */
-package org.apache.portals.applications.content;
+package org.apache.portals.applications.content.demo;
+
+import org.apache.portals.applications.content.DynamicContentPortlet;
 
 /**
  * NewsItemPortlet

Propchange: portals/applications/sandbox/content/trunk/src/main/java/org/apache/portals/applications/content/demo/NewsItemPortlet.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: portals/applications/sandbox/content/trunk/src/main/java/org/apache/portals/applications/content/demo/NewsItemPortlet.java
------------------------------------------------------------------------------
    svn:keywords = Id

Copied: portals/applications/sandbox/content/trunk/src/main/java/org/apache/portals/applications/content/demo/beans/HtmlBodyContent.java
(from r945001, portals/applications/sandbox/content/trunk/src/main/java/org/apache/portals/applications/content/beans/HtmlBodyContent.java)
URL: http://svn.apache.org/viewvc/portals/applications/sandbox/content/trunk/src/main/java/org/apache/portals/applications/content/demo/beans/HtmlBodyContent.java?p2=portals/applications/sandbox/content/trunk/src/main/java/org/apache/portals/applications/content/demo/beans/HtmlBodyContent.java&p1=portals/applications/sandbox/content/trunk/src/main/java/org/apache/portals/applications/content/beans/HtmlBodyContent.java&r1=945001&r2=945055&rev=945055&view=diff
==============================================================================
--- portals/applications/sandbox/content/trunk/src/main/java/org/apache/portals/applications/content/beans/HtmlBodyContent.java
(original)
+++ portals/applications/sandbox/content/trunk/src/main/java/org/apache/portals/applications/content/demo/beans/HtmlBodyContent.java
Mon May 17 09:58:27 2010
@@ -14,7 +14,7 @@
  * See the License for the specific language governing permissions and
  * limitations under the License.
  */
-package org.apache.portals.applications.content.beans;
+package org.apache.portals.applications.content.demo.beans;
 
 import org.apache.jackrabbit.ocm.mapper.impl.annotation.Field;
 import org.apache.jackrabbit.ocm.mapper.impl.annotation.Node;

Propchange: portals/applications/sandbox/content/trunk/src/main/java/org/apache/portals/applications/content/demo/beans/HtmlBodyContent.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: portals/applications/sandbox/content/trunk/src/main/java/org/apache/portals/applications/content/demo/beans/HtmlBodyContent.java
------------------------------------------------------------------------------
    svn:keywords = Id

Propchange: portals/applications/sandbox/content/trunk/src/main/java/org/apache/portals/applications/content/demo/beans/HtmlBodyContent.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Copied: portals/applications/sandbox/content/trunk/src/main/java/org/apache/portals/applications/content/demo/beans/NewsItem.java
(from r945001, portals/applications/sandbox/content/trunk/src/main/java/org/apache/portals/applications/content/beans/NewsItem.java)
URL: http://svn.apache.org/viewvc/portals/applications/sandbox/content/trunk/src/main/java/org/apache/portals/applications/content/demo/beans/NewsItem.java?p2=portals/applications/sandbox/content/trunk/src/main/java/org/apache/portals/applications/content/demo/beans/NewsItem.java&p1=portals/applications/sandbox/content/trunk/src/main/java/org/apache/portals/applications/content/beans/NewsItem.java&r1=945001&r2=945055&rev=945055&view=diff
==============================================================================
--- portals/applications/sandbox/content/trunk/src/main/java/org/apache/portals/applications/content/beans/NewsItem.java
(original)
+++ portals/applications/sandbox/content/trunk/src/main/java/org/apache/portals/applications/content/demo/beans/NewsItem.java
Mon May 17 09:58:27 2010
@@ -14,7 +14,7 @@
  * See the License for the specific language governing permissions and
  * limitations under the License.
  */
-package org.apache.portals.applications.content.beans;
+package org.apache.portals.applications.content.demo.beans;
 
 import org.apache.jackrabbit.ocm.mapper.impl.annotation.Node;
 

Propchange: portals/applications/sandbox/content/trunk/src/main/java/org/apache/portals/applications/content/demo/beans/NewsItem.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: portals/applications/sandbox/content/trunk/src/main/java/org/apache/portals/applications/content/demo/beans/NewsItem.java
------------------------------------------------------------------------------
    svn:keywords = Id

Copied: portals/applications/sandbox/content/trunk/src/main/java/org/apache/portals/applications/content/demo/beans/TextPage.java
(from r945001, portals/applications/sandbox/content/trunk/src/main/java/org/apache/portals/applications/content/beans/TextPage.java)
URL: http://svn.apache.org/viewvc/portals/applications/sandbox/content/trunk/src/main/java/org/apache/portals/applications/content/demo/beans/TextPage.java?p2=portals/applications/sandbox/content/trunk/src/main/java/org/apache/portals/applications/content/demo/beans/TextPage.java&p1=portals/applications/sandbox/content/trunk/src/main/java/org/apache/portals/applications/content/beans/TextPage.java&r1=945001&r2=945055&rev=945055&view=diff
==============================================================================
--- portals/applications/sandbox/content/trunk/src/main/java/org/apache/portals/applications/content/beans/TextPage.java
(original)
+++ portals/applications/sandbox/content/trunk/src/main/java/org/apache/portals/applications/content/demo/beans/TextPage.java
Mon May 17 09:58:27 2010
@@ -14,7 +14,9 @@
  * See the License for the specific language governing permissions and
  * limitations under the License.
  */
-package org.apache.portals.applications.content.beans;
+package org.apache.portals.applications.content.demo.beans;
+
+import java.util.Date;
 
 import org.apache.jackrabbit.ocm.mapper.impl.annotation.Bean;
 import org.apache.jackrabbit.ocm.mapper.impl.annotation.Field;
@@ -29,6 +31,7 @@ import org.apache.jackrabbit.ocm.mapper.
 public class TextPage 
 {
     protected String path;
+    protected Date documentDate;
     protected String title;
     protected String introduction; 
     protected HtmlBodyContent bodyContent;
@@ -44,6 +47,17 @@ public class TextPage 
         this.path = path;
     }
     
+    @Field(jcrName="onehippo:documentdate")
+    public Date getDocumentDate()
+    {
+        return documentDate;
+    }
+    
+    public void setDocumentDate(Date documentDate)
+    {
+        this.documentDate = documentDate;
+    }
+    
     @Field(jcrName="onehippo:title")
     public String getTitle() 
     {

Propchange: portals/applications/sandbox/content/trunk/src/main/java/org/apache/portals/applications/content/demo/beans/TextPage.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: portals/applications/sandbox/content/trunk/src/main/java/org/apache/portals/applications/content/demo/beans/TextPage.java
------------------------------------------------------------------------------
    svn:keywords = Id

Propchange: portals/applications/sandbox/content/trunk/src/main/java/org/apache/portals/applications/content/demo/beans/TextPage.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Modified: portals/applications/sandbox/content/trunk/src/main/webapp/META-INF/context.xml
URL: http://svn.apache.org/viewvc/portals/applications/sandbox/content/trunk/src/main/webapp/META-INF/context.xml?rev=945055&r1=945054&r2=945055&view=diff
==============================================================================
--- portals/applications/sandbox/content/trunk/src/main/webapp/META-INF/context.xml (original)
+++ portals/applications/sandbox/content/trunk/src/main/webapp/META-INF/context.xml Mon May
17 09:58:27 2010
@@ -51,9 +51,9 @@
             type="javax.jcr.Repository"
             factory="org.apache.portals.applications.content.jndi.ObjectContentManagerProviderObjectFactory"
             annotatedClassNames="
-                                org.apache.portals.applications.content.beans.HtmlBodyContent
-                                org.apache.portals.applications.content.beans.TextPage
-                                org.apache.portals.applications.content.beans.NewsItem
+                                org.apache.portals.applications.content.demo.beans.HtmlBodyContent
+                                org.apache.portals.applications.content.demo.beans.TextPage
+                                org.apache.portals.applications.content.demo.beans.NewsItem
                                 "
   />
   -->
@@ -64,9 +64,9 @@
             factory="org.apache.portals.applications.content.jndi.ObjectContentManagerProviderObjectFactory"
             providerClassName="org.hippoecm.hst.jackrabbit.ocm.jndi.DefaultObjectContentManagerProvider"
             annotatedClassNames="
-                                org.apache.portals.applications.content.beans.HtmlBodyContent
-                                org.apache.portals.applications.content.beans.TextPage
-                                org.apache.portals.applications.content.beans.NewsItem
+                                org.apache.portals.applications.content.demo.beans.HtmlBodyContent
+                                org.apache.portals.applications.content.demo.beans.TextPage
+                                org.apache.portals.applications.content.demo.beans.NewsItem
                                 "
   />
   

Modified: portals/applications/sandbox/content/trunk/src/main/webapp/WEB-INF/portlet.xml
URL: http://svn.apache.org/viewvc/portals/applications/sandbox/content/trunk/src/main/webapp/WEB-INF/portlet.xml?rev=945055&r1=945054&r2=945055&view=diff
==============================================================================
--- portals/applications/sandbox/content/trunk/src/main/webapp/WEB-INF/portlet.xml (original)
+++ portals/applications/sandbox/content/trunk/src/main/webapp/WEB-INF/portlet.xml Mon May
17 09:58:27 2010
@@ -98,7 +98,7 @@
       </preference>
       <preference>
         <name>queryClass</name>
-        <value>org.apache.portals.applications.content.beans.TextPage</value>
+        <value>org.apache.portals.applications.content.demo.beans.TextPage</value>
       </preference>
       <preference>
         <name>beginIndex</name>
@@ -119,7 +119,7 @@
     <description>News Item Portlet</description>
     <portlet-name>NewsItemPortlet</portlet-name>
     <display-name>News Item Content</display-name>
-    <portlet-class>org.apache.portals.applications.content.NewsItemPortlet</portlet-class>
+    <portlet-class>org.apache.portals.applications.content.demo.NewsItemPortlet</portlet-class>
     <init-param>
       <name>ViewPage</name>
       <value>/WEB-INF/view/news-item-view.jsp</value>
@@ -194,7 +194,7 @@
       </preference>
       <preference>
         <name>queryClass</name>
-        <value>org.apache.portals.applications.content.beans.NewsItem</value>
+        <value>org.apache.portals.applications.content.demo.beans.NewsItem</value>
       </preference>
       <preference>
         <name>beginIndex</name>

Modified: portals/applications/sandbox/content/trunk/src/main/webapp/WEB-INF/view/generic-content-view.jsp
URL: http://svn.apache.org/viewvc/portals/applications/sandbox/content/trunk/src/main/webapp/WEB-INF/view/generic-content-view.jsp?rev=945055&r1=945054&r2=945055&view=diff
==============================================================================
--- portals/applications/sandbox/content/trunk/src/main/webapp/WEB-INF/view/generic-content-view.jsp
(original)
+++ portals/applications/sandbox/content/trunk/src/main/webapp/WEB-INF/view/generic-content-view.jsp
Mon May 17 09:58:27 2010
@@ -26,6 +26,10 @@ limitations under the License.
     <td>${contentBean.title}</td>
   </tr>
   <tr>
+    <th>Date:</th>
+    <td>${contentBean.documentDate}</td>
+  </tr>
+  <tr>
     <th>Introduction:</th>
     <td>${contentBean.introduction}</td>
   </tr>

Modified: portals/applications/sandbox/content/trunk/src/main/webapp/WEB-INF/view/generic-query-content-view.jsp
URL: http://svn.apache.org/viewvc/portals/applications/sandbox/content/trunk/src/main/webapp/WEB-INF/view/generic-query-content-view.jsp?rev=945055&r1=945054&r2=945055&view=diff
==============================================================================
--- portals/applications/sandbox/content/trunk/src/main/webapp/WEB-INF/view/generic-query-content-view.jsp
(original)
+++ portals/applications/sandbox/content/trunk/src/main/webapp/WEB-INF/view/generic-query-content-view.jsp
Mon May 17 09:58:27 2010
@@ -33,6 +33,26 @@ limitations under the License.
 
 <c:forEach var="contentItem" items="${contentBean}">
 <h3><a href="${portalContextPath}${portalServletPath}${fn:substringAfter(contentItem.path,
contentUrlBase)}">${contentItem.title}</a></h3>
+<div align="right">(${contentItem.documentDate})</div>
 <div>${contentItem.introduction}</div>
 <p>&nbsp;</p>
 </c:forEach>
+
+<hr/>
+
+Pages: 
+<c:forEach begin="1" end="${pageCount}" var="index">
+  &nbsp;
+  <c:choose>
+    <c:when test="${index == pageIndex}">
+      ${index}
+    </c:when>
+    <c:otherwise>
+      <portlet:renderURL var="pageURL">
+        <portlet:param name="page" value="${index}"/>
+      </portlet:renderURL>
+      <a href="${pageURL}">${index}</a>
+    </c:otherwise>
+  </c:choose>
+  &nbsp;
+</c:forEach>

Modified: portals/applications/sandbox/content/trunk/src/main/webapp/WEB-INF/view/news-item-view.jsp
URL: http://svn.apache.org/viewvc/portals/applications/sandbox/content/trunk/src/main/webapp/WEB-INF/view/news-item-view.jsp?rev=945055&r1=945054&r2=945055&view=diff
==============================================================================
--- portals/applications/sandbox/content/trunk/src/main/webapp/WEB-INF/view/news-item-view.jsp
(original)
+++ portals/applications/sandbox/content/trunk/src/main/webapp/WEB-INF/view/news-item-view.jsp
Mon May 17 09:58:27 2010
@@ -26,6 +26,10 @@ limitations under the License.
     <td>${contentBean.title}</td>
   </tr>
   <tr>
+    <th>Date:</th>
+    <td>${contentBean.documentDate}</td>
+  </tr>
+  <tr>
     <th>Introduction:</th>
     <td>${contentBean.introduction}</td>
   </tr>



Mime
View raw message