use of org.jdom.Document in project vcell by virtualcell.
the class PathwayBiopax3Test method bioModelToXML.
static String bioModelToXML(PathwayModel pathwayModel) throws XmlParseException {
String xmlString = null;
try {
if (pathwayModel == null) {
throw new IllegalArgumentException("Invalid input for pathwayModel: " + pathwayModel);
}
String biopaxVersion = "3.0";
// create root element
Element rootElement = new Element("RDF", rdf);
rootElement.setAttribute("version", biopaxVersion);
// get element from producer and add it to root element
PathwayProducerBiopax3 xmlProducer = new PathwayProducerBiopax3(new RDFXMLContext());
// here is work done
xmlProducer.getXML(pathwayModel, rootElement);
// create xml doc and convert to string
Document bioDoc = new Document();
Comment docComment = new Comment("This pathway model was generated in Biopax Version " + biopaxVersion);
bioDoc.addContent(docComment);
bioDoc.setRootElement(rootElement);
xmlString = XmlUtil.xmlToString(bioDoc, false);
System.out.println(xmlString);
} catch (Exception e) {
e.printStackTrace();
throw new XmlParseException("Unable to generate PathwayModel XML", e);
}
return xmlString;
}
use of org.jdom.Document in project vcell by virtualcell.
the class BioModelEditorSabioPanel method treeSelectionChanged.
public void treeSelectionChanged() {
System.out.println("treeSelectionChanged");
final SBEntity kineticLaw = computeSelectedKineticLaw();
if (kineticLaw == null) {
return;
}
String kineticLawID = kineticLaw.getID();
final String kls = new String("kineticLaw");
if (!kineticLawID.contains(kls)) {
return;
}
kineticLawID = kineticLawID.substring(kineticLawID.lastIndexOf(kls) + kls.length());
command = "EntryID:" + kineticLawID;
AsynchClientTask task1 = new AsynchClientTask("Importing Kinetic Laws", AsynchClientTask.TASKTYPE_NONSWING_BLOCKING) {
@Override
public void run(final Hashtable<String, Object> hashTable) throws Exception {
final URL url = new URL("http://sabiork.h-its.org/sabioRestWebServices/searchKineticLaws/biopax?q=" + command);
// final URL url = new URL("http://sabiork.h-its.org/sabioRestWebServices/searchKineticLaws/biopax?q=EntryID:33107");
System.out.println(url.toString());
String ERROR_CODE_TAG = "error_code";
Document jdomDocument = XmlUtil.getJDOMDocument(url, getClientTaskStatusSupport());
Element rootElement = jdomDocument.getRootElement();
String errorCode = rootElement.getChildText(ERROR_CODE_TAG);
if (errorCode != null) {
throw new RuntimeException("Failed to access " + url + " \n\nPlease try again.");
}
PathwayModel pathwayModel = PathwayIOUtil.extractPathwayFromJDOM(jdomDocument, new RDFXMLContext(), getClientTaskStatusSupport());
PathwayData pathwayData = new PathwayData("Sabio Kinetic Laws", pathwayModel);
hashTable.put("pathwayData", pathwayData);
}
};
AsynchClientTask task2 = new AsynchClientTask("showing", AsynchClientTask.TASKTYPE_SWING_BLOCKING) {
@Override
public void run(Hashtable<String, Object> hashTable) throws Exception {
PathwayData pathwayData = (PathwayData) hashTable.get("pathwayData");
if (pathwayData != null) {
setSelectedObjects(new Object[] { pathwayData });
}
}
};
ClientTaskDispatcher.dispatch(this, new Hashtable<String, Object>(), new AsynchClientTask[] { task1, task2 }, true, true, null);
}
use of org.jdom.Document in project vcell by virtualcell.
the class BioModelEditorSabioPanel method populateKineticLawsTree.
public void populateKineticLawsTree() {
// String category1 = (String)categoryList1.getSelectedItem();
String category1 = "AnyRole";
String category2 = (String) categoryList2.getSelectedItem();
String entity1 = entityName1.getText();
String entity2 = entityName2.getText();
// http://sabiork.h-its.org/sabioRestWebServices/searchKineticLaws/biopax?q=%28Pathway:JAK-STAT%20AND%20CellularLocation:cytosol%29
command = "";
if (entity1.isEmpty() && entity2.isEmpty()) {
DialogUtils.showWarningDialog(this, "No search criteria specified.");
return;
}
if (!entity1.isEmpty() && entity2.isEmpty()) {
command += category1 + ":" + entity1;
} else if (entity1.isEmpty() && !entity2.isEmpty()) {
command += category2 + ":" + entity2;
} else {
// both entities present
command += "%28" + category1 + ":" + entity1 + "%20AND%20" + category2 + ":" + entity2 + "%29";
}
AsynchClientTask task1 = new AsynchClientTask("Importing Kinetic Laws", AsynchClientTask.TASKTYPE_NONSWING_BLOCKING) {
@Override
public void run(final Hashtable<String, Object> hashTable) throws Exception {
final URL url = new URL("http://sabiork.h-its.org/sabioRestWebServices/searchKineticLaws/biopax?q=" + command);
System.out.println(url.toString());
String ERROR_CODE_TAG = "error_code";
Document jdomDocument = XmlUtil.getJDOMDocument(url, getClientTaskStatusSupport());
Element rootElement = jdomDocument.getRootElement();
String errorCode = rootElement.getChildText(ERROR_CODE_TAG);
if (errorCode != null) {
throw new RuntimeException("Failed to access " + url + " \n\nPlease try again.");
}
PathwayModel pathwayModel = PathwayIOUtil.extractPathwayFromJDOM(jdomDocument, new RDFXMLContext(), getClientTaskStatusSupport());
PathwayData pathwayData = new PathwayData("Sabio Kinetic Laws", pathwayModel);
hashTable.put("pathwayData", pathwayData);
}
};
AsynchClientTask task2 = new AsynchClientTask("showing", AsynchClientTask.TASKTYPE_SWING_BLOCKING) {
@Override
public void run(Hashtable<String, Object> hashTable) throws Exception {
PathwayData pathwayData = (PathwayData) hashTable.get("pathwayData");
if (pathwayData != null) {
responseTreeModel.addSearchResponse("text", pathwayData);
}
}
};
ClientTaskDispatcher.dispatch(this, new Hashtable<String, Object>(), new AsynchClientTask[] { task1, task2 }, true, true, null);
}
use of org.jdom.Document in project vcell by virtualcell.
the class XMLDict method main.
// tests the x-path functionality
@SuppressWarnings("unchecked")
public static void main(String[] args) throws Exception {
if (args.length < 1)
System.out.println("Test Usage: XMLDict test_BioModel_File");
SAXBuilder builder = new SAXBuilder();
Document doc = builder.build(new FileReader(args[0]));
Element root = doc.getRootElement();
// not the actual usage, but works for testing
XMLDict dict = new XMLDict();
// add just one round
dict.put(root, root.getClass().getName() + ":" + root.getAttributeValue(XMLTags.NameTag), root);
Iterator<Element> i = root.getChildren().iterator();
while (i.hasNext()) {
Element temp = i.next();
dict.put(temp, temp.getClass().getName() + ":" + temp.getAttributeValue(XMLTags.NameTag), temp);
}
Enumeration<String> e = dict.keys();
while (e.hasMoreElements()) {
String key = e.nextElement();
Object value = dict.get(key);
System.out.println("key: " + key + " value: " + value);
}
i = root.getChildren().iterator();
while (i.hasNext()) {
Element temp = (Element) i.next();
Element value = (Element) dict.get(temp, temp.getClass().getName() + ":" + temp.getAttributeValue(XMLTags.NameTag));
System.out.println(value.getName() + " " + value.getAttributeValue(XMLTags.NameTag) + " " + temp.getName() + " " + temp.getAttributeValue(XMLTags.NameTag));
}
}
use of org.jdom.Document in project vcell by virtualcell.
the class XmlUtil method readXML.
public static Document readXML(InputStream inputStream) throws RuntimeException {
SAXBuilder builder = new SAXBuilder(false);
Document sDoc = null;
GenericXMLErrorHandler errorHandler = new GenericXMLErrorHandler();
builder.setErrorHandler(errorHandler);
try {
sDoc = builder.build(inputStream);
// Element root = null;
// root = sDoc.getRootElement();
// flush/replace previous error log with every read.
String errorHandlerLog = errorHandler.getErrorLog();
if (errorHandlerLog.length() > 0) {
System.out.println(errorHandlerLog);
XmlUtil.errorLog = errorHandlerLog;
} else {
XmlUtil.errorLog = "";
}
} catch (JDOMException e) {
e.printStackTrace();
throw new RuntimeException("source document is not well-formed\n" + e.getMessage());
} catch (IOException e) {
e.printStackTrace();
throw new RuntimeException("Unable to read source document\n" + e.getMessage());
}
return sDoc;
}
Aggregations