Package org.xmldb.api.base

Examples of org.xmldb.api.base.Resource


                // Perform operation
                String result = "failure";
                String message = null;
                if("create".equals(operation)) {
                    try {
                        Resource resource = collection.createResource(key, "XMLResource");
                        resource.setContent(document);
                        collection.storeResource(resource);
                        result = "success";
                    } catch (XMLDBException e) {
                        message = "Failed to create resource " + key + ": " + e.errorCode;
                        getLogger().debug(message, e);
                    }
                } else if("delete".equals(operation)) {
                    try {
                        Resource resource = collection.getResource(this.key);
                        if (resource == null) {
                            message = "Resource " + this.key + " does not exist";
                            getLogger().debug(message);
                        } else {
                            collection.removeResource(resource);
View Full Code Here


                  System.out.println("ERROR : Collection not found!");
                  return false;
                }
           
                if (table.get(XMLTools.NAME_OF) != null) {
                     Resource colresource = col.getResource((String)table.get(XMLTools.NAME_OF));
                       
                     col.removeResource(colresource);
                     System.out.println("DELETED: " + table.get(XMLTools.COLLECTION) + "/" + table.get(XMLTools.NAME_OF));
                }
               
View Full Code Here

    /*
     * Create a binary resource, save it in the 'current' collection,
     * then retrieve it and verify that the data comes back right.
     */

        Resource newResource = collection.createResource(null, "BinaryResource");
        newResource.setContent(new byte[] { 0x00, 0x10, 0x01, 0x11 });
    collection.storeResource(newResource);
    String id = newResource.getId();

    Resource foundResource = collection.getResource(id);

    assertNotNull("We know you're in there...", foundResource);
    assertEquals("The resource type is supposed be 'BinaryResource'", "BinaryResource", foundResource.getResourceType());
    assertTrue("The resource is an instance of BinaryResource", foundResource instanceof BinaryResource);

    byte[] newBytes = (byte[]) newResource.getContent();
    byte[] foundBytes = (byte[]) foundResource.getContent();

    assertEquals("The size of the found and saved resource should be the same...", newBytes.length, foundBytes.length);
    for (int i = 0; i < newBytes.length; ++i) {
      assertEquals("The resources differ in byte " + i, newBytes[i], foundBytes[i]);
    }
View Full Code Here

      XPathQueryService service = (XPathQueryService) collection.getService("XPathQueryService", "1.0");
      ResourceSet resourceSet = service.query(xpath);
      ResourceIterator resourceIterator = resourceSet.getIterator();

      while (resourceIterator.hasMoreResources()) {
        Resource resource = resourceIterator.nextResource();
        System.out.println((String) resource.getContent());
      }
    }
    catch (XMLDBException e) {
      System.err.println("XML:DB Exception occured " + e.errorCode + " " + e.getMessage());
    }
View Full Code Here

        //
        // Create a binary resource, save it in the 'current' collection,
        // then list resources.
        //

        Resource newResource = collection.createResource(null, "BinaryResource");
        newResource.setContent(new byte[] { 0x00, 0x10, 0x01, 0x11 });
        collection.storeResource(newResource);
        String id = newResource.getId();

        String[] resources = collection.listResources();
        assertNotNull("Can not be null", resources);
        assertEquals("Should have one resource", 1, resources.length);
        assertEquals("Resource ID should match", id, resources[0]);
View Full Code Here

    /*
     * Create a binary resource, save it in the 'current' collection,
     * then remove it and verify that it was indeed removed.
     */

        Resource newResource = collection.createResource(null, "BinaryResource");
        newResource.setContent(new byte[] { 0x00, 0x10, 0x01, 0x11 });
    collection.storeResource(newResource);
    String id = newResource.getId();

    Resource foundResource = collection.getResource(id);
    assertNotNull("It should be in there", foundResource);

        collection.removeResource(foundResource);
        foundResource = collection.getResource(id);
        assertNull("It should not be in there anymore", foundResource);
View Full Code Here

                    System.out.println("ERROR : Collection not found!");
                    return false;
                }

                if (table.get(XMLTools.NAME_OF) != null) {
                    Resource colresource = col.getResource((String) table.get(XMLTools.NAME_OF));

                    col.removeResource(colresource);
                    System.out.println("DELETED: " + table.get(XMLTools.COLLECTION) + "/" + table.get(XMLTools.NAME_OF));
                } else {
                    // User did not supply document name
View Full Code Here

    Collection collection = null;
    try {

      collection = getCollection("xmldb:xindice:///db/addressbook");

      Resource document = collection.getResource(args[0]);
      collection.removeResource(document);
      System.out.println("Document " + args[0] + " removed");
    }
    catch (XMLDBException e) {
      System.err.println("XML:DB Exception occured " + e.errorCode + " " + e.getMessage());
View Full Code Here

                // Perform operation
                String result = "failure";
                String message = null;
                if("create".equals(operation)) {
                    try {
                        Resource resource = collection.createResource(key, "XMLResource");
                        resource.setContent(document);
                        collection.storeResource(resource);
                        result = "success";
                    } catch (XMLDBException e) {
                        message = "Failed to create resource " + key + ": " + e.errorCode;
                        getLogger().debug(message, e);
                    }
                } else if("delete".equals(operation)) {
                    try {
                        Resource resource = collection.getResource(this.key);
                        if (resource == null) {
                            message = "Resource " + this.key + " does not exist";
                            getLogger().debug(message);
                        } else {
                            collection.removeResource(resource);
View Full Code Here

    /*
     * Create a binary resource, save it in the 'current' collection,
     * then retrieve it and verify that the data comes back right.
     */

        Resource newResource = collection.createResource(null, "BinaryResource");
        newResource.setContent(new byte[] { 0x00, 0x10, 0x01, 0x11 });
    collection.storeResource(newResource);
    String id = newResource.getId();

    Resource foundResource = collection.getResource(id);

    assertNotNull("We know you're in there...", foundResource);
    assertEquals("The resource type is supposed be 'BinaryResource'", "BinaryResource", foundResource.getResourceType());
    assertTrue("The resource is an instance of BinaryResource", foundResource instanceof BinaryResource);

    byte[] newBytes = (byte[]) newResource.getContent();
    byte[] foundBytes = (byte[]) foundResource.getContent();

    assertEquals("The size of the found and saved resource should be the same...", newBytes.length, foundBytes.length);
    for (int i = 0; i < newBytes.length; ++i) {
      assertEquals("The resources differ in byte " + i, newBytes[i], foundBytes[i]);
    }
View Full Code Here

TOP

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

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.