ONJava.com -- The Independent Source for Enterprise Java
oreilly.comSafari Books Online.Conferences.

advertisement

AddThis Social Bookmark Button

Storing an XML Document in Apache Xindice
Pages: 1, 2, 3, 4, 5, 6

Configuring Xindice with WebLogic Server

The Xerces parser is required to configure the Xindice 1.1.b4 database. By default, Xindice uses the XML parser configured in the JVM. As the XML parser included in JDK 1.4.2 is the Crimson parser, using Xindice 1.1b4 with JDK 1.4.2 generates the error:



Failed to create SAXParser

org.xml.sax.SAXNotSupportedException: 

Feature: http://xml.org/sax/features/

external-general-entities

Use JDK 5.0 with Xindice 1.1b4. JDK 5.0 includes the Xerces parser. The WebLogic Server 9.0 is used to deploy the Xindice database. You need to use WebLogic version 9.0 instead of 8.1 because version 9.0 supports JDK 5.0.

JDK 1.4.2 may be used with Xindice by adding Xerces implementation classes in Xerces2-j 2.7.1 to the classpath before the Xerces classes in the JDK 1.4.2, via the endorsed standards override mechanism. To use the endorsed standards override mechanism, either define a system property java.endorsed.dirs with the directory in which Xerces2-j is installed (such as <xerces-2_7_1>), or copy the JAR files from the xerces-2_7_1 directory to the <JDK1.4.2>/jre/lib/endorsed directory.

The configuration procedure in this section applies only to WebLogic Server 9.0:

  1. Modify <Xindice>/Xindice-webapp/xindice-1.1b4/xindice-1.1b4.jar to xindice.jar.
  2. Extract the WEB-INF/server.xml configuration file from the xindice.jar file.
  3. In the server.xml file, specify the dbroot attribute value in the root collection element as C:/xindice/db, a directory path in which the Xindice database shall be created.
  4. Delete WEB-INF/system.xml from the xindice.jar file. Add the modified WEB-INF/server.xml to xindice.jar.
  5. Copy the xindice.jar file to the <weblogic>/user_projects/domains/base_domain/autodeploy directory.
  6. Define the JAVA_HOME environment variable as <weblogic>/jdk150_03, where <weblogic> is the directory in which the WebLogic server is installed.
  7. Start the WebLogic server. This starts the Xindice database server in the WebLogic server and opens the default Xindice database, db. The Xindice server web application gets deployed in the WebLogic server. Access the WebLogic server Administration Console with the URL http://localhost:7001/console. Select the base_domain>Deployments node. Select the Xindice web application link and the Testing tab. The Xindice server URL is shown as http://localhost:/7001/xindice.

Creating a Collection in the Database

After configuring the Xindice database server in the WebLogic server, we shall create an Xindice database collection with the command-line tool and the XML:DB API. A collection is a set of XML documents in the Xindice database.

Create a top-level collection, catalog, with the Xindice command:

>xindice ac -c xmldb:xindice://localhost:7001/db -n catalog

The collection context in the example command line command is the db database instance, the default Xindice database instance. The db database may also be referred to as the root collection. This creates the collection catalog in the db database and prints the message:

Created :xmldb:xindice://localhost:7001/db/catalog

The collection created may be deleted with the command:

>xindice dc -c xmldb:xindice://localhost:7001/db -n catalog

This deletes the collection with the message:

Deleted: xmldb:xindice://localhost:7001/db/catalog

Next, we shall create a collection with the XML:DB API. Import the Xindice core server classes and the XML:DB API classes.

import org.apache.xindice.client.xmldb.services.*;
import org.apache.xindice.util.XindiceException;
import org.apache.xindice.xml.dom.*;
import org.xmldb.api.*;
import org.xmldb.api.base.*;
import org.xmldb.api.modules.*;

Create an instance of the Xindice database engine. The XML:DB driver implementation class for the Xindice database is DatabaseImpl. Register the Xindice database with the org.xmldb.api.DatabaseManager, which is used to obtain a collection from a XML:DB database.

String xindiceDriver = 
  "org.apache.xindice.client.xmldb.DatabaseImpl";
org.xmldb.api.base.Database xindiceDatabase = 
  (org.xmldb.api.base.Database)
  ((Class.forName(xindiceDriver)).newInstance());
org.xmldb.api.DatabaseManager.
   registerDatabase(xindiceDatabase);

Next, obtain the db collection from the database.

 String url = "xmldb:xindice://localhost:7001/db";
 org.xmldb.api.base.Collection  collection = 
    DatabaseManager.getCollection(url);

Create a org.apache.xindice.client.xmldb.services.CollectionManager object. A CollectionManager is required to create and delete collections from the database. Specify the XML configuration to create a collection. The XML configurations are not very well documented in Xindice. Create a database collection with the CollectionManager service.

CollectionManager collectionManagerService = 
   (CollectionManager) 
   collection.getService("CollectionManager", "1.0");

String collectionName = "catalog";
String collectionConfig = "<collection compressed=\"true\" " +
  "   name=\"" + collectionName + "\">" +
  " <filer class=\"org.apache.xindice.core.filer.BTreeFiler\"/>" +
  "</collection>";

catalogCollection = 
  collectionManagerService.createCollection
  (collectionName, 
  DOMParser.toDocument(collectionConfig));

This creates collection, catalog in the db database.

Pages: 1, 2, 3, 4, 5, 6

Next Pagearrow