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
git-svn-id: https://svn.apache.org/repos/asf/ofbiz/trunk@516669 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
@@ -26,6 +26,7 @@ import org.ofbiz.entity.GenericDelegator;
|
||||
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 @@ public class CmsEvents {
|
||||
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 {
|
||||
|
||||
@@ -27,6 +27,7 @@ import org.ofbiz.service.LocalDispatcher;
|
||||
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 @@ public class ContentMapFacade implements Map {
|
||||
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 class ContentMapFacade implements Map {
|
||||
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 @@ public class ContentMapFacade implements Map {
|
||||
|
||||
} 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 @@ public class ContentMapFacade implements Map {
|
||||
}
|
||||
|
||||
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) {
|
||||
|
||||
@@ -188,7 +188,9 @@ public class ContentWorker implements org.ofbiz.widget.ContentWorkerInterface {
|
||||
|
||||
// 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 @@ public class ContentWorker implements org.ofbiz.widget.ContentWorkerInterface {
|
||||
|
||||
// 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);
|
||||
|
||||
+1
-1
@@ -250,7 +250,7 @@ public class TraverseSubContentTransform implements TemplateTransformModel {
|
||||
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());
|
||||
|
||||
@@ -60,10 +60,10 @@ under the License.
|
||||
</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>
|
||||
|
||||
@@ -25,11 +25,10 @@ ${thisContent.subcontent.htmlHead}
|
||||
</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>
|
||||
|
||||
@@ -16,7 +16,7 @@ KIND, either express or implied. See the License for the
|
||||
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>
|
||||
|
||||
@@ -16,7 +16,7 @@ KIND, either express or implied. See the License for the
|
||||
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>
|
||||
|
||||
@@ -18,7 +18,7 @@ under the License.
|
||||
-->
|
||||
<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/>
|
||||
|
||||
Reference in New Issue
Block a user