Search in sources :

Example 1 with Element

use of org.adempiere.pipo2.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;
}
Also used : RuleSet(pcgen.core.doomsdaybook.RuleSet) DataElement(pcgen.core.doomsdaybook.DataElement) Element(org.jdom2.Element)

Example 2 with Element

use of org.adempiere.pipo2.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();
}
Also used : SpaceRule(pcgen.core.doomsdaybook.SpaceRule) HyphenRule(pcgen.core.doomsdaybook.HyphenRule) CRRule(pcgen.core.doomsdaybook.CRRule) DataElement(pcgen.core.doomsdaybook.DataElement) Element(org.jdom2.Element) CRRule(pcgen.core.doomsdaybook.CRRule) HyphenRule(pcgen.core.doomsdaybook.HyphenRule) Rule(pcgen.core.doomsdaybook.Rule) SpaceRule(pcgen.core.doomsdaybook.SpaceRule)

Example 3 with Element

use of org.adempiere.pipo2.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());
        }
    }
}
Also used : Element(org.jdom2.Element) Iterator(java.util.Iterator) ArrayList(java.util.ArrayList) List(java.util.List)

Example 4 with Element

use of org.adempiere.pipo2.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);
}
Also used : Element(org.jdom2.Element)

Example 5 with Element

use of org.adempiere.pipo2.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);
        }
    }
}
Also used : Element(org.jdom2.Element)

Aggregations

Element (org.jdom2.Element)3498 Document (org.jdom2.Document)563 Test (org.junit.Test)469 ArrayList (java.util.ArrayList)357 IOException (java.io.IOException)293 JDOMException (org.jdom2.JDOMException)219 Attribute (org.jdom2.Attribute)215 SAXBuilder (org.jdom2.input.SAXBuilder)158 Namespace (org.jdom2.Namespace)147 File (java.io.File)138 List (java.util.List)138 Test (org.junit.jupiter.api.Test)134 Element (org.osate.aadl2.Element)133 XMLOutputter (org.jdom2.output.XMLOutputter)126 HashMap (java.util.HashMap)123 XConfiguration (org.apache.oozie.util.XConfiguration)98 Configuration (org.apache.hadoop.conf.Configuration)96 StringReader (java.io.StringReader)74 NamedElement (org.osate.aadl2.NamedElement)74 Text (org.jdom2.Text)67