Main.java Source code

Java tutorial

Introduction

Here is the source code for Main.java

Source

//package com.java2s;
// This file is part of nzdis-util package. See the file LICENSE for copyright information

import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStream;

import java.io.Reader;
import java.io.StringReader;
import java.util.Properties;
import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;
import javax.xml.parsers.ParserConfigurationException;

import org.w3c.dom.Document;

import org.xml.sax.InputSource;
import org.xml.sax.SAXException;

public class Main {
    public static Document parseFile(final File aFile) throws SAXException, ParserConfigurationException {
        Properties props;
        props = new Properties();
        return parseFile(aFile, props);
    }

    public static Document parseFile(final File aFile, final String propfilename)
            throws SAXException, ParserConfigurationException {
        Properties props;
        props = new Properties();
        try {
            InputStream propsStream = new FileInputStream(propfilename);
            props.load(propsStream);
        } catch (FileNotFoundException ex) {
            ex.printStackTrace();
        } catch (IOException ex1) {
            ex1.printStackTrace();
        }
        return parseFile(aFile, props);
    }

    public static Document parseFile(final File aFile, final Properties props)
            throws SAXException, ParserConfigurationException {
        InputStream input = null;
        try {
            input = new FileInputStream(aFile);
        } catch (FileNotFoundException ex) {
            ex.printStackTrace();
            return null;
        }
        return parse(input, props);
    }

    public static Document parse(InputStream input, Properties props)
            throws SAXException, ParserConfigurationException {
        return parse(new InputSource(input), props);
    }

    public static Document parse(String input) throws SAXException, ParserConfigurationException {
        return parse(new StringReader(input), null);
    }

    public static Document parse(Reader input) throws SAXException, ParserConfigurationException {
        return parse(new InputSource(input), null);
    }

    public static Document parse(Reader input, Properties props) throws SAXException, ParserConfigurationException {
        return parse(new InputSource(input), props);
    }

    public static Document parse(InputSource input, @SuppressWarnings("unused") Properties props)
            throws SAXException, ParserConfigurationException {

        Document doc = null;
        try {
            DocumentBuilderFactory docBuilderFactory = DocumentBuilderFactory.newInstance();
            DocumentBuilder docBuilder = docBuilderFactory.newDocumentBuilder();
            doc = docBuilder.parse(input);

        } catch (IOException e) {
            e.printStackTrace(System.out);
            //throw e;
        }

        return doc;
    }
}