예제 #1
0
 /*
  * (non-Javadoc)
  *
  * @see org.ajax4jsf.gwt.jsf.GwtComponent#getWidgetParameters()
  */
 public Map getWidgetParameters() {
   Map params = new HashMap();
   String basename = getBundleBase();
   String bundleName = getBundleName();
   if (null != basename && null != bundleName) {
     try {
       ResourceBundle bundle =
           ResourceBundle.getBundle(
               basename, FacesContext.getCurrentInstance().getViewRoot().getLocale());
       HashMap messages = new HashMap();
       for (Enumeration keys = bundle.getKeys(); keys.hasMoreElements(); ) {
         String key = (String) keys.nextElement();
         messages.put(key, bundle.getString(key));
       }
       params.put(bundleName, messages);
     } catch (Exception e) {
       // message bundle not found
     }
   }
   for (Iterator iter = getChildren().iterator(); iter.hasNext(); ) {
     Object element = iter.next();
     if (element instanceof UIParameter) {
       UIParameter param = (UIParameter) element;
       params.put(param.getName(), param.getValue());
     }
   }
   return params;
 }
 @Override
 public Enumeration<String> getKeys() {
   // TODO Auto-generated method stub
   return null != delegate
       ? delegate.getKeys()
       : Collections.<String>enumeration(Collections.<String>emptyList());
 }
    @Override
    public ResourceBundle addingService(ServiceReference<ResourceBundle> serviceReference) {

      Registry registry = RegistryUtil.getRegistry();

      ResourceBundle resourceBundle = registry.getService(serviceReference);

      String languageId =
          GetterUtil.getString(serviceReference.getProperty("language.id"), StringPool.BLANK);
      Map<String, String> languageMap = new HashMap<>();
      Locale locale = null;

      if (Validator.isNotNull(languageId)) {
        locale = LocaleUtil.fromLanguageId(languageId, true);
      } else {
        locale = new Locale(StringPool.BLANK);
      }

      Enumeration<String> keys = resourceBundle.getKeys();

      while (keys.hasMoreElements()) {
        String key = keys.nextElement();

        String value = ResourceBundleUtil.getString(resourceBundle, key);

        languageMap.put(key, value);
      }

      Map<String, String> oldLanguageMap = _putLanguageMap(locale, languageMap);

      _oldLanguageMaps.put(serviceReference, oldLanguageMap);

      return resourceBundle;
    }
  private OurConfiguration createConfiguration() {
    OurConfiguration config = new OurConfiguration();
    config.setHostNameOrIpAddr(HOST_NAME);
    config.setHostTelnetPortNumber(HOST_TELNET_PORT);
    config.setConnectionProperties(null);
    config.setConnectScript(getLoginScript());
    config.setDisconnectScript(getLogoffScript());
    config.setUserName(SYSTEM_USER);
    config.setPassword(new GuardedString(SYSTEM_PASSWORD.toCharArray()));
    config.setEvictionInterval(60000);
    config.setConnectionClassName(WrqConnection.class.getName());

    OurConnectorMessages messages = new OurConnectorMessages();
    Map<Locale, Map<String, String>> catalogs = new HashMap<Locale, Map<String, String>>();
    Map<String, String> foo = new HashMap<String, String>();
    for (String bundleName : new String[] {"org.identityconnectors.rw3270.Messages"}) {
      ResourceBundle messagesBundle = ResourceBundle.getBundle(bundleName);
      Enumeration<String> enumeration = messagesBundle.getKeys();
      while (enumeration.hasMoreElements()) {
        String key = enumeration.nextElement();
        foo.put(key, messagesBundle.getString(key));
      }
    }

    catalogs.put(Locale.getDefault(), foo);
    messages.setCatalogs(catalogs);
    config.setConnectorMessages(messages);
    return config;
  }
  public void load() throws Exception {
    if (loaded) {
      if (loadException != null) {
        throw new Exception(loadException);
      }
      return;
    }
    synchronized (_synObj) {
      if (!loaded) {
        try {
          String tmpFile = propertyFile.trim();
          if (tmpFile.endsWith(".properties")) {
            tmpFile = tmpFile.substring(0, tmpFile.lastIndexOf("."));
          }
          ResourceBundle resource = ResourceBundle.getBundle(tmpFile);
          Enumeration<String> enm = resource.getKeys();

          while (enm.hasMoreElements()) {
            String key = enm.nextElement();
            String value = resource.getString(key);
            properties.put(key, value);
          }
        } catch (Exception e) {
          System.err.println(
              "Exception while loading the config.properties file :: " + e.getMessage());
          loadException = e;
          loaded = true;
          throw e;
        }
        loaded = true;
      }
    }
  }
