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

The following are Jave code examples for showing how to use setMimetype() 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 5 votes
public void setMimetype(String mimetype)
{
    mimetype = mimetype.toLowerCase();
    this.contentData = ContentData.setMimetype(this.contentData, mimetype);
    services.getNodeService().setProperty(nodeRef, this.property, this.contentData);
    updateContentData(false);
}
 
Example 2
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 3
Project: alfresco-repository   File: ImporterActionExecuterTest.java   View Source Code Vote up 5 votes
private void putContent(NodeRef zipFileNodeRef, String resource)
{
    URL url = AbstractContentTransformerTest.class.getClassLoader().getResource(resource);
    final File file = new File(url.getFile());
    
    contentService.getWriter(zipFileNodeRef, ContentModel.PROP_CONTENT, true).putContent(file);

    ContentData contentData = (ContentData) nodeService.getProperty(zipFileNodeRef, ContentModel.PROP_CONTENT);
    ContentData newContentData = ContentData.setMimetype(contentData, MimetypeMap.MIMETYPE_ZIP);

    nodeService.setProperty(zipFileNodeRef, ContentModel.PROP_CONTENT, newContentData);
}
 
Example 4
Project: alfresco-repository   File: ContentDataDAOTest.java   View Source Code Vote up 5 votes
/**
 * the caveat to {@link #testEnsureCaseSensitiveStorage()} is that mimetypes
 * must be normalized to lowercase.
 *
 * @throws Exception
 */
public void testEnsureCaseInsensitiveMimetypeStorage() throws Exception
{
    ContentData contentData = getContentData();
    ContentData cdWithUpperMimetype = ContentData.setMimetype(contentData, "TEXT/MYFORMAT");
    ContentData cdWithLowerMimetype = ContentData.setMimetype(contentData, "text/myformat");

    // In both instances, the created entry should have a lowercase mimetype
    Pair<Long, ContentData> result = create(cdWithUpperMimetype);
    // Ensure the ContentData's mimetype was stored in lowercase
    assertEquals("text/myformat", result.getSecond().getMimetype());

    result = create(cdWithLowerMimetype);
    assertEquals("text/myformat", result.getSecond().getMimetype());
}
 
Example 5
Project: alfresco-repository   File: ContentDataDAOTest.java   View Source Code Vote up 5 votes
public void testUpdate() throws Exception
{
    ContentData contentData = getContentData();
    Pair<Long, ContentData> resultPair = create(contentData);
    Long id = resultPair.getFirst();
    // Update
    contentData = ContentData.setMimetype(contentData, "TEXT/HTML"); // Note the upper case mimetype
    contentData = ContentData.setEncoding(contentData, "UTF-16");
    // Don't update the content itself
    update(id, contentData);
    // Check
    Pair<Long, ContentData> result = getAndCheck(id, contentData);
    // Check the mimetype has been lowercased
    assertEquals("text/html", result.getSecond().getMimetype());
}
 
Example 6
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 7
Project: alfresco-repository   File: ContentDiskDriver2.java   View Source Code Vote up 4 votes
@Override
public void copyContent(NodeRef rootNode, String fromPath, String toPath) throws FileNotFoundException
{
    if(logger.isDebugEnabled())
    {
        logger.debug("copyContent from:" + fromPath + " to:" + toPath);
    }
    
    NodeRef sourceNodeRef = getNodeForPath(rootNode, fromPath);
    NodeRef targetNodeRef = getNodeForPath(rootNode, toPath);
    
    Serializable prop = nodeService.getProperty(sourceNodeRef, ContentModel.PROP_CONTENT);
    if(prop != null)
    { 
        if(prop instanceof ContentData)
        {
            ContentData data = (ContentData)prop;
            if(data.getMimetype().equalsIgnoreCase(MimetypeMap.MIMETYPE_BINARY))
            {
                if(logger.isDebugEnabled())
                {
                    logger.debug("mimetype is binary - guess mimetype has failed");
                }
                Serializable targetProp = nodeService.getProperty(targetNodeRef, ContentModel.PROP_CONTENT);
                
                if(targetProp != null && targetProp instanceof ContentData)
                {
                    ContentData targetData = (ContentData)targetProp;
                    logger.debug("copy the existing mimetype");
                    prop = ContentData.setMimetype(data, targetData.getMimetype());
                }       
            }
        }
        
        nodeService.setProperty(targetNodeRef, ContentModel.PROP_CONTENT, prop);
    }
    else
    {
        logger.debug("no content to save");
        // No content to set - need to remove old content
        ContentWriter writer = contentService.getWriter(targetNodeRef, ContentModel.PROP_CONTENT, true);
        writer.putContent("");
    }
 
}
 
Example 8
Project: alfresco-repository   File: ContentDiskDriver.java   View Source Code Vote up 3 votes
/**
 * Copy content data from file to file
 * 
 * @param sess SrvSession
 * @param tree TreeConnection
 * @param fromNode NodeRef
 * @param toNode NodeRef
 * @param newName String
 */
private void copyContentData( SrvSession sess, TreeConnection tree, NodeRef fromNode, NodeRef toNode, String newName)
{
    ContentData content = (ContentData) nodeService.getProperty(fromNode, ContentModel.PROP_CONTENT);
    if ( newName != null)
        content = ContentData.setMimetype( content, mimetypeService.guessMimetype( newName));
    nodeService.setProperty(toNode, ContentModel.PROP_CONTENT, content);
}