Search in sources :

Example 6 with ContentData

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

the class RenditionsImpl method toApiRendition.

protected Rendition toApiRendition(NodeRef renditionNodeRef) {
    Rendition apiRendition = new Rendition();
    String renditionName = (String) nodeService.getProperty(renditionNodeRef, ContentModel.PROP_NAME);
    apiRendition.setId(renditionName);
    ContentData contentData = getContentData(renditionNodeRef, false);
    ContentInfo contentInfo = null;
    if (contentData != null) {
        contentInfo = new ContentInfo(contentData.getMimetype(), getMimeTypeDisplayName(contentData.getMimetype()), contentData.getSize(), contentData.getEncoding());
    }
    apiRendition.setContent(contentInfo);
    apiRendition.setStatus(RenditionStatus.CREATED);
    return apiRendition;
}
Also used : ContentData(org.alfresco.service.cmr.repository.ContentData) ContentInfo(org.alfresco.rest.api.model.ContentInfo) Rendition(org.alfresco.rest.api.model.Rendition)

Example 7 with ContentData

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

the class TemplateSupportBean method selectDictionaryNodes.

/**
 * @param fc         FacesContext
 * @param xpath      XPath to the nodes to select
 * @param noSelectionLabel   Label to add to the list if no items are found in the search
 * @param mimetype   Optional mimetype of items to add, will not add to list if mimetype does not match
 *
 * @return List of SelectItem wrapper objects for the nodes found at the XPath
 */
private List<SelectItem> selectDictionaryNodes(FacesContext fc, String xpath, String noSelectionLabel, String mimetype) {
    List<SelectItem> wrappers = null;
    try {
        NodeRef rootNodeRef = this.getNodeService().getRootNode(Repository.getStoreRef());
        NamespaceService resolver = Repository.getServiceRegistry(fc).getNamespaceService();
        List<NodeRef> results = this.getSearchService().selectNodes(rootNodeRef, xpath, null, resolver, false);
        wrappers = new ArrayList<SelectItem>(results.size() + 1);
        if (results.size() != 0) {
            DictionaryService dd = Repository.getServiceRegistry(fc).getDictionaryService();
            for (NodeRef ref : results) {
                if (this.getNodeService().exists(ref) == true) {
                    Node childNode = new Node(ref);
                    ContentData content = (ContentData) childNode.getProperties().get(ContentModel.PROP_CONTENT);
                    if (dd.isSubClass(childNode.getType(), ContentModel.TYPE_CONTENT) && (mimetype == null || mimetype.equals(content.getMimetype()))) {
                        wrappers.add(new SelectItem(childNode.getId(), childNode.getName()));
                    }
                }
            }
            // make sure the list is sorted by the label
            QuickSort sorter = new QuickSort(wrappers, "label", true, IDataContainer.SORT_CASEINSENSITIVE);
            sorter.sort();
        }
    } catch (AccessDeniedException accessErr) {
    // ignore the result if we cannot access the root
    }
    // add an entry (at the start) to instruct the user to select an item
    if (wrappers == null) {
        wrappers = new ArrayList<SelectItem>(1);
    }
    wrappers.add(0, new SelectItem(NO_SELECTION, Application.getMessage(FacesContext.getCurrentInstance(), noSelectionLabel)));
    return wrappers;
}
Also used : NodeRef(org.alfresco.service.cmr.repository.NodeRef) DictionaryService(org.alfresco.service.cmr.dictionary.DictionaryService) QuickSort(org.alfresco.web.data.QuickSort) AccessDeniedException(org.alfresco.repo.security.permissions.AccessDeniedException) ContentData(org.alfresco.service.cmr.repository.ContentData) NamespaceService(org.alfresco.service.namespace.NamespaceService) SelectItem(javax.faces.model.SelectItem) Node(org.alfresco.web.bean.repository.Node)

Example 8 with ContentData

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

the class DocumentDetailsDialog method applyInlineEditable.

/**
 * Applies the inlineeditable aspect to the current document
 */
