diff software/eXist/mpdl-modules/src/de/mpg/mpiwg/berlin/mpdl/lt/morph/app/SimpleMorphContentHandler.java @ 0:408254cf2f1d

Erstellung
author Josef Willenborg <jwillenborg@mpiwg-berlin.mpg.de>
date Wed, 24 Nov 2010 17:24:23 +0100
parents
children
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/software/eXist/mpdl-modules/src/de/mpg/mpiwg/berlin/mpdl/lt/morph/app/SimpleMorphContentHandler.java	Wed Nov 24 17:24:23 2010 +0100
@@ -0,0 +1,119 @@
+package de.mpg.mpiwg.berlin.mpdl.lt.morph.app;
+
+import org.xml.sax.*;
+
+
+public class SimpleMorphContentHandler implements ContentHandler {
+  private Element currentElement;
+  private Lemma lemma;
+  private Form form;
+  
+  public SimpleMorphContentHandler() {
+  }
+  
+  public Form getForm() {
+    return form;
+  }
+  
+  public Lemma getLemma() {
+    return lemma;
+  }
+  
+  public void startDocument() throws SAXException {
+  }
+
+  public void endDocument() throws SAXException {
+  }
+  
+  public void characters(char[] c, int start, int length) throws SAXException {
+    if (currentElement != null) {
+      String elemName = currentElement.name;
+      if (form != null) {
+        char[] cCopy = new char[length];
+        System.arraycopy(c, start, cCopy, 0, length);
+        String charactersStr = String.valueOf(cCopy);
+        if (elemName.equals("provider"))
+          form.setProvider(charactersStr);
+        else if (elemName.equals("language"))
+          form.setLanguage(charactersStr);
+        else if (elemName.equals("form-name"))
+          form.setFormName(charactersStr);
+        else if (elemName.equals("lemma-name"))
+          form.setLemmaName(charactersStr);
+        else if (elemName.equals("pos"))
+          form.setPos(charactersStr);
+        else if (elemName.equals("tense"))
+          form.setTense(charactersStr);
+        else if (elemName.equals("voice"))
+          form.setVoice(charactersStr);
+        else if (elemName.equals("casus"))
+          form.setCasus(charactersStr);
+        else if (elemName.equals("number"))
+          form.setNumber(charactersStr);
+        else if (elemName.equals("mood"))
+          form.setMood(charactersStr);
+        else if (elemName.equals("person"))
+          form.setPerson(charactersStr);
+        else if (elemName.equals("gender"))
+          form.setGender(charactersStr);
+        else if (elemName.equals("definite"))
+          form.setDefinite(charactersStr);
+      } else if (lemma != null) {
+        char[] cCopy = new char[length];
+        System.arraycopy(c, start, cCopy, 0, length);
+        String charactersStr = String.valueOf(cCopy);
+        if (elemName.equals("provider"))
+          lemma.setProvider(charactersStr);
+        else if (elemName.equals("language"))
+          lemma.setLanguage(charactersStr);
+        else if (elemName.equals("lemma-name"))
+          lemma.setLemmaName(charactersStr);
+      }
+    }
+  }
+
+  public void ignorableWhitespace(char[] c, int start, int length) throws SAXException {
+  }
+
+  public void processingInstruction(String target, String data) throws SAXException {
+  }
+
+  public void setDocumentLocator(org.xml.sax.Locator arg1) {
+  }
+
+  public void endPrefixMapping(String prefix) throws SAXException {
+  }
+
+  public void skippedEntity(String name) throws SAXException {
+  }
+
+  public void endElement(String uri, String localName, String name) throws SAXException {
+    currentElement = null;
+  }
+
+  public void startElement(String uri, String localName, String name, Attributes attrs) throws SAXException {
+    currentElement = new Element(name);
+    if (name.equals("form")) {
+      form = new Form();
+    } else if (name.equals("lemma")) {
+      lemma = new Lemma();
+    }
+  }
+
+  public void startPrefixMapping(String prefix, String uri) throws SAXException {
+  }
+  
+  private class Element {
+    String name;
+    String value;
+    
+    Element(String name) {
+      this.name = name;
+    }
+
+    Element(String name, String value) {
+      this.name = name;
+      this.value = value;
+    }
+  }
+}