/** * Returns a new DateFormat. * * @return a new DateFormat */ @Override public DateFormat getDateFormat() { return new DelegateDateFormat(new DateFormatSupplier()); }
@Override public Iterable<Class<?>> apply(final Class<?> clazz) { return new ClassAndAllInterfacesIterator(clazz); } };
private Iterable<Method> loadMethodsForName(final String methodName) { return deduplicateByNameAndArgumentTypes( publicMethodsWithName(allClassesAndInterfaces(), methodName)); }
@Override @Nonnull public ClassMap load(@Nonnull final Class<?> key) { return new CachingJiraClassMap(new JiraClassMap(key)); } }, new CacheSettingsBuilder().expireAfterAccess(30, TimeUnit.MINUTES).build());
@Override public Method findMethod(final String name, final Object[] params) throws MethodMap.AmbiguousException { final MethodCacheEntry cacheKey = getCacheKey(name, params); final Option<Method> cachedMethod = methodCache.get(cacheKey); if (cachedMethod != null) { return cachedMethod.getOrNull(); } final Method resolvedMethod = delegate.findMethod(name, params); final Option<Method> prevValue = methodCache.putIfAbsent(cacheKey, Option.option(resolvedMethod)); return prevValue != null ? prevValue.getOrNull() : resolvedMethod; }
public String getBody(final String templateDirectory, String template, Map<String,Object> contextParameters) throws VelocityException { return getEncodedBody(templateDirectory, template, null, null, contextParameters); }
private MethodCacheEntry(final String methodName, final Object[] params) { this.methodName = methodName; this.paramsTypes = VelocityTypesUtil.getParametersTypes(params); }
@Override public Method findMethod(final String name, final Object[] params) throws MethodMap.AmbiguousException { return methodMap.find(name, params); } }
public Object put(String key, Object value) { if (key == null) { return null; } else { return internalPut(key, value); } } };
private MethodCacheEntry getCacheKey(final String name, final Object[] params) { return new MethodCacheEntry(name, params); }
public void writeEncodedBody(final Writer writer, final String templateDirectory, String template, String encoding, Context context) throws VelocityException, IOException { writeEncodedBodyImpl(writer, templateDirectory, template, encoding, context); }
@Override public MethodComparator apply(@Nullable final Method method) { return new MethodComparator(method); } };
@Override public boolean apply(final Method method) { return Arrays.equals(VelocityTypesUtil.getMethodArgsTypes(method), parametersTypes); } }));
public JiraClassMap(@Nonnull final Class<?> clazz) { this.methodMap = new JiraMethodMap(clazz); }
protected synchronized VelocityEngine getVe() { if (ve == null) { ve = new VelocityEngine(); initVe(ve); } return ve; }
public static Class<?>[] getMethodArgsTypes(final Method method) { final Class<?>[] parameterTypes = method.getParameterTypes(); if (parameterTypes.length == 0) { return EMPTY_ARRAY; } final Class<?>[] translatedTypes = new Class[parameterTypes.length]; for (int i = 0; i < parameterTypes.length; i++) { final Class<?> parameterType = parameterTypes[i]; translatedTypes[i] = translateTypes(parameterType); } return translatedTypes; }
private Iterable<Class<?>> allClassesAndInterfaces() { return filter(concat(transform(getSuperClasses(clazz), GET_CLASS_AND_ALL_INTERFACES)), IS_PUBLIC_CLASS); }
private Iterable<Method> publicMethodsWithName(final Iterable<Class<?>> classes, final String methodName) { final Iterable<Method> allMethods = concat(transform(classes, GET_ALL_DECLARED_METHODS)); final Iterable<Method> publicMethods = filter(allMethods, PUBLIC_METHOD); return filter(publicMethods, new MethodByName(methodName)); }
public String getEncodedBody(final String templateDirectory, String template, String encoding, Map<String,Object> contextParameters) throws VelocityException { return getEncodedBody(templateDirectory, template, null, encoding, contextParameters); }
public String getBody(final String templateDirectory, String template, String baseurl, Map<String,Object> contextParameters) throws VelocityException { return getEncodedBody(templateDirectory, template, baseurl, null, contextParameters); }