Author: marijan
Date: Wed Sep 19 13:59:17 2012
New Revision: 1387598

URL: http://svn.apache.org/viewvc?rev=1387598&view=rev
Log:
RAVE-696 Create new rave-web-jcr module providing a JCR based implementation of 
the rave-web-hmvc provided page model and controllers and integration of other 
content services

- change tag so it sets variable instead of fetching properties (Ate's advice)

Modified:
    
rave/sandbox/content-services/demo-portal/src/main/webapp/WEB-INF/freemarker/views/pages/footer.ftl
    
rave/sandbox/content-services/rave-web-jcr/src/main/java/org/apache/rave/portal/web/mvc/data/document/Document.java
    
rave/sandbox/content-services/rave-web-jcr/src/main/java/org/apache/rave/portal/web/mvc/data/document/impl/Content.java
    
rave/sandbox/content-services/rave-web-jcr/src/main/java/org/apache/rave/portal/web/mvc/data/document/impl/ContentFolder.java
    
rave/sandbox/content-services/rave-web-jcr/src/main/java/org/apache/rave/portal/web/mvc/tags/RepositoryContentTag.java
    
rave/sandbox/content-services/rave-web-jcr/src/main/resources/META-INF/rave-jcr.tld

Modified: 
rave/sandbox/content-services/demo-portal/src/main/webapp/WEB-INF/freemarker/views/pages/footer.ftl
URL: 
http://svn.apache.org/viewvc/rave/sandbox/content-services/demo-portal/src/main/webapp/WEB-INF/freemarker/views/pages/footer.ftl?rev=1387598&r1=1387597&r2=1387598&view=diff
==============================================================================
--- 
rave/sandbox/content-services/demo-portal/src/main/webapp/WEB-INF/freemarker/views/pages/footer.ftl
 (original)
+++ 
rave/sandbox/content-services/demo-portal/src/main/webapp/WEB-INF/freemarker/views/pages/footer.ftl
 Wed Sep 19 13:59:17 2012
@@ -1,3 +1,4 @@
+<#-- @ftlvariable name="raveDocument" 
type="org.apache.rave.portal.web.mvc.data.document.impl.Content" -->
 <#import "/spring.ftl"as spring/>
 <#assign ravejcr=JspTaglibs["http://www.apache-rave.org/jsp/jcr"]/>
 <#assign c=JspTaglibs["http://java.sun.com/jsp/jstl/core";] />
@@ -5,8 +6,9 @@
     <div class="container">
         <div class="row">
             <div class="span12 version">
-                <span><@ravejcr.content path="/content/documents/rave.txt" 
name="title"/>${applicationProperties['portal.version']}</span>
-                <a href="http://rave.apache.org";><img class="footer-logo" 
alt="Apache Rave" title="Apache Rave" src="<@c.url 
value="dyn/binaries/images/rave-logo.png"/>"/></a>
+            <@ravejcr.content path="/content/documents/rave.txt" 
var="raveDocument"/>
+                <span>${raveDocument.title} 
${applicationProperties['portal.version']}</span>
+                <a href="http://rave.apache.org";><img class="footer-logo" 
alt="Apache Rave" title="Apache Rave" src="<@c.url 
value="/dyn/binaries/images/rave-logo.png"/>"/></a>
             </div>
         </div>
     </div>

Modified: 
rave/sandbox/content-services/rave-web-jcr/src/main/java/org/apache/rave/portal/web/mvc/data/document/Document.java
URL: 
http://svn.apache.org/viewvc/rave/sandbox/content-services/rave-web-jcr/src/main/java/org/apache/rave/portal/web/mvc/data/document/Document.java?rev=1387598&r1=1387597&r2=1387598&view=diff
==============================================================================
--- 
rave/sandbox/content-services/rave-web-jcr/src/main/java/org/apache/rave/portal/web/mvc/data/document/Document.java
 (original)
+++ 
rave/sandbox/content-services/rave-web-jcr/src/main/java/org/apache/rave/portal/web/mvc/data/document/Document.java
 Wed Sep 19 13:59:17 2012
@@ -45,14 +45,6 @@ public interface Document {
      */
     String getPath();
 
-    /**
-     * Get a document property.
-     *
-     * @param name full qualified property name e.g. <strong>{@code 
jcr:date}</strong>
-     * @return null or (populated) instance of provided class
-     */
-    <T> T getProperty(String name);
-
 
     /**
      * Sets document path

Modified: 
rave/sandbox/content-services/rave-web-jcr/src/main/java/org/apache/rave/portal/web/mvc/data/document/impl/Content.java
URL: 
http://svn.apache.org/viewvc/rave/sandbox/content-services/rave-web-jcr/src/main/java/org/apache/rave/portal/web/mvc/data/document/impl/Content.java?rev=1387598&r1=1387597&r2=1387598&view=diff
==============================================================================
--- 
rave/sandbox/content-services/rave-web-jcr/src/main/java/org/apache/rave/portal/web/mvc/data/document/impl/Content.java
 (original)
+++ 
rave/sandbox/content-services/rave-web-jcr/src/main/java/org/apache/rave/portal/web/mvc/data/document/impl/Content.java
 Wed Sep 19 13:59:17 2012
@@ -19,22 +19,16 @@
 
 package org.apache.rave.portal.web.mvc.data.document.impl;
 
-import java.util.HashMap;
-import java.util.Map;
-
 import org.apache.jackrabbit.ocm.mapper.impl.annotation.Field;
 import org.apache.jackrabbit.ocm.mapper.impl.annotation.Node;
 import org.apache.rave.portal.web.mvc.data.document.Document;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
 
 /**
  * @version "$Id$"
  */
 @Node(discriminator = false, jcrType = "ravedata:document")
 public class Content implements Document {
-    private static final Logger log = LoggerFactory.getLogger(Content.class);
-    private Map<String, Object> propertyMap;
+
 
     @Field(path = true)
     private String path;
@@ -67,22 +61,13 @@ public class Content implements Document
     }
 
 
-    @SuppressWarnings("unchecked")
-    @Override
-    public <T> T getProperty(String name) {
-        if (propertyMap == null) {
-            return null;
-        }
-        return (T) propertyMap.get(name);
-    }
-
     public String getTitle() {
         return title;
     }
 
     public void setTitle(String title) {
         this.title = title;
-        addProperty("title", title);
+
     }
 
     public String getContent() {
@@ -91,7 +76,6 @@ public class Content implements Document
 
     public void setContent(String content) {
         this.content = content;
-        addProperty("content", content);
     }
 
     @Override
@@ -108,12 +92,6 @@ public class Content implements Document
         this.id = id;
     }
 
-    private void addProperty(String name, Object value) {
-        if (propertyMap == null) {
-            propertyMap = new HashMap<String, Object>();
-        }
-        propertyMap.put(name, value);
-    }
 
     @Override
     public String toString() {

Modified: 
rave/sandbox/content-services/rave-web-jcr/src/main/java/org/apache/rave/portal/web/mvc/data/document/impl/ContentFolder.java
URL: 
http://svn.apache.org/viewvc/rave/sandbox/content-services/rave-web-jcr/src/main/java/org/apache/rave/portal/web/mvc/data/document/impl/ContentFolder.java?rev=1387598&r1=1387597&r2=1387598&view=diff
==============================================================================
--- 
rave/sandbox/content-services/rave-web-jcr/src/main/java/org/apache/rave/portal/web/mvc/data/document/impl/ContentFolder.java
 (original)
+++ 
rave/sandbox/content-services/rave-web-jcr/src/main/java/org/apache/rave/portal/web/mvc/data/document/impl/ContentFolder.java
 Wed Sep 19 13:59:17 2012
@@ -52,10 +52,6 @@ public class ContentFolder implements Fo
         return path;
     }
 
-    @Override
-    public <T> T getProperty(String name) {
-        return null;
-    }
 
     @Override
     public void setPath(String path) {

Modified: 
rave/sandbox/content-services/rave-web-jcr/src/main/java/org/apache/rave/portal/web/mvc/tags/RepositoryContentTag.java
URL: 
http://svn.apache.org/viewvc/rave/sandbox/content-services/rave-web-jcr/src/main/java/org/apache/rave/portal/web/mvc/tags/RepositoryContentTag.java?rev=1387598&r1=1387597&r2=1387598&view=diff
==============================================================================
--- 
rave/sandbox/content-services/rave-web-jcr/src/main/java/org/apache/rave/portal/web/mvc/tags/RepositoryContentTag.java
 (original)
+++ 
rave/sandbox/content-services/rave-web-jcr/src/main/java/org/apache/rave/portal/web/mvc/tags/RepositoryContentTag.java
 Wed Sep 19 13:59:17 2012
@@ -19,12 +19,14 @@
 
 package org.apache.rave.portal.web.mvc.tags;
 
-import java.io.IOException;
+import java.util.HashMap;
+import java.util.Map;
 
 import javax.servlet.jsp.JspException;
-import javax.servlet.jsp.JspWriter;
+import javax.servlet.jsp.PageContext;
 import javax.servlet.jsp.tagext.TagSupport;
 
+import org.apache.commons.lang.StringUtils;
 import org.apache.rave.portal.web.mvc.data.document.Document;
 import org.apache.rave.portal.web.mvc.data.mapping.DocumentManager;
 import org.slf4j.Logger;
@@ -38,6 +40,15 @@ public class RepositoryContentTag extend
 
     private static Logger log = 
LoggerFactory.getLogger(RepositoryContentTag.class);
     private static final long serialVersionUID = 1L;
+    private static final Map<String, Integer> SCOPE_MAPPINGS = new 
HashMap<String, Integer>();
+
+    static {
+        SCOPE_MAPPINGS.put("page", PageContext.PAGE_SCOPE);
+        SCOPE_MAPPINGS.put("session", PageContext.SESSION_SCOPE);
+        SCOPE_MAPPINGS.put("application", PageContext.APPLICATION_SCOPE);
+        SCOPE_MAPPINGS.put("request", PageContext.REQUEST_SCOPE);
+
+    }
 
     /**
      * Document service, needs to be static so we can inject it.
@@ -49,12 +60,22 @@ public class RepositoryContentTag extend
      */
     private String path;
     /**
-     * Property name we want to retrieve
+     * name of the variable we are storing document into
+     */
+    private String var;
+    /**
+     * Optional: scope parameter, valid scopes are one of:
+     * {@code page, application, session, request}
      */
-    private String name;
+    private String scope;
 
     @Override
     public int doStartTag() throws JspException {
+        // remove already defined one:
+        if (var != null) {
+            pageContext.removeAttribute(var, PageContext.PAGE_SCOPE);
+        }
+
         return EVAL_BODY_INCLUDE;
     }
 
@@ -69,32 +90,13 @@ public class RepositoryContentTag extend
         final Document document = documentManager.fetchDocument(path);
         if (document == null) {
             if (log.isDebugEnabled()) {
-                log.error("Document was null for path: [{}]", path);
+                log.warn("Document not found for path: {}", path);
             }
-            return EVAL_PAGE;
         }
-        final String property = document.getProperty(name);
-        if (property == null) {
-            if (log.isDebugEnabled()) {
-                log.error("Response was null");
-            }
-            return EVAL_PAGE;
-        }
-
-
-        try {
-            JspWriter writer = pageContext.getOut();
-            writer.write(property);
-            writer.flush();
-
-        } catch (IOException e) {
-            if (log.isDebugEnabled()) {
-                log.error("Error writing property: " + path, e);
-            }
-        }
-
-
+        pageContext.setAttribute(var, document, getVariableScope());
         path = null;
+        scope = null;
+        var = null;
         return EVAL_BODY_INCLUDE;
     }
 
@@ -106,8 +108,27 @@ public class RepositoryContentTag extend
         this.path = path;
     }
 
-    public void setName(String name) {
-        this.name = name;
+    public void setVar(String var) {
+        this.var = var;
+    }
+
+    public void setScope(String scope) {
+        this.scope = scope;
+    }
+
+
+    private int getVariableScope() {
+        if (StringUtils.isBlank(scope)) {
+            return PageContext.PAGE_SCOPE;
+        }
+        final Integer integer = SCOPE_MAPPINGS.get(scope);
+        if (integer == null) {
+            if (log.isDebugEnabled()) {
+                log.warn("Invalid scope used in RepositoryContentTag: {}", 
scope);
+            }
+            return PageContext.PAGE_SCOPE;
+        }
+        return integer;
     }
 
 

Modified: 
rave/sandbox/content-services/rave-web-jcr/src/main/resources/META-INF/rave-jcr.tld
URL: 
http://svn.apache.org/viewvc/rave/sandbox/content-services/rave-web-jcr/src/main/resources/META-INF/rave-jcr.tld?rev=1387598&r1=1387597&r2=1387598&view=diff
==============================================================================
--- 
rave/sandbox/content-services/rave-web-jcr/src/main/resources/META-INF/rave-jcr.tld
 (original)
+++ 
rave/sandbox/content-services/rave-web-jcr/src/main/resources/META-INF/rave-jcr.tld
 Wed Sep 19 13:59:17 2012
@@ -39,24 +39,22 @@
       <type>java.lang.String</type>
     </attribute>
     <attribute>
-      <description>Property name of the document</description>
-      <name>name</name>
+      <description>The name of variable</description>
+      <name>var</name>
       <required>true</required>
       <rtexprvalue>true</rtexprvalue>
       <type>java.lang.String</type>
     </attribute>
-    <!--
-        <attribute>
-          <description>The type of the property being retrieved, 
String(.class) by default</description>
-          <name>type</name>
-          <required>false</required>
-          <rtexprvalue>true</rtexprvalue>
-          <type>java.lang.Class</type>
-        </attribute>
-    -->
+    <attribute>
+      <description>Scope of defined variable, default is page scope 
(PageContext.PAGE_SCOPE). Valid values are: page, session, application, 
request</description>
+      <name>scope</name>
+      <required>false</required>
+      <rtexprvalue>true</rtexprvalue>
+      <type>java.lang.String</type>
+    </attribute>
     <example>
       <![CDATA[
-          <rave-data:content path="/content/mydocuments/mydocument" 
name=""requiredFlag"  />
+          <rave-data:content path="/content/mydocuments/mydocument" 
var="myDocument"  />
       ]]>
     </example>
   </tag>


Reply via email to