in velocity-engine-core/src/main/java/org/apache/velocity/runtime/resource/loader/StringResourceLoader.java [224:289]
public void init(final ExtProperties configuration)
{
log.trace("StringResourceLoader: initialization starting.");
// get the repository configuration info
String repoClass = configuration.getString(REPOSITORY_CLASS, REPOSITORY_CLASS_DEFAULT);
String repoName = configuration.getString(REPOSITORY_NAME, REPOSITORY_NAME_DEFAULT);
boolean isStatic = configuration.getBoolean(REPOSITORY_STATIC, REPOSITORY_STATIC_DEFAULT);
String encoding = configuration.getString(REPOSITORY_ENCODING);
// look for an existing repository of that name and isStatic setting
if (isStatic)
{
this.repository = getRepository(repoName);
if (repository != null)
{
log.debug("Loaded repository '{}' from static repo store", repoName);
}
}
else
{
this.repository = (StringResourceRepository)rsvc.getApplicationAttribute(repoName);
if (repository != null)
{
log.debug("Loaded repository '{}' from application attributes", repoName);
}
}
if (this.repository == null)
{
// since there's no repository under the repo name, create a new one
this.repository = createRepository(repoClass, encoding);
// and store it according to the isStatic setting
if (isStatic)
{
setRepository(repoName, this.repository);
}
else
{
rsvc.setApplicationAttribute(repoName, this.repository);
}
}
else
{
// ok, we already have a repo
// warn them if they are trying to change the class of the repository
if (!this.repository.getClass().getName().equals(repoClass))
{
log.debug("Cannot change class of string repository '{}' from {} to {}." +
" The change will be ignored.",
repoName, this.repository.getClass().getName(), repoClass);
}
// allow them to change the default encoding of the repo
if (encoding != null &&
!this.repository.getEncoding().equals(encoding))
{
log.debug("Changing the default encoding of string repository '{}' from {} to {}",
repoName, this.repository.getEncoding(), encoding);
this.repository.setEncoding(encoding);
}
}
log.trace("StringResourceLoader: initialization complete.");
}