Search in sources :

Example 56 with Document

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;
}
Also used : Comment(org.jdom.Comment) Element(org.jdom.Element) XmlParseException(cbit.vcell.xml.XmlParseException) Document(org.jdom.Document) XmlParseException(cbit.vcell.xml.XmlParseException)

Example 57 with Document

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);
}
Also used : AsynchClientTask(cbit.vcell.client.task.AsynchClientTask) RDFXMLContext(org.vcell.pathway.persistence.RDFXMLContext) Hashtable(java.util.Hashtable) Element(org.jdom.Element) PathwayData(cbit.vcell.client.desktop.biomodel.BioModelEditorPathwayCommonsPanel.PathwayData) Document(org.jdom.Document) PathwayModel(org.vcell.pathway.PathwayModel) SBEntity(org.vcell.pathway.sbpax.SBEntity) URL(java.net.URL) PathwayStringObject(cbit.vcell.client.desktop.biomodel.BioModelEditorPathwayCommonsPanel.PathwayStringObject)

Example 58 with Document

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);
}
Also used : AsynchClientTask(cbit.vcell.client.task.AsynchClientTask) RDFXMLContext(org.vcell.pathway.persistence.RDFXMLContext) Hashtable(java.util.Hashtable) Element(org.jdom.Element) PathwayData(cbit.vcell.client.desktop.biomodel.BioModelEditorPathwayCommonsPanel.PathwayData) PathwayStringObject(cbit.vcell.client.desktop.biomodel.BioModelEditorPathwayCommonsPanel.PathwayStringObject) Document(org.jdom.Document) PathwayModel(org.vcell.pathway.PathwayModel) URL(java.net.URL)

Example 59 with Document

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));
    }
}
Also used : SAXBuilder(org.jdom.input.SAXBuilder) Element(org.jdom.Element) FileReader(java.io.FileReader) Document(org.jdom.Document)

Example 60 with Document

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;
}
Also used : SAXBuilder(org.jdom.input.SAXBuilder) IOException(java.io.IOException) Document(org.jdom.Document) JDOMException(org.jdom.JDOMException)

Aggregations

Document (org.jdom.Document)144 Element (org.jdom.Element)102 SAXBuilder (org.jdom.input.SAXBuilder)51 IOException (java.io.IOException)49 JDOMException (org.jdom.JDOMException)29 File (java.io.File)27 ArrayList (java.util.ArrayList)22 XMLOutputter (org.jdom.output.XMLOutputter)22 List (java.util.List)16 StringReader (java.io.StringReader)15 Format (org.jdom.output.Format)12 VCDocument (org.vcell.util.document.VCDocument)11 XPath (org.jdom.xpath.XPath)10 StringWriter (java.io.StringWriter)9 InputStream (java.io.InputStream)8 URL (java.net.URL)8 NotNull (org.jetbrains.annotations.NotNull)7 Nullable (org.jetbrains.annotations.Nullable)7 FileNotFoundException (java.io.FileNotFoundException)5 Writer (java.io.Writer)5