Format code with spring-javaformat

This commit configures the build to use spring-javaformat and makes a
first pass to format the code of the project. As part of this, imports
have been optimized, and the license header has been harmonized.

Closes gh-1458
This commit is contained in:
Stéphane Nicoll
2025-02-19 13:32:37 +01:00
parent ac71c3017b
commit fdede99aa0
679 changed files with 10401 additions and 7621 deletions

View File

@@ -1,11 +1,11 @@
/*
* Copyright 2005-2022 the original author or authors.
* Copyright 2005-2025 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
@@ -31,8 +31,8 @@ public class DocumentBuilderFactoryUtils {
private static final Log log = LogFactory.getLog(DocumentBuilderFactoryUtils.class);
/**
* Build a {@link DocumentBuilderFactory} then set properties to prevent external entity access.
*
* Build a {@link DocumentBuilderFactory} then set properties to prevent external
* entity access.
* @see DocumentBuilderFactory#newInstance()
*/
public static DocumentBuilderFactory newInstance() {
@@ -40,16 +40,18 @@ public class DocumentBuilderFactoryUtils {
try {
factory.setAttribute(XMLConstants.ACCESS_EXTERNAL_DTD, "");
} catch (IllegalArgumentException e) {
}
catch (IllegalArgumentException e) {
if (log.isWarnEnabled()) {
log.warn(
XMLConstants.ACCESS_EXTERNAL_DTD + " property not supported by " + factory.getClass().getCanonicalName());
log.warn(XMLConstants.ACCESS_EXTERNAL_DTD + " property not supported by "
+ factory.getClass().getCanonicalName());
}
}
try {
factory.setAttribute(XMLConstants.ACCESS_EXTERNAL_SCHEMA, "");
} catch (IllegalArgumentException e) {
}
catch (IllegalArgumentException e) {
if (log.isWarnEnabled()) {
log.warn(XMLConstants.ACCESS_EXTERNAL_SCHEMA + " property not supported by "
+ factory.getClass().getCanonicalName());
@@ -58,7 +60,8 @@ public class DocumentBuilderFactoryUtils {
try {
factory.setFeature("http://apache.org/xml/features/disallow-doctype-decl", true);
} catch (ParserConfigurationException e) {
}
catch (ParserConfigurationException e) {
if (log.isWarnEnabled()) {
log.warn("FEATURE 'http://apache.org/xml/features/disallow-doctype-decl' is probably not supported by "
+ factory.getClass().getCanonicalName());
@@ -67,7 +70,8 @@ public class DocumentBuilderFactoryUtils {
try {
factory.setFeature("http://xml.org/sax/features/external-general-entities", false);
} catch (ParserConfigurationException e) {
}
catch (ParserConfigurationException e) {
if (log.isWarnEnabled()) {
log.warn("FEATURE 'http://xml.org/sax/features/external-general-entities' is probably not supported by "
+ factory.getClass().getCanonicalName());
@@ -76,16 +80,19 @@ public class DocumentBuilderFactoryUtils {
try {
factory.setFeature("http://xml.org/sax/features/external-parameter-entities", false);
} catch (ParserConfigurationException e) {
}
catch (ParserConfigurationException e) {
if (log.isWarnEnabled()) {
log.warn("FEATURE 'http://xml.org/sax/features/external-parameter-entities' is probably not supported by "
+ factory.getClass().getCanonicalName());
log.warn(
"FEATURE 'http://xml.org/sax/features/external-parameter-entities' is probably not supported by "
+ factory.getClass().getCanonicalName());
}
}
try {
factory.setFeature("http://apache.org/xml/features/nonvalidating/load-external-dtd", false);
} catch (ParserConfigurationException e) {
}
catch (ParserConfigurationException e) {
if (log.isWarnEnabled()) {
log.warn(
"FEATURE 'http://apache.org/xml/features/nonvalidating/load-external-dtd' is probably not supported by "
@@ -96,7 +103,8 @@ public class DocumentBuilderFactoryUtils {
try {
factory.setXIncludeAware(false);
factory.setExpandEntityReferences(false);
} catch (Exception e) {
}
catch (Exception e) {
if (log.isWarnEnabled()) {
log.warn("Caught " + e.getMessage() + " attempting to configure your XML parser.");
}
@@ -104,4 +112,5 @@ public class DocumentBuilderFactoryUtils {
return factory;
}
}

View File

@@ -1,11 +1,11 @@
/*
* Copyright 2005-2022 the original author or authors.
* Copyright 2005-2025 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
@@ -19,11 +19,11 @@ package org.springframework.xml;
import org.springframework.util.ClassUtils;
/**
* Helper class used to find the current version of JAXP. We cannot depend on the Java version, since JAXP can be
* upgraded independently of the Java version.
* Helper class used to find the current version of JAXP. We cannot depend on the Java
* version, since JAXP can be upgraded independently of the Java version.
* <p>
* Only distinguishes between JAXP 1.0, 1.1, 1.3, 1.4, and 1.5, since JAXP 1.2 was a maintenance release with no new
* classes.
* Only distinguishes between JAXP 1.0, 1.1, 1.3, 1.4, and 1.5, since JAXP 1.2 was a
* maintenance release with no new classes.
*
* @author Arjen Poutsma
* @author Greg Turnquist
@@ -68,11 +68,13 @@ public abstract class JaxpVersion {
try {
ClassUtils.forName(JAXP_15_CLASS_NAME, classLoader);
jaxpVersion = JAXP_15;
} catch (ClassNotFoundException ex) {
}
catch (ClassNotFoundException ex) {
try {
ClassUtils.forName(JAXP_14_CLASS_NAME, classLoader);
jaxpVersion = JAXP_14;
} catch (ClassNotFoundException e) {
}
catch (ClassNotFoundException e) {
// leave 1.3 as default (it's either 1.3 or unknown)
jaxpVersion = JAXP_13;
}
@@ -80,8 +82,8 @@ public abstract class JaxpVersion {
}
/**
* Gets the JAXP version. This means we can do things like if {@code (getJaxpVersion() < JAXP_13)}.
*
* Gets the JAXP version. This means we can do things like if
* {@code (getJaxpVersion() < JAXP_13)}.
* @return a code comparable to the JAXP_XX codes in this class
* @see #JAXP_10
* @see #JAXP_11
@@ -94,8 +96,8 @@ public abstract class JaxpVersion {
}
/**
* Convenience method to determine if the current JAXP version is at least 1.4 (packaged with JDK 1.6).
*
* Convenience method to determine if the current JAXP version is at least 1.4
* (packaged with JDK 1.6).
* @return {@code true} if the current JAXP version is at least JAXP 1.4
* @see #getJaxpVersion()
* @see #JAXP_14

View File

@@ -1,11 +1,11 @@
/*
* Copyright 2005-2022 the original author or authors.
* Copyright 2005-2025 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
@@ -23,8 +23,8 @@ import javax.xml.stream.XMLInputFactory;
public class XMLInputFactoryUtils {
/**
* Build an {@link XMLInputFactory} and set properties to prevent external entities from accessing.
*
* Build an {@link XMLInputFactory} and set properties to prevent external entities
* from accessing.
* @see XMLInputFactory#newInstance()
*/
public static XMLInputFactory newInstance() {

View File

@@ -1,11 +1,11 @@
/*
* Copyright 2005-2022 the original author or authors.
* Copyright 2005-2025 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
@@ -28,8 +28,8 @@ import org.springframework.core.NestedRuntimeException;
public abstract class XmlException extends NestedRuntimeException {
/**
* Constructs a new instance of the {@code XmlException} with the specific detail message.
*
* Constructs a new instance of the {@code XmlException} with the specific detail
* message.
* @param message the detail message
*/
protected XmlException(String message) {
@@ -37,12 +37,13 @@ public abstract class XmlException extends NestedRuntimeException {
}
/**
* Constructs a new instance of the {@code XmlException} with the specific detail message and exception.
*
* Constructs a new instance of the {@code XmlException} with the specific detail
* message and exception.
* @param message the detail message
* @param throwable the wrapped exception
*/
protected XmlException(String message, Throwable throwable) {
super(message, throwable);
}
}

View File

@@ -1,11 +1,11 @@
/*
* Copyright 2005-2022 the original author or authors.
* Copyright 2005-2025 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
@@ -19,7 +19,6 @@ package org.springframework.xml.dom;
import java.util.ArrayList;
import java.util.List;
import org.springframework.util.Assert;
import org.w3c.dom.Document;
import org.w3c.dom.Element;
import org.w3c.dom.Node;
@@ -30,6 +29,8 @@ import org.xml.sax.ContentHandler;
import org.xml.sax.Locator;
import org.xml.sax.SAXException;
import org.springframework.util.Assert;
/**
* SAX {@code ContentHandler} that transforms callback calls to DOM {@code Node}s.
*
@@ -47,7 +48,6 @@ public class DomContentHandler implements ContentHandler {
/**
* Creates a new instance of the {@code DomContentHandler} with the given node.
*
* @param node the node to publish events to
*/
public DomContentHandler(Node node) {
@@ -55,7 +55,8 @@ public class DomContentHandler implements ContentHandler {
this.node = node;
if (node instanceof Document) {
document = (Document) node;
} else {
}
else {
document = node.getOwnerDocument();
}
Assert.notNull(document, "document must not be null");
@@ -64,7 +65,8 @@ public class DomContentHandler implements ContentHandler {
private Node getParent() {
if (!elements.isEmpty()) {
return elements.get(elements.size() - 1);
} else {
}
else {
return node;
}
}
@@ -97,7 +99,8 @@ public class DomContentHandler implements ContentHandler {
Node lastChild = parent.getLastChild();
if (lastChild != null && lastChild.getNodeType() == Node.TEXT_NODE) {
((Text) lastChild).appendData(data);
} else {
}
else {
Text text = document.createTextNode(data);
parent.appendChild(text);
}
@@ -115,23 +118,31 @@ public class DomContentHandler implements ContentHandler {
*/
@Override
public void setDocumentLocator(Locator locator) {}
public void setDocumentLocator(Locator locator) {
}
@Override
public void startDocument() throws SAXException {}
public void startDocument() throws SAXException {
}
@Override
public void endDocument() throws SAXException {}
public void endDocument() throws SAXException {
}
@Override
public void startPrefixMapping(String prefix, String uri) throws SAXException {}
public void startPrefixMapping(String prefix, String uri) throws SAXException {
}
@Override
public void endPrefixMapping(String prefix) throws SAXException {}
public void endPrefixMapping(String prefix) throws SAXException {
}
@Override
public void ignorableWhitespace(char ch[], int start, int length) throws SAXException {}
public void ignorableWhitespace(char ch[], int start, int length) throws SAXException {
}
@Override
public void skippedEntity(String name) throws SAXException {}
public void skippedEntity(String name) throws SAXException {
}
}

View File

@@ -1,11 +1,11 @@
/*
* Copyright 2005-2022 the original author or authors.
* Copyright 2005-2025 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
@@ -23,7 +23,8 @@ import javax.xml.namespace.QName;
import org.springframework.util.StringUtils;
/**
* PropertyEditor for {@code javax.xml.namespace.QName}, to populate a property of type QName from a String value.
* PropertyEditor for {@code javax.xml.namespace.QName}, to populate a property of type
* QName from a String value.
* <p>
* Expects the syntax
*
@@ -43,8 +44,8 @@ import org.springframework.util.StringUtils;
* {namespace}prefix:localPart
* </pre>
*
* This resembles the {@code toString()} representation of {@code QName} itself, but allows for prefixes to be specified
* as well.
* This resembles the {@code toString()} representation of {@code QName} itself, but
* allows for prefixes to be specified as well.
*
* @author Arjen Poutsma
* @see javax.xml.namespace.QName
@@ -66,13 +67,17 @@ public class QNameEditor extends PropertyEditorSupport {
String prefix = qName.getPrefix();
if (StringUtils.hasLength(qName.getNamespaceURI()) && StringUtils.hasLength(prefix)) {
return "{" + qName.getNamespaceURI() + "}" + prefix + ":" + qName.getLocalPart();
} else if (StringUtils.hasLength(qName.getNamespaceURI())) {
}
else if (StringUtils.hasLength(qName.getNamespaceURI())) {
return "{" + qName.getNamespaceURI() + "}" + qName.getLocalPart();
} else {
}
else {
return qName.getLocalPart();
}
} else {
}
else {
return "";
}
}
}

View File

@@ -1,11 +1,11 @@
/*
* Copyright 2005-2022 the original author or authors.
* Copyright 2005-2025 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
@@ -18,9 +18,10 @@ package org.springframework.xml.namespace;
import javax.xml.namespace.QName;
import org.w3c.dom.Node;
import org.springframework.util.Assert;
import org.springframework.util.StringUtils;
import org.w3c.dom.Node;
/**
* Helper class for using {@link QName}.
@@ -32,10 +33,10 @@ import org.w3c.dom.Node;
public abstract class QNameUtils {
/**
* Creates a new {@code QName} with the given parameters. Sets the prefix if possible, i.e. if the
* {@code QName(String, String, String)} constructor can be found. If this constructor is not available (as is the
* case on older implementations of JAX-RPC), the prefix is ignored.
*
* Creates a new {@code QName} with the given parameters. Sets the prefix if possible,
* i.e. if the {@code QName(String, String, String)} constructor can be found. If this
* constructor is not available (as is the case on older implementations of JAX-RPC),
* the prefix is ignored.
* @param namespaceUri namespace URI of the {@code QName}
* @param localPart local part of the {@code QName}
* @param prefix prefix of the {@code QName}. May be ignored.
@@ -49,10 +50,10 @@ public abstract class QNameUtils {
}
/**
* Returns the prefix of the given {@code QName}. Returns the prefix if available, i.e. if the
* {@code QName.getPrefix()} method can be found. If this method is not available (as is the case on older
* implementations of JAX-RPC), an empty string is returned.
*
* Returns the prefix of the given {@code QName}. Returns the prefix if available,
* i.e. if the {@code QName.getPrefix()} method can be found. If this method is not
* available (as is the case on older implementations of JAX-RPC), an empty string is
* returned.
* @param qName the {@code QName} to return the prefix from
* @return the prefix, if available, or an empty string
* @see javax.xml.namespace.QName#getPrefix()
@@ -65,7 +66,6 @@ public abstract class QNameUtils {
/**
* Validates the given String as a QName
*
* @param text the qualified name
* @return {@code true} if valid, {@code false} otherwise
*/
@@ -85,27 +85,29 @@ public abstract class QNameUtils {
/**
* Returns the qualified name of the given DOM Node.
*
* @param node the node
* @return the qualified name of the node
*/
public static QName getQNameForNode(Node node) {
if (node.getNamespaceURI() != null && node.getPrefix() != null && node.getLocalName() != null) {
return new QName(node.getNamespaceURI(), node.getLocalName(), node.getPrefix());
} else if (node.getNamespaceURI() != null && node.getLocalName() != null) {
}
else if (node.getNamespaceURI() != null && node.getLocalName() != null) {
return new QName(node.getNamespaceURI(), node.getLocalName());
} else if (node.getLocalName() != null) {
}
else if (node.getLocalName() != null) {
return new QName(node.getLocalName());
} else {
}
else {
// as a last resort, use the node name
return new QName(node.getNodeName());
}
}
/**
* Convert a {@code QName} to a qualified name, as used by DOM and SAX. The returned string has a format of
* {@code prefix:localName} if the prefix is set, or just {@code localName} if not.
*
* Convert a {@code QName} to a qualified name, as used by DOM and SAX. The returned
* string has a format of {@code prefix:localName} if the prefix is set, or just
* {@code localName} if not.
* @param qName the {@code QName}
* @return the qualified name
*/
@@ -113,15 +115,15 @@ public abstract class QNameUtils {
String prefix = qName.getPrefix();
if (!StringUtils.hasLength(prefix)) {
return qName.getLocalPart();
} else {
}
else {
return prefix + ":" + qName.getLocalPart();
}
}
/**
* Convert a namespace URI and DOM or SAX qualified name to a {@code QName}. The qualified name can have the form
* {@code prefix:localname} or {@code localName}.
*
* Convert a namespace URI and DOM or SAX qualified name to a {@code QName}. The
* qualified name can have the form {@code prefix:localname} or {@code localName}.
* @param namespaceUri the namespace URI
* @param qualifiedName the qualified name
* @return a QName
@@ -130,16 +132,18 @@ public abstract class QNameUtils {
int idx = qualifiedName.indexOf(':');
if (idx == -1) {
return new QName(namespaceUri, qualifiedName);
} else {
}
else {
return new QName(namespaceUri, qualifiedName.substring(idx + 1), qualifiedName.substring(0, idx));
}
}
/**
* Parse the given qualified name string into a {@code QName}. Expects the syntax {@code localPart},
* {@code {namespace}localPart}, or {@code {namespace}prefix:localPart}. This format resembles the {@code toString()}
* representation of {@code QName} itself, but allows for prefixes to be specified as well.
*
* Parse the given qualified name string into a {@code QName}. Expects the syntax
* {@code localPart}, {@code {namespace}localPart}, or
* {@code {namespace}prefix:localPart}. This format resembles the {@code toString()}
* representation of {@code QName} itself, but allows for prefixes to be specified as
* well.
* @return a corresponding QName instance
* @throws IllegalArgumentException when the given string is {@code null} or empty.
*/
@@ -147,16 +151,19 @@ public abstract class QNameUtils {
Assert.hasLength(qNameString, "QName text may not be null or empty");
if (qNameString.charAt(0) != '{') {
return new QName(qNameString);
} else {
}
else {
int endOfNamespaceURI = qNameString.indexOf('}');
if (endOfNamespaceURI == -1) {
throw new IllegalArgumentException("Cannot create QName from \"" + qNameString + "\", missing closing \"}\"");
throw new IllegalArgumentException(
"Cannot create QName from \"" + qNameString + "\", missing closing \"}\"");
}
int prefixSeperator = qNameString.indexOf(':', endOfNamespaceURI + 1);
String namespaceURI = qNameString.substring(1, endOfNamespaceURI);
if (prefixSeperator == -1) {
return new QName(namespaceURI, qNameString.substring(endOfNamespaceURI + 1));
} else {
}
else {
return new QName(namespaceURI, qNameString.substring(prefixSeperator + 1),
qNameString.substring(endOfNamespaceURI + 1, prefixSeperator));
}

View File

@@ -1,11 +1,11 @@
/*
* Copyright 2005-2022 the original author or authors.
* Copyright 2005-2025 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
@@ -30,8 +30,9 @@ import javax.xml.namespace.NamespaceContext;
import org.springframework.util.Assert;
/**
* Simple {@code javax.xml.namespace.NamespaceContext} implementation. Follows the standard {@code NamespaceContext}
* contract, and is loadable via a {@code java.util.Map} or {@code java.util.Properties} object
* Simple {@code javax.xml.namespace.NamespaceContext} implementation. Follows the
* standard {@code NamespaceContext} contract, and is loadable via a {@code java.util.Map}
* or {@code java.util.Properties} object
*
* @author Arjen Poutsma
* @since 1.0.0
@@ -47,9 +48,11 @@ public class SimpleNamespaceContext implements NamespaceContext {
Assert.notNull(prefix, "prefix is null");
if (XMLConstants.XML_NS_PREFIX.equals(prefix)) {
return XMLConstants.XML_NS_URI;
} else if (XMLConstants.XMLNS_ATTRIBUTE.equals(prefix)) {
}
else if (XMLConstants.XMLNS_ATTRIBUTE.equals(prefix)) {
return XMLConstants.XMLNS_ATTRIBUTE_NS_URI;
} else if (prefixToNamespaceUri.containsKey(prefix)) {
}
else if (prefixToNamespaceUri.containsKey(prefix)) {
return prefixToNamespaceUri.get(prefix);
}
return XMLConstants.NULL_NS_URI;
@@ -69,8 +72,8 @@ public class SimpleNamespaceContext implements NamespaceContext {
}
/**
* Sets the bindings for this namespace context. The supplied map must consist of string key value pairs.
*
* Sets the bindings for this namespace context. The supplied map must consist of
* string key value pairs.
* @param bindings the bindings
*/
public void setBindings(Map<String, String> bindings) {
@@ -81,7 +84,6 @@ public class SimpleNamespaceContext implements NamespaceContext {
/**
* Binds the given namespace as default namespace.
*
* @param namespaceUri the namespace uri
*/
public void bindDefaultNamespaceUri(String namespaceUri) {
@@ -90,7 +92,6 @@ public class SimpleNamespaceContext implements NamespaceContext {
/**
* Binds the given prefix to the given namespace.
*
* @param prefix the namespace prefix
* @param namespaceUri the namespace uri
*/
@@ -98,13 +99,15 @@ public class SimpleNamespaceContext implements NamespaceContext {
Assert.notNull(prefix, "No prefix given");
Assert.notNull(namespaceUri, "No namespaceUri given");
if (XMLConstants.XML_NS_PREFIX.equals(prefix)) {
Assert.isTrue(XMLConstants.XML_NS_URI.equals(namespaceUri), "Prefix \"" + prefix + "\" bound to namespace \""
+ namespaceUri + "\" (should be \"" + XMLConstants.XML_NS_URI + "\")");
} else if (XMLConstants.XMLNS_ATTRIBUTE.equals(prefix)) {
Assert.isTrue(XMLConstants.XML_NS_URI.equals(namespaceUri), "Prefix \"" + prefix
+ "\" bound to namespace \"" + namespaceUri + "\" (should be \"" + XMLConstants.XML_NS_URI + "\")");
}
else if (XMLConstants.XMLNS_ATTRIBUTE.equals(prefix)) {
Assert.isTrue(XMLConstants.XMLNS_ATTRIBUTE_NS_URI.equals(namespaceUri),
"Prefix \"" + prefix + "\" bound to namespace \"" + namespaceUri + "\" (should be \""
+ XMLConstants.XMLNS_ATTRIBUTE_NS_URI + "\")");
} else {
}
else {
prefixToNamespaceUri.put(prefix, namespaceUri);
getPrefixesInternal(namespaceUri).add(prefix);
}
@@ -118,7 +121,6 @@ public class SimpleNamespaceContext implements NamespaceContext {
/**
* Returns all declared prefixes.
*
* @return the declared prefixes
*/
public Iterator<String> getBoundPrefixes() {
@@ -131,7 +133,8 @@ public class SimpleNamespaceContext implements NamespaceContext {
private Set<String> getPrefixesInternal(String namespaceUri) {
if (XMLConstants.XML_NS_URI.equals(namespaceUri)) {
return Collections.singleton(XMLConstants.XML_NS_PREFIX);
} else if (XMLConstants.XMLNS_ATTRIBUTE_NS_URI.equals(namespaceUri)) {
}
else if (XMLConstants.XMLNS_ATTRIBUTE_NS_URI.equals(namespaceUri)) {
return Collections.singleton(XMLConstants.XMLNS_ATTRIBUTE);
}
return namespaceUriToPrefixes.computeIfAbsent(namespaceUri, k -> new LinkedHashSet<>());
@@ -139,7 +142,6 @@ public class SimpleNamespaceContext implements NamespaceContext {
/**
* Removes the given prefix from this context.
*
* @param prefix the prefix to be removed
*/
public void removeBinding(String prefix) {
@@ -153,4 +155,5 @@ public class SimpleNamespaceContext implements NamespaceContext {
public boolean hasBinding(String prefix) {
return prefixToNamespaceUri.containsKey(prefix);
}
}

View File

@@ -1,11 +1,11 @@
/*
* Copyright 2005-2022 the original author or authors.
* Copyright 2005-2025 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
@@ -26,8 +26,8 @@ import org.xml.sax.XMLReader;
import org.xml.sax.ext.LexicalHandler;
/**
* Abstract base class for SAX {@code XMLReader} implementations. Contains properties as defined in {@link XMLReader},
* and does not recognize any features
* Abstract base class for SAX {@code XMLReader} implementations. Contains properties as
* defined in {@link XMLReader}, and does not recognize any features
*
* @author Arjen Poutsma
* @see #setContentHandler(org.xml.sax.ContentHandler)
@@ -94,7 +94,6 @@ public abstract class AbstractXmlReader implements XMLReader {
/**
* Throws a {@code SAXNotRecognizedException} exception.
*
* @throws org.xml.sax.SAXNotRecognizedException always
*/
@Override
@@ -104,7 +103,6 @@ public abstract class AbstractXmlReader implements XMLReader {
/**
* Throws a {@code SAXNotRecognizedException} exception.
*
* @throws SAXNotRecognizedException always
*/
@Override
@@ -113,28 +111,33 @@ public abstract class AbstractXmlReader implements XMLReader {
}
/**
* Throws a {@code SAXNotRecognizedException} exception when the given property does not signify a lexical handler.
* The property name for a lexical handler is {@code http://xml.org/sax/properties/lexical-handler}.
* Throws a {@code SAXNotRecognizedException} exception when the given property does
* not signify a lexical handler. The property name for a lexical handler is
* {@code http://xml.org/sax/properties/lexical-handler}.
*/
@Override
public Object getProperty(String name) throws SAXNotRecognizedException, SAXNotSupportedException {
if ("http://xml.org/sax/properties/lexical-handler".equals(name)) {
return lexicalHandler;
} else {
}
else {
throw new SAXNotRecognizedException(name);
}
}
/**
* Throws a {@code SAXNotRecognizedException} exception when the given property does not signify a lexical handler.
* The property name for a lexical handler is {@code http://xml.org/sax/properties/lexical-handler}.
* Throws a {@code SAXNotRecognizedException} exception when the given property does
* not signify a lexical handler. The property name for a lexical handler is
* {@code http://xml.org/sax/properties/lexical-handler}.
*/
@Override
public void setProperty(String name, Object value) throws SAXNotRecognizedException, SAXNotSupportedException {
if ("http://xml.org/sax/properties/lexical-handler".equals(name)) {
lexicalHandler = (LexicalHandler) value;
} else {
}
else {
throw new SAXNotRecognizedException(name);
}
}
}

View File

@@ -1,11 +1,11 @@
/*
* Copyright 2005-2022 the original author or authors.
* Copyright 2005-2025 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
@@ -22,9 +22,10 @@ import java.net.URISyntaxException;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.springframework.core.io.Resource;
import org.xml.sax.InputSource;
import org.springframework.core.io.Resource;
/**
* Convenient utility methods for dealing with SAX.
*
@@ -36,9 +37,8 @@ public abstract class SaxUtils {
private static final Log logger = LogFactory.getLog(SaxUtils.class);
/**
* Creates a SAX {@code InputSource} from the given resource. Sets the system identifier to the resource's
* {@code URL}, if available.
*
* Creates a SAX {@code InputSource} from the given resource. Sets the system
* identifier to the resource's {@code URL}, if available.
* @param resource the resource
* @return the input source created from the resource
* @throws IOException if an I/O exception occurs
@@ -51,11 +51,15 @@ public abstract class SaxUtils {
return inputSource;
}
/** Retrieves the URL from the given resource as System ID. Returns {@code null} if it cannot be opened. */
/**
* Retrieves the URL from the given resource as System ID. Returns {@code null} if it
* cannot be opened.
*/
public static String getSystemId(Resource resource) {
try {
return new URI(resource.getURL().toExternalForm()).toString();
} catch (IOException | URISyntaxException ex) {
}
catch (IOException | URISyntaxException ex) {
logger.debug("Could not get System ID from [" + resource + "], ex");
return null;
}

View File

@@ -1,11 +1,11 @@
/*
* Copyright 2005-2022 the original author or authors.
* Copyright 2005-2025 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
@@ -20,13 +20,14 @@ import java.io.IOException;
import javax.xml.transform.sax.SAXSource;
import org.springframework.core.io.Resource;
import org.springframework.xml.sax.SaxUtils;
import org.xml.sax.XMLReader;
import org.springframework.core.io.Resource;
import org.springframework.xml.sax.SaxUtils;
/**
* Convenient subclass of {@link SAXSource} that reads from a Spring {@link Resource}. The resource to be read can be
* set via the constructor.
* Convenient subclass of {@link SAXSource} that reads from a Spring {@link Resource}. The
* resource to be read can be set via the constructor.
*
* @author Arjen Poutsma
* @since 1.0.0
@@ -35,7 +36,6 @@ public class ResourceSource extends SAXSource {
/**
* Initializes a new instance of the {@code ResourceSource} with the given resource.
*
* @param content the content
*/
public ResourceSource(Resource content) throws IOException {
@@ -43,11 +43,12 @@ public class ResourceSource extends SAXSource {
}
/**
* Initializes a new instance of the {@code ResourceSource} with the given {@link XMLReader} and resource.
*
* Initializes a new instance of the {@code ResourceSource} with the given
* {@link XMLReader} and resource.
* @param content the content
*/
public ResourceSource(XMLReader reader, Resource content) throws IOException {
super(reader, SaxUtils.createInputSource(content));
}
}

View File

@@ -1,11 +1,11 @@
/*
* Copyright 2005-2022 the original author or authors.
* Copyright 2005-2025 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
@@ -21,8 +21,8 @@ import java.io.StringWriter;
import javax.xml.transform.stream.StreamResult;
/**
* Convenient subclass of {@code StreamResult} that writes to a {@code StringWriter}. The resulting string can be
* retrieved via {@code toString()}.
* Convenient subclass of {@code StreamResult} that writes to a {@code StringWriter}. The
* resulting string can be retrieved via {@code toString()}.
*
* @author Arjen Poutsma
* @see #toString()

View File

@@ -1,11 +1,11 @@
/*
* Copyright 2005-2022 the original author or authors.
* Copyright 2005-2025 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
@@ -25,8 +25,8 @@ import javax.xml.transform.stream.StreamSource;
import org.springframework.util.Assert;
/**
* Convenient subclass of {@code StreamSource} that reads from a {@code StringReader}. The string to be read can be set
* via the constructor.
* Convenient subclass of {@code StreamSource} that reads from a {@code StringReader}. The
* string to be read can be set via the constructor.
*
* @author Arjen Poutsma
* @since 1.0.0
@@ -36,8 +36,8 @@ public class StringSource extends StreamSource {
private final String content;
/**
* Initializes a new instance of the {@code StringSource} with the given string content.
*
* Initializes a new instance of the {@code StringSource} with the given string
* content.
* @param content the content
*/
public StringSource(String content) {
@@ -52,7 +52,6 @@ public class StringSource extends StreamSource {
/**
* Throws {@link UnsupportedOperationException}.
*
* @throws UnsupportedOperationException always
*/
@Override
@@ -62,7 +61,6 @@ public class StringSource extends StreamSource {
/**
* Returns {@code null}.
*
* @return {@code null}
*/
@Override
@@ -72,7 +70,6 @@ public class StringSource extends StreamSource {
/**
* Throws {@link UnsupportedOperationException}.
*
* @throws UnsupportedOperationException always
*/
@Override
@@ -84,4 +81,5 @@ public class StringSource extends StreamSource {
public String toString() {
return content;
}
}

View File

@@ -1,11 +1,11 @@
/*
* Copyright 2005-2022 the original author or authors.
* Copyright 2005-2025 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
@@ -39,13 +39,13 @@ public class TransformerFactoryUtils {
/**
* Build an {@link TransformerFactory} and prevent external entities from accessing.
*
* @see TransformerFactory#newInstance()
*/
public static TransformerFactory newInstance(Class<? extends TransformerFactory> transformerFactoryClass) {
try {
return defaultSettings(transformerFactoryClass.newInstance());
} catch (InstantiationException | IllegalAccessException e) {
}
catch (InstantiationException | IllegalAccessException e) {
throw new TransformerFactoryConfigurationError(e,
"Could not instantiate TransformerFactory [" + transformerFactoryClass + "]");
}
@@ -57,16 +57,18 @@ public class TransformerFactoryUtils {
private static TransformerFactory defaultSettings(TransformerFactory factory) {
try {
factory.setAttribute(XMLConstants.ACCESS_EXTERNAL_DTD, "");
} catch (IllegalArgumentException e) {
}
catch (IllegalArgumentException e) {
if (log.isWarnEnabled()) {
log.warn(
XMLConstants.ACCESS_EXTERNAL_DTD + " property not supported by " + factory.getClass().getCanonicalName());
log.warn(XMLConstants.ACCESS_EXTERNAL_DTD + " property not supported by "
+ factory.getClass().getCanonicalName());
}
}
try {
factory.setAttribute(XMLConstants.ACCESS_EXTERNAL_STYLESHEET, "");
} catch (IllegalArgumentException e) {
}
catch (IllegalArgumentException e) {
if (log.isWarnEnabled()) {
log.warn(XMLConstants.ACCESS_EXTERNAL_STYLESHEET + " property not supported by "
+ factory.getClass().getCanonicalName());
@@ -75,4 +77,5 @@ public class TransformerFactoryUtils {
return factory;
}
}

View File

@@ -1,11 +1,11 @@
/*
* Copyright 2005-2022 the original author or authors.
* Copyright 2005-2025 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
@@ -41,17 +41,20 @@ public class TransformerHelper {
/**
* Initializes a new instance of the {@code TransformerHelper}.
*/
public TransformerHelper() {}
public TransformerHelper() {
}
/**
* Initializes a new instance of the {@code TransformerHelper} with the specified {@link TransformerFactory}.
* Initializes a new instance of the {@code TransformerHelper} with the specified
* {@link TransformerFactory}.
*/
public TransformerHelper(TransformerFactory transformerFactory) {
this.transformerFactory = transformerFactory;
}
/**
* Initializes a new instance of the {@code TransformerHelper} with the specified {@link TransformerFactory} class.
* Initializes a new instance of the {@code TransformerHelper} with the specified
* {@link TransformerFactory} class.
*/
public TransformerHelper(Class<? extends TransformerFactory> transformerFactoryClass) {
setTransformerFactoryClass(transformerFactoryClass);
@@ -68,12 +71,11 @@ public class TransformerHelper {
/**
* Instantiate a new TransformerFactory.
* <p>
* The default implementation simply calls {@link TransformerFactory#newInstance()}. If a
* {@link #setTransformerFactoryClass transformerFactoryClass} has been specified explicitly, the default constructor
* of the specified class will be called instead.
* The default implementation simply calls {@link TransformerFactory#newInstance()}.
* If a {@link #setTransformerFactoryClass transformerFactoryClass} has been specified
* explicitly, the default constructor of the specified class will be called instead.
* <p>
* Can be overridden in subclasses.
*
* @param transformerFactoryClass the specified factory class (if any)
* @return the new TransactionFactory instance
* @see #setTransformerFactoryClass
@@ -82,14 +84,14 @@ public class TransformerHelper {
protected TransformerFactory newTransformerFactory(Class<? extends TransformerFactory> transformerFactoryClass) {
if (transformerFactoryClass != null) {
return TransformerFactoryUtils.newInstance(transformerFactoryClass);
} else {
}
else {
return TransformerFactoryUtils.newInstance();
}
}
/**
* Returns the {@code TransformerFactory}.
*
* @return the transformer factory
*/
public TransformerFactory getTransformerFactory() {
@@ -106,8 +108,8 @@ public class TransformerHelper {
}
/**
* Creates a new {@code Transformer}. Must be called per thread, as transformers are not thread-safe.
*
* Creates a new {@code Transformer}. Must be called per thread, as transformers are
* not thread-safe.
* @return the created transformer
* @throws TransformerConfigurationException if thrown by JAXP methods
*/
@@ -116,9 +118,8 @@ public class TransformerHelper {
}
/**
* Transforms the given {@link Source} to the given {@link Result}. Creates a new {@link Transformer} for every call,
* as transformers are not thread-safe.
*
* Transforms the given {@link Source} to the given {@link Result}. Creates a new
* {@link Transformer} for every call, as transformers are not thread-safe.
* @param source the source to transform from
* @param result the result to transform to
* @throws TransformerException if thrown by JAXP methods

View File

@@ -1,11 +1,11 @@
/*
* Copyright 2005-2022 the original author or authors.
* Copyright 2005-2025 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
@@ -27,9 +27,10 @@ import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
/**
* Convenient base class for objects that use a {@code Transformer}. Subclasses can call {@link #createTransformer()} or
* {@link #transform(Source, Result)}. This should be done per thread (i.e. per incoming request), because
* {@code Transformer} instances are not thread-safe.
* Convenient base class for objects that use a {@code Transformer}. Subclasses can call
* {@link #createTransformer()} or {@link #transform(Source, Result)}. This should be done
* per thread (i.e. per incoming request), because {@code Transformer} instances are not
* thread-safe.
*
* @author Arjen Poutsma
* @see Transformer
@@ -54,12 +55,12 @@ public abstract class TransformerObjectSupport {
/**
* Instantiate a new TransformerFactory.
* <p>
* The default implementation simply calls {@link TransformerFactory#newInstance()}. If a
* {@link #setTransformerFactoryClass "transformerFactoryClass"} has been specified explicitly, the default
* constructor of the specified class will be called instead.
* The default implementation simply calls {@link TransformerFactory#newInstance()}.
* If a {@link #setTransformerFactoryClass "transformerFactoryClass"} has been
* specified explicitly, the default constructor of the specified class will be called
* instead.
* <p>
* Can be overridden in subclasses.
*
* @param transformerFactoryClass the specified factory class (if any)
* @return the new TransactionFactory instance
* @see #setTransformerFactoryClass
@@ -77,8 +78,8 @@ public abstract class TransformerObjectSupport {
}
/**
* Creates a new {@code Transformer}. Must be called per request, as transformers are not thread-safe.
*
* Creates a new {@code Transformer}. Must be called per request, as transformers are
* not thread-safe.
* @return the created transformer
* @throws TransformerConfigurationException if thrown by JAXP methods
*/
@@ -87,9 +88,8 @@ public abstract class TransformerObjectSupport {
}
/**
* Transforms the given {@link Source} to the given {@link Result}. Creates a new {@link Transformer} for every call,
* as transformers are not thread-safe.
*
* Transforms the given {@link Source} to the given {@link Result}. Creates a new
* {@link Transformer} for every call, as transformers are not thread-safe.
* @param source the source to transform from
* @param result the result to transform to
* @throws TransformerException if thrown by JAXP methods

View File

@@ -1,11 +1,11 @@
/*
* Copyright 2005-2022 the original author or authors.
* Copyright 2005-2025 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
@@ -36,8 +36,6 @@ import javax.xml.transform.stax.StAXSource;
import javax.xml.transform.stream.StreamResult;
import javax.xml.transform.stream.StreamSource;
import org.springframework.util.StringUtils;
import org.springframework.util.xml.StaxUtils;
import org.w3c.dom.Document;
import org.w3c.dom.Node;
import org.xml.sax.ContentHandler;
@@ -45,6 +43,9 @@ import org.xml.sax.InputSource;
import org.xml.sax.XMLReader;
import org.xml.sax.ext.LexicalHandler;
import org.springframework.util.StringUtils;
import org.springframework.util.xml.StaxUtils;
/**
* Convenient utility methods for dealing with TrAX.
*
@@ -55,7 +56,6 @@ public abstract class TraxUtils {
/**
* Returns the {@link Document} of the given {@link DOMSource}.
*
* @param source the DOM source
* @return the document
*/
@@ -63,17 +63,19 @@ public abstract class TraxUtils {
Node node = source.getNode();
if (node instanceof Document) {
return (Document) node;
} else if (node != null) {
}
else if (node != null) {
return node.getOwnerDocument();
} else {
}
else {
return null;
}
}
/**
* Performs the given {@linkplain SourceCallback callback} operation on a {@link Source}. Supports both the JAXP 1.4
* {@link StAXSource} and the Spring 3.0 {@link StaxUtils#createStaxSource StaxSource}.
*
* Performs the given {@linkplain SourceCallback callback} operation on a
* {@link Source}. Supports both the JAXP 1.4 {@link StAXSource} and the Spring 3.0
* {@link StaxUtils#createStaxSource StaxSource}.
* @param source source to look at
* @param callback the callback to invoke for each kind of source
*/
@@ -81,28 +83,33 @@ public abstract class TraxUtils {
if (source instanceof DOMSource) {
callback.domSource(((DOMSource) source).getNode());
return;
} else if (StaxUtils.isStaxSource(source)) {
}
else if (StaxUtils.isStaxSource(source)) {
XMLStreamReader streamReader = StaxUtils.getXMLStreamReader(source);
if (streamReader != null) {
callback.staxSource(streamReader);
return;
} else {
}
else {
XMLEventReader eventReader = StaxUtils.getXMLEventReader(source);
if (eventReader != null) {
callback.staxSource(eventReader);
return;
}
}
} else if (source instanceof SAXSource) {
}
else if (source instanceof SAXSource) {
SAXSource saxSource = (SAXSource) source;
callback.saxSource(saxSource.getXMLReader(), saxSource.getInputSource());
return;
} else if (source instanceof StreamSource) {
}
else if (source instanceof StreamSource) {
StreamSource streamSource = (StreamSource) source;
if (streamSource.getInputStream() != null) {
callback.streamSource(streamSource.getInputStream());
return;
} else if (streamSource.getReader() != null) {
}
else if (streamSource.getReader() != null) {
callback.streamSource(streamSource.getReader());
return;
}
@@ -110,16 +117,18 @@ public abstract class TraxUtils {
if (StringUtils.hasLength(source.getSystemId())) {
String systemId = source.getSystemId();
callback.source(systemId);
} else {
}
else {
throw new IllegalArgumentException("Unknown Source type: " + source.getClass());
}
}
/**
* Performs the given {@linkplain org.springframework.xml.transform.TraxUtils.ResultCallback callback} operation on a
* {@link javax.xml.transform.Result}. Supports both the JAXP 1.4 {@link javax.xml.transform.stax.StAXResult} and the
* Spring 3.0 {@link org.springframework.util.xml.StaxUtils#createStaxResult StaxSource}.
*
* Performs the given
* {@linkplain org.springframework.xml.transform.TraxUtils.ResultCallback callback}
* operation on a {@link javax.xml.transform.Result}. Supports both the JAXP 1.4
* {@link javax.xml.transform.stax.StAXResult} and the Spring 3.0
* {@link org.springframework.util.xml.StaxUtils#createStaxResult StaxSource}.
* @param result result to look at
* @param callback the callback to invoke for each kind of result
*/
@@ -127,28 +136,33 @@ public abstract class TraxUtils {
if (result instanceof DOMResult) {
callback.domResult(((DOMResult) result).getNode());
return;
} else if (StaxUtils.isStaxResult(result)) {
}
else if (StaxUtils.isStaxResult(result)) {
XMLStreamWriter streamWriter = StaxUtils.getXMLStreamWriter(result);
if (streamWriter != null) {
callback.staxResult(streamWriter);
return;
} else {
}
else {
XMLEventWriter eventWriter = StaxUtils.getXMLEventWriter(result);
if (eventWriter != null) {
callback.staxResult(eventWriter);
return;
}
}
} else if (result instanceof SAXResult) {
}
else if (result instanceof SAXResult) {
SAXResult saxSource = (SAXResult) result;
callback.saxResult(saxSource.getHandler(), saxSource.getLexicalHandler());
return;
} else if (result instanceof StreamResult) {
}
else if (result instanceof StreamResult) {
StreamResult streamSource = (StreamResult) result;
if (streamSource.getOutputStream() != null) {
callback.streamResult(streamSource.getOutputStream());
return;
} else if (streamSource.getWriter() != null) {
}
else if (streamSource.getWriter() != null) {
callback.streamResult(streamSource.getWriter());
return;
}
@@ -156,7 +170,8 @@ public abstract class TraxUtils {
if (StringUtils.hasLength(result.getSystemId())) {
String systemId = result.getSystemId();
callback.result(systemId);
} else {
}
else {
throw new IllegalArgumentException("Unknown Result type: " + result.getClass());
}
}
@@ -170,52 +185,47 @@ public abstract class TraxUtils {
/**
* Perform an operation on the node contained in a {@link DOMSource}.
*
* @param node the node
*/
void domSource(Node node) throws Exception;
/**
* Perform an operation on the {@code XMLReader} and {@code InputSource} contained in a {@link SAXSource}.
*
* Perform an operation on the {@code XMLReader} and {@code InputSource} contained
* in a {@link SAXSource}.
* @param reader the reader, can be {@code null}
* @param inputSource the input source, can be {@code null}
*/
void saxSource(XMLReader reader, InputSource inputSource) throws Exception;
/**
* Perform an operation on the {@code XMLEventReader} contained in a JAXP 1.4 {@link StAXSource} or Spring
* {@link StaxUtils#createStaxSource StaxSource}.
*
* Perform an operation on the {@code XMLEventReader} contained in a JAXP 1.4
* {@link StAXSource} or Spring {@link StaxUtils#createStaxSource StaxSource}.
* @param eventReader the reader
*/
void staxSource(XMLEventReader eventReader) throws Exception;
/**
* Perform an operation on the {@code XMLStreamReader} contained in a JAXP 1.4 {@link StAXSource} or Spring
* {@link StaxUtils#createStaxSource StaxSource}.
*
* Perform an operation on the {@code XMLStreamReader} contained in a JAXP 1.4
* {@link StAXSource} or Spring {@link StaxUtils#createStaxSource StaxSource}.
* @param streamReader the reader
*/
void staxSource(XMLStreamReader streamReader) throws Exception;
/**
* Perform an operation on the {@code InputStream} contained in a {@link StreamSource}.
*
* Perform an operation on the {@code InputStream} contained in a
* {@link StreamSource}.
* @param inputStream the input stream
*/
void streamSource(InputStream inputStream) throws Exception;
/**
* Perform an operation on the {@code Reader} contained in a {@link StreamSource}.
*
* @param reader the reader
*/
void streamSource(Reader reader) throws Exception;
/**
* Perform an operation on the system identifier contained in any {@link Source}.
*
* @param systemId the system identifier
*/
void source(String systemId) throws Exception;
@@ -231,52 +241,47 @@ public abstract class TraxUtils {
/**
* Perform an operation on the node contained in a {@link DOMResult}.
*
* @param node the node
*/
void domResult(Node node) throws Exception;
/**
* Perform an operation on the {@code ContentHandler} and {@code LexicalHandler} contained in a {@link SAXResult}.
*
* Perform an operation on the {@code ContentHandler} and {@code LexicalHandler}
* contained in a {@link SAXResult}.
* @param contentHandler the content handler
* @param lexicalHandler the lexicalHandler, can be {@code null}
*/
void saxResult(ContentHandler contentHandler, LexicalHandler lexicalHandler) throws Exception;
/**
* Perform an operation on the {@code XMLEventWriter} contained in a JAXP 1.4 {@link StAXResult} or Spring
* {@link StaxUtils#createStaxResult StaxResult}.
*
* Perform an operation on the {@code XMLEventWriter} contained in a JAXP 1.4
* {@link StAXResult} or Spring {@link StaxUtils#createStaxResult StaxResult}.
* @param eventWriter the writer
*/
void staxResult(XMLEventWriter eventWriter) throws Exception;
/**
* Perform an operation on the {@code XMLStreamWriter} contained in a JAXP 1.4 {@link StAXResult} or Spring
* {@link StaxUtils#createStaxResult StaxResult}.
*
* Perform an operation on the {@code XMLStreamWriter} contained in a JAXP 1.4
* {@link StAXResult} or Spring {@link StaxUtils#createStaxResult StaxResult}.
* @param streamWriter the writer
*/
void staxResult(XMLStreamWriter streamWriter) throws Exception;
/**
* Perform an operation on the {@code OutputStream} contained in a {@link StreamResult}.
*
* Perform an operation on the {@code OutputStream} contained in a
* {@link StreamResult}.
* @param outputStream the output stream
*/
void streamResult(OutputStream outputStream) throws Exception;
/**
* Perform an operation on the {@code Writer} contained in a {@link StreamResult}.
*
* @param writer the writer
*/
void streamResult(Writer writer) throws Exception;
/**
* Perform an operation on the system identifier contained in any {@link Result}.
*
* @param systemId the system identifier
*/
void result(String systemId) throws Exception;

View File

@@ -1,11 +1,11 @@
/*
* Copyright 2005-2022 the original author or authors.
* Copyright 2005-2025 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
@@ -24,10 +24,11 @@ import javax.xml.transform.Source;
import javax.xml.validation.Schema;
import javax.xml.validation.Validator;
import org.springframework.core.io.Resource;
import org.xml.sax.SAXException;
import org.xml.sax.SAXParseException;
import org.springframework.core.io.Resource;
/**
* Internal class that uses JAXP 1.0 features to create {@code XmlValidator} instances.
*
@@ -41,7 +42,8 @@ abstract class Jaxp13ValidatorFactory {
try {
Schema schema = SchemaLoaderUtils.loadSchema(resources, schemaLanguage);
return new Jaxp13Validator(schema);
} catch (SAXException ex) {
}
catch (SAXException ex) {
throw new XmlValidationException("Could not create Schema: " + ex.getMessage(), ex);
}
}
@@ -69,13 +71,17 @@ abstract class Jaxp13ValidatorFactory {
try {
validator.validate(source);
return errorHandler.getErrors();
} catch (SAXException ex) {
}
catch (SAXException ex) {
throw new XmlValidationException("Could not validate source: " + ex.getMessage(), ex);
}
}
}
/** {@code ErrorHandler} implementation that stores errors and fatal errors in a list. */
/**
* {@code ErrorHandler} implementation that stores errors and fatal errors in a list.
*/
private static class DefaultValidationErrorHandler implements ValidationErrorHandler {
private List<SAXParseException> errors = new ArrayList<SAXParseException>();
@@ -86,7 +92,8 @@ abstract class Jaxp13ValidatorFactory {
}
@Override
public void warning(SAXParseException ex) throws SAXException {}
public void warning(SAXParseException ex) throws SAXException {
}
@Override
public void error(SAXParseException ex) throws SAXException {
@@ -97,5 +104,7 @@ abstract class Jaxp13ValidatorFactory {
public void fatalError(SAXParseException ex) throws SAXException {
errors.add(ex);
}
}
}

View File

@@ -1,11 +1,11 @@
/*
* Copyright 2005-2022 the original author or authors.
* Copyright 2005-2025 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
@@ -27,15 +27,16 @@ import javax.xml.validation.Validator;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.springframework.core.io.Resource;
import org.xml.sax.SAXException;
import org.xml.sax.SAXNotRecognizedException;
import org.xml.sax.SAXNotSupportedException;
import org.xml.sax.SAXParseException;
import org.springframework.core.io.Resource;
/**
* Internal class that uses JAXP 1.5 features to create an {@code XmlValidator} with settings to prevent external entity
* access.
* Internal class that uses JAXP 1.5 features to create an {@code XmlValidator} with
* settings to prevent external entity access.
*
* @author Arjen Poutsma
* @author Greg Turnquist
@@ -49,7 +50,8 @@ abstract class Jaxp15ValidatorFactory {
try {
Schema schema = SchemaLoaderUtils.loadSchema(resources, schemaLanguage);
return new Jaxp15Validator(schema);
} catch (SAXException ex) {
}
catch (SAXException ex) {
throw new XmlValidationException("Could not create Schema: " + ex.getMessage(), ex);
}
}
@@ -76,7 +78,8 @@ abstract class Jaxp15ValidatorFactory {
try {
validator.setProperty(XMLConstants.ACCESS_EXTERNAL_DTD, "");
} catch (SAXNotRecognizedException | SAXNotSupportedException e) {
}
catch (SAXNotRecognizedException | SAXNotSupportedException e) {
if (log.isWarnEnabled()) {
log.warn(XMLConstants.ACCESS_EXTERNAL_DTD + " property not supported by "
+ validator.getClass().getCanonicalName());
@@ -85,7 +88,8 @@ abstract class Jaxp15ValidatorFactory {
try {
validator.setProperty(XMLConstants.ACCESS_EXTERNAL_SCHEMA, "");
} catch (SAXNotRecognizedException | SAXNotSupportedException e) {
}
catch (SAXNotRecognizedException | SAXNotSupportedException e) {
if (log.isWarnEnabled()) {
log.warn(XMLConstants.ACCESS_EXTERNAL_SCHEMA + " property not supported by "
+ validator.getClass().getCanonicalName());
@@ -96,13 +100,17 @@ abstract class Jaxp15ValidatorFactory {
try {
validator.validate(source);
return errorHandler.getErrors();
} catch (SAXException ex) {
}
catch (SAXException ex) {
throw new XmlValidationException("Could not validate source: " + ex.getMessage(), ex);
}
}
}
/** {@code ErrorHandler} implementation that stores errors and fatal errors in a list. */
/**
* {@code ErrorHandler} implementation that stores errors and fatal errors in a list.
*/
private static class DefaultValidationErrorHandler implements ValidationErrorHandler {
private List<SAXParseException> errors = new ArrayList<SAXParseException>();
@@ -113,7 +121,8 @@ abstract class Jaxp15ValidatorFactory {
}
@Override
public void warning(SAXParseException ex) throws SAXException {}
public void warning(SAXParseException ex) throws SAXException {
}
@Override
public void error(SAXParseException ex) throws SAXException {
@@ -124,5 +133,7 @@ abstract class Jaxp15ValidatorFactory {
public void fatalError(SAXParseException ex) throws SAXException {
errors.add(ex);
}
}
}

View File

@@ -1,11 +1,11 @@
/*
* Copyright 2005-2022 the original author or authors.
* Copyright 2005-2025 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
@@ -20,10 +20,11 @@ import javax.xml.validation.SchemaFactory;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.springframework.util.ResourceUtils;
import org.xml.sax.SAXNotRecognizedException;
import org.xml.sax.SAXNotSupportedException;
import org.springframework.util.ResourceUtils;
/**
* @author Greg Turnquist
* @since 3.0.5
@@ -33,8 +34,8 @@ public class SchemaFactoryUtils {
private static final Log log = LogFactory.getLog(SchemaFactoryUtils.class);
/**
* Build a {@link SchemaFactory} and set properties to prevent external entities from accessing.
*
* Build a {@link SchemaFactory} and set properties to prevent external entities from
* accessing.
* @see SchemaFactory#newInstance(String)
*/
public static SchemaFactory newInstance(String schemaLanguage) {
@@ -42,7 +43,8 @@ public class SchemaFactoryUtils {
try {
schemaFactory.setProperty(XMLConstants.ACCESS_EXTERNAL_DTD, "");
} catch (SAXNotRecognizedException | SAXNotSupportedException e) {
}
catch (SAXNotRecognizedException | SAXNotSupportedException e) {
if (log.isWarnEnabled()) {
log.warn(XMLConstants.ACCESS_EXTERNAL_DTD + " property not supported by "
+ schemaFactory.getClass().getCanonicalName());
@@ -51,9 +53,10 @@ public class SchemaFactoryUtils {
}
try {
schemaFactory.setProperty(XMLConstants.ACCESS_EXTERNAL_SCHEMA,
ResourceUtils.URL_PROTOCOL_FILE + "," + "jar:file" + "," + "nested" + "," + ResourceUtils.URL_PROTOCOL_WSJAR);
} catch (SAXNotRecognizedException | SAXNotSupportedException e) {
schemaFactory.setProperty(XMLConstants.ACCESS_EXTERNAL_SCHEMA, ResourceUtils.URL_PROTOCOL_FILE + ","
+ "jar:file" + "," + "nested" + "," + ResourceUtils.URL_PROTOCOL_WSJAR);
}
catch (SAXNotRecognizedException | SAXNotSupportedException e) {
if (log.isWarnEnabled()) {
log.warn(XMLConstants.ACCESS_EXTERNAL_SCHEMA + " property not supported by "
+ schemaFactory.getClass().getCanonicalName());
@@ -62,4 +65,5 @@ public class SchemaFactoryUtils {
return schemaFactory;
}
}

View File

@@ -1,11 +1,11 @@
/*
* Copyright 2005-2022 the original author or authors.
* Copyright 2005-2025 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
@@ -22,14 +22,16 @@ import javax.xml.transform.Source;
import javax.xml.validation.Schema;
import javax.xml.validation.SchemaFactory;
import org.springframework.core.io.Resource;
import org.springframework.util.Assert;
import org.springframework.xml.transform.ResourceSource;
import org.xml.sax.SAXException;
import org.xml.sax.XMLReader;
import org.springframework.core.io.Resource;
import org.springframework.util.Assert;
import org.springframework.xml.transform.ResourceSource;
/**
* Convenient utility methods for loading of {@link Schema} objects, performing standard handling of input streams.
* Convenient utility methods for loading of {@link Schema} objects, performing standard
* handling of input streams.
*
* @author Arjen Poutsma
* @since 1.0.0
@@ -38,10 +40,9 @@ public abstract class SchemaLoaderUtils {
/**
* Load schema from the given resource.
*
* @param resource the resource to load from
* @param schemaLanguage the language of the schema. Can be {@code XMLConstants.W3C_XML_SCHEMA_NS_URI} or
* {@code XMLConstants.RELAXNG_NS_URI}.
* @param schemaLanguage the language of the schema. Can be
* {@code XMLConstants.W3C_XML_SCHEMA_NS_URI} or {@code XMLConstants.RELAXNG_NS_URI}.
* @throws IOException if loading failed
* @throws SAXException if loading failed
* @see javax.xml.XMLConstants#W3C_XML_SCHEMA_NS_URI
@@ -53,10 +54,9 @@ public abstract class SchemaLoaderUtils {
/**
* Load schema from the given resource.
*
* @param resources the resources to load from
* @param schemaLanguage the language of the schema. Can be {@code XMLConstants.W3C_XML_SCHEMA_NS_URI} or
* {@code XMLConstants.RELAXNG_NS_URI}.
* @param schemaLanguage the language of the schema. Can be
* {@code XMLConstants.W3C_XML_SCHEMA_NS_URI} or {@code XMLConstants.RELAXNG_NS_URI}.
* @throws IOException if loading failed
* @throws SAXException if loading failed
* @see javax.xml.XMLConstants#W3C_XML_SCHEMA_NS_URI
@@ -77,11 +77,15 @@ public abstract class SchemaLoaderUtils {
return schemaFactory.newSchema(schemaSources);
}
/** Retrieves the URL from the given resource as System ID. Returns {@code null} if it cannot be opened. */
/**
* Retrieves the URL from the given resource as System ID. Returns {@code null} if it
* cannot be opened.
*/
public static String getSystemId(Resource resource) {
try {
return resource.getURL().toString();
} catch (IOException e) {
}
catch (IOException e) {
return null;
}
}

View File

@@ -1,11 +1,11 @@
/*
* Copyright 2005-2022 the original author or authors.
* Copyright 2005-2025 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
@@ -29,8 +29,8 @@ public interface ValidationErrorHandler extends ErrorHandler {
/**
* Returns the errors collected by this error handler.
*
* @return the errors
*/
SAXParseException[] getErrors();
}

View File

@@ -1,11 +1,11 @@
/*
* Copyright 2005-2022 the original author or authors.
* Copyright 2005-2025 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
@@ -27,7 +27,6 @@ public class XMLReaderFactoryUtils {
/**
* Build a {@link XMLReader} and set properties to prevent external entity access.
*
* @see XMLReaderFactory#createXMLReader()
*/
public static XMLReader createXMLReader() throws SAXException {
@@ -40,4 +39,5 @@ public class XMLReaderFactoryUtils {
return xmlReader;
}
}

View File

@@ -1,11 +1,11 @@
/*
* Copyright 2005-2022 the original author or authors.
* Copyright 2005-2025 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
@@ -34,4 +34,5 @@ public class XmlValidationException extends XmlException {
public XmlValidationException(String s, Throwable throwable) {
super(s, throwable);
}
}

View File

@@ -1,11 +1,11 @@
/*
* Copyright 2005-2022 the original author or authors.
* Copyright 2005-2025 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
@@ -23,7 +23,8 @@ import javax.xml.transform.Source;
import org.xml.sax.SAXParseException;
/**
* Simple processor that validates a given {@link Source}. Can be created via the {@link XmlValidatorFactory}.
* Simple processor that validates a given {@link Source}. Can be created via the
* {@link XmlValidatorFactory}.
* <p>
* Instances of this class are designed to be thread safe.
*
@@ -34,9 +35,9 @@ import org.xml.sax.SAXParseException;
public interface XmlValidator {
/**
* Validates the given {@link Source}, and returns an array of {@link SAXParseException}s as result. The array will be
* empty if no validation errors are found.
*
* Validates the given {@link Source}, and returns an array of
* {@link SAXParseException}s as result. The array will be empty if no validation
* errors are found.
* @param source the input document
* @return an array of {@code SAXParseException}s
* @throws IOException if the {@code source} cannot be read
@@ -45,11 +46,12 @@ public interface XmlValidator {
SAXParseException[] validate(Source source) throws IOException;
/**
* Validates the given {@link Source} and {@link ValidationErrorHandler}, and returns an array of
* {@link SAXParseException}s as result. The array will be empty if no validation errors are found.
*
* Validates the given {@link Source} and {@link ValidationErrorHandler}, and returns
* an array of {@link SAXParseException}s as result. The array will be empty if no
* validation errors are found.
* @param source the input document
* @param errorHandler the error handler to use. May be {@code null}, in which case a default will be used.
* @param errorHandler the error handler to use. May be {@code null}, in which case a
* default will be used.
* @return an array of {@code SAXParseException}s
* @throws IOException if the {@code source} cannot be read
* @throws XmlValidationException if the {@code source} cannot be validated

View File

@@ -1,11 +1,11 @@
/*
* Copyright 2005-2022 the original author or authors.
* Copyright 2005-2025 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
@@ -22,16 +22,18 @@ import javax.xml.validation.Validator;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.springframework.core.io.Resource;
import org.springframework.util.Assert;
import org.springframework.xml.JaxpVersion;
/**
* Factory for {@link XmlValidator} objects, being aware of JAXP 1.3 {@link Validator}s, and JAXP 1.0 parsing
* capabilities. Mainly for internal use within the framework.
* Factory for {@link XmlValidator} objects, being aware of JAXP 1.3 {@link Validator}s,
* and JAXP 1.0 parsing capabilities. Mainly for internal use within the framework.
* <p>
* The goal of this class is to avoid runtime dependencies on JAXP 1.3 by using the best validation implementation that
* is available. Prefers JAXP 1.3 {@link XmlValidator} implementations to a custom, SAX-based implementation.
* The goal of this class is to avoid runtime dependencies on JAXP 1.3 by using the best
* validation implementation that is available. Prefers JAXP 1.3 {@link XmlValidator}
* implementations to a custom, SAX-based implementation.
*
* @author Arjen Poutsma
* @see XmlValidator
@@ -48,9 +50,8 @@ public abstract class XmlValidatorFactory {
public static final String SCHEMA_RELAX_NG = "http://relaxng.org/ns/structure/1.0";
/**
* Create a {@link XmlValidator} with the given schema resource and schema language type. The schema language must be
* one of the {@code SCHEMA_XXX} constants.
*
* Create a {@link XmlValidator} with the given schema resource and schema language
* type. The schema language must be one of the {@code SCHEMA_XXX} constants.
* @param schemaResource a resource that locates the schema to validate against
* @param schemaLanguage the language of the schema
* @return a validator
@@ -66,10 +67,10 @@ public abstract class XmlValidatorFactory {
}
/**
* Create a {@link XmlValidator} with the given schema resources and schema language type. The schema language must be
* one of the {@code SCHEMA_XXX} constants.
*
* @param schemaResources an array of resource that locate the schemas to validate against
* Create a {@link XmlValidator} with the given schema resources and schema language
* type. The schema language must be one of the {@code SCHEMA_XXX} constants.
* @param schemaResources an array of resource that locate the schemas to validate
* against
* @param schemaLanguage the language of the schemas
* @return a validator
* @throws IOException if the schema resource cannot be read
@@ -91,10 +92,12 @@ public abstract class XmlValidatorFactory {
if (JaxpVersion.getJaxpVersion() >= JaxpVersion.JAXP_15) {
logger.trace("Creating JAXP 1.5 XmlValidator");
return Jaxp15ValidatorFactory.createValidator(schemaResources, schemaLanguage);
} else if (JaxpVersion.getJaxpVersion() >= JaxpVersion.JAXP_13) {
}
else if (JaxpVersion.getJaxpVersion() >= JaxpVersion.JAXP_13) {
logger.trace("Creating JAXP 1.3 XmlValidator");
return Jaxp13ValidatorFactory.createValidator(schemaResources, schemaLanguage);
} else {
}
else {
throw new IllegalStateException("Could not locate JAXP 1.3.");
}
}

View File

@@ -1,11 +1,11 @@
/*
* Copyright 2005-2022 the original author or authors.
* Copyright 2005-2025 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
@@ -22,14 +22,16 @@ import javax.xml.transform.Source;
import javax.xml.transform.TransformerException;
import javax.xml.transform.dom.DOMResult;
import org.springframework.xml.transform.TransformerObjectSupport;
import org.w3c.dom.DOMException;
import org.w3c.dom.Document;
import org.w3c.dom.Element;
import org.w3c.dom.Node;
import org.springframework.xml.transform.TransformerObjectSupport;
/**
* Abstract base class for implementations of {@link XPathOperations}. Contains a namespaces property.
* Abstract base class for implementations of {@link XPathOperations}. Contains a
* namespaces property.
*
* @author Arjen Poutsma
* @since 1.0.0
@@ -54,7 +56,10 @@ public abstract class AbstractXPathTemplate extends TransformerObjectSupport imp
evaluate(expression, context, new NodeCallbackHandlerNodeMapper(callbackHandler));
}
/** Static inner class that adapts a {@link NodeCallbackHandler} to the interface of {@link NodeMapper}. */
/**
* Static inner class that adapts a {@link NodeCallbackHandler} to the interface of
* {@link NodeMapper}.
*/
private static class NodeCallbackHandlerNodeMapper implements NodeMapper<Object> {
private final NodeCallbackHandler callbackHandler;
@@ -68,11 +73,11 @@ public abstract class AbstractXPathTemplate extends TransformerObjectSupport imp
callbackHandler.processNode(node);
return null;
}
}
/**
* Returns the root element of the given source.
*
* @param source the source to get the root element from
* @return the root element
*/

View File

@@ -1,11 +1,11 @@
/*
* Copyright 2005-2022 the original author or authors.
* Copyright 2005-2025 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
@@ -39,7 +39,6 @@ abstract class JaxenXPathExpressionFactory {
/**
* Creates a Jaxen {@code XPathExpression} from the given string expression.
*
* @param expression the XPath expression
* @return the compiled {@code XPathExpression}
* @throws XPathParseException when the given expression cannot be parsed
@@ -48,15 +47,16 @@ abstract class JaxenXPathExpressionFactory {
try {
XPath xpath = new DOMXPath(expression);
return new JaxenXpathExpression(xpath, expression);
} catch (JaxenException ex) {
}
catch (JaxenException ex) {
throw new org.springframework.xml.xpath.XPathParseException(
"Could not compile [" + expression + "] to a XPathExpression: " + ex.getMessage(), ex);
}
}
/**
* Creates a Jaxen {@code XPathExpression} from the given string expression and prefixes.
*
* Creates a Jaxen {@code XPathExpression} from the given string expression and
* prefixes.
* @param expression the XPath expression
* @param namespaces the namespaces
* @return the compiled {@code XPathExpression}
@@ -67,7 +67,8 @@ abstract class JaxenXPathExpressionFactory {
XPath xpath = new DOMXPath(expression);
xpath.setNamespaceContext(new SimpleNamespaceContext(namespaces));
return new JaxenXpathExpression(xpath, expression);
} catch (JaxenException ex) {
}
catch (JaxenException ex) {
throw new org.springframework.xml.xpath.XPathParseException(
"Could not compile [" + expression + "] to a XPathExpression: " + ex.getMessage(), ex);
}
@@ -77,6 +78,7 @@ abstract class JaxenXPathExpressionFactory {
private static class JaxenXpathExpression implements XPathExpression {
private XPath xpath;
private final String expression;
private JaxenXpathExpression(XPath xpath, String expression) {
@@ -93,7 +95,8 @@ abstract class JaxenXPathExpressionFactory {
public Node evaluateAsNode(Node node) {
try {
return (Node) xpath.selectSingleNode(node);
} catch (JaxenException ex) {
}
catch (JaxenException ex) {
throw new XPathException("Could not evaluate XPath expression [" + xpath + "] :" + ex.getMessage(), ex);
}
}
@@ -102,7 +105,8 @@ abstract class JaxenXPathExpressionFactory {
public boolean evaluateAsBoolean(Node node) {
try {
return xpath.booleanValueOf(node);
} catch (JaxenException ex) {
}
catch (JaxenException ex) {
throw new XPathException("Could not evaluate XPath expression [" + xpath + "] :" + ex.getMessage(), ex);
}
}
@@ -111,7 +115,8 @@ abstract class JaxenXPathExpressionFactory {
public double evaluateAsNumber(Node node) {
try {
return xpath.numberValueOf(node).doubleValue();
} catch (JaxenException ex) {
}
catch (JaxenException ex) {
throw new XPathException("Could not evaluate XPath expression [" + xpath + "] :" + ex.getMessage(), ex);
}
}
@@ -120,7 +125,8 @@ abstract class JaxenXPathExpressionFactory {
public String evaluateAsString(Node node) {
try {
return xpath.stringValueOf(node);
} catch (JaxenException ex) {
}
catch (JaxenException ex) {
throw new XPathException("Could not evaluate XPath expression [" + xpath + "] :" + ex.getMessage(), ex);
}
}
@@ -130,7 +136,8 @@ abstract class JaxenXPathExpressionFactory {
public List<Node> evaluateAsNodeList(Node node) {
try {
return xpath.selectNodes(node);
} catch (JaxenException ex) {
}
catch (JaxenException ex) {
throw new XPathException("Could not evaluate XPath expression [" + xpath + "] :" + ex.getMessage(), ex);
}
}
@@ -142,13 +149,16 @@ abstract class JaxenXPathExpressionFactory {
if (result != null) {
try {
return nodeMapper.mapNode(result, 0);
} catch (DOMException ex) {
}
catch (DOMException ex) {
throw new XPathException("Mapping resulted in DOMException", ex);
}
} else {
}
else {
return null;
}
} catch (JaxenException ex) {
}
catch (JaxenException ex) {
throw new XPathException("Could not evaluate XPath expression [" + xpath + "] :" + ex.getMessage(), ex);
}
}
@@ -162,14 +172,18 @@ abstract class JaxenXPathExpressionFactory {
Node node = (Node) nodes.get(i);
try {
results.add(nodeMapper.mapNode(node, i));
} catch (DOMException ex) {
}
catch (DOMException ex) {
throw new XPathException("Mapping resulted in DOMException", ex);
}
}
return results;
} catch (JaxenException ex) {
}
catch (JaxenException ex) {
throw new XPathException("Could not evaluate XPath expression [" + xpath + "] :" + ex.getMessage(), ex);
}
}
}
}

View File

@@ -1,11 +1,11 @@
/*
* Copyright 2005-2022 the original author or authors.
* Copyright 2005-2025 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
@@ -47,9 +47,11 @@ public class JaxenXPathTemplate extends AbstractXPathTemplate {
XPath xpath = createXPath(expression);
Element element = getRootElement(context);
return xpath.booleanValueOf(element);
} catch (JaxenException ex) {
}
catch (JaxenException ex) {
throw new XPathException("Could not evaluate XPath expression [" + expression + "]", ex);
} catch (TransformerException ex) {
}
catch (TransformerException ex) {
throw new XPathException("Could not transform context to DOM Node", ex);
}
}
@@ -60,9 +62,11 @@ public class JaxenXPathTemplate extends AbstractXPathTemplate {
XPath xpath = createXPath(expression);
Element element = getRootElement(context);
return (Node) xpath.selectSingleNode(element);
} catch (JaxenException ex) {
}
catch (JaxenException ex) {
throw new XPathException("Could not evaluate XPath expression [" + expression + "]", ex);
} catch (TransformerException ex) {
}
catch (TransformerException ex) {
throw new XPathException("Could not transform context to DOM Node", ex);
}
}
@@ -74,9 +78,11 @@ public class JaxenXPathTemplate extends AbstractXPathTemplate {
XPath xpath = createXPath(expression);
Element element = getRootElement(context);
return xpath.selectNodes(element);
} catch (JaxenException ex) {
}
catch (JaxenException ex) {
throw new XPathException("Could not evaluate XPath expression [" + expression + "]", ex);
} catch (TransformerException ex) {
}
catch (TransformerException ex) {
throw new XPathException("Could not transform context to DOM Node", ex);
}
}
@@ -87,9 +93,11 @@ public class JaxenXPathTemplate extends AbstractXPathTemplate {
XPath xpath = createXPath(expression);
Element element = getRootElement(context);
return xpath.numberValueOf(element).doubleValue();
} catch (JaxenException ex) {
}
catch (JaxenException ex) {
throw new XPathException("Could not evaluate XPath expression [" + expression + "]", ex);
} catch (TransformerException ex) {
}
catch (TransformerException ex) {
throw new XPathException("Could not transform context to DOM Node", ex);
}
}
@@ -100,9 +108,11 @@ public class JaxenXPathTemplate extends AbstractXPathTemplate {
XPath xpath = createXPath(expression);
Element element = getRootElement(context);
return xpath.stringValueOf(element);
} catch (JaxenException ex) {
}
catch (JaxenException ex) {
throw new XPathException("Could not evaluate XPath expression [" + expression + "]", ex);
} catch (TransformerException ex) {
}
catch (TransformerException ex) {
throw new XPathException("Could not transform context to DOM Node", ex);
}
}
@@ -116,16 +126,20 @@ public class JaxenXPathTemplate extends AbstractXPathTemplate {
if (node != null) {
try {
return nodeMapper.mapNode(node, 0);
} catch (DOMException ex) {
}
catch (DOMException ex) {
throw new XPathException("Mapping resulted in DOMException", ex);
}
} else {
}
else {
return null;
}
} catch (JaxenException ex) {
}
catch (JaxenException ex) {
throw new XPathException("Could not evaluate XPath expression [" + expression + "]", ex);
} catch (TransformerException ex) {
}
catch (TransformerException ex) {
throw new XPathException("Could not transform context to DOM Node", ex);
}
}
@@ -141,14 +155,17 @@ public class JaxenXPathTemplate extends AbstractXPathTemplate {
Node node = (Node) nodes.get(i);
try {
results.add(nodeMapper.mapNode(node, i));
} catch (DOMException ex) {
}
catch (DOMException ex) {
throw new XPathException("Mapping resulted in DOMException", ex);
}
}
return results;
} catch (JaxenException ex) {
}
catch (JaxenException ex) {
throw new XPathException("Could not evaluate XPath expression [" + expression + "]", ex);
} catch (TransformerException ex) {
}
catch (TransformerException ex) {
throw new XPathException("Could not transform context to DOM Node", ex);
}
}
@@ -160,4 +177,5 @@ public class JaxenXPathTemplate extends AbstractXPathTemplate {
}
return xpath;
}
}

View File

@@ -1,11 +1,11 @@
/*
* Copyright 2005-2022 the original author or authors.
* Copyright 2005-2025 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
@@ -26,11 +26,12 @@ import javax.xml.xpath.XPathConstants;
import javax.xml.xpath.XPathExpressionException;
import javax.xml.xpath.XPathFactory;
import org.springframework.xml.namespace.SimpleNamespaceContext;
import org.w3c.dom.DOMException;
import org.w3c.dom.Node;
import org.w3c.dom.NodeList;
import org.springframework.xml.namespace.SimpleNamespaceContext;
/**
* JAXP 1.3-specific factory creating {@link XPathExpression} objects.
*
@@ -45,7 +46,6 @@ abstract class Jaxp13XPathExpressionFactory {
/**
* Creates a JAXP 1.3 {@code XPathExpression} from the given string expression.
*
* @param expression the XPath expression
* @return the compiled {@code XPathExpression}
* @throws XPathParseException when the given expression cannot be parsed
@@ -55,15 +55,16 @@ abstract class Jaxp13XPathExpressionFactory {
XPath xpath = createXPath();
javax.xml.xpath.XPathExpression xpathExpression = xpath.compile(expression);
return new Jaxp13XPathExpression(xpathExpression, expression);
} catch (XPathExpressionException ex) {
}
catch (XPathExpressionException ex) {
throw new org.springframework.xml.xpath.XPathParseException(
"Could not compile [" + expression + "] to a XPathExpression: " + ex.getMessage(), ex);
}
}
/**
* Creates a JAXP 1.3 {@code XPathExpression} from the given string expression and namespaces.
*
* Creates a JAXP 1.3 {@code XPathExpression} from the given string expression and
* namespaces.
* @param expression the XPath expression
* @param namespaces the namespaces
* @return the compiled {@code XPathExpression}
@@ -77,7 +78,8 @@ abstract class Jaxp13XPathExpressionFactory {
xpath.setNamespaceContext(namespaceContext);
javax.xml.xpath.XPathExpression xpathExpression = xpath.compile(expression);
return new Jaxp13XPathExpression(xpathExpression, expression);
} catch (XPathExpressionException ex) {
}
catch (XPathExpressionException ex) {
throw new org.springframework.xml.xpath.XPathParseException(
"Could not compile [" + expression + "] to a XPathExpression: " + ex.getMessage(), ex);
}
@@ -91,6 +93,7 @@ abstract class Jaxp13XPathExpressionFactory {
private static class Jaxp13XPathExpression implements XPathExpression {
private final javax.xml.xpath.XPathExpression xpathExpression;
private final String expression;
private Jaxp13XPathExpression(javax.xml.xpath.XPathExpression xpathExpression, String expression) {
@@ -120,7 +123,8 @@ abstract class Jaxp13XPathExpressionFactory {
synchronized (xpathExpression) {
return xpathExpression.evaluate(node, returnType);
}
} catch (XPathExpressionException ex) {
}
catch (XPathExpressionException ex) {
throw new XPathException("Could not evaluate XPath expression:" + ex.getMessage(), ex);
}
}
@@ -154,10 +158,12 @@ abstract class Jaxp13XPathExpressionFactory {
if (result != null) {
try {
return nodeMapper.mapNode(result, 0);
} catch (DOMException ex) {
}
catch (DOMException ex) {
throw new XPathException("Mapping resulted in DOMException", ex);
}
} else {
}
else {
return null;
}
}
@@ -169,12 +175,14 @@ abstract class Jaxp13XPathExpressionFactory {
for (int i = 0; i < nodes.getLength(); i++) {
try {
results.add(nodeMapper.mapNode(nodes.item(i), i));
} catch (DOMException ex) {
}
catch (DOMException ex) {
throw new XPathException("Mapping resulted in DOMException", ex);
}
}
return results;
}
}
}

View File

@@ -1,11 +1,11 @@
/*
* Copyright 2005-2022 the original author or authors.
* Copyright 2005-2025 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
@@ -34,10 +34,6 @@ import javax.xml.xpath.XPathExpressionException;
import javax.xml.xpath.XPathFactory;
import javax.xml.xpath.XPathFactoryConfigurationException;
import org.springframework.util.xml.StaxUtils;
import org.springframework.xml.namespace.SimpleNamespaceContext;
import org.springframework.xml.transform.TransformerHelper;
import org.springframework.xml.transform.TraxUtils;
import org.w3c.dom.DOMException;
import org.w3c.dom.Document;
import org.w3c.dom.Element;
@@ -46,8 +42,14 @@ import org.w3c.dom.NodeList;
import org.xml.sax.InputSource;
import org.xml.sax.XMLReader;
import org.springframework.util.xml.StaxUtils;
import org.springframework.xml.namespace.SimpleNamespaceContext;
import org.springframework.xml.transform.TransformerHelper;
import org.springframework.xml.transform.TraxUtils;
/**
* Implementation of {@link XPathOperations} that uses JAXP 1.3. JAXP 1.3 is part of Java SE since 1.5.
* Implementation of {@link XPathOperations} that uses JAXP 1.3. JAXP 1.3 is part of Java
* SE since 1.5.
* <p>
* Namespaces can be set using the {@code namespaces} property.
*
@@ -66,7 +68,8 @@ public class Jaxp13XPathTemplate extends AbstractXPathTemplate {
public Jaxp13XPathTemplate(String xpathFactoryUri) {
try {
xpathFactory = XPathFactory.newInstance(xpathFactoryUri);
} catch (XPathFactoryConfigurationException ex) {
}
catch (XPathFactoryConfigurationException ex) {
throw new XPathException("Could not create XPathFactory", ex);
}
}
@@ -109,10 +112,12 @@ public class Jaxp13XPathTemplate extends AbstractXPathTemplate {
if (node != null) {
try {
return nodeMapper.mapNode(node, 0);
} catch (DOMException ex) {
}
catch (DOMException ex) {
throw new XPathException("Mapping resulted in DOMException", ex);
}
} else {
}
else {
return null;
}
}
@@ -124,7 +129,8 @@ public class Jaxp13XPathTemplate extends AbstractXPathTemplate {
for (int i = 0; i < nodes.getLength(); i++) {
try {
results.add(nodeMapper.mapNode(nodes.item(i), i));
} catch (DOMException ex) {
}
catch (DOMException ex) {
throw new XPathException("Mapping resulted in DOMException", ex);
}
}
@@ -142,11 +148,14 @@ public class Jaxp13XPathTemplate extends AbstractXPathTemplate {
EvaluationCallback callback = new EvaluationCallback(xpath, expression, returnType);
TraxUtils.doWithSource(context, callback);
return callback.result;
} catch (javax.xml.xpath.XPathException ex) {
}
catch (javax.xml.xpath.XPathException ex) {
throw new XPathException("Could not evaluate XPath expression [" + expression + "]", ex);
} catch (TransformerException ex) {
}
catch (TransformerException ex) {
throw new XPathException("Could not transform context to DOM Node", ex);
} catch (Exception ex) {
}
catch (Exception ex) {
throw new XPathException(ex.getMessage(), ex);
}
}

View File

@@ -1,11 +1,11 @@
/*
* Copyright 2005-2022 the original author or authors.
* Copyright 2005-2025 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
@@ -20,12 +20,12 @@ import org.w3c.dom.DOMException;
import org.w3c.dom.Node;
/**
* An interface used by {@link XPathOperations} implementations for processing {@link Node} objects on a per-node basis.
* Implementations of this interface perform the actual work of processing nodes, but don't need to worry about
* exception handling.
* An interface used by {@link XPathOperations} implementations for processing
* {@link Node} objects on a per-node basis. Implementations of this interface perform the
* actual work of processing nodes, but don't need to worry about exception handling.
* <p>
* Consider using a {@link NodeMapper} instead if you need to map exactly result object per node, assembling them in a
* List.
* Consider using a {@link NodeMapper} instead if you need to map exactly result object
* per node, assembling them in a List.
*
* @author Arjen Poutsma
* @see XPathOperations#evaluate(String,javax.xml.transform.Source,NodeCallbackHandler)
@@ -35,7 +35,6 @@ public interface NodeCallbackHandler {
/**
* Processed a single node.
*
* @param node the node to map
* @throws DOMException in case of DOM errors
*/

View File

@@ -1,11 +1,11 @@
/*
* Copyright 2005-2022 the original author or authors.
* Copyright 2005-2025 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
@@ -20,9 +20,10 @@ import org.w3c.dom.DOMException;
import org.w3c.dom.Node;
/**
* An interface used by {@link XPathOperations} implementations for mapping {@link Node} objects on a per-node basis.
* Implementations of this interface perform the actual work of mapping each node to a result object, but don't need to
* worry about exception handling.
* An interface used by {@link XPathOperations} implementations for mapping {@link Node}
* objects on a per-node basis. Implementations of this interface perform the actual work
* of mapping each node to a result object, but don't need to worry about exception
* handling.
*
* @author Arjen Poutsma
* @see XPathOperations#evaluate(String,javax.xml.transform.Source,NodeMapper)
@@ -35,7 +36,6 @@ public interface NodeMapper<T> {
/**
* Maps a single node to an arbitrary object.
*
* @param node the node to map
* @param nodeNum the number of the current node
* @return object for the current node

View File

@@ -1,11 +1,11 @@
/*
* Copyright 2005-2022 the original author or authors.
* Copyright 2005-2025 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
@@ -28,8 +28,8 @@ import org.springframework.xml.XmlException;
public class XPathException extends XmlException {
/**
* Constructs a new instance of the {@code XPathException} with the specific detail message.
*
* Constructs a new instance of the {@code XPathException} with the specific detail
* message.
* @param message the detail message
*/
public XPathException(String message) {
@@ -37,12 +37,13 @@ public class XPathException extends XmlException {
}
/**
* Constructs a new instance of the {@code XPathException} with the specific detail message and exception.
*
* Constructs a new instance of the {@code XPathException} with the specific detail
* message and exception.
* @param message the detail message
* @param throwable the wrapped exception
*/
public XPathException(String message, Throwable throwable) {
super(message, throwable);
}
}

View File

@@ -1,11 +1,11 @@
/*
* Copyright 2005-2022 the original author or authors.
* Copyright 2005-2025 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
@@ -21,11 +21,11 @@ import java.util.List;
import org.w3c.dom.Node;
/**
* Defines the contract for a precompiled XPath expression. Concrete instances can be obtained through the
* {@link XPathExpressionFactory}.
* Defines the contract for a precompiled XPath expression. Concrete instances can be
* obtained through the {@link XPathExpressionFactory}.
* <p>
* Implementations of this interface are precompiled, and thus faster, but less flexible, than the XPath expressions
* used by {@link XPathOperations} implementations.
* Implementations of this interface are precompiled, and thus faster, but less flexible,
* than the XPath expressions used by {@link XPathOperations} implementations.
*
* @author Arjen Poutsma
* @since 1.0.0
@@ -33,26 +33,26 @@ import org.w3c.dom.Node;
public interface XPathExpression {
/**
* Evaluates the given expression as a {@code boolean}. Returns the boolean evaluation of the expression, or
* {@code false} if it is invalid.
* Evaluates the given expression as a {@code boolean}. Returns the boolean evaluation
* of the expression, or {@code false} if it is invalid.
* <p>
* The return value is determined per the {@code boolean()} function defined in the XPath specification. This means
* that an expression that selects zero nodes will return {@code false}, while an expression that selects one or more
* nodes will return {@code true}. An expression that returns a string returns {@code false} for empty strings and
* {@code true} for all other strings. An expression that returns a number returns {@code false} for zero and
* {@code true} for non-zero numbers.
*
* The return value is determined per the {@code boolean()} function defined in the
* XPath specification. This means that an expression that selects zero nodes will
* return {@code false}, while an expression that selects one or more nodes will
* return {@code true}. An expression that returns a string returns {@code false} for
* empty strings and {@code true} for all other strings. An expression that returns a
* number returns {@code false} for zero and {@code true} for non-zero numbers.
* @param node the starting point
* @return the result of the evaluation
* @throws XPathException in case of XPath errors
* @see <a href="http://www.w3.org/TR/xpath/#function-boolean">XPath specification - boolean() function</a>
* @see <a href="http://www.w3.org/TR/xpath/#function-boolean">XPath specification -
* boolean() function</a>
*/
boolean evaluateAsBoolean(Node node) throws XPathException;
/**
* Evaluates the given expression as a {@link Node}. Returns the evaluation of the expression, or {@code null} if it
* is invalid.
*
* Evaluates the given expression as a {@link Node}. Returns the evaluation of the
* expression, or {@code null} if it is invalid.
* @param node the starting point
* @return the result of the evaluation
* @throws XPathException in case of XPath errors
@@ -61,9 +61,8 @@ public interface XPathExpression {
Node evaluateAsNode(Node node) throws XPathException;
/**
* Evaluates the given expression, and returns all {@link Node} objects that conform to it. Returns an empty list if
* no result could be found.
*
* Evaluates the given expression, and returns all {@link Node} objects that conform
* to it. Returns an empty list if no result could be found.
* @param node the starting point
* @return a list of {@code Node}s that are selected by the expression
* @throws XPathException in case of XPath errors
@@ -72,35 +71,38 @@ public interface XPathExpression {
List<Node> evaluateAsNodeList(Node node) throws XPathException;
/**
* Evaluates the given expression as a number ({@code double}). Returns the numeric evaluation of the expression, or
* {@link Double#NaN} if it is invalid.
* Evaluates the given expression as a number ({@code double}). Returns the numeric
* evaluation of the expression, or {@link Double#NaN} if it is invalid.
* <p>
* The return value is determined per the {@code number()} function as defined in the XPath specification. This means
* that if the expression selects multiple nodes, it will return the number value of the first node.
*
* The return value is determined per the {@code number()} function as defined in the
* XPath specification. This means that if the expression selects multiple nodes, it
* will return the number value of the first node.
* @param node the starting point
* @return the result of the evaluation
* @throws XPathException in case of XPath errors
* @see <a href="http://www.w3.org/TR/xpath/#function-number">XPath specification - number() function</a>
* @see <a href="http://www.w3.org/TR/xpath/#function-number">XPath specification -
* number() function</a>
*/
double evaluateAsNumber(Node node) throws XPathException;
/**
* Evaluates the given expression as a String. Returns {@code null} if no result could be found.
* Evaluates the given expression as a String. Returns {@code null} if no result could
* be found.
* <p>
* The return value is determined per the {@code string()} function as defined in the XPath specification. This means
* that if the expression selects multiple nodes, it will return the string value of the first node.
*
* The return value is determined per the {@code string()} function as defined in the
* XPath specification. This means that if the expression selects multiple nodes, it
* will return the string value of the first node.
* @param node the starting point
* @return the result of the evaluation
* @throws XPathException in case of XPath errors
* @see <a href="http://www.w3.org/TR/xpath/#function-string">XPath specification - string() function</a>
* @see <a href="http://www.w3.org/TR/xpath/#function-string">XPath specification -
* string() function</a>
*/
String evaluateAsString(Node node) throws XPathException;
/**
* Evaluates the given expression, mapping a single {@link Node} result to a Java object via a {@link NodeMapper}.
*
* Evaluates the given expression, mapping a single {@link Node} result to a Java
* object via a {@link NodeMapper}.
* @param node the starting point
* @param nodeMapper object that will map one object per node
* @return the single mapped object
@@ -110,8 +112,8 @@ public interface XPathExpression {
<T> T evaluateAsObject(Node node, NodeMapper<T> nodeMapper) throws XPathException;
/**
* Evaluates the given expression, mapping each result {@link Node} objects to a Java object via a {@link NodeMapper}.
*
* Evaluates the given expression, mapping each result {@link Node} objects to a Java
* object via a {@link NodeMapper}.
* @param node the starting point
* @param nodeMapper object that will map one object per node
* @return the result list, containing mapped objects
@@ -119,4 +121,5 @@ public interface XPathExpression {
* @see <a href="http://www.w3.org/TR/xpath#node-sets">XPath specification</a>
*/
<T> List<T> evaluate(Node node, NodeMapper<T> nodeMapper) throws XPathException;
}

View File

@@ -1,11 +1,11 @@
/*
* Copyright 2005-2022 the original author or authors.
* Copyright 2005-2025 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
@@ -21,14 +21,16 @@ import java.util.Map;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.springframework.util.Assert;
/**
* Factory for compiled {@code XPathExpression}s, being aware of JAXP 1.3+ XPath functionality, and Jaxen. Mainly for
* internal use of the framework.
* Factory for compiled {@code XPathExpression}s, being aware of JAXP 1.3+ XPath
* functionality, and Jaxen. Mainly for internal use of the framework.
* <p>
* The goal of this class is to avoid runtime dependencies a specific XPath engine, simply using the best XPath
* implementation that is available. Prefers JAXP 1.3+ XPath implementations to Jaxen.
* The goal of this class is to avoid runtime dependencies a specific XPath engine, simply
* using the best XPath implementation that is available. Prefers JAXP 1.3+ XPath
* implementations to Jaxen.
*
* @author Arjen Poutsma
* @see XPathExpression
@@ -40,7 +42,6 @@ public abstract class XPathExpressionFactory {
/**
* Create a compiled XPath expression using the given string.
*
* @param expression the XPath expression
* @return the compiled XPath expression
* @throws IllegalStateException if neither JAXP 1.3+, or Jaxen are available
@@ -48,13 +49,12 @@ public abstract class XPathExpressionFactory {
*/
public static XPathExpression createXPathExpression(String expression)
throws IllegalStateException, XPathParseException {
return createXPathExpression(expression, Collections.<String, String> emptyMap());
return createXPathExpression(expression, Collections.<String, String>emptyMap());
}
/**
* Create a compiled XPath expression using the given string and namespaces. The namespace map should consist of
* string prefixes mapped to string namespaces.
*
* Create a compiled XPath expression using the given string and namespaces. The
* namespace map should consist of string prefixes mapped to string namespaces.
* @param expression the XPath expression
* @param namespaces a map that binds string prefixes to string namespaces
* @return the compiled XPath expression
@@ -70,7 +70,8 @@ public abstract class XPathExpressionFactory {
try {
logger.trace("Creating [javax.xml.xpath.XPathExpression]");
return Jaxp13XPathExpressionFactory.createXPathExpression(expression, namespaces);
} catch (XPathException e) {
}
catch (XPathException e) {
throw e;
}
}

View File

@@ -1,11 +1,11 @@
/*
* Copyright 2005-2022 the original author or authors.
* Copyright 2005-2025 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
@@ -24,10 +24,11 @@ import org.springframework.util.Assert;
import org.springframework.util.CollectionUtils;
/**
* Spring {@link FactoryBean} for {@link XPathExpression} object. Facilitates injection of XPath expressions into
* endpoint beans.
* Spring {@link FactoryBean} for {@link XPathExpression} object. Facilitates injection of
* XPath expressions into endpoint beans.
* <p>
* Uses {@link XPathExpressionFactory} underneath, so support is provided for JAXP 1.3, and Jaxen XPaths.
* Uses {@link XPathExpressionFactory} underneath, so support is provided for JAXP 1.3,
* and Jaxen XPaths.
*
* @author Arjen Poutsma
* @see #setExpression(String)
@@ -46,7 +47,10 @@ public class XPathExpressionFactoryBean implements FactoryBean<XPathExpression>,
expressionString = expression;
}
/** Sets the namespaces for the expressions. The given properties binds string prefixes to string namespaces. */
/**
* Sets the namespaces for the expressions. The given properties binds string prefixes
* to string namespaces.
*/
public void setNamespaces(Map<String, String> namespaces) {
this.namespaces = namespaces;
}
@@ -56,7 +60,8 @@ public class XPathExpressionFactoryBean implements FactoryBean<XPathExpression>,
Assert.notNull(expressionString, "expression is required");
if (CollectionUtils.isEmpty(namespaces)) {
expression = XPathExpressionFactory.createXPathExpression(expressionString);
} else {
}
else {
expression = XPathExpressionFactory.createXPathExpression(expressionString, namespaces);
}
}
@@ -75,4 +80,5 @@ public class XPathExpressionFactoryBean implements FactoryBean<XPathExpression>,
public boolean isSingleton() {
return true;
}
}

View File

@@ -1,11 +1,11 @@
/*
* Copyright 2005-2022 the original author or authors.
* Copyright 2005-2025 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
@@ -23,12 +23,12 @@ import javax.xml.transform.Source;
import org.w3c.dom.Node;
/**
* Interface that specifies a basic set of XPath operations, implemented by various XPathTemplates. Contains numerous
* evaluation methods,
* Interface that specifies a basic set of XPath operations, implemented by various
* XPathTemplates. Contains numerous evaluation methods,
* <p>
* The templates that implement this interface do not use precompiled XPath expressions. Consider using the
* {@link XPathExpressionFactory} or the {@link XPathExpressionFactoryBean} for optimal performance, but less
* flexibility.
* The templates that implement this interface do not use precompiled XPath expressions.
* Consider using the {@link XPathExpressionFactory} or the
* {@link XPathExpressionFactoryBean} for optimal performance, but less flexibility.
*
* @author Arjen Poutsma
* @see Jaxp13XPathTemplate
@@ -38,27 +38,27 @@ import org.w3c.dom.Node;
public interface XPathOperations {
/**
* Evaluates the given expression as a {@code boolean}. Returns the boolean evaluation of the expression, or
* {@code false} if it is invalid.
* Evaluates the given expression as a {@code boolean}. Returns the boolean evaluation
* of the expression, or {@code false} if it is invalid.
* <p>
* The return value is determined per the {@code boolean()} function defined in the XPath specification. This means
* that an expression that selects zero nodes will return {@code false}, while an expression that selects one or more
* nodes will return {@code true}. An expression that returns a string returns {@code false} for empty strings and
* {@code true} for all other strings. An expression that returns a number returns {@code false} for zero and
* {@code true} for non-zero numbers.
*
* The return value is determined per the {@code boolean()} function defined in the
* XPath specification. This means that an expression that selects zero nodes will
* return {@code false}, while an expression that selects one or more nodes will
* return {@code true}. An expression that returns a string returns {@code false} for
* empty strings and {@code true} for all other strings. An expression that returns a
* number returns {@code false} for zero and {@code true} for non-zero numbers.
* @param expression the XPath expression
* @param context the context starting point
* @return the result of the evaluation
* @throws XPathException in case of XPath errors
* @see <a href="http://www.w3.org/TR/xpath/#function-boolean">XPath specification - boolean() function</a>
* @see <a href="http://www.w3.org/TR/xpath/#function-boolean">XPath specification -
* boolean() function</a>
*/
boolean evaluateAsBoolean(String expression, Source context) throws XPathException;
/**
* Evaluates the given expression as a {@link Node}. Returns the evaluation of the expression, or {@code null} if it
* is invalid.
*
* Evaluates the given expression as a {@link Node}. Returns the evaluation of the
* expression, or {@code null} if it is invalid.
* @param expression the XPath expression
* @param context the context starting point
* @return the result of the evaluation
@@ -68,9 +68,8 @@ public interface XPathOperations {
Node evaluateAsNode(String expression, Source context) throws XPathException;
/**
* Evaluates the given expression as a list of {@link Node} objects. Returns the evaluation of the expression, or an
* empty list if no results are found.
*
* Evaluates the given expression as a list of {@link Node} objects. Returns the
* evaluation of the expression, or an empty list if no results are found.
* @param expression the XPath expression
* @param context the context starting point
* @return the result of the evaluation
@@ -80,38 +79,40 @@ public interface XPathOperations {
List<Node> evaluateAsNodeList(String expression, Source context) throws XPathException;
/**
* Evaluates the given expression as a {@code double}. Returns the evaluation of the expression, or {@link Double#NaN}
* if it is invalid.
* Evaluates the given expression as a {@code double}. Returns the evaluation of the
* expression, or {@link Double#NaN} if it is invalid.
* <p>
* The return value is determined per the {@code number()} function as defined in the XPath specification. This means
* that if the expression selects multiple nodes, it will return the number value of the first node.
*
* The return value is determined per the {@code number()} function as defined in the
* XPath specification. This means that if the expression selects multiple nodes, it
* will return the number value of the first node.
* @param expression the XPath expression
* @param context the context starting point
* @return the result of the evaluation
* @throws XPathException in case of XPath errors
* @see <a href="http://www.w3.org/TR/xpath/#function-number">XPath specification - number() function</a>
* @see <a href="http://www.w3.org/TR/xpath/#function-number">XPath specification -
* number() function</a>
*/
double evaluateAsDouble(String expression, Source context) throws XPathException;
/**
* Evaluates the given expression as a {@link String}. Returns the evaluation of the expression, or {@code null} if it
* is invalid.
* Evaluates the given expression as a {@link String}. Returns the evaluation of the
* expression, or {@code null} if it is invalid.
* <p>
* The return value is determined per the {@code string()} function as defined in the XPath specification. This means
* that if the expression selects multiple nodes, it will return the string value of the first node.
*
* The return value is determined per the {@code string()} function as defined in the
* XPath specification. This means that if the expression selects multiple nodes, it
* will return the string value of the first node.
* @param expression the XPath expression
* @param context the context starting point
* @return the result of the evaluation
* @throws XPathException in case of XPath errors
* @see <a href="http://www.w3.org/TR/xpath/#function-string">XPath specification - string() function</a>
* @see <a href="http://www.w3.org/TR/xpath/#function-string">XPath specification -
* string() function</a>
*/
String evaluateAsString(String expression, Source context) throws XPathException;
/**
* Evaluates the given expression, mapping a single {@link Node} result to a Java object via a {@link NodeMapper}.
*
* Evaluates the given expression, mapping a single {@link Node} result to a Java
* object via a {@link NodeMapper}.
* @param expression the XPath expression
* @param context the context starting point
* @param nodeMapper object that will map one object per node
@@ -122,8 +123,8 @@ public interface XPathOperations {
<T> T evaluateAsObject(String expression, Source context, NodeMapper<T> nodeMapper) throws XPathException;
/**
* Evaluates the given expression, mapping each result {@link Node} objects to a Java object via a {@link NodeMapper}.
*
* Evaluates the given expression, mapping each result {@link Node} objects to a Java
* object via a {@link NodeMapper}.
* @param expression the XPath expression
* @param context the context starting point
* @param nodeMapper object that will map one object per node
@@ -134,9 +135,8 @@ public interface XPathOperations {
<T> List<T> evaluate(String expression, Source context, NodeMapper<T> nodeMapper) throws XPathException;
/**
* Evaluates the given expression, handling the result {@link Node} objects on a per-node basis with a
* {@link NodeCallbackHandler}.
*
* Evaluates the given expression, handling the result {@link Node} objects on a
* per-node basis with a {@link NodeCallbackHandler}.
* @param expression the XPath expression
* @param context the context starting point
* @param callbackHandler object that will extract results, one row at a time
@@ -144,4 +144,5 @@ public interface XPathOperations {
* @see <a href="http://www.w3.org/TR/xpath#node-sets">XPath specification</a>
*/
void evaluate(String expression, Source context, NodeCallbackHandler callbackHandler) throws XPathException;
}

View File

@@ -1,11 +1,11 @@
/*
* Copyright 2005-2022 the original author or authors.
* Copyright 2005-2025 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
@@ -26,8 +26,8 @@ package org.springframework.xml.xpath;
public class XPathParseException extends XPathException {
/**
* Constructs a new instance of the {@code XPathParseException} with the specific detail message.
*
* Constructs a new instance of the {@code XPathParseException} with the specific
* detail message.
* @param message the detail message
*/
public XPathParseException(String message) {
@@ -35,12 +35,13 @@ public class XPathParseException extends XPathException {
}
/**
* Constructs a new instance of the {@code XPathParseException} with the specific detail message and exception.
*
* Constructs a new instance of the {@code XPathParseException} with the specific
* detail message and exception.
* @param message the detail message
* @param throwable the wrapped exception
*/
public XPathParseException(String message, Throwable throwable) {
super(message, throwable);
}
}

View File

@@ -1,11 +1,11 @@
/*
* Copyright 2005-2022 the original author or authors.
* Copyright 2005-2025 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
@@ -25,6 +25,10 @@ import javax.xml.parsers.ParserConfigurationException;
import javax.xml.transform.Source;
import javax.xml.transform.dom.DOMSource;
import org.w3c.dom.Document;
import org.w3c.dom.Element;
import org.xml.sax.SAXException;
import org.springframework.beans.factory.InitializingBean;
import org.springframework.core.io.Resource;
import org.springframework.util.Assert;
@@ -32,15 +36,12 @@ import org.springframework.xml.DocumentBuilderFactoryUtils;
import org.springframework.xml.sax.SaxUtils;
import org.springframework.xml.validation.XmlValidator;
import org.springframework.xml.validation.XmlValidatorFactory;
import org.w3c.dom.Document;
import org.w3c.dom.Element;
import org.xml.sax.SAXException;
/**
* The default {@link XsdSchema} implementation.
* <p>
* Allows a XSD to be set by the {@link #setXsd(Resource)}, or directly in the {@link #SimpleXsdSchema(Resource)
* constructor}.
* Allows a XSD to be set by the {@link #setXsd(Resource)}, or directly in the
* {@link #SimpleXsdSchema(Resource) constructor}.
*
* @author Mark LaFond
* @author Arjen Poutsma
@@ -68,13 +69,15 @@ public class SimpleXsdSchema implements XsdSchema, InitializingBean {
* <p>
* A subsequent call to the {@link #setXsd(Resource)} method is required.
*/
public SimpleXsdSchema() {}
public SimpleXsdSchema() {
}
/**
* Create a new instance of the {@link SimpleXsdSchema} class with the specified resource.
*
* Create a new instance of the {@link SimpleXsdSchema} class with the specified
* resource.
* @param xsdResource the XSD resource; must not be {@code null}
* @throws IllegalArgumentException if the supplied {@code xsdResource} is {@code null}
* @throws IllegalArgumentException if the supplied {@code xsdResource} is
* {@code null}
*/
public SimpleXsdSchema(Resource xsdResource) {
Assert.notNull(xsdResource, "xsdResource must not be null");
@@ -82,8 +85,8 @@ public class SimpleXsdSchema implements XsdSchema, InitializingBean {
}
/**
* Set the XSD resource to be exposed by calls to this instances' {@link #getSource()} method.
*
* Set the XSD resource to be exposed by calls to this instances' {@link #getSource()}
* method.
* @param xsdResource the XSD resource
*/
public void setXsd(Resource xsdResource) {
@@ -108,7 +111,8 @@ public class SimpleXsdSchema implements XsdSchema, InitializingBean {
public XmlValidator createValidator() {
try {
return XmlValidatorFactory.createValidator(xsdResource, XmlValidatorFactory.SCHEMA_W3C_XML);
} catch (IOException ex) {
}
catch (IOException ex) {
throw new XsdSchemaException(ex.getMessage(), ex);
}
}

View File

@@ -1,11 +1,11 @@
/*
* Copyright 2005-2022 the original author or authors.
* Copyright 2005-2025 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
@@ -31,22 +31,20 @@ public interface XsdSchema {
/**
* Returns the target namespace of this schema.
*
* @return the target namespace
*/
String getTargetNamespace();
/**
* Returns the {@link Source} of the schema.
*
* @return the source of this XSD schema
*/
Source getSource();
/**
* Creates a {@link XmlValidator} based on the schema.
*
* @return a validator for this schema
*/
XmlValidator createValidator();
}

View File

@@ -1,11 +1,11 @@
/*
* Copyright 2005-2022 the original author or authors.
* Copyright 2005-2025 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
@@ -28,14 +28,12 @@ public interface XsdSchemaCollection {
/**
* Returns all schemas contained in this collection.
*
* @return the schemas contained in this collection
*/
XsdSchema[] getXsdSchemas();
/**
* Creates a {@link XmlValidator} based on the schemas contained in this collection.
*
* @return a validator for this collection
*/
XmlValidator createValidator();

View File

@@ -1,11 +1,11 @@
/*
* Copyright 2005-2022 the original author or authors.
* Copyright 2005-2025 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
@@ -35,4 +35,5 @@ public class XsdSchemaException extends XmlException {
public XsdSchemaException(String message, Throwable throwable) {
super(message, throwable);
}
}

View File

@@ -1,11 +1,11 @@
/*
* Copyright 2005-2022 the original author or authors.
* Copyright 2005-2025 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
@@ -31,6 +31,8 @@ import javax.xml.transform.stream.StreamSource;
import org.apache.ws.commons.schema.XmlSchema;
import org.apache.ws.commons.schema.XmlSchemaCollection;
import org.apache.ws.commons.schema.XmlSchemaSerializer;
import org.w3c.dom.Document;
import org.springframework.beans.BeanInstantiationException;
import org.springframework.beans.BeanUtils;
import org.springframework.core.io.Resource;
@@ -39,10 +41,10 @@ import org.springframework.util.Assert;
import org.springframework.xml.validation.XmlValidator;
import org.springframework.xml.validation.XmlValidatorFactory;
import org.springframework.xml.xsd.XsdSchema;
import org.w3c.dom.Document;
/**
* Implementation of the {@link XsdSchema} interface that uses Apache WS-Commons XML Schema.
* Implementation of the {@link XsdSchema} interface that uses Apache WS-Commons XML
* Schema.
*
* @author Arjen Poutsma
* @see <a href="http://ws.apache.org/commons/XmlSchema/">Commons XML Schema</a>
@@ -55,8 +57,8 @@ public class CommonsXsdSchema implements XsdSchema {
private final XmlSchemaCollection collection;
/**
* Create a new instance of the {@code CommonsXsdSchema} class with the specified {@link XmlSchema} reference.
*
* Create a new instance of the {@code CommonsXsdSchema} class with the specified
* {@link XmlSchema} reference.
* @param schema the Commons {@code XmlSchema} object; must not be {@code null}
* @throws IllegalArgumentException if the supplied {@code schema} is {@code null}
*/
@@ -65,11 +67,11 @@ public class CommonsXsdSchema implements XsdSchema {
}
/**
* Create a new instance of the {@code CommonsXsdSchema} class with the specified {@link XmlSchema} and
* {@link XmlSchemaCollection} reference.
*
* Create a new instance of the {@code CommonsXsdSchema} class with the specified
* {@link XmlSchema} and {@link XmlSchemaCollection} reference.
* @param schema the Commons {@code XmlSchema} object; must not be {@code null}
* @param collection the Commons {@code XmlSchemaCollection} object; can be {@code null}
* @param collection the Commons {@code XmlSchemaCollection} object; can be
* {@code null}
* @throws IllegalArgumentException if the supplied {@code schema} is {@code null}
*/
protected CommonsXsdSchema(XmlSchema schema, XmlSchemaCollection collection) {
@@ -90,7 +92,8 @@ public class CommonsXsdSchema implements XsdSchema {
@Override
public Source getSource() {
// try to use the package-friendly XmlSchemaSerializer first, fall back to slower stream-based version
// try to use the package-friendly XmlSchemaSerializer first, fall back to slower
// stream-based version
try {
XmlSchemaSerializer serializer = BeanUtils.instantiateClass(XmlSchemaSerializer.class);
if (collection != null) {
@@ -98,13 +101,15 @@ public class CommonsXsdSchema implements XsdSchema {
}
Document[] serializedSchemas = serializer.serializeSchema(schema, false);
return new DOMSource(serializedSchemas[0]);
} catch (BeanInstantiationException | XmlSchemaSerializer.XmlSchemaSerializerException ex) {
}
catch (BeanInstantiationException | XmlSchemaSerializer.XmlSchemaSerializerException ex) {
// ignore
}
ByteArrayOutputStream bos = new ByteArrayOutputStream();
try {
schema.write(bos);
} catch (UnsupportedEncodingException ex) {
}
catch (UnsupportedEncodingException ex) {
throw new CommonsXsdSchemaException(ex.getMessage(), ex);
}
ByteArrayInputStream bis = new ByteArrayInputStream(bos.toByteArray());
@@ -116,7 +121,8 @@ public class CommonsXsdSchema implements XsdSchema {
try {
Resource resource = new UrlResource(schema.getSourceURI());
return XmlValidatorFactory.createValidator(resource, XmlValidatorFactory.SCHEMA_W3C_XML);
} catch (IOException ex) {
}
catch (IOException ex) {
throw new CommonsXsdSchemaException(ex.getMessage(), ex);
}
}

View File

@@ -1,11 +1,11 @@
/*
* Copyright 2005-2022 the original author or authors.
* Copyright 2005-2025 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
@@ -32,6 +32,8 @@ import org.apache.ws.commons.schema.XmlSchemaInclude;
import org.apache.ws.commons.schema.XmlSchemaObject;
import org.apache.ws.commons.schema.resolver.DefaultURIResolver;
import org.apache.ws.commons.schema.resolver.URIResolver;
import org.xml.sax.InputSource;
import org.springframework.beans.factory.InitializingBean;
import org.springframework.context.ResourceLoaderAware;
import org.springframework.core.io.Resource;
@@ -44,14 +46,15 @@ import org.springframework.xml.validation.XmlValidator;
import org.springframework.xml.validation.XmlValidatorFactory;
import org.springframework.xml.xsd.XsdSchema;
import org.springframework.xml.xsd.XsdSchemaCollection;
import org.xml.sax.InputSource;
/**
* Implementation of the {@link XsdSchemaCollection} that uses Apache WS-Commons XML Schema.
* Implementation of the {@link XsdSchemaCollection} that uses Apache WS-Commons XML
* Schema.
* <p>
* Setting the {@link #setInline(boolean) inline} flag to {@code true} will result in all referenced schemas (included
* and imported) being merged into the referred schema. When including the schemas into a WSDL, this greatly simplifies
* the deployment of the schemas.
* Setting the {@link #setInline(boolean) inline} flag to {@code true} will result in all
* referenced schemas (included and imported) being merged into the referred schema. When
* including the schemas into a WSDL, this greatly simplifies the deployment of the
* schemas.
*
* @author Arjen Poutsma
* @see <a href="http://ws.apache.org/commons/XmlSchema/">Commons XML Schema</a>
@@ -78,11 +81,12 @@ public class CommonsXsdSchemaCollection implements XsdSchemaCollection, Initiali
* <p>
* A subsequent call to the {@link #setXsds(Resource[])} is required.
*/
public CommonsXsdSchemaCollection() {}
public CommonsXsdSchemaCollection() {
}
/**
* Constructs a new instance of the {@code CommonsXsdSchemaCollection} based on the given resources.
*
* Constructs a new instance of the {@code CommonsXsdSchemaCollection} based on the
* given resources.
* @param resources the schema resources to load
*/
public CommonsXsdSchemaCollection(Resource... resources) {
@@ -91,7 +95,6 @@ public class CommonsXsdSchemaCollection implements XsdSchemaCollection, Initiali
/**
* Sets the schema resources to be loaded.
*
* @param xsdResources the schema resources to be loaded
*/
public void setXsds(Resource... xsdResources) {
@@ -110,7 +113,8 @@ public class CommonsXsdSchemaCollection implements XsdSchemaCollection, Initiali
/**
* Sets the WS-Commons uri resolver to use when resolving (relative) schemas.
* <p>
* Default is an internal subclass of {@link DefaultURIResolver} which correctly handles schemas on the classpath.
* Default is an internal subclass of {@link DefaultURIResolver} which correctly
* handles schemas on the classpath.
*/
public void setUriResolver(URIResolver uriResolver) {
Assert.notNull(uriResolver, "'uriResolver' must not be null");
@@ -141,7 +145,8 @@ public class CommonsXsdSchemaCollection implements XsdSchemaCollection, Initiali
inlineIncludes(xmlSchema, processedIncludes, processedImports);
findImports(xmlSchema, processedImports, processedIncludes);
}
} catch (Exception ex) {
}
catch (Exception ex) {
throw new CommonsXsdSchemaException("Schema [" + xsdResource + "] could not be loaded", ex);
}
}
@@ -173,7 +178,8 @@ public class CommonsXsdSchemaCollection implements XsdSchemaCollection, Initiali
}
}
return XmlValidatorFactory.createValidator(resources, XmlValidatorFactory.SCHEMA_W3C_XML);
} catch (IOException ex) {
}
catch (IOException ex) {
throw new CommonsXsdSchemaException(ex.getMessage(), ex);
}
}
@@ -205,8 +211,8 @@ public class CommonsXsdSchemaCollection implements XsdSchemaCollection, Initiali
if (external instanceof XmlSchemaImport) {
XmlSchemaImport schemaImport = (XmlSchemaImport) external;
XmlSchema importedSchema = schemaImport.getSchema();
if (!"http://www.w3.org/XML/1998/namespace".equals(schemaImport.getNamespace()) && importedSchema != null
&& !processedImports.contains(importedSchema)) {
if (!"http://www.w3.org/XML/1998/namespace".equals(schemaImport.getNamespace())
&& importedSchema != null && !processedImports.contains(importedSchema)) {
inlineIncludes(importedSchema, processedIncludes, processedImports);
findImports(importedSchema, processedImports, processedIncludes);
xmlSchemas.add(importedSchema);
@@ -239,7 +245,8 @@ public class CommonsXsdSchemaCollection implements XsdSchemaCollection, Initiali
Resource resource = resourceLoader.getResource(schemaLocation);
if (resource.exists()) {
return createInputSource(resource);
} else if (StringUtils.hasLength(baseUri)) {
}
else if (StringUtils.hasLength(baseUri)) {
// let's try and find it relative to the baseUri, see SWS-413
try {
Resource baseUriResource = new UrlResource(baseUri);
@@ -247,7 +254,8 @@ public class CommonsXsdSchemaCollection implements XsdSchemaCollection, Initiali
if (resource.exists()) {
return createInputSource(resource);
}
} catch (IOException e) {
}
catch (IOException e) {
// fall through
}
}
@@ -264,10 +272,12 @@ public class CommonsXsdSchemaCollection implements XsdSchemaCollection, Initiali
private InputSource createInputSource(Resource resource) {
try {
return SaxUtils.createInputSource(resource);
} catch (IOException ex) {
}
catch (IOException ex) {
throw new CommonsXsdSchemaException("Could not resolve location", ex);
}
}
}
}

View File

@@ -1,11 +1,11 @@
/*
* Copyright 2005-2022 the original author or authors.
* Copyright 2005-2025 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
@@ -34,4 +34,5 @@ public class CommonsXsdSchemaException extends XsdSchemaException {
public CommonsXsdSchemaException(String message, Throwable exception) {
super(message, exception);
}
}

View File

@@ -1,11 +1,11 @@
/*
* Copyright 2005-2022 the original author or authors.
* Copyright 2005-2025 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
@@ -16,8 +16,6 @@
package org.springframework.xml.dom;
import static org.xmlunit.assertj.XmlAssert.*;
import java.io.StringReader;
import javax.xml.parsers.DocumentBuilder;
@@ -25,13 +23,16 @@ import javax.xml.parsers.DocumentBuilderFactory;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.springframework.xml.DocumentBuilderFactoryUtils;
import org.w3c.dom.Document;
import org.w3c.dom.Element;
import org.xml.sax.InputSource;
import org.xml.sax.XMLReader;
import org.xml.sax.helpers.XMLReaderFactory;
import org.springframework.xml.DocumentBuilderFactoryUtils;
import static org.xmlunit.assertj.XmlAssert.assertThat;
public class DomContentHandlerTest {
private static final String XML_1 = "<?xml version='1.0' encoding='UTF-8'?>" + "<?pi content?>"
@@ -42,7 +43,8 @@ public class DomContentHandlerTest {
private static final String XML_2_EXPECTED = "<?xml version='1.0' encoding='UTF-8'?>" + "<root xmlns='namespace'>"
+ "<child xmlns='namespace2' />" + "</root>";
private static final String XML_2_SNIPPET = "<?xml version='1.0' encoding='UTF-8'?>" + "<child xmlns='namespace2' />";
private static final String XML_2_SNIPPET = "<?xml version='1.0' encoding='UTF-8'?>"
+ "<child xmlns='namespace2' />";
private Document expected;
@@ -99,4 +101,5 @@ public class DomContentHandlerTest {
assertThat(result).and(expected).areSimilar();
}
}

View File

@@ -1,11 +1,11 @@
/*
* Copyright 2005-2022 the original author or authors.
* Copyright 2005-2025 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
@@ -16,13 +16,13 @@
package org.springframework.xml.namespace;
import static org.assertj.core.api.Assertions.*;
import javax.xml.namespace.QName;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import static org.assertj.core.api.Assertions.assertThat;
public class QNameEditorTest {
private QNameEditor editor;
@@ -70,4 +70,5 @@ public class QNameEditorTest {
assertThat(result.getPrefix()).isEqualTo(qname.getPrefix());
assertThat(result.getNamespaceURI()).isEqualTo(qname.getNamespaceURI());
}
}

View File

@@ -1,11 +1,11 @@
/*
* Copyright 2005-2022 the original author or authors.
* Copyright 2005-2025 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
@@ -51,7 +51,8 @@ class SimpleNamespaceContextTest {
assertThat(context.getNamespaceURI("prefix")).isEqualTo("namespaceURI");
assertThat(context.getNamespaceURI("unbound")).isEmpty();
assertThat(context.getNamespaceURI(XMLConstants.XML_NS_PREFIX)).isEqualTo(XMLConstants.XML_NS_URI);
assertThat(context.getNamespaceURI(XMLConstants.XMLNS_ATTRIBUTE)).isEqualTo(XMLConstants.XMLNS_ATTRIBUTE_NS_URI);
assertThat(context.getNamespaceURI(XMLConstants.XMLNS_ATTRIBUTE))
.isEqualTo(XMLConstants.XMLNS_ATTRIBUTE_NS_URI);
}
@Test
@@ -103,13 +104,13 @@ class SimpleNamespaceContextTest {
String result = iterator.next();
assertThat(result)
.has(new Condition<>(value -> value.equals("prefix1") || value.equals("prefix2"), "verify prefix"));
.has(new Condition<>(value -> value.equals("prefix1") || value.equals("prefix2"), "verify prefix"));
assertThat(iterator.hasNext()).isTrue();
result = iterator.next();
assertThat(result)
.has(new Condition<>(value -> value.equals("prefix1") || value.equals("prefix2"), "verify prefix"));
.has(new Condition<>(value -> value.equals("prefix1") || value.equals("prefix2"), "verify prefix"));
assertThat(iterator.hasNext()).isFalse();
}

View File

@@ -1,11 +1,11 @@
/*
* Copyright 2005-2022 the original author or authors.
* Copyright 2005-2025 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
@@ -16,12 +16,13 @@
package org.springframework.xml.sax;
import static org.assertj.core.api.Assertions.*;
import org.junit.jupiter.api.Test;
import org.springframework.core.io.FileSystemResource;
import org.springframework.core.io.Resource;
import static org.assertj.core.api.Assertions.assertThat;
public class SaxUtilsTest {
@Test
@@ -33,4 +34,5 @@ public class SaxUtilsTest {
assertThat(systemId).isNotNull();
assertThat(systemId).endsWith("path%20with%20spaces/file%20with%20spaces.txt");
}
}

View File

@@ -1,11 +1,11 @@
/*
* Copyright 2005-2022 the original author or authors.
* Copyright 2005-2025 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
@@ -16,16 +16,17 @@
package org.springframework.xml.transform;
import static org.xmlunit.assertj.XmlAssert.*;
import javax.xml.transform.Transformer;
import javax.xml.transform.dom.DOMSource;
import org.junit.jupiter.api.Test;
import org.springframework.xml.DocumentBuilderFactoryUtils;
import org.w3c.dom.Document;
import org.w3c.dom.Element;
import org.springframework.xml.DocumentBuilderFactoryUtils;
import static org.xmlunit.assertj.XmlAssert.assertThat;
public class StringResultTest {
@Test
@@ -39,7 +40,9 @@ public class StringResultTest {
StringResult result = new StringResult();
transformer.transform(new DOMSource(document), result);
assertThat(result.toString()).and("<prefix:localName xmlns:prefix='namespace'/>").ignoreWhitespace().areIdentical();
assertThat(result.toString()).and("<prefix:localName xmlns:prefix='namespace'/>")
.ignoreWhitespace()
.areIdentical();
}
}

View File

@@ -1,11 +1,11 @@
/*
* Copyright 2005-2022 the original author or authors.
* Copyright 2005-2025 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
@@ -16,8 +16,6 @@
package org.springframework.xml.transform;
import static org.assertj.core.api.Assertions.*;
import javax.xml.transform.Transformer;
import javax.xml.transform.TransformerException;
import javax.xml.transform.dom.DOMResult;
@@ -25,6 +23,8 @@ import javax.xml.transform.dom.DOMResult;
import org.junit.jupiter.api.Test;
import org.w3c.dom.Element;
import static org.assertj.core.api.Assertions.assertThat;
public class StringSourceTest {
@Test
@@ -40,4 +40,5 @@ public class StringSourceTest {
assertThat(rootElement.getPrefix()).isEqualTo("prefix");
assertThat(rootElement.getNamespaceURI()).isEqualTo("namespace");
}
}

View File

@@ -1,11 +1,11 @@
/*
* Copyright 2005-2022 the original author or authors.
* Copyright 2005-2025 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
@@ -16,9 +16,6 @@
package org.springframework.xml.transform;
import static org.mockito.Mockito.*;
import static org.xmlunit.assertj.XmlAssert.*;
import javax.xml.transform.Result;
import javax.xml.transform.Source;
import javax.xml.transform.Transformer;
@@ -27,9 +24,13 @@ import javax.xml.transform.TransformerException;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import static org.mockito.Mockito.mock;
import static org.xmlunit.assertj.XmlAssert.assertThat;
public class TransformerHelperTest {
private TransformerHelper helper;
private Transformer transformer;
@BeforeEach

View File

@@ -1,11 +1,11 @@
/*
* Copyright 2005-2022 the original author or authors.
* Copyright 2005-2025 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
@@ -16,9 +16,6 @@
package org.springframework.xml.transform;
import static org.assertj.core.api.Assertions.*;
import static org.easymock.EasyMock.*;
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.InputStream;
@@ -47,9 +44,6 @@ import javax.xml.transform.stream.StreamResult;
import javax.xml.transform.stream.StreamSource;
import org.junit.jupiter.api.Test;
import org.springframework.util.xml.StaxUtils;
import org.springframework.xml.DocumentBuilderFactoryUtils;
import org.springframework.xml.XMLInputFactoryUtils;
import org.w3c.dom.Document;
import org.w3c.dom.Element;
import org.xml.sax.ContentHandler;
@@ -60,6 +54,16 @@ import org.xml.sax.ext.LexicalHandler;
import org.xml.sax.helpers.DefaultHandler;
import org.xml.sax.helpers.XMLReaderFactory;
import org.springframework.util.xml.StaxUtils;
import org.springframework.xml.DocumentBuilderFactoryUtils;
import org.springframework.xml.XMLInputFactoryUtils;
import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.assertThatIllegalArgumentException;
import static org.easymock.EasyMock.createMock;
import static org.easymock.EasyMock.replay;
import static org.easymock.EasyMock.verify;
public class TraxUtilsTest {
@Test
@@ -307,7 +311,8 @@ public class TraxUtilsTest {
Source source = new Source() {
public void setSystemId(String systemId) {}
public void setSystemId(String systemId) {
}
public String getSystemId() {
return null;
@@ -321,7 +326,8 @@ public class TraxUtilsTest {
public void testDoWithInvalidResult() throws Exception {
Result result = new Result() {
public void setSystemId(String systemId) {}
public void setSystemId(String systemId) {
}
public String getSystemId() {
return null;
@@ -330,4 +336,5 @@ public class TraxUtilsTest {
assertThatIllegalArgumentException().isThrownBy(() -> TraxUtils.doWithResult(result, null));
}
}

View File

@@ -1,11 +1,11 @@
/*
* Copyright 2005-2022 the original author or authors.
* Copyright 2005-2025 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
@@ -16,8 +16,6 @@
package org.springframework.xml.validation;
import static org.assertj.core.api.Assertions.*;
import java.io.InputStream;
import javax.xml.parsers.DocumentBuilderFactory;
@@ -29,15 +27,18 @@ import javax.xml.transform.stream.StreamSource;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.springframework.core.io.ClassPathResource;
import org.springframework.core.io.Resource;
import org.springframework.xml.DocumentBuilderFactoryUtils;
import org.springframework.xml.transform.ResourceSource;
import org.w3c.dom.Document;
import org.xml.sax.InputSource;
import org.xml.sax.SAXException;
import org.xml.sax.SAXParseException;
import org.springframework.core.io.ClassPathResource;
import org.springframework.core.io.Resource;
import org.springframework.xml.DocumentBuilderFactoryUtils;
import org.springframework.xml.transform.ResourceSource;
import static org.assertj.core.api.Assertions.assertThat;
public abstract class AbstractValidatorFactoryTestCase {
private XmlValidator validator;
@@ -159,11 +160,14 @@ public abstract class AbstractValidatorFactoryTestCase {
return new SAXParseException[0];
}
public void warning(SAXParseException exception) throws SAXException {}
public void warning(SAXParseException exception) throws SAXException {
}
public void error(SAXParseException exception) throws SAXException {}
public void error(SAXParseException exception) throws SAXException {
}
public void fatalError(SAXParseException exception) throws SAXException {}
public void fatalError(SAXParseException exception) throws SAXException {
}
};
SAXParseException[] errors = validator.validate(new StreamSource(invalidInputStream), myHandler);

View File

@@ -1,11 +1,11 @@
/*
* Copyright 2005-2022 the original author or authors.
* Copyright 2005-2025 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
@@ -26,4 +26,5 @@ public class Jaxp13ValidatorFactoryTest extends AbstractValidatorFactoryTestCase
protected XmlValidator createValidator(Resource[] schemaResources, String schemaLanguage) throws IOException {
return Jaxp13ValidatorFactory.createValidator(schemaResources, schemaLanguage);
}
}

View File

@@ -1,11 +1,11 @@
/*
* Copyright 2005-2022 the original author or authors.
* Copyright 2005-2025 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
@@ -26,4 +26,5 @@ public class Jaxp15ValidatorFactoryTest extends AbstractValidatorFactoryTestCase
protected XmlValidator createValidator(Resource[] schemaResources, String schemaLanguage) throws IOException {
return Jaxp15ValidatorFactory.createValidator(schemaResources, schemaLanguage);
}
}

View File

@@ -1,11 +1,11 @@
/*
* Copyright 2005-2022 the original author or authors.
* Copyright 2005-2025 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
@@ -16,15 +16,17 @@
package org.springframework.xml.validation;
import static org.assertj.core.api.Assertions.*;
import javax.xml.XMLConstants;
import javax.xml.validation.Schema;
import org.junit.jupiter.api.Test;
import org.springframework.core.io.ClassPathResource;
import org.springframework.core.io.Resource;
import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.assertThatIllegalArgumentException;
public class SchemaLoaderUtilsTest {
@Test
@@ -50,7 +52,7 @@ public class SchemaLoaderUtilsTest {
public void testLoadNullSchema() throws Exception {
assertThatIllegalArgumentException()
.isThrownBy(() -> SchemaLoaderUtils.loadSchema((Resource) null, XMLConstants.W3C_XML_SCHEMA_NS_URI));
.isThrownBy(() -> SchemaLoaderUtils.loadSchema((Resource) null, XMLConstants.W3C_XML_SCHEMA_NS_URI));
}
@Test
@@ -65,4 +67,5 @@ public class SchemaLoaderUtilsTest {
assertThat(envelope.isOpen()).isFalse();
assertThat(encoding.isOpen()).isFalse();
}
}

View File

@@ -1,11 +1,11 @@
/*
* Copyright 2005-2022 the original author or authors.
* Copyright 2005-2025 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
@@ -16,8 +16,6 @@
package org.springframework.xml.validation;
import static org.assertj.core.api.Assertions.*;
import java.io.File;
import java.io.IOException;
import java.io.InputStream;
@@ -25,10 +23,14 @@ import java.net.URI;
import java.net.URL;
import org.junit.jupiter.api.Test;
import org.springframework.core.io.AbstractResource;
import org.springframework.core.io.ClassPathResource;
import org.springframework.core.io.Resource;
import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.assertThatIllegalArgumentException;
public class XmlValidatorFactoryTest {
@Test
@@ -43,15 +45,15 @@ public class XmlValidatorFactoryTest {
@Test
public void testNonExistentResource() {
assertThatIllegalArgumentException().isThrownBy(
() -> XmlValidatorFactory.createValidator(new NonExistentResource(), XmlValidatorFactory.SCHEMA_W3C_XML));
assertThatIllegalArgumentException().isThrownBy(() -> XmlValidatorFactory
.createValidator(new NonExistentResource(), XmlValidatorFactory.SCHEMA_W3C_XML));
}
@Test
public void testInvalidSchemaLanguage() {
assertThatIllegalArgumentException().isThrownBy(() -> XmlValidatorFactory
.createValidator(new ClassPathResource("schema.xsd", AbstractValidatorFactoryTestCase.class), "bla"));
.createValidator(new ClassPathResource("schema.xsd", AbstractValidatorFactoryTestCase.class), "bla"));
}
private static class NonExistentResource extends AbstractResource {
@@ -105,5 +107,7 @@ public class XmlValidatorFactoryTest {
public boolean isReadable() {
return false;
}
}
}

View File

@@ -1,11 +1,11 @@
/*
* Copyright 2005-2022 the original author or authors.
* Copyright 2005-2025 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
@@ -16,8 +16,6 @@
package org.springframework.xml.xpath;
import static org.assertj.core.api.Assertions.*;
import java.io.IOException;
import java.io.InputStream;
import java.util.HashMap;
@@ -29,12 +27,16 @@ import javax.xml.parsers.DocumentBuilderFactory;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.springframework.xml.DocumentBuilderFactoryUtils;
import org.w3c.dom.DOMException;
import org.w3c.dom.Document;
import org.w3c.dom.Node;
import org.xml.sax.SAXException;
import org.springframework.xml.DocumentBuilderFactoryUtils;
import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.assertThatExceptionOfType;
public abstract class AbstractXPathExpressionFactoryTestCase {
private Document noNamespacesDocument;
@@ -57,14 +59,16 @@ public abstract class AbstractXPathExpressionFactoryTestCase {
try {
noNamespacesDocument = documentBuilder.parse(inputStream);
} finally {
}
finally {
inputStream.close();
}
inputStream = getClass().getResourceAsStream("namespaces.xml");
try {
namespacesDocument = documentBuilder.parse(inputStream);
} finally {
}
finally {
inputStream.close();
}
}
@@ -135,7 +139,8 @@ public abstract class AbstractXPathExpressionFactoryTestCase {
@Test
public void testEvaluateAsDoubleNamespaces() throws IOException, SAXException {
XPathExpression expression = createXPathExpression("/prefix1:root/prefix2:child/prefix2:number/text()", namespaces);
XPathExpression expression = createXPathExpression("/prefix1:root/prefix2:child/prefix2:number/text()",
namespaces);
double result = expression.evaluateAsNumber(namespacesDocument);
assertThat(result).isEqualTo(42.0D);
@@ -229,7 +234,8 @@ public abstract class AbstractXPathExpressionFactoryTestCase {
@Test
public void testEvaluateAsStringNamespaces() {
XPathExpression expression = createXPathExpression("/prefix1:root/prefix2:child/prefix2:text/text()", namespaces);
XPathExpression expression = createXPathExpression("/prefix1:root/prefix2:child/prefix2:text/text()",
namespaces);
String result = expression.evaluateAsString(namespacesDocument);
assertThat(result).isEqualTo("text");
@@ -280,4 +286,5 @@ public abstract class AbstractXPathExpressionFactoryTestCase {
protected abstract XPathExpression createXPathExpression(String expression);
protected abstract XPathExpression createXPathExpression(String expression, Map<String, String> namespaces);
}

View File

@@ -1,11 +1,11 @@
/*
* Copyright 2005-2022 the original author or authors.
* Copyright 2005-2025 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
@@ -16,8 +16,6 @@
package org.springframework.xml.xpath;
import static org.assertj.core.api.Assertions.*;
import java.io.IOException;
import java.io.InputStream;
import java.net.URL;
@@ -36,16 +34,20 @@ import javax.xml.transform.stream.StreamSource;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.springframework.core.io.ClassPathResource;
import org.springframework.xml.DocumentBuilderFactoryUtils;
import org.springframework.xml.sax.SaxUtils;
import org.springframework.xml.transform.ResourceSource;
import org.w3c.dom.DOMException;
import org.w3c.dom.Document;
import org.w3c.dom.Node;
import org.xml.sax.InputSource;
import org.xml.sax.SAXException;
import org.springframework.core.io.ClassPathResource;
import org.springframework.xml.DocumentBuilderFactoryUtils;
import org.springframework.xml.sax.SaxUtils;
import org.springframework.xml.transform.ResourceSource;
import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.assertThatExceptionOfType;
public abstract class AbstractXPathTemplateTestCase {
XPathOperations template;
@@ -58,7 +60,8 @@ public abstract class AbstractXPathTemplateTestCase {
public final void setUp() throws Exception {
template = createTemplate();
namespaces = new ResourceSource(new ClassPathResource("namespaces.xml", AbstractXPathTemplateTestCase.class));
nonamespaces = new ResourceSource(new ClassPathResource("nonamespaces.xml", AbstractXPathTemplateTestCase.class));
nonamespaces = new ResourceSource(
new ClassPathResource("nonamespaces.xml", AbstractXPathTemplateTestCase.class));
}
protected abstract XPathOperations createTemplate() throws Exception;
@@ -153,8 +156,8 @@ public abstract class AbstractXPathTemplateTestCase {
DocumentBuilderFactory documentBuilderFactory = DocumentBuilderFactoryUtils.newInstance();
documentBuilderFactory.setNamespaceAware(true);
DocumentBuilder documentBuilder = documentBuilderFactory.newDocumentBuilder();
Document document = documentBuilder.parse(
SaxUtils.createInputSource(new ClassPathResource("nonamespaces.xml", AbstractXPathTemplateTestCase.class)));
Document document = documentBuilder.parse(SaxUtils
.createInputSource(new ClassPathResource("nonamespaces.xml", AbstractXPathTemplateTestCase.class)));
String result = template.evaluateAsString("/root/child/text", new DOMSource(document));
@@ -231,4 +234,5 @@ public abstract class AbstractXPathTemplateTestCase {
assertThat(results).isNotNull();
assertThat(results).containsExactly("text", "number", "boolean");
}
}

View File

@@ -1,11 +1,11 @@
/*
* Copyright 2005-2022 the original author or authors.
* Copyright 2005-2025 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
@@ -29,4 +29,5 @@ public class Jaxp13XPathExpressionFactoryTest extends AbstractXPathExpressionFac
protected XPathExpression createXPathExpression(String expression, Map<String, String> namespaces) {
return Jaxp13XPathExpressionFactory.createXPathExpression(expression, namespaces);
}
}

View File

@@ -1,11 +1,11 @@
/*
* Copyright 2005-2022 the original author or authors.
* Copyright 2005-2025 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
@@ -16,11 +16,11 @@
package org.springframework.xml.xpath;
import static org.assertj.core.api.Assertions.*;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import static org.assertj.core.api.Assertions.assertThat;
public class XPathExpressionFactoryBeanTest {
private XPathExpressionFactoryBean factoryBean;
@@ -42,4 +42,5 @@ public class XPathExpressionFactoryBeanTest {
assertThat(factoryBean.isSingleton()).isTrue();
assertThat(factoryBean.getObject()).isInstanceOf(XPathExpression.class);
}
}

View File

@@ -1,11 +1,11 @@
/*
* Copyright 2005-2022 the original author or authors.
* Copyright 2005-2025 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
@@ -16,10 +16,11 @@
package org.springframework.xml.xpath;
import static org.assertj.core.api.Assertions.*;
import org.junit.jupiter.api.Test;
import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.assertThatIllegalArgumentException;
public class XPathExpressionFactoryTest {
@Test
@@ -34,4 +35,5 @@ public class XPathExpressionFactoryTest {
public void testCreateEmptyXPathExpression() {
assertThatIllegalArgumentException().isThrownBy(() -> XPathExpressionFactory.createXPathExpression(""));
}
}

View File

@@ -1,11 +1,11 @@
/*
* Copyright 2005-2022 the original author or authors.
* Copyright 2005-2025 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
@@ -16,8 +16,6 @@
package org.springframework.xml.xsd;
import static org.assertj.core.api.Assertions.*;
import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;
import javax.xml.transform.Transformer;
@@ -26,14 +24,17 @@ import javax.xml.transform.dom.DOMResult;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.w3c.dom.Document;
import org.xmlunit.assertj.XmlAssert;
import org.springframework.core.io.ClassPathResource;
import org.springframework.core.io.Resource;
import org.springframework.xml.DocumentBuilderFactoryUtils;
import org.springframework.xml.sax.SaxUtils;
import org.springframework.xml.transform.TransformerFactoryUtils;
import org.springframework.xml.validation.XmlValidator;
import org.w3c.dom.Document;
import org.xmlunit.assertj.XmlAssert;
import static org.assertj.core.api.Assertions.assertThat;
public abstract class AbstractXsdSchemaTestCase {
@@ -91,7 +92,8 @@ public abstract class AbstractXsdSchemaTestCase {
Resource resource = new ClassPathResource("importing.xsd", AbstractXsdSchemaTestCase.class);
XsdSchema importing = createSchema(resource);
assertThat(importing.getTargetNamespace()).isEqualTo("http://www.springframework.org/spring-ws/importing/schema");
assertThat(importing.getTargetNamespace())
.isEqualTo("http://www.springframework.org/spring-ws/importing/schema");
resource = new ClassPathResource("importing.xsd", AbstractXsdSchemaTestCase.class);
Document expected = documentBuilder.parse(SaxUtils.createInputSource(resource));
@@ -130,4 +132,5 @@ public abstract class AbstractXsdSchemaTestCase {
}
protected abstract XsdSchema createSchema(Resource resource) throws Exception;
}

View File

@@ -1,11 +1,11 @@
/*
* Copyright 2005-2022 the original author or authors.
* Copyright 2005-2025 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
@@ -16,8 +16,6 @@
package org.springframework.xml.xsd.commons;
import static org.assertj.core.api.Assertions.*;
import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;
import javax.xml.transform.Transformer;
@@ -26,6 +24,9 @@ import javax.xml.transform.dom.DOMResult;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.w3c.dom.Document;
import org.xmlunit.assertj.XmlAssert;
import org.springframework.core.io.ClassPathResource;
import org.springframework.core.io.Resource;
import org.springframework.xml.DocumentBuilderFactoryUtils;
@@ -34,8 +35,9 @@ import org.springframework.xml.transform.TransformerFactoryUtils;
import org.springframework.xml.validation.XmlValidator;
import org.springframework.xml.xsd.AbstractXsdSchemaTestCase;
import org.springframework.xml.xsd.XsdSchema;
import org.w3c.dom.Document;
import org.xmlunit.assertj.XmlAssert;
import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.assertThatExceptionOfType;
public class CommonsXsdSchemaCollectionTest {
@@ -83,9 +85,10 @@ public class CommonsXsdSchemaCollectionTest {
DOMResult domResult = new DOMResult();
transformer.transform(schemas[0].getSource(), domResult);
XmlAssert.assertThat(domResult.getNode()).and(expected) //
.ignoreWhitespace() //
.areIdentical();
XmlAssert.assertThat(domResult.getNode())
.and(expected) //
.ignoreWhitespace() //
.areIdentical();
assertThat(schemas[1].getTargetNamespace()).isEqualTo("urn:2");
Resource cd = new ClassPathResource("CD.xsd", AbstractXsdSchemaTestCase.class);
@@ -93,9 +96,10 @@ public class CommonsXsdSchemaCollectionTest {
domResult = new DOMResult();
transformer.transform(schemas[1].getSource(), domResult);
XmlAssert.assertThat(domResult.getNode()).and(expected) //
.ignoreWhitespace() //
.areIdentical();
XmlAssert.assertThat(domResult.getNode())
.and(expected) //
.ignoreWhitespace() //
.areIdentical();
}
@Test
@@ -172,4 +176,5 @@ public class CommonsXsdSchemaCollectionTest {
XmlAssert.assertThat(domResult.getNode()).and(expected).ignoreWhitespace().areIdentical();
}
}

View File

@@ -1,11 +1,11 @@
/*
* Copyright 2005-2022 the original author or authors.
* Copyright 2005-2025 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
@@ -16,20 +16,21 @@
package org.springframework.xml.xsd.commons;
import static org.assertj.core.api.Assertions.*;
import javax.xml.transform.dom.DOMSource;
import org.apache.ws.commons.schema.XmlSchema;
import org.apache.ws.commons.schema.XmlSchemaCollection;
import org.junit.jupiter.api.Test;
import org.w3c.dom.Document;
import org.w3c.dom.Element;
import org.springframework.core.io.ClassPathResource;
import org.springframework.core.io.Resource;
import org.springframework.xml.sax.SaxUtils;
import org.springframework.xml.xsd.AbstractXsdSchemaTestCase;
import org.springframework.xml.xsd.XsdSchema;
import org.w3c.dom.Document;
import org.w3c.dom.Element;
import static org.assertj.core.api.Assertions.assertThat;
public class CommonsXsdSchemaTest extends AbstractXsdSchemaTestCase {
@@ -55,7 +56,8 @@ public class CommonsXsdSchemaTest extends AbstractXsdSchemaTestCase {
Element schemaElement = result.getDocumentElement();
Element elementElement = (Element) schemaElement.getFirstChild();
assertThat(elementElement.getAttributeNS("http://www.w3.org/2005/05/xmlmime", "expectedContentTypes")).isNotNull();
assertThat(elementElement.getAttributeNS("http://www.w3.org/2005/05/xmlmime", "expectedContentTypes"))
.isNotNull();
}
}