
com.soulgalore.velocity.PlainFileResourceLoader Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of xml-velocity Show documentation
Show all versions of xml-velocity Show documentation
Merge a XML file with a Velocity template
package com.soulgalore.velocity;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.InputStream;
import org.apache.commons.collections.ExtendedProperties;
import org.apache.velocity.exception.ResourceNotFoundException;
import org.apache.velocity.runtime.resource.Resource;
import org.apache.velocity.runtime.resource.loader.ResourceLoader;
public class PlainFileResourceLoader extends ResourceLoader {
public static final String TEMPLATE_HOME_PROPERTY = "com.soulgalore.velocity.templates.home";
@Override
public void init(ExtendedProperties configuration) {
}
@Override
public InputStream getResourceStream(String source)
throws ResourceNotFoundException {
try {
if (source.startsWith("/"))
return new FileInputStream(source);
else {
return new FileInputStream(System.getProperty(
TEMPLATE_HOME_PROPERTY, ".") + "/" + source);
}
} catch (FileNotFoundException e) {
throw new ResourceNotFoundException("Could not find "
+ (new File(source)).getAbsolutePath());
}
}
@Override
public boolean isSourceModified(Resource resource) {
// TODO Auto-generated method stub
return false;
}
@Override
public long getLastModified(Resource resource) {
// TODO Auto-generated method stub
return 0;
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy