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

The following examples show how to use org.alfresco.service.cmr.repository.ContentData#hasContent() . 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 6 votes vote down vote up
/**
 * 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
Source File: EventGenerationBehaviours.java    From alfresco-repository with GNU Lesser General Public License v3.0 6 votes vote down vote up
@Override
public void onContentPropertyUpdate(NodeRef nodeRef, QName propertyQName, ContentData beforeValue, ContentData afterValue)
{
    boolean hasContentBefore = ContentData.hasContent(beforeValue) && beforeValue.getSize() > 0;
    boolean hasContentAfter = ContentData.hasContent(afterValue) && afterValue.getSize() > 0;
    
    // There are some shortcuts here
    if (!hasContentBefore && !hasContentAfter)
    {
        // Really, nothing happened
        return;
    }
    else if (EqualsHelper.nullSafeEquals(beforeValue, afterValue))
    {
        // Still, nothing happening
        return;
    }

    eventsService.contentWrite(nodeRef, propertyQName, afterValue);
}
 
Example 3
Source File: ScriptNode.java    From alfresco-repository with GNU Lesser General Public License v3.0 5 votes vote down vote up
/**
 * Constructor
 * 
 * @param contentData      The ContentData object this object wraps
 * @param property         The property the ContentData is attached too
 */
public ScriptContentData(ContentData contentData, QName property)
{
    this.contentData = contentData;
    this.property = property;
    this.isDirty = ContentData.hasContent(contentData);
}
 
Example 4
Source File: RenditionsImpl.java    From alfresco-remote-api with GNU Lesser General Public License v3.0 5 votes vote down vote up
private ContentData getContentData(NodeRef nodeRef, boolean validate)
{
    ContentData contentData = (ContentData) nodeService.getProperty(nodeRef, ContentModel.PROP_CONTENT);
    if (validate && !ContentData.hasContent(contentData))
    {
        throw new InvalidArgumentException("Node id '" + nodeRef.getId() + "' has no content.");
    }
    return contentData;
}
 
Example 5
Source File: OnPropertyUpdateRuleTrigger.java    From alfresco-repository with GNU Lesser General Public License v3.0 4 votes vote down vote up
private boolean havePropertiesBeenModified(NodeRef nodeRef, Map<QName, Serializable> before, Map<QName, Serializable> after, boolean newNode, boolean newContentOnly)
{
    if (newContentOnly && nodeService.hasAspect(nodeRef, ContentModel.ASPECT_NO_CONTENT))
    {
        return false;
    }        

    Set<QName> keys = new HashSet<QName>(after.keySet());
    keys.addAll(before.keySet());

    // Compare all properties, ignoring protected properties and giving special treatment to content properties
    boolean nonNullContentProperties = false;
    boolean newContentProperties = false;
    boolean nonNewModifiedContentProperties = false;
    boolean modifiedNonContentProperties = false;
    for (QName name : keys)
    {
        // Skip rule firing on this content property for performance reasons
        if (name.equals(ContentModel.PROP_PREFERENCE_VALUES))
        {
            continue;
        }
        Serializable beforeValue = before.get(name);
        Serializable afterValue = after.get(name);
        PropertyDefinition propertyDefinition = this.dictionaryService.getProperty(name);
        if (propertyDefinition == null)
        {
            if (!EqualsHelper.nullSafeEquals(beforeValue, afterValue))
            {
                modifiedNonContentProperties = true;
            }
        }
        // Ignore protected properties
        else if (!propertyDefinition.isProtected())
        {
            if (propertyDefinition.getDataType().getName().equals(DataTypeDefinition.CONTENT)
                    && !propertyDefinition.isMultiValued())
            {
                // Remember whether the property was populated, regardless of the ignore setting
                if (afterValue != null)
                {
                    nonNullContentProperties = true;
                }                    
                if (this.ignoreEmptyContent)
                {
                    ContentData beforeContent = toContentData(before.get(name));
                    ContentData afterContent = toContentData(after.get(name));
                    if (!ContentData.hasContent(beforeContent) || beforeContent.getSize() == 0)
                    {
                        beforeValue = null;
                    }
                    if (!ContentData.hasContent(afterContent) || afterContent.getSize() == 0)
                    {
                        afterValue = null;
                    }
                }
                if (newNode)
                {
                    if (afterValue != null)
                    {
                        newContentProperties = true;
                    }
                }
                else if (!EqualsHelper.nullSafeEquals(beforeValue, afterValue))
                {
                    if (beforeValue == null)
                    {
                        newContentProperties = true;                            
                    }
                    else
                    {
                        nonNewModifiedContentProperties = true;                            
                    }
                }
            }
            else if (!EqualsHelper.nullSafeEquals(beforeValue, afterValue))
            {
                modifiedNonContentProperties = true;
            }
        }
    }

    if (newContentOnly)
    {
        return (newNode && !nonNullContentProperties ) || newContentProperties;
    }
    else
    {
        return modifiedNonContentProperties || nonNewModifiedContentProperties;
    }
}