[java-shib-shared] branch main updated: Add some additional helpers for processing Spring XML.

Scott Cantor cantor.2 at osu.edu
Mon Nov 14 16:33:55 UTC 2022


This is an automated email from the git hooks/post-receive script.

scantor pushed a commit to branch main
in repository java-shib-shared.

View the commit online:
http://git.shibboleth.net/view/?p=java-shib-shared.git;a=commit;h=3a6651785482cf90ff000de53c519b8652542104

The following commit(s) were added to refs/heads/main by this push:
     new 3a665178 Add some additional helpers for processing Spring XML.
3a665178 is described below

commit 3a6651785482cf90ff000de53c519b8652542104
Author: Scott Cantor <cantor.2 at osu.edu>
AuthorDate: Mon Nov 14 11:33:53 2022 -0500

    Add some additional helpers for processing Spring XML.
---
 .../shared/spring/util/SpringSupport.java          | 11 ++++---
 .../shibboleth/shared/xml/AttributeSupport.java    | 36 ++++++++++++++++++++++
 2 files changed, 42 insertions(+), 5 deletions(-)

diff --git a/shib-spring/src/main/java/net/shibboleth/shared/spring/util/SpringSupport.java b/shib-spring/src/main/java/net/shibboleth/shared/spring/util/SpringSupport.java
index d2b33e0a..891007b0 100644
--- a/shib-spring/src/main/java/net/shibboleth/shared/spring/util/SpringSupport.java
+++ b/shib-spring/src/main/java/net/shibboleth/shared/spring/util/SpringSupport.java
@@ -283,14 +283,15 @@ public final class SpringSupport {
         result.addConstructorArgValue(XMLConstants.LIST_DELIMITERS);
         return result.getBeanDefinition();
     }
-    
+
     /**
-     * Gets the value of a boolean-type string as a (ptentially null) {@link Boolean}.
+     * Gets the value of a boolean-type string as a (potentially null) {@link Boolean}.
      * 
      * @param string value will be turned into a boolean (or null) (after property replacement)
-     * @return a bean which will generate a list of the values.
+     * 
+     * @return a bean which will generate the underlying value
      */
-    @Nullable public static AbstractBeanDefinition getStringValueAsBoolean(@Nullable final String string) {
+    @Nonnull public static AbstractBeanDefinition getStringValueAsBoolean(@Nullable final String string) {
         final BeanDefinitionBuilder result =
                 BeanDefinitionBuilder.rootBeanDefinition(StringSupport.class, "booleanOf");
         result.addConstructorArgValue(string);
@@ -332,7 +333,7 @@ public final class SpringSupport {
      * @return range returned from the browser request with the active Spring locale prepended
      */
     @Nonnull @NonnullElements @Unmodifiable
-    public static List<LanguageRange> getLanguageRange(final HttpServletRequest request) {
+    public static List<LanguageRange> getLanguageRange(@Nonnull final HttpServletRequest request) {
         final List<LanguageRange> fromBrowser = HttpServletSupport.getLanguageRange(request);
         final List<LanguageRange> outList = new ArrayList<>(1+fromBrowser.size());
 
diff --git a/shib-support/src/main/java/net/shibboleth/shared/xml/AttributeSupport.java b/shib-support/src/main/java/net/shibboleth/shared/xml/AttributeSupport.java
index 5221340b..8bbfa30c 100644
--- a/shib-support/src/main/java/net/shibboleth/shared/xml/AttributeSupport.java
+++ b/shib-support/src/main/java/net/shibboleth/shared/xml/AttributeSupport.java
@@ -26,6 +26,7 @@ import javax.annotation.Nonnull;
 import javax.annotation.Nullable;
 import javax.xml.namespace.QName;
 
+import net.shibboleth.shared.annotation.constraint.NotEmpty;
 import net.shibboleth.shared.logic.Constraint;
 import net.shibboleth.shared.primitive.StringSupport;
 
@@ -287,6 +288,41 @@ public final class AttributeSupport {
         return attr.getValue();
     }
 
+    /**
+     * Gets the trimmed value of an attribute from an element, ensuring it is not null or empty.
+     * 
+     * @param element the element from which to retrieve the attribute value
+     * @param namespace the namespace URI of the attribute
+     * @param attributeLocalName the local (unqualified) attribute name
+     * 
+     * @return the trimmed value of the attribute
+     * 
+     * @since 9.0.0
+     */
+    @Nonnull @NotEmpty public static String getRequiredAttributeValue(@Nullable final Element element,
+            @Nullable final String namespace, @Nonnull @NotEmpty final String attributeLocalName) {
+        return Constraint.isNotNull(StringSupport.trimOrNull(
+                getAttributeValue(element, namespace, attributeLocalName)),
+                attributeLocalName + " cannot be null or empty");
+    }
+
+    
+    /**
+     * Gets the trimmed value of an attribute from an element, ensuring it is not null or empty.
+     * 
+     * @param element the element from which to retrieve the attribute value
+     * @param attributeName the name of the attribute
+     * 
+     * @return the trimmed value of the attribute
+     * 
+     * @since 9.0.0
+     */
+    @Nonnull @NotEmpty public static String getRequiredAttributeValue(@Nullable final Element element,
+            @Nonnull final QName attributeName) {
+        return Constraint.isNotNull(StringSupport.trimOrNull(getAttributeValue(element, attributeName)),
+                attributeName.getLocalPart() + " cannot be null or empty");
+    }
+
     /**
      * Parses the attribute's value. If the value is 0 or "false" then false is returned, if the value is 1 or "true"
      * then true is returned, if the value is anything else then null returned.

-- 
To stop receiving notification emails like this one, please contact
the administrator of this repository.


More information about the commits mailing list