List of usage examples for org.jdom2 Document Document
public Document()
From source file:neon.common.files.XMLTranslator.java
License:Open Source License
@Override public Document translate(InputStream input) throws IOException { Document doc = new Document(); try {/*from w w w .j a v a2s .c o m*/ doc = new SAXBuilder().build(input); } catch (JDOMException e) { logger.severe("JDOMException in XMLTranslator"); } return doc; }
From source file:neon.core.GameLoader.java
License:Open Source License
private void loadGame(String save) { Document doc = new Document(); try {/*from w w w. j ava 2s . c o m*/ FileInputStream in = new FileInputStream("saves/" + save + "/save.xml"); doc = new SAXBuilder().build(in); in.close(); } catch (IOException e) { System.out.println("IOException in loadGame"); } catch (JDOMException e) { System.out.println("JDOMException in loadGame"); } Element root = doc.getRootElement(); // save map naar temp kopiren Path savePath = Paths.get("saves", save); Path tempPath = Paths.get("temp"); FileUtils.copy(savePath, tempPath); // maps initialiseren initMaps(engine.getGame().getStore()); // tijd juist zetten (met setTime(), anders worden listeners aangeroepen) engine.getTimer().setTime(Integer.parseInt(root.getChild("timer").getAttributeValue("ticks"))); // player aanmaken loadPlayer(root.getChild("player"), engine.getGame().getAtlas()); // events loadEvents(root.getChild("events")); // quests Element journal = root.getChild("journal"); for (Element e : journal.getChildren()) { Engine.getPlayer().getJournal().addQuest(e.getAttributeValue("id"), e.getText()); Engine.getPlayer().getJournal().updateQuest(e.getAttributeValue("id"), Integer.parseInt(e.getAttributeValue("stage"))); } }
From source file:neon.core.GameSaver.java
License:Open Source License
/** * Saves the current game./*from w w w. j a v a2s . c om*/ */ @Subscribe public void saveGame(SaveEvent se) { Document doc = new Document(); Element root = new Element("save"); doc.setRootElement(root); Player player = Engine.getPlayer(); root.addContent(savePlayer(player)); // player data saven root.addContent(saveJournal(player)); // journal saven root.addContent(saveEvents()); // events saven root.addContent(saveQuests()); // quests saven Element timer = new Element("timer"); timer.setAttribute("ticks", String.valueOf(Engine.getTimer().getTime())); root.addContent(timer); File saves = new File("saves"); if (!saves.exists()) { saves.mkdir(); } File dir = new File("saves/" + player.getName()); if (!dir.exists()) { dir.mkdir(); } // eerst alles vanuit temp naar save kopiren, zodat savedoc zeker niet overschreven wordt Engine.getGame().getAtlas().getCache().commit(); Engine.getGame().getStore().getCache().commit(); files.storeTemp(dir); files.saveFile(doc, new XMLTranslator(), "saves", player.getName(), "save.xml"); }
From source file:neon.editor.ModFiler.java
License:Open Source License
void load(File file, boolean active) { String path = file.getPath(); try {// ww w .j av a 2s .com path = files.mount(path); if (!isMod(path)) { // kijken of dit wel mod is JOptionPane.showMessageDialog(frame, "Selected file is not a valid mod."); files.removePath(path); } else { if (isExtension(path)) { // als extensie: alle masters laden Document doc = files.getFile(new XMLTranslator(), path, "main.xml"); for (Object master : doc.getRootElement().getChildren("master")) { String id = ((Element) master).getText(); Document ini = new Document(); try { // kijken in neon.ini welke mods er zijn FileInputStream in = new FileInputStream("neon.ini"); ini = new SAXBuilder().build(in); in.close(); } catch (JDOMException e) { } // kijken of er een mod is met de juist id for (Element mod : ini.getRootElement().getChild("files").getChildren()) { if (!mod.getText().equals(path)) { // zien dat huidige mod niet nog eens geladen wordt System.out.println(mod.getText() + ", " + path); files.mount(mod.getText()); Document d = files.getFile(new XMLTranslator(), mod.getText(), "main.xml"); if (d.getRootElement().getAttributeValue("id").equals(id)) { store.loadData(mod.getText(), false, false); } else { files.removePath(mod.getText()); } } } } } frame.setTitle("Neon Editor: " + path); store.loadData(path, active, isExtension(path)); editor.mapEditor.loadMaps(Editor.resources.getResources(RMap.class), path); editor.enableEditing(file.isDirectory()); frame.pack(); } } catch (IOException e1) { JOptionPane.showMessageDialog(frame, "Selected file is not a valid mod."); } }
From source file:neon.editor.ModFiler.java
License:Open Source License
private void saveMaps() { for (String name : files.listFiles(store.getActive().getPath()[0], "maps")) { String map = name.substring(name.lastIndexOf(File.separator) + 1, name.length() - 4); // -4 voor ".xml" if (Editor.resources.getResource(map, "maps") == null) { files.delete(name);/*from w ww. ja v a2 s . c o m*/ } } for (RMap map : editor.mapEditor.getActiveMaps()) { Document doc = new Document().setRootElement(map.toElement()); saveFile(doc, "maps", map.id + ".xml"); } }
From source file:neon.editor.tools.SVGConverter.java
License:Open Source License
public static void main(String[] args) throws FileNotFoundException, JDOMException, IOException { System.out.println("loading svg file"); Document doc = new Document(); File file = new File("temp/neon.svg"); doc = new SAXBuilder().build(new FileInputStream(file)); Element svg = doc.getRootElement(); int width = Integer.parseInt(svg.getAttributeValue("width")); int height = Integer.parseInt(svg.getAttributeValue("height")); Element terrain = svg.getChild("g", ns); System.out.println("saving map"); save(terrain, width, height);/* w w w .j av a 2 s . co m*/ System.out.println("finished"); }
From source file:neon.resources.CClient.java
License:Open Source License
public CClient(String... path) { super("client", path); // file inladen Document doc = new Document(); try (FileInputStream in = new FileInputStream(path[0])) { doc = new SAXBuilder().build(in); } catch (Exception e) { e.printStackTrace();/*from w w w .j av a2 s. com*/ } Element root = doc.getRootElement(); // keyboard setKeys(root.getChild("keys")); // taal Properties defaults = new Properties(); // locale.en laden als default try (FileInputStream stream = new FileInputStream("data/locale/locale.en"); InputStreamReader reader = new InputStreamReader(stream, Charset.forName("UTF-8"))) { defaults.load(reader); } catch (IOException e) { e.printStackTrace(); } String lang = root.getChild("lang").getText(); strings = new Properties(defaults); // locale initialiseren met 'en' defaults try (FileInputStream stream = new FileInputStream("data/locale/locale." + lang); InputStreamReader reader = new InputStreamReader(stream, Charset.forName("UTF-8"))) { strings.load(reader); } catch (IOException e) { e.printStackTrace(); } }
From source file:neon.resources.CServer.java
License:Open Source License
public CServer(String... path) { super("ini", path); // file inladen Document doc = new Document(); try (FileInputStream in = new FileInputStream(path[0])) { doc = new SAXBuilder().build(in); } catch (Exception e) { e.printStackTrace();// w w w . j av a 2 s.c om } Element root = doc.getRootElement(); // mods Element files = root.getChild("files"); for (Element file : files.getChildren("file")) { mods.add(file.getText()); } // logging log = root.getChildText("log").toUpperCase(); // ai range ai = Integer.parseInt(root.getChildText("ai")); }
From source file:neon.systems.files.XMLTranslator.java
License:Open Source License
public Document translate(InputStream input) { Document doc = new Document(); try {//from w w w .j av a 2s .c o m doc = new SAXBuilder().build(input); input.close(); } catch (IOException e) { System.out.println("IOException in XMLTranslator"); } catch (JDOMException e) { System.out.println("JDOMException in XMLTranslator"); } return doc; }
From source file:neon.ui.dialog.OptionDialog.java
License:Open Source License
@FXML private void save() { Document doc = new Document(); try {/*from www. ja v a 2 s . c om*/ FileInputStream in = new FileInputStream("neon.ini"); doc = new SAXBuilder().build(in); in.close(); } catch (Exception e) { Engine.getLogger().severe(e.getMessage()); } Element ini = doc.getRootElement(); if (numpadButton.isSelected()) { config.setKeys(CClient.KeyboardSetting.NUMPAD); ini.getChild("keys").setText("numpad"); } else if (azertyButton.isSelected()) { config.setKeys(CClient.KeyboardSetting.AZERTY); ini.getChild("keys").setText("azerty"); } else if (qwertyButton.isSelected()) { config.setKeys(CClient.KeyboardSetting.QWERTY); ini.getChild("keys").setText("qwerty"); } else if (qwertzButton.isSelected()) { config.setKeys(CClient.KeyboardSetting.QWERTZ); ini.getChild("keys").setText("qwertz"); } XMLOutputter outputter = new XMLOutputter(Format.getPrettyFormat()); try { FileOutputStream out = new FileOutputStream("neon.ini"); outputter.output(doc, out); out.close(); } catch (IOException e) { Engine.getLogger().severe(e.getMessage()); } stage.close(); }