1 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 ; 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 22 import org.xmldb.api.modules.XMLResource; 23 import org.apache.log4j.Logger; 24 25 28 public class SAXTest extends XMLDBTestCase implements LevelZeroTestConstants { 29 30 Logger logger = Logger.getLogger(SAXTest.class); 31 32 private final String SAX_PARSER = "org.apache.xerces.parsers.SAXParser"; 33 34 public SAXTest(String name) { 35 super(name); 36 } 37 38 public static Test suite() { 39 return new TestSuite(SAXTest.class); 40 } 41 42 45 public void testSAX() { 46 try { 47 logger.debug("\nLevelZeroTest.testSAX() - started\n"); 48 insertSAXDocument(id, new InputSource (xmlFileName)); 49 retrieveSAXDocument(id); 50 51 } catch (Exception e) { 52 fail( e.getMessage( ) ); 53 } 54 } 55 56 private void insertSAXDocument(String id, InputSource source) throws Exception { 57 58 XMLResource resource = 59 (XMLResource) col.createResource(id, XMLResource.RESOURCE_TYPE); 60 61 ContentHandler handler = resource.setContentAsSAX(); 62 63 XMLReader 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 id) throws Exception { 72 XMLResource resource = (XMLResource) col.getResource(id); 73 74 ContentHandler handle = new DefaultHandler (); 76 77 resource.getContentAsSAX(handle); 78 } 79 80 private void updateSAXDocument() throws Exception { 81 throw new Exception ("LevelZeroTest.updateSAXDocument() - Not implemented yet"); 82 } 83 } 84 | Popular Tags |