Package com.dbxml.xml.sax

Source Code of com.dbxml.xml.sax.SAXTableGenerator

package com.dbxml.xml.sax;

/*
* dbXML - Native XML Database
* Copyright (c) 1999-2006 The dbXML Group, L.L.C.
*
* Permission is hereby granted, free of charge, to any person obtaining
* a copy of this software and associated documentation files (the
* "Software"), to deal in the Software without restriction, including
* without limitation the rights to use, copy, modify, merge, publish,
* distribute, sublicense, and/or sell copies of the Software, and to
* permit persons to whom the Software is furnished to do so, subject to
* the following conditions:
*
* The above copyright notice and this permission notice shall be included
* in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*
* $Id: SAXTableGenerator.java,v 1.6 2006/02/02 19:04:46 bradford Exp $
*/

import java.io.*;

import com.dbxml.xml.dtsm.DTSMException;
import com.dbxml.xml.dtsm.DocumentTable;
import com.dbxml.xml.dtsm.TableBuilder;
import com.dbxml.xml.dtsm.TableGenerator;
import org.xml.sax.InputSource;
import org.xml.sax.SAXException;

/**
* SAXTableGenerator
*/

public class SAXTableGenerator extends TableGenerator {
   private TableBuilder builder;
   private DTSMContentHandler handler;
   private InputSource source;

   public SAXTableGenerator() {
   }

   public SAXTableGenerator(InputStream is) {
      source = new InputSource(is);
   }

   public SAXTableGenerator(Reader reader) {
      source = new InputSource(reader);
   }

   public SAXTableGenerator(File file) throws IOException {
      FileInputStream fis = new FileInputStream(file);
      BufferedInputStream bis = new BufferedInputStream(fis, 4096);
      InputStreamReader isr = new InputStreamReader(bis, "UTF8");
      source = new InputSource(isr);
   }

   public SAXTableGenerator(String uri) {
      source = new InputSource(uri);
   }

   public final DocumentTable process() throws DTSMException {
      try {
         if ( symbols != null )
            builder = new TableBuilder(symbols);
         else
            builder = new TableBuilder();
         handler = new DTSMContentHandler(builder);
         SAXHelper.parse(source, handler);

         SAXException e = handler.getException();
         if ( e != null )
            throw new DTSMException("Error parsing document", e);
         else
            return builder.buildDocumentTable();
      }
      catch ( SAXException e ) {
         throw new DTSMException(e);
      }
      catch ( IOException e ) {
         throw new DTSMException(e);
      }
   }
}
TOP

Related Classes of com.dbxml.xml.sax.SAXTableGenerator

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.