import java.io.PrintWriter;
import java.io.StringWriter;
+import java.io.File;
import java.util.AbstractList;
import java.util.Date;
import java.util.HashMap;
import org.apache.commons.beanutils.MethodUtils;
import org.apache.commons.beanutils.PropertyUtils;
import org.apache.velocity.Template;
-import org.apache.velocity.VelocityContext;
import org.apache.velocity.app.VelocityEngine;
import org.apache.velocity.context.Context;
import org.apache.velocity.exception.ParseErrorException;
/**
*
- * <p>Title: </p>
- * <p>Description: </p>
- * <p>Copyright: Copyright (c) 2003</p>
- * <p>Company: </p>
- * @author not attributable
- * @version 1.0
- */
- private static class ContextAdapter implements Context {
- public boolean containsKey(java.lang.Object key) {
- return false;
- }
-
- public Object get(java.lang.String key) {
- return null;
- }
-
- public Object[] getKeys() {
- return new Object[] {};
- }
-
- public Object put(java.lang.String key, java.lang.Object value) {
- return null;
- }
-
- public Object remove(java.lang.Object key) {
- return null;
- }
- }
-
- /**
- *
* @param aMap
* @return
*/
* @param aFunction
* @return
*/
- private static Object makeFunctionAdapter(Generator.GeneratorFunction aFunction) {
+ private static Object makeFunctionAdapter(Generator.Function aFunction) {
return new FunctionAdapter(aFunction);
}
if (anObject instanceof Context)
return anObject;
- else if (anObject instanceof Generator.GeneratorFunction)
- return makeFunctionAdapter((Generator.GeneratorFunction) anObject);
+ else if (anObject instanceof Generator.Function)
+ return makeFunctionAdapter((Generator.Function) anObject);
else if (anObject instanceof Integer)
return anObject;
else if (anObject instanceof Boolean)
* @version 1.0
*/
public static class FunctionAdapter implements VelocityAdapter {
- private GeneratorFunction function;
+ private Function function;
public Object getOriginal() {
return function;
}
- private FunctionAdapter(GeneratorFunction aFunction) {
+ private FunctionAdapter(Function aFunction) {
function = aFunction;
}
private static class IteratorAdapter extends AbstractList implements VelocityAdapter {
private Iterator iterator;
private List valuesCache;
- private int position;
private IteratorAdapter(Iterator anIterator) {
iterator = anIterator;
valuesCache = new Vector();
- position=0;
-
if (iterator instanceof RewindableIterator) {
((RewindableIterator) iterator).rewind();
private static class ListAdapter extends AbstractList implements VelocityAdapter {
private List list;
private List valuesCache;
- private int position;
private ListAdapter(List aList) {
list = aList;
valuesCache = new Vector();
- position=0;
}
private void getUntil(int anIndex) {
* @author not attributable
* @version 1.0
*/
- public static class VelocityGeneratorLibrary implements GeneratorLibrary {
+ public static class VelocityGeneratorLibrary implements Library {
private VelocityEngine engine;
- public VelocityGeneratorLibrary(String aTemplateRoot) throws GeneratorExc, GeneratorFailure {
+ public VelocityGeneratorLibrary(File aTemplateRoot) throws GeneratorExc, GeneratorFailure {
try {
engine = new VelocityEngine();
try {
engine.setProperty(VelocityEngine.RESOURCE_LOADER, "file");
- }
- catch (Throwable t) {
- logger.error(VelocityEngine.RESOURCE_LOADER);
- }
-
- try {
engine.setProperty("file.resource.loader.class", "org.apache.velocity.runtime.resource.loader.FileResourceLoader");
- }
- catch (Throwable t) {
- logger.error("file.resource.loader.class");
- }
-
- try {
- engine.setProperty("file.resource.loader.path", aTemplateRoot);
- }
- catch (Throwable t) {
- logger.error("file.resource.loader.path");
-
- }
- try {
+ engine.setProperty("file.resource.loader.path", aTemplateRoot.getAbsolutePath());
engine.setProperty("file.resource.loader.cache", "true");
}
catch (Throwable t) {
- logger.error("file.resource.loader.cache");
-
- }
- try {
- engine.setProperty("file.resource.loader.modificationCheckInterval", "10");
- }
- catch (Throwable t) {
- logger.error("file.resource.loader.modificationCheckInterval");
+ logger.error("Error while constructing library: " + t.toString());
+ throw new GeneratorFailure(t);
}
try {
* @author not attributable
* @version 1.0
*/
- public static class VelocityGeneratorLibraryFactory implements GeneratorLibraryFactory {
- private String basePath;
+ public static class VelocityGeneratorLibraryFactory implements LibraryFactory {
+ private File basePath;
- public VelocityGeneratorLibraryFactory(String aBasePath) {
+ public VelocityGeneratorLibraryFactory(File aBasePath) {
basePath = aBasePath;
}
- public GeneratorLibrary makeLibrary(String anInitializationString) throws GeneratorExc, GeneratorFailure {
- return new VelocityGeneratorLibrary(basePath+anInitializationString);
+ public Library makeLibrary(String anInitializationString) throws GeneratorExc, GeneratorFailure {
+ return new VelocityGeneratorLibrary(new File(basePath, anInitializationString));
};
}
}