예제 #6
0
  /** Returns a Map of the known resources for the given locale. */
  private Map<String, Object> getResourceCache(Locale l) {
    Map<String, Object> values = resourceCache.get(l);

    if (values == null) {
      values = new TextAndMnemonicHashMap();
      for (int i = resourceBundles.size() - 1; i >= 0; i--) {
        String bundleName = resourceBundles.get(i);
        try {
          Control c = CoreResourceBundleControl.getRBControlInstance(bundleName);
          ResourceBundle b;
          if (c != null) {
            b = ResourceBundle.getBundle(bundleName, l, c);
          } else {
            b = ResourceBundle.getBundle(bundleName, l);
          }
          Enumeration keys = b.getKeys();

          while (keys.hasMoreElements()) {
            String key = (String) keys.nextElement();

            if (values.get(key) == null) {
              Object value = b.getObject(key);

              values.put(key, value);
            }
          }
        } catch (MissingResourceException mre) {
          // Keep looking
        }
      }
      resourceCache.put(l, values);
    }
    return values;
  }
예제 #7
0
 static Set<String> getLegacyPackages() {
   ResourceBundle legacyBundle = ResourceBundle.getBundle("com.sun.tools.javac.resources.legacy");
   Set<String> keys = new HashSet<String>();
   for (Enumeration<String> e = legacyBundle.getKeys(); e.hasMoreElements(); )
     keys.add(e.nextElement());
   return keys;
 }
예제 #8
0
  /**
   * Construct a JSONObject from a ResourceBundle.
   *
   * @param baseName The ResourceBundle base name.
   * @param locale The Locale to load the ResourceBundle for.
   * @throws JSONException If any JSONExceptions are detected.
   */
  public JSONObject(String baseName, Locale locale) throws JSONException {
    this();
    ResourceBundle bundle =
        ResourceBundle.getBundle(baseName, locale, Thread.currentThread().getContextClassLoader());

    // Iterate through the keys in the bundle.

    Enumeration keys = bundle.getKeys();
    while (keys.hasMoreElements()) {
      Object key = keys.nextElement();
      if (key instanceof String) {

        // Go through the path, ensuring that there is a nested JSONObject for each
        // segment except the last. Add the value using the last segment's name into
        // the deepest nested JSONObject.

        String[] path = ((String) key).split("\\.");
        int last = path.length - 1;
        JSONObject target = this;
        for (int i = 0; i < last; i += 1) {
          String segment = path[i];
          JSONObject nextTarget = target.optJSONObject(segment);
          if (nextTarget == null) {
            nextTarget = new JSONObject();
            target.put(segment, nextTarget);
          }
          target = nextTarget;
        }
        target.put(path[last], bundle.getString((String) key));
      }
    }
  }
