supportedMimetypes, double reliability, long extractionTime)
- {
- this.supportedMimetypes = supportedMimetypes;
- this.reliability = reliability;
- this.extractionTime = extractionTime;
- }
-
- /**
- * Set the registry to register with
- *
- * @param registry a metadata extracter registry
- */
- public void setRegistry(MetadataExtracterRegistry registry)
- {
- this.registry = registry;
- }
-
- /**
- * Helper setter of the mimetype service. This is not always required.
- *
- * @param mimetypeService MimetypeService
- */
- public void setMimetypeService(MimetypeService mimetypeService)
- {
- this.mimetypeService = mimetypeService;
- }
-
- @Override
- public void setBeanName(String beanName)
- {
- this.beanName = beanName;
- }
-
- public String getBeanName()
- {
- return beanName;
- }
-
- /**
- * The Alfresco global properties.
- */
- public void setProperties(Properties properties)
- {
- this.properties = properties;
- }
-
- /**
- * The metadata extracter config.
- */
- public void setMetadataExtracterConfig(MetadataExtracterConfig metadataExtracterConfig)
- {
- this.metadataExtracterConfig = metadataExtracterConfig;
- }
-
- /**
- * @return Returns the mimetype helper
- */
- protected MimetypeService getMimetypeService()
- {
- return mimetypeService;
- }
-
- /**
- * Registers this instance of the extracter with the registry.
- *
- * @see #setRegistry(MetadataExtracterRegistry)
- */
- public void register()
- {
- if (registry == null)
- {
- logger.warn("Property 'registry' has not been set. Ignoring auto-registration: \n" +
- " extracter: " + this);
- return;
- }
- registry.register(this);
- }
-
- /**
- * Default reliability check that returns the reliability as configured by the contstructor
- * if the mimetype is in the list of supported mimetypes.
- *
- * @param mimetype the mimetype to check
- */
- public double getReliability(String mimetype)
- {
- if (supportedMimetypes.contains(mimetype))
- return reliability;
- else
- return 0.0;
- }
-
- /**
- * {@inheritDoc}
- *
- * @return Returns true if the {@link #getReliability(String) reliability}
- * is greater than 0
- */
- public boolean isSupported(String mimetype)
- {
- double reliability = getReliability(mimetype);
- return reliability > 0.0 && isEnabled(mimetype);
- }
-
- private boolean isEnabled(String mimetype)
- {
- return properties == null || mimetypeService == null ||
- (getBooleanProperty(beanName+".enabled", true) &&
- getBooleanProperty(beanName+'.'+mimetypeService.getExtension(mimetype)+".enabled", true));
- }
-
- private boolean getBooleanProperty(String name, boolean defaultValue)
- {
- boolean value = defaultValue;
- if (properties != null)
- {
- String property = properties.getProperty(name);
- if (property != null)
- {
- value = property.trim().equalsIgnoreCase("true");
- }
- }
- return value;
- }
-
- public long getExtractionTime()
- {
- return extractionTime;
- }
-
- /**
- * Checks if the mimetype is supported.
- *
- * @param reader the reader to check
- * @throws AlfrescoRuntimeException if the mimetype is not supported
- */
- protected void checkReliability(ContentReader reader)
- {
- String mimetype = reader.getMimetype();
- if (getReliability(mimetype) <= 0.0)
- {
- throw new AlfrescoRuntimeException(
- "Metadata extracter does not support mimetype: \n" +
- " reader: " + reader + "\n" +
- " supported: " + supportedMimetypes + "\n" +
- " extracter: " + this);
- }
- }
-
- /**
- * {@inheritDoc}
- *
- * A {@code OverwritePolicy.PRAGMATIC} will be applied.
- */
- public Map extract(ContentReader reader, Map destination)
- {
- return extract(reader, OverwritePolicy.PRAGMATIC, destination);
- }
-
- /**
- * {@inheritDoc}
- *
- * @param reader
- * @param overwritePolicy
- * @param destination
- *
- * @see #extract(ContentReader, Map)
- */
- public final Map extract(
- ContentReader reader,
- OverwritePolicy overwritePolicy,
- Map destination) throws ContentIOException
- {
- // check the reliability
- checkReliability(reader);
-
- Map newProperties = new HashMap(13);
- try
- {
- extractInternal(reader, newProperties);
- // Apply the overwrite policy
- Map 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)
- {
- throw new ContentIOException("Metadata extraction failed: \n" +
- " reader: " + reader,
- e);
- }
- finally
- {
- // 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);
- }
- }
- }
-
- /**
- * {@inheritDoc}
- *
- * @param overwritePolicy ignored
- * @param propertyMapping ignored
- *
- * @see #extract(ContentReader, Map)
- */
- public final Map extract(
- ContentReader reader,
- OverwritePolicy overwritePolicy,
- Map destination,
- Map> propertyMapping) throws ContentIOException
- {
- return extract(reader, destination);
- }
-
- /**
- * Override to provide the necessary extraction logic. Implementations must ensure that the reader
- * is closed before the method exits.
- *
- * @param reader the source of the content
- * @param destination the property map to fill
- * @throws Throwable an exception
- *
- * @deprecated Consider deriving from the more configurable {@link AbstractMappingMetadataExtracter}
- */
- protected abstract void extractInternal(ContentReader reader, Map destination) throws Throwable;
-
- /**
- * Examines a value or string for nulls and adds it to the map (if non-empty)
- *
- * @param prop Alfresco's ContentModel.PROP_
to set.
- * @param value Value to set it to
- * @param destination Map into which to set it
- * @return true, if set, false otherwise
- */
- protected boolean trimPut(QName prop, Object value, Map destination)
- {
- if (value == null)
- return false;
- if (value instanceof String)
- {
- String svalue = ((String) value).trim();
- if (svalue.length() > 0)
- {
- destination.put(prop, svalue);
- return true;
- }
- return false;
- }
- else if (value instanceof Serializable)
- {
- destination.put(prop, (Serializable) value);
- }
- else
- {
- destination.put(prop, value.toString());
- }
- return true;
- }
-}
diff --git a/source/java/org/alfresco/repo/content/metadata/MetadataExtracter.java b/source/java/org/alfresco/repo/content/metadata/MetadataExtracter.java
index d7bfc5d10c..051184fd10 100644
--- a/source/java/org/alfresco/repo/content/metadata/MetadataExtracter.java
+++ b/source/java/org/alfresco/repo/content/metadata/MetadataExtracter.java
@@ -316,16 +316,6 @@ public interface MetadataExtracter extends ContentWorker
}
};
- /**
- * Get an estimate of the extracter's reliability on a scale from 0.0 to 1.0.
- *
- * @param mimetype the mimetype to check
- * @return Returns a reliability indicator from 0.0 to 1.0
- *
- * @deprecated This method is replaced by {@link #isSupported(String)}
- */
- public double getReliability(String mimetype);
-
/**
* Determines if the extracter works against the given mimetype.
*
@@ -334,19 +324,6 @@ public interface MetadataExtracter extends ContentWorker
*/
public boolean isSupported(String mimetype);
- /**
- * Provides an estimate, usually a worst case guess, of how long an
- * extraction will take.
- *
- * This method is used to determine, up front, which of a set of equally
- * reliant transformers will be used for a specific extraction.
- *
- * @return Returns the approximate number of milliseconds per transformation
- *
- * @deprecated Generally not useful or used. Extraction is normally specifically configured.
- */
- public long getExtractionTime();
-
/**
* Extracts the metadata values from the content provided by the reader and source
* mimetype to the supplied map. The internal mapping and {@link OverwritePolicy overwrite policy}
diff --git a/source/java/org/alfresco/repo/content/metadata/MetadataExtracterRegistry.java b/source/java/org/alfresco/repo/content/metadata/MetadataExtracterRegistry.java
index f607ddd226..945cd49781 100644
--- a/source/java/org/alfresco/repo/content/metadata/MetadataExtracterRegistry.java
+++ b/source/java/org/alfresco/repo/content/metadata/MetadataExtracterRegistry.java
@@ -201,16 +201,20 @@ public class MetadataExtracterRegistry
return liveExtractor;
}
- @SuppressWarnings("deprecation")
private String getName(MetadataExtracter extractor)
- {
- return extractor == null
- ? null
- : extractor instanceof AbstractMetadataExtracter
- ? ((AbstractMetadataExtracter)extractor).getBeanName()
- : extractor instanceof AbstractMappingMetadataExtracter
- ? ((AbstractMappingMetadataExtracter)extractor).getBeanName()
- : extractor.getClass().getSimpleName();
+ {
+ if (extractor == null)
+ {
+ return null;
+ }
+ else if (extractor instanceof AbstractMappingMetadataExtracter)
+ {
+ return ((AbstractMappingMetadataExtracter)extractor).getBeanName();
+ }
+ else
+ {
+ return extractor.getClass().getSimpleName();
+ }
}
/**
@@ -218,8 +222,11 @@ public class MetadataExtracterRegistry
* @return Returns a set of extractors that will work for the given mimetype
*/
private List findBestExtracters(String sourceMimetype)
- {
- logger.debug("Finding extractors for " + sourceMimetype);
+ {
+ if (logger.isDebugEnabled())
+ {
+ logger.debug("Finding extractors for " + sourceMimetype);
+ }
List extractors = new ArrayList(1);
@@ -227,14 +234,23 @@ public class MetadataExtracterRegistry
{
if (!extractor.isSupported(sourceMimetype))
{
- // extraction not achievable
- logger.debug("Find unsupported: "+getName(extractor));
+ // extraction not achievable
+ if (logger.isDebugEnabled())
+ {
+ logger.debug("Find unsupported: "+getName(extractor));
+ }
continue;
+ }
+ if (logger.isDebugEnabled())
+ {
+ logger.debug("Find supported: "+getName(extractor));
}
- logger.debug("Find supported: "+getName(extractor));
extractors.add(extractor);
+ }
+ if (logger.isDebugEnabled())
+ {
+ logger.debug("Find returning: "+extractors);
}
- logger.debug("Find returning: "+extractors);
return extractors;
}
diff --git a/source/test-java/org/alfresco/repo/content/metadata/OpenOfficeMetadataExtracterTest.java b/source/test-java/org/alfresco/repo/content/metadata/OpenOfficeMetadataExtracterTest.java
index 2defd5d613..c96ebcab98 100644
--- a/source/test-java/org/alfresco/repo/content/metadata/OpenOfficeMetadataExtracterTest.java
+++ b/source/test-java/org/alfresco/repo/content/metadata/OpenOfficeMetadataExtracterTest.java
@@ -94,8 +94,7 @@ public class OpenOfficeMetadataExtracterTest extends AbstractMetadataExtracterTe
for (String mimetype : OpenOfficeMetadataExtracter.SUPPORTED_MIMETYPES)
{
- double reliability = extracter.getReliability(mimetype);
- assertTrue("Expected above zero reliability", reliability > 0.0);
+ assertTrue("Expected above zero reliability", extracter.isSupported(mimetype));
}
}