Java Code Examples for org.alfresco.service.cmr.repository.ContentData.getMimetype()

The following are Jave code examples for showing how to use getMimetype() of the org.alfresco.service.cmr.repository.ContentData class. You can vote up the examples you like. Your votes will be used in our system to get more good examples.
+ Save this method
Example 1
Project: alfresco-repository   File: ScriptNode.java   View Source Code Vote up 6 votes
/**
 * Returns the names of the thumbnail defintions that can be applied to the content property of
 * this node.
 * <p>
 * Thumbanil defintions only appear in this list if they can produce a thumbnail for the content
 * found in the content property.  This will be determined by looking at the mimetype of the content
 * and the destinatino mimetype of the thumbnail.
 * 
 * @return  String[]    array of thumbnail names that are valid for the current content type
 */
public String[] getThumbnailDefinitions()
{
    ThumbnailService thumbnailService = this.services.getThumbnailService();
    
    List<String> result = new ArrayList<String>(7);
    
    Serializable value = this.nodeService.getProperty(nodeRef, ContentModel.PROP_CONTENT);
    ContentData contentData = DefaultTypeConverter.INSTANCE.convert(ContentData.class, value);
    
    if (ContentData.hasContent(contentData))
    {
        String mimetype = contentData.getMimetype();
        List<ThumbnailDefinition> thumbnailDefinitions = thumbnailService.getThumbnailRegistry().getThumbnailDefinitions(mimetype, contentData.getSize());
        for (ThumbnailDefinition thumbnailDefinition : thumbnailDefinitions)
        {
            result.add(thumbnailDefinition.getName());
        }
    }
    
    return (String[])result.toArray(new String[result.size()]);
}
 
Example 2
Project: alfresco-repository   File: FormServiceImplTest.java   View Source Code Vote up 6 votes
private void checkContentDetails(NodeRef node, String expectedName, String expectedTitle, 
            String expectedMimetype, String expectedContent)
{
    Map<QName, Serializable> props = this.nodeService.getProperties(node);
    String name = (String)props.get(ContentModel.PROP_NAME);
    String title = (String)props.get(ContentModel.PROP_TITLE);
    assertEquals(expectedName, name);
    assertEquals(expectedTitle, title);
    
    ContentData contentData = (ContentData) this.nodeService.getProperty(node, ContentModel.PROP_CONTENT);
    assertNotNull(contentData);
    String mimetype = contentData.getMimetype();
    assertEquals(expectedMimetype, mimetype);
    
    ContentReader reader = this.contentService.getReader(node, ContentModel.PROP_CONTENT);
    assertNotNull(reader);
    String content = reader.getContentString();
    assertEquals(expectedContent, content);
}
 
Example 3
Project: alfresco-remote-api   File: WebDAV.java   View Source Code Vote up 6 votes
/**
 * Return the Alfresco property value for the specified WebDAV property
 * 
 * @param davPropName String
 * @return Object
 */
public static Object getDAVPropertyValue( Map<QName, Serializable> props, String davPropName)
{
    // Convert the WebDAV property name to the corresponding Alfresco property
    
    QName propName = _propertyNameMap.get( davPropName);
    if ( propName == null)
        throw new AlfrescoRuntimeException("No mapping for WebDAV property " + davPropName);
    
    //  Return the property value
    Object value = props.get(propName);
    if (value instanceof ContentData)
    {
        ContentData contentData = (ContentData) value;
        if (davPropName.equals(WebDAV.XML_GET_CONTENT_TYPE))
        {
            value = contentData.getMimetype();
        }
        else if (davPropName.equals(WebDAV.XML_GET_CONTENT_LENGTH))
        {
            value = new Long(contentData.getSize());
        }
    }
    return value;
}
 
