Search in sources :

Example 1 with Serializer

use of nu.xom.Serializer in project tetrad by cmu-phil.

the class LoadBayesImXmlAction method printDocument.

private static void printDocument(Document document) {
    Serializer serializer = new Serializer(System.out);
    serializer.setLineSeparator("\n");
    serializer.setIndent(2);
    try {
        serializer.write(document);
    } catch (IOException e) {
        throw new RuntimeException(e);
    }
}
Also used : IOException(java.io.IOException) Serializer(nu.xom.Serializer)

Example 2 with Serializer

use of nu.xom.Serializer in project android-selector-chapek by inmite.

the class SelectorGenerator method generate.

public static void generate(VirtualFile newFile, List<SelectorDetector.Result> detectorResults) {
    Log.d("generating XML:");
    Element root = new Element("selector");
    root.addNamespaceDeclaration(NS, SCHEMA);
    List<String> allStatesWithoutNormal = new ArrayList<String>();
    for (SelectorDetector.Result result : detectorResults) {
        for (String state : result.states) {
            if (!state.equals(Constants.NORMAL) && !allStatesWithoutNormal.contains(state)) {
                allStatesWithoutNormal.add(state);
            }
        }
    }
    for (SelectorDetector.Result result : detectorResults) {
        Log.d("fileName=" + result.drawableName + ", states:" + result.states);
        Element item = new Element("item");
        Attribute attribute = new Attribute("drawable", "@drawable/" + result.drawableName);
        attribute.setNamespace(NS, SCHEMA);
        item.addAttribute(attribute);
        for (String state : allStatesWithoutNormal) {
            boolean defaultValue = Constants.sMapping.get(state).defaultValue;
            addState(item, Constants.sMapping.get(state).attributeName, result.states.contains(state) ? (!defaultValue) : defaultValue);
        }
        Log.d("row=" + item.toXML());
        root.appendChild(item);
    }
    Document doc = new Document(root);
    OutputStream os = null;
    try {
        os = newFile.getOutputStream(null);
        Serializer serializer = new Serializer(os);
        serializer.setIndent(4);
        serializer.write(doc);
    } catch (IOException e) {
        Log.e(e);
    } finally {
        if (os != null) {
            try {
                os.close();
            } catch (IOException e) {
                Log.e(e);
            }
        }
    }
}
Also used : Attribute(nu.xom.Attribute) Element(nu.xom.Element) OutputStream(java.io.OutputStream) ArrayList(java.util.ArrayList) IOException(java.io.IOException) Document(nu.xom.Document) Serializer(nu.xom.Serializer)

Example 3 with Serializer

use of nu.xom.Serializer in project tetrad by cmu-phil.

the class LoadBayesImXsdlXmlAction method printDocument.

private static void printDocument(Document document) {
    Serializer serializer = new Serializer(System.out);
    serializer.setLineSeparator("\n");
    serializer.setIndent(2);
    try {
        serializer.write(document);
    } catch (IOException e) {
        throw new RuntimeException(e);
    }
}
Also used : IOException(java.io.IOException) Serializer(nu.xom.Serializer)

Example 4 with Serializer

use of nu.xom.Serializer in project tetrad by cmu-phil.

the class SaveBayesImXmlAction method actionPerformed.

public void actionPerformed(ActionEvent e) {
    try {
        File outfile = EditorUtils.getSaveFile("bayesim", "xml", this.bayesImEditor, false, "Save Bayes IM as XML...");
        BayesIm bayesIm = bayesImEditor.getWizard().getBayesIm();
        FileOutputStream out = new FileOutputStream(outfile);
        Element element = BayesXmlRenderer.getElement(bayesIm);
        Document document = new Document(element);
        Serializer serializer = new Serializer(out);
        serializer.setLineSeparator("\n");
        serializer.setIndent(2);
        serializer.write(document);
        out.close();
    } catch (IOException e1) {
        throw new RuntimeException(e1);
    }
}
Also used : BayesIm(edu.cmu.tetrad.bayes.BayesIm) FileOutputStream(java.io.FileOutputStream) Element(nu.xom.Element) IOException(java.io.IOException) Document(nu.xom.Document) File(java.io.File) Serializer(nu.xom.Serializer)

Example 5 with Serializer

use of nu.xom.Serializer in project tetrad by cmu-phil.

the class GraphUtils method graphToXml.

public static String graphToXml(Graph graph) {
    Document document = new Document(convertToXml(graph));
    OutputStream out = new ByteArrayOutputStream();
    Serializer serializer = new Serializer(out);
    serializer.setLineSeparator("\n");
    serializer.setIndent(2);
    try {
        serializer.write(document);
    } catch (IOException e) {
        throw new RuntimeException(e);
    }
    return out.toString();
}
Also used : ByteArrayOutputStream(java.io.ByteArrayOutputStream) OutputStream(java.io.OutputStream) FileOutputStream(java.io.FileOutputStream) ByteArrayOutputStream(java.io.ByteArrayOutputStream) IOException(java.io.IOException) Document(nu.xom.Document) Serializer(nu.xom.Serializer)

Aggregations

IOException (java.io.IOException)6 Serializer (nu.xom.Serializer)6 Document (nu.xom.Document)3 FileOutputStream (java.io.FileOutputStream)2 OutputStream (java.io.OutputStream)2 Element (nu.xom.Element)2 BayesIm (edu.cmu.tetrad.bayes.BayesIm)1 ByteArrayOutputStream (java.io.ByteArrayOutputStream)1 File (java.io.File)1 ArrayList (java.util.ArrayList)1 Attribute (nu.xom.Attribute)1