return value; } catch (Exception e) { throw new MustacheException.Context( "Failure fetching variable '" + name + "' on line " + line, name, line, e);
return value; } catch (Exception e) { throw new MustacheException.Context( "Failure fetching variable '" + name + "' on line " + line, name, line, e);
/** * Decomposes the compound key {@code name} into components and resolves the value they * reference. */ protected Object getCompoundValue (Context ctx, String name, int line, boolean missingIsNull) { String[] comps = name.split("\\."); // we want to allow the first component of a compound key to be located in a parent // context, but once we're selecting sub-components, they must only be resolved in the // object that represents that component Object data = getValue(ctx, comps[0].intern(), line, missingIsNull); for (int ii = 1; ii < comps.length; ii++) { if (data == NO_FETCHER_FOUND) { if (!missingIsNull) throw new MustacheException.Context( "Missing context for compound variable '" + name + "' on line " + line + ". '" + comps[ii - 1] + "' was not found.", name, line); return null; } else if (data == null) { return null; } // once we step into a composite key, we drop the ability to query our parent contexts; // that would be weird and confusing data = getValueIn(data, comps[ii].intern(), line); } return checkForMissing(name, line, missingIsNull, data); }
@Override public void execute (Template tmpl, Template.Context ctx, Writer out) { Object value = tmpl.getValueOrDefault(ctx, _name, _line); if (value == null) { throw new MustacheException.Context("No key, method or field with name '" + _name + "' on line " + _line, _name, _line); } write(out, _escaper.escape(_formatter.format(value))); } @Override public void decompile (Delims delims, StringBuilder into) {
protected Object checkForMissing (String name, int line, boolean missingIsNull, Object value) { if (value == NO_FETCHER_FOUND) { if (missingIsNull) return null; throw new MustacheException.Context( "No method or field with name '" + name + "' on line " + line, name, line); } else { return value; } }
private static RuntimeException handleError( final ResourcePath view, final MustacheException.Context e ) { return ProblemException.newBuilder(). lineNumber( e.lineNo ). path( view ). cause( e ). message( e.getMessage() ). build(); } }
/** * Decomposes the compound key {@code name} into components and resolves the value they * reference. */ protected Object getCompoundValue (Context ctx, String name, int line, boolean missingIsNull) { String[] comps = name.split("\\."); // we want to allow the first component of a compound key to be located in a parent // context, but once we're selecting sub-components, they must only be resolved in the // object that represents that component Object data = getValue(ctx, comps[0], line, missingIsNull); for (int ii = 1; ii < comps.length; ii++) { if (data == NO_FETCHER_FOUND) { if (!missingIsNull) throw new MustacheException.Context( "Missing context for compound variable '" + name + "' on line " + line + ". '" + comps[ii - 1] + "' was not found.", name, line); return null; } else if (data == null) { return null; } // once we step into a composite key, we drop the ability to query our parent contexts; // that would be weird and confusing data = getValueIn(data, comps[ii], line); } return checkForMissing(name, line, missingIsNull, data); }
protected Object checkForMissing (String name, int line, boolean missingIsNull, Object value) { if (value == NO_FETCHER_FOUND) { if (missingIsNull) return null; throw new MustacheException.Context( "No method or field with name '" + name + "' on line " + line, name, line); } else { return value; } }
@Override public void execute (Template tmpl, Template.Context ctx, Writer out) { Object value = tmpl.getValueOrDefault(ctx, _name, _line); if (value == null) { String msg = Template.isThisName(_name) ? "Resolved '.' to null (which is disallowed), on line " + _line : "No key, method or field with name '" + _name + "' on line " + _line; throw new MustacheException.Context(msg, _name, _line); } write(out, _escaper.escape(_formatter.format(value))); } @Override public void decompile (Delims delims, StringBuilder into) {