Example 4
Project: alfresco-remote-api   File: Document.java   View Source Code Vote up 6 votes
public Document(NodeRef nodeRef, NodeRef parentNodeRef, Map<QName, Serializable> nodeProps, Map<String, UserInfo> mapUserInfo, ServiceRegistry sr)
{
    super(nodeRef, parentNodeRef, nodeProps, mapUserInfo, sr);

    Serializable val = nodeProps.get(ContentModel.PROP_CONTENT);

    if ((val != null) && (val instanceof ContentData)) {
        ContentData cd = (ContentData)val;
        String mimeType = cd.getMimetype();
        String mimeTypeName = sr.getMimetypeService().getDisplaysByMimetype().get(mimeType);
        contentInfo = new ContentInfo(mimeType, mimeTypeName, cd.getSize(), cd.getEncoding());
    }

    setIsFolder(false);
    setIsFile(true);
}
 
Example 5
Project: alfresco-remote-api   File: RenditionsImpl.java   View Source Code Vote up 6 votes
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;
}
 
Example 6
Project: alfresco-repository   File: NodeContentData.java   View Source Code Vote up 5 votes
/**
 * Construct
 */
public NodeContentData(NodeRef nodeRef, ContentData contentData)
{
    super(contentData.getContentUrl(), contentData.getMimetype(), contentData.getSize(),
            contentData.getEncoding(), contentData.getLocale());
    this.nodeRef = nodeRef;
}
 
Example 7
Project: alfresco-repository   File: ContentDataPart.java   View Source Code Vote up 5 votes
/**
 * ContentDataPart 
 * @param contentService content service
 * @param partName String
 * @param data data
 */
public ContentDataPart(ContentService contentService, String partName, ContentData data) {
    super(partName, data.getMimetype(), data.getEncoding(), null);
    this.contentService = contentService;
    this.data = data;
    this.filename = partName;
}
 
Example 8
Project: alfresco-repository   File: AbstractContentDataDAOImpl.java   View Source Code Vote up 5 votes
private ContentData sanitizeMimetype(ContentData contentData)
{
    String mimetype = contentData.getMimetype();
    if (mimetype != null)
    {
        mimetype = mimetype.toLowerCase();
        contentData = ContentData.setMimetype(contentData, mimetype);
    }
    return contentData;
}
 
Example 9
Project: alfresco-repository   File: ContentStreamMimetypeProperty.java   View Source Code Vote up 5 votes
public Serializable getValueInternal(CMISNodeInfo nodeInfo)
{
    ContentData contentData = getContentData(nodeInfo);

    if (contentData != null)
    {
        return contentData.getMimetype();
    }
    return null;
}
 
Example 10
Project: alfresco-remote-api   File: BulkMetadataGet.java   View Source Code Vote up 5 votes
private String getMimeType(ContentData contentProperty)
{
    String mimetype = null;

    if(contentProperty != null)
    {
        mimetype = contentProperty.getMimetype();
    }

    return mimetype;
}
 
Example 11
Project: alfresco-remote-api   File: RenditionsImpl.java   View Source Code Vote up 5 votes
@Override
public void createRendition(String nodeId, Rendition rendition, boolean executeAsync, Parameters parameters)
{
    // If thumbnail generation has been configured off, then don't bother.
    if (!thumbnailService.getThumbnailsEnabled())
    {
        throw new DisabledServiceException("Thumbnail generation has been disabled.");
    }

    final NodeRef sourceNodeRef = validateSourceNode(nodeId);
    final NodeRef renditionNodeRef = getRenditionByName(sourceNodeRef, rendition.getId(), parameters);
    if (renditionNodeRef != null)
    {
        throw new ConstraintViolatedException(rendition.getId() + " rendition already exists.");
    }

    // Use the thumbnail registry to get the details of the thumbnail
    ThumbnailRegistry registry = thumbnailService.getThumbnailRegistry();
    ThumbnailDefinition thumbnailDefinition = registry.getThumbnailDefinition(rendition.getId());
    if (thumbnailDefinition == null)
    {
        throw new NotFoundException(rendition.getId() + " is not registered.");
    }

    ContentData contentData = getContentData(sourceNodeRef, true);
    // Check if anything is currently available to generate thumbnails for the specified mimeType
    if (!registry.isThumbnailDefinitionAvailable(contentData.getContentUrl(), contentData.getMimetype(), contentData.getSize(), sourceNodeRef,
                thumbnailDefinition))
    {
        throw new InvalidArgumentException("Unable to create thumbnail '" + thumbnailDefinition.getName() + "' for " +
                    contentData.getMimetype() + " as no transformer is currently available.");
    }

    Action action = ThumbnailHelper.createCreateThumbnailAction(thumbnailDefinition, serviceRegistry);

    // Create thumbnail - or else queue for async creation
    actionService.executeAction(action, sourceNodeRef, true, executeAsync);
}
 
