Package org.xmldb.api.modules

Examples of org.xmldb.api.modules.XMLResource


            fail( e.getMessage( ) );
        }
   }

   private XMLResource insertStringDocument(String id, String document) throws Exception {
        XMLResource res = (XMLResource) col.createResource(id, XMLResource.RESOURCE_TYPE);
        super.assertEquals("LevelZeroTest.testString() - id",res.getId(), id);
        super.assertSame(res.getParentCollection(),col);
        res.setContent(document);
        col.storeResource(res);
        return res;
   }
View Full Code Here


        col.storeResource(res);
        return res;
   }

   private String retrieveTextDocument(String id) throws Exception {
        XMLResource resource = (XMLResource) col.getResource(id);
        return (String)resource.getContent();
    }
View Full Code Here

        XMLResource resource = (XMLResource) col.getResource(id);
        return (String)resource.getContent();
    }

   private void updateStringDocument(String id) throws Exception {
        XMLResource resource = (XMLResource) col.getResource(id);
        String document = (String)resource.getContent();

        //change the XML content
        document = document.toLowerCase();

        resource.setContent(document);
        col.storeResource(resource);
   }
View Full Code Here

        }  
    }
   
    private void insertDOMDocument(String id, Document document) throws Exception {
        
        XMLResource resource = (XMLResource) col.createResource(id, XMLResource.RESOURCE_TYPE);

        resource.setContentAsDOM(document);
        col.storeResource(resource);
              
   }
View Full Code Here

              
   }
   
    private void updateDOMDocument(String id) throws Exception {    
        try {
            XMLResource resource = (XMLResource) col.getResource(id);

            Document document = (Document) resource.getContentAsDOM();
            System.out.println("LevelZeroTest.updateDOMDocument() - " + document);
            assertNotNull("LevelZeroTest.updateDOMDocument()", document);
            Element root = document.getDocumentElement();
            // Change document by appending to an element data

            Text nameNode = document.createTextNode("updateAddition");
            NodeList list = root.getElementsByTagName("testName");
            Node parent = list.item(0);
            parent.appendChild(nameNode);

            // insert a new element
            list = root.getElementsByTagName("levelZeroTests");
            Node levelZeroTests = list.item(0);
            Element testName = document.createElement("testName");
            levelZeroTests.appendChild(testName);
            Node name = document.createTextNode("testSAX");
            testName.appendChild(name);
                    
            resource.setContentAsDOM(document);
            col.storeResource(resource);
            super.assertEquals(document, (Document)resource.getContentAsDOM());
        }
        catch (Exception e) {
            e.printStackTrace();
            throw e;
        }
View Full Code Here

            throw e;
        }
   }
  
   private Node retrieveDOMNode(String id) throws Exception {
        XMLResource resource =
           (XMLResource) col.getResource(id);

        Node node = (Node) resource.getContentAsDOM();
        return node;

   }
View Full Code Here

        return node;

   }
  
   private void retrieveDOMDocument(String id) throws Exception {
        XMLResource resource =
           (XMLResource) col.getResource(id);

        Document doc = (Document) resource.getContentAsDOM();      
    }
View Full Code Here

        }  
    }
   
   private void insertSAXDocument(String id, InputSource source) throws Exception{

        XMLResource resource =
           (XMLResource) col.createResource(id, XMLResource.RESOURCE_TYPE);

        ContentHandler handler = resource.setContentAsSAX();       

        XMLReader reader = XMLReaderFactory.createXMLReader(SAX_PARSER);
        reader.setContentHandler(handler);
        reader.parse(source);
View Full Code Here

        col.storeResource(resource);
              
   }
  
   private void retrieveSAXDocument(String id) throws Exception {
        XMLResource resource = (XMLResource) col.getResource(id);

        // Use the DefaultHandler to handle the SAX events for now (doesn't do anything)
        ContentHandler handle = new DefaultHandler();

        resource.getContentAsSAX(handle);     
   }
View Full Code Here

            //Database database = (Database) c.newInstance();     
            System.out.println("collectionURI is " + collectionURI);
            Collection col = DatabaseManager.getCollection(collectionURI);
            //Collection col = database.getCollection(collectionURI);
            Document doc = parseDocument();
            XMLResource resource = (XMLResource)col.getResource(resourceName);
            if (resource == null) {
                OzoneProxy o = db.objectForName(resourceName);
                if (o != null) {
                    System.out.println("Object found as db oject, deleting it..");
                    db.deleteObject(o);
                }
                System.out.println("resource is null, create the resource with name " + resourceName);
                resource = (XMLResource) col.createResource(resourceName, XMLResource.RESOURCE_TYPE);
            }
            else {
                System.out.println("deleting resource" + resourceName);
                col.removeResource(resource);
                resource = (XMLResource) col.createResource(resourceName, XMLResource.RESOURCE_TYPE);
            }
            System.out.println("Created resource " + resourceName + " with id " + resource.getId());
            // double check to see if it actually works
            resource = (XMLResource)col.getResource(resourceName);
            System.out.println("Resource found with name " + resource.getId());          
            resource.setContentAsDOM(doc);
            System.out.println("Updated content: " + resource.getContent());
            col.storeResource(resource);
            //System.out.println("Stored the following Document:\n" + toString(doc));
            System.out.println("Stored the following Document:\n" + doc.getDocumentElement().getTagName());
            col.close();
            db.close();
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.