Example #1
0
  /**
   * @throws RaplaException when the resource-file is missing or can't be accessed or can't be
   *     parsed
   */
  public I18nBundleImpl(RaplaContext context, Configuration config, Logger logger)
      throws RaplaException {
    enableLogging(logger);
    Locale locale;
    try {
      m_localeSelector = (LocaleSelectorImpl) context.lookup(LocaleSelector.class);
    } catch (RaplaContextException ex) {
    }
    if (m_localeSelector != null) {
      m_localeSelector.addLocaleChangeListenerFirst(this);
      locale = m_localeSelector.getLocale();

    } else {
      locale = Locale.getDefault();
    }
    String filePath = config.getChild("file").getValue(null);
    try {
      InputStream resource;
      if (filePath == null) {
        className = config.getChild("classname").getValue(null);
        if (className == null) {
          className = config.getAttribute("id");
        } else {
          className = className.trim();
        }
        String resourceFile = "" + className.replaceAll("\\.", "/") + ".xml";
        resource = getClass().getClassLoader().getResourceAsStream(resourceFile);
        dictionaryFile = resource != null ? resourceFile : null;
      } else {
        File file = new File(filePath);
        getLogger().info("getting lanaguageResources  from " + file.getCanonicalPath());
        resource = new FileInputStream(file);
        dictionaryFile = filePath;
      }
      if (resource != null) {
        dict = new TranslationParser().parse(resource);
        resource.close();
      } else {
        dict = new RaplaDictionary(locale.getLanguage());
      }
    } catch (Exception ex) {
      throw new RaplaException(ex);
    }
    setLocale(locale);
    try {
      parentId = getPack(locale).getString(TranslationParser.PARENT_BUNDLE_IDENTIFIER);
    } catch (MissingResourceException ex) {
    }
  }
Example #2
0
 public void dispose() {
   if (m_localeSelector != null) m_localeSelector.removeLocaleChangeListener(this);
 }