mirror of
https://github.com/Alfresco/alfresco-community-repo.git
synced 2025-07-31 17:39:05 +00:00
ALF-11650 Upgrade Tika for TIKA-789 (MPP Detection), and add tests that show it is now being correctly handled
git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/alfresco/HEAD/root@32320 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261
This commit is contained in:
@@ -61,7 +61,6 @@ public class TikaAutoMetadataExtracter extends TikaPoweredMetadataExtracter
|
|||||||
parser = new AutoDetectParser(config);
|
parser = new AutoDetectParser(config);
|
||||||
|
|
||||||
SUPPORTED_MIMETYPES = new ArrayList<String>();
|
SUPPORTED_MIMETYPES = new ArrayList<String>();
|
||||||
parser = new AutoDetectParser();
|
|
||||||
for(MediaType mt : parser.getParsers().keySet())
|
for(MediaType mt : parser.getParsers().keySet())
|
||||||
{
|
{
|
||||||
// Add the canonical mime type
|
// Add the canonical mime type
|
||||||
|
@@ -18,9 +18,7 @@
|
|||||||
*/
|
*/
|
||||||
package org.alfresco.repo.content.metadata;
|
package org.alfresco.repo.content.metadata;
|
||||||
|
|
||||||
import java.io.BufferedInputStream;
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.io.FileInputStream;
|
|
||||||
import java.io.Serializable;
|
import java.io.Serializable;
|
||||||
import java.net.URL;
|
import java.net.URL;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
@@ -36,7 +34,10 @@ import org.alfresco.service.cmr.repository.ContentReader;
|
|||||||
import org.alfresco.service.cmr.repository.datatype.DefaultTypeConverter;
|
import org.alfresco.service.cmr.repository.datatype.DefaultTypeConverter;
|
||||||
import org.alfresco.service.namespace.NamespaceService;
|
import org.alfresco.service.namespace.NamespaceService;
|
||||||
import org.alfresco.service.namespace.QName;
|
import org.alfresco.service.namespace.QName;
|
||||||
|
import org.apache.commons.logging.Log;
|
||||||
|
import org.apache.commons.logging.LogFactory;
|
||||||
import org.apache.tika.config.TikaConfig;
|
import org.apache.tika.config.TikaConfig;
|
||||||
|
import org.apache.tika.io.TikaInputStream;
|
||||||
import org.apache.tika.metadata.Metadata;
|
import org.apache.tika.metadata.Metadata;
|
||||||
import org.apache.tika.mime.MediaType;
|
import org.apache.tika.mime.MediaType;
|
||||||
import org.apache.tika.parser.AutoDetectParser;
|
import org.apache.tika.parser.AutoDetectParser;
|
||||||
@@ -55,6 +56,8 @@ import org.apache.tika.parser.odf.OpenDocumentParser;
|
|||||||
*/
|
*/
|
||||||
public class TikaAutoMetadataExtracterTest extends AbstractMetadataExtracterTest
|
public class TikaAutoMetadataExtracterTest extends AbstractMetadataExtracterTest
|
||||||
{
|
{
|
||||||
|
private static Log logger = LogFactory.getLog(TikaAutoMetadataExtracterTest.class);
|
||||||
|
|
||||||
private TikaAutoMetadataExtracter extracter;
|
private TikaAutoMetadataExtracter extracter;
|
||||||
private static final QName TIKA_MIMETYPE_TEST_PROPERTY =
|
private static final QName TIKA_MIMETYPE_TEST_PROPERTY =
|
||||||
QName.createQName("TikaMimeTypeTestProp");
|
QName.createQName("TikaMimeTypeTestProp");
|
||||||
@@ -121,12 +124,14 @@ public class TikaAutoMetadataExtracterTest extends AbstractMetadataExtracterTest
|
|||||||
String[] testFiles = new String[] {
|
String[] testFiles = new String[] {
|
||||||
".doc", ".docx", ".xls", ".xlsx",
|
".doc", ".docx", ".xls", ".xlsx",
|
||||||
".ppt", ".pptx",
|
".ppt", ".pptx",
|
||||||
//".vsd", // Not auto-detected properly yet
|
//".vsd", // Our sample file lacks suitable metadata
|
||||||
//"2010.dwg", // Not auto-detected properly yet
|
"2010.dwg",
|
||||||
|
"2003.mpp", "2007.mpp",
|
||||||
".pdf",
|
".pdf",
|
||||||
".odt",
|
".odt",
|
||||||
};
|
};
|
||||||
|
|
||||||
|
AutoDetectParser ap = new AutoDetectParser();
|
||||||
for (String fileBase : testFiles)
|
for (String fileBase : testFiles)
|
||||||
{
|
{
|
||||||
String filename = "quick" + fileBase;
|
String filename = "quick" + fileBase;
|
||||||
@@ -134,13 +139,16 @@ public class TikaAutoMetadataExtracterTest extends AbstractMetadataExtracterTest
|
|||||||
File file = new File(url.getFile());
|
File file = new File(url.getFile());
|
||||||
|
|
||||||
// Cheat and ask Tika for the mime type!
|
// Cheat and ask Tika for the mime type!
|
||||||
AutoDetectParser ap = new AutoDetectParser();
|
|
||||||
Metadata metadata = new Metadata();
|
Metadata metadata = new Metadata();
|
||||||
metadata.set(Metadata.RESOURCE_NAME_KEY, filename);
|
metadata.set(Metadata.RESOURCE_NAME_KEY, filename);
|
||||||
MediaType mt = ap.getDetector().detect(
|
MediaType mt = ap.getDetector().detect(TikaInputStream.get(file), metadata);
|
||||||
new BufferedInputStream(new FileInputStream(file)), metadata);
|
|
||||||
String mimetype = mt.toString();
|
String mimetype = mt.toString();
|
||||||
|
|
||||||
|
if (logger.isDebugEnabled())
|
||||||
|
{
|
||||||
|
logger.debug("Detected mimetype " + mimetype + " for quick test file " + filename);
|
||||||
|
}
|
||||||
|
|
||||||
// Have it processed
|
// Have it processed
|
||||||
Map<QName, Serializable> properties = extractFromFile(file, mimetype);
|
Map<QName, Serializable> properties = extractFromFile(file, mimetype);
|
||||||
|
|
||||||
@@ -178,7 +186,7 @@ public class TikaAutoMetadataExtracterTest extends AbstractMetadataExtracterTest
|
|||||||
|
|
||||||
// Check for extra fields
|
// Check for extra fields
|
||||||
// Author isn't there for the OpenDocument ones
|
// Author isn't there for the OpenDocument ones
|
||||||
if(mimetype.indexOf(".oasis.") == -1 && !mimetype.endsWith("/ogg"))
|
if(mimetype.indexOf(".oasis.") == -1 && !mimetype.endsWith("/ogg") && !mimetype.endsWith("dwg"))
|
||||||
{
|
{
|
||||||
assertEquals(
|
assertEquals(
|
||||||
"Property " + ContentModel.PROP_AUTHOR + " not found for mimetype " + mimetype,
|
"Property " + ContentModel.PROP_AUTHOR + " not found for mimetype " + mimetype,
|
||||||
@@ -192,20 +200,23 @@ public class TikaAutoMetadataExtracterTest extends AbstractMetadataExtracterTest
|
|||||||
"Test Property " + TIKA_MIMETYPE_TEST_PROPERTY + " not found for mimetype " + mimetype,
|
"Test Property " + TIKA_MIMETYPE_TEST_PROPERTY + " not found for mimetype " + mimetype,
|
||||||
properties.containsKey(TIKA_MIMETYPE_TEST_PROPERTY)
|
properties.containsKey(TIKA_MIMETYPE_TEST_PROPERTY)
|
||||||
);
|
);
|
||||||
// TODO - uncomment this when TIKA-391 is properly fixed
|
assertEquals(
|
||||||
// assertEquals(
|
"Test Property " + TIKA_MIMETYPE_TEST_PROPERTY + " incorrect for mimetype " + mimetype,
|
||||||
// "Test Property " + TIKA_MIMETYPE_TEST_PROPERTY + " incorrect for mimetype " + mimetype,
|
mimetype,
|
||||||
// mimetype,
|
DefaultTypeConverter.INSTANCE.convert(String.class, properties.get(TIKA_MIMETYPE_TEST_PROPERTY)));
|
||||||
// DefaultTypeConverter.INSTANCE.convert(String.class, properties.get(TIKA_MIMETYPE_TEST_PROPERTY)));
|
|
||||||
|
|
||||||
// Extra media checks for music formats
|
// Extra media checks for music formats
|
||||||
if(mimetype.endsWith("/ogg"))
|
if(mimetype.startsWith("audio"))
|
||||||
{
|
{
|
||||||
// Pending ALF-6170 for proper music namespace
|
|
||||||
assertEquals(
|
assertEquals(
|
||||||
"Property " + ContentModel.PROP_AUTHOR + " not found for mimetype " + mimetype,
|
"Property " + ContentModel.PROP_AUTHOR + " not found for mimetype " + mimetype,
|
||||||
"Hauskaz",
|
"Hauskaz",
|
||||||
DefaultTypeConverter.INSTANCE.convert(String.class, properties.get(ContentModel.PROP_AUTHOR)));
|
DefaultTypeConverter.INSTANCE.convert(String.class, properties.get(ContentModel.PROP_AUTHOR)));
|
||||||
|
QName artistQ = QName.createQName(NamespaceService.AUDIO_MODEL_1_0_URI, "artist");
|
||||||
|
assertEquals(
|
||||||
|
"Property " + artistQ + " not found for mimetype " + mimetype,
|
||||||
|
"Hauskaz",
|
||||||
|
DefaultTypeConverter.INSTANCE.convert(String.class, properties.get(artistQ)));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user