Search in sources :

Example 36 with XMLDBException

use of org.xmldb.api.base.XMLDBException in project exist by eXist-db.

the class DtdEntityTest method loadWithEntities.

@Test
public void loadWithEntities() throws XMLDBException {
    final String input = "<a>first empty: &empty; then trade: &trade; </a>";
    Collection col = null;
    try {
        col = existEmbeddedServer.createCollection(existEmbeddedServer.getRoot(), "entity");
        ExistXmldbEmbeddedServer.storeResource(col, "docname.xml", input.getBytes());
        // should throw XMLDBException
        ExistXmldbEmbeddedServer.getXMLResource(col, "docname.xml");
    } catch (final XMLDBException e) {
        assertTrue(e.getMessage().contains("The entity \"empty\" was referenced, but not declared"));
        return;
    } finally {
        if (col != null) {
            col.close();
        }
    }
    fail("Should have thrown XMLDBException");
}
Also used : Collection(org.xmldb.api.base.Collection) XMLDBException(org.xmldb.api.base.XMLDBException)

Example 37 with XMLDBException

use of org.xmldb.api.base.XMLDBException in project exist by eXist-db.

the class TestCase method getResource.

public Resource getResource(Object r) throws XMLDBException {
    LocalCollection collection = null;
    Subject user = null;
    LocalXMLResource res = null;
    final BrokerPool pool = existEmbeddedServer.getBrokerPool();
    if (r instanceof NodeProxy) {
        NodeProxy p = (NodeProxy) r;
        res = new LocalXMLResource(user, pool, collection, p);
    } else if (r instanceof Node) {
        res = new LocalXMLResource(user, pool, collection, XmldbURI.EMPTY_URI);
        res.setContentAsDOM((Node) r);
    } else if (r instanceof AtomicValue) {
        res = new LocalXMLResource(user, pool, collection, XmldbURI.EMPTY_URI);
        res.setContent(r);
    } else if (r instanceof LocalXMLResource)
        res = (LocalXMLResource) r;
    else
        throw new XMLDBException(ErrorCodes.VENDOR_ERROR, "unknown object " + r.getClass());
    try {
        Field field = res.getClass().getDeclaredField("outputProperties");
        field.setAccessible(true);
        field.set(res, new Properties(defaultProperties));
    } catch (Exception e) {
    }
    return res;
}
Also used : Field(java.lang.reflect.Field) LocalXMLResource(org.exist.xmldb.LocalXMLResource) LocalCollection(org.exist.xmldb.LocalCollection) Node(org.w3c.dom.Node) XMLDBException(org.xmldb.api.base.XMLDBException) AtomicValue(org.exist.xquery.value.AtomicValue) Properties(java.util.Properties) NodeProxy(org.exist.dom.persistent.NodeProxy) Subject(org.exist.security.Subject) BrokerPool(org.exist.storage.BrokerPool) XMLDBException(org.xmldb.api.base.XMLDBException) IOException(java.io.IOException) SAXException(org.xml.sax.SAXException)

Example 38 with XMLDBException

use of org.xmldb.api.base.XMLDBException in project exist by eXist-db.

the class CollectionConfigurationTest method rangeIndex1.

