All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.soulgalore.velocity.PlainFileResourceLoader Maven / Gradle / Ivy

There is a newer version: 1.8.8
Show newest version
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