package org.apache.xindice.examples;
/*
* 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 511428 2007-02-25 03:30:52Z vgritsenko $
*/
import org.xmldb.api.base.Collection;
import org.xmldb.api.base.XMLDBException;
/**
* Simple XML:DB API example to list collections.
*/
public class ListCollections extends AbstractExample {
public static void main(String[] args) throws Exception {
Collection collection = null;
try {
collection = getCollection("xmldb:xindice://localhost:8888/db/");
//collection = getCollection("xmldb:xindice-embed:///db/");
String[] childCollections = collection.listChildCollections();
System.out.println("Children of collection [" + collection.getName() + "]");
for (int i = 0; i < childCollections.length; i++) {
System.out.println("\t" + (i + 1) + ". " + childCollections[i]);
}
} catch (XMLDBException e) {
System.err.println("XML:DB Exception occured " + e.errorCode + " " + e.getMessage());
e.printStackTrace();
} catch (Exception e) {
System.err.println("Exception occured " + e);
e.printStackTrace();
} finally {
if (collection != null) {
collection.close();
}
}
}
}