use of org.xmldb.api.modules.XMLResource in project exist by eXist-db.
the class StressTest method insertTags.
private void insertTags() throws XMLDBException {
final XUpdateQueryService service = (XUpdateQueryService) testCol.getService("XUpdateQueryService", "1.0");
final XPathQueryService xquery = (XPathQueryService) testCol.getService("XPathQueryService", "1.0");
final String[] tagsWritten = new String[RUNS];
for (int i = 0; i < RUNS; i++) {
final String tag = tags[i];
final String parent;
if (i > 0 && rand.nextInt(100) < 70) {
parent = "//" + tagsWritten[rand.nextInt(i) / 2];
} else {
parent = "/root";
}
final String xupdate = "<xupdate:modifications version=\"1.0\" xmlns:xupdate=\"http://www.xmldb.org/xupdate\">" + "<xupdate:append select=\"" + parent + "\">" + "<xupdate:element name=\"" + tag + "\"/>" + "</xupdate:append>" + "</xupdate:modifications>";
final long mods = service.updateResource("test.xml", xupdate);
assertEquals(mods, 1);
tagsWritten[i] = tag;
final String query = "//" + tagsWritten[rand.nextInt(i + 1)];
final ResourceSet result = xquery.query(query);
assertEquals(result.getSize(), 1);
}
final XMLResource res = (XMLResource) testCol.getResource("test.xml");
assertNotNull(res);
}
use of org.xmldb.api.modules.XMLResource in project exist by eXist-db.
the class XUpdateTest method addDocument.
private void addDocument(final String sourceFile) throws XMLDBException, IOException, URISyntaxException {
final Path f = getRelFile(SOURCE_DIR_NAME + "/" + sourceFile);
final XMLResource document = (XMLResource) col.createResource(XUPDATE_FILE, "XMLResource");
document.setContent(f);
col.storeResource(document);
}
use of org.xmldb.api.modules.XMLResource in project exist by eXist-db.
the class XUpdateTest method updateDocument.
/**
* @return resultant XML document as a String
*/
private String updateDocument(final Path updateFile) throws XMLDBException, IOException, ParserConfigurationException, SAXException {
final XUpdateQueryService service = (XUpdateQueryService) col.getService("XUpdateQueryService", "1.0");
// Read XUpdate-Modifcations
final String xUpdateModifications = new String(Files.readAllBytes(updateFile), UTF_8);
service.update(xUpdateModifications);
final XMLResource ret = (XMLResource) col.getResource(XUPDATE_FILE);
return ((String) ret.getContent());
}
use of org.xmldb.api.modules.XMLResource in project exist by eXist-db.
the class ExistXmldbEmbeddedServer method getXMLResource.
public static String getXMLResource(final Collection collection, final String resource) throws XMLDBException {
collection.setProperty(OutputKeys.INDENT, "yes");
collection.setProperty(EXistOutputKeys.EXPAND_XINCLUDES, "no");
collection.setProperty(EXistOutputKeys.PROCESS_XSL_PI, "yes");
final XMLResource res = (XMLResource) collection.getResource(resource);
return res.getContent().toString();
}
use of org.xmldb.api.modules.XMLResource in project exist by eXist-db.
the class EntitiesTest method storeXMLStringAndGetQueryService.
/**
* stores XML String and get Query Service
* @param documentName to be stored in the DB
* @param content to be stored in the DB
* @return the XQuery Service
* @throws XMLDBException
*/
@SuppressWarnings("unused")
private XQueryService storeXMLStringAndGetQueryService(String documentName, String content) throws XMLDBException {
XMLResource doc = (XMLResource) testCollection.createResource(documentName, "XMLResource");
doc.setContent(content);
testCollection.storeResource(doc);
XQueryService service = (XQueryService) testCollection.getService("XPathQueryService", "1.0");
return service;
}
Aggregations