コード例 #1
0
  @Override
  protected void formInnerEvent(UserRequest ureq, FormItem source, FormEvent event) {
    super.formInnerEvent(ureq, source, event);
    if (source == cancelButton) {
      fireEvent(ureq, Event.CANCELLED_EVENT);

    } else if (source == importFile) {
      if (importFile.isUploadSuccess()) {
        File tmpJar = importFile.getUploadFile();
        Set<String> importLangKeys =
            I18nManager.getInstance().sarchForAvailableLanguagesInJarFile(tmpJar, true);
        if (importLangKeys.size() == 0) {
          showError("configuration.management.package.import.failure.empty");
          return;
        }
        //
        // enable language key selection
        String[] langKeys = ArrayHelper.toArray(importLangKeys);
        importKeys.setKeysAndValues(langKeys, langKeys);
        importKeys.selectAll();
        importKeys.setVisible(true);
        // In language adaption mode the import is done as a package - can't deselect anything
        importKeys.setEnabled(false);
      }
    }
  }
コード例 #2
0
 // cluster_ok only in VM
 public static synchronized LocalizedXSLTransformer getInstance(final Locale locale) {
   LocalizedXSLTransformer instance =
       instanceHash.get(I18nManager.getInstance().getLocaleKey(locale));
   if (instance == null) {
     final Translator trans =
         Util.createPackageTranslator(QTIResultDetailsController.class, locale);
     final LocalizedXSLTransformer newInstance = new LocalizedXSLTransformer(trans);
     instance =
         instanceHash.putIfAbsent(
             I18nManager.getInstance().getLocaleKey(locale),
             newInstance); // see javadoc of ConcurrentHashMap
     if (instance == null) { // newInstance was put into the map
       instance = newInstance;
     }
   }
   return instance;
 }
コード例 #3
0
  @Override
  protected void formOK(UserRequest ureq) {
    if (importKeys.isVisible() && importKeys.getSelectedKeys().size() > 0) {
      Collection<String> importLangKeys = importKeys.getSelectedKeys();
      Set<String> alreadyInstalledLangs = new HashSet<String>();
      for (String langKey : importLangKeys) {
        if (I18nModule.getAvailableLanguageKeys().contains(langKey)) {
          alreadyInstalledLangs.add(langKey);
        }
      }
      if (I18nModule.isTransToolEnabled()) {
        // In translation mode importing will copy the language package
        // over an existing language or create a new language
        File tmpJar = importFile.getUploadFile();
        I18nManager.getInstance().copyLanguagesFromJar(tmpJar, importLangKeys);
        logAudit("Uploaded languages from jar::" + importFile.getUploadFileName(), null);
        showInfo("configuration.management.package.import.success", importLangKeys.toString());

      } else {
        // In language adaption mode: import is copied to user managed i18n package space in
        // olatdata
        if (alreadyInstalledLangs.size() == importLangKeys.size()) {
          showError("configuration.management.package.import.failure.installed");
          return;
        }
        // Ok, contains at least one language, copy to lang pack dir
        importFile.moveUploadFileTo(I18nModule.LANG_PACKS_DIRECTORY);
        logAudit("Uploaded language pack::" + importFile.getUploadFileName(), null);

        if (alreadyInstalledLangs.size() > 0) {
          getWindowControl()
              .setWarning(
                  getTranslator()
                      .translate(
                          "configuration.management.package.import.success.with.existing",
                          new String[] {
                            importLangKeys.toString(), alreadyInstalledLangs.toString()
                          }));
        } else {
          showInfo("configuration.management.package.import.success", importLangKeys.toString());
        }
      }
      // Reset i18n system
      I18nModule.reInitializeAndFlushCache();
      fireEvent(ureq, Event.DONE_EVENT);
    }
  }
