KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > test > xmldb > levelzero > SAXTest


1 // You can redistribute this software and/or modify it under the terms of
2
// the Ozone Library License version 1 published by ozone-db.org.
3
//
4
// The original code and portions created by SMB are
5
// Copyright (C) 1997-@year@ by SMB GmbH. All rights reserved.
6
//
7

8 package test.xmldb.levelzero;
9
10 import test.xmldb.*;
11 import junit.framework.*;
12
13 import org.xmldb.api.modules.TransactionService;
14 import org.xmldb.api.modules.BinaryResource;
15
16 import org.xml.sax.ContentHandler JavaDoc;
17 import org.xml.sax.XMLReader JavaDoc;
18 import org.xml.sax.helpers.XMLReaderFactory JavaDoc;
19 import org.xml.sax.helpers.DefaultHandler JavaDoc;
20 import org.xml.sax.InputSource JavaDoc;
21
22 import org.xmldb.api.modules.XMLResource;
23 import org.apache.log4j.Logger;
24
25 /**
26  * @author Per Nyfelt
27  */

28 public class SAXTest extends XMLDBTestCase implements LevelZeroTestConstants {
29
30     Logger logger = Logger.getLogger(SAXTest.class);
31
32     private final String JavaDoc SAX_PARSER = "org.apache.xerces.parsers.SAXParser";
33     /** Creates new SAXTest */
34     public SAXTest(String JavaDoc name) {
35         super(name);
36     }
37     
38     public static Test suite() {
39         return new TestSuite(SAXTest.class);
40     }
41
42     /**
43      * test all scenarios for using XML as SAX
44      */

45     public void testSAX() {
46         try {
47             logger.debug("\nLevelZeroTest.testSAX() - started\n");
48             insertSAXDocument(id, new InputSource JavaDoc(xmlFileName));
49             retrieveSAXDocument(id);
50     
51         } catch (Exception JavaDoc e) {
52             fail( e.getMessage( ) );
53         }
54     }
55     
56    private void insertSAXDocument(String JavaDoc id, InputSource JavaDoc source) throws Exception JavaDoc{
57
58         XMLResource resource =
59            (XMLResource) col.createResource(id, XMLResource.RESOURCE_TYPE);
60
61         ContentHandler JavaDoc handler = resource.setContentAsSAX();
62
63         XMLReader JavaDoc reader = XMLReaderFactory.createXMLReader(SAX_PARSER);
64         reader.setContentHandler(handler);
65         reader.parse(source);
66
67         col.storeResource(resource);
68                
69    }
70    
71    private void retrieveSAXDocument(String JavaDoc id) throws Exception JavaDoc {
72         XMLResource resource = (XMLResource) col.getResource(id);
73
74         // Use the DefaultHandler to handle the SAX events for now (doesn't do anything)
75
ContentHandler JavaDoc handle = new DefaultHandler JavaDoc();
76
77         resource.getContentAsSAX(handle);
78    }
79    
80    private void updateSAXDocument() throws Exception JavaDoc {
81        throw new Exception JavaDoc("LevelZeroTest.updateSAXDocument() - Not implemented yet");
82    }
83 }
84
Popular Tags