Package test.xmldb.levelzero

Source Code of test.xmldb.levelzero.SAXTest

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

package test.xmldb.levelzero;

import test.xmldb.*;
import junit.framework.*;

import org.xmldb.api.modules.TransactionService;
import org.xmldb.api.modules.BinaryResource;

import org.xml.sax.ContentHandler;
import org.xml.sax.XMLReader;
import org.xml.sax.helpers.XMLReaderFactory;
import org.xml.sax.helpers.DefaultHandler;
import org.xml.sax.InputSource;
import org.apache.xml.serialize.OutputFormat;
import org.apache.xml.serialize.XMLSerializer;

import org.xmldb.api.modules.XMLResource;

/**
* @author  Per Nyfelt
*/
public class SAXTest extends XMLDBTestCase implements LevelZeroTestConstants {

    private final String SAX_PARSER = "org.apache.xerces.parsers.SAXParser";
    /** Creates new SAXTest */
    public SAXTest(String name) {
        super(name);
    }
   
    public static Test suite() {
        return new TestSuite(SAXTest.class);
    }   

    /**
     * test all scenarios for using XML as SAX
     */
    public void testSAX() {
        try {      
            System.out.println("\nLevelZeroTest.testSAX() - started\n");
            insertSAXDocument(id, new InputSource(xmlFileName));
            retrieveSAXDocument(id);
   
        } catch (Exception e) {
            fail( e.getMessage( ) );
        }  
    }
   
   private void insertSAXDocument(String id, InputSource source) throws Exception{

        XMLResource resource =
           (XMLResource) col.createResource(id, XMLResource.RESOURCE_TYPE);

        ContentHandler handler = resource.setContentAsSAX();       

        XMLReader reader = XMLReaderFactory.createXMLReader(SAX_PARSER);
        reader.setContentHandler(handler);
        reader.parse(source);

        col.storeResource(resource);
              
   }
  
   private void retrieveSAXDocument(String id) throws Exception {
        XMLResource resource = (XMLResource) col.getResource(id);

        // Use the DefaultHandler to handle the SAX events for now (doesn't do anything)
        ContentHandler handle = new DefaultHandler();

        resource.getContentAsSAX(handle);     
   }
  
   private void updateSAXDocument() throws Exception {
       throw new Exception("LevelZeroTest.updateSAXDocument() - Not implemented yet");
   }   
}
TOP

Related Classes of test.xmldb.levelzero.SAXTest

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.