protected MustacheException valueNotAFormattableObject(Object value, MustacheTagInfo tagInfo) { return new MustacheException( MustacheProblem.RENDER_HELPER_INVALID_OPTIONS, "Value is not a formattable object [value: %s, template: %s, line: %s]", value, tagInfo.getTemplateName(), tagInfo.getLine()); }
@Override public Object handle(MustacheTagInfo info) { throw new MustacheException( MustacheProblem.RENDER_NO_VALUE, "No value for the given key found: %s [template: %s, line: %s]", info.getText(), info.getTemplateName(), info.getLine()); }
void release() { if (valueWrappers != null) { int wrappersSize = valueWrappers.size(); if (wrappersSize == 1) { valueWrappers.get(0).release(); } else if (wrappersSize > 1) { for (ValueWrapper wrapper : valueWrappers) { wrapper.release(); } } } if (pushed > 0) { LOGGER.info( "{} remaining objects pushed on the context stack will be automatically garbage collected [helperName: {}, template: {}]", pushed, splitHelperName(segment.getTagInfo().getText(), segment).next(), segment.getTagInfo().getTemplateName()); } }
@Override public void execute(Options options) { Map<String, Object> hash = options.getHash(); Object key = hash.get(KEY); Object guard = hash.get(GUARD); Object expire = hash.get(EXPIRE); Object unit = expire != null ? hash.get(UNIT) : null; StringBuilder fragmentKey = new StringBuilder(); fragmentKey.append(options.getTagInfo().getTemplateGeneratedId()); fragmentKey.append(options.getTagInfo().getId()); if (key != null) { fragmentKey.append(key.toString()); } Fragment fragment = fragments .get(new Key(fragmentKey.toString(), options)); if (fragment.getHits() > 0 && (isExpired(fragment, expire, unit) || isGuardCompromised(fragment, guard))) { fragment.update(getContent(options), guard); } fragment.touch(); options.append(fragment.getContent()); }
/** * * @param options * @return <code>true</code> if the underlying tag represents a section, * <code>false</code> otherwise */ public static boolean isSection(Options options) { return options.getTagInfo().getType().equals(MustacheTagType.SECTION); }
@Override public void validate(HelperDefinition definition) { super.validate(definition); Set<String> validNames = new HashSet<>(4); for (Entry<String, Helper> entry : configuration.getHelpers() .entrySet()) { if (entry.getValue() instanceof WhenHelper || entry.getValue() instanceof OtherwiseHelper) { validNames.add(entry.getKey()); } } for (MustacheTagInfo info : definition.getTagInfo().getChildTags()) { if (!isValid(info, validNames)) { LOGGER.warn( "Invalid content detected {}. This helper should only contain when and otherwise sections. Other types of segments are always rendered!", info); } } }
/** * * @param options * @return <code>true</code> if the underlying tag represents a variable * which shouldn't be escaped, <code>false</code> otherwise */ public static boolean isUnescapeVariable(Options options) { return options.getTagInfo().getType() .equals(MustacheTagType.UNESCAPE_VARIABLE); }
@Override public void validate(HelperDefinition definition) { super.validate(definition); Set<String> validNames = new HashSet<>(4); for (Entry<String, Helper> entry : configuration.getHelpers() .entrySet()) { if (entry.getValue() instanceof CaseHelper || entry.getValue() instanceof DefaultHelper) { validNames.add(entry.getKey()); } } for (MustacheTagInfo info : definition.getTagInfo().getChildTags()) { if (!isValid(info, validNames)) { LOGGER.warn( "Invalid content detected {}. This helper should only contain case and default sections. Other types of segments are always rendered!", info); } } }
protected MustacheException unknownStyle(String style, MustacheTagInfo tagInfo) { return new MustacheException( MustacheProblem.RENDER_HELPER_INVALID_OPTIONS, "Unknown style defined %s [template: %s, line: %s]", style, tagInfo.getTemplateName(), tagInfo.getLine()); }
public static MustacheException newInvalidFlowException(MustacheTagInfo tagInfo) { return new MustacheException( MustacheProblem.RENDER_HELPER_INVALID_OPTIONS, MESSAGE_INVALID_FLOW, tagInfo.getText(), tagInfo.getTemplateName(), tagInfo.getLine()); }
/** * * @param options * @return <code>true</code> if the underlying tag represents a variable, * <code>false</code> otherwise */ public static boolean isVariable(Options options) { return options.getTagInfo().getType().equals(MustacheTagType.VARIABLE) || isUnescapeVariable(options); }
public static MustacheException newValidationException(String msg, Class<? extends Helper> helperClazz, HelperDefinition definition) { return new MustacheException( MustacheProblem.COMPILE_HELPER_VALIDATION_FAILURE, msg + " [helper: %s, template: %s, line: %s]", helperClazz.getName(), definition.getTagInfo().getTemplateName(), definition.getTagInfo().getLine()); }
/** * * @param helperClazz * @param definition * @param allowedTypes * @throws MustacheException * If the helper tag type does not match any one of the * specified types */ public static void checkType(Class<? extends Helper> helperClazz, HelperDefinition definition, MustacheTagType... allowedTypes) { Checker.checkArgumentsNotNull(definition, allowedTypes); if (!Arrays.contains(allowedTypes, definition.getTagInfo().getType())) { throw newValidationException("Unsupported tag type", helperClazz, definition); } }
@Override public void validate(HelperDefinition definition) { super.validate(definition); if (definition.getParameters().size() == 1) { LOGGER.warn( "{} is not really useful for single parameter [template: {}, line: {}]", getClass().getSimpleName(), definition.getTagInfo().getTemplateName(), definition.getTagInfo().getLine()); } }
static BigDecimal getDecimal(Object value, Options options) { BigDecimal decimal; if (value instanceof BigDecimal) { decimal = (BigDecimal) value; } else if (value instanceof BigInteger) { decimal = new BigDecimal((BigInteger) value); } else if (value instanceof Long) { decimal = new BigDecimal((Long) value); } else if (value instanceof Integer) { decimal = new BigDecimal((Integer) value); } else if (value instanceof Double) { decimal = new BigDecimal((Double) value); } else if (value instanceof String) { decimal = new BigDecimal(value.toString()); } else { throw new MustacheException( MustacheProblem.RENDER_HELPER_INVALID_OPTIONS, "Parameter is not valid [param: %s, helper: %s, template: %s, line: %s]", value, NumericExpressionHelper.class.getName(), options.getTagInfo().getTemplateName(), options.getTagInfo().getLine()); } return decimal; }
@Override public void execute(Options options) { String message = options.getParameters().get(0).toString(); if (appendTemplateInfo) { StringBuilder builder = new StringBuilder(message); builder.append(" ["); builder.append(options.getTagInfo().getTemplateName()); builder.append(":"); builder.append(options.getTagInfo().getLine()); builder.append("]"); message = builder.toString(); } adapter.log(getLevel(options.getHash()), message, getMessageParams(options.getParameters())); }
"Cache fragment will not be automatically updated [helper: {}, template: {}, line: {}]", getClass().getName(), definition.getTagInfo().getTemplateName(), definition.getTagInfo().getLine());
/** * * @param helperClazz * @param definition * @param paramSize * @throws MustacheException * If the helper expects more params */ public static void checkParams(Class<? extends Helper> helperClazz, HelperDefinition definition, int paramSize) { Checker.checkArgumentNotNull(definition); Checker.checkArgument(paramSize >= 0, "Helper may only require zero or more params"); int size = definition.getParameters().size(); if (size < paramSize) { throw newValidationException(String.format( "Insufficient number of parameters - expected: %s, current: %s", paramSize, size), helperClazz, definition); } if (size > paramSize) { LOGGER.trace( "{} superfluous parameters detected [helper: {}, template: {}, line: {}]", size - paramSize, helperClazz.getName(), definition.getTagInfo().getTemplateName(), definition.getTagInfo().getLine()); } }