Search in sources :

Example 1 with MetadataExtracter

use of org.alfresco.repo.content.metadata.MetadataExtracter in project acs-community-packaging by Alfresco.

the class Repository method extractMetadata.

/**
 * Extracts the metadata of a "raw" piece of content into a map.
 *
 * @param context Faces Context
 * @param reader Content reader for the source content to extract from
 * @param destination Map of metadata to set metadata values into
 * @return True if an extracter was found
 */
public static boolean extractMetadata(FacesContext context, ContentReader reader, Map<QName, Serializable> destination) {
    // check that source mimetype is available
    String mimetype = reader.getMimetype();
    if (mimetype == null) {
        throw new AlfrescoRuntimeException("The content reader mimetype must be set: " + reader);
    }
    // look for a transformer
    MetadataExtracter extracter = getMetadataExtracterRegistry(context).getExtracter(mimetype);
    if (extracter == null) {
        // No metadata extracter is not a failure, but we flag it
        return false;
    }
    try {
        // we have a transformer, so do it
        extracter.extract(reader, destination);
        return true;
    } catch (Throwable e) {
        // it failed
        logger.warn("Metadata extraction failed: \n" + "   reader: " + reader + "\n" + "   extracter: " + extracter);
        return false;
    }
}
Also used : MetadataExtracter(org.alfresco.repo.content.metadata.MetadataExtracter) AlfrescoRuntimeException(org.alfresco.error.AlfrescoRuntimeException)

Example 2 with MetadataExtracter

use of org.alfresco.repo.content.metadata.MetadataExtracter in project alfresco-remote-api by Alfresco.

the class MimetypesGet method getExtractors.

protected List<String> getExtractors(String mimetype) {
    List<String> exts = new ArrayList<String>();
    MetadataExtracter extractor = metadataExtracterRegistry.getExtracter(mimetype);
    if (extractor != null) {
        exts.add(extractor.getClass().getName());
    }
    return exts;
}
Also used : MetadataExtracter(org.alfresco.repo.content.metadata.MetadataExtracter) ArrayList(java.util.ArrayList)

Aggregations

MetadataExtracter (org.alfresco.repo.content.metadata.MetadataExtracter)2 ArrayList (java.util.ArrayList)1 AlfrescoRuntimeException (org.alfresco.error.AlfrescoRuntimeException)1