Exemplo n.º 1
0
  /**
   * Gets an I18N (internationalization) message.
   *
   * @param m The message name to retrieve. Must be a valid entry into the file specified by <code>
   *     i18n.file</code> property.
   * @return String With the message
   * @param localeName String
   */
  public static String getMessage(String localeName, String m) {
    if (!messagesMap.containsKey(localeName)) {
      load(localeName);
    }

    return (((Properties) messagesMap.get(localeName)).getProperty(m));
  }
Exemplo n.º 2
0
  /**
   * Setup optios and values for the user's session if authentication was ok.
   *
   * @param userSession The UserSession instance of the user
   * @param user The User instance of the authenticated user
   */
  protected void configureUserSession(UserSession userSession, User user) {

    LOG.trace("configureUserSession");
    userSession.dataToUser(user);

    // As an user may come back to the forum before its
    // last visit's session expires, we should check for
    // existent user information and then, if found, store
    // it to the database before getting his information back.
    String sessionId = SessionFacade.isUserInSession(user.getId());

    UserSession tmpUs;
    if (sessionId != null) {
      SessionFacade.storeSessionData(sessionId, JForumExecutionContext.getConnection());
      tmpUs = SessionFacade.getUserSession(sessionId);
      SessionFacade.remove(sessionId);
    } else {
      UserSessionDAO sm = DataAccessDriver.getInstance().newUserSessionDAO();
      tmpUs = sm.selectById(userSession, JForumExecutionContext.getConnection());
    }

    if (tmpUs == null) {
      userSession.setLastVisit(new Date(System.currentTimeMillis()));
    } else {
      // Update last visit and session start time
      userSession.setLastVisit(new Date(tmpUs.getStartTime().getTime() + tmpUs.getSessionTime()));
    }

    // If the execution point gets here, then the user
    // has chosen "autoLogin"
    userSession.setAutoLogin(true);
    SessionFacade.makeLogged();

    I18n.load(user.getLang());
  }
Exemplo n.º 3
0
  protected void loadConfigStuff() {
    ConfigLoader.loadUrlPatterns();
    I18n.load();
    Tpl.load(SystemGlobals.getValue(ConfigKeys.TEMPLATES_MAPPING));

    // BB Code
    BBCodeRepository.setBBCollection(new BBCodeHandler().parse());
  }
Exemplo n.º 4
0
  /** Load the default I18n file */
  public static synchronized void load() {
    baseDir =
        SystemGlobals.getApplicationResourceDir()
            + "/"
            + SystemGlobals.getValue(ConfigKeys.LOCALES_DIR);

    loadLocales();

    defaultName = SystemGlobals.getValue(ConfigKeys.I18N_DEFAULT_ADMIN);
    load(defaultName, null);

    String custom = SystemGlobals.getValue(ConfigKeys.I18N_DEFAULT);
    if (!custom.equals(defaultName)) {
      load(custom, defaultName);
      defaultName = custom;
    }
  }
Exemplo n.º 5
0
  static void load(String localeName, String mergeWith, boolean force) {
    if (!force
        && (localeName == null || localeName.trim().equals("") || I18n.contains(localeName))) {
      return;
    }

    if (localeNames.size() == 0) {
      loadLocales();
    }

    Properties p = new Properties();

    if (mergeWith != null) {
      if (!I18n.contains(mergeWith)) {
        load(mergeWith, null);
      }

      p.putAll((Properties) messagesMap.get(mergeWith));
    }

    FileInputStream fis = null;

    try {
      String filename = baseDir + localeNames.getProperty(localeName);

      // If the requested locale does not exist, use the default
      if (!new File(filename).exists()) {
        filename =
            baseDir
                + localeNames.getProperty(SystemGlobals.getValue(ConfigKeys.I18N_DEFAULT_ADMIN));
      }

      fis = new FileInputStream(filename);
      p.load(fis);
    } catch (IOException e) {
      throw new ForumException(e);
    } finally {
      if (fis != null) {
        try {
          fis.close();
        } catch (Exception e) {
        }
      }
    }

    messagesMap.put(localeName, p);

    watchForChanges(localeName);
  }
Exemplo n.º 6
0
 /**
  * Loads a new locale. If <code>localeName</code> is either null or empty, or if the locale is
  * already loaded, the method will return without executing any code.
  *
  * @param localeName The locale name to load
  */
 public static void load(String localeName) {
   load(localeName, SystemGlobals.getValue(ConfigKeys.I18N_DEFAULT));
 }
Exemplo n.º 7
0
 static void load(String localeName, String mergeWith) {
   load(localeName, mergeWith, false);
 }
Exemplo n.º 8
0
 public static void changeBoardDefault(String newDefaultLanguage) {
   load(newDefaultLanguage, SystemGlobals.getValue(ConfigKeys.I18N_DEFAULT_ADMIN));
   defaultName = newDefaultLanguage;
 }