예제 #9
0
  public static final PriceItemBean[] loadItems(String propsName) {
    ResourceBundle priceBundle = ResourceBundle.getBundle(propsName);

    Enumeration bundleKeys = priceBundle.getKeys();
    ArrayList keyList = new ArrayList();

    while (bundleKeys.hasMoreElements()) {
      String key = (String) bundleKeys.nextElement();
      String value = priceBundle.getString(key);
      keyList.add(value);
    }

    PriceItemBean[] items =
        (PriceItemBean[]) Array.newInstance(PriceItemBean.class, keyList.size());
    int k = 0;

    for (Iterator it = keyList.iterator(); it.hasNext(); ) {
      String s = (String) it.next();
      int commaIndex = s.indexOf(",");
      String name = s.substring(0, commaIndex).trim();
      String price = s.substring(commaIndex + 1, s.length()).trim();
      items[k] = new PriceItemBean(name, new BigDecimal(price));
      k++;
    }

    return items;
  }
예제 #10
0
파일: CarBean.java 프로젝트: kowsercse/jsf
  /**
   * For each entry in data, create component and cause it to be populated with values.
   *
   * @param context the <code>FacesContext</code> for the current request
   * @param data a ResourceBundle
   */
  private void initComponentsFromProperties(FacesContext context, ResourceBundle data) {

    // populate the map
    for (Enumeration<String> keys = data.getKeys(); keys.hasMoreElements(); ) {

      String key = keys.nextElement();
      if (key == null) {
        continue;
      }
      // skip secondary keys.
      if (key.contains("_")) {
        continue;
      }
      String value = data.getString(key);
      String componentType = data.getString(key + "_componentType");
      String valueType = data.getString(key + "_valueType");
      if (LOGGER.isLoggable(Level.FINE)) {
        LOGGER.fine(
            "populating map for "
                + key
                + "\n"
                + "\n\tvalue: "
                + value
                + "\n\tcomponentType: "
                + componentType
                + "\n\tvalueType: "
                + valueType);
      }
      // create the component for this componentType
      UIComponent component = context.getApplication().createComponent(componentType);
      populateComponentWithValue(context, component, componentType, value, valueType);
      components.put(key, component);
    }
  }
예제 #11
0
 public static Properties convertBundleToProperties(ResourceBundle rb) {
   Properties props = new Properties();
   for (Enumeration<String> keys = rb.getKeys(); keys.hasMoreElements(); ) {
     String key = (String) keys.nextElement();
     props.put(key, rb.getString(key));
   }
   return props;
 }
  /**
   * Looks up a resource named 'name' in the classpath. The resource must map to a file with
   * .properties extention. The name is assumed to be absolute and can use either "/" or "." for
   * package segment separation with an optional leading "/" and optional ".properties" suffix.
   * Thus, the following names refer to the same resource:
   *
   * <pre>
   * some.pkg.Resource
   * some.pkg.Resource.properties
   * some/pkg/Resource
   * some/pkg/Resource.properties
   * /some/pkg/Resource
   * /some/pkg/Resource.properties
   * </pre>
   *
   * @param name classpath resource name [may not be null]
   * @param loader classloader through which to load the resource [null is equivalent to the
   *     application loader]
   * @return resource converted to java.util.Properties [may be null if the resource was not found
   *     and THROW_ON_LOAD_FAILURE is false]
   * @throws IllegalArgumentException if the resource was not found and THROW_ON_LOAD_FAILURE is
   *     true
   */
  public static Properties loadProperties(String name, ClassLoader loader) {
    if (name == null) throw new IllegalArgumentException("null input: name");

    if (name.startsWith("/")) name = name.substring(1);

    if (name.endsWith(SUFFIX)) name = name.substring(0, name.length() - SUFFIX.length());

    Properties result = null;

    InputStream in = null;
    try {
      if (loader == null) loader = ClassLoader.getSystemClassLoader();

      if (LOAD_AS_RESOURCE_BUNDLE) {
        name = name.replace('/', '.');
        // Throws MissingResourceException on lookup failures:
        final ResourceBundle rb = ResourceBundle.getBundle(name, Locale.getDefault(), loader);

        result = new Properties();
        for (Enumeration keys = rb.getKeys(); keys.hasMoreElements(); ) {
          final String key = (String) keys.nextElement();
          final String value = rb.getString(key);

          result.put(key, value);
        }
      } else {
        name = name.replace('.', '/');

        if (!name.endsWith(SUFFIX)) name = name.concat(SUFFIX);

        // Returns null on lookup failures:
        in = loader.getResourceAsStream(name);
        if (in != null) {
          result = new Properties();
          result.load(in); // Can throw IOException
        }
      }
    } catch (Exception e) {
      result = null;
    } finally {
      if (in != null)
        try {
          in.close();
        } catch (Throwable ignore) {
        }
    }

    if (THROW_ON_LOAD_FAILURE && (result == null)) {
      throw new IllegalArgumentException(
          "could not load ["
              + name
              + "]"
              + " as "
              + (LOAD_AS_RESOURCE_BUNDLE ? "a resource bundle" : "a classloader resource"));
    }

    return result;
  }
