public void saveConfiguration(File file) throws IOException { try { DocumentBuilderFactory dbFactory = DocumentBuilderFactory.newInstance(); DocumentBuilder dBuilder = dbFactory.newDocumentBuilder(); Document configuration = dBuilder.newDocument(); Element configRoot = configuration.createElement("configuration"); configuration.appendChild(configRoot); Element prefElement = configuration.createElement("preferences"); configRoot.appendChild(prefElement); preferences.saveValuesToXML(prefElement); Element modulesElement = configuration.createElement("modules"); configRoot.appendChild(modulesElement); // traverse modules for (MZmineModule module : MZmineStarter.getAllModules()) { String className = module.getClass().getName(); Element moduleElement = configuration.createElement("module"); moduleElement.setAttribute("class", className); modulesElement.appendChild(moduleElement); Element paramElement = configuration.createElement("parameters"); moduleElement.appendChild(paramElement); ParameterSet moduleParameters = getModuleParameters(module.getClass()); moduleParameters.saveValuesToXML(paramElement); } TransformerFactory transfac = TransformerFactory.newInstance(); Transformer transformer = transfac.newTransformer(); transformer.setOutputProperty(OutputKeys.METHOD, "xml"); transformer.setOutputProperty(OutputKeys.INDENT, "yes"); transformer.setOutputProperty(OutputKeys.ENCODING, "UTF-8"); transformer.setOutputProperty("{http://xml.apache.org/xslt}indent-amount", "4"); StreamResult result = new StreamResult(new FileOutputStream(file)); DOMSource source = new DOMSource(configuration); transformer.transform(source, result); logger.info("Saved configuration to file " + file); } catch (Exception e) { throw new IOException(e); } }
public void loadConfiguration(File file) throws IOException { try { DocumentBuilderFactory dbFactory = DocumentBuilderFactory.newInstance(); DocumentBuilder dBuilder = dbFactory.newDocumentBuilder(); Document configuration = dBuilder.parse(file); XPathFactory factory = XPathFactory.newInstance(); XPath xpath = factory.newXPath(); logger.info("Loading desktop configuration"); XPathExpression expr = xpath.compile("//configuration/preferences"); NodeList nodes = (NodeList) expr.evaluate(configuration, XPathConstants.NODESET); if (nodes.getLength() == 1) { Element preferencesElement = (Element) nodes.item(0); preferences.loadValuesFromXML(preferencesElement); } logger.info("Loading modules configuration"); for (MZmineModule module : MZmineStarter.getAllModules()) { String className = module.getClass().getName(); expr = xpath.compile("//configuration/modules/module[@class='" + className + "']/parameters"); nodes = (NodeList) expr.evaluate(configuration, XPathConstants.NODESET); if (nodes.getLength() != 1) continue; Element moduleElement = (Element) nodes.item(0); ParameterSet moduleParameters = getModuleParameters(module.getClass()); moduleParameters.loadValuesFromXML(moduleElement); } logger.info("Loaded configuration from file " + file); } catch (Exception e) { throw new IOException(e); } }
public DecimalFormat getMZFormat() { return preferences.getParameter(MZminePreferences.mzFormat).getValue(); }
public DecimalFormat getIntensityFormat() { return preferences.getParameter(MZminePreferences.intensityFormat).getValue(); }
public Boolean getSendStatistics() { return preferences.getParameter(MZminePreferences.sendStatistics).getValue(); }