Example 12
Project: alfresco-repository   File: ContentDiskDriver.java   View Source Code Vote up 4 votes
/**
 * Clone node
 * 
 * @param newName the new name of the node
 * @param fromNode the node to copy from
 * @param toNode the node to copy to
 * @param ctx
 */
private void cloneNode(String newName, NodeRef fromNode, NodeRef toNode, ContentContext ctx) 
{
    if(logger.isDebugEnabled())
    {
        logger.debug("clone node from fromNode:" + fromNode + "toNode:" + toNode);
    }
    cloneNodeAspects(newName, fromNode, toNode, ctx);

    // copy over the node creator and owner properties
    // need to disable the auditable aspect first to prevent default audit behaviour
    policyBehaviourFilter.disableBehaviour(ContentModel.ASPECT_AUDITABLE);
    try
    {
    	nodeService.setProperty(toNode, ContentModel.PROP_CREATOR, nodeService.getProperty(fromNode, ContentModel.PROP_CREATOR));
    	ownableService.setOwner(toNode, ownableService.getOwner(fromNode));
    }
    finally
    {
        policyBehaviourFilter.enableBehaviour(ContentModel.ASPECT_AUDITABLE);
    }
    
    Set<AccessPermission> permissions = permissionService.getAllSetPermissions(fromNode);
    boolean inheritParentPermissions = permissionService.getInheritParentPermissions(fromNode);
    permissionService.deletePermissions(fromNode);
    
    permissionService.setInheritParentPermissions(toNode, inheritParentPermissions);        
    for(AccessPermission permission : permissions)
    {
        permissionService.setPermission(toNode, permission.getAuthority(), permission.getPermission(), (permission.getAccessStatus() == AccessStatus.ALLOWED));
    }
    
    // Need to take a new guess at the mimetype based upon the new file name.
    ContentData content = (ContentData)nodeService.getProperty(toNode, ContentModel.PROP_CONTENT);
        
    // Take a guess at the mimetype (if it has not been set by something already)
    if (content != null && (content.getMimetype() == null || content.getMimetype().equals(MimetypeMap.MIMETYPE_BINARY)))
    {
        String mimetype = mimetypeService.guessMimetype(newName);
        if(logger.isDebugEnabled())
        {
            logger.debug("set new mimetype to:" + mimetype);
        }
        ContentData replacement = ContentData.setMimetype(content, mimetype);
        nodeService.setProperty(toNode, ContentModel.PROP_CONTENT, replacement);
    }

    // Extract metadata pending change for ALF-5082
    Action action = getActionService().createAction(ContentMetadataExtracter.EXECUTOR_NAME);
    if(action != null)
    {
        getActionService().executeAction(action, toNode);
    }
}
 
Example 13
Project: alfresco-repository   File: UpdateThumbnailActionExecuter.java   View Source Code Vote up 4 votes
/**
 * @see org.alfresco.repo.action.executer.ActionExecuterAbstractBase#executeImpl(org.alfresco.service.cmr.action.Action, org.alfresco.service.cmr.repository.NodeRef)
 */
