Search in sources :

Example 6 with Path

use of org.alfresco.service.cmr.repository.Path in project acs-community-packaging by Alfresco.

the class Repository method getNameForCategoryNode.

/**
 * Helper to get the display name path for a category node.
 *
 * @param nodeService NodeService
 * @param ref the category node ref
 * @return display name string for the specified category node.
 */
public static String getNameForCategoryNode(NodeService nodeService, NodeRef ref) {
    String name = null;
    // Check that node reference still exists
    if (nodeService.exists(ref) == true) {
        Path path = nodeService.getPath(ref);
        name = Repository.getNamePath(nodeService, path, null, "/", null);
    }
    return name;
}
Also used : Path(org.alfresco.service.cmr.repository.Path)

Example 7 with Path

use of org.alfresco.service.cmr.repository.Path in project acs-community-packaging by Alfresco.

the class Repository method getNamePath.

/**
 * Resolve a Path by converting each element into its display NAME attribute
 *
 * @param path       Path to convert
 * @param separator  Separator to user between path elements
 * @param prefix     To prepend to the path
 *
 * @return Path converted using NAME attribute on each element
 */
public static String getNamePath(NodeService nodeService, Path path, NodeRef rootNode, String separator, String prefix) {
    StringBuilder buf = new StringBuilder(128);
    // ignore root node check if not passed in
    boolean foundRoot = (rootNode == null);
    if (prefix != null) {
        buf.append(prefix);
    }
    // skip first element as it represents repo root '/'
    for (int i = 1; i < path.size(); i++) {
        Path.Element element = path.get(i);
        String elementString = null;
        if (element instanceof Path.ChildAssocElement) {
            ChildAssociationRef elementRef = ((Path.ChildAssocElement) element).getRef();
            if (elementRef.getParentRef() != null) {
                // only append if we've found the root already
                if (foundRoot == true) {
                    Object nameProp = nodeService.getProperty(elementRef.getChildRef(), ContentModel.PROP_NAME);
                    if (nameProp != null) {
                        elementString = nameProp.toString();
                    } else {
                        elementString = element.getElementString();
                    }
                }
                // either we've found root already or may have now
                // check after as we want to skip the root as it represents the CIFS share name
                foundRoot = (foundRoot || elementRef.getChildRef().equals(rootNode));
            }
        } else {
            elementString = element.getElementString();
        }
        if (elementString != null) {
            buf.append(separator);
            buf.append(elementString);
        }
    }
    return buf.toString();
}
Also used : Path(org.alfresco.service.cmr.repository.Path) ChildAssociationRef(org.alfresco.service.cmr.repository.ChildAssociationRef)

Example 8 with Path

use of org.alfresco.service.cmr.repository.Path in project acs-community-packaging by Alfresco.

the class NodePathLinkRenderer method buildPathAsSingular.

/**
 * Return the path with the entire path as a single clickable link
 *
 * @param context        FacesContext
 * @param component      UIComponent to get display attribute from
 * @param path           Node Path to use
 *
 * @return the entire path as a single clickable link
 */
private String buildPathAsSingular(FacesContext context, UIComponent component, Path path, boolean showLeaf, boolean disabled) {
    StringBuilder buf = new StringBuilder(512);
    NodeService nodeService = getNodeService(context);
    PermissionService permissionService = getPermissionService(context);
    NodeRef lastElementRef = null;
    int size = (showLeaf ? path.size() : path.size() - 1);
    int lastElementPos = (showLeaf ? path.size() - 1 : path.size() - 2);
    for (int i = 0; i < size; i++) {
        Path.Element element = path.get(i);
        String elementString = null;
        if (element instanceof Path.ChildAssocElement) {
            ChildAssociationRef elementRef = ((Path.ChildAssocElement) element).getRef();
            if (elementRef.getParentRef() != null) {
                String name = null;
                if (permissionService.hasPermission(elementRef.getChildRef(), PermissionService.READ) == AccessStatus.ALLOWED) {
                    // use the name property if we are allowed access to it
                    elementString = nodeService.getProperty(elementRef.getChildRef(), ContentModel.PROP_NAME).toString();
                } else {
                    // revert to using QName if not
                    elementString = elementRef.getQName().getLocalName();
                }
            }
            if (i == lastElementPos) {
                lastElementRef = elementRef.getChildRef();
            }
        } else {
            elementString = element.getElementString();
        }
        if (elementString != null) {
            buf.append("/");
            buf.append(elementString);
        }
    }
    if (disabled == false && lastElementRef != null) {
        return renderPathElement(context, component, lastElementRef, buf.toString());
    } else {
        return buf.toString();
    }
}
Also used : PermissionService(org.alfresco.service.cmr.security.PermissionService) Path(org.alfresco.service.cmr.repository.Path) UINodePath(org.alfresco.web.ui.repo.component.UINodePath) NodeRef(org.alfresco.service.cmr.repository.NodeRef) NodeService(org.alfresco.service.cmr.repository.NodeService) ChildAssociationRef(org.alfresco.service.cmr.repository.ChildAssociationRef)

