Package org.xmldb.api.base

Examples of org.xmldb.api.base.Collection


   }

   public void removeDocument(String path,
                              String name)
         throws Exception {
      Collection col = DatabaseManager.getCollection(driver + "/" + path);
      XMLResource document = (XMLResource) col.getResource(name);

      col.removeResource(document);
   }
View Full Code Here


                "<email type=\"work\">john@lovesushi.com</email>" +
                "<address type=\"home\">34 S. Colon St.</address>" +
                "<address type=\"work\">9967 W. Shrimp Ave.</address>" +
                "</person>";

        Collection col = this.client.getCollection(TEST_COLLECTION_PATH);
        XUpdateQueryService service = (XUpdateQueryService) col.getService("XUpdateQueryService", "1.0");

        long count = service.update(xupdate);
        assertEquals(1, count);

        String doc = this.client.getDocument(TEST_COLLECTION_PATH, "xupdatedoc");
View Full Code Here

      this.client.dropCollection(TEST_COLLECTION_PATH, "getname");
   }

   public void testGetParentCollection()
         throws Exception {
      Collection col = this.client.createCollection(TEST_COLLECTION_PATH, "childcol");

      Collection parent = col.getParentCollection();
      assertNotNull(parent);
      assertEquals("current", parent.getName());

      parent = parent.getParentCollection();
      assertNotNull(parent);
      assertEquals("testing", parent.getName());

      parent = parent.getParentCollection();
      assertNull(parent);

      this.client.dropCollection(TEST_COLLECTION_PATH, "childcol");
   }
View Full Code Here

      assertNull(this.client.getCollection(TEST_COLLECTION_PATH + "/unknown"));
   }

   public void testChildCollectionCount()
         throws Exception {
      Collection col = this.client.createCollection(TEST_COLLECTION_PATH, "childcol");
      assertEquals(0, col.getChildCollectionCount());

      this.client.createCollection(TEST_COLLECTION_PATH, "colcount");
      assertEquals(0, col.getChildCollectionCount());

      this.client.dropCollection(TEST_COLLECTION_PATH, "colcount");
      assertEquals(0, col.getChildCollectionCount());
   }
