Search in sources :

Example 41 with NodeService

use of org.alfresco.service.cmr.repository.NodeService 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 42 with NodeService

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

Example 43 with NodeService

use of org.alfresco.service.cmr.repository.NodeService in project alfresco-remote-api by Alfresco.

the class AbstractArchivedNodeWebScript method getArchivedNodesFrom.

/**
 * * This method gets all nodes from the archive which were originally
 * contained within the specified StoreRef.
 *
 * @param storeRef mandatory store ref
 * @param paging mandatory paging
 * @param filter optional filter
 */
protected PagingResults<NodeRef> getArchivedNodesFrom(StoreRef storeRef, ScriptPagingDetails paging, String filter) {
    NodeService nodeService = serviceRegistry.getNodeService();
    NodeRef archiveStoreRootNodeRef = nodeService.getStoreArchiveNode(storeRef);
    // Create canned query
    ArchivedNodesCannedQueryBuilder queryBuilder = new ArchivedNodesCannedQueryBuilder.Builder(archiveStoreRootNodeRef, paging).filter(filter).sortOrderAscending(false).build();
    // Query the DB
    PagingResults<NodeRef> result = nodeArchiveService.listArchivedNodes(queryBuilder);
    return result;
}
Also used : NodeRef(org.alfresco.service.cmr.repository.NodeRef) ArchivedNodesCannedQueryBuilder(org.alfresco.repo.node.archive.ArchivedNodesCannedQueryBuilder) NodeService(org.alfresco.service.cmr.repository.NodeService)

Example 44 with NodeService

use of org.alfresco.service.cmr.repository.NodeService in project alfresco-remote-api by Alfresco.

the class ArchivedNodeState method create.

public static ArchivedNodeState create(NodeRef archivedNode, ServiceRegistry serviceRegistry) {
    ArchivedNodeState result = new ArchivedNodeState();
    NodeService nodeService = serviceRegistry.getNodeService();
    Map<QName, Serializable> properties = nodeService.getProperties(archivedNode);
    result.archivedNodeRef = archivedNode;
    result.archivedBy = (String) properties.get(ContentModel.PROP_ARCHIVED_BY);
    result.archivedDate = (Date) properties.get(ContentModel.PROP_ARCHIVED_DATE);
    result.name = (String) properties.get(ContentModel.PROP_NAME);
    result.title = (String) properties.get(ContentModel.PROP_TITLE);
    result.description = (String) properties.get(ContentModel.PROP_DESCRIPTION);
    QName type = nodeService.getType(archivedNode);
    result.isContentType = (type.equals(ContentModel.TYPE_CONTENT) || serviceRegistry.getDictionaryService().isSubClass(type, ContentModel.TYPE_CONTENT));
    result.nodeType = type.toPrefixString(serviceRegistry.getNamespaceService());
    PersonService personService = serviceRegistry.getPersonService();
    if (result.archivedBy != null && personService.personExists(result.archivedBy)) {
        NodeRef personNodeRef = personService.getPerson(result.archivedBy, false);
        Map<QName, Serializable> personProps = nodeService.getProperties(personNodeRef);
        result.firstName = (String) personProps.get(ContentModel.PROP_FIRSTNAME);
        result.lastName = (String) personProps.get(ContentModel.PROP_LASTNAME);
    }
    ChildAssociationRef originalParentAssoc = (ChildAssociationRef) properties.get(ContentModel.PROP_ARCHIVED_ORIGINAL_PARENT_ASSOC);
    if (serviceRegistry.getPermissionService().hasPermission(originalParentAssoc.getParentRef(), PermissionService.READ).equals(AccessStatus.ALLOWED) && nodeService.exists(originalParentAssoc.getParentRef())) {
        result.displayPath = PathUtil.getDisplayPath(nodeService.getPath(originalParentAssoc.getParentRef()), true);
    } else {
        result.displayPath = "";
    }
    return result;
}
Also used : NodeRef(org.alfresco.service.cmr.repository.NodeRef) Serializable(java.io.Serializable) QName(org.alfresco.service.namespace.QName) NodeService(org.alfresco.service.cmr.repository.NodeService) PersonService(org.alfresco.service.cmr.security.PersonService) ChildAssociationRef(org.alfresco.service.cmr.repository.ChildAssociationRef)

Example 45 with NodeService

use of org.alfresco.service.cmr.repository.NodeService in project alfresco-remote-api by Alfresco.

the class GetMethod method generateDirectoryListing.

/**
 * Generates a HTML representation of the contents of the path represented by the given node
 *
 * @param fileInfo the file to use
 */
