private void execute(Writer writer, Callable callable) throws Exception { Object call = callable.call(); execute(writer, call == null ? null : oh.stringify(call)); }
public static Object unwrap(ObjectHandler oh, int scopeIndex, Wrapper[] wrappers, List<Object> scopes) throws GuardException { Object scope = oh.coerce(scopes.get(scopeIndex)); // The value may be buried by . notation if (wrappers != null) { for (Wrapper wrapper : wrappers) { scope = oh.coerce(wrapper.call(ObjectHandler.makeList(scope))); } } return scope; }
public DefaultCode(TemplateContext tc, DefaultMustacheFactory df, Mustache mustache, String name, String type) { this.df = df; this.oh = df == null ? null : df.getObjectHandler(); this.mustache = mustache; this.type = type; this.name = name; this.tc = tc; this.binding = oh == null ? null : oh.createBinding(name, tc, this); this.returnThis = ".".equals(name); }
/** * Execute the mustache object with a given writer and a single scope context. * * @param writer write the output of the executed template here * @param scope the root object to use * @return the new writer */ default Writer execute(Writer writer, Object scope) { return execute(writer, makeList(scope)); }
private Object createAndGet(List<Object> scopes) { // Make a new wrapper for this set of scopes and add it to the set Wrapper wrapper = getWrapper(name, scopes); previousSet.add(wrapper); if (prevWrappers == null || prevWrappers.length != previousSet.size()) { prevWrappers = previousSet.toArray(EMPTY_WRAPPERS); } // If this fails the guard, there is a bug try { return oh.coerce(wrapper.call(scopes)); } catch (GuardException e) { throw new GuardException("BUG: Unexpected guard failure: " + name + " " + previousSet + " " + singletonList(scopes)); } }
@Override protected Writer execute(Writer writer, Object resolve, List<Object> scopes) { return oh.falsey(this, writer, resolve, scopes); }
protected synchronized Wrapper getWrapper(String name, List<Object> scopes) { Wrapper wrapper = oh.find(name, scopes); if (wrapper instanceof MissingWrapper) { if (debug) { // Ugly but generally not interesting if (!(code instanceof PartialCode)) { logWarning("Failed to find: ", name, scopes, tc); } } } return wrapper; }
protected Writer execute(Writer writer, Object resolve, List<Object> scopes) { return oh.iterate(this, writer, resolve, scopes); }
@Override public boolean apply(List<Object> objects) { Object scope = unwrap(oh, index, wrappers, objects); for (Guard predicate : wrapperGuard) { if (!predicate.apply(makeList(scope))) { return false; } } return true; }
try { current = prevWrapper; return oh.coerce(prevWrapper.call(scopes)); } catch (GuardException ge) {
@Override protected Writer execute(Writer writer, Object resolve, List<Object> scopes) { return oh.falsey(this, writer, resolve, scopes); }
protected synchronized Wrapper getWrapper(String name, List<Object> scopes) { Wrapper wrapper = oh.find(name, scopes); if (wrapper instanceof MissingWrapper) { if (debug) { // Ugly but generally not interesting if (!(code instanceof PartialCode)) { logWarning("Failed to find: ", name, scopes, tc); } } } return wrapper; }
protected Writer execute(Writer writer, Object resolve, List<Object> scopes) { return oh.iterate(this, writer, resolve, scopes); }
@Override public Writer execute(Writer writer, final List<Object> scopes) { try { final Object object = get(scopes); if (object != null) { if (object instanceof Function) { handleFunction(writer, (Function) object, scopes); } else if (object instanceof Callable) { return handleCallable(writer, (Callable) object, scopes); } else { execute(writer, oh.stringify(object)); } } return super.execute(writer, scopes); } catch (Exception e) { throw new MustacheException("Failed to get value for " + name, e, tc); } }
public static Object unwrap(ObjectHandler oh, int scopeIndex, Wrapper[] wrappers, List<Object> scopes) throws GuardException { Object scope = oh.coerce(scopes.get(scopeIndex)); // The value may be buried by . notation if (wrappers != null) { for (Wrapper wrapper : wrappers) { scope = oh.coerce(wrapper.call(ObjectHandler.makeList(scope))); } } return scope; }
@Override public Object call(List<Object> scopes) throws GuardException { guardCall(scopes); Object scope = oh.coerce(unwrap(scopes)); try { if (scope == null) return null; if (method == null) { return field.get(scope); } else { return method.invoke(scope, arguments); } } catch (IllegalArgumentException | IllegalAccessException e) { throw new MustacheException("Error accessing " + getTargetDescription() + " on " + elementToString(scope) + ", scope: [" + elementsToString(scopes, scopeIndex) + "]" + ", guards: " + Arrays.toString(guards), e); } catch (InvocationTargetException e) { throw new MustacheException("Error invoking " + getTargetDescription() + " on " + elementToString(scope), e.getTargetException()); } catch (Exception e) { throw new MustacheException("Error invoking " + getTargetDescription() + " on " + elementToString(scope), e); } }
@Override protected Writer execute(Writer writer, Object resolve, List<Object> scopes) { return oh.falsey(this, writer, resolve, scopes); }
public DefaultCode(TemplateContext tc, DefaultMustacheFactory df, Mustache mustache, String name, String type) { this.df = df; this.oh = df == null ? null : df.getObjectHandler(); this.mustache = mustache; this.type = type; this.name = name; this.tc = tc; this.binding = oh == null ? null : oh.createBinding(name, tc, this); this.returnThis = ".".equals(name); }
protected synchronized Wrapper getWrapper(String name, List<Object> scopes) { Wrapper wrapper = oh.find(name, scopes); if (wrapper instanceof MissingWrapper) { if (debug) { // Ugly but generally not interesting if (!(code instanceof PartialCode)) { logWarning("Failed to find: ", name, scopes, tc); } } } return wrapper; }