xml-xindice-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "David J. Thomson" <dthom...@eecs.tufts.edu>
Subject Re: Sample Code
Date Mon, 24 Feb 2003 15:32:30 GMT
Simon,

First, you set these properties (to your own values):


System.setProperty(
"xindice.home",System.getProperty("user.dir")+fsep+"roots"+fsep+(String)session.get("sphere_id")+fsep+"DB");

System.setProperty("xindice.configuration",System.getProperty("user.dir")+fsep+"system.xml");



Then, you initialize the database:


Database maindb = null;
Collection sc = null;

try {
         String driver =
"org.apache.xindice.client.xmldb.embed.DatabaseImpl";
         Class c = Class.forName(driver);

         maindb = (Database) c.newInstance();
         DatabaseManager.registerDatabase(maindb);



	   sc =
DatabaseManager.getCollection("xmldb:xindice-embed:///db/suprasphere");

      }catch (XMLDBException e) {
         System.err.println("XML:DB Exception occured " + e.errorCode);
      }
      catch (InstantiationException ie) {
	      System.err.println("ie");
      }
      catch (ClassNotFoundException cnfe) {
	      System.err.println("cnfe");
      }
      catch (IllegalAccessException iae) {
	      System.err.println("iae");
      }


Then, you use it (this has some specifics to the XML parser I'm using):


public Vector getAll() {


		Vector all = new Vector();
		String apath = "//*";


      try {


	       String[] docs = sc.listResources();

	    for (int i=0;i<docs.length;i++) {

	    XMLResource res = (XMLResource) sc.getResource(docs[i]);

	 DocumentHelper df = new DocumentHelper();

	 try {

	 Document document = df.parseText(((String)res.getContent()));


	    all.add(document);

	 } catch (DocumentException de) {}

         }



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



	return all;

	}


Please let me know if you have any more specific questions, or any
questions about the code above. I have code to
add/remove/replace/query/search document(s), but not much dealing with
XUpdate.

-David


On 24 Feb 2003, Simon Farrow wrote:

> Having had a little root around in my code and discovered a few other
> errors with my use of embedded Xindice. I'm going to broaden the scope
> of my original question. Does anyone have any sample code for setting up
> and dealing with embedded Xindice?
>
> Simon.
>
>


Mime
View raw message