Exemplo n.º 1
0
 public static List<String> getAllLanguages(UIComponent component) {
   LocaleConfigService configService =
       component.getApplicationComponent(LocaleConfigService.class);
   List<String> languages = new ArrayList<String>();
   for (LocaleConfig localeConfig : configService.getLocalConfigs()) {
     languages.add(localeConfig.getLocale().getDisplayLanguage());
   }
   return languages;
 }
  /**
   * The constructor of this class is used to build the tree of UI components that will be
   * aggregated in the portal page. 1) The component is stored in the current PortalRequestContext
   * ThreadLocal 2) The configuration for the portal associated with the current user request is
   * extracted from the PortalRequestContext 3) Then according to the context path, either a public
   * or private portal is initiated. Usually a public portal does not contain the left column and
   * only the private one has it. 4) The skin to use is setup 5) Finally, the current component is
   * associated with the current portal owner
   *
   * @throws Exception
   */
  public UIPortalApplication() throws Exception {
    log = ExoLogger.getLogger("portal:UIPortalApplication");
    PortalRequestContext context = PortalRequestContext.getCurrentInstance();
    userPortalConfig_ = (UserPortalConfig) context.getAttribute(UserPortalConfig.class);
    if (userPortalConfig_ == null) throw new Exception("Can't load user portal config");

    // dang.tung - set portal language by user preference -> browser -> default
    // ------------------------------------------------------------------------------
    String portalLanguage = null;
    LocaleConfigService localeConfigService = getApplicationComponent(LocaleConfigService.class);
    OrganizationService orgService = getApplicationComponent(OrganizationService.class);
    LocaleConfig localeConfig =
        localeConfigService.getLocaleConfig(userPortalConfig_.getPortalConfig().getLocale());
    String user = context.getRemoteUser();
    if (user != null) {
      UserProfile userProfile = orgService.getUserProfileHandler().findUserProfileByName(user);
      if (userProfile != null) {
        portalLanguage = userProfile.getUserInfoMap().get("user.language");
      } else {
        if (log.isWarnEnabled())
          log.warn("Could not load user profile for " + user + ". Using default portal locale.");
      }
    }
    localeConfig = localeConfigService.getLocaleConfig(portalLanguage);
    if (portalLanguage == null || !portalLanguage.equals(localeConfig.getLanguage())) {
      // if user language no support by portal -> get browser language if no ->
      // get portal
      portalLanguage = context.getRequest().getLocale().getLanguage();
      localeConfig = localeConfigService.getLocaleConfig(portalLanguage);
      if (!portalLanguage.equals(localeConfig.getLanguage())) {
        localeConfig =
            localeConfigService.getLocaleConfig(userPortalConfig_.getPortalConfig().getLocale());
      }
    }
    setLocale(localeConfig.getLocale());
    setOrientation(localeConfig.getOrientation());
    // -------------------------------------------------------------------------------
    context.setUIApplication(this);

    addWorkingWorkspace();

    String currentSkin = userPortalConfig_.getPortalConfig().getSkin();
    if (currentSkin != null && currentSkin.trim().length() > 0) skin_ = currentSkin;
    setOwner(context.getPortalOwner());
  }