Search in sources :

Example 1 with Element

use of org.osate.aadl2.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.osate.aadl2.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.osate.aadl2.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.osate.aadl2.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.osate.aadl2.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)3198 Document (org.jdom2.Document)484 Test (org.junit.Test)437 ArrayList (java.util.ArrayList)320 IOException (java.io.IOException)263 Attribute (org.jdom2.Attribute)199 JDOMException (org.jdom2.JDOMException)198 NamedElement (org.osate.aadl2.NamedElement)135 Namespace (org.jdom2.Namespace)134 List (java.util.List)133 Element (org.osate.aadl2.Element)133 Test (org.junit.jupiter.api.Test)131 File (java.io.File)124 SAXBuilder (org.jdom2.input.SAXBuilder)119 HashMap (java.util.HashMap)116 XMLOutputter (org.jdom2.output.XMLOutputter)99 XConfiguration (org.apache.oozie.util.XConfiguration)98 Configuration (org.apache.hadoop.conf.Configuration)96 Iterator (java.util.Iterator)64 EObject (org.eclipse.emf.ecore.EObject)63