Package org.xmldb.api.modules

Examples of org.xmldb.api.modules.XMLResource


                             itsExpectedResourceCount, aResourceSet.getSize());
            }

            if (itsExpectedResources != null && itsExpectedResources.length > 1) {
                for (int anIndex = 0; anIndex < itsExpectedResources.length / 2; anIndex += 2) {
                    XMLResource aResource = (XMLResource) aResourceSet.getResource(anIndex);
                    Node aNode = aResource.getContentAsDOM();
                    int anExpectedSourceDocumentIndex = ((Integer) itsExpectedResources[anIndex]).intValue();
                    String anExpected = "<?xml version=\"1.0\"?>\n" + addSource((String) itsExpectedResources[anIndex + 1],
                                                                                TEST_DOCUMENT_PREFIX + anIndex,
                                                                                IndexedSearchTest.INDEXED_SEARCH_TEST_COLLECTION_PATH);
                    String anActual = TextWriter.toString(aNode);
View Full Code Here


                                  ser);
            reader.parse(new InputSource(fis));
            fis.close();

            // Create the XMLResource and store the document
            XMLResource resource =
                    (XMLResource) col.createResource((String) table.get(XMLTools.NAME_OF),
                                                     "XMLResource");
            resource.setContent(ser.toString());
            col.storeResource(resource);

            System.out.println("Added document " + table.get(XMLTools.COLLECTION) + "/" +
                               resource.getId());
            resource = null;
        } finally {
            if (col != null) {
                col.close();
            }
View Full Code Here

                    return false;
                }

                if (table.get(XMLTools.NAME_OF) != null) {

                    XMLResource resource = (XMLResource) col.getResource(docname);
                    // Verify that we were able to find the document
                    if (resource == null) {
                        System.out.println("ERROR : Document not found!");
                        return false;
                    }

                    String documentstr = (String) resource.getContent();

                    if ((documentstr != null) && (table.get(XMLTools.FILE_PATH) != "")) {
                        try {
                            File file = new File((String) table.get(XMLTools.FILE_PATH));
                            // Create the directory structure if necessary
View Full Code Here

      collection = getCollection("xmldb:xindice:///db/addressbook");
     
      String data = readFileFromDisk(args[0]);

      XMLResource document = (XMLResource) collection.createResource(null, "XMLResource");
      document.setContent(data);
      collection.storeResource(document);
      System.out.println("Document " + args[0] + " inserted as " + document.getId());
    }
    catch (XMLDBException e) {
      System.err.println("XML:DB Exception occured " + e.errorCode + " " + e.getMessage());
    }
    finally {
View Full Code Here

    Collection collection = null;
    try {

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

      XMLResource xmlResource = (XMLResource) collection.getResource(args[0]);
      if (xmlResource != null) {
        System.out.println("Document " + args[0]);
        System.out.println(xmlResource.getContent());
      }
      else {
        System.out.println("Document not found");
      }
    }
View Full Code Here

            // Create a new person instance to add to Group
            Person person = new Person();

            // Retrieve the next node
            XMLResource resource = (XMLResource) results.nextResource();
            // Cast to Dom Node
            Node originalnode = resource.getContentAsDOM();

            // Get the document key for this node for later use
            String dockey = resource.getDocumentId();
            person.setDocKey(dockey);

            // Use Xalan xpath parser to extract data, store into hastable
            XObject xo = new XObject();
View Full Code Here

            XObject xo = new XObject();
            // Create a new hastable to store into vector
            Hashtable table = new Hashtable();

            // Retrieve the next node
            XMLResource resource = (XMLResource) results.nextResource();
            Node originalnode = resource.getContentAsDOM();

            // Get the document key for this node for later use
            String dockey = resource.getDocumentId();
            table.put("dockey", dockey);

            // Use Xalan xpath parser to extract data, store into hastable
            xo = XPathAPI.eval(originalnode, "/person/fname");
            table.put("fname", xo.toString());
View Full Code Here

         // Create xml string from from values
         ourdoc = toXml(fname,lname,workphone,homephone,cellphone,homeemail,workemail,
                           homeaddress,workaddress);
  
         // Create the XMLResource and store the document
         XMLResource resource = (XMLResource) col.createResource( "", "XMLResource" );
         resource.setContent(ourdoc);
         col.storeResource(resource);
        
      } catch ( Exception e) {
          e.printStackTrace();
View Full Code Here

        xpathservice.setNamespace("h", "http://example.net/person");

        ResourceSet resultSet = xpathservice.query(query);
        assertEquals(1, resultSet.getSize());

        XMLResource resource = (XMLResource) resultSet.getResource(0);

        // ensure that the resource has the correct doc id.
        assertEquals("doc3", resource.getDocumentId());

        Node node = resource.getContentAsDOM();

        // add source node information to the compared xml as it's added by
        // the query processor.
        XMLAssert.assertXMLEqual("<first xmlns:src='http://xml.apache.org/xindice/Query' src:col='/db/testing/current' src:key='doc3' xmlns='http://example.net/person'>Sally</first>",
                                 TextWriter.toString(node));
View Full Code Here

        String query = "//person[first='John' and last='Smith']";

        ResourceSet resultSet = xpathservice.query(query);
        assertEquals(1, resultSet.getSize());

        XMLResource resource = (XMLResource) resultSet.getResource(0);

        String john
                = "<?xml version=\"1.0\"?>"
                + "<person xmlns:src='http://xml.apache.org/xindice/Query' src:col='/db/testing/current' src:key='doc1'>"
                +   "<!-- John Smith -->"
                +   "<first>John</first>"
                +   "<last>Smith</last>"
                +   "<age>30</age>"
                +   "<phone type=\"work\">555-345-6789</phone>"
                + "</person>";

        // ensure that the resource has the correct doc id.
        assertEquals("doc1", resource.getDocumentId());

        XMLAssert.assertXMLEqual(john, TextWriter.toString(resource.getContentAsDOM()));
    }
View Full Code Here

TOP

Related Classes of org.xmldb.api.modules.XMLResource

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.