[utilities COMMIT] /java-support/trunk/src/main/java/net/shibboleth/utilities/java/support/velocity/Template.java

noreply at shibboleth.net noreply at shibboleth.net
Mon Feb 6 15:13:14 GMT 2012


Author: lajoie
Date: Mon Feb  6 15:13:14 2012
New Revision: 229

URL: http://svn.shibboleth.net/view/utilities?rev=229&view=rev
Log:
Add check to see if template is, at least, parsable at construction time

Modified:
    java-support/trunk/src/main/java/net/shibboleth/utilities/java/support/velocity/Template.java

Modified: java-support/trunk/src/main/java/net/shibboleth/utilities/java/support/velocity/Template.java
URL: http://svn.shibboleth.net/view/utilities/java-support/trunk/src/main/java/net/shibboleth/utilities/java/support/velocity/Template.java?rev=229&r1=228&r2=229&view=diff
==============================================================================
--- java-support/trunk/src/main/java/net/shibboleth/utilities/java/support/velocity/Template.java (original)
+++ java-support/trunk/src/main/java/net/shibboleth/utilities/java/support/velocity/Template.java Mon Feb  6 15:13:14 2012
@@ -38,8 +38,6 @@
 import com.google.common.base.Charsets;
 import com.google.common.base.Objects;
 
-//TODO(lajoie) see if we can validate the template at construction time
-
 /**
  * This is a helper class that wraps a velocity engine and template information into a single object. It provides
  * methods, {@link #fromTemplate()}, for evaluating literal templates as well as named templates. It also ensures that
@@ -142,6 +140,12 @@
                     "Velocity engine is not configured to load templates from the default StringResourceRepository");
         }
 
+        try {
+            engine.getTemplate(templateName);
+        } catch (VelocityException e) {
+            throw new VelocityException("The following template is not valid:\n" + trimmedTemplate, e);
+        }
+
         return new Template(engine, templateName, encoding.name());
     }
 
@@ -185,6 +189,12 @@
         if (!engine.resourceExists(name)) {
             throw new VelocityException("No template with the name " + trimmedName
                     + " is available to the velocity engine");
+        }
+
+        try {
+            engine.getTemplate(trimmedName);
+        } catch (VelocityException e) {
+            throw new VelocityException("Template '" + trimmedName + "' is not a valid template", e);
         }
 
         return new Template(engine, trimmedName, encoding.name());



More information about the commits mailing list