Java Code Examples for org.apache.commons.configuration.XMLConfiguration#save()
The following examples show how to use
org.apache.commons.configuration.XMLConfiguration#save() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: XmlBasedComponents.java From pxf with Apache License 2.0 | 5 votes |
/** * Saves {@link XMLConfiguration} to its file location * * @param conf * @throws ConfigurationException * @throws IOException * @throws InterruptedException */ protected void save(XMLConfiguration conf) throws ConfigurationException, IOException, InterruptedException { FileOutputStream fos = new FileOutputStream(conf.getFile()); conf.save(fos); // Making sure the file fos.close(); // wait to make sure new change loaded Thread.sleep(_2_SECONDS); }
Example 2
Source File: LogTableFormatConfigView.java From otroslogviewer with Apache License 2.0 | 5 votes |
private void exportToFile(File file, List<ColumnLayout> columnLayouts) throws ConfigurationException, FileNotFoundException { FileOutputStream out = null; try { final XMLConfiguration xmlConfiguration = new XMLConfiguration(); saveColumnLayouts(columnLayouts, xmlConfiguration); out = new FileOutputStream(file); xmlConfiguration.save(out); otrosApplication.getStatusObserver().updateStatus(String.format("Column layouts have been exported to %s", file.getAbsolutePath())); } finally { IOUtils.closeQuietly(out); } }
Example 3
Source File: LogTableFormatConfigView.java From otroslogviewer with Apache License 2.0 | 5 votes |
private void exportToClipBoard(List<ColumnLayout> columnLayouts) throws ConfigurationException { final XMLConfiguration xmlConfiguration = new XMLConfiguration(); saveColumnLayouts(columnLayouts, xmlConfiguration); final StringWriter writer = new StringWriter(); xmlConfiguration.save(writer); StringSelection stringSelection = new StringSelection(writer.getBuffer().toString()); Clipboard clipboard = Toolkit.getDefaultToolkit().getSystemClipboard(); clipboard.setContents(stringSelection, null); otrosApplication.getStatusObserver().updateStatus("Column layouts have been exported to clipboard"); }
Example 4
Source File: ClientConfig.java From juddi with Apache License 2.0 | 5 votes |
/** * Use this method to attempt to save the jUDDI configuration file after * you've modified it using the Apache Commons Configuration settings. * This is especially useful if you've constructed a user interface for manipulating * the configuration like a properties sheet and is used by the juddi-gui (web ui) * @since 3.2.1 * @throws org.apache.commons.configuration.ConfigurationException */ public void saveConfigRaw() throws ConfigurationException{ XMLConfiguration saveConfiguration = new XMLConfiguration(configurationFile); Configuration cc = new CompositeConfiguration(saveConfiguration); Iterator<String> keys = this.config.getKeys(); while (keys.hasNext()){ String key = keys.next(); if (key.startsWith("client") || key.startsWith("config")) { cc.setProperty(key, config.getProperty(key)); } } saveConfiguration.save(); }
Example 5
Source File: YangXmlUtils.java From onos with Apache License 2.0 | 5 votes |
/** * Return the string representation of the XMLConfig without header * and configuration element. * * @param cfg the XML to convert * @return the cfg string. */ public String getString(XMLConfiguration cfg) { StringWriter stringWriter = new StringWriter(); try { cfg.save(stringWriter); } catch (ConfigurationException e) { log.error("Cannot convert configuration", e.getMessage()); } String xml = stringWriter.toString(); xml = xml.substring(xml.indexOf("\n")); xml = xml.substring(xml.indexOf(">") + 1); return xml; }
Example 6
Source File: XmlConfigParser.java From onos with Apache License 2.0 | 5 votes |
public static String createControllersConfig(HierarchicalConfiguration cfg, HierarchicalConfiguration actualCfg, String target, String netconfOperation, String controllerOperation, List<ControllerInfo> controllers) { //cfg.getKeys().forEachRemaining(key -> System.out.println(key)); cfg.setProperty("edit-config.target", target); cfg.setProperty("edit-config.default-operation", netconfOperation); cfg.setProperty("edit-config.config.capable-switch.id", parseCapableSwitchId(actualCfg)); cfg.setProperty("edit-config.config.capable-switch." + "logical-switches.switch.id", parseSwitchId(actualCfg)); List<ConfigurationNode> newControllers = new ArrayList<>(); for (ControllerInfo ci : controllers) { XMLConfiguration controller = new XMLConfiguration(); controller.setRoot(new HierarchicalConfiguration.Node("controller")); String id = ci.type() + ":" + ci.ip() + ":" + ci.port(); controller.setProperty("id", id); controller.setProperty("ip-address", ci.ip()); controller.setProperty("port", ci.port()); controller.setProperty("protocol", ci.type()); newControllers.add(controller.getRootNode()); } cfg.addNodes("edit-config.config.capable-switch.logical-switches." + "switch.controllers", newControllers); XMLConfiguration editcfg = (XMLConfiguration) cfg; StringWriter stringWriter = new StringWriter(); try { editcfg.save(stringWriter); } catch (ConfigurationException e) { log.error("createControllersConfig()", e); } String s = stringWriter.toString() .replaceAll("<controller>", "<controller nc:operation=\"" + controllerOperation + "\">"); s = s.replace("<target>" + target + "</target>", "<target><" + target + "/></target>"); return s; }