|
0
|
1 package de.mpiwg.dwinter.duomo.lexdump;
|
|
|
2
|
|
|
3 import java.io.File;
|
|
|
4 import java.io.IOException;
|
|
|
5 import java.util.List;
|
|
|
6
|
|
|
7 import org.jdom.Attribute;
|
|
|
8 import org.jdom.Document;
|
|
|
9 import org.jdom.Element;
|
|
|
10 import org.jdom.JDOMException;
|
|
|
11 import org.jdom.input.SAXBuilder;
|
|
|
12 import org.jdom.xpath.XPath;
|
|
|
13
|
|
|
14
|
|
|
15 public class LexDumpImporter {
|
|
|
16
|
|
|
17 private Document doc;
|
|
|
18
|
|
|
19 public LexDumpImporter(String path) throws JDOMException, IOException{
|
|
|
20
|
|
|
21 SAXBuilder builder = new SAXBuilder();
|
|
|
22
|
|
|
23 doc = builder.build(new File(path));
|
|
|
24
|
|
|
25 }
|
|
|
26
|
|
|
27 @SuppressWarnings("unchecked")
|
|
|
28 public List<Element> getCartas() throws JDOMException{
|
|
|
29 return (List<Element>)XPath.selectNodes(doc, "//carta");
|
|
|
30 }
|
|
|
31
|
|
|
32 public List<Element> getSignatures() throws JDOMException {
|
|
|
33 return (List<Element>)XPath.selectNodes(doc, "//segna");
|
|
|
34 }
|
|
|
35
|
|
|
36 public String getValue(Object context, String path) throws JDOMException {
|
|
|
37
|
|
|
38 Object node = XPath.selectSingleNode(context, path);
|
|
|
39
|
|
|
40 if (node==null){
|
|
|
41 return "";
|
|
|
42 } else if (Element.class.isInstance(node)){
|
|
|
43 return ((Element)node).getTextTrim();
|
|
|
44 } else if (Attribute.class.isInstance(node)){
|
|
|
45 return ((Attribute)node).getValue();
|
|
|
46 }
|
|
|
47
|
|
|
48 return "";
|
|
|
49 }
|
|
|
50 }
|