view software/mpdl-services/mpiwg-mpdl-xml/src/de/mpg/mpiwg/berlin/mpdl/xml/test/TestLocal.java @ 23:e845310098ba

diverse Korrekturen
author Josef Willenborg <jwillenborg@mpiwg-berlin.mpg.de>
date Tue, 27 Nov 2012 12:35:19 +0100
parents dc5e9fcb3fdc
children
line wrap: on
line source

package de.mpg.mpiwg.berlin.mpdl.xml.test;

import java.io.File;
import java.net.URL;

import org.apache.commons.io.FileUtils;

import net.sf.saxon.s9api.Axis;
import net.sf.saxon.s9api.QName;
import net.sf.saxon.s9api.XdmNode;
import net.sf.saxon.s9api.XdmSequenceIterator;

import de.mpg.mpiwg.berlin.mpdl.exception.ApplicationException;
import de.mpg.mpiwg.berlin.mpdl.xml.transform.BasicTransformer;
import de.mpg.mpiwg.berlin.mpdl.xml.xquery.Hits;
import de.mpg.mpiwg.berlin.mpdl.xml.xquery.XQueryEvaluator;

public class TestLocal {
  private XQueryEvaluator xQueryEvaluator;

  public TestLocal() {
    init();  
  }
  
  public static void main(String[] args) throws ApplicationException {
    try {
      TestLocal test = new TestLocal();
      test.xqueries();
      // test.testTransform();
    } catch (Exception e) {
      e.printStackTrace();
    }
  }

  private void init() {
    xQueryEvaluator = new XQueryEvaluator();
  }
  
  private void testTransform() throws ApplicationException {
    try {
      BasicTransformer basicTransformer = new BasicTransformer();
      String srcUrl = "file:/Users/jwillenborg/tmp/blablabla/Benedetti_1585.xml";
      String xslUrl = "file:/Users/jwillenborg/tmp/blablabla/replaceAnchors.xsl";
      String result = basicTransformer.transform(srcUrl, xslUrl, null, null);
      File outFile = new File("/Users/jwillenborg/tmp/blablabla/Benedetti_1585-New.xml");
      FileUtils.writeStringToFile(outFile, result, "utf-8");
    } catch (Exception e) {
      throw new ApplicationException(e);
    }
  }
  
  private void test() throws ApplicationException {
    String result = null;
    try {
      URL srcUrl = new URL("http://mpdl-system.mpiwg-berlin.mpg.de/mpdl/getDoc?doc=/tei/de/dt-ptolemaeus-tei-merge2.xml");
      srcUrl = new URL("file:/Users/jwillenborg/tmp/errorFile.xml");
      XdmNode docNode = xQueryEvaluator.parse(srcUrl);
      String docType = getNodeType(docNode);
      String bla = "";
    } catch (Exception e) {
      throw new ApplicationException(e);
    }
  }
  
  private void xqueries() throws ApplicationException {
    String result = null;
    try {
      // URL srcUrl = new URL("http://mpdl-system.mpiwg-berlin.mpg.de/mpdl/getDoc?doc=/tei/de/dt-ptolemaeus-tei-merge2.xml");
      URL srcUrl = new URL("file:/Users/jwillenborg/test/dt-ptolemaeus-tei-merge2.xml");
      Hits hits = xQueryEvaluator.evaluate(srcUrl, "//*[@xml:id != '1']", 0, 9);
      String bla = "";
    } catch (Exception e) {
      throw new ApplicationException(e);
    }
  }
  
  private String getNodeType(XdmNode node) {
    String nodeType = null;
    XdmSequenceIterator iter = node.axisIterator(Axis.CHILD);
    if (iter != null) {
      while (iter.hasNext()) {
        XdmNode firstChild = (XdmNode) iter.next();
        if (firstChild != null) {
          QName nodeQName = firstChild.getNodeName();
          nodeType = nodeQName.getLocalName();
        }
      }
    }
    return nodeType;
  }
  
}