private static final Log LOG = ExoLogger.getLogger("exo.jcr.component.ext.AddMetadataAction");
public boolean execute(Context ctx) throws Exception
{
PropertyImpl property = (PropertyImpl)ctx.get("currentItem");
NodeImpl parent = property.getParent();
if (!parent.isNodeType("nt:resource"))
{
throw new Exception("incoming node is not nt:resource type");
}
InputStream data = null;
String mimeType;
try
{
if (property.getInternalName().equals(Constants.JCR_DATA))
{
data = ((PropertyData)property.getData()).getValues().get(0).getAsStream();
try
{
mimeType = parent.getProperty("jcr:mimeType").getString();
}
catch (PathNotFoundException e)
{
return false;
}
}
else if (property.getInternalName().equals(Constants.JCR_MIMETYPE))
{
int evt = (Integer)ctx.get(InvocationContext.EVENT);
if (evt != ExtendedEvent.PROPERTY_ADDED)
{
// In case the mime type is modified we assume that the property jcr:data is modified too so to
// prevent issue like JCR-1873 we do the data extraction only on jcr:data change
return false;
}
mimeType = property.getString();
try
{
PropertyImpl propertyImpl = (PropertyImpl)parent.getProperty("jcr:data");
data = ((PropertyData)propertyImpl.getData()).getValues().get(0).getAsStream();
}
catch (PathNotFoundException e)
{
return false;
}