comparison 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
comparison
equal deleted inserted replaced
22:6a45a982c333 23:e845310098ba
1 package de.mpg.mpiwg.berlin.mpdl.xml.test; 1 package de.mpg.mpiwg.berlin.mpdl.xml.test;
2 2
3 import java.io.File;
3 import java.net.URL; 4 import java.net.URL;
4 5
6 import org.apache.commons.io.FileUtils;
7
8 import net.sf.saxon.s9api.Axis;
9 import net.sf.saxon.s9api.QName;
10 import net.sf.saxon.s9api.XdmNode;
11 import net.sf.saxon.s9api.XdmSequenceIterator;
12
5 import de.mpg.mpiwg.berlin.mpdl.exception.ApplicationException; 13 import de.mpg.mpiwg.berlin.mpdl.exception.ApplicationException;
14 import de.mpg.mpiwg.berlin.mpdl.xml.transform.BasicTransformer;
15 import de.mpg.mpiwg.berlin.mpdl.xml.xquery.Hits;
6 import de.mpg.mpiwg.berlin.mpdl.xml.xquery.XQueryEvaluator; 16 import de.mpg.mpiwg.berlin.mpdl.xml.xquery.XQueryEvaluator;
7 17
8 public class TestLocal { 18 public class TestLocal {
9 private XQueryEvaluator xQueryEvaluator; 19 private XQueryEvaluator xQueryEvaluator;
10 20
14 24
15 public static void main(String[] args) throws ApplicationException { 25 public static void main(String[] args) throws ApplicationException {
16 try { 26 try {
17 TestLocal test = new TestLocal(); 27 TestLocal test = new TestLocal();
18 test.xqueries(); 28 test.xqueries();
29 // test.testTransform();
19 } catch (Exception e) { 30 } catch (Exception e) {
20 e.printStackTrace(); 31 e.printStackTrace();
21 } 32 }
22 } 33 }
23 34
24 private void init() { 35 private void init() {
25 xQueryEvaluator = new XQueryEvaluator(); 36 xQueryEvaluator = new XQueryEvaluator();
26 } 37 }
27 38
28 private void xqueries() throws ApplicationException { 39 private void testTransform() throws ApplicationException {
40 try {
41 BasicTransformer basicTransformer = new BasicTransformer();
42 String srcUrl = "file:/Users/jwillenborg/tmp/blablabla/Benedetti_1585.xml";
43 String xslUrl = "file:/Users/jwillenborg/tmp/blablabla/replaceAnchors.xsl";
44 String result = basicTransformer.transform(srcUrl, xslUrl, null, null);
45 File outFile = new File("/Users/jwillenborg/tmp/blablabla/Benedetti_1585-New.xml");
46 FileUtils.writeStringToFile(outFile, result, "utf-8");
47 } catch (Exception e) {
48 throw new ApplicationException(e);
49 }
50 }
51
52 private void test() throws ApplicationException {
29 String result = null; 53 String result = null;
30 try { 54 try {
31 URL srcUrl = new URL("http://mpdl-system.mpiwg-berlin.mpg.de/mpdl/getDoc?doc=/tei/en/Test_1789.xml"); 55 URL srcUrl = new URL("http://mpdl-system.mpiwg-berlin.mpg.de/mpdl/getDoc?doc=/tei/de/dt-ptolemaeus-tei-merge2.xml");
32 result = xQueryEvaluator.evaluateAsString(srcUrl, "declare namespace TEI=\"http://www.tei-c.org/ns/1.0\"; //TEI:s"); 56 srcUrl = new URL("file:/Users/jwillenborg/tmp/errorFile.xml");
57 XdmNode docNode = xQueryEvaluator.parse(srcUrl);
58 String docType = getNodeType(docNode);
33 String bla = ""; 59 String bla = "";
34 } catch (Exception e) { 60 } catch (Exception e) {
35 throw new ApplicationException(e); 61 throw new ApplicationException(e);
36 } 62 }
37 } 63 }
64
65 private void xqueries() throws ApplicationException {
66 String result = null;
67 try {
68 // URL srcUrl = new URL("http://mpdl-system.mpiwg-berlin.mpg.de/mpdl/getDoc?doc=/tei/de/dt-ptolemaeus-tei-merge2.xml");
69 URL srcUrl = new URL("file:/Users/jwillenborg/test/dt-ptolemaeus-tei-merge2.xml");
70 Hits hits = xQueryEvaluator.evaluate(srcUrl, "//*[@xml:id != '1']", 0, 9);
71 String bla = "";
72 } catch (Exception e) {
73 throw new ApplicationException(e);
74 }
75 }
76
77 private String getNodeType(XdmNode node) {
78 String nodeType = null;
79 XdmSequenceIterator iter = node.axisIterator(Axis.CHILD);
80 if (iter != null) {
81 while (iter.hasNext()) {
82 XdmNode firstChild = (XdmNode) iter.next();
83 if (firstChild != null) {
84 QName nodeQName = firstChild.getNodeName();
85 nodeType = nodeQName.getLocalName();
86 }
87 }
88 }
89 return nodeType;
90 }
91
38 } 92 }