private void view(HttpServletRequest request, ModelAndView next, WikiPageInfo pageInfo) throws Exception { String language = request.getParameter("language"); String filename = filename(request); SortedProperties translations = new SortedProperties(Environment.loadProperties("ApplicationResources.properties")); if (StringUtils.hasText(language)) { filename = filename(request); translations.putAll(Environment.loadProperties(filename)); } pageInfo.setContentJsp(JSP_ADMIN_TRANSLATION); pageInfo.setAdmin(true); pageInfo.setPageTitle(new WikiMessage("translation.title")); next.addObject("translations", new TreeMap(translations)); next.addObject("codes", this.retrieveTranslationCodes()); }
/** * Sets a new value for the given property name. * * @param name The name of the property whose value is to be set. * @param value The value of the property being set. */ public static void setValue(String name, String value) { // it is invalid to set a property value null, so convert to empty string if (value == null) { value = ""; // NOPMD } props.setProperty(name, value); }
/** The constructor loads property values from the property file. */ private Environment() { try { initDefaultProperties(); logger.fine("Default properties initialized: " + defaults.toString()); props = loadProperties(PROPERTY_FILE_NAME, defaults); logger.fine("JAMWiki properties initialized: " + props.toString()); } catch (Exception e) { logger.severe("Failure while initializing property values", e); } }
/** * Given a property file name, load the property file and return an object representing the * property values. * * @param propertyFile The name of the property file to load. * @param def Default property values, or <code>null</code> if there are no defaults. * @return The loaded SortedProperties object. */ public static SortedProperties loadProperties(String propertyFile, Properties def) { SortedProperties properties = new SortedProperties(); if (def != null) { properties = new SortedProperties(def); } File file = null; try { file = findProperties(propertyFile); if (file == null) { logger.warning("Property file " + propertyFile + " does not exist"); } else if (!file.exists()) { logger.warning("Property file " + file.getPath() + " does not exist"); } else { logger.config("Loading properties from " + file.getPath()); properties.load(new FileInputStream(file)); } } catch (Exception e) { logger.severe("Failure while trying to load properties file " + file.getPath(), e); } return properties; }
private void translate(HttpServletRequest request, ModelAndView next, WikiPageInfo pageInfo) throws Exception { pageInfo.setContentJsp(JSP_ADMIN_TRANSLATION); pageInfo.setAdmin(true); pageInfo.setPageTitle(new WikiMessage("translation.title")); Enumeration names = request.getParameterNames(); String name; SortedProperties translations = new SortedProperties(); while (names.hasMoreElements()) { name = (String) names.nextElement(); if (!name.startsWith("translations[") || !name.endsWith("]")) { continue; } String key = name.substring("translations[".length(), name.length() - "]".length()); String value = request.getParameter(name); translations.setProperty(key, value); } Environment.saveProperties(filename(request), translations, null); this.writeTopic(request, null); next.addObject("translations", new TreeMap(translations)); next.addObject("codes", this.retrieveTranslationCodes()); }
/** * Save the specified property values to the filesystem. * * @param propertyFile The name of the property file to save. * @param properties The properties object that is to be saved. * @param comments A comment to save in the properties file. * @throws IOException Thrown if the file cannot be found or if an I/O error occurs. */ public static void saveProperties( String propertyFile, SortedProperties properties, String comments) throws IOException { File file = findProperties(propertyFile); FileOutputStream out = null; try { out = new FileOutputStream(file); properties.store(out, comments); } finally { if (out != null) { try { out.close(); } catch (Exception e) { // NOPMD ignore, unimportant if a close fails } } } }
/** * Sets a new integer value for the given property name. * * @param name The name of the property whose value is to be set. * @param value The value of the property being set. */ public static void setIntValue(String name, int value) { props.setProperty(name, Integer.toString(value)); }
/** * Set a new boolean value for the given property name. * * @param name The name of the property whose value is to be set. * @param value The value of the property being set. */ public static void setBooleanValue(String name, boolean value) { props.setProperty(name, Boolean.toString(value)); }
/** * Returns the value of a property. * * @param name The name of the property whose value is to be retrieved. * @return The value of the property. */ public static String getValue(String name) { return props.getProperty(name); }