Example 9 with Path

use of org.alfresco.service.cmr.repository.Path 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)

Example 10 with Path

use of org.alfresco.service.cmr.repository.Path in project acs-community-packaging by Alfresco.

the class NodePathLinkRenderer method buildPathAsBreadcrumb.

/**
 * Return the path with each element as a single clickable link e.g. breadcrumb style
 *
 * @param context        FacesContext
 * @param component      UIComponent to get display attribute from
 * @param path           Node Path to use
 *
 * @return the path with each individual element clickable
 */
private String buildPathAsBreadcrumb(FacesContext context, UIComponent component, Path path, boolean showLeaf) {
    StringBuilder buf = new StringBuilder(1024);
    NodeService nodeService = getNodeService(context);
    PermissionService permissionService = getPermissionService(context);
    int size = (showLeaf ? path.size() : path.size() - 1);
    for (int i = 0; i < size; i++) {
        Path.Element element = path.get(i);
        String elementString = null;
        if (element instanceof Path.ChildAssocElement) {
            ChildAssociationRef elementRef = ((Path.ChildAssocElement) element).getRef();
            if (elementRef.getParentRef() != null) {
                String name = null;
                if (permissionService.hasPermission(elementRef.getChildRef(), PermissionService.READ) == AccessStatus.ALLOWED) {
                    // use the name property if we are allowed access to it
                    name = nodeService.getProperty(elementRef.getChildRef(), ContentModel.PROP_NAME).toString();
                } else {
                    // revert to using QName if not
                    name = elementRef.getQName().getLocalName();
                }
                elementString = renderPathElement(context, component, elementRef.getChildRef(), name);
            }
        } else {
            elementString = element.getElementString();
        }
        if (elementString != null) {
            buf.append("/");
            buf.append(elementString);
        }
    }
    return buf.toString();
}
Also used : PermissionService(org.alfresco.service.cmr.security.PermissionService) Path(org.alfresco.service.cmr.repository.Path) UINodePath(org.alfresco.web.ui.repo.component.UINodePath) NodeService(org.alfresco.service.cmr.repository.NodeService) ChildAssociationRef(org.alfresco.service.cmr.repository.ChildAssociationRef)

Aggregations

Path (org.alfresco.service.cmr.repository.Path)13 NodeRef (org.alfresco.service.cmr.repository.NodeRef)8 ChildAssociationRef (org.alfresco.service.cmr.repository.ChildAssociationRef)6 NodeService (org.alfresco.service.cmr.repository.NodeService)5 Serializable (java.io.Serializable)3 ArrayList (java.util.ArrayList)3 QName (org.alfresco.service.namespace.QName)3 UINodePath (org.alfresco.web.ui.repo.component.UINodePath)3 IOException (java.io.IOException)2 Writer (java.io.Writer)2 Date (java.util.Date)2 FilterPropBoolean (org.alfresco.repo.node.getchildren.FilterPropBoolean)2 AccessDeniedException (org.alfresco.repo.security.permissions.AccessDeniedException)2 PathInfo (org.alfresco.rest.api.model.PathInfo)2 ElementInfo (org.alfresco.rest.api.model.PathInfo.ElementInfo)2 FileInfo (org.alfresco.service.cmr.model.FileInfo)2 InvalidNodeRefException (org.alfresco.service.cmr.repository.InvalidNodeRefException)2 Element (org.alfresco.service.cmr.repository.Path.Element)2 PermissionService (org.alfresco.service.cmr.security.PermissionService)2 FacesContext (javax.faces.context.FacesContext)1