Package org.apache.xindice.tools.command

Source Code of org.apache.xindice.tools.command.ListCollections

/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements.  See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License.  You may obtain a copy of the License at
*
*     http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
* $Id: ListCollections.java 578602 2007-09-23 20:33:31Z natalia $
*/

package org.apache.xindice.tools.command;

import org.apache.xindice.tools.XMLTools;

import org.xmldb.api.DatabaseManager;
import org.xmldb.api.base.Collection;

/**
* ListCollections.java is designed to let the user list all Collections from
* a parent Collection or a nested Collection.
*
* NOTE:  Collection names are not returned in any specific order
*
* @version $Revision: 578602 $, $Date: 2007-09-23 16:33:31 -0400 (Sun, 23 Sep 2007) $
*/
public class ListCollections extends Command {

    public boolean execute(XMLTools.Config table) throws Exception {

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

        Collection col = null;
        try {
            // list the COLLECTIONURI + The collection passed in
            String colstring = normalizeCollectionURI(table.getString(XMLTools.COLLECTION),
                                                      table.getBoolean(XMLTools.LOCAL));

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

            String[] 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;
    }

    public void usage() {
        System.out.println("Format: xindice lc  -c <context> [-l [-d <path>]] [-v]");
        System.out.println();
        System.out.println("Lists child collections in a specific collection");
        System.out.println();
    }
}

TOP

Related Classes of org.apache.xindice.tools.command.ListCollections

TOP
Copyright © 2018 www.massapi.com. 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.