/** @param reallyRemoveIt true: really remove it; false: dry run, only produce logging */
 public void removeXKeysTask(boolean reallyRemoveIt) {
   List<String> allBundles = I18nModule.getBundleNamesContainingI18nFiles();
   Set<String> allLangs = getAllLanguages();
   int counter = 0;
   for (String langKey : allLangs) {
     Locale locale = i18nMgr.getLocaleOrNull(langKey);
     for (String bundleName : allBundles) {
       Properties properties =
           i18nMgr.getPropertiesWithoutResolvingRecursively(locale, bundleName);
       Set<Object> keys = properties.keySet();
       for (Object keyObj : keys) {
         String key = (String) keyObj;
         if (key.endsWith("X")) {
           String value = properties.getProperty(key);
           if (StringHelper.containsNonWhitespace(value)) {
             log.warn(
                 "NONEMPTY XKEY detected in lang::"
                     + locale.getLanguage()
                     + " bundle::"
                     + bundleName
                     + " key::"
                     + key
                     + " value::"
                     + value);
             if (reallyRemoveIt) {
               addKey(locale, bundleName, key.substring(0, key.length() - 1), value);
             }
           }
           log.info(
               "XKEY detected in lang::"
                   + locale.getLanguage()
                   + " bundle::"
                   + bundleName
                   + " key::"
                   + key);
           logText.append(
               i18nMgr.getPropertiesFile(
                       locale, bundleName, I18nModule.getPropertyFilesBaseDir(locale, bundleName))
                   + " XKEY detected in lang::"
                   + locale.getLanguage()
                   + " bundle::"
                   + bundleName
                   + " key::"
                   + key
                   + " value::"
                   + value
                   + "\n");
           if (reallyRemoveIt) {
             deleteKey(locale, bundleName, key);
           }
           counter++;
         }
       }
     }
   }
   if (reallyRemoveIt) {
     log.info(counter + " X-Keys got removed!");
   }
 }
 public String getNodeByUri(final String uri) {
   if (StringHelper.containsNonWhitespace(uri)) {
     final TreeNode node = ctm.lookupTreeNodeByHref(uri);
     if (node != null) {
       return node.getIdent();
     }
   }
   return getInitialSelectedNodeId();
 }
Beispiel #3
0
  @Override
  protected void initForm(
      final FormItemContainer formLayout, final Controller listener, final UserRequest ureq) {
    setFormTitle("pane.tab.infos_config.title");
    setFormContextHelp(
        InfoConfigForm.class.getPackage().getName(),
        "ced-info-config.html",
        "help.hover.info.config");

    final String page = velocity_root + "/editShow.html";
    final FormLayoutContainer showLayout =
        FormLayoutContainer.createCustomFormLayout(
            "pane.tab.infos_config.shown", getTranslator(), page);
    showLayout.setLabel("pane.tab.infos_config.shown", null);
    formLayout.add(showLayout);

    durationSelection =
        uifactory.addDropdownSingleselect(
            "pane.tab.infos_config.max_duration",
            showLayout,
            maxDurationValues,
            maxDurationValues,
            null);
    durationSelection.setLabel("pane.tab.infos_config.max", null);
    final String durationStr = (String) config.get(InfoCourseNodeConfiguration.CONFIG_DURATION);
    if (StringHelper.containsNonWhitespace(durationStr)) {
      durationSelection.select(durationStr, true);
    } else {
      durationSelection.select("30", true);
    }

    lengthSelection =
        uifactory.addDropdownSingleselect(
            "pane.tab.infos_config.max_shown", showLayout, maxLengthValues, maxLengthValues, null);
    lengthSelection.setLabel("pane.tab.infos_config.max", null);
    final String lengthStr = (String) config.get(InfoCourseNodeConfiguration.CONFIG_LENGTH);
    if (StringHelper.containsNonWhitespace(lengthStr)) {
      lengthSelection.select(lengthStr, true);
    } else {
      lengthSelection.select("5", true);
    }

    uifactory.addFormSubmitButton("save", formLayout);
  }
