コード例 #1
0
  /**
   * schedule timer task to save/update the bundle data. We are using Timer to offload the work,
   * otherwise intial loads of tools will appear very slow, this way it happens in the background.
   * In the original rSmart impl JMS was used, but since the MessageService is in contrib not core
   * we need another solution to avoid that dependency. Currently we are using a java.util.Timer and
   * scheduled Timer task to queue up and process the calls to this method. This is a similar
   * strategy to that used in BaseDigestService.
   *
   * @param baseName
   * @param moduleName
   * @param newBundle
   * @param loc
   */
  public void saveOrUpdate(
      String baseName, String moduleName, ResourceBundle newBundle, Locale loc) {
    String keyName = getIndexKeyName(baseName, moduleName, loc.toString());
    if (indexedList.contains(keyName)) {
      logger.debug("skip saveOrUpdate() as its already happened once for :" + keyName);
      return;
    }

    if (scheduleSaves) {
      queueBundle(baseName, moduleName, convertResourceBundleToMap(newBundle), loc);
    } else {
      saveOrUpdateInternal(
          baseName, moduleName, convertResourceBundleToMap(newBundle), loc.toString());
    }
  }
コード例 #2
0
  /**
   * internal work for responding to a save or update request. This method will add new bundles data
   * if it doesn't exist, otherwise updates the data preserving any current value if its been
   * modified. This approach allows for upgrades to automatically detect and persist new keys, as
   * well as updating any default values that flow in from an upgrade.
   *
   * @param baseName
   * @param moduleName
   * @param newBundle
   * @param loc
   */
  protected void saveOrUpdateInternal(
      String baseName, String moduleName, Map<String, String> newBundle, String loc) {
    String keyName = getIndexKeyName(baseName, moduleName, loc);
    if (indexedList.contains(keyName)) {
      logger.debug("skip saveOrUpdate() as its already happened once for :" + keyName);
      return;
    }

    Set<Entry<String, String>> entrySet = newBundle.entrySet();
    Iterator<Entry<String, String>> entries = entrySet.iterator();

    while (entries.hasNext()) {
      Entry<String, String> entry = entries.next();
      String key = entry.getKey();
      MessageBundleProperty mbp = new MessageBundleProperty();
      mbp.setBaseName(baseName);
      mbp.setModuleName(moduleName);
      mbp.setLocale(loc.toString());
      mbp.setPropertyName(key);
      mbp.setDefaultValue(entry.getValue());
      MessageBundleProperty existingMbp = getProperty(mbp);
      if (existingMbp != null) {
        // don"t update id or value, we don't want to loose that data
        BeanUtils.copyProperties(mbp, existingMbp, new String[] {"id", "value"});
        logger.debug(
            "updating message bundle data for : "
                + getIndexKeyName(mbp.getBaseName(), mbp.getModuleName(), mbp.getLocale()));
        updateMessageBundleProperty(existingMbp);
      } else {
        logger.debug(
            "adding message bundle data for : "
                + getIndexKeyName(mbp.getBaseName(), mbp.getModuleName(), mbp.getLocale()));
        updateMessageBundleProperty(mbp);
      }
    }

    indexedList.add(getIndexKeyName(baseName, moduleName, loc));
  }