Search in sources :

Example 71 with XMLResource

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);
}
Also used : XUpdateQueryService(org.xmldb.api.modules.XUpdateQueryService) XPathQueryService(org.xmldb.api.modules.XPathQueryService) ResourceSet(org.xmldb.api.base.ResourceSet) XMLResource(org.xmldb.api.modules.XMLResource)

Example 72 with XMLResource

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);
}
Also used : Path(java.nio.file.Path) XMLResource(org.xmldb.api.modules.XMLResource)

Example 73 with XMLResource

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());
}
Also used : XUpdateQueryService(org.xmldb.api.modules.XUpdateQueryService) XMLResource(org.xmldb.api.modules.XMLResource)

Example 74 with XMLResource

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();
}
Also used : XMLResource(org.xmldb.api.modules.XMLResource)

Example 75 with XMLResource

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;
}
Also used : XQueryService(org.xmldb.api.modules.XQueryService) XMLResource(org.xmldb.api.modules.XMLResource)

Aggregations

XMLResource (org.xmldb.api.modules.XMLResource)142 Collection (org.xmldb.api.base.Collection)56 ResourceSet (org.xmldb.api.base.ResourceSet)56 XPathQueryService (org.xmldb.api.modules.XPathQueryService)49 Test (org.junit.Test)33 Resource (org.xmldb.api.base.Resource)24 XQueryService (org.xmldb.api.modules.XQueryService)23 Node (org.w3c.dom.Node)22 CollectionManagementService (org.xmldb.api.modules.CollectionManagementService)20 EXistXPathQueryService (org.exist.xmldb.EXistXPathQueryService)18 Document (org.w3c.dom.Document)16 XMLDBException (org.xmldb.api.base.XMLDBException)15 EXistResource (org.exist.xmldb.EXistResource)9 EXistXQueryService (org.exist.xmldb.EXistXQueryService)9 BinaryResource (org.xmldb.api.modules.BinaryResource)9 Path (java.nio.file.Path)8 Before (org.junit.Before)8 Element (org.w3c.dom.Element)8 Source (javax.xml.transform.Source)7 SAXSerializer (org.exist.util.serializer.SAXSerializer)7