Beispiel #4
0
 /**
  * Internal helper to check for emtpy config variables
  *
  * @param param
  * @return true: not empty; false: empty or null
  */
 private boolean checkConfigParameterIsNotEmpty(final String param) {
   if (StringHelper.containsNonWhitespace(param)) {
     return true;
   } else {
     log.error(
         "Missing configuration '"
             + param
             + "'. Add this configuration to olatextconfig.xml first. Disabling LDAP");
     setEnableLDAPLogins(false);
     return false;
   }
 }
 @Override
 protected boolean validateFormLogic(@SuppressWarnings("unused") final UserRequest ureq) {
   // validate date-fields for correct date and start < end date
   dateStart.clearError();
   dateEnd.clearError();
   boolean isInputValid = true;
   if (dateEnd.hasError() || dateEnd.getDate() == null) {
     dateEnd.setErrorKey("filter.date.invalid", null);
     isInputValid = false;
   }
   if (StringHelper.containsNonWhitespace(dateStart.getValue())
       && (dateStart.hasError() || dateStart.getDate() == null)) {
     dateStart.setErrorKey("filter.date.invalid", null);
     isInputValid = false;
   } else if (isInputValid
       && StringHelper.containsNonWhitespace(dateStart.getValue())
       && dateStart.getDate().after(dateEnd.getDate())) {
     dateStart.setErrorKey("filter.date.invalid.afterend", null);
     isInputValid = false;
   }
   return isInputValid;
 }
 /** @param reallyRemoveIt true: really remove it; false: dry run, only produce logging */
 public void removeEmptyKeysTask(boolean reallyRemoveIt) {
   List<String> allBundles = I18nModule.getBundleNamesContainingI18nFiles();
   int counter = 0;
   Set<String> allLangs = getAllLanguages();
   for (String langKey : allLangs) {
     Locale locale = i18nMgr.getLocaleOrNull(langKey);
     for (String bundleName : allBundles) {
       Properties properties =
           i18nMgr.getPropertiesWithoutResolvingRecursively(locale, bundleName);
       Set<Object> keys = properties.keySet();
       for (Object keyObj : keys) {
         String key = (String) keyObj;
         String value = properties.getProperty(key);
         if (!StringHelper.containsNonWhitespace(value)) {
           log.info(
               "empty Key detected in lang::"
                   + locale.getLanguage()
                   + " bundle::"
                   + bundleName
                   + " key::"
                   + key
                   + " value::"
                   + value);
           logText.append(
               i18nMgr.getPropertiesFile(
                       locale, bundleName, I18nModule.getPropertyFilesBaseDir(locale, bundleName))
                   + " empty Key detected in lang"
                   + locale.getLanguage()
                   + " bundle::"
                   + bundleName
                   + " key::"
                   + key
                   + " value::"
                   + value
                   + "\n");
           if (reallyRemoveIt) {
             deleteKey(locale, bundleName, key);
           }
         }
         counter++;
       } // each key
     } // each bundle
   }
   log.info(counter + " empty Keys got removed!");
 }
