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);
}
}
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);
}
}
}
}
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);
}
}
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);
}
}
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();
}
Aggregations