use of org.xmldb.api.base.Resource in project exist by eXist-db.
the class XMLDBMoveTask method execute.
@Override
public void execute() throws BuildException {
if (uri == null) {
throw (new BuildException("You have to specify an XMLDB collection URI"));
}
if ((resource == null) && (collection == null)) {
throw (new BuildException("Missing parameter: either resource or collection should be specified"));
}
registerDatabase();
try {
log("Get base collection: " + uri, Project.MSG_DEBUG);
final Collection base = DatabaseManager.getCollection(uri, user, password);
if (base == null) {
final String msg = "Collection " + uri + " could not be found.";
if (failonerror) {
throw (new BuildException(msg));
} else {
log(msg, Project.MSG_ERR);
}
}
log("Create collection management service for collection " + base.getName(), Project.MSG_DEBUG);
final EXistCollectionManagementService service = (EXistCollectionManagementService) base.getService("CollectionManagementService", "1.0");
if (resource != null) {
log("Moving resource: " + resource, Project.MSG_INFO);
final Resource res = base.getResource(resource);
if (res == null) {
final String msg = "Resource " + resource + " not found.";
if (failonerror) {
throw (new BuildException(msg));
} else {
log(msg, Project.MSG_ERR);
}
} else {
service.moveResource(XmldbURI.xmldbUriFor(resource), XmldbURI.xmldbUriFor(destination), XmldbURI.xmldbUriFor(name));
}
} else {
log("Moving collection: " + collection, Project.MSG_INFO);
service.move(XmldbURI.xmldbUriFor(collection), XmldbURI.xmldbUriFor(destination), XmldbURI.xmldbUriFor(name));
}
} catch (final XMLDBException e) {
final String msg = "XMLDB exception during move: " + e.getMessage();
if (failonerror) {
throw (new BuildException(msg, e));
} else {
log(msg, e, Project.MSG_ERR);
}
} catch (final URISyntaxException e) {
final String msg = "URI syntax exception: " + e.getMessage();
if (failonerror) {
throw (new BuildException(msg, e));
} else {
log(msg, e, Project.MSG_ERR);
}
}
}
use of org.xmldb.api.base.Resource in project exist by eXist-db.
the class ExpandTest method expandPersistentDomAttrNs.
@Test
public void expandPersistentDomAttrNs() throws XMLDBException {
final String query = "declare namespace x = \"http://x\";\n" + "util:expand(doc('/db/expand-test/doc4.xml')/doc4/@x:foo)";
final ResourceSet result = existEmbeddedServer.executeQuery(query);
final Resource res = result.getResource(0);
assertEquals(XMLResource.RESOURCE_TYPE, res.getResourceType());
final XMLResource xmlRes = (XMLResource) res;
final Node node = xmlRes.getContentAsDOM();
assertEquals(Node.ATTRIBUTE_NODE, node.getNodeType());
assertEquals("http://x", node.getNamespaceURI());
assertEquals("foo", node.getNodeName());
assertEquals("bar", node.getNodeValue());
}
use of org.xmldb.api.base.Resource in project exist by eXist-db.
the class EvalTest method evalAndSerializeJson.
@Test
public void evalAndSerializeJson() throws XMLDBException {
String query = "let $query := \"<outer><elem1>hello</elem1></outer>\"\n" + "return\n" + "util:eval-and-serialize($query, map { \"method\": \"json\" })";
ResourceSet result = existEmbeddedServer.executeQuery(query);
Resource r = result.getResource(0);
assertEquals("{\"elem1\":\"hello\"}", r.getContent());
}
use of org.xmldb.api.base.Resource in project exist by eXist-db.
the class EvalTest method evalAndSerialize.
@Test
public void evalAndSerialize() throws XMLDBException {
final String query = "let $query := \"<elem1>hello</elem1>\"\n" + "return\n" + "util:eval-and-serialize($query, ())";
final ResourceSet result = existEmbeddedServer.executeQuery(query);
final Resource r = result.getResource(0);
assertEquals("<elem1>hello</elem1>", r.getContent());
}
use of org.xmldb.api.base.Resource in project exist by eXist-db.
the class EvalTest method evalAndSerializeAdaptive.
@Test
public void evalAndSerializeAdaptive() throws XMLDBException {
String query = "let $query := 'map { \"key\": \"value\"}'\n" + "return\n" + "util:eval-and-serialize($query, map { \"method\": \"adaptive\" })";
ResourceSet result = existEmbeddedServer.executeQuery(query);
Resource r = result.getResource(0);
assertEquals("map{\"key\":\"value\"}", r.getContent());
}
Aggregations