@Override
protected void executeImpl(Action action, NodeRef actionedUponNodeRef)
{
    // Check if thumbnailing is generally disabled
    if (!thumbnailService.getThumbnailsEnabled())
    {
        if (logger.isDebugEnabled())
        {
            logger.debug("Thumbnail transformations are not enabled");
        }
        return;
    }
    
    // Get the thumbnail
    NodeRef thumbnailNodeRef = (NodeRef)action.getParameterValue(PARAM_THUMBNAIL_NODE);
    if (thumbnailNodeRef == null)
    {
        thumbnailNodeRef = actionedUponNodeRef;
    }
    
    if (this.nodeService.exists(thumbnailNodeRef) == true &&
            renditionService.isRendition(thumbnailNodeRef))
    {            
        // Get the thumbnail Name
        ChildAssociationRef parent = renditionService.getSourceNode(thumbnailNodeRef);
        String thumbnailName = parent.getQName().getLocalName();
        
        // Get the details of the thumbnail
        ThumbnailRegistry registry = this.thumbnailService.getThumbnailRegistry();
        ThumbnailDefinition details = registry.getThumbnailDefinition(thumbnailName);
        if (details == null)
        {
            throw new AlfrescoRuntimeException("The thumbnail name '" + thumbnailName + "' is not registered");
        }
        
        // Get the content property
        QName contentProperty = (QName)action.getParameterValue(PARAM_CONTENT_PROPERTY);
        if (contentProperty == null)
        {
            contentProperty = ContentModel.PROP_CONTENT;
        }
        
        Serializable contentProp = nodeService.getProperty(actionedUponNodeRef, contentProperty);
        if (contentProp == null)
        {
            logger.info("Creation of thumbnail, null content for " + details.getName());
            return;
        }

        if(contentProp instanceof ContentData)
        {
            ContentData content = (ContentData)contentProp;
            String mimetype = content.getMimetype();
            if (mimetypeMaxSourceSizeKBytes != null)
            {
                Long maxSourceSizeKBytes = mimetypeMaxSourceSizeKBytes.get(mimetype);
                if (maxSourceSizeKBytes != null && maxSourceSizeKBytes >= 0 && maxSourceSizeKBytes < (content.getSize()/1024L))
                {
                    logger.debug("Unable to create thumbnail '" + details.getName() + "' for " +
                            mimetype + " as content is too large ("+(content.getSize()/1024L)+"K > "+maxSourceSizeKBytes+"K)");
                    return; //avoid transform
                }
            }
        }
        // Create the thumbnail
        this.thumbnailService.updateThumbnail(thumbnailNodeRef, details.getTransformationOptions());
    }
}
 
Example 14
Project: alfresco-repository   File: AbstractContentDataDAOImpl.java   View Source Code Vote up 4 votes
/**
 * Translates the {@link ContentData} into persistable values using the helper DAOs
 */
protected ContentDataEntity createContentDataEntity(ContentData contentData)
{
    // Resolve the content URL
    Long contentUrlId = null;
    String contentUrl = contentData.getContentUrl();
    long size = contentData.getSize();
    if (contentUrl != null)
    {
        ContentUrlEntity contentUrlEntity = new ContentUrlEntity();
        contentUrlEntity.setContentUrl(contentUrl);
        contentUrlEntity.setSize(size);
        Pair<Long, ContentUrlEntity> pair = contentUrlCache.createOrGetByValue(contentUrlEntity, controlDAO);
        contentUrlId = pair.getFirst();
    }

    // Resolve the mimetype
    Long mimetypeId = null;
    String mimetype = contentData.getMimetype();
    if (mimetype != null)
    {
        mimetypeId = mimetypeDAO.getOrCreateMimetype(mimetype).getFirst();
    }
    // Resolve the encoding
    Long encodingId = null;
    String encoding = contentData.getEncoding();
    if (encoding != null)
    {
        encodingId = encodingDAO.getOrCreateEncoding(encoding).getFirst();
    }
    // Resolve the locale
    Long localeId = null;
    Locale locale = contentData.getLocale();
    if (locale != null)
    {
        localeId = localeDAO.getOrCreateLocalePair(locale).getFirst();
    }
    
    // Create ContentDataEntity
    ContentDataEntity contentDataEntity = createContentDataEntity(contentUrlId, mimetypeId, encodingId, localeId);
    // Done
    return contentDataEntity;
}
 
Example 15
Project: alfresco-repository   File: AbstractContentDataDAOImpl.java   View Source Code Vote up 4 votes
/**
 * Translates the {@link ContentData} into persistable values using the helper DAOs
 */
