Author: jonesde
Date: Sat Mar 10 01:38:03 2007
New Revision: 516669

URL: http://svn.apache.org/viewvc?view=rev&rev=516669
Log:
Various cleanups in the cmsssite templates and data; implemented a change to 
support rendering the Content instead of the DataResource when it is decorated, 
which is necessary in order for the thisContent object to exist and function, 
which is necessary for including sub-content and such; also implemented the 
content map facade link element to get a link out of the context that the cms 
event puts in it

Modified:
    ofbiz/trunk/applications/content/src/org/ofbiz/content/cms/CmsEvents.java
    
ofbiz/trunk/applications/content/src/org/ofbiz/content/content/ContentMapFacade.java
    
ofbiz/trunk/applications/content/src/org/ofbiz/content/content/ContentWorker.java
    
ofbiz/trunk/applications/content/src/org/ofbiz/content/webapp/ftl/TraverseSubContentTransform.java
    ofbiz/trunk/specialpurpose/cmssite/data/CmsSiteDemoData.xml
    ofbiz/trunk/specialpurpose/cmssite/template/cms/MainDecorator.ftl
    ofbiz/trunk/specialpurpose/cmssite/webapp/cmssite/DemoFooter.ftl
    ofbiz/trunk/specialpurpose/cmssite/webapp/cmssite/DemoHeader.ftl
    ofbiz/trunk/specialpurpose/cmssite/webapp/cmssite/DemoHome.ftl

Modified: 
ofbiz/trunk/applications/content/src/org/ofbiz/content/cms/CmsEvents.java
URL: 
http://svn.apache.org/viewvc/ofbiz/trunk/applications/content/src/org/ofbiz/content/cms/CmsEvents.java?view=diff&rev=516669&r1=516668&r2=516669
==============================================================================
--- ofbiz/trunk/applications/content/src/org/ofbiz/content/cms/CmsEvents.java 
(original)
+++ ofbiz/trunk/applications/content/src/org/ofbiz/content/cms/CmsEvents.java 
Sat Mar 10 01:38:03 2007
@@ -26,6 +26,7 @@
 import org.ofbiz.entity.GenericEntityException;
 import org.ofbiz.entity.GenericValue;
 import org.ofbiz.entity.util.EntityUtil;
+import org.ofbiz.webapp.control.RequestHandler;
 import org.ofbiz.widget.screen.ScreenRenderer;
 import org.ofbiz.widget.html.HtmlFormRenderer;
 import org.ofbiz.service.LocalDispatcher;
