private void attemptToReadPropertiesFile(File file, PageData data, long lastModifiedTime) throws Exception { InputStream input = null; try { final WikiPageProperties props = new WikiPageProperties(); input = new FileInputStream(file); props.loadFromXmlStream(input); props.setLastModificationTime(new Date(lastModifiedTime)); data.setProperties(props); } finally { if (input != null) input.close(); } }
private void saveNewProperties(String path, Properties oldProps) throws Exception { File newPropsFile = new File(path + FileSystemPage.propertiesFilename); WikiPageProperties newProps = new WikiPageProperties(); for (Iterator iterator = oldProps.keySet().iterator(); iterator.hasNext(); ) { String key = (String) iterator.next(); String value = (String) oldProps.get(key); if (!"false".equals(value)) newProps.set(key, value); } FileOutputStream os = new FileOutputStream(newPropsFile); newProps.save(os); os.close(); }
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); } } }
private void removeAlwaysChangingProperties(WikiPageProperties properties) { properties.remove(PageData.PropertyLAST_MODIFIED); }