Package org.xmldb.api.base

Examples of org.xmldb.api.base.Collection


        service.createIndexer(DOMParser.toDocument(indexdef));
    }

    public String[] listIndexes(String path) throws Exception {
        Collection col = DatabaseManager.getCollection(driver + "/" + path);
        if (col == null) {
            throw new XindiceException("DatabaseManager.getCollection(" + driver + "/" + path + ") returned null");
        }
        CollectionManager service = (CollectionManager) col.getService("CollectionManager", "1.0");

        return service.listIndexers();
    }
View Full Code Here


        return service.listIndexers();
    }

    public void dropIndexer(String path, String name) throws Exception {
        Collection col = DatabaseManager.getCollection(driver + "/" + path);
        if (col == null) {
            throw new XindiceException("DatabaseManager.getCollection(" + driver + "/" + path + ") returned null");
        }
        CollectionManager service = (CollectionManager) col.getService("CollectionManager", "1.0");

        service.dropIndexer(name);
    }
View Full Code Here

        service.dropIndexer(name);
    }

    public void insertDocument(String path, String name, String doc) throws Exception {
        Collection col = DatabaseManager.getCollection(driver + "/" + path);
        if (col == null) {
            throw new XindiceException("DatabaseManager.getCollection(" + driver + "/" + path + ") returned null");
        }

        XMLResource document = (XMLResource) col.createResource(name, "XMLResource");
        document.setContent(doc);
        col.storeResource(document);
    }
View Full Code Here

        document.setContent(doc);
        col.storeResource(document);
    }

    public int countDocument(String path) throws Exception {
        Collection col = DatabaseManager.getCollection(driver + "/" + path);
        if (col == null) {
            throw new XindiceException("DatabaseManager.getCollection(" + driver + "/" + path + ") returned null");
        }

        return col.getResourceCount();
    }
View Full Code Here

        return col.getResourceCount();
    }

    public String getDocument(String path, String name) throws Exception {
        Collection col = DatabaseManager.getCollection(driver + "/" + path);
        if (col == null) {
            throw new XindiceException("DatabaseManager.getCollection(" + driver + "/" + path + ") returned null");
        }
        XMLResource document = (XMLResource) col.getResource(name);

        if (document == null) {
            return null;
        }
View Full Code Here

        return document.getContent().toString();
    }

    public void updateDocument(String path, String name, String doc) throws Exception {
        Collection col = DatabaseManager.getCollection(driver + "/" + path);
        if (col == null) {
            throw new XindiceException("DatabaseManager.getCollection(" + driver + "/" + path + ") returned null");
        }
        XMLResource document = (XMLResource) col.getResource(name);
        document.setContent(doc);
        col.storeResource(document);
    }
View Full Code Here

        document.setContent(doc);
        col.storeResource(document);
    }

    public void getDocumentAsSax(String path, String name, ContentHandler handler) throws Exception {
        Collection col = DatabaseManager.getCollection(driver + "/" + path);
        if (col == null) {
            throw new XindiceException("DatabaseManager.getCollection(" + driver + "/" + path + ") returned null");
        }
        XMLResource document = (XMLResource) col.getResource(name);

        if (document == null) {
            return;
        }
View Full Code Here

        document.getContentAsSAX(handler);
    }


    public String[] listDocuments(String path) throws Exception {
        Collection col = DatabaseManager.getCollection(driver + "/" + path);
        return col.listResources();
    }
View Full Code Here

        Collection col = DatabaseManager.getCollection(driver + "/" + path);
        return col.listResources();
    }

    public void removeDocument(String path, String name) throws Exception {
        Collection col = DatabaseManager.getCollection(driver + "/" + path);
        if (col == null) {
            throw new XindiceException("DatabaseManager.getCollection(" + driver + "/" + path + ") returned null");
        }
        XMLResource document = (XMLResource) col.getResource(name);

        col.removeResource(document);
    }
View Full Code Here

*/
public class AddMultipleDocuments extends Command {

    public boolean execute(Hashtable table) throws Exception {

        Collection col = null;
        try {

            // Verify that user has supplied necessary arguments
            if (table.get(XMLTools.COLLECTION) == null) {
                System.out.println("ERROR : Collection and switch required");
                return false;
            }

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

            // Get a Collection reference to the collection
            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 collection
            // CollectionManager colman = (CollectionManager)col.getService("CollectionManager",XMLDBAPIVERSION);

            // Get a File object for the Directory passed in
            File dir = new File((String) table.get(XMLTools.FILE_PATH));

            if (dir.isDirectory()) {

                String[] children = new String[]{};
                final String ext = (String) table.get(XMLTools.EXTENSION);

                // If the user supplied a file extension, filter on it, else use entire contents of the directory
                if (!ext.equals("")) {

                    children = dir.list(new FilenameFilter() {
                        public boolean accept(File none, String name) {
                            return name.endsWith("." + ext);
                        }
                    });
                } else if (ext.equals("")) {
                    children = dir.list();
                }

                System.out.println("Reading files from: " + dir.getName());

                // Loop over documents, adding to db
                for (int i = 0; i < children.length; i++) {

                    File files = new File(dir, children[i]);

                    if (files.isFile()) {
                        FileInputStream insr = new FileInputStream(files);
                        byte[] fileBuffer = new byte[(int) files.length()];
                        insr.read(fileBuffer);

                        try {

                            // Use the functionality already provided in Command.AddDocument to add this document
                            Command cmd = (Command) Class.forName("org.apache.xindice.tools.command.AddDocument").newInstance();
                            Hashtable localtable = new Hashtable();
                            String filepath = dir.getPath() + "/" + files.getName();

                            // Populate hashtable to pass to AddDocument class
                            localtable.put(XMLTools.COLLECTION, table.get(XMLTools.COLLECTION));
                            localtable.put(XMLTools.NAME_OF, files.getName());
                            localtable.put(XMLTools.FILE_PATH, filepath);

                            // Execute the class!
                            cmd.execute(localtable);

                        } catch (Exception e) {
                            System.out.println("Error Adding File: " + files.getName());
                            //System.out.println(e);
                            continue;
                        }
                    } else
                        continue;
                } // for loop
            }

        } finally {
            // Release all resources
            if (col != null) {
                col.close();
            }
        }

        return true;
    }
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.