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;