Search in sources :

Example 31 with XMLOutputter

use of org.jdom.output.XMLOutputter in project vcell by virtualcell.

the class RulebasedTransformer method compareOperations.

private static void compareOperations(Element eTheirs, Element eOurs) {
    XMLOutputter outp = new XMLOutputter();
    Set<String> theirOperations = new HashSet<String>();
    Set<String> ourOperations = new HashSet<String>();
    Element le = eTheirs.getChild("ListOfOperations", Namespace.getNamespace("http://www.sbml.org/sbml/level3"));
    List<Element> children = new ArrayList<Element>();
    children = le.getChildren();
    for (Element e : children) {
        String s = outp.outputString(e);
        s = s.replace("xmlns=\"http://www.sbml.org/sbml/level3\"", "");
        s = s.replaceAll("\\s+", "");
        if (theirOperations.add(s) == false) {
            System.out.println("Duplicate their operation: " + s);
        }
        System.out.println(s);
    }
    le = eOurs.getChild("ListOfOperations");
    children = le.getChildren();
    for (Element e : children) {
        String s = outp.outputString(e);
        s = s.replace(".0", "");
        s = s.replaceAll("\\s+", "");
        if (ourOperations.add(s) == false) {
            System.out.println("Duplicate our operation: " + s);
        }
        System.out.println(s);
    }
    List<String> theirUnmatched = new ArrayList<String>();
    for (String their : theirOperations) {
        if (!ourOperations.contains(their)) {
            theirUnmatched.add(their);
        }
    }
    List<String> ourUnmatched = new ArrayList<String>();
    for (String our : ourOperations) {
        if (!theirOperations.contains(our)) {
            ourUnmatched.add(our);
        }
    }
    if (!theirUnmatched.isEmpty() || !ourUnmatched.isEmpty()) {
        String s1 = "theirs: ";
        String s2 = "ours  : ";
        for (String their : theirUnmatched) {
            s1 += their + "' ";
        }
        for (String our : ourUnmatched) {
            s2 += our + "' ";
        }
        throw new RuntimeException("Operations not matching for rule\n" + s1 + "\n" + s2 + "\n");
    } else {
        System.out.println("Operations matching for rule");
    }
}
Also used : XMLOutputter(org.jdom.output.XMLOutputter) Element(org.jdom.Element) ArrayList(java.util.ArrayList) HashSet(java.util.HashSet)

Example 32 with XMLOutputter

use of org.jdom.output.XMLOutputter in project vcell by virtualcell.

the class RulebasedTransformer method parseObservablesBngOutput.

private void parseObservablesBngOutput(SimulationContext simContext, BNGOutput bngOutput) {
    Model model = simContext.getModel();
    Document bngNFSimXMLDocument = bngOutput.getNFSimXMLDocument();
    bngRootElement = bngNFSimXMLDocument.getRootElement();
    Element modelElement = bngRootElement.getChild("model", Namespace.getNamespace("http://www.sbml.org/sbml/level3"));
    Element listOfObservablesElement = modelElement.getChild("ListOfObservables", Namespace.getNamespace("http://www.sbml.org/sbml/level3"));
    XMLOutputter outp = new XMLOutputter();
    String sTheirs = outp.outputString(listOfObservablesElement);
    sTheirs = sTheirs.replace("xmlns=\"http://www.sbml.org/sbml/level3\"", "");
    // System.out.println("==================== Their Observables ===================================================================");
    // System.out.println(sTheirs);
    // System.out.println("=======================================================================================");
    saveAsText("c:\\TEMP\\ddd\\theirObservables.txt", sTheirs);
// sTheirs = sTheirs.replaceAll("\\s+","");
}
Also used : XMLOutputter(org.jdom.output.XMLOutputter) Element(org.jdom.Element) Model(cbit.vcell.model.Model) Document(org.jdom.Document)

Example 33 with XMLOutputter

use of org.jdom.output.XMLOutputter in project vcell by virtualcell.

the class ExportRawTimeSeriesToVFrapOp method exportToVFRAP.

public void exportToVFRAP(File vfrapFile, ImageTimeSeries<UShortImage> imageTimeSeries, ClientTaskStatusSupport clientTaskStatusSupport) throws Exception {
    Xmlproducer vcellXMLProducer = new Xmlproducer(false);
    boolean bSaveCompressed = true;
    ImageDataset imageData = new ImageDataset(imageTimeSeries.getAllImages(), imageTimeSeries.getImageTimeStamps(), imageTimeSeries.getSizeZ());
    Element root = new Element(MicroscopyXMLTags.FRAPStudyTag);
    Element next = new Element(MicroscopyXMLTags.FRAPDataTag);
    root.addContent(next);
    Element imageDataXML = MicroscopyXmlproducer.getXML(imageData, vcellXMLProducer, clientTaskStatusSupport, bSaveCompressed);
    next.addContent(imageDataXML);
    java.io.FileOutputStream fileOutStream = new java.io.FileOutputStream(vfrapFile);
    BufferedOutputStream bufferedStream = new BufferedOutputStream(fileOutStream);
    // XmlUtil.writeXmlToStream(root, false, bufferedStream);
    XMLOutputter xmlOut = new XMLOutputter(Format.getPrettyFormat());
    xmlOut.getFormat().setTextMode(Format.TextMode.PRESERVE);
    xmlOut.output(root, bufferedStream);
    bufferedStream.flush();
    fileOutStream.flush();
    fileOutStream.close();
}
Also used : XMLOutputter(org.jdom.output.XMLOutputter) Xmlproducer(cbit.vcell.xml.Xmlproducer) MicroscopyXmlproducer(cbit.vcell.microscopy.MicroscopyXmlproducer) ImageDataset(cbit.vcell.VirtualMicroscopy.ImageDataset) Element(org.jdom.Element) BufferedOutputStream(java.io.BufferedOutputStream)

Example 34 with XMLOutputter

use of org.jdom.output.XMLOutputter in project vcell by virtualcell.

the class BiomodelsDB_TestSuite method writeSupportedModelsReport.

public static Document writeSupportedModelsReport(File supportInfoDir, File saveSupportedXMLPathname) throws Exception {
    if (!supportInfoDir.isDirectory()) {
        throw new IllegalArgumentException("File " + supportInfoDir.getAbsolutePath() + " must be a directory.");
    }
    File[] xmlReportFiles = supportInfoDir.listFiles(new FileFilter() {

        public boolean accept(File pathname) {
            if (pathname.isFile()) {
                if (pathname.getName().endsWith("_report.xml")) {
                    return true;
                }
            }
            return false;
        }
    });
    Document supportedDocument = new Document(new Element("Supported_BioModelsNet"));
    List<Element> supportedElements = new ArrayList<Element>();
    for (int i = 0; i < xmlReportFiles.length; i++) {
        byte[] xmlBytes = new byte[(int) xmlReportFiles[i].length()];
        FileInputStream fis = new FileInputStream(xmlReportFiles[i]);
        BufferedInputStream bis = new BufferedInputStream(fis);
        DataInputStream dis = new DataInputStream(bis);
        dis.readFully(xmlBytes);
        dis.close();
        Document document = XmlUtil.stringToXML(new String(xmlBytes), null);
        Element bioModelElement = document.getRootElement().getChild(BioModelsNetPanel.BIOMODELINFO_ELEMENT_NAME);
        Attribute supportedAttribute = bioModelElement.getAttribute(BioModelsNetPanel.SUPPORTED_ATTRIBUTE_NAME);
        if (supportedAttribute.getBooleanValue()) {
            Element newBioModelElement = new Element(BioModelsNetPanel.BIOMODELINFO_ELEMENT_NAME);
            @SuppressWarnings("unchecked") List<Attribute> attrList = bioModelElement.getAttributes();
            Iterator<Attribute> iterAttr = attrList.iterator();
            while (iterAttr.hasNext()) {
                newBioModelElement.setAttribute((Attribute) iterAttr.next().clone());
            }
            supportedElements.add(newBioModelElement);
        }
    }
    // Collections.sort(supportedElements, new ElementComparer());
    Element root = supportedDocument.getRootElement();
    for (Element e : supportedElements) {
        root.addContent(e);
    }
    if (saveSupportedXMLPathname != null) {
        try (FileWriter fw = new FileWriter(saveSupportedXMLPathname.getAbsolutePath())) {
            Format format = Format.getPrettyFormat();
            XMLOutputter out = new XMLOutputter(format);
            out.output(supportedDocument, fw);
        }
    }
    return supportedDocument;
}
Also used : XMLOutputter(org.jdom.output.XMLOutputter) Attribute(org.jdom.Attribute) Element(org.jdom.Element) FileWriter(java.io.FileWriter) ArrayList(java.util.ArrayList) Document(org.jdom.Document) DataInputStream(java.io.DataInputStream) FileInputStream(java.io.FileInputStream) Format(org.jdom.output.Format) BufferedInputStream(java.io.BufferedInputStream) FileFilter(java.io.FileFilter) File(java.io.File)

Example 35 with XMLOutputter

use of org.jdom.output.XMLOutputter in project yamcs-studio by yamcs.

the class XMLUtil method getXMLOutputter.

/**
 * Create and configure an XMLOutputter object.
 *
 * @param prettyFormat
 * @return the XMLOutputter
 */
private static XMLOutputter getXMLOutputter(boolean prettyFormat) {
    Format format = Format.getRawFormat();
    if (prettyFormat)
        // $NON-NLS-1$
        format.setIndent("  ");
    // Always use Unix-style line endings.
    format.setLineSeparator("\n");
    XMLOutputter xmlOutputter = new XMLOutputter();
    xmlOutputter.setFormat(format);
    return xmlOutputter;
}
Also used : XMLOutputter(org.jdom.output.XMLOutputter) Format(org.jdom.output.Format)

Aggregations

XMLOutputter (org.jdom.output.XMLOutputter)64 Element (org.jdom.Element)34 Document (org.jdom.Document)22 Format (org.jdom.output.Format)22 IOException (java.io.IOException)16 StringWriter (java.io.StringWriter)14 ArrayList (java.util.ArrayList)7 StringReader (java.io.StringReader)5 Writer (java.io.Writer)5 SAXBuilder (org.jdom.input.SAXBuilder)5 FileWriter (java.io.FileWriter)4 List (java.util.List)3 TreeMap (java.util.TreeMap)3 StudyBean (org.akaza.openclinica.bean.managestudy.StudyBean)3 JDOMException (org.jdom.JDOMException)3 ElementFilter (org.jdom.filter.ElementFilter)3 BufferedOutputStream (java.io.BufferedOutputStream)2 ByteArrayInputStream (java.io.ByteArrayInputStream)2 ByteArrayOutputStream (java.io.ByteArrayOutputStream)2 File (java.io.File)2