コード例 #4
0
  private void sendFeedback(List<BulkAssessmentFeedback> feedbacks) {
    if (task == null) {
      log.error("Haven't a task to know creator and modifiers of the task", null);
      return;
    }

    Identity creator = task.getCreator();
    String language = creator.getUser().getPreferences().getLanguage();
    Locale locale = I18nManager.getInstance().getLocaleOrDefault(language);
    Translator translator =
        Util.createPackageTranslator(
            BulkAssessmentOverviewController.class,
            locale,
            Util.createPackageTranslator(AssessmentManager.class, locale));
    MailManager mailManager = CoreSpringFactory.getImpl(MailManager.class);
    TaskExecutorManager taskManager = CoreSpringFactory.getImpl(TaskExecutorManager.class);

    String feedbackStr = renderFeedback(feedbacks, translator);

    MailBundle mail = new MailBundle();
    mail.setToId(creator);
    mail.setFrom(WebappHelper.getMailConfig("mailReplyTo"));
    List<Identity> modifiers = taskManager.getModifiers(task);
    if (modifiers.size() > 0) {
      ContactList cc = new ContactList("CC");
      cc.addAllIdentites(modifiers);
      mail.setContactList(cc);
    }

    String businessPath = "";
    ICourse course = CourseFactory.loadCourse(courseRes);
    CourseNode node = course.getRunStructure().getNode(courseNodeIdent);
    String courseTitle = course.getCourseTitle();
    String nodeTitle = node.getShortTitle();
    String numOfAssessedIds = Integer.toString(datas == null ? 0 : datas.getRowsSize());
    String date = Formatter.getInstance(locale).formatDateAndTime(new Date());

    mail.setContext(new MailContextImpl(courseRes, courseNodeIdent, businessPath));
    String subject =
        translator.translate("confirmation.mail.subject", new String[] {courseTitle, nodeTitle});
    String body =
        translator.translate(
            "confirmation.mail.body",
            new String[] {courseTitle, nodeTitle, feedbackStr, numOfAssessedIds, date});
    mail.setContent(subject, body);
    mailManager.sendMessage(mail);
  }
コード例 #5
0
 public Languages getLanguages() {
   I18nManager i18nMgr = I18nManager.getInstance();
   Collection<String> enabledKeysSet = I18nModule.getEnabledLanguageKeys();
   Map<String, String> langNames = new HashMap<String, String>();
   Map<String, String> langTranslators = new HashMap<String, String>();
   String[] enabledKeys = ArrayHelper.toArray(enabledKeysSet);
   String[] names = new String[enabledKeys.length];
   for (int i = 0; i < enabledKeys.length; i++) {
     String key = enabledKeys[i];
     String langName = i18nMgr.getLanguageInEnglish(key, I18nModule.isOverlayEnabled());
     langNames.put(key, langName);
     names[i] = langName;
     String author = i18nMgr.getLanguageAuthor(key);
     langTranslators.put(key, author);
   }
   ArrayHelper.sort(enabledKeys, names, true, true, true);
   return new Languages(enabledKeys, langNames, langTranslators);
 }
コード例 #6
0
 /** @return current language code as found in (current)Locale.toString() method */
 public String getLanguageCode() {
   Locale currentLocale = I18nManager.getInstance().getCurrentThreadLocale();
   return currentLocale.toString();
 }
コード例 #7
0
  /**
   * @see
   *     org.olat.search.service.indexer.AbstractHierarchicalIndexer#doIndex(org.olat.search.service.SearchResourceContext,
   *     java.lang.Object, org.olat.search.service.indexer.OlatFullIndexer)
   */
  @Override
  public void doIndex(
      SearchResourceContext parentResourceContext, Object parentObject, OlatFullIndexer indexWriter)
      throws IOException, InterruptedException {
    if (!ContextHelpModule.isContextHelpEnabled()) {
      // don't index context help when disabled
      return;
    }
    long startTime = System.currentTimeMillis();
    Set<String> helpPageIdentifyers = ContextHelpModule.getAllContextHelpPages();
    Set<String> languages = I18nModule.getEnabledLanguageKeys();
    if (log.isDebug())
      log.debug(
          "ContextHelpIndexer helpPageIdentifyers.size::"
              + helpPageIdentifyers.size()
              + " and languages.size::"
              + languages.size());
    // loop over all help pages
    for (String helpPageIdentifyer : helpPageIdentifyers) {
      String[] identifyerSplit = helpPageIdentifyer.split(":");
      String bundleName = identifyerSplit[0];
      String page = identifyerSplit[1];
      // fxdiff: FXOLAT-221: don't use velocity on images
      if (page == null || !page.endsWith(".html")) {
        continue;
      }

      // Translator with default locale. Locale is set to each language in the
      // language iteration below
      Translator pageTranslator = new PackageTranslator(bundleName, I18nModule.getDefaultLocale());
      // Open velocity page for this help page
      String pagePath = bundleName.replace('.', '/') + ContextHelpModule.CHELP_DIR + page;
      VelocityContainer container =
          new VelocityContainer("contextHelpPageVC", pagePath, pageTranslator, null);
      Context ctx = container.getContext();
      GlobalSettings globalSettings =
          new GlobalSettings() {
            public int getFontSize() {
              return 100;
            }

            public AJAXFlags getAjaxFlags() {
              return new EmptyAJAXFlags();
            }

            public ComponentRenderer getComponentRendererFor(Component source) {
              return null;
            }

            public boolean isIdDivsForced() {
              return false;
            }
          };
      Renderer renderer =
          Renderer.getInstance(
              container, pageTranslator, new EmptyURLBuilder(), null, globalSettings);
      // Add render decorator with helper methods
      VelocityRenderDecorator vrdec = new VelocityRenderDecorator(renderer, container, null);
      ctx.put("r", vrdec);
      // Add empty static dir url - only used to not generate error messages
      ctx.put("chelpStaticDirUrl", "");
      // Create document for each language using the velocity context
      for (String langCode : languages) {
        Locale locale = I18nManager.getInstance().getLocaleOrNull(langCode);
        String relPagePath = langCode + "/" + bundleName + "/" + page;
        if (log.isDebug()) log.debug("Indexing help page with path::" + relPagePath);
        SearchResourceContext searchResourceContext =
            new SearchResourceContext(parentResourceContext);
        searchResourceContext.setBusinessControlFor(
            OresHelper.createOLATResourceableType(
                ContextHelpModule.class.getSimpleName())); // to match the list of indexer
        // Create context help document and index now, set translator to current locale
        pageTranslator.setLocale(locale);
        Document document =
            ContextHelpDocument.createDocument(
                searchResourceContext, bundleName, page, pageTranslator, ctx, pagePath);
        indexWriter.addDocument(document);
      }
      IOUtils.closeQuietly(vrdec);
    }
    long indexTime = System.currentTimeMillis() - startTime;
    if (log.isDebug()) log.debug("ContextHelpIndexer finished in " + indexTime + " ms");
  }
