Package org.apache.xindice.tools.command

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

/*
* 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: DeleteDocument.java 511426 2007-02-25 03:25:02Z vgritsenko $
*/

package org.apache.xindice.tools.command;

import org.apache.xindice.tools.XMLTools;

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

import java.util.Hashtable;

/**
* DeleteDocument.java is designed to let the user delete or drop
* a Document, referred by the Key, from a specific Collection or Nested
* Collection.
*
* @version $Revision: 511426 $, $Date: 2007-02-24 22:25:02 -0500 (Sat, 24 Feb 2007) $
*/
public class DeleteDocument extends Command {

    public boolean execute(Hashtable table) throws Exception {
        Collection col = null;

        try {
            if (table.get(XMLTools.COLLECTION) != 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;
                }

                if (table.get(XMLTools.NAME_OF) != null) {
                    Resource colresource = col.getResource((String) table.get(XMLTools.NAME_OF));

                    col.removeResource(colresource);
                    System.out.println("DELETED: " + table.get(XMLTools.COLLECTION) + "/" + table.get(XMLTools.NAME_OF));
                } else {
                    // User did not supply document name
                    System.out.println("ERROR : Document Key and switch required");
                }

            } else
            // User did not supply collection name
                System.out.println("ERROR : Collection and switch required");

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

        return true;
    }
}
TOP

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

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.