Changeset 62

Show
Ignore:
Timestamp:
06/01/06 17:29:48 (2 years ago)
Author:
mikey
Message:

added XmlReader?.parse(InputStream? stream) method, refactored init of XmlReader?.parserFactory into its own method XmlReader?.initParserFactory()

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/src/main/java/net/schst/XJConf/XmlReader.java

    r61 r62  
    33import java.io.File; 
    44import java.io.IOException; 
     5import java.io.InputStream; 
    56import java.util.HashMap; 
    67import java.util.Stack; 
     
    3132 *  
    3233 * @author Stephan Schmidt <stephan.schmidt@schlund.de> 
     34 * @author Frank Kleine <frank.kleine@schlund.de> 
    3335 */ 
    3436public class XmlReader extends DefaultHandler { 
     
    158160        this.addExtension(ns, ext); 
    159161    } 
     162     
     163    /** 
     164     * Parse an input stream. 
     165     *  
     166     * @param  stream      input stream to parse 
     167     * @throws XJConfException 
     168     * @throws IOException 
     169     */ 
     170    public void parse(InputStream stream) throws XJConfException, IOException { 
     171        this.initParserFactory(); 
     172         
     173        SAXParser saxParser; 
     174        try { 
     175            saxParser = this.parserFactory.newSAXParser(); 
     176            saxParser.parse(stream, this); 
     177        } catch (XJConfException e) { 
     178            throw e; 
     179        } catch (ParserConfigurationException e) { 
     180            throw new InternalError("Could not configure the parser correctly.");  
     181        } catch (SAXException e) { 
     182            throw new XJConfException(e.getMessage()); 
     183        } 
     184    } 
     185     
     186    /** 
     187     * initialize the parser factory 
     188     * 
     189     */ 
     190    private void initParserFactory() { 
     191        if (null == this.parserFactory) { 
     192            this.parserFactory = SAXParserFactory.newInstance(); 
     193            this.parserFactory.setNamespaceAware(true); 
     194        } 
     195    } 
    160196 
    161197    /** 
     
    182218    */ 
    183219    public void parse(File file) throws XJConfException, IOException { 
    184         if (this.parserFactory == null) { 
    185             this.parserFactory = SAXParserFactory.newInstance(); 
    186             this.parserFactory.setNamespaceAware(true); 
    187         }     
     220        this.initParserFactory(); 
    188221         
    189222        this.openFiles.push(file);