View Full Code Here

      return null;
    }
    getLogger ().debug ("DBXMLAUTH: query is: " + query);


    Collection col = CreateConnection( conf );

    if ( col != null )
    {
      if ( col.isOpen() )
      {

        try
        {
          XPathQueryService service = (XPathQueryService) col.getService("XPathQueryService", "1.0");

          rs = service.query(query);
          ResourceIterator results = rs.getIterator();

          if (results.hasMoreResources() == false)
          {
              getLogger ().debug ("DBXMLAUTH: auth failed");
              return null;
          } else {
            getLogger ().debug ("DBXMLAUTH: auth OK");
            return rs;
          }

        } catch (XMLDBException e) {

          getLogger ().debug ("DBXMLAUTH: got exception: " + e);
          return null;

        } finally {

          // close col
          if (col != null) {
            try {
              col.close();
            } catch (Exception e) { /* ignore */ }
          }
          getLogger ().debug ("DBXMLAUTH: collection closed");

        }
View Full Code Here

  }


  private Collection CreateConnection( Configuration conf ) throws Exception, XMLDBException {

    Collection col = null;

    Configuration conn = conf.getChild ("connection");

    try {
View Full Code Here

        final String col = url.substring(0, url.lastIndexOf('/'));
        final String res = url.substring(url.lastIndexOf('/') + 1);

        try {
            Collection collection = DatabaseManager.getCollection(col);
            if (collection == null) {
                throw new ResourceNotFoundException("Document " + url + " not found");
            }

            XMLResource xmlResource = (XMLResource) collection.getResource(res);
            if (xmlResource == null) {
                throw new ResourceNotFoundException("Document " + url + " not found");
            }

            if (query != null) {
                // Query resource
                if (log.isDebugEnabled()) {
                    this.log.debug("Querying resource " + res + " from collection " + url + "; query= " + this.query);
                }

                queryToSAX(handler, collection, res);
            } else {
                // Return entire resource
                if (log.isDebugEnabled()) {
                    this.log.debug("Obtaining resource " + res + " from collection " + col);
                }

                xmlResource.getContentAsSAX(handler);
            }

            collection.close();
        } catch (XMLDBException xde) {
            String error = "Unable to fetch content. Error "
                     + xde.errorCode + ": " + xde.getMessage();
            this.log.debug(error, xde);
            throw new SAXException(error, xde);
View Full Code Here

    private void collectionToSAX(ContentHandler handler) throws SAXException, ProcessingException {

        AttributesImpl attributes = new AttributesImpl();

        try {
            Collection collection = DatabaseManager.getCollection(url);
            if (collection == null) {
                throw new ResourceNotFoundException("Collection " + url +
                        " not found");
            }

            if (query != null) {
                // Query collection
                if (log.isDebugEnabled()) {
                    this.log.debug("Querying collection " + url + "; query= " + this.query);
                }

                queryToSAX(handler, collection, null);
            } else {
                // List collection
                if (log.isDebugEnabled()) {
                    this.log.debug("Listing collection " + url);
                }

                final String ncollections = Integer.toString(collection.getChildCollectionCount());
                final String nresources = Integer.toString(collection.getResourceCount());
                attributes.addAttribute("", RESOURCE_COUNT_ATTR,
                        RESOURCE_COUNT_ATTR, "CDATA", nresources);
                attributes.addAttribute("", COLLECTION_COUNT_ATTR,
                        COLLECTION_COUNT_ATTR, "CDATA", ncollections);
//                attributes.addAttribute("", COLLECTION_BASE_ATTR,
//                        COLLECTION_BASE_ATTR, "CDATA", url);

                handler.startDocument();
                handler.startPrefixMapping(PREFIX, URI);
                handler.startElement(URI, COLLECTIONS, QCOLLECTIONS, attributes);

                // Print child collections
                String[] collections = collection.listChildCollections();
                for (int i = 0; i < collections.length; i++) {
                    attributes.clear();
                    attributes.addAttribute("", NAME_ATTR, NAME_ATTR, CDATA, collections[i]);
                    handler.startElement(URI, COLLECTION,
                            QCOLLECTION, attributes);
                    handler.endElement(URI, COLLECTION, COLLECTION);
                }

                // Print child resources
                String[] resources = collection.listResources();
                for (int i = 0; i < resources.length; i++) {
                    attributes.clear();
                    attributes.addAttribute("", NAME_ATTR, NAME_ATTR, CDATA, resources[i]);
                    handler.startElement(URI, RESOURCE,
                            QRESOURCE, attributes);
                    handler.endElement(URI, RESOURCE, RESOURCE);
                }

                handler.endElement(URI, COLLECTIONS, QCOLLECTIONS);
                handler.endPrefixMapping(PREFIX);
                handler.endDocument();
            }

            collection.close();
        } catch (XMLDBException xde) {
            String error = "Collection listing failed. Error " + xde.errorCode + ": " + xde.getMessage();
            this.log.debug(error, xde);
            throw new SAXException(error, xde);
        }
View Full Code Here

*/
public class CollectionTest extends AbstractXmlDbClientTest {

    public void testGetUnknownDatabase() throws Exception {
        try {
            Collection col = this.client.getCollection("doesnotexist");
            fail("Expected ErrorCodes.NO_SUCH_DATABASE (" + ErrorCodes.NO_SUCH_DATABASE + "), got collection: " + col);
        } catch (XMLDBException e) {
            if (e.errorCode != ErrorCodes.NO_SUCH_DATABASE) {
                fail("Expected ErrorCodes.NO_SUCH_DATABASE (" + ErrorCodes.NO_SUCH_DATABASE + "), got: " + e);
            }
View Full Code Here

        assertEquals("getname", this.client.getName(TEST_COLLECTION_PATH + "/getname/"));
        this.client.dropCollection(TEST_COLLECTION_PATH, "getname");
    }

    public void testGetParentCollection() throws Exception {
        Collection col = this.client.createCollection(TEST_COLLECTION_PATH, "childcol");

        Collection parent = col.getParentCollection();
        assertNotNull(parent);
        assertEquals("current", parent.getName());

        parent = parent.getParentCollection();
        assertNotNull(parent);
        assertEquals("testing", parent.getName());

        parent = parent.getParentCollection();

        // Must return root database collection
        assertNotNull(parent);
        assertEquals("", parent.getName());

        this.client.dropCollection(TEST_COLLECTION_PATH, "childcol");
    }
View Full Code Here

TOP

Related Classes of org.xmldb.api.base.Collection

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.