예제 #13
0
 private void setLocale(Locale locale, String resourceBundleName) {
   if (locale == null) {
     throw new IllegalArgumentException("locale is null.");
   }
   resourceBundle = ResourceBundle.getBundle(resourceBundleName, locale);
   for (Enumeration<String> keys = resourceBundle.getKeys(); keys.hasMoreElements(); ) {
     this.keyList.add(keys.nextElement());
   }
 }
예제 #14
0
 public Map fileToMap(String fileName) {
   String bundleName = fileName;
   ResourceBundle bundle = ResourceBundle.getBundle(bundleName);
   HashSet<String> keys = new HashSet<>(Collections.list(bundle.getKeys()));
   for (String key : keys) {
     file.put(key, bundle.getString(key));
   }
   return file;
 }
예제 #15
0
  static void iterateKeys(Locale currentLocale) {
    ResourceBundle labels = ResourceBundle.getBundle("LabelsBundle", currentLocale);
    Enumeration bundlekey = labels.getKeys();

    while (bundlekey.hasMoreElements()) {
      String key = (String) bundlekey.nextElement();
      String value = labels.getString(key);
      System.out.println("key=" + key + "," + "value=" + value);
    }
  }
예제 #16
0
  /**
   * Returns an <code>Enumeration</code> of the keys contained in this <code>ResourceBundle</code>
   * and its parent bundles.
   *
   * @return an <code>Enumeration</code> of the keys contained in this <code>ResourceBundle</code>
   *     and its parent bundles.
   * @see #keySet()
   */
  public Enumeration<String> getKeys() {
    // lazily load the lookup hashtable.
    if (lookup == null) {
      loadLookup();
    }

    ResourceBundle parent = this.parent;
    return new ResourceBundleEnumeration(
        lookup.keySet(), (parent != null) ? parent.getKeys() : null);
  }
