/** * <p> * Obtain the conversion service (implementation of {@link IStandardConversionService}) registered by * the Standard Dialect that is being currently used. * </p> * * @param configuration the configuration object for the current template execution environment. * @return the conversion service object. */ public static IStandardConversionService getConversionService(final IEngineConfiguration configuration) { final Object conversionService = configuration.getExecutionAttributes().get(STANDARD_CONVERSION_SERVICE_ATTRIBUTE_NAME); if (conversionService == null || (!(conversionService instanceof IStandardConversionService))) { throw new TemplateProcessingException( "No Standard Conversion Service has been registered as an execution argument. " + "This is a requirement for using Standard Expressions, and might happen " + "if neither the Standard or the SpringStandard dialects have " + "been added to the Template Engine and none of the specified dialects registers an " + "attribute of type " + IStandardConversionService.class.getName() + " with name " + "\"" + STANDARD_CONVERSION_SERVICE_ATTRIBUTE_NAME + "\""); } return (IStandardConversionService) conversionService; }
/** * <p> * Obtain the CSS serializer (implementation of {@link IStandardCSSSerializer}) registered by * the Standard Dialect that is being currently used. * </p> * * @param configuration the configuration object for the current template execution environment. * @return the variable expression evaluator object. */ public static IStandardCSSSerializer getCSSSerializer(final IEngineConfiguration configuration) { final Object serializer = configuration.getExecutionAttributes().get(STANDARD_CSS_SERIALIZER_ATTRIBUTE_NAME); if (serializer == null || (!(serializer instanceof IStandardCSSSerializer))) { throw new TemplateProcessingException( "No CSS Serializer has been registered as an execution argument. " + "This is a requirement for using Standard serialization, and might happen " + "if neither the Standard or the SpringStandard dialects have " + "been added to the Template Engine and none of the specified dialects registers an " + "attribute of type " + IStandardCSSSerializer.class.getName() + " with name " + "\"" + STANDARD_CSS_SERIALIZER_ATTRIBUTE_NAME + "\""); } return (IStandardCSSSerializer) serializer; }
/** * <p> * Obtain the expression parser (implementation of {@link IStandardExpressionParser}) registered by * the Standard Dialect that is being currently used. * </p> * * @param configuration the configuration object for the current template execution environment. * @return the parser object. */ public static IStandardExpressionParser getExpressionParser(final IEngineConfiguration configuration) { final Object parser = configuration.getExecutionAttributes().get(STANDARD_EXPRESSION_PARSER_ATTRIBUTE_NAME); if (parser == null || (!(parser instanceof IStandardExpressionParser))) { throw new TemplateProcessingException( "No Standard Expression Parser has been registered as an execution argument. " + "This is a requirement for using Standard Expressions, and might happen " + "if neither the Standard or the SpringStandard dialects have " + "been added to the Template Engine and none of the specified dialects registers an " + "attribute of type " + IStandardExpressionParser.class.getName() + " with name " + "\"" + STANDARD_EXPRESSION_PARSER_ATTRIBUTE_NAME + "\""); } return (IStandardExpressionParser) parser; }
/** * <p> * Obtain the JavaScript serializer (implementation of {@link IStandardJavaScriptSerializer}) registered by * the Standard Dialect that is being currently used. * </p> * * @param configuration the configuration object for the current template execution environment. * @return the parser object. */ public static IStandardJavaScriptSerializer getJavaScriptSerializer(final IEngineConfiguration configuration) { final Object serializer = configuration.getExecutionAttributes().get(STANDARD_JAVASCRIPT_SERIALIZER_ATTRIBUTE_NAME); if (serializer == null || (!(serializer instanceof IStandardJavaScriptSerializer))) { throw new TemplateProcessingException( "No JavaScript Serializer has been registered as an execution argument. " + "This is a requirement for using Standard serialization, and might happen " + "if neither the Standard or the SpringStandard dialects have " + "been added to the Template Engine and none of the specified dialects registers an " + "attribute of type " + IStandardJavaScriptSerializer.class.getName() + " with name " + "\"" + STANDARD_JAVASCRIPT_SERIALIZER_ATTRIBUTE_NAME + "\""); } return (IStandardJavaScriptSerializer) serializer; }
/** * <p> * Obtain the variable expression evaluator (implementation of {@link IStandardVariableExpressionEvaluator}) * registered by the Standard Dialect that is being currently used. * </p> * <p> * Normally, there should be no need to obtain this object from the developers' code (only internally from * {@link IStandardExpression} implementations). * </p> * * @param configuration the configuration object for the current template execution environment. * @return the variable expression evaluator object. */ public static IStandardVariableExpressionEvaluator getVariableExpressionEvaluator(final IEngineConfiguration configuration) { final Object expressionEvaluator = configuration.getExecutionAttributes().get(STANDARD_VARIABLE_EXPRESSION_EVALUATOR_ATTRIBUTE_NAME); if (expressionEvaluator == null || (!(expressionEvaluator instanceof IStandardVariableExpressionEvaluator))) { throw new TemplateProcessingException( "No Standard Variable Expression Evaluator has been registered as an execution argument. " + "This is a requirement for using Standard Expressions, and might happen " + "if neither the Standard or the SpringStandard dialects have " + "been added to the Template Engine and none of the specified dialects registers an " + "attribute of type " + IStandardVariableExpressionEvaluator.class.getName() + " with name " + "\"" + STANDARD_VARIABLE_EXPRESSION_EVALUATOR_ATTRIBUTE_NAME + "\""); } return (IStandardVariableExpressionEvaluator) expressionEvaluator; }
/** * <p> * Check whether compilation of Spring EL expressions should be enabled or not. * </p> * <p> * This is done through configuration methods at the {@link org.thymeleaf.spring4.dialect.SpringStandardDialect} * instance being used, and its value is offered to the engine as an <em>execution attribute</em>. * </p> * * @param configuration the configuration object for the current template execution environment. * @return {@code true} if the SpEL compiler should be enabled if available, {@code false} if not. */ public static boolean isSpringELCompilerEnabled(final IEngineConfiguration configuration) { final Object enableSpringELCompiler = configuration.getExecutionAttributes().get(ENABLE_SPRING_EL_COMPILER_ATTRIBUTE_NAME); if (enableSpringELCompiler == null) { return false; } if (!(enableSpringELCompiler instanceof Boolean)) { throw new TemplateProcessingException( "A value for the \"" + ENABLE_SPRING_EL_COMPILER_ATTRIBUTE_NAME + "\" execution attribute " + "has been specified, but it is not of the required type Boolean. " + "(" + enableSpringELCompiler.getClass().getName() + ")"); } return ((Boolean) enableSpringELCompiler).booleanValue(); }
/** * <p> * Check whether compilation of Spring EL expressions should be enabled or not. * </p> * <p> * This is done through configuration methods at the {@link SpringStandardDialect} * instance being used, and its value is offered to the engine as an <em>execution attribute</em>. * </p> * * @param configuration the configuration object for the current template execution environment. * @return {@code true} if the SpEL compiler should be enabled if available, {@code false} if not. */ public static boolean isSpringELCompilerEnabled(final IEngineConfiguration configuration) { final Object enableSpringELCompiler = configuration.getExecutionAttributes().get(ENABLE_SPRING_EL_COMPILER_ATTRIBUTE_NAME); if (enableSpringELCompiler == null) { return false; } if (!(enableSpringELCompiler instanceof Boolean)) { throw new TemplateProcessingException( "A value for the \"" + ENABLE_SPRING_EL_COMPILER_ATTRIBUTE_NAME + "\" execution attribute " + "has been specified, but it is not of the required type Boolean. " + "(" + enableSpringELCompiler.getClass().getName() + ")"); } return ((Boolean) enableSpringELCompiler).booleanValue(); }
/** * <p> * Check whether compilation of Spring EL expressions should be enabled or not. * </p> * <p> * This is done through configuration methods at the {@link org.thymeleaf.spring4.dialect.SpringStandardDialect} * instance being used, and its value is offered to the engine as an <em>execution attribute</em>. * </p> * * @param configuration the configuration object for the current template execution environment. * @return {@code true} if the SpEL compiler should be enabled if available, {@code false} if not. */ public static boolean isSpringELCompilerEnabled(final IEngineConfiguration configuration) { final Object enableSpringELCompiler = configuration.getExecutionAttributes().get(ENABLE_SPRING_EL_COMPILER_ATTRIBUTE_NAME); if (enableSpringELCompiler == null) { return false; } if (!(enableSpringELCompiler instanceof Boolean)) { throw new TemplateProcessingException( "A value for the \"" + ENABLE_SPRING_EL_COMPILER_ATTRIBUTE_NAME + "\" execution attribute " + "has been specified, but it is not of the required type Boolean. " + "(" + enableSpringELCompiler.getClass().getName() + ")"); } return ((Boolean) enableSpringELCompiler).booleanValue(); }
final Map<String,Object> executionAttributes = configuration.getExecutionAttributes();
/** * This method replaces the attribute device:replace="XXX" with th:replace"DEVICE_PREFIX/XXX" * This is useful for including device specific fragments */ @Override protected void doProcess( ITemplateContext context, IProcessableElementTag tag, AttributeName attributeName, String attributeValue, IElementTagStructureHandler structureHandler ) { ApplicationContext applicationContext = (ApplicationContext) context.getConfiguration() .getExecutionAttributes() .get( DeviceDialect.APPLICATION_CONTEXT_ATTRIBUTE ); DeviceBasedViewNameResolver deviceBasedViewNameResolver = applicationContext.getBean( DeviceBasedViewNameResolver.class ); structureHandler.setAttribute( StandardDialect.PREFIX + ":" + StandardReplaceTagProcessor.ATTR_NAME, deviceBasedViewNameResolver.resolveDeviceSpecificView( attributeValue ) ); } }