This post if part of a series about the File System Toolkit - a custom content delivery API for SDL Tridion.
This post presents the Component Presentation Factory in the Toolkit. Its role is to retrieve a Dynamic ComponentPresentationMeta models based on several criteria.
The factory implements lookup methods by ids - Publication id, Component id, Component Template id and another one for getting a DCP based on the highest linking priority.
This method retrieves the Component model and then iterates over its DCP collection, returning the DCP with the given Component Template id, if available.
This post presents the Component Presentation Factory in the Toolkit. Its role is to retrieve a Dynamic ComponentPresentationMeta models based on several criteria.
The factory implements lookup methods by ids - Publication id, Component id, Component Template id and another one for getting a DCP based on the highest linking priority.
Method getComponentPresentation(int, int, int)
The three parameters, Publication id, Component id and Component Template id identify uniquely a Dynamic Component Presentation. If such a DCP is exists (i.e. is published), it id returned.This method retrieves the Component model and then iterates over its DCP collection, returning the DCP with the given Component Template id, if available.
public ComponentPresentationMeta getComponentPresentation(int publicationId, int componentId, int templateId) { TcmUri componentUri = new TcmUri(publicationId, componentId); ComponentMeta componentMeta = modelFactory.getModel(componentUri); if (componentMeta == null) { return null; } List<ComponentPresentationMeta> dcpMetas = componentMeta.getDynamicComponentPresentationMetas(); if (dcpMetas == null) { return null; } for (ComponentPresentationMeta meta : dcpMetas) { if (meta.getPublicationId() == publicationId && meta.getComponentId() == componentId && meta.getTemplateId() == templateId) { return meta; } } return null; }
Method getComponentPresentationWithHighestPriority(int, int)
This method returns the first Dynamic Component Presentation that has the highest Component Template linking priority on a given Component. The parameters, Publication id and Component id are used to uniquely identify a Component model. Next, the DCP with highest priority is retained and returned.public ComponentPresentationMeta getComponentPresentationWithHighestPriority(int publicationId, int componentId) { TcmUri componentUri = new TcmUri(publicationId, componentId); ComponentMeta componentMeta = modelFactory.getModel(componentUri); if (componentMeta == null) { return null; } List<ComponentPresentationMeta> dcpMetas = componentMeta.getDynamicComponentPresentationMetas(); if (dcpMetas == null) { return null; } int maxPriority = 0; ComponentPresentationMeta result = null; for (ComponentPresentationMeta meta : dcpMetas) { if (meta.getPriority() > maxPriority) { maxPriority = meta.getPriority(); result = meta; } } return result; }
Comments