ehatcher 2004/01/11 06:12:19
Modified:
contributions/XML-Indexing-Demo/src/java/org/apache/lucenesandbox/xmlindexingdemo
XMLDocumentHandlerDOM.java
XMLDocumentHandlerSAX.java
Added: contributions/XML-Indexing-Demo build.xml
Log:
build and code cleanup
Revision Changes Path
1.1 jakarta-lucene-sandbox/contributions/XML-Indexing-Demo/build.xml
Index: build.xml
===================================================================
<?xml version="1.0"?>
<project name="xml" default="default">
<description>
Example of Lucene XML indexing
</description>
<import file="../common.xml"/>
</project>
1.2 +33 -47
jakarta-lucene-sandbox/contributions/XML-Indexing-Demo/src/java/org/apache/lucenesandbox/xmlindexingdemo/XMLDocumentHandlerDOM.java
Index: XMLDocumentHandlerDOM.java
===================================================================
RCS file:
/home/cvs/jakarta-lucene-sandbox/contributions/XML-Indexing-Demo/src/java/org/apache/lucenesandbox/xmlindexingdemo/XMLDocumentHandlerDOM.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- XMLDocumentHandlerDOM.java 21 Jun 2002 15:02:51 -0000 1.1
+++ XMLDocumentHandlerDOM.java 11 Jan 2004 14:12:19 -0000 1.2
@@ -10,49 +10,38 @@
/**
*
*/
-public class XMLDocumentHandlerDOM
-{
- public org.apache.lucene.document.Document createXMLDocument(File f)
- {
- org.apache.lucene.document.Document document = new
org.apache.lucene.document.Document();
- DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
- try
- {
- DocumentBuilder df = dbf.newDocumentBuilder();
- org.w3c.dom.Document d = df.parse(f);
- Node root = d.getDocumentElement();
- traverseTree(root, document);
- }
- catch (Exception e)
- {
- System.out.println("error: " + e);
- e.printStackTrace();
- }
- return document;
+public class XMLDocumentHandlerDOM {
+ public org.apache.lucene.document.Document createXMLDocument(File f) {
+ org.apache.lucene.document.Document document = new
org.apache.lucene.document.Document();
+ DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
+ try {
+ DocumentBuilder df = dbf.newDocumentBuilder();
+ org.w3c.dom.Document d = df.parse(f);
+ Node root = d.getDocumentElement();
+ traverseTree(root, document);
+ } catch (Exception e) {
+ System.out.println("error: " + e);
+ e.printStackTrace();
}
+ return document;
+ }
- static private void traverseTree(Node node, org.apache.lucene.document.Document
document)
- {
- NodeList nl = node.getChildNodes();
- if (nl.getLength() == 0)
- {
- if (node.getNodeType() == Node.TEXT_NODE)
- {
- Node parentNode = node.getParentNode();
- if (parentNode.getNodeType() == Node.ELEMENT_NODE)
- {
- String parentNodeName = parentNode.getNodeName();
+ static private void traverseTree(Node node, org.apache.lucene.document.Document
document) {
+ NodeList nl = node.getChildNodes();
+ if (nl.getLength() == 0) {
+ if (node.getNodeType() == Node.TEXT_NODE) {
+ Node parentNode = node.getParentNode();
+ if (parentNode.getNodeType() == Node.ELEMENT_NODE) {
+// String parentNodeName = parentNode.getNodeName();
// String nodeValue = node.getNodeValue();
// if (parentNodeName.equals("name"))
// {
- Node siblingNode = node.getNextSibling();
- if (siblingNode != null)
- {
- if (siblingNode.getNodeType() == Node.CDATA_SECTION_NODE)
- {
- document.add(Field.Text("name",
siblingNode.getNodeValue()));
- }
- }
+ Node siblingNode = node.getNextSibling();
+ if (siblingNode != null) {
+ if (siblingNode.getNodeType() == Node.CDATA_SECTION_NODE) {
+ document.add(Field.Text("name", siblingNode.getNodeValue()));
+ }
+ }
// }
// else if (parentNodeName.equals("profession"))
// {
@@ -131,15 +120,12 @@
// }
// }
// }
- }
- }
- }
- else
- {
- for(int i=0; i<nl.getLength(); i++)
- {
- traverseTree(nl.item(i), document);
- }
}
+ }
+ } else {
+ for (int i = 0; i < nl.getLength(); i++) {
+ traverseTree(nl.item(i), document);
+ }
}
+ }
}
1.2 +40 -49
jakarta-lucene-sandbox/contributions/XML-Indexing-Demo/src/java/org/apache/lucenesandbox/xmlindexingdemo/XMLDocumentHandlerSAX.java
Index: XMLDocumentHandlerSAX.java
===================================================================
RCS file:
/home/cvs/jakarta-lucene-sandbox/contributions/XML-Indexing-Demo/src/java/org/apache/lucenesandbox/xmlindexingdemo/XMLDocumentHandlerSAX.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- XMLDocumentHandlerSAX.java 21 Jun 2002 15:02:51 -0000 1.1
+++ XMLDocumentHandlerSAX.java 11 Jan 2004 14:12:19 -0000 1.2
@@ -1,8 +1,6 @@
package org.apache.lucenesandbox.xmlindexingdemo;
import org.xml.sax.*;
-import org.xml.sax.helpers.*;
-import org.xml.sax.AttributeList;
import javax.xml.parsers.*;
import org.apache.lucene.document.Document;
@@ -12,51 +10,44 @@
import java.io.IOException;
public class XMLDocumentHandlerSAX
- extends HandlerBase
-{
- /** A buffer for each XML element */
- private StringBuffer elementBuffer = new StringBuffer();
-
- private Document mDocument;
-
- // constructor
- public XMLDocumentHandlerSAX(File xmlFile)
- throws ParserConfigurationException, SAXException, IOException
- {
- SAXParserFactory spf = SAXParserFactory.newInstance();
-
- SAXParser parser = spf.newSAXParser();
- parser.parse(xmlFile, this);
- }
-
- // call at document start
- public void startDocument()
- {
- mDocument = new Document();
- }
-
- // call at element start
- public void startElement(String localName, AttributeList atts)
- throws SAXException
- {
- elementBuffer.setLength(0);
- }
-
- // call when cdata found
- public void characters(char[] text, int start, int length)
- {
- elementBuffer.append(text, start, length);
- }
-
- // call at element end
- public void endElement(String localName)
- throws SAXException
- {
- mDocument.add(Field.Text(localName, elementBuffer.toString()));
- }
-
- public Document getDocument()
- {
- return mDocument;
- }
+ extends HandlerBase {
+ /** A buffer for each XML element */
+ private StringBuffer elementBuffer = new StringBuffer();
+
+ private Document mDocument;
+
+ // constructor
+ public XMLDocumentHandlerSAX(File xmlFile)
+ throws ParserConfigurationException, SAXException, IOException {
+ SAXParserFactory spf = SAXParserFactory.newInstance();
+
+ SAXParser parser = spf.newSAXParser();
+ parser.parse(xmlFile, this);
+ }
+
+ // call at document start
+ public void startDocument() {
+ mDocument = new Document();
+ }
+
+ // call at element start
+ public void startElement(String localName, AttributeList atts)
+ throws SAXException {
+ elementBuffer.setLength(0);
+ }
+
+ // call when cdata found
+ public void characters(char[] text, int start, int length) {
+ elementBuffer.append(text, start, length);
+ }
+
+ // call at element end
+ public void endElement(String localName)
+ throws SAXException {
+ mDocument.add(Field.Text(localName, elementBuffer.toString()));
+ }
+
+ public Document getDocument() {
+ return mDocument;
+ }
}
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]