private void generateDirectoryListing(FileInfo fileInfo) {
    MimetypeService mimeTypeService = getMimetypeService();
    NodeService nodeService = getNodeService();
    Writer writer = null;
    try {
        writer = m_response.getWriter();
        boolean wasLink = false;
        if (fileInfo.isLink()) {
            fileInfo = getFileFolderService().getFileInfo(fileInfo.getLinkNodeRef());
            wasLink = true;
        }
        // Get the list of child nodes for the parent node
        List<FileInfo> childNodeInfos = getDAVHelper().getChildren(fileInfo);
        // Send back the start of the HTML
        writer.write("<html><head><title>");
        writer.write(WebDAVHelper.encodeHTML(I18NUtil.getMessage("webdav.repository_title")));
        writer.write("</title>");
        writer.write("<style>");
        writer.write("body { font-family: Arial, Helvetica; font-size: 12pt; background-color: white; }\n");
        writer.write("table { font-family: Arial, Helvetica; font-size: 12pt; background-color: white; }\n");
        writer.write(".listingTable { border: solid black 1px; }\n");
        writer.write(".textCommand { font-family: verdana; font-size: 10pt; }\n");
        writer.write(".textLocation { font-family: verdana; font-size: 11pt; font-weight: bold; color: #2a568f; }\n");
        writer.write(".textData { font-family: verdana; font-size: 10pt; }\n");
        writer.write(".tableHeading { font-family: verdana; font-size: 10pt; font-weight: bold; color: white; background-color: #2a568f; }\n");
        writer.write(".rowOdd { background-color: #eeeeee; }\n");
        writer.write(".rowEven { background-color: #dddddd; }\n");
        writer.write("</style></head>\n");
        writer.flush();
        // Send back the table heading
        writer.write("<body>\n");
        writer.write("<table cellspacing='2' cellpadding='3' border='0' width='100%'>\n");
        writer.write("<tr><td colspan='4' class='textLocation'>");
        writer.write(WebDAVHelper.encodeHTML(I18NUtil.getMessage("webdav.directory_listing")));
        writer.write(' ');
        writer.write(WebDAVHelper.encodeHTML(getPath()));
        writer.write("</td></tr>\n");
        writer.write("<tr><td height='10' colspan='4'></td></tr></table>");
        writer.write("<table cellspacing='2' cellpadding='3' border='0' width='100%' class='listingTable'>\n");
        writer.write("<tr><td class='tableHeading' width='*'>");
        writer.write(WebDAVHelper.encodeHTML(I18NUtil.getMessage("webdav.column.name")));
        writer.write("</td>");
        writer.write("<td class='tableHeading' width='10%'>");
        writer.write(WebDAVHelper.encodeHTML(I18NUtil.getMessage("webdav.column.size")));
        writer.write("</td>");
        writer.write("<td class='tableHeading' width='20%'>");
        writer.write(WebDAVHelper.encodeHTML(I18NUtil.getMessage("webdav.column.type")));
        writer.write("</td>");
        writer.write("<td class='tableHeading' width='25%'>");
        writer.write(WebDAVHelper.encodeHTML(I18NUtil.getMessage("webdav.column.modifieddate")));
        writer.write("</td>");
        writer.write("</tr>\n");
        // Get the URL for the root path
        String rootURL = getURLForPath(m_request, getPath(), true);
        if (rootURL.endsWith(WebDAVHelper.PathSeperator) == false) {
            rootURL = rootURL + WebDAVHelper.PathSeperator;
        }
        if (wasLink) {
            Path pathToNode = nodeService.getPath(fileInfo.getNodeRef());
            if (pathToNode.size() > 2) {
                pathToNode = pathToNode.subPath(2, pathToNode.size() - 1);
            }
            rootURL = getURLForPath(m_request, pathToNode.toDisplayPath(nodeService, getPermissionService()), true);
            if (rootURL.endsWith(WebDAVHelper.PathSeperator) == false) {
                rootURL = rootURL + WebDAVHelper.PathSeperator;
            }
            rootURL = rootURL + WebDAVHelper.encodeURL(fileInfo.getName(), m_userAgent) + WebDAVHelper.PathSeperator;
        }
        // Start with a link to the parent folder so we can navigate back up, unless we are at the root level
        if (!getDAVHelper().isRootPath(getPath(), getServletPath())) {
            writer.write("<tr class='rowOdd'>");
            writer.write("<td colspan='4' class='textData'><a href=\"");
            // Strip the last folder from the path
            String parentFolderUrl = parentFolder(rootURL);
            writer.write(parentFolderUrl);
            writer.write("\">");
            writer.write("[");
            writer.write(WebDAVHelper.encodeHTML(I18NUtil.getMessage("webdav.column.navigate_up")));
            writer.write("]</a>");
            writer.write("</tr>\n");
        }
        // Send back what we have generated so far
        writer.flush();
        int rowId = 0;
        for (FileInfo childNodeInfo : childNodeInfos) {
            // Output the details for the current node
            writer.write("<tr class='");
            if ((rowId++ & 1) == 1) {
                writer.write("rowOdd");
            } else {
                writer.write("rowEven");
            }
            writer.write("'><td class='textData'><a href=\"");
            writer.write(rootURL);
            // name field
            String fname = childNodeInfo.getName();
            writer.write(WebDAVHelper.encodeURL(fname, m_userAgent));
            writer.write("\">");
            writer.write(WebDAVHelper.encodeHTML(fname));
            writer.write("</a>");
            // size field
            writer.write("</td><td class='textData'>");
            ContentData contentData = null;
            if (!childNodeInfo.isFolder()) {
                Serializable contentPropertyName = nodeService.getProperty(childNodeInfo.getNodeRef(), ContentModel.PROP_CONTENT_PROPERTY_NAME);
                QName contentPropertyQName = DefaultTypeConverter.INSTANCE.convert(QName.class, contentPropertyName);
                if (null == contentPropertyQName) {
                    contentPropertyQName = ContentModel.PROP_CONTENT;
                }
                Serializable contentProperty = nodeService.getProperty(childNodeInfo.getNodeRef(), contentPropertyQName);
                if (contentProperty instanceof ContentData) {
                    contentData = (ContentData) contentProperty;
                }
            }
            if (childNodeInfo.isFolder()) {
                writer.write("&nbsp;");
            } else {
                if (null != contentData) {
                    writer.write(formatSize(Long.toString(contentData.getSize())));
                } else {
                    writer.write("&nbsp;");
                }
            }
            writer.write("</td><td class='textData'>");
            // mimetype field
            if (childNodeInfo.isFolder()) {
                writer.write("&nbsp;");
            } else {
                String mimetype = "&nbsp;";
                if (null != contentData) {
                    mimetype = contentData.getMimetype();
                    String displayType = mimeTypeService.getDisplaysByMimetype().get(mimetype);
                    if (displayType != null) {
                        mimetype = displayType;
                    }
                }
                writer.write(mimetype);
            }
            writer.write("</td><td class='textData'>");
            // modified date field
            Date modifiedDate = childNodeInfo.getModifiedDate();
            if (modifiedDate != null) {
                writer.write(WebDAV.formatHeaderDate(DefaultTypeConverter.INSTANCE.longValue(modifiedDate)));
            } else {
                writer.write("&nbsp;");
            }
            writer.write("</td></tr>\n");
            // flush every few rows
            if ((rowId & 15) == 0) {
                writer.flush();
            }
        }
        writer.write("</table></body></html>");
    } catch (Throwable e) {
        logger.error(e);
        if (writer != null) {
            try {
                writer.write("</table><table><tr><td style='color:red'>");
                writer.write(WebDAVHelper.encodeHTML(I18NUtil.getMessage("webdav.err.dir")));
                writer.write("</td></tr></table></body></html>");
                writer.flush();
            } catch (IOException ioe) {
            }
        }
    }
}
Also used : Path(org.alfresco.service.cmr.repository.Path) Serializable(java.io.Serializable) QName(org.alfresco.service.namespace.QName) NodeService(org.alfresco.service.cmr.repository.NodeService) IOException(java.io.IOException) Date(java.util.Date) ContentData(org.alfresco.service.cmr.repository.ContentData) FileInfo(org.alfresco.service.cmr.model.FileInfo) MimetypeService(org.alfresco.service.cmr.repository.MimetypeService) Writer(java.io.Writer)

