/** * Return a string that tells the current location of this node. */ protected String getLocation(InternalContextAdapter context) { return StringUtils.formatFileString(this); }
/** * @see Exception#getMessage() * @since 1.5 */ public String getMessage() { StringBuilder message = new StringBuilder(); message.append(super.getMessage()); message.append(" at "); message.append(StringUtils.formatFileString(templateName, lineNumber, columnNumber)); return message.toString(); } }
/** * Check whether the number of arguments given matches the number defined. */ protected void checkArgumentCount(Node node, int callArgNum) { // Check if we have more calling arguments then the macro accepts if (callArgNum > macroArgs.size() - 1) { if (strictArguments) { throw new VelocityException("Provided " + callArgNum + " arguments but macro #" + macroArgs.get(0).name + " accepts at most " + (macroArgs.size()-1) + " at " + StringUtils.formatFileString(node)); } // Backward compatibility logging, Mainly for MacroForwardDefinedTestCase log.debug("VM #{}: too many arguments to macro. Wanted {} got {}", macroArgs.get(0).name, macroArgs.size() - 1, callArgNum); } }
/** * @param sb */ protected void appendTemplateInfo(final StringBuilder sb) { sb.append(StringUtils.formatFileString(getTemplateName(), getLineNumber(), getColumnNumber())); sb.append(eol); } }
public boolean compareNonNumber(Object left, Object right) { // by default, log and bail String msg = (right instanceof Number ? "Left" : "Right") + " side of comparison operation is not a number at " + StringUtils.formatFileString(this); if (rsvc.getBoolean(RuntimeConstants.RUNTIME_REFERENCES_STRICT, false)) { throw new VelocityException(msg); } log.error(msg); return false; }
/** * @param sb * @since 1.5 */ protected void appendTemplateInfo(final StringBuilder sb) { sb.append(StringUtils.formatFileString(getTemplateName(), getLineNumber(), getColumnNumber())); sb.append(eol); } }
/** * Render the AST of this block into the writer using the context. */ public boolean render(InternalContextAdapter context, Writer writer) { depth++; if (depth > parent.maxDepth) { /* this is only a debug message, as recursion can * happen in quasi-innocent situations and is relatively * harmless due to how we handle it here. * this is more to help anyone nuts enough to intentionally * use recursive block definitions and having problems * pulling it off properly. */ parent.log.debug("Max recursion depth reached for {} at {}", parent.id(context), StringUtils.formatFileString(parent)); depth--; return false; } else { parent.render(context, writer); depth--; return true; } }
out.append(" at ").append(StringUtils.formatFileString(this)); log.error(out.toString());
/** * Creates a string that formats the template filename with line number * and column of the given Directive. We use this routine to provide a consistent format for displaying * file errors. */ public static String formatFileString(Directive directive) { return formatFileString(directive.getTemplateName(), directive.getLine(), directive.getColumn()); }
/** * Formats a textual representation of this object as <code>SOURCE * [line X, column Y]</code>. * * @return String representing this object. * @since 1.5 */ public String toString() { return StringUtils.formatFileString(getTemplateName(), getLine(), getColumn()); } }
/** * Creates a string that formats the template filename with line number * and column of the given Node. We use this routine to provide a consistent format for displaying * file errors. */ public static String formatFileString(Node node) { return formatFileString(node.getTemplateName(), node.getLine(), node.getColumn()); }
/** * Simply creates a string that formats the template filename with line number * and column. We use this routine to provide a consistent format for displaying * file errors. */ public static String formatFileString(Info info) { return formatFileString(info.getTemplateName(), info.getLine(), info.getColumn()); }
+ node.literal() + " at " + StringUtils.formatFileString(node); log.error(msg, ee); throw new VelocityException(msg, ee); + StringUtils.formatFileString(node) + " is of type " + iterable.getClass().getName() + " and cannot be iterated by " + rsvc.getUberspect().getClass().getName(); log.error(msg);
/** * Always false by default, != and == subclasses must override this. */ public boolean compareNull(Object left, Object right) { // if either side is null, log and bail String msg = (left == null ? "Left" : "Right") + " side (" + jjtGetChild( (left == null? 0 : 1) ).literal() + ") of comparison operation has null value at " + StringUtils.formatFileString(this); if (rsvc.getBoolean(RuntimeConstants.RUNTIME_REFERENCES_STRICT, false)) { throw new VelocityException(msg); } log.error(msg); return false; }
variable, StringUtils.formatFileString(uberInfo)); throw e; variable, StringUtils.formatFileString(uberInfo)); throw new MethodInvocationException("Variable $" + variable + " has not been set", null, identifier,
public boolean render(InternalContextAdapter context, Writer writer) { preRender(context); try { return block.render(context, writer); } catch (IOException e) { String msg = "Failed to render " + id(context) + " to writer at " + StringUtils.formatFileString(this); log.error(msg, e); throw new RuntimeException(msg, e); } catch (StopCommand stop) { if (!stop.isFor(this)) { throw stop; } return true; } finally { postRender(context); } }
+ (argument == null ? "null" : argument.getClass().getName()) + ")' in " + o.getClass().getName() + " at " + StringUtils.formatFileString(this); log.error(msg, e); throw new VelocityException(msg, e);
/** * Computes boolean value of this reference * Returns the actual value of reference return type * boolean, and 'true' if value is not null * * @param context context to compute value with * @return True if evaluation was ok. * @throws MethodInvocationException */ public boolean evaluate(InternalContextAdapter context) throws MethodInvocationException { Object value = execute(this, context); // non-null object as first parameter by convention for 'evaluate' if (value == null) { return false; } try { return DuckType.asBoolean(value, checkEmpty); } catch(Exception e) { throw new VelocityException("Reference evaluation threw an exception at " + StringUtils.formatFileString(this), e); } }
/** * This directive throws a StopCommand which signals either * the nearest Scope or the specified scope to stop rendering * its content. * @return never, always throws a StopCommand or Exception */ public boolean render(InternalContextAdapter context, Writer writer, Node node) { if (!scoped) { throw new StopCommand(); } Object argument = node.jjtGetChild(0).value(context); if (argument instanceof Scope) { ((Scope)argument).stop(); throw new IllegalStateException("Scope.stop() failed to throw a StopCommand"); } else { throw new VelocityException(node.jjtGetChild(0).literal()+ " is not a valid " + Scope.class.getName() + " instance at " + StringUtils.formatFileString(this)); } }
/** * simple init - get the key */ public void init(RuntimeServices rs, InternalContextAdapter context, Node node) throws TemplateInitException { super.init(rs, context, node); // the first child is the block name (key), the second child is the block AST body if ( node.jjtGetNumChildren() != 2 ) { throw new VelocityException("parameter missing: block name at " + StringUtils.formatFileString(this)); } /* * first token is the name of the block. We don't even check the format, * just assume it looks like this: $block_name. Should we check if it has * a '$' or not? */ key = node.jjtGetChild(0).getFirstTokenImage().substring(1); /* * default max depth of two is used because intentional recursion is * unlikely and discouraged, so make unintentional ones end fast */ maxDepth = rsvc.getInt(RuntimeConstants.DEFINE_DIRECTIVE_MAXDEPTH, 2); }