Search in sources :

Example 6 with Element

use of org.omegat.filters3.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)

Example 7 with Element

use of org.omegat.filters3.Element in project pcgen by PCGen.

the class TravelMethodFactory method create.

public static TravelMethod create(Document methodSet) {
    Localized name;
    Map<String, Map<String, Combo>> multByRoadByTerrains;
    Map<String, List<Localized>> terrains2;
    Map<String, Map<Localized, String>> terrainsById2;
    Map<String, List<Localized>> routes2;
    Map<String, Map<Localized, String>> routesById2;
    List<Method> methods;
    Element travel = methodSet.getRootElement();
    NumberFormat nf = getNumberFormat(travel);
    name = new Localized(travel);
    multByRoadByTerrains = new HashMap<>();
    terrains2 = new HashMap<>();
    terrainsById2 = new HashMap<>();
    routes2 = new HashMap<>();
    routesById2 = new HashMap<>();
    methods = new ArrayList<>();
    for (Object methodObj : travel.getChildren()) {
        Element child = (Element) methodObj;
        if (child.getName().equals(XML_ELEMENT_WAY)) {
            String wayId = child.getAttributeValue(XML_ATTRIBUTE_ID);
            List<Localized> terrains = new ArrayList<>();
            terrains2.put(wayId, terrains);
            List<Localized> routes = new ArrayList<>();
            routes2.put(wayId, routes);
            Map<Localized, String> terrainsById = new HashMap<>();
            terrainsById2.put(wayId, terrainsById);
            Map<Localized, String> routesById = new HashMap<>();
            routesById2.put(wayId, routesById);
            for (Object o : child.getChildren()) {
                if (o instanceof Element) {
                    Element grandchild = (Element) o;
                    if (grandchild.getName().equals(XML_ELEMENT_TERRAIN)) {
                        String id = grandchild.getAttributeValue(XML_ATTRIBUTE_ID);
                        Localized terrain = new Localized(grandchild);
                        terrains.add(terrain);
                        terrainsById.put(terrain, id);
                        if (!multByRoadByTerrains.containsKey(id)) {
                            multByRoadByTerrains.put(id, new TreeMap<>());
                        }
                    } else if (grandchild.getName().equals(XML_ELEMENT_ROUTE)) {
                        String id = grandchild.getAttributeValue(XML_ATTRIBUTE_ID);
                        Localized route = new Localized(grandchild);
                        routes.add(route);
                        routesById.put(route, id);
                        for (Object gcc : grandchild.getChildren(XML_ELEMENT_COMBO)) {
                            if (gcc instanceof Element) {
                                Element grandgrandchild = (Element) gcc;
                                String idTerrain = grandgrandchild.getAttributeValue(XML_ELEMENT_TERRAIN);
                                Number mult = parseNumber(nf, grandgrandchild, XML_ATTRIBUTE_MULT, 1);
                                Number addMph = parseNumber(nf, grandgrandchild, XML_ATTRIBUTE_ADDMPH, 0);
                                Number addKmh = parseNumber(nf, grandgrandchild, XML_ATTRIBUTE_ADDKMH, 0);
                                if (!multByRoadByTerrains.containsKey(idTerrain)) {
                                    multByRoadByTerrains.put(idTerrain, new TreeMap<>());
                                }
                                multByRoadByTerrains.get(idTerrain).put(id, new Combo(mult, addMph, addKmh));
                            }
                        }
                    }
                }
            }
        // Sort the terrains by locale name
        // TODO sort, but with one that do toString on the object. Collections.sort(terrains, Collator.getInstance());
        // not sorting routes intentionally (it goes from easier to navigate to hardest)
        } else if (child.getName().equals(XML_ELEMENT_METHOD)) {
            String way = child.getAttributeValue(XML_ELEMENT_WAY);
            Method method = new Method(new Localized(child), way);
            methods.add(method);
            for (Object o : child.getChildren()) {
                if (o instanceof Element) {
                    Element grandchild = (Element) o;
                    if (grandchild.getName().equals(XML_ELEMENT_PACE)) {
                        Localized pace = new Localized(grandchild);
                        boolean useDays = Boolean.parseBoolean(grandchild.getAttributeValue(XML_ATTRIBUTE_DAYS));
                        Localized comment = new Localized(grandchild, XML_ATTRIBUTE_COMMENT);
                        Number mult = parseNumber(nf, grandchild, XML_ATTRIBUTE_MULT, 1);
                        Pace newPace = new Pace(pace, comment, useDays, mult);
                        method.add(newPace);
                    }
                    if (grandchild.getName().equals(XML_ELEMENT_CHOOSE_FROM)) {
                        // XXX other default?
                        Number kmh = parseNumber(nf, grandchild, XML_ATTRIBUTE_KMH, 0.75);
                        // XXX other default?
                        Number mph = parseNumber(nf, grandchild, XML_ATTRIBUTE_MPH, 0.5);
                        // XXX other default?
                        Number hoursInDay = parseNumber(nf, grandchild, XML_ATTRIBUTE_HOURSINDAY, 24);
                        for (Object o2 : grandchild.getChildren(XML_ELEMENT_CHOICE)) {
                            if (o2 instanceof Element) {
                                Element grandgrandchild = (Element) o2;
                                Localized choiceName = new Localized(grandgrandchild);
                                Number mult = parseNumber(nf, grandgrandchild, XML_ATTRIBUTE_MULT, 1);
                                Choice c = new Choice(choiceName, hoursInDay, mult.doubleValue() * kmh.doubleValue(), mult.doubleValue() * mph.doubleValue());
                                method.add(c);
                            }
                        }
                    }
                }
            }
        }
    }
    return new TravelMethodImplementation(name, multByRoadByTerrains, terrains2, terrainsById2, routes2, routesById2, methods);
}
Also used : Choice(plugin.overland.model.TravelMethodImplementation.Choice) HashMap(java.util.HashMap) Element(org.jdom2.Element) ArrayList(java.util.ArrayList) Combo(plugin.overland.model.TravelMethodImplementation.Combo) Pace(plugin.overland.model.TravelMethodImplementation.Pace) ArrayList(java.util.ArrayList) List(java.util.List) Method(plugin.overland.model.TravelMethodImplementation.Method) TreeMap(java.util.TreeMap) HashMap(java.util.HashMap) TreeMap(java.util.TreeMap) Map(java.util.Map) Localized(plugin.overland.util.Localized) NumberFormat(java.text.NumberFormat)

