List of usage examples for org.jdom2 Element detach
@Override
public Element detach()
From source file:neon.editor.DataStore.java
License:Open Source License
private Element loadCC(String... file) { Element cc; try {/*from w w w . j a v a 2 s . com*/ cc = Editor.files.getFile(new XMLTranslator(), file).getRootElement(); cc.detach(); } catch (NullPointerException e) { // file bestaat niet cc = new Element("root"); cc.addContent(new Element("races")); cc.addContent(new Element("items")); cc.addContent(new Element("spells")); cc.addContent(new Element("map")); } return cc; }
From source file:neon.editor.editors.NPCEditor.java
License:Open Source License
protected void save() { data.name = nameField.getText();//from w ww.j a va 2s . c o m RCreature species = raceBox.getItemAt(raceBox.getSelectedIndex()); data.species = species.id; if (species.aiType.equals(aiTypeBox.getItemAt(aiTypeBox.getSelectedIndex()))) { data.aiType = null; } else { data.aiType = aiTypeBox.getItemAt(aiTypeBox.getSelectedIndex()); } if (species.aiRange == (Integer) rangeField.getValue()) { data.aiRange = -1; } else { data.aiRange = (Integer) rangeField.getValue(); } if (species.aiAggr == (Integer) aggressionSpinner.getValue()) { data.aiAggr = -1; } else { data.aiAggr = (Integer) aggressionSpinner.getValue(); } if (species.aiConf == (Integer) confidenceSpinner.getValue()) { data.aiConf = -1; } else { data.aiConf = (Integer) confidenceSpinner.getValue(); } data.factions.clear(); for (String f : joinedFactions.keySet()) { data.factions.put(f, joinedFactions.get(f)); } data.services.clear(); if (tradeBox.isSelected()) { data.services.add(new Element("service").setAttribute("id", "trade")); } data.items.clear(); for (Enumeration<String> e = itemListModel.elements(); e.hasMoreElements();) { data.items.add(e.nextElement()); } if (spellMakerBox.isSelected()) { data.services.add(new Element("service").setAttribute("id", "spellmaker")); } if (healerBox.isSelected()) { data.services.add(new Element("service").setAttribute("id", "healer")); } if (spellBox.isSelected()) { data.services.add(new Element("service").setAttribute("id", "spells")); } for (Enumeration<String> e = spellListModel.elements(); e.hasMoreElements();) { data.spells.add(e.nextElement()); } if (trainBox.isSelected()) { Element training = new Element("service"); training.setAttribute("id", "training"); data.services.add(training); for (Skill s : trainedSkills) { training.addContent(new Element("skill").setText(s.toString())); } } data.skills.clear(); for (Skill s : skills.keySet()) { if (skills.get(s) != null && !skills.get(s).equals(0)) { skills.put(s, skills.get(s)); } } if (travelBox.isSelected()) { Element travel = new Element("service"); travel.setAttribute("id", "travel"); // effen wat magic om laatst aangepaste waarde toch nog in destMap te frommelen if (currentDest != null) { currentDest.setAttribute("x", destX.getValue().toString()); currentDest.setAttribute("y", destY.getValue().toString()); currentDest.setAttribute("cost", destCost.getValue().toString()); } // magic gedaan for (Element d : destMap.values()) { d.detach(); travel.addContent(d); } data.services.add(travel); } if (potionBox.isSelected()) { data.services.add(new Element("service").setAttribute("id", "alchemy")); } if (tattooBox.isSelected()) { data.services.add(new Element("service").setAttribute("id", "tattoo")); } data.setPath(Editor.getStore().getActive().get("id")); }
From source file:neon.editor.resources.RMap.java
License:Open Source License
public Element toElement() { System.out.println("save map: " + name); Element root = new Element(isDungeon() ? "dungeon" : "world"); Element header = new Element("header"); header.setAttribute("uid", Short.toString(uid)); header.addContent(new Element("name").setText(name)); root.addContent(header);/* w w w. j a va 2 s. c o m*/ if (type == DUNGEON) { for (Integer level : zones.keySet()) { root.addContent(zones.get(level).toElement().setAttribute("l", level.toString())); } } else { RZone zone = zones.get(0); Element creatures = new Element("creatures"); Element items = new Element("items"); Element regions = new Element("regions"); for (Renderable r : zone.getScene().getElements()) { Instance i = (Instance) r; Element element = i.toElement(); element.detach(); if (element.getName().equals("region")) { regions.addContent(element); } else if (element.getName().equals("creature")) { creatures.addContent(element); } else if (element.getName().equals("item") || element.getName().equals("door") || element.getName().equals("container")) { items.addContent(element); } } root.addContent(creatures); root.addContent(items); root.addContent(regions); } return root; }
From source file:neon.editor.resources.RZone.java
License:Open Source License
public Element toElement() { Element level = new Element("level"); level.setAttribute("name", name); Element creatures = new Element("creatures"); Element items = new Element("items"); Element regions = new Element("regions"); for (Renderable r : scene.getElements()) { Instance i = (Instance) r;//ww w . j av a 2s.c o m Element element = i.toElement(); element.detach(); if (element.getName().equals("region")) { regions.addContent(element); } else if (element.getName().equals("creature")) { creatures.addContent(element); } else if (element.getName().equals("item") || element.getName().equals("door") || element.getName().equals("container")) { items.addContent(element); } } level.addContent(creatures); level.addContent(items); level.addContent(regions); return level; }
From source file:neon.resources.RPerson.java
License:Open Source License
public RPerson(Element person, String... path) { super(person.getAttributeValue("id"), path); name = person.getAttributeValue("name"); species = person.getAttributeValue("race"); if (person.getChild("factions") != null) { for (Element f : person.getChild("factions").getChildren()) { int rank = f.getAttribute("rank") != null ? Integer.parseInt(f.getAttributeValue("rank")) : 0; factions.put(f.getAttributeValue("id"), rank); }// w w w. ja v a 2s. c om } Element brain = person.getChild("ai"); if (brain != null && !brain.getText().isEmpty()) { aiType = AIType.valueOf(brain.getText()); } else { aiType = null; } if (brain != null && brain.getAttribute("r") != null) { aiRange = Integer.parseInt(brain.getAttributeValue("r")); } else { aiRange = -1; } if (brain != null && brain.getAttribute("a") != null) { aiAggr = Integer.parseInt(brain.getAttributeValue("a")); } else { aiAggr = -1; } if (brain != null && brain.getAttribute("c") != null) { aiConf = Integer.parseInt(brain.getAttributeValue("c")); } else { aiConf = -1; } Element skillList = person.getChild("skills"); if (skillList != null) { for (Element skill : skillList.getChildren()) { skills.put(Skill.valueOf(skill.getAttributeValue("id").toUpperCase()), Integer.parseInt(skill.getAttributeValue("rank"))); } } Element itemList = person.getChild("items"); if (itemList != null) { for (Element item : itemList.getChildren()) { items.add(item.getAttributeValue("id")); } } Element spellList = person.getChild("spells"); if (spellList != null) { for (Element spell : spellList.getChildren()) { spells.add(spell.getAttributeValue("id")); } } // nieuwe arraylist om concurrentmodificationexceptions te vermijden for (Element service : new ArrayList<Element>(person.getChildren("service"))) { services.add(service.detach()); } for (Element script : person.getChildren("script")) { scripts.add(script.getText()); } }
From source file:neon.resources.RPerson.java
License:Open Source License
public Element toElement() { Element npc = new Element("npc"); npc.setAttribute("race", species); npc.setAttribute("id", id); for (Element service : services) { service.detach(); // anders fout bij 2de keer saven npc.addContent(service);/*from w w w. j a v a2 s . c o m*/ } if (!factions.isEmpty()) { Element factionList = new Element("factions"); for (String f : factions.keySet()) { Element faction = new Element("faction"); faction.setAttribute("id", f); faction.setAttribute("rank", Integer.toString(factions.get(f))); factionList.addContent(faction); } npc.addContent(factionList); } if (!items.isEmpty()) { Element itemList = new Element("items"); for (String ri : items) { Element item = new Element("item"); item.setAttribute("id", ri); itemList.addContent(item); } npc.addContent(itemList); } if (!spells.isEmpty()) { Element spellList = new Element("spells"); for (String rs : spells) { Element spell = new Element("spell"); spell.setAttribute("id", rs); spellList.addContent(spell); } npc.addContent(spellList); } if (aiAggr > -1 || aiConf > -1 || aiRange > -1 || aiType != null) { Element ai = new Element("ai"); if (aiType != null) { ai.setText(aiType.toString()); } if (aiAggr > -1) { ai.setAttribute("a", Integer.toString(aiAggr)); } if (aiConf > -1) { ai.setAttribute("c", Integer.toString(aiConf)); } if (aiRange > -1) { ai.setAttribute("r", Integer.toString(aiRange)); } npc.addContent(ai); } return npc; }
From source file:neon.resources.RRegionTheme.java
License:Open Source License
public RRegionTheme(Element theme, String... path) { super(theme.getAttributeValue("id"), path); String[] data = theme.getAttributeValue("random").split(";"); for (Element creature : theme.getChildren("creature")) { creatures.put(creature.getText(), Integer.parseInt(creature.getAttributeValue("n"))); }/*from ww w . j av a 2 s.com*/ // nieuwe arraylist om concurrentmodificationexceptions te vermijden for (Element feature : new ArrayList<Element>(theme.getChildren("feature"))) { features.add(feature.detach()); } floor = theme.getAttributeValue("floor"); type = Type.valueOf(data[0]); for (Element plant : theme.getChildren("plant")) { int abundance = Integer.parseInt(plant.getAttributeValue("a")); vegetation.put(plant.getText(), abundance); } switch (type) { // mottig switch met ontbrekende breaks case town: case town_big: case town_small: wall = data[1]; door = data[2]; break; default: break; } }
From source file:neon.ui.graphics.svg.SVGLoader.java
License:Open Source License
public static JVShape loadShape(String shape) { StringReader stringReader = new StringReader(shape); SAXBuilder builder = new SAXBuilder(); // doc al initialiseren, in geval builder.build faalt Document doc = new Document(); try {//from w w w. ja v a 2 s . c o m doc = builder.build(stringReader); } catch (Exception e) { e.printStackTrace(); } Element root = doc.getRootElement(); root.detach(); return loadShape(root); }
From source file:net.alegen.datpass.library.configure.XMLConfigurator.java
License:Open Source License
@Override public void removeProfile(String profileName) { Element profilesElem = this.root.getChild(XmlConstants.PROFILES); for (Element elem : profilesElem.getChildren()) { String name = elem.getAttributeValue(FieldManager.NAME_FIELD); if (name != null && name.equals(profileName)) { elem.detach(); return; }// w w w . jav a 2 s.c o m } }
From source file:net.visualillusionsent.tellplugin.xml.TellSaveHandler.java
License:Open Source License
public void deleteData(Tell tell) { ArrayList<Element> toremove = new ArrayList<Element>(); for (Element element : getDocument().getRootElement().getChildren()) { VIBotX.log.info(element.getChildText("receiver")); VIBotX.log.info(element.getChildText("sender")); VIBotX.log.info(element.getChildText("message")); VIBotX.log.info(element.getChildText("date")); if (!tell.getReceiver().equals(element.getChildText("receiver"))) continue; if (!tell.getSender().equals(element.getChildText("sender"))) continue; if (!tell.getMessage().equals(element.getChildText("message"))) continue; if (!tell.getDateString().equals(element.getChildText("date"))) continue; toremove.add(element);//from w w w .j av a 2 s .c o m } for (Element e : toremove) { e.detach(); } try { write(); } catch (IOException e) { VIBotX.log.error("Error deleting from TellPlugin Xml File", e); } }