From f294d9aa8a95bd26c350ea61b619d12748368cbc Mon Sep 17 00:00:00 2001 From: Max Schenkelberg Date: Fri, 15 Mar 2013 12:14:50 -0500 Subject: [PATCH] Issue #1638 Fixed Velocity templates for windows build Change-Id: I144825fc138f0064294f7d540b51f5cff7995a3a Former-commit-id: 93c416e914f4b13a01e888decf6b4db3590f3570 [formerly 07a6fd494d9bd7cf273233c05bb0959d92ffc16a] [formerly 2c3ee8d35d3d6c8ee087ae1b7c9075a22572f685] [formerly beb801517e654e1aeae03648e7c6c9b38bcc8aa1 [formerly 2c3ee8d35d3d6c8ee087ae1b7c9075a22572f685 [formerly da9666be71adf84f394f255406a66afa6c3f28be]]] Former-commit-id: beb801517e654e1aeae03648e7c6c9b38bcc8aa1 Former-commit-id: 1728f5f643c879365568ae1dc33fadaaaaa596c0 [formerly 582de5717c519fbd21a7d41078a4dd6b0c03442f] Former-commit-id: c3232f2581f5322611765062f08056de1b593223 --- .../common/dataplugin/PluginDataObject.java | 15 +++--- .../uf/common/velocity/VelocityManager.java | 8 +--- .../velocity/VelocityTemplateLoader.java | 48 +++++++++++-------- 3 files changed, 36 insertions(+), 35 deletions(-) diff --git a/edexOsgi/com.raytheon.uf.common.dataplugin/src/com/raytheon/uf/common/dataplugin/PluginDataObject.java b/edexOsgi/com.raytheon.uf.common.dataplugin/src/com/raytheon/uf/common/dataplugin/PluginDataObject.java index 89c059618c..90ffaa8b06 100644 --- a/edexOsgi/com.raytheon.uf.common.dataplugin/src/com/raytheon/uf/common/dataplugin/PluginDataObject.java +++ b/edexOsgi/com.raytheon.uf.common.dataplugin/src/com/raytheon/uf/common/dataplugin/PluginDataObject.java @@ -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; } -} \ No newline at end of file +} diff --git a/edexOsgi/com.raytheon.uf.common.velocity/src/com/raytheon/uf/common/velocity/VelocityManager.java b/edexOsgi/com.raytheon.uf.common.velocity/src/com/raytheon/uf/common/velocity/VelocityManager.java index e219b8fae5..e9890540d4 100644 --- a/edexOsgi/com.raytheon.uf.common.velocity/src/com/raytheon/uf/common/velocity/VelocityManager.java +++ b/edexOsgi/com.raytheon.uf.common.velocity/src/com/raytheon/uf/common/velocity/VelocityManager.java @@ -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", diff --git a/edexOsgi/com.raytheon.uf.common.velocity/src/com/raytheon/uf/common/velocity/VelocityTemplateLoader.java b/edexOsgi/com.raytheon.uf.common.velocity/src/com/raytheon/uf/common/velocity/VelocityTemplateLoader.java index c2ada1c989..b6170fe90d 100644 --- a/edexOsgi/com.raytheon.uf.common.velocity/src/com/raytheon/uf/common/velocity/VelocityTemplateLoader.java +++ b/edexOsgi/com.raytheon.uf.common.velocity/src/com/raytheon/uf/common/velocity/VelocityTemplateLoader.java @@ -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 * * * @@ -53,7 +56,7 @@ import org.apache.velocity.runtime.resource.loader.FileResourceLoader; public class VelocityTemplateLoader extends FileResourceLoader { - private String path; + private List paths = new ArrayList(); /* * (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; } }