Package org.xmldb.api.modules

Examples of org.xmldb.api.modules.XMLResource


        set.setAttribute("xmlns:xapi", RESOURCE_SET_NS);
        doc.appendChild(set);

        int i = 0;
        while (i < resources.size()) {
            XMLResource res = (XMLResource) resources.get(i);
            Element resource = doc.createElementNS(RESOURCE_SET_NS,
                                                   "xapi:resource");
            resource.setAttributeNS(RESOURCE_SET_NS, "xapi:documentID",
                                    res.getDocumentId());

            resource.appendChild(doc.importNode(
                    ((Document) res.getContentAsDOM()).getDocumentElement(), true));

            set.appendChild(resource);

            i++;
        }
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");
            }
        } catch (XMLDBException e) {
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

         // Create xml string from form values
         ourdoc = toXml(fname,lname,workphone,homephone,cellphone,homeemail,workemail,
                           homeaddress,workaddress);
     
         // Get the XMLResource and replace the content
         XMLResource resource = (XMLResource) col.getResource(dockey);
         resource.setContent(ourdoc);
         col.storeResource(resource);
        
      } catch ( Exception e) {
         e.printStackTrace();
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

            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 "
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, RESULT);
            }

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

        // Create an XObject to be used in Xpath query
        xo = new XObject();

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

        originalnode = resource.getContentAsDOM();

      }
      catch (Exception e) {
        getLogger ().debug ("DBXMLAUTH: error creating XObject ");
      }
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);
            try {
                result.getContentAsSAX(includeHandler);
            } catch(XMLDBException xde) {
                // That may be a text-only result
                Object content = result.getContent();
                if (content instanceof String) {
                    String text = (String)content;
                    handler.characters(text.toCharArray(), 0, text.length());
                } else {
                    // Cannot do better
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.