assertTrue("addContentOrStylesFile (styles)",
eq(xStmtsEnum, manifestStmts));
XURI xFoo = URI.createNS(xContext, xBaseURI.getStringValue(),
fooPath);
Statement xM_BaseHaspartFoo =
new Statement(xBaseURI, pkg_hasPart, xFoo, manifest);
Statement xM_FooTypeMetadata =
new Statement(xFoo, rdf_type, pkg_MetadataFile, manifest);
Statement xM_FooTypeBar =
new Statement(xFoo, rdf_type, bar, manifest);
xDocMDAccess.addMetadataFile(fooPath, new XURI[] { bar });
xStmtsEnum = xManifest.getStatements(null, null, null);
assertTrue("addMetadataFile",
eq(xStmtsEnum, merge(manifestStmts, new Statement[] {
xM_BaseHaspartFoo, xM_FooTypeMetadata, xM_FooTypeBar
})));
XURI[] graphsBar = xDocMDAccess.getMetadataGraphsWithType(bar);
assertTrue("getMetadataGraphsWithType",
graphsBar.length == 1 && eq(graphsBar[0], xFoo));
xDocMDAccess.removeMetadataFile(xFoo);
xStmtsEnum = xManifest.getStatements(null, null, null);
assertTrue("removeMetadataFile",
eq(xStmtsEnum, manifestStmts));
System.out.println("...done");
System.out.println("Checking mapping...");
XEnumerationAccess xTextEnum = UnoRuntime.queryInterface(XEnumerationAccess.class, xText.getText());
Object o = xTextEnum.createEnumeration().nextElement();
XMetadatable xMeta1 = UnoRuntime.queryInterface(XMetadatable.class, o);
XURI uri;
XMetadatable xMeta;
xMeta = xDocMDAccess.getElementByURI(xMeta1);
assertTrue("getElementByURI: null", null != xMeta);
String XmlId = xMeta.getMetadataReference().Second;
String XmlId1 = xMeta1.getMetadataReference().Second;
assertTrue("getElementByURI: no xml id", !XmlId.equals(""));
assertTrue("getElementByURI: different xml id", XmlId.equals(XmlId1));
System.out.println("...done");
System.out.println("Checking storing and loading...");
XURI xFoobar = URI.createNS(xContext, xBaseURI.getStringValue(),
fooBarPath);
Statement[] metadataStmts = getMetadataFileStmts(xBaseURI,
fooBarPath);
xDocMDAccess.addMetadataFile(fooBarPath, new XURI[0]);
xStmtsEnum = xRep.getStatements(null, null, null);
assertTrue("addMetadataFile",
eq(xStmtsEnum, merge(manifestStmts, metadataStmts )));
Statement xFoobar_FooBarFoo =
new Statement(foo, bar, foo, xFoobar);
xRep.getGraph(xFoobar).addStatement(foo, bar, foo);
xStmtsEnum = xRep.getStatements(null, null, null);
assertTrue("addStatement",
eq(xStmtsEnum, merge(manifestStmts, merge(metadataStmts,
new Statement[] { xFoobar_FooBarFoo }))));
PropertyValue noMDNoContentFile = new PropertyValue();
noMDNoContentFile.Name = "URL";
noMDNoContentFile.Value = TestDocument.getUrl("CUSTOM.odt");
PropertyValue noMDFile = new PropertyValue();
noMDFile.Name = "URL";
noMDFile.Value = TestDocument.getUrl("TEST.odt");
PropertyValue file = new PropertyValue();
file.Name = "URL";
file.Value = tempDir + "TESTDMA.odt";
/*
PropertyValue baseURL = new PropertyValue();
baseURL.Name = "DocumentBaseURL";
baseURL.Value = tempDir + "TMP.odt";
*/
PropertyValue mimetype = new PropertyValue();
mimetype.Name = "MediaType";
mimetype.Value = "application/vnd.oasis.opendocument.text";
PropertyValue[] argsEmptyNoContent = { mimetype, noMDNoContentFile};
PropertyValue[] argsEmpty = { mimetype, noMDFile };
PropertyValue[] args = { mimetype, file };
xStmtsEnum = xRep.getStatements(null, null, null);
XURI[] graphs = xRep.getGraphNames();
xDocMDAccess.storeMetadataToMedium(args);
// this should re-init
xDocMDAccess.loadMetadataFromMedium(argsEmptyNoContent);
xRep = xRepoSupplier.getRDFRepository();
assertTrue("xRep null", null != xRep);
assertTrue("baseURI still tdoc?",
!baseURI.equals(xDocMDAccess.getStringValue()));
Statement[] manifestStmts2 = getManifestStmts((XURI) xDocMDAccess);
xStmtsEnum = xRep.getStatements(null, null, null);
// there is no content or styles file in here, so we have just
// the package stmt
assertTrue("loadMetadataFromMedium (no metadata, no content)",
eq(xStmtsEnum, new Statement[] { manifestStmts2[0] }));
// this should re-init
xDocMDAccess.loadMetadataFromMedium(argsEmpty);
xRep = xRepoSupplier.getRDFRepository();
assertTrue("xRep null", null != xRep);
assertTrue("baseURI still tdoc?",
!baseURI.equals(xDocMDAccess.getStringValue()));
Statement[] manifestStmts3 = getManifestStmts((XURI) xDocMDAccess);
xStmtsEnum = xRep.getStatements(null, null, null);
assertTrue("loadMetadataFromMedium (no metadata)",
eq(xStmtsEnum, manifestStmts3));
xDocMDAccess.loadMetadataFromMedium(args);
xRep = xRepoSupplier.getRDFRepository();
assertTrue("xRep null", null != xRep);
Statement[] manifestStmts4 = getManifestStmts((XURI) xDocMDAccess);
Statement[] metadataStmts4 = getMetadataFileStmts((XURI) xDocMDAccess,
fooBarPath);
xStmtsEnum = xRep.getStatements(null, null, null);
assertTrue("some graph(s) not reloaded",
graphs.length == xRep.getGraphNames().length);
XURI xFoobar4 = URI.createNS(xContext, xDocMDAccess.getStringValue(),
fooBarPath);
Statement xFoobar_FooBarFoo4 =
new Statement(foo, bar, foo, xFoobar4);
assertTrue("loadMetadataFromMedium (re-load)",
eq(xStmtsEnum, merge(manifestStmts4, merge(metadataStmts4,
new Statement[] { xFoobar_FooBarFoo4 }))));
System.out.println("...done");
System.out.println("Checking storing and loading via model...");
String f = tempDir + "TESTPARA.odt";
XStorable xStor = UnoRuntime.queryInterface(XStorable.class, xRepoSupplier);
xStor.storeToURL(f, new PropertyValue[0]);
xComp2 = util.DesktopTools.loadDoc(xMSF, f, loadProps);
XDocumentMetadataAccess xDMA2 = UnoRuntime.queryInterface(XDocumentMetadataAccess.class, xComp2);
assertTrue("xDMA2 null", null != xDMA2);
XRepositorySupplier xRS2 = UnoRuntime.queryInterface(XRepositorySupplier.class, xComp2);
assertTrue("xRS2 null", null != xRS2);
XRepository xRep2 = xRS2.getRDFRepository();
assertTrue("xRep2 null", null != xRep2);
Statement[] manifestStmts5 = getManifestStmts((XURI) xDMA2);
Statement[] metadataStmts5 = getMetadataFileStmts((XURI) xDMA2,
fooBarPath);
XURI xFoobar5 = URI.createNS(xContext, xDMA2.getStringValue(),
fooBarPath);
Statement xFoobar_FooBarFoo5 =
new Statement(foo, bar, foo, xFoobar5);
xStmtsEnum = xRep.getStatements(null, null, null);
XEnumeration xStmtsEnum2 = xRep2.getStatements(null, null, null);
assertTrue("load: repository differs",
eq(xStmtsEnum2, merge(manifestStmts5, merge(metadataStmts5,
new Statement[] { xFoobar_FooBarFoo5 }))));