Issue #1638 Fixed Velocity templates for windows build

Change-Id: I144825fc138f0064294f7d540b51f5cff7995a3a

Former-commit-id: da9666be71adf84f394f255406a66afa6c3f28be
This commit is contained in:
Max Schenkelberg 2013-03-15 12:14:50 -05:00
parent 4230e1a9b8
commit 2c3ee8d35d
3 changed files with 36 additions and 35 deletions

View file

@ -466,15 +466,14 @@ public abstract class PluginDataObject extends PersistableDataObject implements
}
/**
* Used to determine if a given subclass exposes the IDecoderGettable
* interface. Normally if the class does implement the interface then a
* reference to "this" is returned. Otherwise a null reference indicates
* that the interface is not implemented.
* TODO: Rework non-PointDataContainer plots and remove
*
* @return The IDecoderGettable interface implementation. Null reference if
* not implemented.
* @return
*/
public abstract IDecoderGettable getDecoderGettable();
@Deprecated
public IDecoderGettable getDecoderGettable() {
return null;
}
public void setDataURI(String dataURI) {
this.dataURI = dataURI;
@ -549,4 +548,4 @@ public abstract class PluginDataObject extends PersistableDataObject implements
return result;
}
}
}

View file

@ -86,14 +86,10 @@ public class VelocityManager {
if (engine == null) {
engine = new VelocityEngine();
Properties p = new Properties();
String scriptDir = globalTemplateDir.getAbsolutePath();
String rootsToCheck = scriptDir;
for (File root : File.listRoots()) {
rootsToCheck += "," + root.getAbsolutePath();
}
p.setProperty("file.resource.loader.class",
VelocityTemplateLoader.class.getName());
p.setProperty("file.resource.loader.path", rootsToCheck);
p.setProperty("file.resource.loader.path",
globalTemplateDir.getAbsolutePath());
p.setProperty("velocimacro.permissions.allowInline", "true");
p.setProperty(
"velocimacro.permissions.allow.inline.to.replace.global",

View file

@ -23,6 +23,9 @@ import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.InputStream;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import org.apache.commons.collections.ExtendedProperties;
import org.apache.velocity.exception.ResourceNotFoundException;
@ -42,7 +45,7 @@ import org.apache.velocity.runtime.resource.loader.FileResourceLoader;
* ------------ ---------- ----------- --------------------------
* 04/17/2008 1088 chammack Initial Creation.
* 06/01/2012 DR 14555 D. Friedman Support new version of Velocity.
* 03/12/2013 1638 njensen Move to new plugin and rename
* 03/12/2013 1638 njensen Move to new plugin and rename
*
*
* </pre>
@ -53,7 +56,7 @@ import org.apache.velocity.runtime.resource.loader.FileResourceLoader;
public class VelocityTemplateLoader extends FileResourceLoader {
private String path;
private List<String> paths = new ArrayList<String>();
/*
* (non-Javadoc)
@ -63,8 +66,7 @@ public class VelocityTemplateLoader extends FileResourceLoader {
*/
@Override
public long getLastModified(Resource resource) {
File file = new File(resource.getName());
return file.lastModified();
return resolvePath(resource.getName()).lastModified();
}
/*
@ -74,11 +76,10 @@ public class VelocityTemplateLoader extends FileResourceLoader {
* getResourceStream(java.lang.String)
*/
@Override
public InputStream getResourceStream(String arg0)
public InputStream getResourceStream(String resource)
throws ResourceNotFoundException {
try {
FileInputStream fis = new FileInputStream(resolvePath(arg0));
return fis;
return new FileInputStream(resolvePath(resource));
} catch (FileNotFoundException e) {
throw new ResourceNotFoundException(e);
}
@ -92,8 +93,8 @@ public class VelocityTemplateLoader extends FileResourceLoader {
* .apache.commons.collections.ExtendedProperties)
*/
@Override
public void init(ExtendedProperties arg0) {
this.path = arg0.getString("path");
public void init(ExtendedProperties props) {
this.paths.addAll(Arrays.asList(props.getStringArray("path")));
}
/*
@ -103,24 +104,29 @@ public class VelocityTemplateLoader extends FileResourceLoader {
* isSourceModified(org.apache.velocity.runtime.resource.Resource)
*/
@Override
public boolean isSourceModified(Resource arg0) {
File file = new File(arg0.getName());
return (file.lastModified() != arg0.getLastModified());
public boolean isSourceModified(Resource rsc) {
File file = resolvePath(rsc.getName());
return (file.lastModified() != rsc.getLastModified());
}
@Override
public boolean resourceExists(String name) {
File f = new File(resolvePath(name));
return f.isFile();
return resolvePath(name).exists();
}
private String resolvePath(String arg0) {
String dir = null;
if (arg0.startsWith(File.separator) || arg0.charAt(1) == ':') // Win32
dir = arg0;
else
dir = this.path + File.separator + arg0;
return dir;
private File resolvePath(String path) {
File file = new File(path);
if (file.isAbsolute()) {
// Absolute path, always use
return file;
}
for (String p : paths) {
File tmpFile = new File(p, path);
if (tmpFile.exists()) {
return tmpFile;
}
}
return file;
}
}