@Override protected boolean isVisible( final ITemplateContext context, final IProcessableElementTag tag, final AttributeName attributeName, final String attributeValue) { final IStandardExpressionParser expressionParser = StandardExpressions.getExpressionParser(context.getConfiguration()); final IStandardExpression expression = expressionParser.parseExpression(context, attributeValue); final Object value = expression.execute(context); return EvaluationUtils.evaluateAsBoolean(value); }
public String createAbsentMessageRepresentation( final ITemplateContext context, final Class<?> origin, final String key, final Object[] messageParameters) { Validate.notNull(key, "Message key cannot be null"); if (context.getLocale() != null) { return "??"+key+"_" + context.getLocale().toString() + "??"; } return "??"+key+"_" + "??"; }
(StandardSwitchTagProcessor.SwitchStructure) context.getVariable(StandardSwitchTagProcessor.SWITCH_VARIABLE_NAME); throw new TemplateProcessingException( "Cannot specify a \"" + attributeName + "\" attribute in an environment where no " + "switch operator has been defined before."); new Object[] {TemplateEngine.threadIndex(), LoggingUtils.loggifyTemplateName(context.getTemplateData().getTemplate()), attributeValue, attributeName, attributeValue, Boolean.TRUE}); final IStandardExpressionParser expressionParser = StandardExpressions.getExpressionParser(context.getConfiguration()); expressionParser.parseExpression(context, attributeValue); new Object[] {TemplateEngine.threadIndex(), LoggingUtils.loggifyTemplateName(context.getTemplateData().getTemplate()), attributeValue, attributeName, attributeValue, Boolean.valueOf(visible)});
Validate.notNull(this.context, "Context cannot be null"); Validate.notNull(this.context.getTemplateMode(), "Template Mode returned by context cannot be null"); this.configuration = context.getConfiguration(); Validate.notNull(this.configuration, "Engine Configuration returned by context cannot be null"); Validate.notNull(this.configuration.getElementDefinitions(), "Element Definitions returned by the Engine Configuration cannot be null"); Validate.notNull(this.configuration.getAttributeDefinitions(), "Attribute Definitions returned by the Engine Configuration cannot be null"); this.templateMode = this.context.getTemplateMode(); // Just a way to avoid doing the call each time
final IElementTagStructureHandler structureHandler) { final IEngineConfiguration configuration = context.getConfiguration(); final IStandardExpressionParser expressionParser = StandardExpressions.getExpressionParser(configuration); final IStandardExpression expression = expressionParser.parseExpression(context, attributeValue); expressionResult = expression.execute(context, StandardExpressionExecutionContext.RESTRICTED); structureHandler.removeBody(); return; structureHandler.setBody(((Fragment)expressionResult).getTemplateModel(), false); return; structureHandler.setBody(unescapedTextStr, false); return; context.getTemplateData(), unescapedTextStr, 0, 0, // we won't apply offset here because the inserted text does not really come from the template itself
EscapedAttributeUtils.unescapeAttribute(context.getTemplateMode(), attribute.getValue()); final IStandardExpressionParser expressionParser = StandardExpressions.getExpressionParser(context.getConfiguration()); if (attributeValue != null) { final IStandardExpression expression = expressionParser.parseExpression(context, attributeValue); expressionResult = expression.execute(context, StandardExpressionExecutionContext.RESTRICTED); structureHandler.removeAttribute(attributeName); return; structureHandler.removeAttribute(newAttributeName); structureHandler.removeAttribute(attributeName); } else { if (!e.hasTemplateName()) { e.setTemplateName(tag.getTemplateName()); if (!e.hasLineAndCol()) { e.setLineAndCol(attribute.getLine(), attribute.getCol());
@Override protected final void doProcess( final ITemplateContext context, final IProcessableElementTag tag, final AttributeName attributeName, final String attributeValue, final IElementTagStructureHandler structureHandler) { final IStandardExpressionParser expressionParser = StandardExpressions.getExpressionParser(context.getConfiguration()); final IStandardExpression expression = expressionParser.parseExpression(context, attributeValue); validateSelectionValue(context, tag, attributeName, attributeValue, expression); final Object newSelectionTarget = expression.execute(context); final Map<String,Object> additionalLocalVariables = computeAdditionalLocalVariables(context, tag, attributeName, attributeValue, expression); if (additionalLocalVariables != null && additionalLocalVariables.size() > 0) { for (final Map.Entry<String,Object> variableEntry : additionalLocalVariables.entrySet()) { structureHandler.setLocalVariable(variableEntry.getKey(), variableEntry.getValue()); } } structureHandler.setSelectionTarget(newSelectionTarget); }
throw new TemplateProcessingException("Expression content is null, which is not allowed"); (useSelectionAsRoot && templateContext != null && templateContext.hasSelectionTarget()? templateContext.getSelectionTarget() : templateContext); StandardExpressions.getConversionService(configuration); throw new TemplateProcessingException( "Exception evaluating OGNL expression: \"" + expression.getExpression() + "\"", e);
public static Map<String, String> getExtraHiddenFields(final ITemplateContext context) { if (!canApply || !(context instanceof IWebContext)) { return null; } final RequestContext requestContext = (RequestContext) context.getVariable(SpringContextVariableNames.SPRING_REQUEST_CONTEXT); if (requestContext == null) { return null; } if (spring4Delegate != null) { return spring4Delegate.getExtraHiddenFields(requestContext, ((IWebContext)context).getRequest()); } throw new TemplateProcessingException( "According to the detected Spring version info, a RequestDataValueProcessor delegate should be available, " + "but none seem applicable"); }
@Override protected void doProcess( final ITemplateContext context, final IProcessableElementTag tag, final AttributeName attributeName, final String attributeValue, final IElementTagStructureHandler structureHandler) { final IStandardExpressionParser expressionParser = StandardExpressions.getExpressionParser(context.getConfiguration()); final IStandardExpression switchExpression = expressionParser.parseExpression(context, attributeValue); structureHandler.setLocalVariable(SWITCH_VARIABLE_NAME, new SwitchStructure(switchExpression)); }
throw new TemplateProcessingException("Fragment specifications cannot be empty"); final IEngineConfiguration configuration = context.getConfiguration(); structureHandler.removeElement(); } else { structureHandler.removeBody(); throw new TemplateProcessingException( "Fragment '" + attributeValue + "' specifies synthetic (unnamed) parameters, but the resolved fragment " + "does not match a fragment signature (th:fragment,data-th-fragment) which could apply names to " + if (context.getTemplateMode() != fragmentModel.getTemplateMode()) { throw new TemplateProcessingException( "Template being processed uses template mode " + context.getTemplateMode() + ", " + "inserted fragment \"" + attributeValue + "\" uses template mode " + fragmentModel.getTemplateMode() + ". Cross-template-mode fragment insertion is not " + structureHandler.replaceWith(stringWriter.toString(), false); } else { structureHandler.setBody(stringWriter.toString(), false);
private static IStandardExpression parseAttributeExpression(final ITemplateContext context, final String attributeValue) { final IStandardExpressionParser expressionParser = StandardExpressions.getExpressionParser(context.getConfiguration()); return expressionParser.parseExpression(context, attributeValue); }
@Override protected IInliner getInliner(final ITemplateContext context, final StandardInlineMode inlineMode) { switch (inlineMode) { case NONE: return NoOpInliner.INSTANCE; case XML: return new StandardXMLInliner(context.getConfiguration()); case TEXT: return new StandardTextInliner(context.getConfiguration()); default: throw new TemplateProcessingException( "Invalid inline mode selected: " + inlineMode + ". Allowed inline modes in template mode " + getTemplateMode() + " are: " + "\"" + StandardInlineMode.XML + "\", \"" + StandardInlineMode.TEXT + "\", " + "\"" + StandardInlineMode.NONE + "\""); } }
public final String resolveMessage( final ITemplateContext context, final Class<?> origin, final String key, final Object[] messageParameters) { Validate.notNull(context.getLocale(), "Locale in context cannot be null"); Validate.notNull(key, "Message key cannot be null"); "[THYMELEAF][{}] Resolving message with key \"{}\" for template \"{}\" and locale \"{}\". " + "Messages will be retrieved from Spring's MessageSource infrastructure.", new Object[]{TemplateEngine.threadIndex(), key, context.getTemplateData().getTemplate(), context.getLocale()}); return this.messageSource.getMessage(key, messageParameters, context.getLocale()); } catch (NoSuchMessageException e) {
StandardExpressions.getExpressionParser(context.getConfiguration());
expressionResult = expression.execute(context, StandardExpressionExecutionContext.RESTRICTED_FORBID_UNSAFE_EXP_RESULTS); final TemplateManager templateManager = context.getConfiguration().getTemplateManager(); context.getTemplateData(), attributeValue, attribute.getLine(), attribute.getCol(), TemplateMode.JAVASCRIPT, true); structureHandler.removeAttribute(attributeName); return;
EscapedAttributeUtils.unescapeAttribute(context.getTemplateMode(), firstEvent.getAttributeValue(attributeName)); if (firstEventLocation >= 0) { firstEvent = (IProcessableElementTag) model.get(firstEventLocation); final IModelFactory modelFactory = context.getModelFactory(); final IProcessableElementTag newFirstEvent = modelFactory.removeAttribute(firstEvent,attributeName); if (newFirstEvent != firstEvent) { if (!e.hasTemplateName()) { e.setTemplateName(attributeTemplateName); if (!e.hasLineAndCol()) { e.setLineAndCol(attributeLine, attributeCol);
private CharSequence inlineSwitchTemplateMode(final ITemplateContext context, final IText text) { final TemplateManager templateManager = context.getConfiguration().getTemplateManager(); final TemplateModel templateModel = templateManager.parseString( context.getTemplateData(), text.getText(), text.getLine(), text.getCol(), this.templateMode, true); if (!this.writeTextsToOutput) { final Writer stringWriter = new FastStringWriter(50); templateManager.process(templateModel, context, stringWriter); return stringWriter.toString(); } // If we can directly write to output (and text is an IText), we will use a LazyProcessingCharSequence return new LazyProcessingCharSequence(context, templateModel); }
public String seq(final Object id) { Validate.notNull(id, "ID cannot be null"); final String str = id.toString(); return str + this.context.getIdentifierSequences().getAndIncrementIDSeq(str); }
@Override protected void doProcess(ITemplateContext context, IProcessableElementTag tag, AttributeName attributeName, String attributeValue, IElementTagStructureHandler structureHandler) { Locale locale = context.getLocale(); loadSelectorValues(locale); String selectorStyle = String.valueOf(attributeValue).trim(); String messageKey = getMessageKey(selectorStyle); String options = composeSelectorOptions(selectorStyle, context); String message = Messages.getMessage(BUNDLE_NAME, messageKey, locale, options); structureHandler.setBody(message, false); }