/** * Returns the value of the specified variable, noting that it is intended to be used as the * contents for a section. */ protected Object getSectionValue (Context ctx, String name, int line) { Object value = getValue(ctx, name, line, !_compiler.strictSections); // TODO: configurable behavior on null values? return (value == null) ? Collections.emptyList() : value; }
/** * 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); }
/** * 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); }
/** * Returns the value for the specified variable, or the configured default value if the * variable resolves to null. See {@link #getValue}. */ protected Object getValueOrDefault (Context ctx, String name, int line) { Object value = getValue(ctx, name, line, _compiler.missingIsNull); // getValue will raise MustacheException if a variable cannot be resolved and missingIsNull // is not configured; so we're safe to assume that any null that makes it up to this point // can be converted to nullValue return (value == null) ? _compiler.computeNullValue(name) : value; }
/** * Returns the value of the specified variable, noting that it is intended to be used as the * contents for a section. */ protected Object getSectionValue (Context ctx, String name, int line) { Object value = getValue(ctx, name, line, !_compiler.strictSections); // TODO: configurable behavior on null values? return (value == null) ? Collections.emptyList() : value; }
/** * Returns the value for the specified variable, or the configured default value if the * variable resolves to null. See {@link #getValue}. */ protected Object getValueOrDefault (Context ctx, String name, int line) { Object value = getValue(ctx, name, line, _compiler.missingIsNull); // getValue will raise MustacheException if a variable cannot be resolved and missingIsNull // is not configured; so we're safe to assume that any null that makes it up to this point // can be converted to nullValue return (value == null) ? _compiler.computeNullValue(name) : value; }