01: // You can redistribute this software and/or modify it under the terms of
02: // the Ozone Library License version 1 published by ozone-db.org.
03: //
04: // The original code and portions created by SMB are
05: // Copyright (C) 1997-@year@ by SMB GmbH. All rights reserved.
06: //
07:
08: package test.xmldb.levelzero;
09:
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;
17: import org.xml.sax.XMLReader;
18: import org.xml.sax.helpers.XMLReaderFactory;
19: import org.xml.sax.helpers.DefaultHandler;
20: import org.xml.sax.InputSource;
21: import org.apache.xml.serialize.OutputFormat;
22: import org.apache.xml.serialize.XMLSerializer;
23:
24: import org.xmldb.api.modules.XMLResource;
25:
26: /**
27: * @author Per Nyfelt
28: */
29: public class SAXTest extends XMLDBTestCase implements
30: LevelZeroTestConstants {
31:
32: private final String SAX_PARSER = "org.apache.xerces.parsers.SAXParser";
33:
34: /** Creates new SAXTest */
35: public SAXTest(String name) {
36: super (name);
37: }
38:
39: public static Test suite() {
40: return new TestSuite(SAXTest.class);
41: }
42:
43: /**
44: * test all scenarios for using XML as SAX
45: */
46: public void testSAX() {
47: try {
48: System.out.println("\nLevelZeroTest.testSAX() - started\n");
49: insertSAXDocument(id, new InputSource(xmlFileName));
50: retrieveSAXDocument(id);
51:
52: } catch (Exception e) {
53: fail(e.getMessage());
54: }
55: }
56:
57: private void insertSAXDocument(String id, InputSource source)
58: throws Exception {
59:
60: XMLResource resource = (XMLResource) col.createResource(id,
61: XMLResource.RESOURCE_TYPE);
62:
63: ContentHandler handler = resource.setContentAsSAX();
64:
65: XMLReader reader = XMLReaderFactory.createXMLReader(SAX_PARSER);
66: reader.setContentHandler(handler);
67: reader.parse(source);
68:
69: col.storeResource(resource);
70:
71: }
72:
73: private void retrieveSAXDocument(String id) throws Exception {
74: XMLResource resource = (XMLResource) col.getResource(id);
75:
76: // Use the DefaultHandler to handle the SAX events for now (doesn't do anything)
77: ContentHandler handle = new DefaultHandler();
78:
79: resource.getContentAsSAX(handle);
80: }
81:
82: private void updateSAXDocument() throws Exception {
83: throw new Exception(
84: "LevelZeroTest.updateSAXDocument() - Not implemented yet");
85: }
86: }
|