protected int updateContentDataEntity(ContentDataEntity contentDataEntity, ContentData contentData)
{
    // Resolve the content URL
    Long oldContentUrlId = contentDataEntity.getContentUrlId();
    ContentUrlEntity contentUrlEntity = null;
    if(oldContentUrlId != null)
    {
        Pair<Long, ContentUrlEntity> entityPair = contentUrlCache.getByKey(oldContentUrlId);
        if (entityPair == null)
        {
            throw new DataIntegrityViolationException("No ContentUrl value exists for ID " + oldContentUrlId);
        }
        contentUrlEntity = entityPair.getSecond();
    }

    String oldContentUrl = (contentUrlEntity != null ? contentUrlEntity.getContentUrl() : null);
    String newContentUrl = contentData.getContentUrl();
    if (!EqualsHelper.nullSafeEquals(oldContentUrl, newContentUrl))
    {
        if (oldContentUrl != null)
        {
            // We have a changed value.  The old content URL has been dereferenced.
            registerDereferencedContentUrl(oldContentUrl);
        }
        if (newContentUrl != null)
        {
            if(contentUrlEntity == null)
            {
                contentUrlEntity = new ContentUrlEntity();
                contentUrlEntity.setContentUrl(newContentUrl);
            }
            Pair<Long, ContentUrlEntity> pair = contentUrlCache.getOrCreateByValue(contentUrlEntity);
            Long newContentUrlId = pair.getFirst();
            contentUrlEntity.setId(newContentUrlId);
            contentDataEntity.setContentUrlId(newContentUrlId);
        }
        else
        {
            contentDataEntity.setId(null);
            contentDataEntity.setContentUrlId(null);
        }
    }

    // Resolve the mimetype
    Long mimetypeId = null;
    String mimetype = contentData.getMimetype();
    if (mimetype != null)
    {
        mimetypeId = mimetypeDAO.getOrCreateMimetype(mimetype).getFirst();
    }
    // Resolve the encoding
    Long encodingId = null;
    String encoding = contentData.getEncoding();
    if (encoding != null)
    {
        encodingId = encodingDAO.getOrCreateEncoding(encoding).getFirst();
    }
    // Resolve the locale
    Long localeId = null;
    Locale locale = contentData.getLocale();
    if (locale != null)
    {
        localeId = localeDAO.getOrCreateLocalePair(locale).getFirst();
    }

    contentDataEntity.setMimetypeId(mimetypeId);
    contentDataEntity.setEncodingId(encodingId);
    contentDataEntity.setLocaleId(localeId);

    return updateContentDataEntity(contentDataEntity);
}
 
Example 16
Project: alfresco-remote-api   File: NodesImpl.java   View Source Code Vote up 4 votes
@Override
public BinaryResource getContent(NodeRef nodeRef, Parameters parameters, boolean recordActivity)
{
    if (!nodeMatches(nodeRef, Collections.singleton(ContentModel.TYPE_CONTENT), null, false))
    {
        throw new InvalidArgumentException("NodeId of content is expected: " + nodeRef.getId());
    }

    Map<QName, Serializable> nodeProps = nodeService.getProperties(nodeRef);
    ContentData cd = (ContentData) nodeProps.get(ContentModel.PROP_CONTENT);
    String name = (String) nodeProps.get(ContentModel.PROP_NAME);

    org.alfresco.rest.framework.resource.content.ContentInfo ci = null;
    String mimeType = null;
    if (cd != null)
    {
        mimeType = cd.getMimetype();
        ci = new org.alfresco.rest.framework.resource.content.ContentInfoImpl(mimeType, cd.getEncoding(), cd.getSize(), cd.getLocale());
    }

    // By default set attachment header (with filename) unless attachment=false *and* content type is pre-configured as non-attach
    boolean attach = true;
    String attachment = parameters.getParameter("attachment");
    if (attachment != null)
    {
        Boolean a = Boolean.valueOf(attachment);
        if (!a)
        {
            if (nonAttachContentTypes.contains(mimeType))
            {
                attach = false;
            }
            else
            {
                logger.warn("Ignored attachment=false for "+nodeRef.getId()+" since "+mimeType+" is not in the whitelist for non-attach content types");
            }
        }
    }
    String attachFileName = (attach ? name : null);

    if (recordActivity)
    {
        final ActivityInfo activityInfo = getActivityInfo(getParentNodeRef(nodeRef), nodeRef);
        postActivity(Activity_Type.DOWNLOADED, activityInfo, true);
    }

    return new NodeBinaryResource(nodeRef, ContentModel.PROP_CONTENT, ci, attachFileName);
}
 
