();
// make a writer for the target of the embed, we won't actually use it
File targetFile = TempFileProvider.createTempFile(
getClass().getSimpleName() + "_" + getName() + "_embed",
".txt");
FileContentWriter writer = new FileContentWriter(targetFile);
writer.setMimetype(DummyMetadataEmbedder.MIMETYPE_EMBEDDABLE);
try
{
embedder.embed(propertiesToEmbed, reader, writer);
}
catch (AlfrescoRuntimeException e)
{
if (e.getMessage().contains("Metadata extracter does not support embedding mimetype"))
{
fail("Embed mimetype should not be tied to extracter's extract mimetypes");
}
else
{
fail(e.getMessage());
}
}
finally
{
if (targetFile != null && targetFile.exists())
{
targetFile.delete();
}
}
}
/**
* A spoofed-up extracter that extracts the following:
*
* a: - A --> my:a1, my:a2
* b: - B --> my:b
* c: - C
* d: - D
*
* @author Derek Hulley
*/
public static class DummyMappingMetadataExtracter extends AbstractMappingMetadataExtracter
{
public static final String PROP_A = "a";
public static final String PROP_B = "b";
public static final String PROP_C = "c";
public static final String PROP_D = "d";
public static final String PROP_E = "e";
public static final String PROP_IMG = "exif";
public static final String VALUE_A = "AAA";
public static final String VALUE_B = "BBB";
public static final String VALUE_C = "CCC";
public static final String VALUE_D = "DDD";
public static final String VALUE_IMG = "IMAGE";
public static final String EXTRACTER_NAME = "extracter.Dummy";
public static final String NAMESPACE_MY = "http://DummyMappingMetadataExtracter";
public static final QName QNAME_A1 = QName.createQName(NAMESPACE_MY, "a1");
public static final QName QNAME_A2 = QName.createQName(NAMESPACE_MY, "a2");
public static final QName QNAME_A3 = QName.createQName(NAMESPACE_MY, "a3");
public static final QName QNAME_B = QName.createQName(NAMESPACE_MY, "b");
public static final QName QNAME_C = QName.createQName(NAMESPACE_MY, "c");
public static final QName QNAME_D = QName.createQName(NAMESPACE_MY, "d");
public static final QName QNAME_E = QName.createQName(NAMESPACE_MY, "e"); // not extracted
public static final QName QNAME_IMG = QName.createQName(NamespaceService.EXIF_MODEL_1_0_URI, "test");
private static final Set MIMETYPES;
static
{
MIMETYPES = new HashSet(5);
MIMETYPES.add(MimetypeMap.MIMETYPE_TEXT_PLAIN);
MIMETYPES.add(MimetypeMap.MIMETYPE_XML);
}
Map> defaultMapping;
private boolean initCheck;
public DummyMappingMetadataExtracter()
{
super(MIMETYPES);
initCheck = false;
setBeanName(EXTRACTER_NAME);
}
@Override
protected void init()
{
defaultMapping = new HashMap>(7);
defaultMapping.put(PROP_A, new HashSet(Arrays.asList(QNAME_A1, QNAME_A2)));
defaultMapping.put(PROP_B, new HashSet(Arrays.asList(QNAME_B)));
defaultMapping.put(PROP_IMG, new HashSet(Arrays.asList(QNAME_IMG)));
initCheck = true;
super.init();
}
@Override
protected Map> getDefaultMapping()
{
return defaultMapping;
}
@Override
protected Map extractRaw(ContentReader reader)
{
reader.getContentString();
Map ret = new HashMap(7);
ret.put(PROP_A, VALUE_A);
ret.put(PROP_B, VALUE_B);
ret.put(PROP_C, VALUE_C);
ret.put(PROP_D, VALUE_D);
ret.put(PROP_IMG, VALUE_IMG);
return ret;
}
}
public static class DummyPropertiesInPackageLocationMappingMetadataExtracter extends AbstractMappingMetadataExtracter
{
@Override
protected Map extractRaw(ContentReader reader) throws Throwable
{
return null;
}
}
public static class DummyPropertiesInMetadataLocationMappingMetadataExtracter extends AbstractMappingMetadataExtracter
{
@Override
protected Map extractRaw(ContentReader reader) throws Throwable
{
return null;
}
}
public static class DummyPropertiesMissingMappingMetadataExtracter extends AbstractMappingMetadataExtracter
{
@Override
protected Map extractRaw(ContentReader reader) throws Throwable
{
return null;
}
}
private static class JunkValue implements Serializable
{
private static final JunkValue INSTANCE = new JunkValue();
private static final long serialVersionUID = 1L;
}
/**
* Mock metadata embedder which has a set of supported embed mimetypes different than
* the supported extract mimetypes.
*/
private class DummyMetadataEmbedder extends AbstractMappingMetadataExtracter
{
private static final String MIMETYPE_EXTRACTABLE = "extractableMimetype";
private static final String MIMETYPE_EMBEDDABLE = "embeddableMimetype";
public DummyMetadataEmbedder()
{
super(Collections.singleton(MIMETYPE_EXTRACTABLE),
Collections.singleton(MIMETYPE_EMBEDDABLE));
init();
}
@Override
protected Map extractRaw(ContentReader reader) throws Throwable
{
return null;
}
}
}