/** * Adds a key to the given list; if the last part is "label", adds another key without it. * * @see #keyify(String...) */ protected void addKey(List<String> keys, boolean stripLabelSuffix, String... parts) { this.addKey(keys, keyify(parts)); if (stripLabelSuffix && LABEL.equals(parts[parts.length - 1])) { //this unnecessary increases count of keys in memory, kept for compatibility this.addKey(keys, keyify(Arrays.copyOfRange(parts, 0, parts.length - 1))); } }
/** * Returns the {@link I18nKeyGenerator}s corresponding to the parent objects of the given object. * * @see #getAncestors(Object) */ protected <C> List<I18nKeyGenerator> getAncestorKeyGenerators(C obj) { return Lists.transform(getAncestors(obj), new Function<Object, I18nKeyGenerator>() { @Override public I18nKeyGenerator apply(Object input) { return getKeyGenerator(input); } }); }
protected String getIdOrNameForUnknownRoot(Object obj) { return getIdOrNameForUnknownRoot(obj, true); }
/** * Returns the {@link I18nKeyGenerator}s corresponding to the root object of the given object. * * @see #getRoot(Object) */ protected <C> I18nKeyGenerator getRootKeyGenerator(C obj) { return getKeyGenerator(getRoot(obj)); }
final Object root = getParentViaCast(obj) != null ? getRoot(obj) : obj; @SuppressWarnings("unchecked") final Set<Method> methods = ReflectionUtils.getMethods(root.getClass(), new Predicate<Method>() { idOrName = (String) iterator.next().invoke(root); if (StringUtils.isNotBlank(idOrName)) { return keyify ? keyify(idOrName) : idOrName;
protected void addKey(List<String> keys, String... parts) { this.addKey(keys, true, parts); }
/** * Protected only to be able to test - ancestors should NOT override this method, unless they have <b>very</b> good reason to do this. * @deprecated since 5.4.5. Will be removed in a future version. */ @Deprecated protected String resolveMessageBundleNameUpwards(Object object) { String bundleName = null; try { Method getI18nBasename = object.getClass().getMethod("getI18nBasename"); bundleName = (String) getI18nBasename.invoke(object); } catch (NoSuchMethodException e) { // expected - not every parent has to have such method } catch (SecurityException e) { throw new RuntimeException(e); } catch (IllegalArgumentException e) { throw new RuntimeException(e); } catch (IllegalAccessException e) { throw new RuntimeException(e); } catch (InvocationTargetException e) { throw new RuntimeException(e); } if (bundleName == null) { Object parent = getParentViaCast(object); if (parent != null) { bundleName = resolveMessageBundleNameUpwards(parent); } } return bundleName; }
/** * Returns the root object that of the {@link I18nParentable} hierarchy. * * @see #getParentViaCast(Object) */ protected <C> Object getRoot(C obj) { Object root = null; Object p = getParentViaCast(obj); while (p != null) { root = p; p = getParentViaCast(p); } return root; }
@Override public I18nKeyGenerator apply(Object input) { return getKeyGenerator(input); } });
/** * @deprecated since 5.4.5. Will be removed in a future version. */ @Deprecated @Override public String messageBundleNameFor(T object) { return resolveMessageBundleNameUpwards(object); }
/** * Returns the name of the field or method passed to {@link I18nKeyGenerator#keysFor(String, T, java.lang.reflect.AnnotatedElement)}. */ protected String fieldOrGetterName(AnnotatedElement el) { if (el instanceof Field) { return ((Field) el).getName(); } else if (el instanceof Method) { return getterToField((Method) el); } else { throw new IllegalArgumentException("Can't derive i18n key suffix from " + el); } }
protected String getIdWithoutModuleName(String id) { return keyify(StringUtils.contains(id, ":") ? StringUtils.substringAfter(id, ":") : id); }
/** * Default implementation for {@link #keysFor(String, Object, java.lang.reflect.AnnotatedElement)}, which sets * the undecoratedResult value if it is not null, and delegates to {@link #keysFor(java.util.List, Object, java.lang.reflect.AnnotatedElement)}. */ @Override public String[] keysFor(String undecoratedResult, T object, AnnotatedElement el) { final List<String> keys = new ArrayList<>(); keysFor(keys, object, el); if (undecoratedResult != null) { keys.add(0, undecoratedResult); } return keys.toArray(new String[keys.size()]); }
/** * Returns the list of parent objects as set via the {@link I18nParentable} interface * when the object was decorated by {@link I18nizer}. * * @see #getParentViaCast(Object) */ protected <C> List<Object> getAncestors(C obj) { final ArrayList<Object> ancestors = new ArrayList<Object>(); Object p = getParentViaCast(obj); while (p != null) { ancestors.add(p); p = getParentViaCast(p); } return ancestors; }