Mercurial > hg > mpdl-group
diff 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 diff
--- a/software/mpdl-services/mpiwg-mpdl-xml/src/de/mpg/mpiwg/berlin/mpdl/xml/test/TestLocal.java Wed Dec 14 13:57:09 2011 +0100 +++ b/software/mpdl-services/mpiwg-mpdl-xml/src/de/mpg/mpiwg/berlin/mpdl/xml/test/TestLocal.java Tue Nov 27 12:35:19 2012 +0100 @@ -1,8 +1,18 @@ 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 { @@ -16,6 +26,7 @@ try { TestLocal test = new TestLocal(); test.xqueries(); + // test.testTransform(); } catch (Exception e) { e.printStackTrace(); } @@ -25,14 +36,57 @@ xQueryEvaluator = new XQueryEvaluator(); } - private void xqueries() throws ApplicationException { + 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/en/Test_1789.xml"); - result = xQueryEvaluator.evaluateAsString(srcUrl, "declare namespace TEI=\"http://www.tei-c.org/ns/1.0\"; //TEI:s"); + 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; + } + }