private void recreateTemplateCacheWith( TemplateLoader loader, CacheStorage storage, TemplateLookupStrategy templateLookupStrategy, TemplateNameFormat templateNameFormat, TemplateConfigurationFactory templateConfigurations) { TemplateCache oldCache = cache; cache = new TemplateCache( loader, storage, templateLookupStrategy, templateNameFormat, templateConfigurations, this); cache.clear(); // for fully BC behavior cache.setDelay(oldCache.getDelay()); cache.setLocalizedLookup(localizedLookup); }
return TemplateLookupResult.from(path, findTemplateSource(path)); return TemplateLookupResult.from(path, findTemplateSource(path)); String basePath = concatPath(tokpath, 0, lastAsterisk); String resourcePath = concatPath(tokpath, lastAsterisk + 1, tokpath.size()); if (resourcePath.endsWith("/")) { resourcePath = resourcePath.substring(0, resourcePath.length() - 1); for (; ; ) { String fullPath = buf.append(resourcePath).toString(); Object templateSource = findTemplateSource(fullPath); if (templateSource != null) { return TemplateLookupResult.from(fullPath, templateSource);
/** * Sets the {@link TemplateLookupStrategy} that is used to look up templates based on the requested name; as a side * effect the template cache will be emptied. The default value is {@link TemplateLookupStrategy#DEFAULT_2_3_0}. * * @since 2.3.22 */ public void setTemplateLookupStrategy(TemplateLookupStrategy templateLookupStrategy) { if (cache.getTemplateLookupStrategy() != templateLookupStrategy) { recreateTemplateCacheWith(cache.getTemplateLoader(), cache.getCacheStorage(), templateLookupStrategy, cache.getTemplateNameFormat(), cache.getTemplateConfigurations()); } templateLookupStrategyExplicitlySet = true; }
private void createTemplateCache() { cache = new TemplateCache( getDefaultTemplateLoader(), getDefaultCacheStorage(), getDefaultTemplateLookupStrategy(), getDefaultTemplateNameFormat(), null, this); cache.clear(); // for fully BC behavior cache.setDelay(5000); }
final boolean debug = LOG.isDebugEnabled(); final String debugName = debug ? buildDebugName(name, locale, customLookupCondition, encoding, parseAsFTL) : null; final TemplateKey tk = new TemplateKey(name, locale, customLookupCondition, encoding, parseAsFTL); return (Template) t; } else if (t instanceof RuntimeException) { throwLoadFailedException((RuntimeException) t); } else if (t instanceof IOException) { rethrown = true; throwLoadFailedException((IOException) t); newLookupResult = lookupTemplate(name, locale, customLookupCondition); storeNegativeLookup(tk, cachedTemplate, null); return null; storeCached(tk, cachedTemplate); return (Template) cachedTemplate.templateOrException; } else if (debug) { newLookupResult = lookupTemplate(name, locale, customLookupCondition); storeNegativeLookup(tk, cachedTemplate, null); return null; Template template = loadTemplate( templateLoader, source,
private void createTemplateCache(TemplateLoader loader, CacheStorage storage) { TemplateCache oldCache = cache; cache = new TemplateCache(loader, storage); cache.setDelay(oldCache.getDelay()); cache.setConfiguration(this); cache.setLocalizedLookup(localizedLookup); } /**
throwLoadFailedException((RuntimeException)t); throwLoadFailedException((IOException)t); newlyFoundSource = findTemplateSource(name, locale); storeNegativeLookup(tk, cachedTemplate, null); return null; storeCached(tk, cachedTemplate); return (Template)cachedTemplate.templateOrException; newlyFoundSource = findTemplateSource(name, locale); if (newlyFoundSource == null) { storeNegativeLookup(tk, cachedTemplate, null); return null; Template t = loadTemplate(loader, name, locale, encoding, parse, source); cachedTemplate.templateOrException = t; cachedTemplate.lastModified = ? loader.getLastModified(source) : lastModified; storeCached(tk, cachedTemplate); return t; storeNegativeLookup(tk, cachedTemplate, e); throw e;
/** * Removes all entries from the template cache, thus forcing reloading of templates * on subsequent <code>getTemplate</code> calls. * * <p>This method is thread-safe and can be called while the engine processes templates. */ public void clearTemplateCache() { cache.clear(); }
public Configuration() { cache = new TemplateCache(); cache.setConfiguration(this); cache.setDelay(5000); loadBuiltInSharedVariables(); }
/** * Similar to {@link #getTemplate(String, Locale, Object, String, boolean)} with {@code null} * {@code customLookupCondition}. * * @return {@link MaybeMissingTemplate#getTemplate()} of the * {@link #getTemplate(String, Locale, Object, String, boolean)} return value. * * @deprecated Use {@link #getTemplate(String, Locale, Object, String, boolean)}, which can return more detailed * result when the template is missing. */ @Deprecated public Template getTemplate(String name, Locale locale, String encoding, boolean parseAsFTL) throws IOException { return getTemplate(name, locale, null, encoding, parseAsFTL).getTemplate(); }
public Object clone() { try { Configuration copy = (Configuration)super.clone(); copy.variables = new HashMap(variables); copy.encodingMap = new HashMap(encodingMap); copy.createTemplateCache(cache.getTemplateLoader(), cache.getCacheStorage()); return copy; } catch (CloneNotSupportedException e) { throw new RuntimeException("Clone is not supported, but it should be: " + e.getMessage()); } }
/** * The getter pair of {@link #setTemplateLoader(TemplateLoader)}. */ public TemplateLoader getTemplateLoader() { if (cache == null) { return null; } return cache.getTemplateLoader(); }
/** * The getter pair of {@link #setLocalizedLookup(boolean)}. * * <p>This method is thread-safe and can be called while the engine works. */ public boolean getLocalizedLookup() { return cache.getLocalizedLookup(); }
/** * The getter pair of {@link #setCacheStorage(CacheStorage)}. * * @since 2.3.20 */ public CacheStorage getCacheStorage() { // "synchronized" is removed from the API as it's not safe to set anything after publishing the Configuration synchronized (this) { if (cache == null) { return null; } return cache.getCacheStorage(); } }
/** * The getter pair of {@link #setTemplateUpdateDelayMilliseconds(long)}. * * @since 2.3.23 */ public long getTemplateUpdateDelayMilliseconds() { return cache.getDelay(); }
throw new IllegalArgumentException("Argument \"encoding\" can't be null"); name = normalizeName(name); if(name == null) { return null; result = getTemplate(mainLoader, name, locale, encoding, parse);
String basePath = concatPath(tokpath, 0, lastAsterisk); String resourcePath = concatPath(tokpath, lastAsterisk + 1, tokpath.size()); if(resourcePath.endsWith("/"))
final boolean debug = LOG.isDebugEnabled(); final String debugName = debug ? buildDebugName(name, locale, customLookupCondition, encoding, parseAsFTL) : null; final TemplateKey tk = new TemplateKey(name, locale, customLookupCondition, encoding, parseAsFTL); return (Template) t; } else if (t instanceof RuntimeException) { throwLoadFailedException((RuntimeException) t); } else if (t instanceof IOException) { rethrown = true; throwLoadFailedException((IOException) t); newLookupResult = lookupTemplate(name, locale, customLookupCondition); storeNegativeLookup(tk, cachedTemplate, null); return null; storeCached(tk, cachedTemplate); return (Template) cachedTemplate.templateOrException; } else if (debug) { newLookupResult = lookupTemplate(name, locale, customLookupCondition); storeNegativeLookup(tk, cachedTemplate, null); return null; Template template = loadTemplate( templateLoader, source,
private void createTemplateCache() { cache = new TemplateCache( getDefaultTemplateLoader(), getDefaultCacheStorage(), getDefaultTemplateLookupStrategy(), getDefaultTemplateNameFormat(), null, this); cache.clear(); // for fully BC behavior cache.setDelay(5000); }
/** * Setis if localized template lookup is enabled or not. */ public void setLocalizedLookup(boolean localizedLookup) { // synchronized was moved here so that we don't advertise that it's thread-safe, as it's not. synchronized (this) { if (this.localizedLookup != localizedLookup) { this.localizedLookup = localizedLookup; clear(); } } }