Search in sources :

Example 6 with Element

use of org.eclipse.xtext.parsetree.reconstr.bug302128.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 7 with Element

use of org.eclipse.xtext.parsetree.reconstr.bug302128.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 8 with Element

use of org.eclipse.xtext.parsetree.reconstr.bug302128.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 9 with Element

use of org.eclipse.xtext.parsetree.reconstr.bug302128.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)

Example 10 with Element

use of org.eclipse.xtext.parsetree.reconstr.bug302128.Element 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);
    }
}
Also used : PcgCombatant(gmgen.plugin.PcgCombatant) Element(org.jdom2.Element) HyperlinkEvent(javax.swing.event.HyperlinkEvent) ListSelectionEvent(javax.swing.event.ListSelectionEvent) ActionEvent(java.awt.event.ActionEvent) Event(gmgen.plugin.Event) List(java.util.List) InitHolderList(gmgen.plugin.InitHolderList) ArrayList(java.util.ArrayList) InitHolder(gmgen.plugin.InitHolder) XMLCombatant(plugin.initiative.XMLCombatant) Spell(gmgen.plugin.Spell)

Aggregations

Element (org.jdom2.Element)829 Attribute (org.jdom2.Attribute)76 Document (org.jdom2.Document)75 Test (org.junit.Test)70 File (java.io.File)53 ArrayList (java.util.ArrayList)45 JDOMException (org.jdom2.JDOMException)37 IOException (java.io.IOException)34 HashMap (java.util.HashMap)28 NamedIcon (jmri.jmrit.catalog.NamedIcon)27 List (java.util.List)26 XmlFile (jmri.jmrit.XmlFile)24 SAXBuilder (org.jdom2.input.SAXBuilder)21 Turnout (jmri.Turnout)20 DataConversionException (org.jdom2.DataConversionException)20 DocType (org.jdom2.DocType)19 Editor (jmri.jmrit.display.Editor)18 XMLOutputter (org.jdom2.output.XMLOutputter)18 Namespace (org.jdom2.Namespace)17 Point (java.awt.Point)15