List of usage examples for org.jdom2 Document Document
public Document(List<? extends Content> content)
Document
, with the supplied list of content, and a DocType
declaration only if the content contains a DocType instance. From source file:neon.editor.tools.SVGConverter.java
License:Open Source License
private static void save(Element shapes, int width, int height) throws IOException { Element root = new Element("map"); root.setAttribute("id", "aneirin"); root.setAttribute("name", "Aneirin"); root.setAttribute("uid", "1"); root.setAttribute("module", "aneirin"); Element size = new Element("size"); size.setAttribute("width", Integer.toString(width)); size.setAttribute("height", Integer.toString(height)); root.addContent(size);/*from ww w .j av a 2s . co m*/ int dx = 0; int dy = 13700; Element terrain = new Element("terrain"); root.addContent(terrain); Element base = new Element("region"); base.setAttribute("x", "0"); base.setAttribute("y", "0"); base.setAttribute("w", Integer.toString(width)); base.setAttribute("h", Integer.toString(height)); base.setAttribute("id", "sea"); terrain.addContent(base); for (Element rect : shapes.getChildren("rect", ns)) { int x = Integer.parseInt(rect.getAttributeValue("x")) + dx; int y = Integer.parseInt(rect.getAttributeValue("y")) + dy; int w = Integer.parseInt(rect.getAttributeValue("width")); int h = Integer.parseInt(rect.getAttributeValue("height")); String id = "grass"; String style = rect.getAttributeValue("style"); if (style.contains("#ffff00")) { id = "sand"; } else if (style.contains("#ff0000")) { id = "mud"; } else if (style.contains("#550000")) { id = "rock"; } else if (style.contains("#22cc51")) { id = "moss"; } else if (style.contains("#008080")) { id = "marsh"; } else if (style.contains("#bcff00")) { id = "meadow"; } Element region = new Element("region"); region.setAttribute("x", Integer.toString(x)); region.setAttribute("y", Integer.toString(y)); region.setAttribute("w", Integer.toString(w)); region.setAttribute("h", Integer.toString(h)); region.setAttribute("id", id); terrain.addContent(region); } Element elevation = new Element("elevation"); root.addContent(elevation); Element entities = new Element("entities"); root.addContent(entities); XMLOutputter outputter = new XMLOutputter(); outputter.setFormat(Format.getPrettyFormat()); outputter.output(new Document(root), new FileWriter("temp/map.xml")); }
From source file:neon.editor.XMLBuilder.java
License:Open Source License
public Document getEventsDoc() { Element root = new Element("events"); for (String script : store.getEvents().keySet()) { for (String stamp : store.getEvents().get(script)) { Element event = new Element("event"); event.setAttribute("script", script); event.setAttribute("tick", stamp); root.addContent(event);/* www . j ava2s . co m*/ } } return new Document(root); }
From source file:neon.editor.XMLBuilder.java
License:Open Source License
public Document getListDoc(Collection<? extends RData> elements, String name, RMod mod) { Element root = new Element(name); for (RData resource : elements) { if (resource.getPath()[0].equals(mod.get("id"))) { root.addContent(resource.toElement()); }/* w w w . j a v a 2 s . co m*/ } return new Document(root); }
From source file:neon.editor.XMLBuilder.java
License:Open Source License
public Document getResourceDoc(Collection<? extends RData> elements, String name, RMod mod) { ArrayList<RData> buffer = new ArrayList<RData>(elements); Collections.sort(buffer, new IDComparator()); Element root = new Element(name); for (RData resource : buffer) { if (resource.getPath()[0].equals(mod.get("id"))) { root.addContent(resource.toElement()); }/*from w w w . j av a2 s.c o m*/ } return new Document(root); }
From source file:neon.server.entity.EntityManager.java
License:Open Source License
private void saveEntity(Entity entity) { Document doc = new Document(saver.save(entity)); try {/*from w w w . j ava 2 s. c o m*/ files.saveFile(doc, new XMLTranslator(), "entities", Long.toString(entity.uid) + ".xml"); } catch (IOException e) { e.printStackTrace(); } }
From source file:neon.server.resource.ConfigurationLoader.java
License:Open Source License
@Override public void save(Resource resource) throws IOException { if (resource.id.equals("game")) { Element root = saveGame(CGame.class.cast(resource)); files.saveFile(new Document(root), translator, namespace, resource.id + ".xml"); } else if (resource.id.equals("client")) { Element root = saveClient(CClient.class.cast(resource)); files.saveFile(new Document(root), translator, namespace, resource.id + ".xml"); } else if (resource.id.equals("server")) { Element root = saveServer(CServer.class.cast(resource)); files.saveFile(new Document(root), translator, namespace, resource.id + ".xml"); } else {/*from w ww. j a v a 2 s .c om*/ throw new IllegalArgumentException("Argument is not a configuration resource"); } }
From source file:neon.systems.conversation.DialogLoader.java
License:Open Source License
@Override public void save(Resource resource) throws IOException { Element dialog = new Element("dialog"); files.saveFile(new Document(dialog), translator, namespace, resource.id + ".xml"); }
From source file:neon.systems.magic.SpellLoader.java
License:Open Source License
@Override public void save(Resource resource) throws IOException { Element spell = new Element("spell"); files.saveFile(new Document(spell), translator, namespace, resource.id + ".xml"); }
From source file:neon.systems.narrative.QuestLoader.java
License:Open Source License
@Override public void save(Resource resource) throws IOException { RQuest quest = RQuest.class.cast(resource); Element root = new Element("quest"); root.setAttribute("id", quest.id); files.saveFile(new Document(root), translator, namespace, resource.id + ".xml"); }
From source file:net.alegen.datpass.library.configure.XMLConfigurator.java
License:Open Source License
public XMLConfigurator(String configFileName) throws IOException, JDOMException { try {/*from www . j av a 2 s .co m*/ this.configFileName = configFileName; File configFile = new File(configFileName); if (!configFile.exists()) { this.root = new Element(XmlConstants.DATPASS); Document doc = new Document(this.root); XMLOutputter xmlOutput = new XMLOutputter(); xmlOutput.setFormat(Format.getPrettyFormat()); FileWriter fileWriter = new FileWriter(configFileName); xmlOutput.output(doc, fileWriter); fileWriter.flush(); fileWriter.close(); } else this.root = new SAXBuilder().build(configFile).getRootElement(); } catch (JDOMException e) { log.error("The XML configuration file is not valid. Please check for syntax errors."); throw e; } catch (IOException e) { log.error("There was a problem when trying to read the XML configuration file."); throw e; } }