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

The following examples show how to use org.alfresco.service.cmr.repository.ContentData#setMimetype() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: ScriptNode.java    From alfresco-repository with GNU Lesser General Public License v3.0 5 votes vote down vote up
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
Source File: AbstractContentDataDAOImpl.java    From alfresco-repository with GNU Lesser General Public License v3.0 5 votes vote down vote up
private ContentData sanitizeMimetype(ContentData contentData)
{
    String mimetype = contentData.getMimetype();
    if (mimetype != null)
    {
        mimetype = mimetype.toLowerCase();
        contentData = ContentData.setMimetype(contentData, mimetype);
    }
    return contentData;
}
 
Example 3
Source File: ContentDataDAOTest.java    From alfresco-repository with GNU Lesser General Public License v3.0 5 votes vote down vote up
/**
 * 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 4
Source File: ContentDataDAOTest.java    From alfresco-repository with GNU Lesser General Public License v3.0 5 votes vote down vote up
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 5
Source File: ContentDiskDriver.java    From alfresco-repository with GNU Lesser General Public License v3.0 4 votes vote down vote up
/**
 * 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 6
Source File: ContentDiskDriver2.java    From alfresco-repository with GNU Lesser General Public License v3.0 4 votes vote down vote up
@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 7
Source File: ContentDiskDriver.java    From alfresco-repository with GNU Lesser General Public License v3.0 3 votes vote down vote up
/**
 * 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);
}