Package org.xmldb.api.base

Examples of org.xmldb.api.base.Collection


    public void testGetCollectionUnknown() throws Exception {
        assertNull(this.client.getCollection(TEST_COLLECTION_PATH + "/unknown"));
    }

    public void testChildCollectionCount() throws Exception {
        Collection col = this.client.createCollection(TEST_COLLECTION_PATH, "childcol");
        assertEquals(0, col.getChildCollectionCount());

        this.client.createCollection(TEST_COLLECTION_PATH, "colcount");
        assertEquals(0, col.getChildCollectionCount());

        this.client.dropCollection(TEST_COLLECTION_PATH, "colcount");
        assertEquals(0, col.getChildCollectionCount());
    }
View Full Code Here


public class EditContact extends Action {

   public boolean edit(HttpServletRequest request, HttpServletResponse response )
         throws ServletException, IOException {
        
      Collection col = null;
      String ourdoc = null;
     
      try {
        
         // Get the collection instance
         col = getCollection(request,response);
        
         // Grab all parameters from form, store as strings
         String dockey = request.getParameter("DOCKEY");
         String fname = request.getParameter("FNAME");
         String lname = request.getParameter("LNAME");
         String workphone = request.getParameter("WORKPHONE");
         String homephone = request.getParameter("HOMEPHONE");
         String cellphone = request.getParameter("CELLPHONE");
         String homeemail = request.getParameter("HOMEEMAIL");
         String workemail = request.getParameter("WORKEMAIL");
         String homeaddress = request.getParameter("HOMEADDRESS");
         String workaddress = request.getParameter("WORKADDRESS");
        
        
         // 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();

    // there's not much else we can do if the response is committed
View Full Code Here

*/
public class ListCollectionDocuments extends Command {

    public boolean execute(Hashtable table) throws Exception {

        Collection col = null;
        String colstring = null;
        String[] documentarray = null;
        try {

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

                // Create a collection instance
                colstring = normalizeCollectionURI((String) table.get(XMLTools.COLLECTION),
                                                   (String) table.get(XMLTools.LOCAL));

                col = DatabaseManager.getCollection(colstring);
                if (col == null) {
                    System.out.println("ERROR : Collection not found!");
                    return false;
                }
                documentarray = col.listResources();

                System.out.println();

                for (int i = 0; i < documentarray.length; i++) {
                    System.out.println("\t" + documentarray[i]);
                }

                System.out.println("\nTotal documents: " + documentarray.length);
            } else
                System.out.println("ERROR : Collection and switch required");

        } finally {
            // Release the collection object
            if (col != null) {
                col.close();
            }
        }

        return true;
    }
View Full Code Here

*/
public class DeleteCollection extends Command {

    public boolean execute(Hashtable table) throws Exception {

        Collection col = null;
        try {
            // Verify that the collection passed in is not null
            if (table.get(XMLTools.COLLECTION) != null && table.get(XMLTools.NAME_OF) != null) {

                // Get a Collection reference to the collection to be deleted
                String colstring = normalizeCollectionURI((String) table.get(XMLTools.COLLECTION),
                                                          (String) table.get(XMLTools.LOCAL));
                col = DatabaseManager.getCollection(colstring);
                if (col == null) {
                    System.out.println("ERROR : Collection not found!");
                    return false;
                }

                // Create a collection manager instance for the parent of the collection
                CollectionManager colman = (CollectionManager) col.getService("CollectionManager", XMLDBAPIVERSION);

                // Drop the collection
                colman.dropCollection((String) table.get(XMLTools.NAME_OF));

                System.out.println("Deleted: " + table.get(XMLTools.COLLECTION) + "/" + (String) table.get(XMLTools.NAME_OF));
            } else
                System.out.println("Error : Collection Context and Name required");

        } finally {
            if (col != null) {
                col.close();
            }
        }

        return true;
    }
View Full Code Here

    private static final Log log = LogFactory.getLog(XPathQuery.class);

    public boolean execute(Hashtable table) throws Exception {

        Collection col = null;
        try {
            if ((String) table.get(XMLTools.COLLECTION) == null) {
                System.out.println("ERROR : Collection name and switch required");
                return false;
            }

            if ((String) table.get(XMLTools.QUERY) == "") {
                System.out.println("ERROR : Query and switch required");
                return false;
            }

            String colstring = normalizeCollectionURI((String) table.get(XMLTools.COLLECTION), (String) table.get(XMLTools.LOCAL));
            String querystring = (String) table.get(XMLTools.QUERY);
            XPathQueryService service = null;
            ResourceIterator results = null;

            col = DatabaseManager.getCollection(colstring);

            if (col == null) {
                System.out.println("ERROR : Collection not found!");
                return false;
            }

            service = (XPathQueryService) col.getService("XPathQueryService", "1.0");
            addNamespaces(service, (String) table.get("namespaces"));

            ResourceSet resultSet = service.query(querystring);
            results = resultSet.getIterator();

            while (results.hasMoreResources()) {
                XMLResource resource = (XMLResource) results.nextResource();
                String documentstr = (String) resource.getContent();
                System.out.println(documentstr);
            }

        } catch (Exception e) {
            System.out.println("ERROR : " + e.getMessage());
            if (table.get(XMLTools.VERBOSE).equals("true")) {
                if (log.isWarnEnabled()) {
                    log.warn("ignored exception", e);
                }
            }
            return false;

        } finally {
            if (col != null) {
                col.close();
            }
        }

        return true;
    }
View Full Code Here

    private static final Log log = LogFactory.getLog(XUpdate.class);

    public boolean execute(Hashtable table) throws Exception {

        Collection col = null;
        try {

            if ((String) table.get(XMLTools.COLLECTION) == null) {
                System.out.println("ERROR : Collection name and switch required");
                return false;
            }

            if ((String) table.get(XMLTools.FILE_PATH) == "") {
                System.out.println("ERROR : Path to file containing XUpdate to execute required");
                return false;
            }

            String name = (String) table.get(XMLTools.NAME_OF);
           
            // Nomalize the collection URI
            String colstring = normalizeCollectionURI((String) table.get(XMLTools.COLLECTION),
                                                      (String) table.get(XMLTools.LOCAL));

            // Read in the XUpdate commands from the file
            StringBuffer commands = new StringBuffer();
            File file = new File((String) table.get(XMLTools.FILE_PATH));

            BufferedReader reader = new BufferedReader(new InputStreamReader(new FileInputStream(file), "UTF-8"));
            String line;
            while ((line = reader.readLine()) != null) {
                commands.append(line);
            }

            reader.close();

            // Get the collection reference for the requested collection
            col = DatabaseManager.getCollection(colstring);
            if (col == null) {
                System.out.println("ERROR : Collection not found!");
                return false;
            }

            // To run XUpdate commands we use the XUpdateQueryService
            XUpdateQueryService service = null;           
            service = (XUpdateQueryService) col.getService("XUpdateQueryService", "1.0");

           
            long result = 0;

            // See if we're updating one document or the whole collection.
            if (name == null) {
                result = service.update(commands.toString());
            }
            else {
                result = service.updateResource(name, commands.toString());
            }
               

            System.out.println(result + " documents updated");

        } catch (Exception e) {
            System.out.println("ERROR : " + e.getMessage());
            if (table.get(XMLTools.VERBOSE).equals("true")) {
                if (log.isWarnEnabled()) {
                    log.warn("ignored exception", e);
                }
            }
            return false;

        } finally {
            if (col != null) {
                col.close();
            }
        }

        return true;
    }
View Full Code Here

     * @param table Description of Parameter
     * @return Description of the Returned Value
     */
    public boolean execute(Hashtable table) throws Exception {

        Collection col = null;

        if (table.get(XMLTools.FILE_PATH).equals("")) {
            System.out.println("ERROR: Directory name and switch required");
            return false;
        }
View Full Code Here

    Command addDocument = null;
    Command addCollection = null;

    public boolean execute(Hashtable table) throws Exception {

        Collection col = null;
        try {
            // Setup the creation commands we'll use to add documents and create
            // collections.
            addDocument =
                    (Command) Class.forName("org.apache.xindice.tools.command.AddDocument").newInstance();

            addCollection =
                    (Command) Class.forName("org.apache.xindice.tools.command.AddCollection").newInstance();

            String startcollection = null;

            // Verify that the correct command line parameters were passed in
            if (table.get(XMLTools.FILE_PATH) == null) {
                System.out.println("ERROR : Directory name and switch required");
                return false;
            }
            if (table.get(XMLTools.COLLECTION) == null) {
                System.out.println("ERROR : Collection name and switch required");
                return false;
            }

            startcollection = (String) table.get(XMLTools.COLLECTION);

            // Make sure the root collection exists
            String colstring = normalizeCollectionURI(startcollection,
                                                      (String) table.get(XMLTools.LOCAL));
            if ((col = DatabaseManager.getCollection(colstring)) == null) {
                System.out.println("ERROR : Collection not found!");
                return false;
            }

            File startdir = new File((String) table.get(XMLTools.FILE_PATH));

            // Make call to process, this is called recursively!
            process(startdir, colstring, table);

        } finally {
            // Be sure to close collection objects
            if (col != null) {
                col.close();
            }
        }

        return true;
    }
View Full Code Here

    public boolean execute(Hashtable table) throws Exception {

        String[] colarray = null;
        String colstring = null;
        Collection col = null;
        try {

            if (table.get(XMLTools.COLLECTION) == null) {
                System.out.println("ERROR : Collection context required");
                return false;
            }

            // list the COLLECTIONURI + The collection passed in
            colstring = normalizeCollectionURI((String) table.get(XMLTools.COLLECTION),
                                               (String) table.get(XMLTools.LOCAL));



            // Get a Collection reference
            col = DatabaseManager.getCollection(colstring);
            if (col == null) {
                // log a debug message
                log.debug("Error fetching collection '" + colstring + "'");
                System.out.println("ERROR : Collection not found!");
                return false;
            } else {
                colarray = col.listChildCollections();

                System.out.println();

                for (int i = 0; i < colarray.length; i++) {
                    System.out.println("\t" + colarray[i]);
                }

                System.out.println("\nTotal collections: " + colarray.length);
            }
        } finally {
            // Close collection objects and release
            if (col != null) {
                col.close();
            }
        }
        return true;
    }
View Full Code Here

        super.tearDown();
    }

    public void testMetaServicePresent() throws Exception {
        // Get meta service
        Collection col = this.client.getCollection(TEST_COLLECTION_PATH);
        MetaService service = (MetaService) col.getService("MetaService", "1.0");
        assertNotNull("MetaService is not found!", service);
    }
View Full Code Here

TOP

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

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.