Package org.jamwiki.utils

Examples of org.jamwiki.utils.SortedProperties


  /**
   *
   */
  private void translate(HttpServletRequest request, WikiPageInfo pageInfo) throws Exception {
    // first load existing translations
    SortedProperties translations = new SortedProperties();
    String language = this.retrieveLanguage(request);
    if (!StringUtils.isBlank(language)) {
      String filename = filename(language);
      translations.putAll(Environment.loadProperties(filename));
    }
    // now update with translations from the request
    Enumeration names = request.getParameterNames();
    String name;
    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(language), translations, null);
    this.writeTopic(request, pageInfo);
  }
View Full Code Here


  /**
   *
   */
  private void view(HttpServletRequest request, ModelAndView next, WikiPageInfo pageInfo) throws Exception {
    String language = this.retrieveLanguage(request);
    SortedProperties translations = new SortedProperties(Environment.loadProperties("ApplicationResources.properties"));
    if (!StringUtils.isBlank(language)) {
      String filename = filename(language);
      // add all translated keys to the base translation list
      translations.putAll(Environment.loadProperties(filename));
      // if the user wants to see only untranslated values, return the intersection of the base
      // translation list and the translated file list
      if (BooleanUtils.toBoolean(request.getParameter("hideTranslated"))) {
        Map tmp = Utilities.intersect(translations, Environment.loadProperties("ApplicationResources.properties"));
        translations = new SortedProperties();
        translations.putAll(tmp);
        next.addObject("hideTranslated", true);
      }
    }
    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());
    next.addObject("language", language);
    SortedProperties defaultTranslations = new SortedProperties(Environment.loadProperties("ApplicationResources.properties"));
    next.addObject("defaultTranslations", new TreeMap(defaultTranslations));
  }
View Full Code Here

   *          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;
    FileInputStream fis = 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());
        fis = new FileInputStream(file);
        properties.load(fis);
      }
    } catch (IOException e) {
      logger.severe("Failure while trying to load properties file "
          + file.getPath(), e);
    } finally {
      if (fis != null) {
        try {
          fis.close();
        } catch (IOException e) {
          // NOPMD
        }
      }
    }
    properties.loadFromDatastore();
    return properties;
  }
View Full Code Here

TOP

Related Classes of org.jamwiki.utils.SortedProperties

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.