mirror of
https://github.com/Alfresco/alfresco-community-repo.git
synced 2025-07-24 17:32:48 +00:00
Fixed NPE when extracter action hits properties not in the dictionary.
Exposed extracter OverwritePolicy, but it still defaults to the OverwritePolicy specified in the extracters configuration. git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/alfresco/HEAD/root@6013 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261
This commit is contained in:
@@ -354,8 +354,9 @@ abstract public class AbstractMappingMetadataExtracter implements MetadataExtrac
|
||||
while (tokenizer.hasMoreTokens())
|
||||
{
|
||||
String qnameStr = tokenizer.nextToken().trim();
|
||||
// Check if we need to resolve a namespace reference
|
||||
int index = qnameStr.indexOf(QName.NAMESPACE_PREFIX);
|
||||
if (index > -1)
|
||||
if (index > -1 && qnameStr.charAt(0) != QName.NAMESPACE_BEGIN)
|
||||
{
|
||||
String prefix = qnameStr.substring(0, index);
|
||||
String suffix = qnameStr.substring(index + 1);
|
||||
@@ -490,7 +491,7 @@ abstract public class AbstractMappingMetadataExtracter implements MetadataExtrac
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
public final boolean extract(ContentReader reader, Map<QName, Serializable> destination) throws ContentIOException
|
||||
public final Map<QName, Serializable> extract(ContentReader reader, Map<QName, Serializable> destination)
|
||||
{
|
||||
return extract(reader, this.overwritePolicy, destination, this.mapping);
|
||||
}
|
||||
@@ -498,11 +499,22 @@ abstract public class AbstractMappingMetadataExtracter implements MetadataExtrac
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
public final boolean extract(
|
||||
public final Map<QName, Serializable> extract(
|
||||
ContentReader reader,
|
||||
OverwritePolicy overwritePolicy,
|
||||
Map<QName, Serializable> destination)
|
||||
{
|
||||
return extract(reader, overwritePolicy, destination, this.mapping);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
public final Map<QName, Serializable> extract(
|
||||
ContentReader reader,
|
||||
OverwritePolicy overwritePolicy,
|
||||
Map<QName, Serializable> destination,
|
||||
Map<String, Set<QName>> mapping) throws ContentIOException
|
||||
Map<String, Set<QName>> mapping)
|
||||
{
|
||||
// Done
|
||||
if (logger.isDebugEnabled())
|
||||
@@ -522,14 +534,14 @@ abstract public class AbstractMappingMetadataExtracter implements MetadataExtrac
|
||||
// check the reliability
|
||||
checkIsSupported(reader);
|
||||
|
||||
boolean changed = false;
|
||||
Map<QName, Serializable> changedProperties = null;
|
||||
try
|
||||
{
|
||||
Map<String, Serializable> rawMetadata = extractRaw(reader);
|
||||
// Convert to system properties (standalone)
|
||||
Map<QName, Serializable> systemProperties = mapRawToSystem(rawMetadata);
|
||||
// Now use the proper overwrite policy
|
||||
changed = overwritePolicy.applyProperties(systemProperties, destination);
|
||||
changedProperties = overwritePolicy.applyProperties(systemProperties, destination);
|
||||
}
|
||||
catch (Throwable e)
|
||||
{
|
||||
@@ -539,8 +551,8 @@ abstract public class AbstractMappingMetadataExtracter implements MetadataExtrac
|
||||
}
|
||||
finally
|
||||
{
|
||||
// check that the reader was closed
|
||||
if (!reader.isClosed())
|
||||
// check that the reader was closed (if used)
|
||||
if (reader.isChannelOpen())
|
||||
{
|
||||
logger.error("Content reader not closed by metadata extracter: \n" +
|
||||
" reader: " + reader + "\n" +
|
||||
@@ -554,9 +566,9 @@ abstract public class AbstractMappingMetadataExtracter implements MetadataExtrac
|
||||
logger.debug("Completed metadata extraction: \n" +
|
||||
" reader: " + reader + "\n" +
|
||||
" extracter: " + this + "\n" +
|
||||
" changed: " + changed);
|
||||
" changed: " + changedProperties);
|
||||
}
|
||||
return changed;
|
||||
return changedProperties;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@@ -26,6 +26,7 @@ package org.alfresco.repo.content.metadata;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.Collections;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
@@ -43,6 +44,7 @@ import org.apache.commons.logging.LogFactory;
|
||||
* @deprecated Use the {@link org.alfresco.repo.content.metadata.AbstractMappingMetadataExtracter}
|
||||
*
|
||||
* @author Jesper Steen Møller
|
||||
* @author Derek Hulley
|
||||
*/
|
||||
abstract public class AbstractMetadataExtracter implements MetadataExtracter
|
||||
{
|
||||
@@ -164,15 +166,43 @@ abstract public class AbstractMetadataExtracter implements MetadataExtracter
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
* <p>
|
||||
* A {@linkplain OverwritePolicy#PRAGMATIC pragmatic} overwrite policy will be applied.
|
||||
*/
|
||||
public boolean extract(ContentReader reader, Map<QName, Serializable> destination) throws ContentIOException
|
||||
public Map<QName, Serializable> extract(ContentReader reader, Map<QName, Serializable> destination)
|
||||
{
|
||||
return extract(reader, OverwritePolicy.PRAGMATIC, destination);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*
|
||||
* @param propertyMapping ignored
|
||||
*
|
||||
* @see #extract(ContentReader, Map)
|
||||
*/
|
||||
public final Map<QName, Serializable> extract(
|
||||
ContentReader reader,
|
||||
OverwritePolicy overwritePolicy,
|
||||
Map<QName, Serializable> destination) throws ContentIOException
|
||||
{
|
||||
// check the reliability
|
||||
checkReliability(reader);
|
||||
|
||||
Map<QName, Serializable> newProperties = new HashMap<QName, Serializable>(13);
|
||||
try
|
||||
{
|
||||
extractInternal(reader, destination);
|
||||
extractInternal(reader, newProperties);
|
||||
// Apply the overwrite policy
|
||||
Map<QName, Serializable> modifiedProperties = overwritePolicy.applyProperties(newProperties, destination);
|
||||
// done
|
||||
if (logger.isDebugEnabled())
|
||||
{
|
||||
logger.debug("Completed metadata extraction: \n" +
|
||||
" reader: " + reader + "\n" +
|
||||
" extracter: " + this);
|
||||
}
|
||||
return modifiedProperties;
|
||||
}
|
||||
catch (Throwable e)
|
||||
{
|
||||
@@ -182,23 +212,14 @@ abstract public class AbstractMetadataExtracter implements MetadataExtracter
|
||||
}
|
||||
finally
|
||||
{
|
||||
// check that the reader was closed
|
||||
if (!reader.isClosed())
|
||||
// check that the reader was closed (if used)
|
||||
if (reader.isChannelOpen())
|
||||
{
|
||||
logger.error("Content reader not closed by metadata extracter: \n" +
|
||||
" reader: " + reader + "\n" +
|
||||
" extracter: " + this);
|
||||
}
|
||||
}
|
||||
|
||||
// done
|
||||
if (logger.isDebugEnabled())
|
||||
{
|
||||
logger.debug("Completed metadata extraction: \n" +
|
||||
" reader: " + reader + "\n" +
|
||||
" extracter: " + this);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -209,7 +230,7 @@ abstract public class AbstractMetadataExtracter implements MetadataExtracter
|
||||
*
|
||||
* @see #extract(ContentReader, Map)
|
||||
*/
|
||||
public final boolean extract(
|
||||
public final Map<QName, Serializable> extract(
|
||||
ContentReader reader,
|
||||
OverwritePolicy overwritePolicy,
|
||||
Map<QName, Serializable> destination,
|
||||
|
@@ -25,6 +25,7 @@
|
||||
package org.alfresco.repo.content.metadata;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
@@ -61,9 +62,9 @@ public interface MetadataExtracter extends ContentWorker
|
||||
EAGER
|
||||
{
|
||||
@Override
|
||||
public boolean applyProperties(Map<QName, Serializable> extractedProperties, Map<QName, Serializable> targetProperties)
|
||||
public Map<QName, Serializable> applyProperties(Map<QName, Serializable> extractedProperties, Map<QName, Serializable> targetProperties)
|
||||
{
|
||||
boolean modified = false;
|
||||
Map<QName, Serializable> modifiedProperties = new HashMap<QName, Serializable>(7);
|
||||
for (Map.Entry<QName, Serializable> entry : extractedProperties.entrySet())
|
||||
{
|
||||
QName propertyQName = entry.getKey();
|
||||
@@ -74,9 +75,9 @@ public interface MetadataExtracter extends ContentWorker
|
||||
continue;
|
||||
}
|
||||
targetProperties.put(propertyQName, extractedValue);
|
||||
modified = true;
|
||||
modifiedProperties.put(propertyQName, extractedValue);
|
||||
}
|
||||
return modified;
|
||||
return modifiedProperties;
|
||||
}
|
||||
},
|
||||
/**
|
||||
@@ -91,12 +92,12 @@ public interface MetadataExtracter extends ContentWorker
|
||||
PRAGMATIC
|
||||
{
|
||||
@Override
|
||||
public boolean applyProperties(Map<QName, Serializable> extractedProperties, Map<QName, Serializable> targetProperties)
|
||||
public Map<QName, Serializable> applyProperties(Map<QName, Serializable> extractedProperties, Map<QName, Serializable> targetProperties)
|
||||
{
|
||||
/*
|
||||
* Negative and positive checks are mixed in the loop.
|
||||
*/
|
||||
boolean modified = false;
|
||||
Map<QName, Serializable> modifiedProperties = new HashMap<QName, Serializable>(7);
|
||||
for (Map.Entry<QName, Serializable> entry : extractedProperties.entrySet())
|
||||
{
|
||||
QName propertyQName = entry.getKey();
|
||||
@@ -111,7 +112,7 @@ public interface MetadataExtracter extends ContentWorker
|
||||
{
|
||||
// There is nothing currently
|
||||
targetProperties.put(propertyQName, extractedValue);
|
||||
modified = true;
|
||||
modifiedProperties.put(propertyQName, extractedValue);
|
||||
continue;
|
||||
}
|
||||
Serializable originalValue = targetProperties.get(propertyQName);
|
||||
@@ -119,7 +120,7 @@ public interface MetadataExtracter extends ContentWorker
|
||||
{
|
||||
// The current value is null
|
||||
targetProperties.put(propertyQName, extractedValue);
|
||||
modified = true;
|
||||
modifiedProperties.put(propertyQName, extractedValue);
|
||||
continue;
|
||||
}
|
||||
// Check the string representation
|
||||
@@ -135,13 +136,13 @@ public interface MetadataExtracter extends ContentWorker
|
||||
{
|
||||
// The original string is trivial
|
||||
targetProperties.put(propertyQName, extractedValue);
|
||||
modified = true;
|
||||
modifiedProperties.put(propertyQName, extractedValue);
|
||||
continue;
|
||||
}
|
||||
}
|
||||
// We have some other object as the original value, so keep it
|
||||
}
|
||||
return modified;
|
||||
return modifiedProperties;
|
||||
}
|
||||
},
|
||||
/**
|
||||
@@ -157,9 +158,9 @@ public interface MetadataExtracter extends ContentWorker
|
||||
CAUTIOUS
|
||||
{
|
||||
@Override
|
||||
public boolean applyProperties(Map<QName, Serializable> extractedProperties, Map<QName, Serializable> targetProperties)
|
||||
public Map<QName, Serializable> applyProperties(Map<QName, Serializable> extractedProperties, Map<QName, Serializable> targetProperties)
|
||||
{
|
||||
boolean modified = false;
|
||||
Map<QName, Serializable> modifiedProperties = new HashMap<QName, Serializable>(7);
|
||||
for (Map.Entry<QName, Serializable> entry : extractedProperties.entrySet())
|
||||
{
|
||||
QName propertyQName = entry.getKey();
|
||||
@@ -176,18 +177,20 @@ public interface MetadataExtracter extends ContentWorker
|
||||
continue;
|
||||
}
|
||||
targetProperties.put(propertyQName, extractedValue);
|
||||
modified = true;
|
||||
modifiedProperties.put(propertyQName, extractedValue);
|
||||
}
|
||||
return modified;
|
||||
return modifiedProperties;
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* Apply the overwrite policy for the extracted properties.
|
||||
*
|
||||
* @return Returns true if <i>any</i> properties were set on the target properties
|
||||
* @return
|
||||
* Returns a map of all properties that were applied to the target map. If the result is
|
||||
* an empty map, then the target map remains unchanged.
|
||||
*/
|
||||
public boolean applyProperties(Map<QName, Serializable> extractedProperties, Map<QName, Serializable> targetProperties)
|
||||
public Map<QName, Serializable> applyProperties(Map<QName, Serializable> extractedProperties, Map<QName, Serializable> targetProperties)
|
||||
{
|
||||
throw new UnsupportedOperationException("Override this method");
|
||||
}
|
||||
@@ -235,12 +238,40 @@ public interface MetadataExtracter extends ContentWorker
|
||||
*
|
||||
* @param reader the source of the content
|
||||
* @param destination the map of properties to populate (essentially a return value)
|
||||
* @return Returns <tt>true</tt> if the destination map was modified
|
||||
* @return Returns a map of all properties on the destination map that were
|
||||
* added or modified. If the return map is empty, then no properties
|
||||
* were modified.
|
||||
* @throws ContentIOException if a detectable error occurs
|
||||
*
|
||||
* @see #extract(ContentReader, OverwritePolicy, Map, Map)
|
||||
*/
|
||||
public boolean extract(ContentReader reader, Map<QName, Serializable> destination) throws ContentIOException;
|
||||
public Map<QName, Serializable> extract(ContentReader reader, Map<QName, Serializable> destination);
|
||||
|
||||
/**
|
||||
* Extracts the metadata values from the content provided by the reader and source
|
||||
* mimetype to the supplied map.
|
||||
* <p>
|
||||
* The extraction viability can be determined by an up front call to {@link #isSupported(String)}.
|
||||
* <p>
|
||||
* The source mimetype <b>must</b> be available on the
|
||||
* {@link org.alfresco.service.cmr.repository.ContentAccessor#getMimetype()} method
|
||||
* of the reader.
|
||||
*
|
||||
* @param reader the source of the content
|
||||
* @param overwritePolicy the policy stipulating how the system properties must be
|
||||
* overwritten if present
|
||||
* @param destination the map of properties to populate (essentially a return value)
|
||||
* @return Returns a map of all properties on the destination map that were
|
||||
* added or modified. If the return map is empty, then no properties
|
||||
* were modified.
|
||||
* @throws ContentIOException if a detectable error occurs
|
||||
*
|
||||
* @see #extract(ContentReader, OverwritePolicy, Map, Map)
|
||||
*/
|
||||
public Map<QName, Serializable> extract(
|
||||
ContentReader reader,
|
||||
OverwritePolicy overwritePolicy,
|
||||
Map<QName, Serializable> destination);
|
||||
|
||||
/**
|
||||
* Extracts the metadata from the content provided by the reader and source
|
||||
@@ -260,14 +291,16 @@ public interface MetadataExtracter extends ContentWorker
|
||||
* overwritten if present
|
||||
* @param destination the map of properties to populate (essentially a return value)
|
||||
* @param mapping a mapping of document-specific properties to system properties.
|
||||
* @return Returns <tt>true</tt> if the destination map was modified
|
||||
* @return Returns a map of all properties on the destination map that were
|
||||
* added or modified. If the return map is empty, then no properties
|
||||
* were modified.
|
||||
* @throws ContentIOException if a detectable error occurs
|
||||
*
|
||||
* @see #extract(ContentReader, Map)
|
||||
*/
|
||||
public boolean extract(
|
||||
public Map<QName, Serializable> extract(
|
||||
ContentReader reader,
|
||||
OverwritePolicy overwritePolicy,
|
||||
Map<QName, Serializable> destination,
|
||||
Map<String, Set<QName>> mapping) throws ContentIOException;
|
||||
Map<String, Set<QName>> mapping);
|
||||
}
|
||||
|
Reference in New Issue
Block a user