本文整理汇总了Java中com.mitchellbosecke.pebble.extension.escaper.SafeString类的典型用法代码示例。如果您正苦于以下问题:Java SafeString类的具体用法?Java SafeString怎么用?Java SafeString使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
SafeString类属于com.mitchellbosecke.pebble.extension.escaper包,在下文中一共展示了SafeString类的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: execute
import com.mitchellbosecke.pebble.extension.escaper.SafeString; //导入依赖的package包/类
@Override
public Object execute(Map<String, Object> args) {
String messageKey = (String) args.get("key");
EvaluationContext context = (EvaluationContext) args.get("_context");
Locale locale = context.getLocale();
String requestLang = locale.toLanguageTag();
List<Object> messageArgs = Lists.newArrayList();
for (int i = 1; i <= 5; i++) {
if (args.containsKey("arg" + i)) {
Object object = args.get("arg" + i);
messageArgs.add(object);
}
}
String messageValue = messages.get(messageKey, requestLang, messageArgs.toArray());
return new SafeString(messageValue);
}
示例2: applyTemporal
import com.mitchellbosecke.pebble.extension.escaper.SafeString; //导入依赖的package包/类
private Object applyTemporal(final TemporalAccessor input, PebbleTemplate self, final Locale locale,
int lineNumber, final String format) throws PebbleException {
final DateTimeFormatter formatter = format != null
? DateTimeFormatter.ofPattern(format, locale)
: DateTimeFormatter.ISO_DATE_TIME;
try {
return new SafeString(formatter.format(input));
} catch (DateTimeException dte) {
throw new PebbleException(dte, String.format("Could not parse the string '%1' into a date.",
input.toString()), lineNumber, self.getName());
}
}
示例3: add
import com.mitchellbosecke.pebble.extension.escaper.SafeString; //导入依赖的package包/类
public static Object add(Object op1, Object op2) {
if (op1 instanceof String || op2 instanceof String) {
return concatenateStrings(String.valueOf(op1), String.valueOf(op2));
} else if (op1 instanceof SafeString || op2 instanceof SafeString) {
return concatenateStrings(String.valueOf(op1), String.valueOf(op2));
} else if (op1 instanceof List) {
return addToList((List<?>) op1, op2);
}
return wideningConversionBinaryOperation(op1, op2, Operation.ADD);
}
示例4: evaluate
import com.mitchellbosecke.pebble.extension.escaper.SafeString; //导入依赖的package包/类
@Override
public Object evaluate(PebbleTemplateImpl self, EvaluationContextImpl context) throws PebbleException {
FilterInvocationExpression filterInvocation = (FilterInvocationExpression) getRightExpression();
ArgumentsNode args = filterInvocation.getArgs();
String filterName = filterInvocation.getFilterName();
if (this.filter == null) {
this.filter = context.getExtensionRegistry().getFilter(filterInvocation.getFilterName());
}
if (filter == null) {
throw new PebbleException(null, String.format("Filter [%s] does not exist.", filterName),
this.getLineNumber(), self.getName());
}
Map<String, Object> namedArguments = args.getArgumentMap(self, context, filter);
// This check is not nice, because we use instanceof. However this is
// the only filter which should not fail in strict mode, when the variable
// is not set, because this method should exactly test this. Hence a
// generic solution to allow other tests to reuse this feature make no sense
Object input;
if (filter instanceof DefaultFilter) {
try {
input = getLeftExpression().evaluate(self, context);
} catch (AttributeNotFoundException ex) {
input = null;
}
} else {
input = getLeftExpression().evaluate(self, context);
}
if (input instanceof SafeString && !(filter instanceof EscapeFilter)) {
input = input.toString();
}
return filter.apply(input, namedArguments, self, context, this.getLineNumber());
}
示例5: execute
import com.mitchellbosecke.pebble.extension.escaper.SafeString; //导入依赖的package包/类
@Override
public Object execute(Map<String, Object> args) {
TemplateFunction freshFunction = contextProvider.get().getInjector().getInstance(functionClass);
JSONObject object = new JSONObject(args);
freshFunction.extractOptions(contextProvider.get(), object);
Object output = freshFunction.apply(null);
if(freshFunction.isSafe()) {
return new SafeString(output.toString());
}
else {
return output;
}
}
示例6: apply
import com.mitchellbosecke.pebble.extension.escaper.SafeString; //导入依赖的package包/类
@Override
public Object apply(Object input, Map<String, Object> args) {
TemplateFunction freshFunction = contextProvider.get().getInjector().getInstance(functionClass);
JSONObject object = new JSONObject(args);
freshFunction.extractOptions(contextProvider.get(), object);
Object output = freshFunction.apply(input);
if(freshFunction.isSafe()) {
return new SafeString(output.toString());
}
else {
return output;
}
}
示例7: apply
import com.mitchellbosecke.pebble.extension.escaper.SafeString; //导入依赖的package包/类
@Override
public Object apply(Object input, Map<String, Object> args) {
if (input == null) {
return null;
}
EvaluationContext context = (EvaluationContext) args.get("_context");
Locale locale = context.getLocale();
DateFormat existingFormat;
DateFormat intendedFormat;
String format = (String) args.get("format");
int type = parseStyle(format);
if (type == -1) {
intendedFormat = new SimpleDateFormat(format, locale);
} else {
intendedFormat = DateFormat.getDateTimeInstance(type, type, locale);
}
Date date;
if (args.get(EXISTING_FORMAT) != null) {
existingFormat = new SimpleDateFormat((String) args.get(EXISTING_FORMAT), locale);
try {
date = existingFormat.parse((String) input);
} catch (ParseException e) {
throw new RuntimeException("Could not parse date", e);
}
} else {
date = getDateObject(input);
}
return new SafeString(intendedFormat.format(date));
}
示例8: apply
import com.mitchellbosecke.pebble.extension.escaper.SafeString; //导入依赖的package包/类
@Override
public Object apply(Object input, Map<String, Object> args) {
if (input == null) {
return null;
}
EvaluationContext context = (EvaluationContext) args.get("_context");
Locale locale = context.getLocale();
String result = prettyTimeCache.getUnchecked(locale).format(getFormattableObject(input));
return new SafeString(result);
}