Search in sources :

Example 1 with UINodePath

use of org.alfresco.web.ui.repo.component.UINodePath in project acs-community-packaging by Alfresco.

the class NodePathLinkRenderer 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()) {
        return;
    }
    Writer out = context.getResponseWriter();
    // make sure we have a NodeRef or Path from the 'value' property ValueBinding
    Path path = null;
    NodeRef nodeRef = null;
    Object val = ((UINodePath) component).getValue();
    if (val instanceof NodeRef) {
        nodeRef = (NodeRef) val;
    } else if (val instanceof Path) {
        path = (Path) val;
    } else if (val != null) {
        throw new IllegalArgumentException("UINodePath component 'value' " + "property must resolve to a NodeRef " + "or Path.  Got a " + val.getClass().getName());
    }
    if (val != null) {
        boolean isBreadcrumb = false;
        Boolean breadcrumb = (Boolean) component.getAttributes().get("breadcrumb");
        if (breadcrumb != null) {
            isBreadcrumb = breadcrumb.booleanValue();
        }
        boolean isDisabled = false;
        Boolean disabled = (Boolean) component.getAttributes().get("disabled");
        if (disabled != null) {
            isDisabled = disabled.booleanValue();
        }
        boolean showLeaf = false;
        Boolean showLeafBool = (Boolean) component.getAttributes().get("showLeaf");
        if (showLeafBool != null) {
            showLeaf = showLeafBool.booleanValue();
        }
        // use Spring JSF integration to get the node service bean
        NodeService service = getNodeService(context);
        UserTransaction tx = null;
        try {
            tx = Repository.getUserTransaction(FacesContext.getCurrentInstance(), true);
            tx.begin();
            if (path == null) {
                path = service.getPath(nodeRef);
            }
            if (isBreadcrumb == false || isDisabled == true) {
                out.write(buildPathAsSingular(context, component, path, showLeaf, isDisabled));
            } else {
                out.write(buildPathAsBreadcrumb(context, component, path, showLeaf));
            }
            tx.commit();
        } catch (InvalidNodeRefException refErr) {
            // this error simply means we cannot output the path
            try {
                if (tx != null) {
                    tx.rollback();
                }
            } catch (Exception tex) {
            }
        } catch (AccessDeniedException accessErr) {
            // this error simply means we cannot output the path
            try {
                if (tx != null) {
                    tx.rollback();
                }
            } catch (Exception tex) {
            }
        } catch (Throwable err) {
            try {
                if (tx != null) {
                    tx.rollback();
                }
            } catch (Exception tex) {
            }
            throw new RuntimeException(err);
        }
    }
}
Also used : Path(org.alfresco.service.cmr.repository.Path) UINodePath(org.alfresco.web.ui.repo.component.UINodePath) UserTransaction(javax.transaction.UserTransaction) AccessDeniedException(org.alfresco.repo.security.permissions.AccessDeniedException) NodeService(org.alfresco.service.cmr.repository.NodeService) IOException(java.io.IOException) AccessDeniedException(org.alfresco.repo.security.permissions.AccessDeniedException) InvalidNodeRefException(org.alfresco.service.cmr.repository.InvalidNodeRefException) NodeRef(org.alfresco.service.cmr.repository.NodeRef) UINodePath(org.alfresco.web.ui.repo.component.UINodePath) InvalidNodeRefException(org.alfresco.service.cmr.repository.InvalidNodeRefException) Writer(java.io.Writer)

Aggregations

IOException (java.io.IOException)1 Writer (java.io.Writer)1 UserTransaction (javax.transaction.UserTransaction)1 AccessDeniedException (org.alfresco.repo.security.permissions.AccessDeniedException)1 InvalidNodeRefException (org.alfresco.service.cmr.repository.InvalidNodeRefException)1 NodeRef (org.alfresco.service.cmr.repository.NodeRef)1 NodeService (org.alfresco.service.cmr.repository.NodeService)1 Path (org.alfresco.service.cmr.repository.Path)1 UINodePath (org.alfresco.web.ui.repo.component.UINodePath)1