use of org.alfresco.web.ui.repo.component.UINodeDescendants in project acs-community-packaging by Alfresco.
the class NodeDescendantsLinkRenderer method encodeEnd.
/**
* @see javax.faces.render.Renderer#encodeEnd(javax.faces.context.FacesContext, javax.faces.component.UIComponent)
*/
public void encodeEnd(FacesContext context, UIComponent component) throws IOException {
// always check for this flag - as per the spec
if (component.isRendered() == true) {
Writer out = context.getResponseWriter();
UINodeDescendants control = (UINodeDescendants) component;
// make sure we have a NodeRef from the 'value' property ValueBinding
Object val = control.getValue();
if (val instanceof NodeRef == false) {
throw new IllegalArgumentException("UINodeDescendants component 'value' property must resolve to a NodeRef!");
}
NodeRef parentRef = (NodeRef) val;
// use Spring JSF integration to get the node service bean
NodeService service = getNodeService(context);
DictionaryService dd = getDictionaryService(context);
UserTransaction tx = null;
try {
tx = Repository.getUserTransaction(FacesContext.getCurrentInstance(), true);
tx.begin();
// TODO: need a comparator to sort node refs (based on childref qname)
// as currently the list is returned in a random order per request!
String separator = (String) component.getAttributes().get("separator");
if (separator == null) {
separator = DEFAULT_SEPARATOR;
}
// calculate the number of displayed child refs
if (service.exists(parentRef) == true) {
List<ChildAssociationRef> childRefs = service.getChildAssocs(parentRef, ContentModel.ASSOC_CONTAINS, RegexQNamePattern.MATCH_ALL);
List<Node> nodes = new ArrayList<Node>(childRefs.size());
for (int index = 0; index < childRefs.size(); index++) {
ChildAssociationRef ref = childRefs.get(index);
QName type = service.getType(ref.getChildRef());
TypeDefinition typeDef = dd.getType(type);
if (typeDef != null && dd.isSubClass(type, ContentModel.TYPE_FOLDER) && dd.isSubClass(type, ContentModel.TYPE_SYSTEM_FOLDER) == false) {
nodes.add(new Node(ref.getChildRef()));
}
}
QuickSort sorter = new QuickSort(nodes, "name", true, IDataContainer.SORT_CASEINSENSITIVE);
sorter.sort();
// walk each child ref and output a descendant link control for each item
int total = 0;
int maximum = nodes.size() > control.getMaxChildren() ? control.getMaxChildren() : nodes.size();
for (int index = 0; index < maximum; index++) {
Node node = nodes.get(index);
QName type = service.getType(node.getNodeRef());
TypeDefinition typeDef = dd.getType(type);
if (typeDef != null && dd.isSubClass(type, ContentModel.TYPE_FOLDER) && dd.isSubClass(type, ContentModel.TYPE_SYSTEM_FOLDER) == false) {
// output separator if appropriate
if (total > 0) {
out.write(separator);
}
out.write(renderDescendant(context, control, node.getNodeRef(), false));
total++;
}
}
// do we need to render ellipses to indicate more items than the maximum
if (control.getShowEllipses() == true && nodes.size() > maximum) {
out.write(separator);
// TODO: is this the correct way to get the information we need?
// e.g. primary parent may not be the correct path? how do we make sure we find
// the correct parent and more importantly the correct Display Name value!
out.write(renderDescendant(context, control, service.getPrimaryParent(parentRef).getChildRef(), true));
}
}
tx.commit();
} catch (Throwable err) {
try {
if (tx != null) {
tx.rollback();
}
} catch (Exception tex) {
}
throw new RuntimeException(err);
}
}
}
Aggregations