/** * @see org.apache.velocity.tools.generic.ResourceTool#get(java.lang.Object, java.lang.String[], * java.lang.Object) */ @Override public Object get(Object code, String[] resourceNamePrefixes, Object locale) { Object msg = super.get(code, resourceNamePrefixes, locale); //if code's translation is blank, use the english equivalent if (msg == null || StringUtils.isBlank(msg.toString())) { msg = super.get(code, resourceNamePrefixes, Locale.ENGLISH.toString()); } return msg; } }
/** * Its need to override base class method to be able to change its locale property outside the * class hierarchy * * @see org.apache.velocity.tools.generic.ResourceTool#setLocale(Locale locale) */ @Override public void setLocale(Locale locale) { super.setLocale(locale); }
/** * Retrieves the {@link ResourceBundle} for the specified baseName * and locale, if such exists. If the baseName or locale is null * or if the locale argument cannot be converted to a {@link Locale}, * then this will return null. * @param baseName base name * @param loc locale * @return resource bundle */ protected ResourceBundle getBundle(String baseName, Object loc) { Locale locale = (loc == null) ? getLocale() : toLocale(loc); if (baseName == null || locale == null) { return null; } return ResourceBundle.getBundle(baseName, locale); }
public Key insert(Object arg) { return insert(new Object[] { arg }); }
/** * Accepts objects and uses their string value as the key. * @param key key * @return Key object */ public Key get(String key) { return new Key(key, this.bundles, getLocale(), null); }
/** * Returns the value for the specified key in the ResourceBundle for * the specified basename and locale. If no such resource can be * found, no errors are thrown and {@code null} is returned. * * @param key the key for the requested resource * @param baseName the base name of the resource bundle to search * @param loc the locale to use * @return value */ public Object get(Object key, String baseName, Object loc) { ResourceBundle bundle = getBundle(baseName, loc); if (key == null || bundle == null) { return null; } try { return bundle.getObject(String.valueOf(key)); } catch (Exception e) { return null; } }
public List<String> getKeys() { return ResourceTool.this.getKeys(this.key, this.bundles, this.locale); }
resourceTool.configure(toolConfig); context.put("resource", resourceTool);
public Key insert(Object arg0, Object arg1) { return insert(new Object[] { arg0, arg1 }); }
public Key insert(Object[] args) { return new Key(null, this.bundles, getLocale(), args); }
ResourceBundle bundle = getBundle(baseName, loc); if (bundle == null)
public Object getRaw() { if (!this.cached) { this.rawValue = ResourceTool.this.get(this.key, this.bundles, this.locale); this.cached = true; } return this.rawValue; }
public Key insert(List args) { return insert(args.toArray()); }
public Key bundle(String bundle) { return new Key(null, new String[] { bundle }, getLocale(), null); }
/** * Accepts objects and uses their string value as the key. * @param k key * @return Key object */ public Key get(Object k) { String key = k == null ? null : String.valueOf(k); return get(key); }
/** * Retrieve a resource for the specified key from the first of the * specified bundles in which a matching resource is found. * If no resource is found, no exception will be thrown and {@code null} * will be returned. * * @param k the key for the requested resource * @param bundles the resource bundles to search * @param l the locale to use * @return value */ public Object get(Object k, String[] bundles, Object l) { String key = k == null ? null : String.valueOf(k); for (int i=0; i < bundles.length; i++) { Object resource = get(key, bundles[i], l); if (resource != null) { return resource; } } return null; }