@Test
@Ignore
public void rangeIndex1() throws XMLDBException {
    Collection testCollection = DatabaseManager.getCollection(XmldbURI.LOCAL_DB + "/" + TEST_COLLECTION);
    // Configure collection automatically
    IndexQueryService idxConf = (IndexQueryService) testCollection.getService("IndexQueryService", "1.0");
    idxConf.configureCollection(CONFIG2);
    // ... then index document
    XMLResource doc = (XMLResource) testCollection.createResource(TestConstants.TEST_XML_URI.toString(), "XMLResource");
    doc.setContent(DOCUMENT_CONTENT2);
    testCollection.storeResource(doc);
    XPathQueryService service = (XPathQueryService) testCollection.getService("XPathQueryService", "1.0");
    ResourceSet result = service.query("util:index-key-occurrences(/test/c, xs:dateTime(\"2002-12-07T12:20:46.275+01:00\") )");
    assertEquals(1, result.getSize());
    assertEquals("1", result.getResource(0).getContent());
    result = service.query("util:index-type(/test/c)");
    assertEquals("xs:dateTime", result.getResource(0).getContent());
    result = service.query("util:index-key-occurrences(/test/d, xs:double(1) )");
    assertEquals(1, result.getSize());
    assertEquals("1", result.getResource(0).getContent());
    result = service.query("util:index-type(/test/d)");
    assertEquals("xs:double", result.getResource(0).getContent());
    result = service.query("util:index-key-occurrences(/test/e, xs:float(1) )");
    assertEquals(1, result.getSize());
    assertEquals("1", result.getResource(0).getContent());
    result = service.query("util:index-type(/test/e)");
    assertEquals("xs:float", result.getResource(0).getContent());
    result = service.query("util:index-key-occurrences(/test/f, true())");
    assertEquals(1, result.getSize());
    assertEquals("1", result.getResource(0).getContent());
    result = service.query("util:index-type(/test/f)");
    assertEquals("xs:boolean", result.getResource(0).getContent());
    result = service.query("util:index-key-occurrences(/test/g, xs:integer(1))");
    assertEquals(1, result.getSize());
    assertEquals("1", result.getResource(0).getContent());
    result = service.query("util:index-type(/test/g)");
    assertEquals("xs:integer", result.getResource(0).getContent());
    result = service.query("util:index-key-occurrences(/test/h, '1')");
    assertEquals(1, result.getSize());
    assertEquals("1", result.getResource(0).getContent());
    result = service.query("util:index-type(/test/h)");
    assertEquals("xs:string", result.getResource(0).getContent());
    result = service.query("/test/c[(# exist:force-index-use #) { . = xs:dateTime(\"2002-12-07T12:20:46.275+01:00\") }]");
    assertEquals(1, result.getSize());
    result = service.query("/test[(# exist:force-index-use #) { c = xs:dateTime(\"2002-12-07T12:20:46.275+01:00\") }]");
    assertEquals(1, result.getSize());
    result = service.query("/test/d[(# exist:force-index-use #) { . = xs:double(1) }]");
    assertEquals(1, result.getSize());
    result = service.query("/test[(# exist:force-index-use #) { d = xs:double(1) }]");
    assertEquals(1, result.getSize());
    result = service.query("/test/e[(# exist:force-index-use #) { . = xs:float(1) }]");
    assertEquals(1, result.getSize());
    result = service.query("/test[(# exist:force-index-use #) { e = xs:float(1) }]");
    assertEquals(1, result.getSize());
    result = service.query("/test/f[(# exist:force-index-use #) { . = true() }]");
    assertEquals(1, result.getSize());
    result = service.query("/test[(# exist:force-index-use #) { f = true() }]");
    assertEquals(1, result.getSize());
    result = service.query("/test/g[(# exist:force-index-use #) { . = 1 }]");
    assertEquals(1, result.getSize());
    result = service.query("/test[(# exist:force-index-use #) { g = 1 }]");
    assertEquals(1, result.getSize());
    result = service.query("/test/h[(# exist:force-index-use #) { . = '1' }]");
    assertEquals(1, result.getSize());
    result = service.query("/test[(# exist:force-index-use #) { h = '1' }]");
    assertEquals(1, result.getSize());
    boolean exceptionCaught = false;
    try {
        result = service.query("/test[(# exist:force-index-use #) { contains(d, '1') }]");
        assertEquals(0, result.getSize());
    } catch (XMLDBException e) {
        exceptionCaught = true;
    }
    assertTrue("contains() should not use index of type xs:double", exceptionCaught);
    exceptionCaught = false;
    try {
        result = service.query("/test[(# exist:force-index-use #) { matches(d, '1') }]");
        assertEquals(0, result.getSize());
    } catch (XMLDBException e) {
        exceptionCaught = true;
    }
    assertTrue("matches() should not use index of type xs:double", exceptionCaught);
    result = service.query("/test[matches(h, '1')]");
    assertEquals(1, result.getSize());
}
Also used : XPathQueryService(org.xmldb.api.modules.XPathQueryService) Collection(org.xmldb.api.base.Collection) XMLDBException(org.xmldb.api.base.XMLDBException) ResourceSet(org.xmldb.api.base.ResourceSet) XMLResource(org.xmldb.api.modules.XMLResource)