コード例 #8
0
  /**
   * @see org.olat.core.gui.control.DefaultController#event(org.olat.core.gui.UserRequest,
   *     org.olat.core.gui.control.Controller, org.olat.core.gui.control.Event)
   */
  @Override
  public void event(UserRequest ureq, Controller source, Event event) {
    if (source == loginForm && event == Event.DONE_EVENT) {
      String login = loginForm.getLogin();
      String pass = loginForm.getPass();
      if (loginModule.isLoginBlocked(login)) {
        // do not proceed when blocked
        showError("login.blocked", loginModule.getAttackPreventionTimeoutMin().toString());
        getLogger()
            .audit(
                "Login attempt on already blocked login for "
                    + login
                    + ". IP::"
                    + ureq.getHttpReq().getRemoteAddr(),
                null);
        return;
      }
      authenticatedIdentity = olatAuthenticationSpi.authenticate(null, login, pass);
      if (authenticatedIdentity == null) {
        if (loginModule.registerFailedLoginAttempt(login)) {
          getLogger()
              .audit(
                  "Too many failed login attempts for "
                      + login
                      + ". Login blocked. IP::"
                      + ureq.getHttpReq().getRemoteAddr(),
                  null);
          showError("login.blocked", loginModule.getAttackPreventionTimeoutMin().toString());
          return;
        } else {
          showError("login.error", WebappHelper.getMailConfig("mailReplyTo"));
          return;
        }
      } else {
        try {
          String language = authenticatedIdentity.getUser().getPreferences().getLanguage();
          UserSession usess = ureq.getUserSession();
          if (StringHelper.containsNonWhitespace(language)) {
            usess.setLocale(I18nManager.getInstance().getLocaleOrDefault(language));
          }
        } catch (Exception e) {
          logError("Cannot set the user language", e);
        }
      }

      loginModule.clearFailedLoginAttempts(login);

      // Check if disclaimer has been accepted
      if (registrationManager.needsToConfirmDisclaimer(authenticatedIdentity)) {
        // accept disclaimer first

        removeAsListenerAndDispose(disclaimerCtr);
        disclaimerCtr = new DisclaimerController(ureq, getWindowControl());
        listenTo(disclaimerCtr);

        removeAsListenerAndDispose(cmc);
        cmc =
            new CloseableModalController(
                getWindowControl(), translate("close"), disclaimerCtr.getInitialComponent());
        listenTo(cmc);

        cmc.activate();

      } else {
        // disclaimer acceptance not required
        authenticated(ureq, authenticatedIdentity);
      }
    } else if (source == disclaimerCtr) {
      cmc.deactivate();
      if (event == Event.DONE_EVENT) {
        // disclaimer accepted
        registrationManager.setHasConfirmedDislaimer(authenticatedIdentity);
        authenticated(ureq, authenticatedIdentity);
      }
    } else if (cmc == source) {
      cleanUp();
    }
    if (source == subController) {
      if (event == Event.CANCELLED_EVENT) {
        cmc.deactivate();
        cleanUp();
      }
    }
  }