/** * <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 ICacheManager getCacheManager() { return this.configuration.getCacheManager(); }
/** * <p> * Returns the configured dialects, referenced by their prefixes. * </p> * * @return the {@link IDialect} instances currently configured. */ public final Map<String,IDialect> getDialectsByPrefix() { return this.configuration.getDialects(); }
/** * <p> * Adds a new dialect for this template engine, using the specified prefix. * </p> * <p> * This dialect will be added to the set of currently configured ones. * </p> * <p> * This operation can only be executed before processing templates for the first * time. Once a template is processed, the template engine is considered to be * <i>initialized</i>, and from then on any attempt to change its configuration * will result in an exception. * </p> * * @param prefix the prefix that will be used for this dialect * @param dialect the new {@link IDialect} to be added to the existing ones. */ public void addDialect(final String prefix, final IDialect dialect) { this.configuration.addDialect(prefix, dialect); }
public Set<IDialect> getDialectSet() { if (!isInitialized()) { // If we haven't initialized yet, compute return Collections.unmodifiableSet(new LinkedHashSet<IDialect>(getDialects().values())); } return this.dialectSet; }
/** * * @since 2.0.8 */ public static Document getDOMFor(final Reader source, final ITemplateParser parser) { Validate.notNull(source, "Source cannot be null"); Validate.notNull(parser, "Template parser cannot be null"); final Configuration configuration = new Configuration(); configuration.addTemplateResolver(new ClassLoaderTemplateResolver()); configuration.addMessageResolver(new StandardMessageResolver()); configuration.setTemplateModeHandlers(StandardTemplateModeHandlers.ALL_TEMPLATE_MODE_HANDLERS); configuration.initialize(); return getDOMFor(configuration, source, parser); }
public void setCacheManager(final ICacheManager cacheManager) { // Can be set to null (= no caches) checkNotInitialized(); this.cacheManager = cacheManager; }
/** * <p> * Sets an additional set of dialects for this template engine, all of them using * their default prefixes. * </p> * <p> * This operation can only be executed before processing templates for the first * time. Once a template is processed, the template engine is considered to be * <i>initialized</i>, and from then on any attempt to change its configuration * will result in an exception. * </p> * * @param additionalDialects the new set of {@link IDialect} objects to be used. * * @since 2.0.9 * */ public void setAdditionalDialects(final Set<IDialect> additionalDialects) { Validate.notNull(additionalDialects, "Additional dialect set cannot be null"); final Map<String,IDialect> dialectMap = new LinkedHashMap<String, IDialect>(5, 1.0f); dialectMap.putAll(this.configuration.getDialects()); for (final IDialect dialect : additionalDialects) { dialectMap.put(dialect.getPrefix(), dialect); } this.configuration.setDialects(dialectMap); }
/** * <p> * This constructor should only be called directly for <p>testing purposes</p>. * </p> * * @param configuration the configuration being currently used. */ public TemplateRepository(final Configuration configuration) { super(); Validate.notNull(configuration, "Configuration object cannot be null"); final ICacheManager cacheManager = configuration.getCacheManager(); if (cacheManager == null) { this.templateCache = null; this.fragmentCache = null; } else { this.templateCache = cacheManager.getTemplateCache(); this.fragmentCache = cacheManager.getFragmentCache(); } this.parsersByTemplateMode = new HashMap<String,ITemplateParser>(10, 1.0f); for (final ITemplateModeHandler handler : configuration.getTemplateModeHandlers()) { this.parsersByTemplateMode.put(handler.getTemplateModeName(), handler.getTemplateParser()); } }
public Map<String,Object> getExecutionAttributes() { checkInitialized(); return this.mergedExecutionAttributes; }
/** * <p> * Adds a new template resolver to the current set. * </p> * * @param templateResolver the new template resolver. */ public void addTemplateResolver(final ITemplateResolver templateResolver) { this.configuration.addTemplateResolver(templateResolver); }
/** * <p> * Removes all the currently configured dialects. * </p> * <p> * This operation can only be executed before processing templates for the first * time. Once a template is processed, the template engine is considered to be * <i>initialized</i>, and from then on any attempt to change its configuration * will result in an exception. * </p> */ public void clearDialects() { this.configuration.clearDialects(); }
/** * <p> * Adds a message resolver to the set of message resolvers to be used * by the template engine. * </p> * <p> * This operation can only be executed before processing templates for the first * time. Once a template is processed, the template engine is considered to be * <i>initialized</i>, and from then on any attempt to change its configuration * will result in an exception. * </p> * * @param messageResolver the new message resolver to be added. */ public void addMessageResolver(final IMessageResolver messageResolver) { this.configuration.addMessageResolver(messageResolver); }
/** * <p> * Adds a Template Mode Handler to the set of Template Mode Handlers to be used * by the template engine. * Every available template mode must have its corresponding handler. * </p> * <p> * By default, template mode handlers set are * {@link StandardTemplateModeHandlers#ALL_TEMPLATE_MODE_HANDLERS} * </p> * <p> * This operation can only be executed before processing templates for the first * time. Once a template is processed, the template engine is considered to be * <i>initialized</i>, and from then on any attempt to change its configuration * will result in an exception. * </p> * * @param templateModeHandler the new Template Mode Handler to be added. */ public void addTemplateModeHandler(final ITemplateModeHandler templateModeHandler) { this.configuration.addTemplateModeHandler(templateModeHandler); }
/** * <p> * Constructor for <tt>TemplateEngine</tt> objects. * </p> * <p> * This is the only way to create a <tt>TemplateEngine</tt> instance (which * should be configured after creation). * </p> */ public TemplateEngine() { super(); this.configuration = new Configuration(); this.initialized = false; setCacheManager(new StandardCacheManager()); setDefaultMessageResolvers(Collections.singleton(new StandardMessageResolver())); setDefaultTemplateModeHandlers(StandardTemplateModeHandlers.ALL_TEMPLATE_MODE_HANDLERS); }
public void clearDialects() { checkNotInitialized(); this.dialectConfigurations.clear(); }
public Set<IDocTypeTranslation> getDocTypeTranslations() { checkInitialized(); return this.mergedDocTypeTranslations; }
private static <V> void putIntoCache(final Configuration configuration, final String input, final V value, final String prefix) { final ICacheManager cacheManager = configuration.getCacheManager(); if (cacheManager != null) { final ICache<String,Object> cache = cacheManager.getExpressionCache(); if (cache != null) { cache.put(prefix + input, value); } } }
private static String getStandardDialectPrefix(final Configuration configuration) { for (final Map.Entry<String,IDialect> dialectByPrefix : configuration.getDialects().entrySet()) { final IDialect dialect = dialectByPrefix.getValue(); if (StandardDialect.class.isAssignableFrom(dialect.getClass())) { return dialectByPrefix.getKey(); } } throw new ConfigurationException( "A Thymeleaf Standard Dialect has not been found in the current configuration, but it is " + "required in order to use " + StandardDOMSelectorFragmentSpec.class.getName()); }
public void addTemplateResolver(final ITemplateResolver templateResolver) { checkNotInitialized(); Validate.notNull(templateResolver, "Template Resolver cannot be null"); this.templateResolvers.add(templateResolver); }
public Set<IDocTypeResolutionEntry> getDocTypeResolutionEntries() { checkInitialized(); return this.mergedDocTypeResolutionEntries; }