package javakurs.musterloesung.uebung03.aufgabe2;

import java.io.FileInputStream;
import java.io.IOException;
import java.util.HashMap;
import java.util.Map;

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 AnnotationMergerTest} applies the XSLT script of task 2.
 *
 * @author Joerg Steffen, DFKI
 * @version $Id: AnnotationMergerTest.java,v 1.1 2010/11/18 23:06:11 steffen Exp $
 */
public final class AnnotationMergerTest {

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

    // 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/verbcontexts.xsl";

    // parse input file into DOM
    Document doc = null;
    try {
      DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
      DocumentBuilder builder = factory.newDocumentBuilder();
      doc = builder.parse(new FileInputStream(inputFile));
      // set parameters
      Map<String, Object> parameter = new HashMap<String, Object>();
      parameter.put("docid", "C02-1004");
      // transform DOM
      DomConverter.convert(
        doc, xslFile, parameter, "AnnotationMergerTest-Result.xml");
    } catch (ParserConfigurationException e) {
      e.printStackTrace();
    } catch (IOException e) {
      e.printStackTrace();
    } catch (SAXException e) {
      e.printStackTrace();
    } catch (TransformerException e) {
      e.printStackTrace();
    }
  }
}
