i know how to get ChildCollections and built collection tree
but also i have to get documents stores in particular collections. There are methods like getDocumentsCount() and listDocuments() in org.apache.xindice.core.Collection class but this class isn`t work with org.xmldb.api.DatabaseManager so i cant register database. Maybe there is another way to register database using org.apache.xindice.core.Collection class? or there is another way to listDocumetns and count their number??

DBConnection.java
package praca.app;



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



public final class DBConnection
{
 public String addressIP;
 public String port;
 protected static Database db = null;




 Database getDB() throws Exception
 {

    try
 {
db = (Database)Class.forName("org.apache.xindice.client.xmldb.DatabaseImpl").newInstance();
    DatabaseManager.registerDatabase(db);
 }
    catch(Exception e)
 {
     System.out.println(e.getMessage());
     e.printStackTrace();
 }
   return db;
 }


}

CollectionTree.java
import org.xmldb.api.DatabaseManager;
import org.xmldb.api.base.Collection;
import org.xmldb.api.base.Database;

//import org.apache.xindice.client.xmldb.DatabaseImpl;
//import org.apache.xindice.core.Collection;
//import org.apache.xindice.core.Database;

public class CollectionTree
{
   public static  Database db = null;
public static final String XINDICEURI="xmldb:xindice://localhost:8080/db/";
   protected static Collection collection;
   static int errorCode = 0;
static int okCode = 1;
static int liczbaSpacji = 0;

public static void ileSpacji(int liczba)
{
 if (liczba>0)
 {
   for (int i=0; i<liczba; i++)
    System.out.print("  ");
 }
}

   public static int treeCreate(Collection kolekcja) throws Exception
   {

    int  liczbaKolekcji = (int)kolekcja.getChildCollectionCount();
    //int  liczbaDokumentow = (int)kolekcja.getDocumentCount();

    if (liczbaKolekcji > 0)
     {
       String tablica[] = new String[liczbaKolekcji];
       tablica = kolekcja.listChildCollections();

       for (int i=0; i<liczbaKolekcji; i++)
       {
        ileSpacji(liczbaSpacji);
        System.out.println("<"+tablica[i]+">");
        liczbaSpacji++;
        treeCreate(kolekcja.getChildCollection(tablica[i]));
        liczbaSpacji--;
        ileSpacji(liczbaSpacji);
        kolekcja.getClass();
        /*if (liczbaDokumentow > 0)
        {
         String tablicaDok[] = new String[liczbaDokumentow];
          tablicaDok = kolekcja.listDocuments();
          for (int j=0; j<liczbaDokumentow; j++)
            {
           System.out.println("<DOC "+tablicaDok[j]+" /");
            }
        }
        */
        System.out.println("</"+tablica[i]+">");

       }

     }
    else
         return errorCode;
    return okCode;
   }
   public static void main(String[] args) throws Exception
{



 try
 {
   DBConnection dbcon = new DBConnection();
   db = dbcon.getDB();
   collection = DatabaseManager.getCollection(XINDICEURI);

 }
 catch(Exception e)
 {
  System.err.println("XML:DB Exception occured " +
         e.getMessage());
  e.printStackTrace();
 }


 if (collection.getChildCollectionCount() > 0)
  treeCreate(collection);

}

}


Reply via email to