Algorithm for determing content item type
git-svn-id: https://svn.libreccm.org/ccm/trunk@5845 8810af33-2d31-482b-a856-94f89814c4dfmaster
parent
acf540edfb
commit
2a880b591c
|
|
@ -17,13 +17,15 @@ 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.SimpleScalar;
|
|
||||||
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;
|
||||||
|
|
@ -399,9 +401,9 @@ public class FreeMarkerPresentationManager implements PresentationManager {
|
||||||
style = "";
|
style = "";
|
||||||
}
|
}
|
||||||
|
|
||||||
return findContentItemTemplate(templates,
|
return findContentItemTemplate(templates,
|
||||||
itemModel,
|
itemModel,
|
||||||
contentItemView,
|
contentItemView,
|
||||||
style);
|
style);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -413,9 +415,39 @@ public class FreeMarkerPresentationManager implements PresentationManager {
|
||||||
final ContentItemViews view,
|
final ContentItemViews view,
|
||||||
final String style) throws TemplateModelException {
|
final String style) throws TemplateModelException {
|
||||||
|
|
||||||
final String contentType = ((TemplateScalarModel) itemModel
|
final String nodeNamespace = itemModel.getNodeNamespace();
|
||||||
.get("objectType"))
|
final String nodeName = itemModel.getNodeName();
|
||||||
.getAsString();
|
|
||||||
|
final String contentType;
|
||||||
|
if ("http://www.arsdigita.com/cms/1.0".equals(nodeNamespace)
|
||||||
|
&& "item".equals(nodeName)) {
|
||||||
|
contentType = ((TemplateScalarModel) itemModel
|
||||||
|
.get("objectType"))
|
||||||
|
.getAsString();
|
||||||
|
} else if ("http://ccm.redhat.com/navigation".equals(nodeNamespace)
|
||||||
|
&& "item".equals(nodeName)) {
|
||||||
|
final TemplateModel objectTypeElems = itemModel
|
||||||
|
.get("attribute[@name='objectType']");
|
||||||
|
if (objectTypeElems instanceof TemplateSequenceModel) {
|
||||||
|
final TemplateModel objectTypeElem
|
||||||
|
= ((TemplateSequenceModel) objectTypeElems)
|
||||||
|
.get(0);
|
||||||
|
contentType = ((TemplateScalarModel) objectTypeElem)
|
||||||
|
.getAsString();
|
||||||
|
} else if (objectTypeElems instanceof TemplateScalarModel) {
|
||||||
|
contentType = ((TemplateScalarModel) objectTypeElems)
|
||||||
|
.getAsString();
|
||||||
|
} else {
|
||||||
|
throw new IllegalArgumentException(
|
||||||
|
"Can't determine object type of item.");
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
throw new IllegalArgumentException(String.format(
|
||||||
|
"Unexpected combination of node namespace and nodename. "
|
||||||
|
+ "nodeNamespace = \"%s\"; nodeName = \"%s\"",
|
||||||
|
nodeNamespace,
|
||||||
|
nodeName));
|
||||||
|
}
|
||||||
|
|
||||||
final Optional<ContentItemTemplate> forTypeViewAndStyle = templates
|
final Optional<ContentItemTemplate> forTypeViewAndStyle = templates
|
||||||
.getContentItems()
|
.getContentItems()
|
||||||
|
|
@ -452,13 +484,13 @@ public class FreeMarkerPresentationManager implements PresentationManager {
|
||||||
final String contentType,
|
final String contentType,
|
||||||
final ContentItemViews view) {
|
final ContentItemViews view) {
|
||||||
|
|
||||||
final ContentItemViews templateView;
|
final ContentItemViews templateView;
|
||||||
if (template.getView() == null) {
|
if (template.getView() == null) {
|
||||||
templateView = ContentItemViews.DETAIL;
|
templateView = ContentItemViews.DETAIL;
|
||||||
} else {
|
} else {
|
||||||
templateView = template.getView();
|
templateView = template.getView();
|
||||||
}
|
}
|
||||||
|
|
||||||
return template.getContentType().equals(contentType)
|
return template.getContentType().equals(contentType)
|
||||||
&& templateView == view;
|
&& templateView == view;
|
||||||
}
|
}
|
||||||
|
|
@ -475,14 +507,14 @@ public class FreeMarkerPresentationManager implements PresentationManager {
|
||||||
} else {
|
} else {
|
||||||
templateView = template.getView();
|
templateView = template.getView();
|
||||||
}
|
}
|
||||||
|
|
||||||
final String templateStyle;
|
final String templateStyle;
|
||||||
if (template.getStyle() == null) {
|
if (template.getStyle() == null) {
|
||||||
templateStyle = "";
|
templateStyle = "";
|
||||||
} else {
|
} else {
|
||||||
templateStyle = template.getStyle();
|
templateStyle = template.getStyle();
|
||||||
}
|
}
|
||||||
|
|
||||||
return template.getContentType().equals(contentType)
|
return template.getContentType().equals(contentType)
|
||||||
&& templateView == view
|
&& templateView == view
|
||||||
&& templateStyle.equals(style);
|
&& templateStyle.equals(style);
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue