Package org.xmldb.api.modules

Examples of org.xmldb.api.modules.XMLResource


            Database database = (Database) c.newInstance();
            System.out.println("Registring Database " + database);
            DatabaseManager.registerDatabase(database);
            Collection col = database.getCollection(collectionURI);
            System.out.println("Got Collection " + col);
            XMLResource resource = (XMLResource) col.getResource(resourceName);
            System.out.println("Got resource " + resource + " for " + resourceName);
           
            Document doc = (Document)resource.getContentAsDOM();
            System.out.println("Retrieved the Document with root: " + doc.getDocumentElement().getTagName());
            String content = (String)resource.getContent();
            System.out.println("here's the content:\n" + content);
            col.close();
        }
        catch (Exception e) {
            e.printStackTrace();
View Full Code Here


        TransactionService transaction =
           (TransactionService) col.getService("TransactionService", "1.0");

        transaction.begin();

        XMLResource resource1 =
           (XMLResource) col.createResource(id1, XMLResource.RESOURCE_TYPE);

        resource1.setContentAsDOM(document1);
        col.storeResource(resource1);

        XMLResource resource2 =
           (XMLResource) col.createResource(id2, XMLResource.RESOURCE_TYPE);

        resource2.setContentAsDOM(document2);
        col.storeResource(resource2);

        transaction.commit();

   }
View Full Code Here

        if (i.hasMoreResources()) {
          Class c = getManager().getHandlerClass();
          JMHandler handler = (JMHandler) c.newInstance();
          handler.setObserver(pObserver);
          while(i.hasMoreResources()) {
            XMLResource r = (XMLResource) i.nextResource();
            r.getContentAsSAX(handler);
          }
        }
      }
    } catch (IllegalAccessException e) {
      throw new PMException(e);
View Full Code Here

   */
  public void insert(Element pElement) throws PMException {
    try {
      Collection col = getXmlDbCollection();
      String id = getId(pElement);
      XMLResource resource = (XMLResource) col.createResource(id, XMLResource.RESOURCE_TYPE);
      ContentHandler ch = resource.setContentAsSAX();
      Marshaller marshaller = getManager().getFactory().createMarshaller();
      marshaller.marshal(pElement, ch);
      col.storeResource(resource);
    } catch (XMLDBException e) {
      throw new PMException(e);
View Full Code Here

   */
  public void update(Element pElement) throws PMException {
    try {
      Collection col = getXmlDbCollection();
      String id = getId(pElement);
      XMLResource resource = (XMLResource) col.getResource(id);
      ContentHandler ch = resource.setContentAsSAX();
      Marshaller marshaller = getManager().getFactory().createMarshaller();
      marshaller.marshal(pElement, ch);
      col.storeResource(resource);
    } catch (XMLDBException e) {
      throw new PMException(e);
View Full Code Here

   */
  public void delete(Element pElement) throws PMException {
    try {
     Collection col = getXmlDbCollection();
     String id = getId(pElement);
     XMLResource resource = (XMLResource) col.createResource(id, XMLResource.RESOURCE_TYPE);
     col.removeResource(resource);
   } catch (XMLDBException e) {
     throw new PMException(e);
   } catch (IllegalAccessException e) {
     throw new PMException(e);
View Full Code Here

            collection = DatabaseManager.getCollection(col, user, password);
            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 (getLogger().isDebugEnabled()) {
                    getLogger().debug("Querying resource " + res + " from collection " + url + "; query= " + this.query);
                }

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

                xmlResource.getContentAsSAX(handler);
            }
        } catch (XMLDBException xde) {
            String error = "Unable to fetch content. Error "
                           + xde.errorCode + ": " + xde.getMessage();
            throw new SAXException(error, xde);
View Full Code Here

            IncludeXMLConsumer includeHandler = new IncludeXMLConsumer(handler);

            // Print search results
            ResourceIterator results = resultSet.getIterator();
            while (results.hasMoreResources()) {
                XMLResource result = (XMLResource)results.nextResource();

                final String id = result.getId();
                final String documentId = result.getDocumentId();

                attributes.clear();
                if (id != null) {
                    attributes.addAttribute("", RESULT_ID_ATTR, RESULT_ID_ATTR,
                                            CDATA, id);
                }
                if (documentId != null) {
                    attributes.addAttribute("", RESULT_DOCID_ATTR, RESULT_DOCID_ATTR,
                                            CDATA, documentId);
                }

                handler.startElement(URI, RESULT, QRESULT, attributes);
                result.getContentAsSAX(includeHandler);
                handler.endElement(URI, RESULT, QRESULT);
            }

            handler.endElement(URI, RESULTSET, QRESULTSET);
            handler.endPrefixMapping(PREFIX);
View Full Code Here

        try {
            collection = DatabaseManager.getCollection(col, user, password);
            if (collection == null) {
                result = false;
            } else {
                XMLResource xmlResource = (XMLResource) collection.getResource(res);
                if (xmlResource == null) {
                    result = false;
                }
            }
        } catch (XMLDBException xde) {
View Full Code Here

      ResourceIterator i = result.getIterator();
      if (i.hasMoreResources()) {
        JMUnmarshallerHandler handler = (JMUnmarshallerHandler) getManager().getFactory().createUnmarshaller().getUnmarshallerHandler();
        handler.setObserver(pObserver);
        while(i.hasMoreResources()) {
          XMLResource r = (XMLResource) i.nextResource();
          r.getContentAsSAX(handler);
        }
      }
    }
  } catch (XMLDBException e) {
    throw new PMException(e);
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.