Example 17
Project: alfresco-remote-api   File: QuickShareLinksImpl.java   View Source Code Vote up 4 votes
private QuickShareLink getQuickShareInfo(NodeRef nodeRef, Map<String, Object> map, boolean noAuth, List<String> includeParam)
{
    String sharedId = (String)map.get("sharedId");

    try
    {
        Map<QName, Serializable> nodeProps = nodeService.getProperties(nodeRef);
        ContentData cd = (ContentData)nodeProps.get(ContentModel.PROP_CONTENT);

        String mimeType = cd.getMimetype();
        String mimeTypeName = mimeTypeService.getDisplaysByMimetype().get(mimeType);
        ContentInfo contentInfo = new ContentInfo(mimeType, mimeTypeName, cd.getSize(), cd.getEncoding());

        Map<String, UserInfo> mapUserInfo = new HashMap<>(2);

        // note: if noAuth mode then don't return userids (to limit disclosure and be consistent with v0 internal)
        boolean displayNameOnly = noAuth;

        UserInfo modifiedByUser = Node.lookupUserInfo((String)nodeProps.get(ContentModel.PROP_MODIFIER), mapUserInfo, personService, displayNameOnly);

        // TODO review - should we return sharedByUser for authenticated users only ?? (not exposed by V0 but needed for "find")
        String sharedByUserId = (String)nodeProps.get(QuickShareModel.PROP_QSHARE_SHAREDBY);
        UserInfo sharedByUser = Node.lookupUserInfo(sharedByUserId, mapUserInfo, personService, displayNameOnly);

        QuickShareLink qs = new QuickShareLink(sharedId, nodeRef.getId());
        qs.setName((String) map.get("name"));
        qs.setTitle((String) map.get("title"));
        qs.setDescription((String) map.get("description"));
        qs.setContent(contentInfo);
        qs.setModifiedAt((Date) map.get("modified"));
        qs.setModifiedByUser(modifiedByUser);
        qs.setSharedByUser(sharedByUser);
        qs.setExpiresAt((Date) map.get("expiryDate"));

        // note: if noAuth mode then do not return allowable operations (eg. but can be optionally returned when finding shared links)
        if (!noAuth)
        {
            if (includeParam.contains(PARAM_INCLUDE_ALLOWABLEOPERATIONS))
            {
                if (quickShareService.canDeleteSharedLink(nodeRef, sharedByUserId))
                {
                    // the allowable operations for the shared link
                    qs.setAllowableOperations(Collections.singletonList(Nodes.OP_DELETE));
                }

                Node doc = nodes.getFolderOrDocument(nodeRef, null, null, includeParam, null);
                List<String> allowableOps = doc.getAllowableOperations();
                // the allowable operations for the actual file being shared
                qs.setAllowableOperationsOnTarget(allowableOps);
            }

            
            // in noAuth mode we don't return the path info
            if (includeParam.contains(PARAM_INCLUDE_PATH))
            {
                qs.setPath(nodes.lookupPathInfo(nodeRef, null));
            }
        }


        return qs;
    }
    catch (InvalidSharedIdException ex)
    {
        logger.warn("Unable to find: " + sharedId);
        throw new EntityNotFoundException(sharedId);
    }
    catch (InvalidNodeRefException inre)
    {
        logger.warn("Unable to find: " + sharedId + " [" + inre.getNodeRef() + "]");
        throw new EntityNotFoundException(sharedId);
    }
}
 
Example 18
Project: alfresco-remote-api   File: RenditionsImpl.java   View Source Code Vote up 4 votes
private String getMimeType(NodeRef nodeRef)
{
    ContentData contentData = getContentData(nodeRef, true);
    return contentData.getMimetype();
}