@Override public void renderString(String templateContent, Map<String, Object> model, Writer writer) { String language = (String) model.get(PippoConstants.REQUEST_PARAMETER_LANG); if (StringUtils.isNullOrEmpty(language)) { language = getLanguageOrDefault(language); } // prepare the locale Locale locale = (Locale) model.get(PippoConstants.REQUEST_PARAMETER_LOCALE); if (locale == null) { locale = getLocaleOrDefault(language); } try { localeSupport.setCurrentLocale(locale); Mustache template = engine.compileMustache("StringTemplate", templateContent); template.render(writer, model); writer.flush(); } catch (Exception e) { if (e instanceof PippoRuntimeException) { throw (PippoRuntimeException) e; } throw new PippoRuntimeException(e); } finally { localeSupport.remove(); } }
@Override public void renderString(String templateContent, Map<String, Object> model, Writer writer) { String language = (String) model.get(PippoConstants.REQUEST_PARAMETER_LANG); if (StringUtils.isNullOrEmpty(language)) { language = getLanguageOrDefault(language); } // prepare the locale Locale locale = (Locale) model.get(PippoConstants.REQUEST_PARAMETER_LOCALE); if (locale == null) { locale = getLocaleOrDefault(language); } try { localeSupport.setCurrentLocale(locale); Mustache template = engine.compileMustache("StringTemplate", templateContent); template.render(writer, model); writer.flush(); } catch (Exception e) { if (e instanceof PippoRuntimeException) { throw (PippoRuntimeException) e; } throw new PippoRuntimeException(e); } finally { localeSupport.remove(); } }
private void processLambda(Appendable appendable, ExecutionContext context, Object value) { Lambda lambda = (Lambda) value; String input; switch (lambda.getInputType()) { case LITERAL: // Try to reconstruct the original text input = getContentLiteralBlock(); break; case PROCESSED: StringBuilder processed = new StringBuilder(); super.execute(processed, context); input = processed.toString(); break; default: throw new IllegalStateException("Unsupported lambda input type"); } String returnValue = lambda.invoke(input); if (lambda.isReturnValueInterpolated()) { // Parse and interpolate the return value Template temp = (Template) getEngine().compileMustache( Lambdas.constructLambdaOneoffTemplateName(this), returnValue); temp.getRootSegment().execute(appendable, context); } else { append(appendable, returnValue); } }
private void processLambda(Appendable appendable, ExecutionContext context, Object value) { Lambda lambda = (Lambda) value; String returnValue = lambda.invoke(null); if (returnValue == null) { Object replacement = getEngineConfiguration() .getMissingValueHandler().handle(getTagInfo()); if (replacement != null) { processValue(appendable, context, replacement); return; } } else if (!returnValue.equals(Strings.EMPTY)) { if (lambda.isReturnValueInterpolated()) { // Parse and interpolate the return value StringBuilder interpolated = new StringBuilder(); Template temp = (Template) getEngine().compileMustache( Lambdas.constructLambdaOneoffTemplateName(this), returnValue); temp.getRootSegment().execute(interpolated, context); writeValue(appendable, interpolated.toString()); } else { writeValue(appendable, returnValue); } } }