本文整理汇总了Java中org.apache.velocity.runtime.resource.loader.ResourceLoader类的典型用法代码示例。如果您正苦于以下问题:Java ResourceLoader类的具体用法?Java ResourceLoader怎么用?Java ResourceLoader使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
ResourceLoader类属于org.apache.velocity.runtime.resource.loader包,在下文中一共展示了ResourceLoader类的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: init
import org.apache.velocity.runtime.resource.loader.ResourceLoader; //导入依赖的package包/类
@Override
public void init(ExtendedProperties configuration) {
this.resourceLoader = (org.springframework.core.io.ResourceLoader)
this.rsvc.getApplicationAttribute(SPRING_RESOURCE_LOADER);
String resourceLoaderPath = (String) this.rsvc.getApplicationAttribute(SPRING_RESOURCE_LOADER_PATH);
if (this.resourceLoader == null) {
throw new IllegalArgumentException(
"'resourceLoader' application attribute must be present for SpringResourceLoader");
}
if (resourceLoaderPath == null) {
throw new IllegalArgumentException(
"'resourceLoaderPath' application attribute must be present for SpringResourceLoader");
}
this.resourceLoaderPaths = StringUtils.commaDelimitedListToStringArray(resourceLoaderPath);
for (int i = 0; i < this.resourceLoaderPaths.length; i++) {
String path = this.resourceLoaderPaths[i];
if (!path.endsWith("/")) {
this.resourceLoaderPaths[i] = path + "/";
}
}
if (logger.isInfoEnabled()) {
logger.info("SpringResourceLoader for Velocity: using resource loader [" + this.resourceLoader +
"] and resource loader paths " + Arrays.asList(this.resourceLoaderPaths));
}
}
示例2: setupTemplate
import org.apache.velocity.runtime.resource.loader.ResourceLoader; //导入依赖的package包/类
private Template setupTemplate(ResourceLoader loader, RuntimeInstance runtimeServices, String templateName, InputStream templateContents) {
try {
Template template = new Template();
template.setRuntimeServices(runtimeServices);
template.setResourceLoader(loader);
template.setName(templateName);
byte[] bytes = IOUtils.toByteArray(templateContents);
templateContents.close();
when(loader.getResourceStream(templateName)).thenReturn(new ByteArrayInputStream(bytes));
doReturn(template).when(runtimeServices).getTemplate(templateName);
doReturn(template).when(runtimeServices).getTemplate(eq(templateName), Matchers.<String>any());
return template;
} catch (Exception e) {
throw new RuntimeException(e);
}
}
示例3: refreshResource
import org.apache.velocity.runtime.resource.loader.ResourceLoader; //导入依赖的package包/类
@Override
protected Resource refreshResource(final Resource resource, final String encoding) {
resource.touch();
final ResourceLoader loader = resource.getResourceLoader();
if (resourceLoaders.size() > 0 && resourceLoaders.indexOf(loader) > 0) {
final String name = resource.getName();
if (loader != getLoaderForResource(name)) {
return loadResource(name, resource.getType(), encoding);
}
}
if (resource.isSourceModified()) {
if (!StringUtils.equals(resource.getEncoding(), encoding)) {
resource.setEncoding(encoding);
}
final String resourceName = resource.getName();
final Resource newResource = AliadaResourceFactory.getResource(resourceName, resource.getType());
newResource.setRuntimeServices(rsvc);
newResource.setName(resourceName);
newResource.setEncoding(resource.getEncoding());
newResource.setResourceLoader(loader);
newResource.setModificationCheckInterval(loader.getModificationCheckInterval());
newResource.process();
newResource.setLastModified(loader.getLastModified(resource));
globalCache.put(
new StringBuilder(resource.getType())
.append(resource.getName())
.toString(),
newResource);
return newResource;
}
return resource;
}
示例4: getLoaderForResource
import org.apache.velocity.runtime.resource.loader.ResourceLoader; //导入依赖的package包/类
/**
* Returns the first {@link ResourceLoader} in which the specified
* resource exists.
*
* @param resourceName the resource name.
* @return a resource loader for the given resource.
*/
@SuppressWarnings("unchecked")
private ResourceLoader getLoaderForResource(final String resourceName) {
for (final Iterator<ResourceLoader> i = resourceLoaders.iterator(); i.hasNext();) {
final ResourceLoader loader = (ResourceLoader)i.next();
if (loader.resourceExists(resourceName)) {
return loader;
}
}
return null;
}
示例5: TestVelocityView
import org.apache.velocity.runtime.resource.loader.ResourceLoader; //导入依赖的package包/类
public TestVelocityView(String templatePath, Map<String, Object> modelData) {
this.templatePath = templatePath;
this.modelData = modelData;
this.additionalTemplates = new ArrayList<>();
loader = mock(ResourceLoader.class);
runtimeServices = spy(new RuntimeInstance());
setupToolAttributes();
}
示例6: setupContentResource
import org.apache.velocity.runtime.resource.loader.ResourceLoader; //导入依赖的package包/类
private void setupContentResource(ResourceLoader loader, RuntimeInstance runtimeServices, String templateName, String fakeContent) {
try {
ContentResource resource = new ContentResource();
resource.setRuntimeServices(runtimeServices);
resource.setResourceLoader(loader);
resource.setName(templateName);
resource.setData(fakeContent);
doReturn(resource).when(runtimeServices).getContent(templateName);
doReturn(resource).when(runtimeServices).getContent(eq(templateName), Matchers.<String>any());
} catch (Exception e) {
throw new RuntimeException(e);
}
}