add pp.xml parsing from cgi

main
josch 13 years ago
parent 3b9bf6c688
commit 1d5d45378c

@ -54,6 +54,22 @@ public class Dom {
return null;
}
public static Element getSecondChildElement(Node item) {
NodeList list = item.getChildNodes();
int count = 0;
for (int i = 0; i < list.getLength(); i++) {
Node child = list.item(i);
if (child.getNodeType() == Node.ELEMENT_NODE) {
if (count == 1) {
return (Element)child;
} else {
count++;
}
}
}
return null;
}
public static Node getFirstChild(Node item, String name) {
NodeList list = item.getChildNodes();
for (int i = 0; i < list.getLength(); i++) {

@ -7,6 +7,7 @@ import java.io.IOException;
import de.unibremen.informatik.hets.model.HetFile;
import de.unibremen.informatik.hets.model.PPXMLParserException;
import de.unibremen.informatik.hets.common.xml.Dom;
import de.unibremen.informatik.hets.common.io.IOUtils;
import de.unibremen.informatik.hets.common.lang.StringUtils;
import org.w3c.dom.Document;
@ -133,10 +134,18 @@ public class PPXMLParser {
throw new PPXMLParserException();
}
SpecDefn specdefn = new SpecDefn(((Element)item).getAttribute("name"), currentlogic);
String annotation = "";
Element child = Dom.getFirstChildElement(item);
if (child.getTagName() == "Left") {
annotation = Dom.getTextContent(Dom.getFirstChildElement(child));
child = Dom.getSecondChildElement(item);
}
SpecDefn specdefn = new SpecDefn(((Element)item).getAttribute("name"), currentlogic, annotation);
if (child.getTagName() == "Basicspec") {
specdefn.add(parsespecspec(hetfile, child));
} else if (child.getTagName() == "Extension") {
@ -145,6 +154,8 @@ public class PPXMLParser {
for (Element spec : speclist) {
specdefn.add(parsespec(hetfile, spec));
}
} else {
throw new PPXMLParserException("unexpected element: " + child.getTagName());
}
het.add(specdefn);

@ -7,10 +7,12 @@ public class SpecDefn {
private ArrayList<Spec> specs;
private String name;
private String logic;
private String annotation;
public SpecDefn(String n, String l) {
public SpecDefn(String n, String l, String a) {
name = n;
logic = l;
annotation = a;
specs = new ArrayList<Spec>();
}
@ -25,12 +27,16 @@ public class SpecDefn {
public String toString() {
StringBuilder builder = new StringBuilder();
if (annotation != null && annotation != "") {
builder.append(annotation);
builder.append("\n");
}
builder.append("spec ");
builder.append(name);
builder.append(" =");
Iterator<Spec> it = specs.iterator();
for (;;) {
while (it.hasNext()) {
Spec spec = it.next();
String annotation = spec.getAnnotation();

@ -1,8 +1,16 @@
package de.unibremen.informatik.hets.protege;
import java.io.File;
import java.io.InputStream;
import java.io.FileInputStream;
import java.io.IOException;
import java.util.Set;
import java.util.HashSet;
import java.util.HashMap;
import java.util.regex.Pattern;
import java.util.regex.Matcher;
import java.net.URL;
import java.net.MalformedURLException;
import javax.swing.*;
import java.awt.event.ActionEvent;
@ -11,6 +19,12 @@ import java.awt.HeadlessException;
import org.protege.editor.owl.ui.action.ProtegeOWLAction;
import org.protege.editor.core.ui.util.UIUtil;
import de.unibremen.informatik.hets.common.net.HttpPostUrlencoded;
import de.unibremen.informatik.hets.common.io.IOUtils;
import de.unibremen.informatik.hets.model.HetFile;
import de.unibremen.informatik.hets.model.PPXMLParser;
import de.unibremen.informatik.hets.model.PPXMLParserException;
public class CGIImportHetsAction extends ProtegeOWLAction {
private static final long serialVersionUID = -4056096587762591108L;
@ -28,12 +42,47 @@ public class CGIImportHetsAction extends ProtegeOWLAction {
Set<String> exts = new HashSet<String>();
exts.add("het");
exts.add("owl");
File file = null;
InputStream input = null;
Matcher matcher = null;
HetFile hetfile = null;
File file = UIUtil.openFile(new JFrame(), "HetCASL", "Please select a *.het file", exts);
HashMap<String, Object> args = new HashMap<String, Object>();
args.put("f0x0", file);
args.put("f0x3", "on");
args.put("s0x5", "Submit");
try {
file = UIUtil.openFile(new JFrame(), "HetCASL", "Please select a *.het file", exts);
} catch (HeadlessException e) {
// TODO Auto-generated catch block
input = HttpPostUrlencoded.post(new URL("http://www.informatik.uni-bremen.de/cgi-bin/cgiwrap/maeder/hets.cgi"), args);
} catch (MalformedURLException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
String patternStr = "http://www.informatik.uni-bremen.de/cofi/hets-tmp/result\\d+.pp.xml";
Pattern pattern = Pattern.compile(patternStr);
try {
matcher = pattern.matcher(IOUtils.getBuffer(input));
} catch (IOException e) {
e.printStackTrace();
}
if (!matcher.find()) {
// TODO: throw exception
}
try {
hetfile = PPXMLParser.parse(new URL(matcher.group()).openStream(),
IOUtils.getString(new FileInputStream(file)));
} catch (MalformedURLException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
} catch (PPXMLParserException e) {
e.printStackTrace();
}
System.out.println(hetfile.toString());
}
}

Loading…
Cancel
Save