예제 #17
0
  /**
   * Creating a list of common excludes
   *
   * @return a list of excludes to consider
   */
  private String[] getDefaultExcludes() {
    final ResourceBundle excludesList = ResourceBundle.getBundle("defaultExcludes");
    final List<String> excludes = new ArrayList<String>();

    for (final Enumeration<String> keys = excludesList.getKeys(); keys.hasMoreElements(); ) {
      excludes.add(excludesList.getString(keys.nextElement()));
    }

    return excludes.toArray(new String[excludes.size()]);
  }
 public HashMap<String, String> getAllProperties() {
   ResourceBundle resource = this.getResource();
   Enumeration<String> keys = resource.getKeys();
   HashMap<String, String> result = new HashMap<String, String>();
   while (keys.hasMoreElements()) {
     String key = keys.nextElement();
     String value = resource.getString(key);
     result.put(key, value);
   }
   return result;
 }
  private Map<String, String> convertResourceBundleToMap(ResourceBundle resource) {
    Map<String, String> map = new HashMap<String, String>();

    Enumeration<String> keys = resource.getKeys();
    while (keys.hasMoreElements()) {
      String key = keys.nextElement();
      map.put(key, resource.getString(key));
    }

    return map;
  }
 /**
  * Register bean definitions contained in a ResourceBundle.
  *
  * <p>Similar syntax as for a Map. This method is useful to enable standard Java
  * internationalization support.
  *
  * @param rb the ResourceBundle to load from
  * @param prefix match or filter within the keys in the map: e.g. 'beans.' (can be empty or <code>
  *     null</code>)
  * @return the number of bean definitions found
  * @throws BeansException in case of loading or parsing errors
  */
 public int registerBeanDefinitions(ResourceBundle rb, String prefix)
     throws BeanDefinitionStoreException {
   // Simply create a map and call overloaded method.
   Map map = new HashMap();
   Enumeration keys = rb.getKeys();
   while (keys.hasMoreElements()) {
     String key = (String) keys.nextElement();
     map.put(key, rb.getObject(key));
   }
   return registerBeanDefinitions(map, prefix);
 }
  public static Properties convertResourceBundleToProperties(ResourceBundle resource) {
    Properties properties = new Properties();

    Enumeration<String> keys = resource.getKeys();
    while (keys.hasMoreElements()) {
      String key = keys.nextElement();
      properties.put(key, resource.getString(key));
    }

    return properties;
  }
예제 #22
0
 public static void addBundle(ResourceBundle r) {
   synchronized (mutex) {
     Enumeration en = r.getKeys();
     while (en.hasMoreElements()) {
       String alphaCode = (String) en.nextElement();
       String[] tmp = r.getString(alphaCode).split(" ");
       String isoCode = tmp[0];
       int numDecimals = Integer.parseInt(tmp[1]);
       addCurrency(alphaCode, isoCode, numDecimals);
     }
   }
 }
예제 #23
0
  public Map asMap() {
    Map result = new HashMap();

    Enumeration e = delegate.getKeys();
    while (e.hasMoreElements()) {
      String key = (String) e.nextElement();
      String value = getString(key);
      result.put(key, value);
    }

    return result;
  }
예제 #24
0
  /**
   * Utility method to populate a javabean-style object with values from a Properties file
   *
   * @param obj the model object to populate
   * @return Object populated object
   * @throws Exception if BeanUtils fails to copy properly
   */
  protected Object populate(Object obj) throws Exception {
    // loop through all the beans methods and set its properties from its .properties file
    Map<String, String> map = new HashMap<String, String>();

    for (Enumeration<String> keys = rb.getKeys(); keys.hasMoreElements(); ) {
      String key = keys.nextElement();
      map.put(key, rb.getString(key));
    }

    BeanUtils.copyProperties(map, obj);

    return obj;
  }
예제 #25
0
 protected void initResourceBundle(UIDefaults table) {
   // The following line of code does not work, when Quaqua has been loaded with
   // a custom class loader. That's why, we have to inject the labels
   // by ourselves:
   // table.addResourceBundle( "ch.randelshofer.quaqua.Labels" );
   ResourceBundle bundle =
       ResourceBundle.getBundle(
           "ch.randelshofer.quaqua.Labels", Locale.getDefault(), getClass().getClassLoader());
   for (Enumeration i = bundle.getKeys(); i.hasMoreElements(); ) {
     String key = (String) i.nextElement();
     table.put(key, bundle.getObject(key));
   }
 }
