package javakurs.musterloesung.uebung03.aufgabe1;

import java.io.FileInputStream;
import java.io.IOException;

import javakurs.musterloesung.uebung03.aufgabe2.DomConverter;

import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;
import javax.xml.parsers.ParserConfigurationException;
import javax.xml.transform.TransformerException;

import org.w3c.dom.Document;
import org.xml.sax.SAXException;

/**
 * {@link XPathTest} applies the XSLT script of task 1.
 *
 * @author Joerg Steffen, DFKI
 * @version $Id: XPathTest.java,v 1.1 2010/11/18 23:06:11 steffen Exp $
 */
public final class XPathTest {

  /**
   * This would create a new instance of {@link XPathTest}. Not to be used.
   */
  private XPathTest() {

    // private constructor to enforce noninstantiability
  }


  /**
   * This is the main method. It requires no arguments.
   *
   * @param args
   *          the arguments; not used here
   */
  public static void main(String[] args) {

    String inputFile =
      "data/uebung03/sentences.xml";
    String xslFile =
      "xslt/xpathtest.xsl";

    // parse input file into DOM
    Document doc = null;
    try {
      DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
      DocumentBuilder builder = factory.newDocumentBuilder();
      doc = builder.parse(new FileInputStream(inputFile));
      // transform DOM
      DomConverter.convert(doc, xslFile, null, "XPathTest-Result.txt");
    } catch (ParserConfigurationException e) {
      e.printStackTrace();
    } catch (IOException e) {
      e.printStackTrace();
    } catch (SAXException e) {
      e.printStackTrace();
    } catch (TransformerException e) {
      e.printStackTrace();
    }


  }
}
