本文整理汇总了Java中com.mitchellbosecke.pebble.template.PebbleTemplate.getName方法的典型用法代码示例。如果您正苦于以下问题:Java PebbleTemplate.getName方法的具体用法?Java PebbleTemplate.getName怎么用?Java PebbleTemplate.getName使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.mitchellbosecke.pebble.template.PebbleTemplate
的用法示例。
在下文中一共展示了PebbleTemplate.getName方法的14个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: render
import com.mitchellbosecke.pebble.template.PebbleTemplate; //导入方法依赖的package包/类
private String render(Renderable renderable, PebbleTemplate template) {
try {
StringWriter writer=new StringWriter();
PebbleWrapper it = PebbleWrapper.builder()
.markupRenderFactory(markupRenderFactory)
.context(renderable.context())
.addAllAllBlobs(renderable.blobs())
.build();
template.evaluate(writer, Maps.newLinkedHashMap(ImmutableMap.of("it",it)));
return writer.toString();
} catch (PebbleException | IOException | RuntimePebbleException px) {
throw new RuntimeException("rendering fails for "+template.getName(),px);
}
}
示例2: apply
import com.mitchellbosecke.pebble.template.PebbleTemplate; //导入方法依赖的package包/类
@Override
public Object apply(Object inputObject, Map<String, Object> args, PebbleTemplate self, EvaluationContext context, int lineNumber) throws PebbleException {
if (inputObject == null || inputObject instanceof SafeString) {
return inputObject;
}
String input = StringUtils.toString(inputObject);
String strategy = defaultStrategy;
if (args.get("strategy") != null) {
strategy = (String) args.get("strategy");
}
if (!strategies.containsKey(strategy)) {
throw new PebbleException(null, String.format("Unknown escaping strategy [%s]", strategy), lineNumber, self.getName());
}
return new SafeString(strategies.get(strategy).escape(input));
}
示例3: apply
import com.mitchellbosecke.pebble.template.PebbleTemplate; //导入方法依赖的package包/类
@Override
public Object apply(Object input, Map<String, Object> args, PebbleTemplate self, EvaluationContext context, int lineNumber)
throws PebbleException {
if (input == null) {
return null;
}
if (input instanceof String) {
String inputString = (String) input;
return inputString.charAt(0);
}
if (input.getClass().isArray()) {
int length = Array.getLength(input);
return length > 0 ? Array.get(input, 0) : null;
} else if (input instanceof Collection) {
Collection<?> inputCollection = (Collection<?>) input;
return inputCollection.iterator().next();
} else {
throw new PebbleException(null,
"The 'first' filter expects that the input is either a collection, an array or a string.",
lineNumber, self.getName());
}
}
示例4: apply
import com.mitchellbosecke.pebble.template.PebbleTemplate; //导入方法依赖的package包/类
@Override
public Object apply(Object input, Map<String, Object> args, PebbleTemplate self, EvaluationContext context, int lineNumber) throws PebbleException {
Object items = args.get("items");
if (input == null && items == null) {
throw new PebbleException(null, "The two arguments to be merged are null", lineNumber, self.getName());
} else if (input != null && items == null) {
return input;
} else if (items != null && input == null) {
return items;
}
// left hand side argument defines resulting type
if (input instanceof Map) {
return mergeAsMap((Map<?, ?>) input, items);
} else if (input instanceof List) {
return mergeAsList((List<?>) input, items, lineNumber, self);
} else if (input.getClass().isArray()) {
return mergeAsArray(input, items, lineNumber, self);
} else {
throw new PebbleException(null, "The object being filtered is not a Map/List/Array", lineNumber, self.getName());
}
}
示例5: apply
import com.mitchellbosecke.pebble.template.PebbleTemplate; //导入方法依赖的package包/类
@Override
public Object apply(Object input, Map<String, Object> args, PebbleTemplate self, EvaluationContext context, int lineNumber) throws PebbleException{
if (input == null) {
return null;
}
if (!(input instanceof Number)) {
throw new PebbleException(null, "The input for the 'NumberFormat' filter has to be a number.", lineNumber, self.getName());
}
Number number = (Number) input;
Locale locale = context.getLocale();
if (args.get("format") != null) {
Format format = new DecimalFormat((String) args.get("format"), new DecimalFormatSymbols(locale));
return format.format(number);
} else {
NumberFormat numberFormat = NumberFormat.getInstance(locale);
return numberFormat.format(number);
}
}
示例6: apply
import com.mitchellbosecke.pebble.template.PebbleTemplate; //导入方法依赖的package包/类
@Override
public String apply(Object input, Map<String, Object> args, PebbleTemplate self, EvaluationContext context, int lineNumber) throws PebbleException{
if (input == null) {
return null;
}
if (!(input instanceof List)) {
throw new PebbleException(null, "The 'listToString' filter expects that the input to be a list.", lineNumber, self.getName());
}
List<?> inputList = (List<?>)input;
StringBuilder result = new StringBuilder("[");
for (int i = 0; i < inputList.size(); i++) {
if (i > 0) result.append(",");
result.append(inputList.get(i));
}
result.append("]");
return result.toString();
}
示例7: apply
import com.mitchellbosecke.pebble.template.PebbleTemplate; //导入方法依赖的package包/类
@Override
public boolean apply(Object input, Map<String, Object> args, PebbleTemplate self, EvaluationContext context, int lineNumber) throws PebbleException {
if (input == null) {
throw new PebbleException(null, "Can not pass null value to \"even\" test.", lineNumber, self.getName());
}
if (input instanceof Integer) {
return ((Integer) input) % 2 == 0;
} else {
return ((Long) input) % 2 == 0;
}
}
示例8: mergeAsArray
import com.mitchellbosecke.pebble.template.PebbleTemplate; //导入方法依赖的package包/类
private Object mergeAsArray(Object arg1, Object arg2, int lineNumber, PebbleTemplate self) throws PebbleException{
Class<?> arg1Class = arg1.getClass().getComponentType();
Class<?> arg2Class = arg2.getClass().getComponentType();
if (!arg1Class.equals(arg2Class)) {
throw new PebbleException(null,
"Currently, only Arrays of the same component class can be merged. Arg1: " + arg1Class.getName()
+ ", Arg2: " + arg2Class.getName(), lineNumber, self.getName());
}
Object output = Array.newInstance(arg1Class, Array.getLength(arg1) + Array.getLength(arg2));
System.arraycopy(arg1, 0, output, 0, Array.getLength(arg1));
System.arraycopy(arg2, 0, output, Array.getLength(arg1), Array.getLength(arg2));
return output;
}
示例9: apply
import com.mitchellbosecke.pebble.template.PebbleTemplate; //导入方法依赖的package包/类
@Override
public Number apply(Object input, Map<String, Object> args, PebbleTemplate self, EvaluationContext context, int lineNumber)
throws PebbleException {
if (input == null) {
throw new PebbleException(null, "Can not pass null value to \"abs\" filter.", lineNumber, self.getName());
}
if (input instanceof Integer) {
return Math.abs((Integer) input);
} else if (input instanceof Byte) {
return Math.abs((Byte) input);
} else if (input instanceof Short) {
return Math.abs((Short) input);
} else if (input instanceof Float) {
return Math.abs((Float) input);
} else if (input instanceof Long) {
return Math.abs((Long) input);
} else if (input instanceof Double) {
return Math.abs((Double) input);
} else if (input instanceof BigDecimal) {
return ((BigDecimal) input).abs();
} else if (input instanceof BigInteger) {
return ((BigInteger) input).abs();
} else if (input instanceof Number) {
// We make here an assumption that we have checked all special
// cases.
return Math.abs(((Number) input).doubleValue());
} else {
throw new PebbleException(null, "The 'abs' filter does require as input a number.", lineNumber,
self.getName());
}
}
示例10: apply
import com.mitchellbosecke.pebble.template.PebbleTemplate; //导入方法依赖的package包/类
@Override
public Object apply(Object input, Map<String, Object> args, PebbleTemplate self, EvaluationContext context, int lineNumber)
throws PebbleException {
if (input == null) {
return null;
}
String value = (String) input;
int maxWidth = ((Long) args.get("length")).intValue();
if (maxWidth < 0) {
throw new PebbleException(null, "Invalid argument to abbreviate filter; must be greater than zero",
lineNumber, self.getName());
}
String ellipsis = "...";
int length = value.length();
if (length < maxWidth) {
return value;
}
if (length <= 3) {
return value;
}
if (maxWidth <= 3) {
return value.substring(0, maxWidth);
}
return value.substring(0, Math.max(0, maxWidth - 3)) + ellipsis;
}
示例11: apply
import com.mitchellbosecke.pebble.template.PebbleTemplate; //导入方法依赖的package包/类
@Override
public Object apply(Object input, Map<String, Object> args, PebbleTemplate self, EvaluationContext context, int lineNumber)
throws PebbleException {
if (input == null) {
return null;
}
String glue = null;
if (args.containsKey("separator")) {
glue = (String) args.get("separator");
}
if (input.getClass().isArray()) {
List<Object> items = new ArrayList<>();
int length = Array.getLength(input);
for (int i = 0; i < length; i++) {
items.add(Array.get(input, i));
}
return join(items, glue);
}
else if (input instanceof Collection) {
return join((Collection<?>) input, glue);
} else {
throw new PebbleException(null,
"The 'join' filter expects that the input is either a collection or an array.", lineNumber,
self.getName());
}
}
示例12: applyTemporal
import com.mitchellbosecke.pebble.template.PebbleTemplate; //导入方法依赖的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());
}
}
示例13: apply
import com.mitchellbosecke.pebble.template.PebbleTemplate; //导入方法依赖的package包/类
@Override
public Object apply(Object input, Map<String, Object> args, PebbleTemplate self, EvaluationContext context, int lineNumber) throws PebbleException{
String data = input.toString();
if (args.get(ARGUMENT_NAME) == null) {
throw new PebbleException(null, MessageFormat.format("The argument ''{0}'' is required.", ARGUMENT_NAME), lineNumber, self.getName());
}
Map<?, ?> replacePair = (Map<?, ?>) args.get(ARGUMENT_NAME);
for (Entry<?, ?> entry : replacePair.entrySet()) {
data = data.replace(entry.getKey().toString(), entry.getValue().toString());
}
return data;
}
示例14: execute
import com.mitchellbosecke.pebble.template.PebbleTemplate; //导入方法依赖的package包/类
@Override
public Object execute(Map<String, Object> args, PebbleTemplate self, EvaluationContext context, int lineNumber) throws PebbleException {
Object start = args.get(PARAM_START);
Object end = args.get(PARAM_END);
Object increment = (Object) args.get(PARAM_INCREMENT);
if (increment == null) {
increment = 1L;
} else if (!(increment instanceof Number)) {
throw new PebbleException(null, "The increment of the range function must be a number " + increment,
lineNumber, self.getName());
}
Long incrementNum = ((Number) increment).longValue();
List<Object> results = new ArrayList<>();
// Iterating over Number
if (start instanceof Number && end instanceof Number) {
Long startNum = ((Number) start).longValue();
Long endNum = ((Number) end).longValue();
if (incrementNum > 0) {
for (Long i = startNum; i <= endNum; i += incrementNum) {
results.add(i);
}
} else if (incrementNum < 0) {
for (Long i = startNum; i >= endNum; i += incrementNum) {
results.add(i);
}
} else {
throw new PebbleException(null, "The increment of the range function must be different than 0",
lineNumber, self.getName());
}
}
// Iterating over character
else if (start instanceof String && end instanceof String) {
String startStr = (String) start;
String endStr = (String) end;
if (startStr.length() != 1 || endStr.length() != 1) {
throw new PebbleException(null, "Arguments of range function must be of type Number or String with "
+ "a length of 1", lineNumber, self.getName());
}
char startChar = startStr.charAt(0);
char endChar = endStr.charAt(0);
if (incrementNum > 0) {
for (int i = startChar; i <= endChar; i += incrementNum) {
results.add((char) i);
}
} else if (incrementNum < 0) {
for (int i = startChar; i >= endChar; i += incrementNum) {
results.add((char) i);
}
} else {
throw new PebbleException(null, "The increment of the range function must be different than 0",
lineNumber, self.getName());
}
} else {
throw new PebbleException(null, "Arguments of range function must be of type Number or String with a "
+ "length of 1", lineNumber, self.getName());
}
return results;
}