use of org.jdom2.Document in project gocd by gocd.
the class HgModificationSplitter method parseDOMTree.
private List<Modification> parseDOMTree(Document document) throws ParseException {
List<Modification> modifications = new ArrayList<>();
Element rootElement = document.getRootElement();
List logEntries = rootElement.getChildren("changeset");
for (Iterator iterator = logEntries.iterator(); iterator.hasNext(); ) {
Element changeset = (Element) iterator.next();
modifications.add(parseChangeset(changeset));
}
return modifications;
}
use of org.jdom2.Document 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.Document in project pcgen by PCGen.
the class DiceBagModel method loadFromDocument.
/**
* <p>Loads the dicebag data from the specified jdom document.</p>
*
* @param doc A JDOM document.
*/
private void loadFromDocument(Document doc) {
m_dice.clear();
Element root = doc.getRootElement();
if (root.getName().equals("dice-bag")) {
m_name = root.getAttributeValue("name");
List children = root.getChildren("dice-roll");
for (Iterator i = children.iterator(); i.hasNext(); ) {
Element die = (Element) i.next();
m_dice.add(die.getTextNormalize());
}
}
}
use of org.jdom2.Document in project pcgen by PCGen.
the class DiceBagModel method saveToFile.
/**
* <p>Saves the dicebag to the specified file as a UTF-8 xml file, with the format
* specified above in {@code loadFromFile()}</p>
*
* @param file File to save to.
*/
void saveToFile(File file) {
try {
Document doc = new Document();
saveToDocument(doc);
XMLOutputter xmlOut = new XMLOutputter();
xmlOut.setFormat(Format.getPrettyFormat());
FileWriter fr = new FileWriter(file);
xmlOut.output(doc, fr);
fr.flush();
fr.close();
m_filePath = file.getPath();
m_changed = false;
} catch (Exception e) {
JOptionPane.showMessageDialog(GMGenSystem.inst, "File load error: " + file.getName());
Logging.errorPrint("File Load Error" + file.getName());
Logging.errorPrint(e.getMessage(), e);
}
}
use of org.jdom2.Document in project pcgen by PCGen.
the class Initiative method loadFromDocument.
/**
* Loads a character or party from an XML document
*
*@param character XML document containing a character or a party
* @param comp
*/
private void loadFromDocument(Document character, PCGenMessageHandler comp) {
if (character.getRootElement().getName().equals("Party")) {
Element party = character.getRootElement();
List xmlList = party.getChildren("Character");
for (Object aXmlList : xmlList) {
Element eCharacter = (Element) aXmlList;
InitHolder combatant = new XMLCombatant(eCharacter);
initList.add(combatant);
}
List pcgList = party.getChildren("PcgCombatant");
for (Object aPcgList : pcgList) {
Element eCharacter = (Element) aPcgList;
final PcgCombatant combatant = new PcgCombatant(eCharacter, comp, messageHandler);
initList.add(combatant);
addTab(combatant);
}
List eventList = party.getChildren("Event");
for (Object anEventList : eventList) {
Element eCharacter = (Element) anEventList;
InitHolder combatant = new Event(eCharacter);
initList.add(combatant);
}
List spellList = party.getChildren("Spell");
for (Object aSpellList : spellList) {
Element eCharacter = (Element) aSpellList;
InitHolder combatant = new Spell(eCharacter);
initList.add(combatant);
}
initList.calculateNumberField();
} else if (character.getRootElement().getName().equals("Character")) {
Element eCharacter = character.getRootElement();
InitHolder combatant = new XMLCombatant(eCharacter);
initList.add(combatant);
}
}
Aggregations