Example 8 with Element

use of org.omegat.filters3.Element in project gocd by gocd.

the class BuildLogElement method setBuildLogHeader.

public Element setBuildLogHeader(String execCommand) {
    Element target = new Element("target");
    target.setAttribute("name", "exec");
    build.addContent(target);
    buildTask = new Element("task");
    buildTask.setAttribute("name", execCommand);
    target.addContent(buildTask);
    return buildTask;
}
Also used : Element(org.jdom2.Element)

Example 9 with Element

use of org.omegat.filters3.Element in project gocd by gocd.

the class BuildWork method execute.

private JobResult execute(EnvironmentVariableContext environmentVariableContext) {
    Date now = new Date();
    // collect project information
    // TODO - #2409
    buildLog.addContent(new Element("info"));
    JobResult result = builders.build(environmentVariableContext);
    goPublisher.reportCompleting(result);
    try {
        buildLog.writeLogFile(now);
    } catch (IOException e) {
        throw bomb("Failed to write log file", e);
    }
    buildLog.reset();
    return result;
}
Also used : Element(org.jdom2.Element) IOException(java.io.IOException) Date(java.util.Date)

Example 10 with Element

use of org.omegat.filters3.Element in project gocd by gocd.

the class GoControlLog method writeLogFile.

/**
     * Writes the current build log to the appropriate directory and filename.
     */
public void writeLogFile(Date now) throws IOException {
    String logFilename = decideLogfileName(now);
    // Add the logDir as an info element
    Element logDirElement = new Element("property");
    logDirElement.setAttribute("name", "logdir");
    logDirElement.setAttribute("value", new File(logDir).getAbsolutePath());
    buildLog.getChild("info").addContent(logDirElement);
    // Add the logFile as an info element
    Element logFileElement = new Element("property");
    logFileElement.setAttribute("name", "logfile");
    logFileElement.setAttribute("value", logFilename);
    buildLog.getChild("info").addContent(logFileElement);
    File logfile = new File(logDir, logFilename);
    if (LOG.isDebugEnabled()) {
        LOG.debug("Writing log file [" + logfile.getAbsolutePath() + "]");
    }
    writeLogFile(logfile, buildLog);
}
Also used : Element(org.jdom2.Element) File(java.io.File)

Aggregations

Element (org.jdom2.Element)1444 Document (org.jdom2.Document)242 Test (org.junit.Test)157 ArrayList (java.util.ArrayList)111 Attribute (org.jdom2.Attribute)106 IOException (java.io.IOException)76 File (java.io.File)71 JDOMException (org.jdom2.JDOMException)65 XMLOutputter (org.jdom2.output.XMLOutputter)54 List (java.util.List)51 SAXBuilder (org.jdom2.input.SAXBuilder)51 HashMap (java.util.HashMap)49 Test (org.junit.jupiter.api.Test)34 Map (java.util.Map)33 Node (gov.cms.qpp.conversion.model.Node)29 MCRException (org.mycore.common.MCRException)28 MCRJDOMContent (org.mycore.common.content.MCRJDOMContent)28 NamedIcon (jmri.jmrit.catalog.NamedIcon)27 Namespace (org.jdom2.Namespace)25 XmlFile (jmri.jmrit.XmlFile)24