use of org.jdom2.DocType in project pcgen by PCGen.
the class NameGenPanel method loadData.
private void loadData(File path) {
if (path.isDirectory()) {
File[] dataFiles = path.listFiles(new XMLFilter());
SAXBuilder builder = new SAXBuilder();
GeneratorDtdResolver resolver = new GeneratorDtdResolver(path);
builder.setEntityResolver(resolver);
for (File dataFile : dataFiles) {
try {
URL url = dataFile.toURI().toURL();
Document nameSet = builder.build(url);
DocType dt = nameSet.getDocType();
if (dt.getElementName().equals("GENERATOR")) {
loadFromDocument(nameSet);
}
} catch (Exception e) {
Logging.errorPrint(e.getMessage(), e);
JOptionPane.showMessageDialog(this, "XML Error with file " + dataFile.getName());
}
}
loadDropdowns();
} else {
JOptionPane.showMessageDialog(this, "No data files in directory " + path.getPath());
}
}
use of org.jdom2.DocType in project pcgen by PCGen.
the class RoomBoardFactory method load.
public static RoomBoard load(File dataDir) {
//Create a new list for the room and board
PairList<RBCost> inns = new PairList<>();
PairList<RBCost> foods = new PairList<>();
PairList<RBCost> animals = new PairList<>();
File path = new File(dataDir, DIR_RNBPRICE);
if (path.isDirectory()) {
File[] dataFiles = path.listFiles(new XMLFilter());
SAXBuilder builder = new SAXBuilder();
for (int i = 0; i < dataFiles.length; i++) {
try {
Document methodSet = builder.build(dataFiles[i]);
DocType dt = methodSet.getDocType();
if (//$NON-NLS-1$
dt.getElementName().equals("RNBPRICE")) {
//Do work here
loadRBData(methodSet, inns, foods, animals);
}
methodSet = null;
dt = null;
} catch (Exception e) {
Logging.errorPrintLocalised("XML Error with file {0}", dataFiles[i].getName());
Logging.errorPrint(e.getMessage(), e);
}
}
} else {
//$NON-NLS-1$
Logging.errorPrintLocalised("in_plugin_overland_noDatafile", path.getPath());
}
return new RoomBoardImplementation(inns, foods, animals);
}
use of org.jdom2.DocType in project JMRI by JMRI.
the class QualifiedVarTest method setupDoc.
// provide a test document in the above static variables
void setupDoc() {
// create a JDOM tree with just some elements
root = new Element("programmer-config");
doc = new Document(root);
doc.setDocType(new DocType("programmer-config", "programmer-config.dtd"));
// add some elements
root.addContent(new Element("programmer").setAttribute("showFnLanelPane", "no").setAttribute("showRosterMediaPane", "no").addContent(new Element("pane").setAttribute("name", "Test").addContent(new Element("column").addContent(new Element("display").setAttribute("item", "Primary Address")).addContent(new Element("display").setAttribute("item", "CV2")).addContent(new Element("display").setAttribute("item", "CV3")).addContent(new Element("display").setAttribute("item", "CV4")).addContent(new Element("display").setAttribute("item", "CV5")).addContent(new Element("display").setAttribute("item", "CV6")).addContent(new Element("separator")).addContent(new Element("label").setAttribute("label", "set cv3 >= 100 to see CV4")).addContent(new Element("label").setAttribute("label", "set cv3 <=100 to see CV5, CV6"))).addContent(new Element("column").addContent(new Element("display").setAttribute("item", "Minor Version Number")).addContent(new Element("display").setAttribute("item", "Major Version Number")).addContent(new Element("display").setAttribute("item", "iCV53.5.0")).addContent(new Element("display").setAttribute("item", "iCV55.92.0")).addContent(new Element("display").setAttribute("item", "iCV55.92.1")).addContent(new Element("separator")).addContent(new Element("label").setAttribute("label", "set cv3 >= 100 to see iCV53.5.0")).addContent(new Element("label").setAttribute("label", "set minor >= 100 to see iCV55.92.0")).addContent(new Element("label").setAttribute("label", "set minor, major >= 100 to see iCV55.92.1")))).addContent(new Element("pane").setAttribute("name", "CV").addContent(new Element("column").addContent(new Element("cvtable")))).addContent(new Element("pane").setAttribute("name", "iCV").addContent(new Element("column").addContent(new Element("indxcvtable")))).addContent(new Element("pane").setAttribute("name", "CV3>50").addContent(new Element("qualifier").addContent(new Element("variableref").addContent("CV3")).addContent(new Element("relation").addContent("gt")).addContent(new Element("value").addContent("50"))).addContent(new Element("column").addContent(new Element("display").setAttribute("item", "CV3")).addContent(new Element("display").setAttribute("item", "CV4")).addContent(new Element("label").setAttribute("label", "Pane visible with CV3>100")))));
return;
}
use of org.jdom2.DocType in project JMRI by JMRI.
the class QualifierAdderTest method setUp.
// The minimal setup for log4J
@Override
protected void setUp() {
apps.tests.Log4JFixture.setUp();
p = new ProgDebugger();
cvtable = new CvTableModel(new JLabel(""), p);
model = new VariableTableModel(new JLabel(""), new String[] { "Name", "Value" }, cvtable, new IndexedCvTableModel(new JLabel(""), p));
// 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 el1, el2, el3;
root.addContent(// the sites information here lists all relevant
new Element("decoder").addContent(new Element("variables").addContent(el1 = new Element("variable").setAttribute("CV", "1").setAttribute("item", "one").addContent(new Element("decVal").setAttribute("max", "31").setAttribute("min", "1"))).addContent(el2 = new Element("variable").setAttribute("CV", "2").setAttribute("item", "two").addContent(new Element("decVal").setAttribute("max", "31").setAttribute("min", "1"))).addContent(el3 = new Element("variable").setAttribute("CV", "3").setAttribute("item", "three").addContent(new Element("decVal").setAttribute("max", "31").setAttribute("min", "1")))));
// end of adding contents
// and test reading this
model.setRow(0, el1);
model.setRow(1, el2);
model.setRow(1, el3);
v1 = model.findVar("one");
v2 = model.findVar("two");
v3 = model.findVar("three");
}
use of org.jdom2.DocType in project JMRI by JMRI.
the class QualifierAdderTest method testExistsOk1.
public void testExistsOk1() {
Element e = new Element("variable").addContent(new Element("qualifier").addContent(new Element("variableref").addContent("one")).addContent(new Element("relation").addContent("exists")).addContent(new Element("value").addContent("1")));
// 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"));
root.addContent(// the sites information here lists all relevant
new Element("decoder").addContent(new Element("variables").addContent(e)));
// print JDOM tree, to check
//org.jdom2.output.XMLOutputter fmt
// = new org.jdom2.output.XMLOutputter(org.jdom2.output.Format.getPrettyFormat());
//try {
// fmt.output(doc, System.out);
//} catch (Exception ex) { log.error("error writing XML", ex);}
// test Exists
processModifierElements(e, v2);
Assert.assertTrue(v2.getAvailable());
}
Aggregations