private String getStringOption(String optionName, TemplateModel value) throws TemplateModelException { if (!(value instanceof TemplateScalarModel)) { throw _MessageUtil.newMethodArgInvalidValueException(methodName, 1, "The value of the ", new _DelayedJQuote(optionName), " option must be a string, but it was ", new _DelayedAOrAn(new _DelayedFTLTypeDescription(value)), "."); } return EvalUtil.modelToString((TemplateScalarModel) value, null, null); }
/** * Used for some backward compatibility hacks. */ MixedContent asMixedContent() { MixedContent mixedContent = new MixedContent(); if (count != 0) { TemplateElement first = buffer[0]; mixedContent.setChildren(this); mixedContent.setLocation(first.getTemplate(), first, getLast()); } return mixedContent; }
private static FMParserTokenManager readerToTokenManager(Reader reader, ParserConfiguration pCfg) { SimpleCharStream simpleCharStream = new SimpleCharStream(reader, 1, 1); simpleCharStream.setTabSize(pCfg.getTabSize()); return new FMParserTokenManager(simpleCharStream); }
public static TemplateException newCantFormatNumberException(TemplateNumberFormat format, Expression dataSrcExp, TemplateValueFormatException e, boolean useTempModelExc) { _ErrorDescriptionBuilder desc = new _ErrorDescriptionBuilder( "Failed to format number with format ", new _DelayedJQuote(format.getDescription()), ": ", e.getMessage()) .blame(dataSrcExp); return useTempModelExc ? new _TemplateModelException(e, (Environment) null, desc) : new _MiscTemplateException(e, (Environment) null, desc); }
public static TemplateException newCantFormatDateException(TemplateDateFormat format, Expression dataSrcExp, TemplateValueFormatException e, boolean useTempModelExc) { _ErrorDescriptionBuilder desc = new _ErrorDescriptionBuilder( "Failed to format date/time/datetime with format ", new _DelayedJQuote(format.getDescription()), ": ", e.getMessage()) .blame(dataSrcExp); return useTempModelExc ? new _TemplateModelException(e, (Environment) null, desc) : new _MiscTemplateException(e, (Environment) null, desc); }
private Object parse(TemplateDateFormat df) throws TemplateModelException { try { return df.parse(text, dateType); } catch (TemplateValueFormatException e) { throw new _TemplateModelException(e, "The string doesn't match the expected date/time/date-time format. " + "The string to parse was: ", new _DelayedJQuote(text), ". ", "The expected format was: ", new _DelayedJQuote(df.getDescription()), ".", e.getMessage() != null ? "\nThe nested reason given follows:\n" : "", e.getMessage() != null ? e.getMessage() : ""); } }
@Override TemplateElement[] accept(Environment env) throws TemplateException { if (exp != null) { env.setLastReturnValue(exp.eval(env)); } if (nextSibling() == null && getParentElement() instanceof Macro) { // Avoid unnecessary exception throwing return null; } throw Return.INSTANCE; }
@Override void setLocation(Template template, int beginColumn, int beginLine, int endColumn, int endLine) { super.setLocation(template, beginColumn, beginLine, endColumn, endLine); if (isLiteral()) { try { constantValue = _eval(null); } catch (Exception e) { // deliberately ignore. } } }
@Override protected Expression deepCloneWithIdentifierReplaced_inner( String replacedIdentifier, Expression replacement, ReplacemenetState replacementState) { return new MethodCall( target.deepCloneWithIdentifierReplaced(replacedIdentifier, replacement, replacementState), (ListLiteral) arguments.deepCloneWithIdentifierReplaced(replacedIdentifier, replacement, replacementState)); }
@Override public TemplateModel get(String key) throws TemplateModelException { ensureInitializedTME(); return super.get(key); }
@Override TemplateModel _eval(Environment env) throws TemplateException { TemplateModel model = target.eval(env); if (model instanceof TemplateNodeModel) { return calculateResult((TemplateNodeModel) model, env); } else { throw new NonNodeException(target, model, env); } } abstract TemplateModel calculateResult(TemplateNodeModel nodeModel, Environment env)
@Override TemplateModel _eval(Environment env) throws TemplateException { TemplateModel model = target.eval(env); if (model instanceof TemplateNodeModelEx) { return calculateResult((TemplateNodeModelEx) model, env); } else { throw new NonExtendedNodeException(target, model, env); } } abstract TemplateModel calculateResult(TemplateNodeModelEx nodeModel, Environment env)
@Override TemplateModel _eval(Environment env) throws TemplateException { TemplateModel model = target.eval(env); if (!(model instanceof TemplateMarkupOutputModel)) { throw new NonMarkupOutputException(target, model, env); } return calculateResult((TemplateMarkupOutputModel) model); }
@Override TemplateModel _eval(Environment env) throws TemplateException { TemplateModel model = target.eval(env); if (!(model instanceof TemplateSequenceModel)) { throw new NonSequenceException(target, model, env); } return calculateResult((TemplateSequenceModel) model); } abstract TemplateModel calculateResult(TemplateSequenceModel tsm)
@Override public void putAll(Map m) { ensureInitializedRTE(); super.putAll(m); }
private int jjStartNfaWithStates_4(int pos, int kind, int state) { jjmatchedKind = kind; jjmatchedPos = pos; try { curChar = input_stream.readChar(); } catch(java.io.IOException e) { return pos + 1; } return jjMoveNfa_4(state, pos + 1); } private int jjMoveNfa_4(int startState, int curPos)
/** * Throw an exception if the expression passed in is a boolean Literal */ private void notBooleanLiteral(Expression exp, String expected) throws ParseException { if (exp instanceof BooleanLiteral) { throw new ParseException("Found: " + exp.getCanonicalForm() + ". Expecting " + expected, exp); } }
@Override TemplateElement[] accept(Environment env) throws TemplateException, IOException { if (condition == null || condition.evalToBoolean(env)) { return getChildBuffer(); } return null; }
/** * Detects the naming convention used, both in start- and end-tag tokens. * * @param charIdxInName * The index of the deciding character relatively to the first letter of the name. */ private static int getTagNamingConvention(Token tok, int charIdxInName) { return _CoreStringUtils.isUpperUSASCII(getTagNameCharAt(tok, charIdxInName)) ? Configuration.CAMEL_CASE_NAMING_CONVENTION : Configuration.LEGACY_NAMING_CONVENTION; }