Beispiel #7
0
 public static String getLdapDateFormat() {
   if (StringHelper.containsNonWhitespace(ldapDateFormat)) {
     return ldapDateFormat;
   }
   return "yyyyMMddHHmmss'Z'"; // default
 }
 /**
  * org.olat.presentation.framework.components.form.flexible.FormItem,
  * org.olat.presentation.framework.components.form.flexible.impl.FormEvent)
  */
 @SuppressWarnings("unused")
 @Override
 protected void formInnerEvent(
     final UserRequest ureq, final FormItem source, final FormEvent event) {
   if (source instanceof FormLink) {
     final FormLink link = (FormLink) source;
     if (link.getName().startsWith(TAG_CMP_IDENTIFIER)) {
       // a tag-Link got clicked, find out which
       final String selectedTag = (String) link.getUserObject();
       if (!selectedTagsList.contains(selectedTag)) {
         selectedTagsList.add(selectedTag);
         tagAllBtn.toggleOff();
         tagNoneBtn.toggleOff();
       } else {
         selectedTagsList.remove(selectedTag);
         if (selectedTagsList.isEmpty()) {
           tagAllBtn.toggleOn();
         }
       }
       filterSettings.setTagFilter(selectedTagsList);
       fireEvent(ureq, new PortfolioFilterChangeEvent(filterSettings));
     } else if (link.getName().startsWith(HANDLER_PREFIX)) {
       // a type-link got clicked
       final String selectedType = (String) link.getUserObject();
       if (!selectedTypeList.contains(selectedType)) {
         selectedTypeList.add(selectedType);
         typeAllBtn.toggleOff();
       } else {
         selectedTypeList.remove(selectedType);
         if (selectedTypeList.isEmpty()) {
           typeAllBtn.toggleOn();
         }
       }
       filterSettings.setTypeFilter(selectedTypeList);
       fireEvent(ureq, new PortfolioFilterChangeEvent(filterSettings));
     }
   }
   if (source == tagAllBtn) {
     resetTagLinks();
     tagNoneBtn.toggleOff();
     filterSettings.setTagFilter(selectedTagsList);
     fireEvent(ureq, new PortfolioFilterChangeEvent(filterSettings));
   } else if (source == tagNoneBtn) {
     resetTagLinks();
     tagAllBtn.toggleOff();
     filterSettings.setNoTagFilter();
     fireEvent(ureq, new PortfolioFilterChangeEvent(filterSettings));
   } else if (source == typeAllBtn) {
     resetTypeLinks();
     filterSettings.setTypeFilter(selectedTypeList);
     fireEvent(ureq, new PortfolioFilterChangeEvent(filterSettings));
   } else if (source == dateStart || source == dateEnd) {
     if (validateFormLogic(ureq)) {
       final List<Date> dateList = new ArrayList<Date>();
       final Date selStartDate = dateStart.getDate();
       final Date selEndDate = dateEnd.getDate();
       dateList.add(selStartDate);
       dateList.add(selEndDate);
       filterSettings.setDateFilter(dateList);
       fireEvent(ureq, new PortfolioFilterChangeEvent(filterSettings));
     }
   } else if (source == typeEditBtn) {
     popupTypesCallout(ureq);
   } else if (source == tagEditBtn) {
     popupTagsCallout(ureq);
   } else if (source == searchFld) {
     final String searchText = searchFld.getValue();
     filterSettings.setTextFilter(searchText);
     fireEvent(ureq, new PortfolioFilterChangeEvent(filterSettings));
   } else if (source == filterSave) {
     if (StringHelper.containsNonWhitespace(filterName.getValue())) {
       final String oldFilterName = filterSettings.getFilterName();
       filterSettings.setFilterName(filterName.getValue());
       filterSettings.setTextFilter(searchFld.getValue());
       if (filterSave.getUserObject() != null && filterName.getValue().equals(oldFilterName)) {
         // fake update, delete before adding again
         final String filterID = (String) filterSave.getUserObject();
         ePFMgr.deleteFilterFromUsersList(getIdentity(), filterID);
       }
       if (!filterName.getValue().equals(oldFilterName) && oldFilterName != null) {
         // set another id, to distinguish from old
         filterSettings.setFilterIdToUniqueId();
       }
       final List<EPFilterSettings> filterList = ePFMgr.getSavedFilterSettings(getIdentity());
       // create a new or insert existing again
       filterList.add(filterSettings);
       ePFMgr.setSavedFilterSettings(getIdentity(), filterList);
       toggleSaveUpdateFilterButtons(true);
       showInfo("filter.saved", filterSettings.getFilterName());
       updateUI(ureq, filterSettings);
     }
   } else if (source == filterDel) {
     if (filterDel.getUserObject() != null) {
       ePFMgr.deleteFilterFromUsersList(getIdentity(), (String) filterDel.getUserObject());
       // refresh ui
       filterName.setValue("");
       toggleSaveUpdateFilterButtons(false);
       showInfo("filter.deleted");
       updateUI(ureq, new EPFilterSettings());
     }
   } else if (source == filterName) {
     final String oldFilterName = filterSettings.getFilterName();
     if (filterSave.getUserObject() != null && !filterName.getValue().equals(oldFilterName)) {
       toggleSaveUpdateFilterButtons(false);
     } else if (filterName.getValue().equals(oldFilterName)) {
       toggleSaveUpdateFilterButtons(true);
     }
   } else if (source == filterSel) {
     if (filterSel.isOneSelected()) {
       final int filterIndex = filterSel.getSelected();
       if (filterIndex == 0) {
         final EPFilterSettings newSettings = new EPFilterSettings();
         updateUI(ureq, newSettings);
         fireEvent(ureq, new PortfolioFilterChangeEvent(newSettings));
       } else if (filterIndex > 0 && filterIndex - 1 < nonEmptyFilters.size()) {
         final EPFilterSettings newSettings = nonEmptyFilters.get(filterIndex - 1);
         if (!filterSettings.getFilterId().equals(newSettings.getFilterId())) {
           updateUI(ureq, newSettings);
           fireEvent(ureq, new PortfolioFilterChangeEvent(newSettings));
         }
       }
     }
   }
 }
  /**
   * once again check for keys in branch (lost keys) and move them to Head reallyCopy: set to true
   * to create Props/keys in Head, false: only log them
   */
  public void getLostTranslationsFromBranch(
      boolean reallyCopy,
      String[] referenceLanguages,
      String pathToOlatBranch,
      String pathToCoreBranch) {
    List<String> allBundles = new ArrayList<String>(I18nModule.getBundleNamesContainingI18nFiles());

    Set<String> allLangs = getAllLanguages();
    // loop over all langs
    int totalCounter = 0;
    for (String langKey : allLangs) {
      int langCounter = 0;
      // ignore ref langs
      boolean isRefLang = false;
      for (String refLangKey : referenceLanguages) {
        if (refLangKey.equals(langKey)) {
          isRefLang = true;
          break;
        }
      }
      if (isRefLang) continue;

      // load current language
      Locale locale = i18nMgr.getLocaleOrNull(langKey);
      for (String bundleName : allBundles) {
        int bundleCounter = 0;
        // get valid keys from ref langs and this bundle
        Set<String> allValidKeys = new HashSet<String>();
        for (String refLangKey : referenceLanguages) {
          Properties properties =
              i18nMgr.getPropertiesWithoutResolvingRecursively(
                  i18nMgr.getLocaleOrNull(refLangKey), bundleName);
          if (properties == null) {
            throw new OLATRuntimeException("Invalid reference language::" + refLangKey, null);
          } else {
            for (Object keyObj : properties.keySet()) {
              String key = (String) keyObj;
              allValidKeys.add(key);
            }
          }
        } // for

        // check if bundle + this locale exists in branch
        String bundlePath = bundleName.replace(".", "/");
        String langPropFileName =
            I18nModule.LOCAL_STRINGS_FILE_PREFIX + langKey + I18nModule.LOCAL_STRINGS_FILE_POSTFIX;
        File bundleInOlat =
            new File(
                pathToOlatBranch
                    + bundlePath
                    + "/"
                    + I18nManager.I18N_DIRNAME
                    + "/"
                    + langPropFileName);
        File bundleInCore =
            new File(
                pathToCoreBranch
                    + bundlePath
                    + "/"
                    + I18nManager.I18N_DIRNAME
                    + "/"
                    + langPropFileName);
        File bundleToUse;
        if (bundleInOlat.exists()) {
          bundleToUse = bundleInOlat;
        } else if (bundleInCore.exists()) {
          bundleToUse = bundleInCore;
        } else { // no bundle found in branch, its not even worth to look after keys
          log.debug(
              "getLostTrans: no OLD prop file found in BRANCH for locale: "
                  + locale
                  + " and bundle: "
                  + bundleName
                  + " => continue with next bundle");
          continue;
        }

        // look after all valid keys in given lang in Head

        Properties targetProperties =
            i18nMgr.getPropertiesWithoutResolvingRecursively(locale, bundleName);
        Set<Object> targetLangBundleKeys = targetProperties.keySet();
        Properties oldProps = new Properties();
        FileInputStream is;
        try {
          is = new FileInputStream(bundleToUse);
          oldProps.load(is);
          is.close();
        } catch (Exception e) {
          e.printStackTrace();
        }
        for (Object keyObj : allValidKeys) {
          String key = (String) keyObj;
          if (targetLangBundleKeys.contains(key)) {
            // everything ok
          } else {
            // only work on keys found in reference lang (de/en) but not in this bundle
            // try to load key from branch
            if (oldProps.containsKey(key)) {
              String oldValue = oldProps.getProperty(key);
              if (StringHelper.containsNonWhitespace(oldValue)
                  && !oldValue.trim().startsWith("TODO")) {
                langCounter++;
                bundleCounter++;
                totalCounter++;
                if (reallyCopy) {
                  addKey(locale, bundleName, key, oldValue);
                } else {
                  log.debug(
                      "getLostTrans: add a key from BRANCH to locale: "
                          + locale
                          + " and bundle: "
                          + bundleName
                          + " key: "
                          + key);
                }
              } else {
                log.debug(
                    "getLostTrans: ignoring invalid value::'"
                        + oldValue
                        + "' from BRANCH to locale: "
                        + locale
                        + " and bundle: "
                        + bundleName
                        + " key: "
                        + key);
              }
            }
          }
        } // for: keys
        if (bundleCounter > 0)
          log.info(
              "Changed "
                  + bundleCounter
                  + " keys for locale: "
                  + locale
                  + " and bundle: "
                  + bundleName);
      } // for: bundles
      if (langCounter > 0) log.info("Changed " + langCounter + " keys for locale: " + locale);
    } // for: langs
    if (totalCounter > 0) log.info("Changed " + totalCounter + " keys in total");
  }