/** * <p> * Returns the cache manager in effect. This manager is in charge of providing * the various caches needed by the system during its process. * </p> * <p> * By default, an instance of {@link org.thymeleaf.cache.StandardCacheManager} * is set. * </p> * * @return the cache manager */ public final ICacheManager getCacheManager() { if (this.initialized) { return this.configuration.getCacheManager(); } return this.cacheManager; }
/** * <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; }
@Override public IExpressionObjects getExpressionObjects() { // We delay creation of expression objects in case they are not needed at all if (this.expressionObjects == null) { this.expressionObjects = new ExpressionObjects(this, this.configuration.getExpressionObjectFactory()); } return this.expressionObjects; }
public StandardModelFactory(final IEngineConfiguration configuration, final TemplateMode templateMode) { super(); Validate.notNull(configuration, "Configuration cannot be null"); Validate.notNull(configuration.getAttributeDefinitions(), "Attribute Definitions returned by Engine Configuration cannot be null"); Validate.notNull(configuration.getElementDefinitions(), "Element Definitions returned by Engine Configuration cannot be null"); Validate.notNull(templateMode, "Template Mode cannot be null"); this.configuration = configuration; this.attributeDefinitions = this.configuration.getAttributeDefinitions(); this.elementDefinitions = this.configuration.getElementDefinitions(); this.templateMode = templateMode; }
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.attributeDefinitions = this.configuration.getAttributeDefinitions(); final Set<ITemplateBoundariesProcessor> templateBoundariesProcessorSet = this.configuration.getTemplateBoundariesProcessors(this.templateMode); final Set<ICDATASectionProcessor> cdataSectionProcessorSet = this.configuration.getCDATASectionProcessors(this.templateMode); final Set<ICommentProcessor> commentProcessorSet = this.configuration.getCommentProcessors(this.templateMode); final Set<IDocTypeProcessor> docTypeProcessorSet = this.configuration.getDocTypeProcessors(this.templateMode); final Set<IProcessingInstructionProcessor> processingInstructionProcessorSet = this.configuration.getProcessingInstructionProcessors(this.templateMode); final Set<ITextProcessor> textProcessorSet = this.configuration.getTextProcessors(this.templateMode); final Set<IXMLDeclarationProcessor> xmlDeclarationProcessorSet = this.configuration.getXMLDeclarationProcessors(this.templateMode);
final ICacheManager cacheManager = configuration.getCacheManager(); final Set<ITemplateResolver> templateResolvers = configuration.getTemplateResolvers(); final Set<IMessageResolver> messageResolvers = configuration.getMessageResolvers(); final Set<ILinkBuilder> linkBuilders = configuration.getLinkBuilders(); final Set<DialectConfiguration> dialectConfigurations = configuration.getDialectConfigurations();
public IModel parse(final TemplateData ownerTemplate, final String template) { // We will be setting useCache to false because we don't want to pollute the cache with mere String // parsing done from here. Also, we are 'artificially' specifying it as nested even if we don't really // know if this fragment is exactly a nested text inside the template, but that's not really important... return this.configuration.getTemplateManager().parseString(ownerTemplate, template, 0, 0, this.templateMode, false); }
/** * <p> * This constructor should only be called directly for <strong>testing purposes</strong>. * </p> * * @param configuration the engine configuration */ public TemplateManager(final IEngineConfiguration configuration) { super(); Validate.notNull(configuration, "Configuration cannot be null"); this.configuration = configuration; final ICacheManager cacheManager = this.configuration.getCacheManager(); if (cacheManager == null) { this.templateCache = null; } else { this.templateCache = cacheManager.getTemplateCache(); } final boolean standardDialectPresent = this.configuration.isStandardDialectPresent(); // TODO Make these parser implementations configurable: one parser per template mode, then make default implementations extensible/configurable (e.g. AttoParser config) this.htmlParser = new HTMLTemplateParser(DEFAULT_PARSER_POOL_SIZE,DEFAULT_PARSER_BLOCK_SIZE); this.xmlParser = new XMLTemplateParser(DEFAULT_PARSER_POOL_SIZE, DEFAULT_PARSER_BLOCK_SIZE); this.textParser = new TextTemplateParser(DEFAULT_PARSER_POOL_SIZE, DEFAULT_PARSER_BLOCK_SIZE, standardDialectPresent); this.javascriptParser = new JavaScriptTemplateParser(DEFAULT_PARSER_POOL_SIZE, DEFAULT_PARSER_BLOCK_SIZE, standardDialectPresent); this.cssParser = new CSSTemplateParser(DEFAULT_PARSER_POOL_SIZE, DEFAULT_PARSER_BLOCK_SIZE, standardDialectPresent); this.rawParser = new RawTemplateParser(DEFAULT_PARSER_POOL_SIZE, DEFAULT_PARSER_BLOCK_SIZE); }
templateName, templateHandler, configuration.getElementDefinitions(), configuration.getAttributeDefinitions(), templateMode, lineOffset, colOffset); configuration, templateMode, configuration.getStandardDialectPrefix(), handler);
final Set<IPostProcessor> postProcessors = configuration.getPostProcessors(getTemplateMode()); if (postProcessors.isEmpty()) { structureHandler.setBody(unescapedTextStr, false); configuration.getTemplateManager().parseString( context.getTemplateData(), unescapedTextStr,
@Override protected void writeUnresolved(final Writer writer) throws IOException { this.context.getConfiguration().getTemplateManager().process(this.templateModel, this.context, writer); }
templateName, templateHandler, configuration.getElementDefinitions(), configuration.getAttributeDefinitions(), templateMode, lineOffset, colOffset); configuration, templateMode, configuration.getStandardDialectPrefix(), handler); final String standardDialectPrefix = configuration.getStandardDialectPrefix(); referenceResolver = (standardDialectPrefix != null ?
static <V> void removeFromCache(final IEngineConfiguration configuration, final String input, final String type) { final ICacheManager cacheManager = configuration.getCacheManager(); if (cacheManager != null) { final ICache<ExpressionCacheKey,Object> cache = cacheManager.getExpressionCache(); if (cache != null) { cache.clearKey(new ExpressionCacheKey(type,input)); } } }
/** * <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; }
@Override protected String resolveText() { final Writer stringWriter = new FastStringWriter(); this.context.getConfiguration().getTemplateManager().process(this.templateModel, this.context, stringWriter); return stringWriter.toString(); }
public final IExpressionObjects getExpressionObjects() { // We delay creation of expression objects in case they are not needed at all if (this.expressionObjects == null) { this.expressionObjects = new ExpressionObjects(this, this.configuration.getExpressionObjectFactory()); } return this.expressionObjects; }
static Object getFromCache(final IEngineConfiguration configuration, final String input, final String type) { final ICacheManager cacheManager = configuration.getCacheManager(); if (cacheManager != null) { final ICache<ExpressionCacheKey,Object> cache = cacheManager.getExpressionCache(); if (cache != null) { return cache.get(new ExpressionCacheKey(type,input)); } } return null; }
/** * <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> * Completely clears the Template Cache. * </p> * <p> * If this method is called before the TemplateEngine has been initialized, * it causes its initialization. * </p> */ public void clearTemplateCache() { if (!this.initialized) { initialize(); } this.configuration.getTemplateManager().clearCaches(); }
@Override public IExpressionObjects getExpressionObjects() { // We delay creation of expression objects in case they are not needed at all if (this.expressionObjects == null) { this.expressionObjects = new ExpressionObjects(this, this.configuration.getExpressionObjectFactory()); } return this.expressionObjects; }