use of org.jdom2.output.XMLOutputter in project JMRI by JMRI.
the class VariableTableModelTest method testVarTableLoad_2_3.
// Check loading two columns, three rows
public void testVarTableLoad_2_3() {
String[] args = { "CV", "Name" };
VariableTableModel t = new VariableTableModel(null, args, new CvTableModel(null, p), null);
// create a JDOM tree with just some elements
Element root = new Element("decoder-config");
Document doc = new Document(root);
doc.setDocType(new DocType("decoder-config", "decoder-config.dtd"));
// add some elements
Element el0, el1;
root.addContent(// the sites information here lists all relevant
new Element("decoder").addContent(new Element("variables").addContent(el0 = new Element("variable").setAttribute("CV", "1").setAttribute("label", "one").setAttribute("mask", "VVVVVVVV").setAttribute("item", "really two").setAttribute("readOnly", "no").addContent(new Element("decVal").setAttribute("max", "31").setAttribute("min", "1"))).addContent(el1 = new Element("variable").setAttribute("CV", "4").setAttribute("readOnly", "no").setAttribute("mask", "XXXVVVVX").setAttribute("label", "two").addContent(new Element("decVal").setAttribute("max", "31").setAttribute("min", "1")))));
// end of adding contents
// print JDOM tree, to check
//OutputStream o = System.out;
//XMLOutputter fmt = new XMLOutputter();
//fmt.setNewlines(true); // pretty printing
//fmt.setIndent(true);
//try {
// fmt.output(doc, o);
//} catch (Exception e) { System.out.println("error writing XML: "+e);}
// and test reading this
t.setRow(0, el0);
Assert.assertTrue(t.getValueAt(0, 0).equals("1"));
Assert.assertTrue(t.getValueAt(0, 1).equals("one"));
// check that the variable names were set right
Assert.assertEquals("check loaded label ", "one", t.getLabel(0));
Assert.assertEquals("check loaded item ", "really two", t.getItem(0));
t.setRow(1, el1);
Assert.assertTrue(t.getValueAt(1, 0).equals("4"));
Assert.assertTrue(t.getValueAt(1, 1).equals("two"));
Assert.assertTrue(t.getRowCount() == 2);
// check finding
Assert.assertEquals("find variable two ", 1, t.findVarIndex("two"));
Assert.assertEquals("find nonexistant variable ", -1, t.findVarIndex("not there, eh?"));
}
use of org.jdom2.output.XMLOutputter in project JMRI by JMRI.
the class VariableTableModelTest method testVarTableLoadLongAddr.
// Check creating a longaddr type, walk through its programming
public void testVarTableLoadLongAddr() {
String[] args = { "CV", "Name" };
VariableTableModel t = new VariableTableModel(null, args, new CvTableModel(null, p), null);
// create a JDOM tree with just some elements
Element root = new Element("decoder-config");
Document doc = new Document(root);
doc.setDocType(new DocType("decoder-config", "decoder-config.dtd"));
// add some elements
Element el0;
root.addContent(// the sites information here lists all relevant
new Element("decoder").addContent(new Element("variables").addContent(el0 = new Element("variable").setAttribute("CV", "17").setAttribute("readOnly", "no").setAttribute("mask", "VVVVVVVV").setAttribute("label", "long").addContent(new Element("longAddressVal")))));
// end of adding contents
// print JDOM tree, to check
//OutputStream o = System.out;
//XMLOutputter fmt = new XMLOutputter();
//fmt.setNewlines(true); // pretty printing
//fmt.setIndent(true);
//try {
// fmt.output(doc, o);
//} catch (Exception e) { System.out.println("error writing XML: "+e);}
// and test reading this
t.setRow(0, el0);
Assert.assertTrue(t.getValueAt(0, 0).equals("17"));
Assert.assertTrue(t.getValueAt(0, 1).equals("long"));
Assert.assertTrue(t.getRowCount() == 1);
}
use of org.jdom2.output.XMLOutputter in project pcgen by PCGen.
the class Initiative method saveToDocument.
/**
* Saves the current combatants out to an XML file
*
*@param xml The File to save to
*@exception Exception XML and file IO exceptions
*/
private void saveToDocument(File xml) throws IOException {
Element party = new Element("Party");
party.setAttribute("filever", "1.0");
party.setAttribute("filetype", "initsave");
/*if(currentInit > -1) {
party.setAttribute("current_init", Integer.toString(currentInit));
}*/
initList.forEach((InitHolder anInitList) -> party.addContent(anInitList.getSaveElement()));
XMLOutputter xmlOut = new XMLOutputter();
xmlOut.setFormat(Format.getRawFormat().setEncoding("US-ASCII"));
try (Writer fr = new FileWriter(xml)) {
Document saveDocument = new Document(party);
xmlOut.output(saveDocument, fr);
fr.flush();
fr.close();
}
}
Aggregations