diff src/de/mpiwg/dwinter/duomo/lexdump/LexDumpImporter.java @ 0:fb3f3df002df

first release
author dwinter
date Thu, 03 Feb 2011 10:15:16 +0100
parents
children 919e9f3b5efd
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/de/mpiwg/dwinter/duomo/lexdump/LexDumpImporter.java	Thu Feb 03 10:15:16 2011 +0100
@@ -0,0 +1,50 @@
+package de.mpiwg.dwinter.duomo.lexdump;
+
+import java.io.File;
+import java.io.IOException;
+import java.util.List;
+
+import org.jdom.Attribute;
+import org.jdom.Document;
+import org.jdom.Element;
+import org.jdom.JDOMException;
+import org.jdom.input.SAXBuilder;
+import org.jdom.xpath.XPath;
+
+
+public class LexDumpImporter {
+
+	private Document doc;
+
+	public LexDumpImporter(String path) throws JDOMException, IOException{
+		
+		SAXBuilder builder = new SAXBuilder();
+		
+		doc = builder.build(new File(path));
+		
+	}
+	
+	@SuppressWarnings("unchecked")
+	public List<Element> getCartas() throws JDOMException{
+		return (List<Element>)XPath.selectNodes(doc, "//carta");
+	}
+
+	public List<Element> getSignatures() throws JDOMException {
+		return (List<Element>)XPath.selectNodes(doc, "//segna");
+	}
+
+	public String getValue(Object context, String path) throws JDOMException {
+		
+		Object node = XPath.selectSingleNode(context, path);
+		
+		if (node==null){
+			return "";
+		} else if (Element.class.isInstance(node)){
+			return ((Element)node).getTextTrim();
+		} else if (Attribute.class.isInstance(node)){
+			return ((Attribute)node).getValue();
+		}
+		
+		return "";
+	}
+}