@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);
    }
  }
Ejemplo n.º 2
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);
 }
 @Override
 protected void initForm(FormItemContainer formLayout, Controller listener, UserRequest ureq) {
   // A title, displayed in fieldset
   setFormTitle("configuration.management.package.import.title");
   if (I18nModule.isTransToolEnabled()) {
     setFormDescription("configuration.management.package.import.description.transserver");
   } else {
     setFormDescription("configuration.management.package.import.description");
   }
   //
   // The import file upload
   importFile =
       uifactory.addFileElement("configuration.management.package.import.file", formLayout);
   importFile.setLabel("configuration.management.package.import.file", null);
   importFile.setMandatory(true, "configuration.management.package.import.file.error.mandatory");
   // Limit to jar files and set upload limit to 50 MB
   importFile.setMaxUploadSizeKB(
       50000, "configuration.management.package.import.file.error.size", null);
   Set<String> mimeTypes = new HashSet<String>();
   mimeTypes.add("application/java-archive");
   mimeTypes.add("application/x-jar");
   mimeTypes.add("application/x-java-jar");
   importFile.limitToMimeType(
       mimeTypes, "configuration.management.package.import.file.error.type", null);
   importFile.addActionListener(FormEvent.ONCHANGE); // trigger auto-upload	
   //
   // Add checkboxes for the found languages - hide so far
   String[] langKeys = new String[] {};
   importKeys =
       uifactory.addCheckboxesVertical(
           "configuration.management.package.import.select", flc, langKeys, langKeys, 1);
   importKeys.setVisible(false);
   //
   // Add cancel and submit in button group layout
   FormLayoutContainer buttonGroupLayout =
       FormLayoutContainer.createButtonLayout("buttonGroupLayout", getTranslator());
   formLayout.add(buttonGroupLayout);
   cancelButton = uifactory.addFormLink("cancel", buttonGroupLayout, Link.BUTTON);
   uifactory.addFormSubmitButton("configuration.management.package.import", buttonGroupLayout);
 }
 /**
  * @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 == dialogCtr) {
     if (DialogBoxUIFactory.isYesEvent(event)) {
       // Yes case, delete now
       for (String deleteLangPack : deleteLangPackSelection.getSelectedKeys()) {
         File file = new File(I18nModule.LANG_PACKS_DIRECTORY, deleteLangPack);
         if (file.exists()) file.delete();
         logAudit("Deleted language pack::" + deleteLangPack, null);
       }
       // Reset i18n system
       I18nModule.reInitializeAndFlushCache();
       // wow, everything worked fine
       showInfo(
           "configuration.management.package.delete.success",
           deleteLangPackSelection.getSelectedKeys().toString());
       fireEvent(ureq, Event.DONE_EVENT);
     } else {
       // No case, do nothing.
     }
   }
 }
  /**
   * @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");
  }