⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 saxtest.java

📁 Java的面向对象数据库系统的源代码
💻 JAVA
字号:
// 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.xmldb.api.modules.XMLResource;
import org.apache.log4j.Logger;

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

    Logger logger = Logger.getLogger(SAXTest.class);

    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 {       
            logger.debug("\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");
   }    
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -