/** * Writes the current skin to the specified XML file. * * @param filename */ public static void writeSkinToFile(String filename) { File filePath = new MegaMekFile(Configuration.skinsDir(), filename).getFile(); try (Writer output = new BufferedWriter(new OutputStreamWriter( new FileOutputStream(filePath)));){ output.write(SKIN_HEADER); for (String component : skinSpecs.keySet()) { writeSkinComponent(component, output); } if (udSpec != null) { writeUnitDisplaySkinSpec(output); } output.write(SKIN_FOOTER); output.close(); } catch (IOException e) { System.out.println(e.getMessage()); e.printStackTrace(); } }
/** * Checks whether the given path points to a file that is a valid skin * specification. * * @param path * @return */ public static boolean validSkinSpecFile(String fileName) { File file = new MegaMekFile(Configuration.skinsDir(), fileName).getFile(); if (!file.exists() || !file.isFile()) { return false; } try { DocumentBuilder builder = MegaMekXmlUtil.newSafeDocumentBuilder(); Document doc = builder.parse(file); // TODO: Just validate against the XSD // Until that's done, just assume anything with UI_ELEMENT tags is // valid NodeList listOfComponents = doc.getElementsByTagName(UI_ELEMENT); if (listOfComponents.getLength() > 0) { return true; } else { return false; } } catch (Exception e) { return false; } }
/** * */ private void updateSkinCombo() { removeListeners(); currSkinCombo.removeAllItems(); String[] xmlFiles = Configuration.skinsDir().list(new FilenameFilter() { public boolean accept(File directory, String fileName) { return fileName.endsWith(".xml"); } }); for (String file : xmlFiles) { if (SkinXMLHandler.validSkinSpecFile(file)) { currSkinCombo.addItem(file); } } // Select the default file first currSkinCombo.setSelectedItem(SkinXMLHandler.defaultSkinXML); // If this select fails, the default skin will be selected currSkinCombo.setSelectedItem(GUIPreferences.getInstance() .getSkinFile()); addListeners(); }
File file = new MegaMekFile(Configuration.skinsDir(), fileName).getFile(); if (!file.exists() || !file.isFile()) { System.out.println("ERROR: Bad skin specification file: " +
.asList(Configuration.skinsDir().list(new FilenameFilter() { public boolean accept(File directory, String fileName) { return fileName.endsWith(".xml"); String[] files = new File(Configuration.userdataDir(), Configuration.skinsDir().toString()) .list(new FilenameFilter() { public boolean accept(File directory, String fileName) {