use of org.omegat.filters3.Element in project pcgen by PCGen.
the class NameGenPanel method loadRuleSet.
private RuleSet loadRuleSet(Element ruleSet) throws DataConversionException {
RuleSet rs = new RuleSet(allVars, ruleSet.getAttributeValue("title"), ruleSet.getAttributeValue("id"), ruleSet.getAttributeValue("usage"));
java.util.List<?> elements = ruleSet.getChildren();
ListIterator<?> elementsIterator = elements.listIterator();
int num = 0;
while (elementsIterator.hasNext()) {
Element child = (Element) elementsIterator.next();
String elementName = child.getName();
if (elementName.equals("CATEGORY")) {
loadCategory(child, rs);
} else if (elementName.equals("RULE")) {
rs.add(loadRule(child, rs.getId() + num));
}
num++;
}
return rs;
}
use of org.omegat.filters3.Element in project pcgen by PCGen.
the class NameGenPanel method loadRule.
private String loadRule(Element rule, String id) throws DataConversionException {
Rule dataRule = new Rule(allVars, id, id, rule.getAttribute("weight").getIntValue());
java.util.List<?> elements = rule.getChildren();
for (final Object element : elements) {
Element child = (Element) element;
String elementName = child.getName();
if (elementName.equals("GETLIST")) {
String listId = child.getAttributeValue("idref");
dataRule.add(listId);
} else if (elementName.equals("SPACE")) {
SpaceRule sp = new SpaceRule();
allVars.addDataElement(sp);
dataRule.add(sp.getId());
} else if (elementName.equals("HYPHEN")) {
HyphenRule hy = new HyphenRule();
allVars.addDataElement(hy);
dataRule.add(hy.getId());
} else if (elementName.equals("CR")) {
CRRule cr = new CRRule();
allVars.addDataElement(cr);
dataRule.add(cr.getId());
} else if (elementName.equals("GETRULE")) {
String ruleId = child.getAttributeValue("idref");
dataRule.add(ruleId);
}
}
allVars.addDataElement(dataRule);
return dataRule.getId();
}
use of org.omegat.filters3.Element 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.omegat.filters3.Element in project pcgen by PCGen.
the class DiceBagModel method saveToDocument.
/**
* <p>Loads the current dicebag's information into the
* given JDOM document.</p>
*
* @param doc
*/
private void saveToDocument(Document doc) {
Element party = new Element("dice-bag");
party.setAttribute("name", m_name);
for (String dieString : m_dice) {
Element die = new Element("dice-roll");
die.addContent(dieString);
party.addContent(die);
}
doc.setRootElement(party);
}
use of org.omegat.filters3.Element in project pcgen by PCGen.
the class Localized method update.
/**
*
* @param e
* @param attribute if {@code null}, use the trimmed text.
*/
private void update(Element e, String attribute) {
List<?> children = e.getChildren(ELEMENT_LOC);
for (Object object : children) {
if (object instanceof Element) {
Element child = (Element) object;
String lang = child.getAttributeValue(ATTRIBUTE_LANGUAGE);
String name;
if (attribute == null)
name = child.getTextTrim();
else
name = child.getAttributeValue(attribute);
if (lang != null && !lang.isEmpty())
addName(lang, name);
}
}
}
Aggregations