Macro for content items now works for object lists and details views
git-svn-id: https://svn.libreccm.org/ccm/trunk@5846 8810af33-2d31-482b-a856-94f89814c4dfmaster
parent
2a880b591c
commit
71e498bced
|
|
@ -23,12 +23,21 @@
|
||||||
-->
|
-->
|
||||||
<#macro contentItem item view="detail" style="">
|
<#macro contentItem item view="detail" style="">
|
||||||
|
|
||||||
<#include getContentItemTemplate(item, view, style)>
|
|
||||||
|
|
||||||
<#--<pre>
|
<#--<pre>
|
||||||
Using content item template ${getContentItemTemplate(item, view, style)}
|
item["/objectType"]: ${item["./objectType"]?size}
|
||||||
|
item["/nav:attribute[@name='objectType']"]: ${item["./nav:attribute[@name='objectType']"]?size}
|
||||||
</pre>-->
|
</pre>-->
|
||||||
|
|
||||||
|
|
||||||
|
<#if (item["./objectType"]?size > 0)>
|
||||||
|
<#include getContentItemTemplate(item["./objectType"], view, style)>
|
||||||
|
<#elseif (item["./nav:attribute[@name='objectType']"]?size > 0)>
|
||||||
|
<#include getContentItemTemplate(item["./nav:attribute[@name='objectType'][1]"], view, style)>
|
||||||
|
<#else>
|
||||||
|
<#include getContentItemTemplate("com.arsdigita.cms.ContentItem", view, style)>
|
||||||
|
</#if>
|
||||||
|
|
||||||
|
|
||||||
</#macro>
|
</#macro>
|
||||||
|
|
||||||
<#--
|
<#--
|
||||||
|
|
|
||||||
|
|
@ -17,15 +17,12 @@ import freemarker.cache.MultiTemplateLoader;
|
||||||
import freemarker.cache.TemplateLoader;
|
import freemarker.cache.TemplateLoader;
|
||||||
import freemarker.cache.WebappTemplateLoader;
|
import freemarker.cache.WebappTemplateLoader;
|
||||||
import freemarker.ext.dom.NodeModel;
|
import freemarker.ext.dom.NodeModel;
|
||||||
import freemarker.ext.xml.NodeListModel;
|
|
||||||
import freemarker.template.Configuration;
|
import freemarker.template.Configuration;
|
||||||
import freemarker.template.Template;
|
import freemarker.template.Template;
|
||||||
import freemarker.template.TemplateException;
|
import freemarker.template.TemplateException;
|
||||||
import freemarker.template.TemplateMethodModelEx;
|
import freemarker.template.TemplateMethodModelEx;
|
||||||
import freemarker.template.TemplateModel;
|
|
||||||
import freemarker.template.TemplateModelException;
|
import freemarker.template.TemplateModelException;
|
||||||
import freemarker.template.TemplateScalarModel;
|
import freemarker.template.TemplateScalarModel;
|
||||||
import freemarker.template.TemplateSequenceModel;
|
|
||||||
import org.libreccm.theming.manifest.ThemeManifest;
|
import org.libreccm.theming.manifest.ThemeManifest;
|
||||||
import org.libreccm.theming.manifest.ThemeManifestUtil;
|
import org.libreccm.theming.manifest.ThemeManifestUtil;
|
||||||
import org.w3c.dom.NamedNodeMap;
|
import org.w3c.dom.NamedNodeMap;
|
||||||
|
|
@ -376,16 +373,21 @@ public class FreeMarkerPresentationManager implements PresentationManager {
|
||||||
+ "item: NodeModel, view: String, style: String");
|
+ "item: NodeModel, view: String, style: String");
|
||||||
}
|
}
|
||||||
|
|
||||||
final Object arg0 = list.get(0);
|
// final Object arg0 = list.get(0);
|
||||||
if (!(arg0 instanceof NodeModel)) {
|
// if (!(arg0 instanceof NodeModel)) {
|
||||||
throw new IllegalArgumentException(
|
// throw new IllegalArgumentException(
|
||||||
"Parameter item must be a NodeModel.");
|
// "Parameter item must be a NodeModel.");
|
||||||
}
|
// }
|
||||||
final NodeModel itemModel = (NodeModel) arg0;
|
// final NodeModel itemModel = (NodeModel) arg0;
|
||||||
|
|
||||||
|
final String objectType = ((TemplateScalarModel) list
|
||||||
|
.get(0))
|
||||||
|
.getAsString();
|
||||||
|
|
||||||
final String view;
|
final String view;
|
||||||
if (list.size() >= 2) {
|
if (list.size() >= 2) {
|
||||||
view = ((TemplateScalarModel) list.get(1))
|
view = ((TemplateScalarModel) list
|
||||||
|
.get(1))
|
||||||
.getAsString()
|
.getAsString()
|
||||||
.toUpperCase(Locale.ROOT);
|
.toUpperCase(Locale.ROOT);
|
||||||
} else {
|
} else {
|
||||||
|
|
@ -402,7 +404,7 @@ public class FreeMarkerPresentationManager implements PresentationManager {
|
||||||
}
|
}
|
||||||
|
|
||||||
return findContentItemTemplate(templates,
|
return findContentItemTemplate(templates,
|
||||||
itemModel,
|
objectType,
|
||||||
contentItemView,
|
contentItemView,
|
||||||
style);
|
style);
|
||||||
}
|
}
|
||||||
|
|
@ -411,49 +413,49 @@ public class FreeMarkerPresentationManager implements PresentationManager {
|
||||||
|
|
||||||
private String findContentItemTemplate(
|
private String findContentItemTemplate(
|
||||||
final Templates templates,
|
final Templates templates,
|
||||||
final NodeModel itemModel,
|
final String objectType,
|
||||||
final ContentItemViews view,
|
final ContentItemViews view,
|
||||||
final String style) throws TemplateModelException {
|
final String style) throws TemplateModelException {
|
||||||
|
|
||||||
final String nodeNamespace = itemModel.getNodeNamespace();
|
// final String nodeNamespace = itemModel.getNodeNamespace();
|
||||||
final String nodeName = itemModel.getNodeName();
|
// final String nodeName = itemModel.getNodeName();
|
||||||
|
|
||||||
final String contentType;
|
// final String contentType;
|
||||||
if ("http://www.arsdigita.com/cms/1.0".equals(nodeNamespace)
|
// if ("http://www.arsdigita.com/cms/1.0".equals(nodeNamespace)
|
||||||
&& "item".equals(nodeName)) {
|
// && "item".equals(nodeName)) {
|
||||||
contentType = ((TemplateScalarModel) itemModel
|
// contentType = ((TemplateScalarModel) itemModel
|
||||||
.get("objectType"))
|
// .get("objectType"))
|
||||||
.getAsString();
|
// .getAsString();
|
||||||
} else if ("http://ccm.redhat.com/navigation".equals(nodeNamespace)
|
// } else if ("http://ccm.redhat.com/navigation".equals(nodeNamespace)
|
||||||
&& "item".equals(nodeName)) {
|
// && "item".equals(nodeName)) {
|
||||||
final TemplateModel objectTypeElems = itemModel
|
// final TemplateModel objectTypeElems = itemModel
|
||||||
.get("attribute[@name='objectType']");
|
// .get("attribute[@name='objectType']");
|
||||||
if (objectTypeElems instanceof TemplateSequenceModel) {
|
// if (objectTypeElems instanceof TemplateSequenceModel) {
|
||||||
final TemplateModel objectTypeElem
|
// final TemplateModel objectTypeElem
|
||||||
= ((TemplateSequenceModel) objectTypeElems)
|
// = ((TemplateSequenceModel) objectTypeElems)
|
||||||
.get(0);
|
// .get(0);
|
||||||
contentType = ((TemplateScalarModel) objectTypeElem)
|
// contentType = ((TemplateScalarModel) objectTypeElem)
|
||||||
.getAsString();
|
// .getAsString();
|
||||||
} else if (objectTypeElems instanceof TemplateScalarModel) {
|
// } else if (objectTypeElems instanceof TemplateScalarModel) {
|
||||||
contentType = ((TemplateScalarModel) objectTypeElems)
|
// contentType = ((TemplateScalarModel) objectTypeElems)
|
||||||
.getAsString();
|
// .getAsString();
|
||||||
} else {
|
// } else {
|
||||||
throw new IllegalArgumentException(
|
// throw new IllegalArgumentException(
|
||||||
"Can't determine object type of item.");
|
// "Can't determine object type of item.");
|
||||||
}
|
// }
|
||||||
} else {
|
// } else {
|
||||||
throw new IllegalArgumentException(String.format(
|
// throw new IllegalArgumentException(String.format(
|
||||||
"Unexpected combination of node namespace and nodename. "
|
// "Unexpected combination of node namespace and nodename. "
|
||||||
+ "nodeNamespace = \"%s\"; nodeName = \"%s\"",
|
// + "nodeNamespace = \"%s\"; nodeName = \"%s\"",
|
||||||
nodeNamespace,
|
// nodeNamespace,
|
||||||
nodeName));
|
// nodeName));
|
||||||
}
|
// }
|
||||||
|
|
||||||
final Optional<ContentItemTemplate> forTypeViewAndStyle = templates
|
final Optional<ContentItemTemplate> forTypeViewAndStyle = templates
|
||||||
.getContentItems()
|
.getContentItems()
|
||||||
.stream()
|
.stream()
|
||||||
.filter(template -> filterContentItemTemplate(template,
|
.filter(template -> filterContentItemTemplate(template,
|
||||||
contentType,
|
objectType,
|
||||||
view,
|
view,
|
||||||
style))
|
style))
|
||||||
.findAny();
|
.findAny();
|
||||||
|
|
@ -466,7 +468,7 @@ public class FreeMarkerPresentationManager implements PresentationManager {
|
||||||
.getContentItems()
|
.getContentItems()
|
||||||
.stream()
|
.stream()
|
||||||
.filter(template -> filterContentItemTemplate(template,
|
.filter(template -> filterContentItemTemplate(template,
|
||||||
contentType,
|
objectType,
|
||||||
view))
|
view))
|
||||||
.findAny();
|
.findAny();
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue