| 19 | // Internal dependancies: Logger, Main |
| 20 | |
| 21 | public class ExitParser { |
| 22 | |
| 23 | public static Document getDocument(String docString) { |
| 24 | try { |
| 25 | DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance(); |
| 26 | factory.setIgnoringComments(true); |
| 27 | factory.setIgnoringElementContentWhitespace(true); |
| 28 | DocumentBuilder builder = factory.newDocumentBuilder(); |
| 29 | return builder.parse(new InputSource(docString)); |
| 30 | } |
| 31 | catch(Exception ex) { |
| 32 | Logger.error(ex.getMessage()); |
| 33 | } |
| 34 | return null; |
| 35 | } |
| 36 | |
| 37 | public static void createNewSave(File pathToFile) throws IOException { |
| 38 | pathToFile.getParentFile().mkdirs(); |
| 39 | InputStream stream = null; |
| 40 | OutputStream resStreamOut = null; |
| 41 | String jarFolder; |
| 42 | try { |
| 43 | stream = ExitParser.class.getResourceAsStream("/resources/save.ecsave");//note that each / is a directory down in the "jar tree" been the jar the root of the tree |
| 44 | if(stream == null) { |
| 45 | throw new Exception("Cannot get resource \"/resources/save.ecsave\" from Jar file."); |
| 46 | } |
| 47 | int readBytes; |
| 48 | byte[] buffer = new byte[4096]; |
| 49 | resStreamOut = new FileOutputStream(pathToFile); |
| 50 | while ((readBytes = stream.read(buffer)) > 0) { |
| 51 | resStreamOut.write(buffer, 0, readBytes); |
| 52 | } |
| 53 | } catch (Exception ex) { |
| 54 | ex.printStackTrace(); |
| 55 | } finally { |
| 56 | stream.close(); |
| 57 | resStreamOut.close(); |
| 58 | } |
| 59 | } |
| 60 | |
| 61 | public static String getBuildDefaultSystem(String hostname) { |
| 62 | String system = String.format("<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"no\"?>\n\n" + |
| 63 | "<system>\n" + |
| 64 | " <info>\n" + |
| 65 | " <system name=\"PiXElos\"/>\n" + |
| 66 | " <host name=\"%s\"/>\n" + |
| 67 | " <owner uid=\"1000\"/>\n" + |
| 68 | " <top dir=\"/\"/>\n" + |
| 69 | " </info>\n" + |
| 70 | "\n" + |
| 71 | " <hardware>\n" + |
| 72 | " <type name=\"Laptop\"/>\n" + |
| 73 | " <cpu ghz=\"1.0\" cores=\"1\" type=\"1\" upgradeable=\"false\"/>\n" + |
| 74 | " <ram mb=\"500\" max_mb=\"500\" upgradeable=\"false\"/>\n" + |
| 75 | " <storage mb=\"1000\" type=\"1\" upgradeable=\"false\"/>\n" + |
| 76 | " </hardware>\n" + |
| 77 | "\n" + |
| 78 | " <files>\n" + |
nothing calls this directly
no outgoing calls
no test coverage detected