예제 #26
0
파일: Apps.java 프로젝트: dpharris/JMRI
 protected final void addToActionModel() {
   apps.CreateButtonModel bm = InstanceManager.getDefault(apps.CreateButtonModel.class);
   ResourceBundle actionList = ResourceBundle.getBundle("apps.ActionListBundle");
   Enumeration<String> e = actionList.getKeys();
   while (e.hasMoreElements()) {
     String key = e.nextElement();
     try {
       bm.addAction(key, actionList.getString(key));
     } catch (ClassNotFoundException ex) {
       log.error("Did not find class {}", key);
     }
   }
 }
    /**
     * Creates a new AggregateBundle.
     *
     * @param bundles A list of source bundles, which shall be merged into one aggregated bundle.
     *     The newly created bundle will contain all keys from all source bundles. In case a key
     *     occurs in multiple source bundles, the value will be taken from the first bundle
     *     containing the key.
     */
    public AggregateBundle(List<ResourceBundle> bundles) {
      if (bundles != null) {

        for (ResourceBundle bundle : bundles) {
          Enumeration<String> keys = bundle.getKeys();
          while (keys.hasMoreElements()) {
            String oneKey = keys.nextElement();
            if (!contents.containsKey(oneKey)) {
              contents.put(oneKey, bundle.getObject(oneKey));
            }
          }
        }
      }
    }
예제 #28
0
 /**
  * 获取urlMap
  *
  * @return
  */
 public static Map<String, String> getUrlMap() {
   if (urlsMap != null && !urlsMap.isEmpty()) {
     return urlsMap;
   }
   urlsMap = new HashMap<String, String>();
   Enumeration e = res.getKeys();
   while (e.hasMoreElements()) {
     String key = e.nextElement().toString();
     String value = get(key);
     urlsMap.put(key, value);
     System.out.println(key + "---" + value);
   }
   return urlsMap;
 }
예제 #29
0
 private void addPlugin(String pluginKey) {
   try {
     String bundleKey = BUNDLE_PACKAGE + pluginKey;
     ResourceBundle bundle =
         ResourceBundle.getBundle(bundleKey, Locale.ENGLISH, this.classloader, control);
     Enumeration<String> keys = bundle.getKeys();
     while (keys.hasMoreElements()) {
       String key = keys.nextElement();
       propertyToBundles.put(key, bundleKey);
     }
   } catch (MissingResourceException e) {
     // ignore
   }
 }
  public AlchemyResponse crawlAndExtract(String url) throws Exception {
    AlchemyResponse alchemyResponse = new AlchemyResponse();

    AlchemyResponse alchemyResponseURL = new AlchemyResponse();
    if (logger.isTraceEnabled()) {
      logger.trace("Invoking Alchemy for url:" + url);
    }

    // Proxy settings
    // System.getProperties().put("proxySet", "true");
    // System.getProperties().put("http.proxyHost", "192.168.100.40");
    // System.getProperties().put("http.proxyPort", "8080");
    MultiValueMap<String, String> map = new LinkedMultiValueMap<String, String>();
    map.add(urlPropertyKey, url);

    Enumeration<String> keys = bundle.getKeys();
    String key;
    while (keys.hasMoreElements()) {
      key = keys.nextElement();
      map.add(key, bundle.getString(key));
    }

    // header and message converter preparation
    HttpHeaders headers = new HttpHeaders();
    headers.setContentType(MediaType.APPLICATION_FORM_URLENCODED);

    HttpEntity<MultiValueMap<String, String>> request =
        new HttpEntity<MultiValueMap<String, String>>(map, headers);
    List<HttpMessageConverter<?>> messageConverters = new ArrayList<HttpMessageConverter<?>>();
    messageConverters.add(new MappingJackson2HttpMessageConverter(new ObjectMapper()));
    messageConverters.add(new FormHttpMessageConverter());
    restTemplate.setMessageConverters(messageConverters);

    // call to alchymy
    try {
      alchemyResponse =
          restTemplate.postForObject(
              getRestServiceUrl() + "URLGetRankedNamedEntities", request, AlchemyResponse.class);

      alchemyResponseURL =
          restTemplate.postForObject(
              getRestServiceUrl() + "URLGetTitle", request, AlchemyResponse.class);

      alchemyResponse.setTitle(alchemyResponseURL.getTitle());
    } catch (ResourceAccessException e) {
      throw new Exception("Alchemy online service not accessible.", e);
    }
    return alchemyResponse;
  }