[java-identity-provider COMMIT] in /trunk/idp-attribute-resolver-impl/src: main/java/net/shibboleth/idp/attribute/res...
noreply at shibboleth.net
noreply at shibboleth.net
Wed Apr 17 14:56:53 EDT 2013
Author: rdw
Date: Wed Apr 17 14:56:53 2013
New Revision: 4408
URL: http://svn.shibboleth.net/view/java-identity-provider?rev=4408&view=rev
Log:
IDP-205 Template definition gets the velocity engine injected. Also the case where no template text is provided is aligned with the V2.x behavior. Test coverage for this and previous checkin.
Modified:
trunk/idp-attribute-resolver-impl/src/main/java/net/shibboleth/idp/attribute/resolver/impl/ad/TemplateAttributeDefinition.java
trunk/idp-attribute-resolver-impl/src/test/java/net/shibboleth/idp/attribute/resolver/impl/ad/TemplateAttributeTest.java
Modified: trunk/idp-attribute-resolver-impl/src/main/java/net/shibboleth/idp/attribute/resolver/impl/ad/TemplateAttributeDefinition.java
URL: http://svn.shibboleth.net/view/java-identity-provider/trunk/idp-attribute-resolver-impl/src/main/java/net/shibboleth/idp/attribute/resolver/impl/ad/TemplateAttributeDefinition.java?rev=4408&r1=4407&r2=4408&view=diff
==============================================================================
--- trunk/idp-attribute-resolver-impl/src/main/java/net/shibboleth/idp/attribute/resolver/impl/ad/TemplateAttributeDefinition.java (original)
+++ trunk/idp-attribute-resolver-impl/src/main/java/net/shibboleth/idp/attribute/resolver/impl/ad/TemplateAttributeDefinition.java Wed Apr 17 14:56:53 2013
@@ -42,10 +42,11 @@
import net.shibboleth.utilities.java.support.collection.LazyMap;
import net.shibboleth.utilities.java.support.component.ComponentInitializationException;
import net.shibboleth.utilities.java.support.component.ComponentSupport;
-import net.shibboleth.utilities.java.support.logic.Constraint;
+import net.shibboleth.utilities.java.support.primitive.StringSupport;
import net.shibboleth.utilities.java.support.velocity.Template;
import org.apache.velocity.VelocityContext;
+import org.apache.velocity.app.VelocityEngine;
import org.apache.velocity.exception.VelocityException;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -73,6 +74,12 @@
/** Template to be evaluated. */
private Template template;
+
+ /** Template (as Text) to be evaluated. */
+ private String templateText;
+
+ /** VelocityEngine. */
+ private VelocityEngine engine;
/** The names of the attributes we need. */
private List<String> sourceAttributes = Collections.EMPTY_LIST;
@@ -101,7 +108,7 @@
}
/**
- * Gets the template to be evaluated.
+ * Gets the template text to be evaluated.
*
* @return the template
*/
@@ -110,15 +117,45 @@
}
/**
+ * Gets the template text to be evaluated.
+ *
+ * @return the template
+ */
+ @Nullable public String getTemplateText() {
+ return templateText;
+ }
+
+ /**
* Sets the template to be evaluated.
*
* @param velocityTemplate template to be evaluated
*/
- public synchronized void setTemplate(@Nonnull Template velocityTemplate) {
+ public synchronized void setTemplateText(String velocityTemplate) {
ComponentSupport.ifInitializedThrowUnmodifiabledComponentException(this);
ComponentSupport.ifDestroyedThrowDestroyedComponentException(this);
- template = Constraint.isNotNull(velocityTemplate, "Template can not be null");
+ templateText = velocityTemplate;
+ }
+
+ /**
+ * Gets the {@link VelocityEngine} to be used.
+ *
+ * @return the template
+ */
+ @Nullable public VelocityEngine getVelocityEngine() {
+ return engine;
+ }
+
+ /**
+ * Sets the {@link VelocityEngine} to be used.
+ *
+ * @param velocityEngine engine to be used
+ */
+ public synchronized void setVelocityEngine(VelocityEngine velocityEngine) {
+ ComponentSupport.ifInitializedThrowUnmodifiabledComponentException(this);
+ ComponentSupport.ifDestroyedThrowDestroyedComponentException(this);
+
+ engine = velocityEngine;
}
/** {@inheritDoc} */
@@ -176,14 +213,33 @@
+ "': no dependencies were configured");
}
- if (null == template) {
+ if (null == engine) {
throw new ComponentInitializationException("Attribute definition '" + getId()
- + "': no template was configured");
+ + "': no velocity engine was configured" );
}
if (sourceAttributes.isEmpty()) {
log.info("Attribute Definition '{}': No Source Attributes supplied, was this intended?");
}
+
+ templateText = StringSupport.trimOrNull(templateText);
+
+ if (null == templateText) {
+ StringBuffer defaultTemplate = new StringBuffer();
+ for (String id : sourceAttributes) {
+ defaultTemplate.append("${").append(id).append("} ");
+ }
+ if (defaultTemplate.length() > 0) {
+ templateText = defaultTemplate.toString();
+ } else {
+ throw new ComponentInitializationException("Attribute definition '" + getId()
[... 142 lines stripped ...]
More information about the commits
mailing list