public String applyInlineEditable() {
    try {
        RetryingTransactionHelper txnHelper = Repository.getRetryingTransactionHelper(FacesContext.getCurrentInstance());
        RetryingTransactionCallback<Object> callback = new RetryingTransactionCallback<Object>() {

            public Object execute() throws Throwable {
                // add the inlineeditable aspect to the node
                Map<QName, Serializable> props = new HashMap<QName, Serializable>(1, 1.0f);
                String contentType = null;
                ContentData contentData = (ContentData) getDocument().getProperties().get(ContentModel.PROP_CONTENT);
                if (contentData != null) {
                    contentType = contentData.getMimetype();
                }
                if (contentType != null) {
                    // set the property to true by default if the filetype is a known content type
                    if (MimetypeMap.MIMETYPE_HTML.equals(contentType) || MimetypeMap.MIMETYPE_TEXT_PLAIN.equals(contentType) || MimetypeMap.MIMETYPE_XML.equals(contentType) || MimetypeMap.MIMETYPE_TEXT_CSS.equals(contentType) || MimetypeMap.MIMETYPE_JAVASCRIPT.equals(contentType)) {
                        props.put(ApplicationModel.PROP_EDITINLINE, true);
                    }
                }
                getNodeService().addAspect(getDocument().getNodeRef(), ApplicationModel.ASPECT_INLINEEDITABLE, props);
                return null;
            }
        };
        txnHelper.doInTransaction(callback);
        // reset the state of the current document
        getDocument().reset();
    } catch (Throwable e) {
        Utils.addErrorMessage(MessageFormat.format(Application.getMessage(FacesContext.getCurrentInstance(), MSG_ERROR_ASPECT_INLINEEDITABLE), e.getMessage()), e);
        ReportedException.throwIfNecessary(e);
    }
    // force recreation of the details view - this means the properties sheet component will reinit
    return OUTCOME_RETURN;
}
Also used : Serializable(java.io.Serializable) ContentData(org.alfresco.service.cmr.repository.ContentData) RetryingTransactionHelper(org.alfresco.repo.transaction.RetryingTransactionHelper) RetryingTransactionCallback(org.alfresco.repo.transaction.RetryingTransactionHelper.RetryingTransactionCallback) HashMap(java.util.HashMap) QName(org.alfresco.service.namespace.QName)

Example 9 with ContentData

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

the class DocumentPropertiesDialog method setupDocumentForAction.

/**
 * Event handler called to setup the document for property editing
 *
 * @param event The event
 */
public void setupDocumentForAction(ActionEvent event) {
    this.editableNode = new Node(this.browseBean.getDocument().getNodeRef());
    // special case for Mimetype - since this is a sub-property of the ContentData object
    // we must extract it so it can be edited in the client, then we check for it later
    // and create a new ContentData object to wrap it and it's associated URL
    ContentData content = (ContentData) this.editableNode.getProperties().get(ContentModel.PROP_CONTENT);
    if (content != null) {
        this.editableNode.getProperties().put(TEMP_PROP_MIMETYPE, content.getMimetype());
        this.editableNode.getProperties().put(TEMP_PROP_ENCODING, content.getEncoding());
    }
    this.hasOtherProperties = null;
}
Also used : ContentData(org.alfresco.service.cmr.repository.ContentData) Node(org.alfresco.web.bean.repository.Node)

Example 10 with ContentData

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

the class ViewContentPropertiesDialog method init.

// ------------------------------------------------------------------------------
// Dialog implementation
@Override
public void init(Map<String, String> parameters) {
    super.init(parameters);
    Node document = this.browseBean.getDocument();
    if (document != null) {
        // setup the editable node
        this.viewingNode = new Node(document.getNodeRef());
        // special case for Mimetype - since this is a sub-property of the ContentData object
        // we must extract it so it can be edited in the client, then we check for it later
        // and create a new ContentData object to wrap it and it's associated URL
        ContentData content = (ContentData) this.viewingNode.getProperties().get(ContentModel.PROP_CONTENT);
        if (content != null) {
            this.viewingNode.getProperties().put(TEMP_PROP_MIMETYPE, content.getMimetype());
            this.viewingNode.getProperties().put(TEMP_PROP_ENCODING, content.getEncoding());
        }
        // add the specially handled 'size' property
        this.viewingNode.addPropertyResolver("size", this.browseBean.resolverSize);
    }
}
Also used : ContentData(org.alfresco.service.cmr.repository.ContentData) Node(org.alfresco.web.bean.repository.Node)

Aggregations

ContentData (org.alfresco.service.cmr.repository.ContentData)29 Serializable (java.io.Serializable)14 QName (org.alfresco.service.namespace.QName)14 NodeRef (org.alfresco.service.cmr.repository.NodeRef)10 Date (java.util.Date)5 InvalidArgumentException (org.alfresco.rest.framework.core.exceptions.InvalidArgumentException)5 HashMap (java.util.HashMap)4 InputStream (java.io.InputStream)3 Map (java.util.Map)3 ContentInfo (org.alfresco.rest.api.model.ContentInfo)3 ConstraintViolatedException (org.alfresco.rest.framework.core.exceptions.ConstraintViolatedException)3 DisabledServiceException (org.alfresco.rest.framework.core.exceptions.DisabledServiceException)3 FileExistsException (org.alfresco.service.cmr.model.FileExistsException)3 ChildAssociationRef (org.alfresco.service.cmr.repository.ChildAssociationRef)3 ContentWriter (org.alfresco.service.cmr.repository.ContentWriter)3 InvalidNodeRefException (org.alfresco.service.cmr.repository.InvalidNodeRefException)3 Node (org.alfresco.web.bean.repository.Node)3 SessionUser (org.alfresco.repo.SessionUser)2 AccessDeniedException (org.alfresco.repo.security.permissions.AccessDeniedException)2 RetryingTransactionCallback (org.alfresco.repo.transaction.RetryingTransactionHelper.RetryingTransactionCallback)2