public void check()
{
XComponent xComp = null;
XComponent xComp2 = null;
try {
XEnumeration xStmtsEnum;
XNamedGraph xManifest;
log.println("Creating document with Repository...");
// we cannot create a XDMA directly, we must create
// a document and get it from there :(
// create document
PropertyValue[] loadProps = new PropertyValue[1];
loadProps[0] = new PropertyValue();
loadProps[0].Name = "Hidden";
loadProps[0].Value = new Boolean(true);
xComp = util.DesktopTools.openNewDoc(xMSF, "swriter", loadProps);
XTextDocument xText = (XTextDocument) UnoRuntime.queryInterface(
XTextDocument.class, xComp);
XRepositorySupplier xRS = (XRepositorySupplier)
UnoRuntime.queryInterface(XRepositorySupplier.class, xComp);
assure("xRS null", null != xRS);
XDocumentMetadataAccess xDMA = (XDocumentMetadataAccess)
UnoRuntime.queryInterface(XDocumentMetadataAccess.class, xRS);
assure("xDMA null", null != xDMA);
xRep = xRS.getRDFRepository();
assure("xRep null", null != xRep);
log.println("...done");
log.println("Checking that new repository is initialized...");
XURI xBaseURI = (XURI) xDMA;
String baseURI = xBaseURI.getStringValue();
assure("new: baseURI",
null != xBaseURI && !xBaseURI.getStringValue().equals(""));
assure("new: # graphs", 1 == xRep.getGraphNames().length);
XURI manifest = URI.createNS(xContext, xBaseURI.getStringValue(),
manifestPath);
xManifest = xRep.getGraph(manifest);
assure("new: manifest graph", null != xManifest);
Statement[] manifestStmts = getManifestStmts(xBaseURI);
xStmtsEnum = xRep.getStatements(null, null, null);
assure("new: manifest graph", eq(xStmtsEnum, manifestStmts));
log.println("...done");
log.println("Checking some invalid args...");
String content = "behold, for i am the content.";
XTextRange xTR = new TestRange(content);
XMetadatable xM = (XMetadatable) xTR;
try {
xDMA.getElementByURI(null);
assure("getElementByURI: null allowed", false);
} catch (IllegalArgumentException e) {
// ignore
}
try {
xDMA.getMetadataGraphsWithType(null);
assure("getMetadataGraphsWithType: null URI allowed", false);
} catch (IllegalArgumentException e) {
// ignore
}
try {
xDMA.addMetadataFile("", new XURI[0]);
assure("addMetadataFile: empty filename allowed", false);
} catch (IllegalArgumentException e) {
// ignore
}
try {
xDMA.addMetadataFile("/foo", new XURI[0]);
assure("addMetadataFile: absolute filename allowed", false);
} catch (IllegalArgumentException e) {
// ignore
}
try {
xDMA.addMetadataFile("fo\"o", new XURI[0]);
assure("addMetadataFile: invalid filename allowed", false);
} catch (IllegalArgumentException e) {
// ignore
}
try {
xDMA.addMetadataFile("../foo", new XURI[0]);
assure("addMetadataFile: filename with .. allowed", false);
} catch (IllegalArgumentException e) {
// ignore
}
try {
xDMA.addMetadataFile("foo/../../bar", new XURI[0]);
assure("addMetadataFile: filename with nest .. allowed", false);
} catch (IllegalArgumentException e) {
// ignore
}
try {
xDMA.addMetadataFile("foo/././bar", new XURI[0]);
assure("addMetadataFile: filename with nest . allowed", false);
} catch (IllegalArgumentException e) {
// ignore
}
try {
xDMA.addMetadataFile("content.xml", new XURI[0]);
assure("addMetadataFile: content.xml allowed", false);
} catch (IllegalArgumentException e) {
// ignore
}
try {
xDMA.addMetadataFile("styles.xml", new XURI[0]);
assure("addMetadataFile: styles.xml allowed", false);
} catch (IllegalArgumentException e) {
// ignore
}
try {
xDMA.addMetadataFile("meta.xml", new XURI[0]);
assure("addMetadataFile: meta.xml allowed", false);
} catch (IllegalArgumentException e) {
// ignore
}
try {
xDMA.addMetadataFile("settings.xml", new XURI[0]);
assure("addMetadataFile: settings.xml allowed", false);
} catch (IllegalArgumentException e) {
// ignore
}
try {
xDMA.importMetadataFile(FileFormat.RDF_XML, null, "foo",
foo, new XURI[0]);
assure("importMetadataFile: null stream allowed", false);
} catch (IllegalArgumentException e) {
// ignore
}
try {
XInputStream xFooIn =
new StreamSimulator(tempDir + "empty.rdf", true, param);
xDMA.importMetadataFile(FileFormat.RDF_XML, xFooIn, "",
foo, new XURI[0]);
assure("importMetadataFile: empty filename allowed", false);
} catch (IllegalArgumentException e) {
// ignore
}
try {
XInputStream xFooIn =
new StreamSimulator(tempDir + "empty.rdf", true, param);
xDMA.importMetadataFile(FileFormat.RDF_XML, xFooIn, "meta.xml",
foo, new XURI[0]);
assure("importMetadataFile: meta.xml filename allowed", false);
} catch (IllegalArgumentException e) {
// ignore
}
try {
XInputStream xFooIn =
new StreamSimulator(tempDir + "empty.rdf", true, param);
xDMA.importMetadataFile(FileFormat.RDF_XML,
xFooIn, "foo", null, new XURI[0]);
assure("importMetadataFile: null base URI allowed", false);
} catch (IllegalArgumentException e) {
// ignore
}
try {
XInputStream xFooIn =
new StreamSimulator(tempDir + "empty.rdf", true, param);
xDMA.importMetadataFile(FileFormat.RDF_XML,
xFooIn, "foo", rdf_type, new XURI[0]);
assure("importMetadataFile: non-absolute base URI allowed",
false);
} catch (IllegalArgumentException e) {
// ignore
}
try {
xDMA.removeMetadataFile(null);
assure("removeMetadataFile: null URI allowed", false);
} catch (IllegalArgumentException e) {
// ignore
}
try {
xDMA.addContentOrStylesFile("");
assure("addContentOrStylesFile: empty filename allowed",
false);
} catch (IllegalArgumentException e) {
// ignore
}
try {
xDMA.addContentOrStylesFile("/content.xml");
assure("addContentOrStylesFile: absolute filename allowed",
false);
} catch (IllegalArgumentException e) {
// ignore
}
try {
xDMA.addContentOrStylesFile("foo.rdf");
assure("addContentOrStylesFile: invalid filename allowed",
false);
} catch (IllegalArgumentException e) {
// ignore
}
try {
xDMA.removeContentOrStylesFile("");
assure("removeContentOrStylesFile: empty filename allowed",
false);
} catch (IllegalArgumentException e) {
// ignore
}
try {
xDMA.loadMetadataFromStorage(null, foo, null);
assure("loadMetadataFromStorage: null storage allowed", false);
} catch (IllegalArgumentException e) {
// ignore
}
try {
xDMA.storeMetadataToStorage(null/*, base*/);
assure("storeMetadataToStorage: null storage allowed", false);
} catch (IllegalArgumentException e) {
// ignore
}
try {
xDMA.loadMetadataFromMedium(new PropertyValue[0]);
assure("loadMetadataFromMedium: empty medium allowed", false);
} catch (IllegalArgumentException e) {
// ignore
}
try {
xDMA.storeMetadataToMedium(new PropertyValue[0]);
assure("storeMetadataToMedium: empty medium allowed", false);
} catch (IllegalArgumentException e) {
// ignore
}
log.println("...done");
log.println("Checking file addition/removal...");
xDMA.removeContentOrStylesFile(contentPath);
xStmtsEnum = xManifest.getStatements(null, null, null);
assure("removeContentOrStylesFile (content)",
eq(xStmtsEnum, new Statement[] {
manifestStmts[0], manifestStmts[2], manifestStmts[4]
}));
xDMA.addContentOrStylesFile(contentPath);
xStmtsEnum = xManifest.getStatements(null, null, null);
assure("addContentOrStylesFile (content)",
eq(xStmtsEnum, manifestStmts));
xDMA.removeContentOrStylesFile(stylesPath);
xStmtsEnum = xManifest.getStatements(null, null, null);
assure("removeContentOrStylesFile (styles)",
eq(xStmtsEnum, new Statement[] {
manifestStmts[0], manifestStmts[1], manifestStmts[3]
}));
xDMA.addContentOrStylesFile(stylesPath);
xStmtsEnum = xManifest.getStatements(null, null, null);
assure("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);
xDMA.addMetadataFile(fooPath, new XURI[] { bar });
xStmtsEnum = xManifest.getStatements(null, null, null);
assure("addMetadataFile",
eq(xStmtsEnum, merge(manifestStmts, new Statement[] {
xM_BaseHaspartFoo, xM_FooTypeMetadata, xM_FooTypeBar
})));
XURI[] graphsBar = xDMA.getMetadataGraphsWithType(bar);
assure("getMetadataGraphsWithType",
graphsBar.length == 1 && eq(graphsBar[0], xFoo));
xDMA.removeMetadataFile(xFoo);
xStmtsEnum = xManifest.getStatements(null, null, null);
assure("removeMetadataFile",
eq(xStmtsEnum, manifestStmts));
log.println("...done");
log.println("Checking mapping...");
XEnumerationAccess xTextEnum = (XEnumerationAccess)
UnoRuntime.queryInterface(XEnumerationAccess.class,
xText.getText());
Object o = xTextEnum.createEnumeration().nextElement();
XMetadatable xMeta1 = (XMetadatable) UnoRuntime.queryInterface(
XMetadatable.class, o);
XURI uri;
XMetadatable xMeta;
xMeta = xDMA.getElementByURI(xMeta1);
assure("getElementByURI: null", null != xMeta);
String XmlId = xMeta.getMetadataReference().Second;
String XmlId1 = xMeta1.getMetadataReference().Second;
assure("getElementByURI: no xml id", !XmlId.equals(""));
assure("getElementByURI: different xml id", XmlId.equals(XmlId1));
log.println("...done");
log.println("Checking storing and loading...");
XURI xFoobar = URI.createNS(xContext, xBaseURI.getStringValue(),
fooBarPath);
Statement[] metadataStmts = getMetadataFileStmts(xBaseURI,
fooBarPath);
xDMA.addMetadataFile(fooBarPath, new XURI[0]);
xStmtsEnum = xRep.getStatements(null, null, null);
assure("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);
assure("addStatement",
eq(xStmtsEnum, merge(manifestStmts, merge(metadataStmts,
new Statement[] { xFoobar_FooBarFoo }))));
PropertyValue noMDNoContentFile = new PropertyValue();
noMDNoContentFile.Name = "URL";
noMDNoContentFile.Value = util.utils.getFullTestURL("CUSTOM.odt");
PropertyValue noMDFile = new PropertyValue();
noMDFile.Name = "URL";
noMDFile.Value = util.utils.getFullTestURL("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();
xDMA.storeMetadataToMedium(args);
// this should re-init
xDMA.loadMetadataFromMedium(argsEmptyNoContent);
xRep = xRS.getRDFRepository();
assure("xRep null", null != xRep);
assure("baseURI still tdoc?",
!baseURI.equals(xDMA.getStringValue()));
Statement[] manifestStmts2 = getManifestStmts((XURI) xDMA);
xStmtsEnum = xRep.getStatements(null, null, null);
// there is no content or styles file in here, so we have just
// the package stmt
assure("loadMetadataFromMedium (no metadata, no content)",
eq(xStmtsEnum, new Statement[] { manifestStmts2[0] }));
// this should re-init
xDMA.loadMetadataFromMedium(argsEmpty);
xRep = xRS.getRDFRepository();
assure("xRep null", null != xRep);
assure("baseURI still tdoc?",
!baseURI.equals(xDMA.getStringValue()));
Statement[] manifestStmts3 = getManifestStmts((XURI) xDMA);
xStmtsEnum = xRep.getStatements(null, null, null);
assure("loadMetadataFromMedium (no metadata)",
eq(xStmtsEnum, manifestStmts3));
xDMA.loadMetadataFromMedium(args);
xRep = xRS.getRDFRepository();
assure("xRep null", null != xRep);
Statement[] manifestStmts4 = getManifestStmts((XURI) xDMA);
Statement[] metadataStmts4 = getMetadataFileStmts((XURI) xDMA,
fooBarPath);
xStmtsEnum = xRep.getStatements(null, null, null);
assure("some graph(s) not reloaded",
graphs.length == xRep.getGraphNames().length);
XURI xFoobar4 = URI.createNS(xContext, xDMA.getStringValue(),
fooBarPath);
Statement xFoobar_FooBarFoo4 =
new Statement(foo, bar, foo, xFoobar4);
assure("loadMetadataFromMedium (re-load)",
eq(xStmtsEnum, merge(manifestStmts4, merge(metadataStmts4,
new Statement[] { xFoobar_FooBarFoo4 }))));
log.println("...done");
log.println("Checking storing and loading via model...");
String f = tempDir + "TESTPARA.odt";
XStorable xStor = (XStorable) UnoRuntime.queryInterface(
XStorable.class, xRS);
xStor.storeToURL(f, new PropertyValue[0]);
xComp2 = util.DesktopTools.loadDoc(xMSF, f, loadProps);
XDocumentMetadataAccess xDMA2 = (XDocumentMetadataAccess)
UnoRuntime.queryInterface(XDocumentMetadataAccess.class,
xComp2);
assure("xDMA2 null", null != xDMA2);
XRepositorySupplier xRS2 = (XRepositorySupplier)
UnoRuntime.queryInterface(XRepositorySupplier.class, xComp2);
assure("xRS2 null", null != xRS2);
XRepository xRep2 = xRS2.getRDFRepository();
assure("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);
assure("load: repository differs",
eq(xStmtsEnum2, merge(manifestStmts5, merge(metadataStmts5,
new Statement[] { xFoobar_FooBarFoo5 }))));
log.println("...done");