protected synchronized void saveContent(String content) throws Exception { if (content == null) { return; } final String separator = System.getProperty("line.separator"); if (content.endsWith("|")) { content += separator; } content = content.replaceAll("\r\n", separator); String contentPath = getFileSystemPath() + contentFilename; final File output = new File(contentPath); OutputStreamWriter writer = null; try { if (output.exists()) cmSystem.edit(contentPath); writer = new OutputStreamWriter(new FileOutputStream(output), "UTF-8"); writer.write(content); } finally { if (writer != null) { writer.close(); cmSystem.update(contentPath); } } }
protected synchronized void saveAttributes(final WikiPageProperties attributes) throws Exception { OutputStream output = null; String propertiesFilePath = "<unknown>"; try { propertiesFilePath = getFileSystemPath() + propertiesFilename; File propertiesFile = new File(propertiesFilePath); if (propertiesFile.exists()) cmSystem.edit(propertiesFilePath); output = new FileOutputStream(propertiesFile); WikiPageProperties propertiesToSave = new WikiPageProperties(attributes); removeAlwaysChangingProperties(propertiesToSave); propertiesToSave.save(output); } catch (final Exception e) { System.err.println( "Failed to save properties file: \"" + propertiesFilePath + "\" (exception: " + e + ")."); e.printStackTrace(); throw e; } finally { if (output != null) { output.close(); cmSystem.update(propertiesFilePath); } } }