@Override public void resolve(TemplateVariable variable, TemplateContext context) { List<String> params= variable.getVariableType().getParams(); if (params.size() >= 1 && params.get(0) != null) { resolveWithParams(variable, context, params); } else { // No parameter, use default format: super.resolve(variable, context); } }
@Override public void resolve(TemplateVariable variable, TemplateContext context) { List<String> params= variable.getVariableType().getParams(); if (params.size() >= 1 && params.get(0) != null) { resolveWithParams(variable, context, params); } else { // No parameter, use default: super.resolve(variable, context); } }
@Override public void resolve(TemplateVariable variable, TemplateContext context) { List<String> params= variable.getVariableType().getParams(); if (params.size() >= 1 && params.get(0) != null) { resolveWithParams(variable, context, params); } else { // No parameter, use default: super.resolve(variable, context); } }
@Override public void resolve(TemplateVariable variable, TemplateContext context) { List<String> params= variable.getVariableType().getParams(); if (params.size() >= 1 && params.get(0) != null) { resolveWithParams(variable, context, params); } else { // No parameter, use default format: super.resolve(variable, context); } }
private void resolveWithParams(TemplateVariable variable, TemplateContext context, List<String> params) { try { // There is a least one parameter (params.get(0) is not null), set the format depending on second parameter: DateFormat format; if (params.size() >= 2 && params.get(1) != null) { format= new SimpleDateFormat(params.get(0), new ULocale(params.get(1))); } else { format= new SimpleDateFormat(params.get(0)); } variable.setValue(format.format(new java.util.Date())); variable.setUnambiguous(true); variable.setResolved(true); } catch (IllegalArgumentException e) { // Date formating did not work, use default format instead: super.resolve(variable, context); } }
private void resolveWithParams(TemplateVariable variable, TemplateContext context, List<String> params) { try { // There is a least one parameter (params.get(0) is not null), set the format depending on second parameter: DateFormat format; if (params.size() >= 2 && params.get(1) != null) { format= new SimpleDateFormat(params.get(0), new ULocale(params.get(1))); } else { format= new SimpleDateFormat(params.get(0)); } variable.setValue(format.format(new java.util.Date())); variable.setUnambiguous(true); variable.setResolved(true); } catch (IllegalArgumentException e) { // Date formating did not work, use default format instead: super.resolve(variable, context); } }