Example 39 with XMLDBException

use of org.xmldb.api.base.XMLDBException in project exist by eXist-db.

the class CollectionConfigurationTest method rangeIndex2.

@Test
@Ignore
public void rangeIndex2() throws XMLDBException {
    Collection testCollection = DatabaseManager.getCollection(XmldbURI.LOCAL_DB + "/" + TEST_COLLECTION);
    // Configure collection automatically
    IndexQueryService idxConf = (IndexQueryService) testCollection.getService("IndexQueryService", "1.0");
    idxConf.configureCollection(QNAME_CONFIG2);
    // ... then index document
    XMLResource doc = (XMLResource) testCollection.createResource(TestConstants.TEST_XML_URI.toString(), "XMLResource");
    doc.setContent(DOCUMENT_CONTENT2);
    testCollection.storeResource(doc);
    XPathQueryService service = (XPathQueryService) testCollection.getService("XPathQueryService", "1.0");
    ResourceSet result = service.query("util:index-key-occurrences(/test/c, xs:dateTime(\"2002-12-07T12:20:46.275+01:00\") )");
    assertEquals(1, result.getSize());
    assertEquals("1", result.getResource(0).getContent());
    result = service.query("util:index-type(/test/c)");
    assertEquals("xs:dateTime", result.getResource(0).getContent());
    result = service.query("util:index-key-occurrences(/test/d, xs:double(1) )");
    assertEquals(1, result.getSize());
    assertEquals("1", result.getResource(0).getContent());
    result = service.query("util:index-type(/test/d)");
    assertEquals("xs:double", result.getResource(0).getContent());
    result = service.query("util:index-key-occurrences(/test/e, xs:float(1) )");
    assertEquals(1, result.getSize());
    assertEquals("1", result.getResource(0).getContent());
    result = service.query("util:index-type(/test/e)");
    assertEquals("xs:float", result.getResource(0).getContent());
    result = service.query("util:index-key-occurrences(/test/f, true())");
    assertEquals(1, result.getSize());
    assertEquals("1", result.getResource(0).getContent());
    result = service.query("util:index-type(/test/f)");
    assertEquals("xs:boolean", result.getResource(0).getContent());
    result = service.query("util:index-key-occurrences(/test/g, xs:integer(1))");
    assertEquals(1, result.getSize());
    assertEquals("1", result.getResource(0).getContent());
    result = service.query("util:index-type(/test/g)");
    assertEquals("xs:integer", result.getResource(0).getContent());
    result = service.query("util:index-key-occurrences(/test/h, '1')");
    assertEquals(1, result.getSize());
    assertEquals("1", result.getResource(0).getContent());
    result = service.query("util:index-type(/test/h)");
    assertEquals("xs:string", result.getResource(0).getContent());
    result = service.query("(# exist:force-index-use #) { /test/c[. = xs:dateTime(\"2002-12-07T12:20:46.275+01:00\")] }");
    assertEquals(1, result.getSize());
    result = service.query("(# exist:force-index-use #) { /test[c = xs:dateTime(\"2002-12-07T12:20:46.275+01:00\")] }");
    assertEquals(1, result.getSize());
    result = service.query("(# exist:force-index-use #) { /test/d[. = xs:double(1)] }");
    assertEquals(1, result.getSize());
    result = service.query("(# exist:force-index-use #) { /test[d = xs:double(1)] }");
    assertEquals(1, result.getSize());
    result = service.query("(# exist:force-index-use #) { /test/e[. = xs:float(1)] }");
    assertEquals(1, result.getSize());
    result = service.query("(# exist:force-index-use #) { /test[e = xs:float(1)] }");
    assertEquals(1, result.getSize());
    result = service.query("(# exist:force-index-use #) { /test/f[. = true()] }");
    assertEquals(1, result.getSize());
    result = service.query("(# exist:force-index-use #) { /test[f = true()] }");
    assertEquals(1, result.getSize());
    result = service.query("(# exist:force-index-use #) { /test/g[. = 1] }");
    assertEquals(1, result.getSize());
    result = service.query("(# exist:force-index-use #) { /test[g = 1] }");
    assertEquals(1, result.getSize());
    result = service.query("(# exist:force-index-use #) { /test/h[. = '1'] }");
    assertEquals(1, result.getSize());
    result = service.query("(# exist:force-index-use #) { /test[h = '1'] }");
    assertEquals(1, result.getSize());
    boolean exceptionCaught = false;
    try {
        result = service.query("(# exist:force-index-use #) { /test[contains(d, '1')] }");
        assertEquals(0, result.getSize());
    } catch (XMLDBException e) {
        exceptionCaught = true;
    }
    assertTrue("contains() should not use index of type xs:double", exceptionCaught);
    exceptionCaught = false;
    try {
        result = service.query("(# exist:force-index-use #) { /test[matches(d, '1')] }");
        assertEquals(0, result.getSize());
    } catch (XMLDBException e) {
        exceptionCaught = true;
    }
    assertTrue("matches() should not use index of type xs:double", exceptionCaught);
    result = service.query("/test[matches(h, '1')]");
    assertEquals(1, result.getSize());
}
Also used : XPathQueryService(org.xmldb.api.modules.XPathQueryService) Collection(org.xmldb.api.base.Collection) XMLDBException(org.xmldb.api.base.XMLDBException) ResourceSet(org.xmldb.api.base.ResourceSet) XMLResource(org.xmldb.api.modules.XMLResource)