@@ -187,6 +188,12 @@
                 MapStack templateMap = MapStack.create();
                 ScreenRenderer.populateContextForRequest(templateMap, null, 
request, response, servletContext);
                 templateMap.put("formStringRenderer", new 
HtmlFormRenderer(request, response));
+                
+                // make the link prefix
+                ServletContext ctx = (ServletContext) 
request.getAttribute("servletContext");
+                RequestHandler rh = (RequestHandler) 
ctx.getAttribute("_REQUEST_HANDLER_");
+                String contextLinkPrefix = rh.makeLink(request, response, "", 
true, false, true);
+                templateMap.put("_CONTEXT_LINK_PREFIX_", contextLinkPrefix);
 
                 Writer writer;
                 try {

Modified: 
ofbiz/trunk/applications/content/src/org/ofbiz/content/content/ContentMapFacade.java
URL: 
http://svn.apache.org/viewvc/ofbiz/trunk/applications/content/src/org/ofbiz/content/content/ContentMapFacade.java?view=diff&rev=516669&r1=516668&r2=516669
==============================================================================
--- 
ofbiz/trunk/applications/content/src/org/ofbiz/content/content/ContentMapFacade.java
 (original)
+++ 
ofbiz/trunk/applications/content/src/org/ofbiz/content/content/ContentMapFacade.java
 Sat Mar 10 01:38:03 2007
@@ -27,6 +27,7 @@
 import org.ofbiz.base.util.UtilMisc;
 import org.ofbiz.base.util.Debug;
 import org.ofbiz.base.util.GeneralException;
+import org.ofbiz.base.util.UtilValidate;
 import org.ofbiz.content.data.DataResourceWorker;
 
 import java.util.*;
@@ -52,6 +53,7 @@
     protected final String mimeType;
     protected final boolean cache;
     protected boolean allowRender = true;
+    protected boolean isDecorated = false;
 
     // internal objects
     private DataResource dataResource;
@@ -104,6 +106,10 @@
     public void setRenderFlag(boolean render) {
         this.allowRender = render;
     }
+    
+    public void setIsDecorated(boolean isDecorated) {
+        this.isDecorated = isDecorated;
+    }
 
     // interface methods
     public int size() {
@@ -191,7 +197,19 @@
 
         } else if ("link".equalsIgnoreCase(name)) {
             // link to this content
-            return "";
+            // TODO: make more intelligent to use a link alias if exists
+            String contextLinkPrefix = (String) 
this.context.get("_CONTEXT_LINK_PREFIX_");
+            if (UtilValidate.isNotEmpty(contextLinkPrefix)) {
+                StringBuffer linkBuf = new StringBuffer();
+                linkBuf.append(contextLinkPrefix);
+                if (!contextLinkPrefix.endsWith("/")) {
+                    linkBuf.append("/");
+                }
+                linkBuf.append(this.contentId);
+                return linkBuf.toString();
+            } else {
+                return this.contentId;
+            }
         } else if ("data".equalsIgnoreCase(name) || 
"dataresource".equalsIgnoreCase(name)) {
             // data (resource) object
             return dataResource;   
@@ -236,13 +254,19 @@
     }
     
     protected String renderThis() {
-        Map renderCtx = FastMap.newInstance();
-        renderCtx.putAll(context);
-        if (!allowRender) {
+        if (!this.allowRender && !this.isDecorated) {
             String errorMsg = "WARNING: Cannot render content being rendered! 
(Infinite Recursion NOT allowed!)";
             Debug.logWarning(errorMsg, module);
             return "=========> " + errorMsg + " <=========";
         }
+        // TODO: change to use the MapStack instead of a cloned Map
+        Map renderCtx = FastMap.newInstance();
+        renderCtx.putAll(context);
+        
+        if (this.isDecorated) {
+            renderCtx.put("_IS_DECORATED_", Boolean.TRUE);
+        }
+        
         try {
             return ContentWorker.renderContentAsText(dispatcher, delegator, 
contentId, renderCtx, locale, mimeType, cache);
         } catch (GeneralException e) {

Modified: 
ofbiz/trunk/applications/content/src/org/ofbiz/content/content/ContentWorker.java
URL: 
http://svn.apache.org/viewvc/ofbiz/trunk/applications/content/src/org/ofbiz/content/content/ContentWorker.java?view=diff&rev=516669&r1=516668&r2=516669
==============================================================================
--- 
ofbiz/trunk/applications/content/src/org/ofbiz/content/content/ContentWorker.java
 (original)
+++ 
ofbiz/trunk/applications/content/src/org/ofbiz/content/content/ContentWorker.java
 Sat Mar 10 01:38:03 2007
@@ -188,7 +188,9 @@
 
         // look for a content decorator
         String contentDecoratorId = content.getString("decoratorContentId");
-        if (UtilValidate.isNotEmpty(contentDecoratorId)) {
+        // check to see if the decorator has already been run
+        boolean isDecorated = 
Boolean.TRUE.equals(templateContext.get("_IS_DECORATED_"));
+        if (!isDecorated && UtilValidate.isNotEmpty(contentDecoratorId)) {
             // if there is a decorator content; do not render this content;
             // instead render the decorator
             GenericValue decorator;
@@ -203,6 +205,7 @@
 
             // render the decorator
             ContentMapFacade decFacade = new ContentMapFacade(dispatcher, 
decorator, templateContext, locale, mimeTypeId, cache);
+            facade.setIsDecorated(true);
             templateContext.put("decoratedContent", facade); // decorated 
content
             templateContext.put("thisContent", decFacade); // decorator content
             ContentWorker.renderContentAsText(dispatcher, delegator, 
contentDecoratorId, out, templateContext, locale, mimeTypeId, cache);

Modified: 
ofbiz/trunk/applications/content/src/org/ofbiz/content/webapp/ftl/TraverseSubContentTransform.java
URL: 
http://svn.apache.org/viewvc/ofbiz/trunk/applications/content/src/org/ofbiz/content/webapp/ftl/TraverseSubContentTransform.java?view=diff&rev=516669&r1=516668&r2=516669
==============================================================================
--- 
ofbiz/trunk/applications/content/src/org/ofbiz/content/webapp/ftl/TraverseSubContentTransform.java
 (original)
+++ 
ofbiz/trunk/applications/content/src/org/ofbiz/content/webapp/ftl/TraverseSubContentTransform.java
 Sat Mar 10 01:38:03 2007
@@ -250,7 +250,7 @@
                     if (locale == null)
                         locale = Locale.getDefault();
                     try {
-                        ContentWorker.renderContentAsText(dispatcher, 
delegator, wrapTemplateId, out, templateRoot, locale, mimeTypeId, false);
+                        ContentWorker.renderContentAsText(dispatcher, 
delegator, wrapTemplateId, out, templateRoot, locale, mimeTypeId, true);
                     } catch (GeneralException e) {
                         Debug.logError(e, "Error rendering content", module);
                         throw new IOException("Error rendering content" + 
e.toString());

Modified: ofbiz/trunk/specialpurpose/cmssite/data/CmsSiteDemoData.xml
URL: 
http://svn.apache.org/viewvc/ofbiz/trunk/specialpurpose/cmssite/data/CmsSiteDemoData.xml?view=diff&rev=516669&r1=516668&r2=516669
==============================================================================
--- ofbiz/trunk/specialpurpose/cmssite/data/CmsSiteDemoData.xml (original)
+++ ofbiz/trunk/specialpurpose/cmssite/data/CmsSiteDemoData.xml Sat Mar 10 
01:38:03 2007
@@ -60,10 +60,10 @@
     </ElectronicText>
     <Content contentId="CMSS_DEMO_PAGE1" contentTypeId="DOCUMENT" 
decoratorContentId="CMSS_DEC" contentName="CMS Site Demo Page 1" 
dataResourceId="CMSS_DEMO_PAGE1"/>
     <ContentAssoc contentId="CMSS_PPOINT" contentIdTo="CMSS_DEMO_PAGE1" 
contentAssocTypeId="SUB_CONTENT" fromDate="2001-01-01 00:00:00"/>
-    <DataResource dataResourceId="CMSS_DEMO_PAGE1_1" 
dataResourceTypeId="SHORT_TEXT" objectInfo="Sub-content 1 of Sub-content 1"/>
+    <DataResource dataResourceId="CMSS_DEMO_PAGE1_1" 
dataResourceTypeId="SHORT_TEXT" objectInfo="Sub-content 1"/>
     <Content contentId="CMSS_DEMO_PAGE1_1" contentTypeId="DOCUMENT" 
contentName="CMS Site Demo Page 1_1" dataResourceId="CMSS_DEMO_PAGE1_1"/>
     <ContentAssoc contentId="CMSS_DEMO_PAGE1" contentIdTo="CMSS_DEMO_PAGE1_1" 
contentAssocTypeId="SUB_CONTENT" mapKey="sub1" fromDate="2001-01-01 00:00:00"/>
-    <DataResource dataResourceId="CMSS_DEMO_PAGE1_2" 
dataResourceTypeId="SHORT_TEXT" objectInfo="Sub-content 2 of Sub-content 1"/>
+    <DataResource dataResourceId="CMSS_DEMO_PAGE1_2" 
dataResourceTypeId="SHORT_TEXT" objectInfo="Sub-content 2"/>
     <Content contentId="CMSS_DEMO_PAGE1_2" contentTypeId="DOCUMENT" 
contentName="CMS Site Demo Page 1_2" dataResourceId="CMSS_DEMO_PAGE1_2"/>
     <ContentAssoc contentId="CMSS_DEMO_PAGE1" contentIdTo="CMSS_DEMO_PAGE1_2" 
contentAssocTypeId="SUB_CONTENT" mapKey="sub2" fromDate="2001-01-01 00:00:00"/>
 </entity-engine-xml>

Modified: ofbiz/trunk/specialpurpose/cmssite/template/cms/MainDecorator.ftl
URL: 
http://svn.apache.org/viewvc/ofbiz/trunk/specialpurpose/cmssite/template/cms/MainDecorator.ftl?view=diff&rev=516669&r1=516668&r2=516669
==============================================================================
--- ofbiz/trunk/specialpurpose/cmssite/template/cms/MainDecorator.ftl (original)
+++ ofbiz/trunk/specialpurpose/cmssite/template/cms/MainDecorator.ftl Sat Mar 
10 01:38:03 2007
@@ -25,11 +25,10 @@
 </head>
 
 <body>
-${(thisContent.subcontent.header.render)?if_exists}
+${(thisContent.subcontent.header)?if_exists}
 
-${decoratedContent.data.render}    
+${decoratedContent}    
 
-${(thisContent.subcontent.footer.render)?if_exists}    
+${(thisContent.subcontent.footer)?if_exists}    
 </body>
-
 </html>

Modified: ofbiz/trunk/specialpurpose/cmssite/webapp/cmssite/DemoFooter.ftl
URL: 
http://svn.apache.org/viewvc/ofbiz/trunk/specialpurpose/cmssite/webapp/cmssite/DemoFooter.ftl?view=diff&rev=516669&r1=516668&r2=516669
==============================================================================
--- ofbiz/trunk/specialpurpose/cmssite/webapp/cmssite/DemoFooter.ftl (original)
+++ ofbiz/trunk/specialpurpose/cmssite/webapp/cmssite/DemoFooter.ftl Sat Mar 10 
01:38:03 2007
@@ -16,7 +16,7 @@
 specific language governing permissions and limitations
 under the License.
 -->
-<div>
-This is the footer!
-</div>
+<div id="footer">
 <hr/>
+<div>This is the footer!</div>
+</div>

Modified: ofbiz/trunk/specialpurpose/cmssite/webapp/cmssite/DemoHeader.ftl
URL: 
http://svn.apache.org/viewvc/ofbiz/trunk/specialpurpose/cmssite/webapp/cmssite/DemoHeader.ftl?view=diff&rev=516669&r1=516668&r2=516669
==============================================================================
--- ofbiz/trunk/specialpurpose/cmssite/webapp/cmssite/DemoHeader.ftl (original)
+++ ofbiz/trunk/specialpurpose/cmssite/webapp/cmssite/DemoHeader.ftl Sat Mar 10 
01:38:03 2007
@@ -16,7 +16,7 @@
 specific language governing permissions and limitations
 under the License.
 -->
-<div>
-This is the header!
-</div>
+<div id="header">
+<div>This is the header!</div>
 <hr/>
+</div>

Modified: ofbiz/trunk/specialpurpose/cmssite/webapp/cmssite/DemoHome.ftl
URL: 
http://svn.apache.org/viewvc/ofbiz/trunk/specialpurpose/cmssite/webapp/cmssite/DemoHome.ftl?view=diff&rev=516669&r1=516668&r2=516669
==============================================================================
--- ofbiz/trunk/specialpurpose/cmssite/webapp/cmssite/DemoHome.ftl (original)
+++ ofbiz/trunk/specialpurpose/cmssite/webapp/cmssite/DemoHome.ftl Sat Mar 10 
01:38:03 2007
@@ -18,7 +18,7 @@
 -->
 <div>
 <h1>Welcome to the Home page.</h1>
-<div><a href="/cmssite/cms/CMSS_DEMO_PAGE1">Demo Page 1</a></div>
-<div><a href="${thisContent.content.CMSS_DEMO_PAGE1.link}">Demo Page 
1</a></div>
+<div><a href="/cmssite/cms/CMSS_DEMO_PAGE1">Demo Page 1 - Hard Coded 
Link</a></div>
+<div><a href="${thisContent.content.CMSS_DEMO_PAGE1.link}">Demo Page 1 - 
Dynamic Link</a></div>
 </div>
 <hr/>


Reply via email to