[java-shib-shared] branch main updated: Begin to tighten up inputs to some XML support methods.
Scott Cantor
cantor.2 at osu.edu
Tue Mar 7 15:52:37 UTC 2023
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=2083d1986328293e3a7aac1ffd15e85779b4005f
The following commit(s) were added to refs/heads/main by this push:
new 2083d198 Begin to tighten up inputs to some XML support methods.
2083d198 is described below
commit 2083d1986328293e3a7aac1ffd15e85779b4005f
Author: Scott Cantor <cantor.2 at osu.edu>
AuthorDate: Tue Mar 7 10:52:34 2023 -0500
Begin to tighten up inputs to some XML support methods.
---
.../spring/custom/BaseSpringNamespaceHandler.java | 2 +-
.../net/shibboleth/shared/xml/DOMTypeSupport.java | 36 +++++++++++-----------
.../net/shibboleth/shared/xml/QNameSupport.java | 6 +---
3 files changed, 20 insertions(+), 24 deletions(-)
diff --git a/shib-spring/src/main/java/net/shibboleth/shared/spring/custom/BaseSpringNamespaceHandler.java b/shib-spring/src/main/java/net/shibboleth/shared/spring/custom/BaseSpringNamespaceHandler.java
index 9fe219b9..bbf43b7a 100644
--- a/shib-spring/src/main/java/net/shibboleth/shared/spring/custom/BaseSpringNamespaceHandler.java
+++ b/shib-spring/src/main/java/net/shibboleth/shared/spring/custom/BaseSpringNamespaceHandler.java
@@ -153,7 +153,7 @@ public abstract class BaseSpringNamespaceHandler implements NamespaceHandler {
*
* @return the parser for the given bean element
*/
- protected BeanDefinitionParser findParserForElement(final Element element) {
+ protected BeanDefinitionParser findParserForElement(@Nonnull final Element element) {
BeanDefinitionParser parser = null;
final QName typeName = DOMTypeSupport.getXSIType(element);
diff --git a/shib-support/src/main/java/net/shibboleth/shared/xml/DOMTypeSupport.java b/shib-support/src/main/java/net/shibboleth/shared/xml/DOMTypeSupport.java
index d8c435b0..5e4cc780 100644
--- a/shib-support/src/main/java/net/shibboleth/shared/xml/DOMTypeSupport.java
+++ b/shib-support/src/main/java/net/shibboleth/shared/xml/DOMTypeSupport.java
@@ -40,10 +40,10 @@ import org.w3c.dom.Element;
public final class DOMTypeSupport {
/** JAXP DatatypeFactory. */
- private static DatatypeFactory dataTypeFactory;
+ @Nonnull private static final DatatypeFactory DATA_TYPE_FACTORY;
/** Baseline for duration calculations (comes from XML Schema standard). */
- private static Calendar baseline;
+ @Nonnull private static final Calendar BASELINE;
/** Constructor. */
private DOMTypeSupport() {
@@ -60,7 +60,7 @@ public final class DOMTypeSupport {
final String trimmedString =
Constraint.isNotNull(StringSupport.trimOrNull(dateTime), "Lexical dateTime may not be null or empty");
- final XMLGregorianCalendar calendar = dataTypeFactory.newXMLGregorianCalendar(trimmedString);
+ final XMLGregorianCalendar calendar = DATA_TYPE_FACTORY.newXMLGregorianCalendar(trimmedString);
return calendar.toGregorianCalendar().toInstant();
}
@@ -72,7 +72,7 @@ public final class DOMTypeSupport {
* @return duration in Java form
*/
public static Duration stringToDuration(@Nonnull final String duration) {
- return Duration.ofMillis(dataTypeFactory.newDuration(duration).getTimeInMillis(baseline));
+ return Duration.ofMillis(DATA_TYPE_FACTORY.newDuration(duration).getTimeInMillis(BASELINE));
}
/**
@@ -81,7 +81,7 @@ public final class DOMTypeSupport {
* @return the factory or null if the factory could not be created
*/
public static DatatypeFactory getDataTypeFactory() {
- return dataTypeFactory;
+ return DATA_TYPE_FACTORY;
}
/**
@@ -91,11 +91,13 @@ public final class DOMTypeSupport {
*
* @return the type or null
*/
- @Nullable public static QName getXSIType(@Nullable final Element e) {
- if (hasXSIType(e) && null != e) {
+ @Nullable public static QName getXSIType(@Nonnull final Element e) {
+ if (hasXSIType(e)) {
final Attr attribute = e.getAttributeNodeNS(XMLConstants.XSI_NS, "type");
- final String attributeValue = attribute.getTextContent().trim();
- return QNameSupport.constructQName(e, attributeValue);
+ final String attributeValue = StringSupport.trimOrNull(attribute.getTextContent());
+ if (attributeValue != null) {
+ return QNameSupport.constructQName(e, attributeValue);
+ }
}
return null;
}
@@ -107,11 +109,9 @@ public final class DOMTypeSupport {
*
* @return true if there is a type, false if not
*/
- public static boolean hasXSIType(@Nullable final Element e) {
- if (e != null) {
- if (e.getAttributeNodeNS(XMLConstants.XSI_NS, "type") != null) {
- return true;
- }
+ public static boolean hasXSIType(@Nonnull final Element e) {
+ if (e.getAttributeNodeNS(XMLConstants.XSI_NS, "type") != null) {
+ return true;
}
return false;
@@ -135,7 +135,7 @@ public final class DOMTypeSupport {
calendar.setTimeZone(TimeZone.getTimeZone("UTC"));
calendar.setTimeInMillis(dateTime.toEpochMilli());
- return dataTypeFactory.newXMLGregorianCalendar(calendar).normalize().toXMLFormat();
+ return DATA_TYPE_FACTORY.newXMLGregorianCalendar(calendar).normalize().toXMLFormat();
}
/**
@@ -146,13 +146,13 @@ public final class DOMTypeSupport {
* @return the lexical representation
*/
@Nonnull public static String durationToString(@Nonnull final Duration duration) {
- return dataTypeFactory.newDuration(duration.toMillis()).toString();
+ return DATA_TYPE_FACTORY.newDuration(duration.toMillis()).toString();
}
static {
try {
- dataTypeFactory = DatatypeFactory.newInstance();
- baseline = new GregorianCalendar(1696, 9, 1, 0, 0, 0);
+ DATA_TYPE_FACTORY = DatatypeFactory.newInstance();
+ BASELINE = new GregorianCalendar(1696, 9, 1, 0, 0, 0);
} catch (final DatatypeConfigurationException e) {
throw new RuntimeException("JVM is required to support XML DatatypeFactory but it does not", e);
}
diff --git a/shib-support/src/main/java/net/shibboleth/shared/xml/QNameSupport.java b/shib-support/src/main/java/net/shibboleth/shared/xml/QNameSupport.java
index 6b484434..65f206f2 100644
--- a/shib-support/src/main/java/net/shibboleth/shared/xml/QNameSupport.java
+++ b/shib-support/src/main/java/net/shibboleth/shared/xml/QNameSupport.java
@@ -93,11 +93,7 @@ public final class QNameSupport {
*
* @return the QName for the element or null if the element was null
*/
- @Nullable public static QName getNodeQName(@Nullable final Node domNode) {
- if (domNode == null) {
- return null;
- }
-
+ @Nonnull public static QName getNodeQName(@Nonnull final Node domNode) {
return constructQName(domNode.getNamespaceURI(), domNode.getLocalName(), domNode.getPrefix());
}
--
To stop receiving notification emails like this one, please contact
the administrator of this repository.
More information about the commits
mailing list