Example 40 with XMLDBException

use of org.xmldb.api.base.XMLDBException in project exist by eXist-db.

the class BackupSystemTask method execute.

@Override
public void execute(final DBBroker broker, final Txn transaction) throws EXistException {
    // see if old zip files need to be purged
    if (zipFilesMax > 0) {
        try {
            purgeZipFiles();
        } catch (final IOException ioe) {
            throw new EXistException("Unable to purge zip files", ioe);
        }
    }
    final String dateTime = creationDateFormat.format(Calendar.getInstance().getTime());
    final Path dest = directory.resolve(prefix + dateTime + suffix);
    final Backup backup = new Backup(user, password, dest, collection, null, deduplicateBlobs);
    try {
        backup.backup(false, null);
    } catch (final XMLDBException | SAXException | IOException e) {
        LOG.error(e.getMessage(), e);
        throw new EXistException(e.getMessage(), e);
    }
}
Also used : Path(java.nio.file.Path) Backup(org.exist.backup.Backup) XMLDBException(org.xmldb.api.base.XMLDBException) IOException(java.io.IOException) EXistException(org.exist.EXistException) SAXException(org.xml.sax.SAXException)

Aggregations

XMLDBException (org.xmldb.api.base.XMLDBException)174 Collection (org.xmldb.api.base.Collection)66 Resource (org.xmldb.api.base.Resource)34 URISyntaxException (java.net.URISyntaxException)30 XMLResource (org.xmldb.api.modules.XMLResource)30 ResourceSet (org.xmldb.api.base.ResourceSet)23 BuildException (org.apache.tools.ant.BuildException)21 IOException (java.io.IOException)19 XPathException (org.exist.xquery.XPathException)18 PermissionDeniedException (org.exist.security.PermissionDeniedException)16 SAXException (org.xml.sax.SAXException)16 EXistException (org.exist.EXistException)15 UserManagementService (org.exist.xmldb.UserManagementService)15 XPathQueryService (org.xmldb.api.modules.XPathQueryService)13 BinaryResource (org.xmldb.api.modules.BinaryResource)12 ArrayList (java.util.ArrayList)11 Account (org.exist.security.Account)11 EXistResource (org.exist.xmldb.EXistResource)10 EXistXPathQueryService (org.exist.xmldb.EXistXPathQueryService)10 Properties (java.util.Properties)9