/*
* Copyright (C) 2005 Jesper Steen Møller
*
* This file is part of Alfresco
*
* Alfresco is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Alfresco is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with Alfresco. If not, see
* Currently, the default {@linkplain MetadataExtracter.OverwritePolicy overwrite policy}
* for each extracter is used. (TODO: Add overwrite policy as a parameter.)
*
* @see MetadataExtracter.OverwritePolicy
*
* @author Jesper Steen Møller
*/
public class ContentMetadataExtracter extends ActionExecuterAbstractBase
{
private static Log logger = LogFactory.getLog(ContentMetadataExtracter.class);
private NodeService nodeService;
private ContentService contentService;
private DictionaryService dictionaryService;
private MetadataExtracterRegistry metadataExtracterRegistry;
private boolean carryAspectProperties;
public ContentMetadataExtracter()
{
carryAspectProperties = true;
}
/**
* @param nodeService the node service
*/
public void setNodeService(NodeService nodeService)
{
this.nodeService = nodeService;
}
/**
* @param contentService The contentService to set.
*/
public void setContentService(ContentService contentService)
{
this.contentService = contentService;
}
/**
* @param dictService The DictionaryService to set.
*/
public void setDictionaryService(DictionaryService dictService)
{
this.dictionaryService = dictService;
}
/**
* @param metadataExtracterRegistry The metadataExtracterRegistry to set.
*/
public void setMetadataExtracterRegistry(MetadataExtracterRegistry metadataExtracterRegistry)
{
this.metadataExtracterRegistry = metadataExtracterRegistry;
}
/**
* Whether or not aspect-related properties must be carried to the new version of the node
*
* @param carryAspectProperties true (default) to carry all aspect-linked
* properties forward. false will clean the
* aspect of any unextracted values.
*/
public void setCarryAspectProperties(boolean carryAspectProperties)
{
this.carryAspectProperties = carryAspectProperties;
}
/**
* @see org.alfresco.repo.action.executer.ActionExecuter#execute(org.alfresco.service.cmr.repository.NodeRef,
* NodeRef)
*/
public void executeImpl(Action ruleAction, NodeRef actionedUponNodeRef)
{
if (!nodeService.exists(actionedUponNodeRef))
{
// Node is gone
return;
}
ContentReader reader = contentService.getReader(actionedUponNodeRef, ContentModel.PROP_CONTENT);
// The reader may be null, e.g. for folders and the like
if (reader == null || reader.getMimetype() == null)
{
// No content to extract data from
return;
}
String mimetype = reader.getMimetype();
MetadataExtracter extracter = metadataExtracterRegistry.getExtracter(mimetype);
if (extracter == null)
{
// There is no extracter to use
return;
}
// Get all the node's properties
Map