Aggregations

NodeService (org.alfresco.service.cmr.repository.NodeService)53 NodeRef (org.alfresco.service.cmr.repository.NodeRef)36 QName (org.alfresco.service.namespace.QName)15 ChildAssociationRef (org.alfresco.service.cmr.repository.ChildAssociationRef)11 ResponseWriter (javax.faces.context.ResponseWriter)10 IOException (java.io.IOException)8 UserTransaction (javax.transaction.UserTransaction)8 ServiceRegistry (org.alfresco.service.ServiceRegistry)8 DictionaryService (org.alfresco.service.cmr.dictionary.DictionaryService)8 Serializable (java.io.Serializable)7 HashMap (java.util.HashMap)7 FileFolderService (org.alfresco.service.cmr.model.FileFolderService)7 PermissionService (org.alfresco.service.cmr.security.PermissionService)7 PersonService (org.alfresco.service.cmr.security.PersonService)7 SearchService (org.alfresco.service.cmr.search.SearchService)6 ArrayList (java.util.ArrayList)5 ResourceBundle (java.util.ResourceBundle)5 FileInfo (org.alfresco.service.cmr.model.FileInfo)5 Path (org.alfresco.service.cmr.repository.Path)5 TransactionService (org.alfresco.service.transaction.TransactionService)5