This commit is contained in:
Stéphane Nicoll
2025-02-27 14:26:51 +01:00
parent 4ffe014733
commit 3a60f3638e
178 changed files with 404 additions and 489 deletions

View File

@@ -42,7 +42,7 @@ public class DomContentHandler implements ContentHandler {
private final Document document;
private final List<Element> elements = new ArrayList<Element>();
private final List<Element> elements = new ArrayList<>();
private final Node node;
@@ -93,7 +93,7 @@ public class DomContentHandler implements ContentHandler {
}
@Override
public void characters(char ch[], int start, int length) throws SAXException {
public void characters(char[] ch, int start, int length) throws SAXException {
String data = new String(ch, start, length);
Node parent = getParent();
Node lastChild = parent.getLastChild();
@@ -138,7 +138,7 @@ public class DomContentHandler implements ContentHandler {
}
@Override
public void ignorableWhitespace(char ch[], int start, int length) throws SAXException {
public void ignorableWhitespace(char[] ch, int start, int length) throws SAXException {
}
@Override

View File

@@ -98,13 +98,11 @@ public abstract class TraxUtils {
}
}
}
else if (source instanceof SAXSource) {
SAXSource saxSource = (SAXSource) source;
else if (source instanceof SAXSource saxSource) {
callback.saxSource(saxSource.getXMLReader(), saxSource.getInputSource());
return;
}
else if (source instanceof StreamSource) {
StreamSource streamSource = (StreamSource) source;
else if (source instanceof StreamSource streamSource) {
if (streamSource.getInputStream() != null) {
callback.streamSource(streamSource.getInputStream());
return;
@@ -151,13 +149,11 @@ public abstract class TraxUtils {
}
}
}
else if (result instanceof SAXResult) {
SAXResult saxSource = (SAXResult) result;
else if (result instanceof SAXResult saxSource) {
callback.saxResult(saxSource.getHandler(), saxSource.getLexicalHandler());
return;
}
else if (result instanceof StreamResult) {
StreamResult streamSource = (StreamResult) result;
else if (result instanceof StreamResult streamSource) {
if (streamSource.getOutputStream() != null) {
callback.streamResult(streamSource.getOutputStream());
return;

View File

@@ -84,11 +84,11 @@ abstract class Jaxp13ValidatorFactory {
*/
private static class DefaultValidationErrorHandler implements ValidationErrorHandler {
private List<SAXParseException> errors = new ArrayList<SAXParseException>();
private List<SAXParseException> errors = new ArrayList<>();
@Override
public SAXParseException[] getErrors() {
return errors.toArray(new SAXParseException[errors.size()]);
return errors.toArray(new SAXParseException[0]);
}
@Override

View File

@@ -113,11 +113,11 @@ abstract class Jaxp15ValidatorFactory {
*/
private static class DefaultValidationErrorHandler implements ValidationErrorHandler {
private List<SAXParseException> errors = new ArrayList<SAXParseException>();
private List<SAXParseException> errors = new ArrayList<>();
@Override
public SAXParseException[] getErrors() {
return errors.toArray(new SAXParseException[errors.size()]);
return errors.toArray(new SAXParseException[0]);
}
@Override

View File

@@ -167,7 +167,7 @@ abstract class JaxenXPathExpressionFactory {
public <T> List<T> evaluate(Node context, NodeMapper<T> nodeMapper) throws XPathException {
try {
List<?> nodes = xpath.selectNodes(context);
List<T> results = new ArrayList<T>(nodes.size());
List<T> results = new ArrayList<>(nodes.size());
for (int i = 0; i < nodes.size(); i++) {
Node node = (Node) nodes.get(i);
try {

View File

@@ -150,7 +150,7 @@ public class JaxenXPathTemplate extends AbstractXPathTemplate {
XPath xpath = createXPath(expression);
Element element = getRootElement(context);
List<?> nodes = xpath.selectNodes(element);
List<T> results = new ArrayList<T>(nodes.size());
List<T> results = new ArrayList<>(nodes.size());
for (int i = 0; i < nodes.size(); i++) {
Node node = (Node) nodes.get(i);
try {

View File

@@ -130,7 +130,7 @@ abstract class Jaxp13XPathExpressionFactory {
}
private List<Node> toNodeList(NodeList nodeList) {
List<Node> result = new ArrayList<Node>(nodeList.getLength());
List<Node> result = new ArrayList<>(nodeList.getLength());
for (int i = 0; i < nodeList.getLength(); i++) {
result.add(nodeList.item(i));
}
@@ -171,7 +171,7 @@ abstract class Jaxp13XPathExpressionFactory {
@Override
public <T> List<T> evaluate(Node node, NodeMapper<T> nodeMapper) throws XPathException {
NodeList nodes = (NodeList) evaluate(node, XPathConstants.NODESET);
List<T> results = new ArrayList<T>(nodes.getLength());
List<T> results = new ArrayList<>(nodes.getLength());
for (int i = 0; i < nodes.getLength(); i++) {
try {
results.add(nodeMapper.mapNode(nodes.item(i), i));

View File

@@ -88,7 +88,7 @@ public class Jaxp13XPathTemplate extends AbstractXPathTemplate {
@Override
public List<Node> evaluateAsNodeList(String expression, Source context) throws XPathException {
NodeList result = (NodeList) evaluate(expression, context, XPathConstants.NODESET);
List<Node> nodes = new ArrayList<Node>(result.getLength());
List<Node> nodes = new ArrayList<>(result.getLength());
for (int i = 0; i < result.getLength(); i++) {
nodes.add(result.item(i));
}
@@ -125,7 +125,7 @@ public class Jaxp13XPathTemplate extends AbstractXPathTemplate {
@Override
public <T> List<T> evaluate(String expression, Source context, NodeMapper<T> nodeMapper) throws XPathException {
NodeList nodes = (NodeList) evaluate(expression, context, XPathConstants.NODESET);
List<T> results = new ArrayList<T>(nodes.getLength());
List<T> results = new ArrayList<>(nodes.getLength());
for (int i = 0; i < nodes.getLength(); i++) {
try {
results.add(nodeMapper.mapNode(nodes.item(i), i));

View File

@@ -49,7 +49,7 @@ public abstract class XPathExpressionFactory {
*/
public static XPathExpression createXPathExpression(String expression)
throws IllegalStateException, XPathParseException {
return createXPathExpression(expression, Collections.<String, String>emptyMap());
return createXPathExpression(expression, Collections.emptyMap());
}
/**
@@ -67,13 +67,8 @@ public abstract class XPathExpressionFactory {
if (namespaces == null) {
namespaces = Collections.emptyMap();
}
try {
logger.trace("Creating [javax.xml.xpath.XPathExpression]");
return Jaxp13XPathExpressionFactory.createXPathExpression(expression, namespaces);
}
catch (XPathException e) {
throw e;
}
logger.trace("Creating [javax.xml.xpath.XPathExpression]");
return Jaxp13XPathExpressionFactory.createXPathExpression(expression, namespaces);
}
}

View File

@@ -86,8 +86,8 @@ public class CommonsXsdSchema implements XsdSchema {
}
public QName[] getElementNames() {
List<QName> result = new ArrayList<QName>(schema.getElements().keySet());
return result.toArray(new QName[result.size()]);
List<QName> result = new ArrayList<>(schema.getElements().keySet());
return result.toArray(new QName[0]);
}
@Override

View File

@@ -66,7 +66,7 @@ public class CommonsXsdSchemaCollection implements XsdSchemaCollection, Initiali
private final XmlSchemaCollection schemaCollection = new XmlSchemaCollection();
private final List<XmlSchema> xmlSchemas = new ArrayList<XmlSchema>();
private final List<XmlSchema> xmlSchemas = new ArrayList<>();
private Resource[] xsdResources;
@@ -132,8 +132,8 @@ public class CommonsXsdSchemaCollection implements XsdSchemaCollection, Initiali
schemaCollection.setSchemaResolver(uriResolver);
Set<XmlSchema> processedIncludes = new HashSet<XmlSchema>();
Set<XmlSchema> processedImports = new HashSet<XmlSchema>();
Set<XmlSchema> processedIncludes = new HashSet<>();
Set<XmlSchema> processedImports = new HashSet<>();
for (Resource xsdResource : xsdResources) {
Assert.isTrue(xsdResource.exists(), xsdResource + " does not exist");
@@ -208,8 +208,7 @@ public class CommonsXsdSchemaCollection implements XsdSchemaCollection, Initiali
processedImports.add(schema);
List<XmlSchemaExternal> externals = schema.getExternals();
for (XmlSchemaExternal external : externals) {
if (external instanceof XmlSchemaImport) {
XmlSchemaImport schemaImport = (XmlSchemaImport) external;
if (external instanceof XmlSchemaImport schemaImport) {
XmlSchema importedSchema = schemaImport.getSchema();
if (!"http://www.w3.org/XML/1998/namespace".equals(schemaImport.getNamespace())
&& importedSchema != null && !processedImports.contains(importedSchema)) {

View File

@@ -28,7 +28,7 @@ public class QNameEditorTest {
private QNameEditor editor;
@BeforeEach
public void setUp() throws Exception {
public void setUp() {
editor = new QNameEditor();
}

View File

@@ -34,7 +34,7 @@ public class TransformerHelperTest {
private Transformer transformer;
@BeforeEach
public void setUp() throws Exception {
public void setUp() {
helper = new TransformerHelper();
transformer = mock(Transformer.class);

View File

@@ -115,7 +115,6 @@ public abstract class AbstractValidatorFactoryTest {
SAXParseException[] errors = validator.validate(new DOMSource(document));
assertThat(errors).isEmpty();
;
}
@Test
@@ -149,7 +148,6 @@ public abstract class AbstractValidatorFactoryTest {
errors = validator.validate(document);
assertThat(errors).isEmpty();
;
}
@Test
@@ -160,13 +158,13 @@ public abstract class AbstractValidatorFactoryTest {
return new SAXParseException[0];
}
public void warning(SAXParseException exception) throws SAXException {
public void warning(SAXParseException exception) {
}
public void error(SAXParseException exception) throws SAXException {
public void error(SAXParseException exception) {
}
public void fatalError(SAXParseException exception) throws SAXException {
public void fatalError(SAXParseException exception) {
}
};

View File

@@ -40,7 +40,7 @@ public class SchemaLoaderUtilsTest {
}
@Test
public void testLoadNonExistantSchema() throws Exception {
public void testLoadNonExistantSchema() {
assertThatIllegalArgumentException().isThrownBy(() -> {
Resource nonExistent = new ClassPathResource("bla");
@@ -49,7 +49,7 @@ public class SchemaLoaderUtilsTest {
}
@Test
public void testLoadNullSchema() throws Exception {
public void testLoadNullSchema() {
assertThatIllegalArgumentException()
.isThrownBy(() -> SchemaLoaderUtils.loadSchema((Resource) null, XMLConstants.W3C_XML_SCHEMA_NS_URI));

View File

@@ -43,7 +43,7 @@ public abstract class AbstractXPathExpressionFactoryTest {
private Document namespacesDocument;
private Map<String, String> namespaces = new HashMap<String, String>();
private Map<String, String> namespaces = new HashMap<>();
@BeforeEach
public void setUp() throws Exception {
@@ -82,7 +82,7 @@ public abstract class AbstractXPathExpressionFactoryTest {
}
@Test
public void testEvaluateAsBooleanInvalidNamespaces() throws IOException, SAXException {
public void testEvaluateAsBooleanInvalidNamespaces() {
XPathExpression expression = createXPathExpression("/prefix1:root/prefix2:otherchild", namespaces);
boolean result = expression.evaluateAsBoolean(namespacesDocument);
@@ -91,7 +91,7 @@ public abstract class AbstractXPathExpressionFactoryTest {
}
@Test
public void testEvaluateAsBooleanInvalidNoNamespaces() throws IOException, SAXException {
public void testEvaluateAsBooleanInvalidNoNamespaces() {
XPathExpression expression = createXPathExpression("/root/otherchild");
boolean result = expression.evaluateAsBoolean(noNamespacesDocument);
@@ -100,7 +100,7 @@ public abstract class AbstractXPathExpressionFactoryTest {
}
@Test
public void testEvaluateAsBooleanNamespaces() throws IOException, SAXException {
public void testEvaluateAsBooleanNamespaces() {
XPathExpression expression = createXPathExpression("/prefix1:root/prefix2:child/prefix2:boolean/text()",
namespaces);
@@ -110,7 +110,7 @@ public abstract class AbstractXPathExpressionFactoryTest {
}
@Test
public void testEvaluateAsBooleanNoNamespaces() throws IOException, SAXException {
public void testEvaluateAsBooleanNoNamespaces() {
XPathExpression expression = createXPathExpression("/root/child/boolean/text()");
boolean result = expression.evaluateAsBoolean(noNamespacesDocument);
@@ -119,7 +119,7 @@ public abstract class AbstractXPathExpressionFactoryTest {
}
@Test
public void testEvaluateAsDoubleInvalidNamespaces() throws IOException, SAXException {
public void testEvaluateAsDoubleInvalidNamespaces() {
XPathExpression expression = createXPathExpression("/prefix1:root/prefix2:otherchild", namespaces);
double result = expression.evaluateAsNumber(noNamespacesDocument);
@@ -128,7 +128,7 @@ public abstract class AbstractXPathExpressionFactoryTest {
}
@Test
public void testEvaluateAsDoubleInvalidNoNamespaces() throws IOException, SAXException {
public void testEvaluateAsDoubleInvalidNoNamespaces() {
XPathExpression expression = createXPathExpression("/root/otherchild");
double result = expression.evaluateAsNumber(noNamespacesDocument);
@@ -137,7 +137,7 @@ public abstract class AbstractXPathExpressionFactoryTest {
}
@Test
public void testEvaluateAsDoubleNamespaces() throws IOException, SAXException {
public void testEvaluateAsDoubleNamespaces() {
XPathExpression expression = createXPathExpression("/prefix1:root/prefix2:child/prefix2:number/text()",
namespaces);
@@ -147,7 +147,7 @@ public abstract class AbstractXPathExpressionFactoryTest {
}
@Test
public void testEvaluateAsDoubleNoNamespaces() throws IOException, SAXException {
public void testEvaluateAsDoubleNoNamespaces() {
XPathExpression expression = createXPathExpression("/root/child/number/text()");
double result = expression.evaluateAsNumber(noNamespacesDocument);
@@ -156,7 +156,7 @@ public abstract class AbstractXPathExpressionFactoryTest {
}
@Test
public void testEvaluateAsNodeInvalidNamespaces() throws IOException, SAXException {
public void testEvaluateAsNodeInvalidNamespaces() {
XPathExpression expression = createXPathExpression("/prefix1:root/prefix2:otherchild", namespaces);
Node result = expression.evaluateAsNode(namespacesDocument);
@@ -165,7 +165,7 @@ public abstract class AbstractXPathExpressionFactoryTest {
}
@Test
public void testEvaluateAsNodeInvalidNoNamespaces() throws IOException, SAXException {
public void testEvaluateAsNodeInvalidNoNamespaces() {
XPathExpression expression = createXPathExpression("/root/otherchild");
Node result = expression.evaluateAsNode(noNamespacesDocument);
@@ -174,7 +174,7 @@ public abstract class AbstractXPathExpressionFactoryTest {
}
@Test
public void testEvaluateAsNodeNamespaces() throws IOException, SAXException {
public void testEvaluateAsNodeNamespaces() {
XPathExpression expression = createXPathExpression("/prefix1:root/prefix2:child", namespaces);
Node result = expression.evaluateAsNode(namespacesDocument);
@@ -184,7 +184,7 @@ public abstract class AbstractXPathExpressionFactoryTest {
}
@Test
public void testEvaluateAsNodeNoNamespaces() throws IOException, SAXException {
public void testEvaluateAsNodeNoNamespaces() {
XPathExpression expression = createXPathExpression("/root/child");
Node result = expression.evaluateAsNode(noNamespacesDocument);
@@ -194,7 +194,7 @@ public abstract class AbstractXPathExpressionFactoryTest {
}
@Test
public void testEvaluateAsNodeListNamespaces() throws IOException, SAXException {
public void testEvaluateAsNodeListNamespaces() {
XPathExpression expression = createXPathExpression("/prefix1:root/prefix2:child/*", namespaces);
List<Node> results = expression.evaluateAsNodeList(namespacesDocument);
@@ -254,7 +254,7 @@ public abstract class AbstractXPathExpressionFactoryTest {
public void testEvaluateAsObject() {
XPathExpression expression = createXPathExpression("/root/child");
String result = expression.evaluateAsObject(noNamespacesDocument, new NodeMapper<String>() {
String result = expression.evaluateAsObject(noNamespacesDocument, new NodeMapper<>() {
public String mapNode(Node node, int nodeNum) throws DOMException {
return node.getLocalName();
}
@@ -268,7 +268,7 @@ public abstract class AbstractXPathExpressionFactoryTest {
public void testEvaluate() throws Exception {
XPathExpression expression = createXPathExpression("/root/child/*");
List<String> results = expression.evaluate(noNamespacesDocument, new NodeMapper<String>() {
List<String> results = expression.evaluate(noNamespacesDocument, new NodeMapper<>() {
public String mapNode(Node node, int nodeNum) throws DOMException {
return node.getLocalName();
}

View File

@@ -211,7 +211,7 @@ public abstract class AbstractXPathTemplateTest {
@Test
public void testEvaluateAsObject() throws Exception {
String result = template.evaluateAsObject("/root/child", nonamespaces, new NodeMapper<String>() {
String result = template.evaluateAsObject("/root/child", nonamespaces, new NodeMapper<>() {
public String mapNode(Node node, int nodeNum) throws DOMException {
return node.getLocalName();
}
@@ -224,7 +224,7 @@ public abstract class AbstractXPathTemplateTest {
@Test
public void testEvaluate() throws Exception {
List<String> results = template.evaluate("/root/child/*", nonamespaces, new NodeMapper<String>() {
List<String> results = template.evaluate("/root/child/*", nonamespaces, new NodeMapper<>() {
public String mapNode(Node node, int nodeNum) throws DOMException {
return node.getLocalName();
}

View File

@@ -34,12 +34,12 @@ public class JaxenXPathExpressionFactoryTest extends AbstractXPathExpressionFact
}
@Override
public void testEvaluateAsDoubleNoNamespaces() throws IOException, SAXException {
public void testEvaluateAsDoubleNoNamespaces() {
// Currently not working on Jaxen 1.1 beta 8, hence the override here
}
@Override
public void testEvaluateAsDoubleNamespaces() throws IOException, SAXException {
public void testEvaluateAsDoubleNamespaces() {
// Currently not working on Jaxen 1.1 beta 8, hence the override here
}

View File

@@ -25,7 +25,7 @@ public class JaxenXPathTemplateTest extends AbstractXPathTemplateTest {
protected XPathOperations createTemplate() {
JaxenXPathTemplate template = new JaxenXPathTemplate();
Map<String, String> namespaces = new HashMap<String, String>();
Map<String, String> namespaces = new HashMap<>();
namespaces.put("prefix1", "namespace1");
namespaces.put("prefix2", "namespace2");
template.setNamespaces(namespaces);

View File

@@ -26,7 +26,7 @@ public class XPathExpressionFactoryBeanTest {
private XPathExpressionFactoryBean factoryBean;
@BeforeEach
public void setUp() throws Exception {
public void setUp() {
factoryBean = new XPathExpressionFactoryBean();
}

View File

@@ -140,7 +140,7 @@ public class CommonsXsdSchemaCollectionTest {
}
@Test
public void testInvalidSchema() throws Exception {
public void testInvalidSchema() {
Resource invalid = new ClassPathResource("invalid.xsd", AbstractXsdSchemaTest.class);
collection.setXsds(invalid);