Deprecate org.springframework.batch.item.xml.StaxUtils

This commit deprecates org.springframework.batch.item.xml.StaxUtils
in favor of org.springframework.util.xml.StaxUtils.

Resolves #3779
This commit is contained in:
Mahmoud Ben Hassine
2020-09-16 10:08:28 +02:00
parent 9449551d9f
commit 264243b73c
6 changed files with 18 additions and 12 deletions

View File

@@ -45,6 +45,7 @@ import org.springframework.oxm.Unmarshaller;
import org.springframework.util.Assert;
import org.springframework.util.ClassUtils;
import org.springframework.util.StringUtils;
import org.springframework.util.xml.StaxUtils;
/**
* Item reader for reading XML input based on StAX.
@@ -81,7 +82,7 @@ ResourceAwareItemReaderItemStream<T>, InitializingBean {
private boolean strict = true;
private XMLInputFactory xmlInputFactory = StaxUtils.createXmlInputFactory();
private XMLInputFactory xmlInputFactory = StaxUtils.createDefensiveInputFactory();
private String encoding = DEFAULT_ENCODING;
@@ -269,7 +270,7 @@ ResourceAwareItemReaderItemStream<T>, InitializingBean {
try {
@SuppressWarnings("unchecked")
T mappedFragment = (T) unmarshaller.unmarshal(StaxUtils.getSource(fragmentReader));
T mappedFragment = (T) unmarshaller.unmarshal(StaxUtils.createStaxSource(fragmentReader));
item = mappedFragment;
}
finally {

View File

@@ -59,6 +59,7 @@ import org.springframework.util.Assert;
import org.springframework.util.ClassUtils;
import org.springframework.util.CollectionUtils;
import org.springframework.util.StringUtils;
import org.springframework.util.xml.StaxUtils;
/**
* An implementation of {@link ItemWriter} which uses StAX and
@@ -578,7 +579,7 @@ ResourceAwareItemWriterItemStream<T>, InitializingBean {
* @return a result for writing to
*/
protected Result createStaxResult() {
return StaxUtils.getResult(eventWriter);
return StaxUtils.createStaxResult(eventWriter);
}
/**

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2006-2019 the original author or authors.
* Copyright 2006-2020 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.
@@ -33,8 +33,11 @@ import javax.xml.transform.stax.StAXSource;
*
* @author Josh Long
* @author Mahmoud Ben Hassine
*
* @deprecated in favor of {@link org.springframework.util.xml.StaxUtils}
*
*/
@Deprecated
public abstract class StaxUtils {
public static Source getSource(XMLEventReader r) throws XMLStreamException {

View File

@@ -22,11 +22,11 @@ import java.util.List;
import javax.xml.stream.XMLInputFactory;
import org.springframework.batch.item.xml.StaxEventItemReader;
import org.springframework.batch.item.xml.StaxUtils;
import org.springframework.core.io.Resource;
import org.springframework.oxm.Unmarshaller;
import org.springframework.util.Assert;
import org.springframework.util.StringUtils;
import org.springframework.util.xml.StaxUtils;
/**
* A fluent builder for the {@link StaxEventItemReader}
@@ -54,7 +54,7 @@ public class StaxEventItemReaderBuilder<T> {
private int currentItemCount;
private XMLInputFactory xmlInputFactory = StaxUtils.createXmlInputFactory();
private XMLInputFactory xmlInputFactory = StaxUtils.createDefensiveInputFactory();
private String encoding = StaxEventItemReader.DEFAULT_ENCODING;

View File

@@ -31,6 +31,7 @@ import org.springframework.oxm.Unmarshaller;
import org.springframework.oxm.UnmarshallingFailureException;
import org.springframework.oxm.XmlMappingException;
import org.springframework.util.ClassUtils;
import org.springframework.util.xml.StaxUtils;
import javax.xml.namespace.QName;
import javax.xml.stream.FactoryConfigurationError;
@@ -356,7 +357,7 @@ public class StaxEventItemReaderTests {
@Test
public void testMoveCursorToNextFragment() throws XMLStreamException, FactoryConfigurationError, IOException {
Resource resource = new ByteArrayResource(xml.getBytes());
XMLEventReader reader = StaxUtils.createXmlInputFactory().createXMLEventReader(resource.getInputStream());
XMLEventReader reader = StaxUtils.createDefensiveInputFactory().createXMLEventReader(resource.getInputStream());
final int EXPECTED_NUMBER_OF_FRAGMENTS = 2;
for (int i = 0; i < EXPECTED_NUMBER_OF_FRAGMENTS; i++) {
@@ -373,7 +374,7 @@ public class StaxEventItemReaderTests {
@Test
public void testMoveCursorToNextFragmentOnEmpty() throws XMLStreamException, FactoryConfigurationError, IOException {
Resource resource = new ByteArrayResource(emptyXml.getBytes());
XMLEventReader reader = StaxUtils.createXmlInputFactory().createXMLEventReader(resource.getInputStream());
XMLEventReader reader = StaxUtils.createDefensiveInputFactory().createXMLEventReader(resource.getInputStream());
assertFalse(source.moveCursorToNextFragment(reader));
}
@@ -384,7 +385,7 @@ public class StaxEventItemReaderTests {
@Test
public void testMoveCursorToNextFragmentOnMissing() throws XMLStreamException, FactoryConfigurationError, IOException {
Resource resource = new ByteArrayResource(missingXml.getBytes());
XMLEventReader reader = StaxUtils.createXmlInputFactory().createXMLEventReader(resource.getInputStream());
XMLEventReader reader = StaxUtils.createDefensiveInputFactory().createXMLEventReader(resource.getInputStream());
assertFalse(source.moveCursorToNextFragment(reader));
}

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2008-2019 the original author or authors.
* Copyright 2008-2020 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.
@@ -24,9 +24,9 @@ import javax.xml.stream.events.XMLEvent;
import junit.framework.TestCase;
import org.springframework.batch.item.xml.EventHelper;
import org.springframework.batch.item.xml.StaxUtils;
import org.springframework.core.io.ByteArrayResource;
import org.springframework.core.io.Resource;
import org.springframework.util.xml.StaxUtils;
/**
* Tests for {@link DefaultFragmentEventReader}.
@@ -51,7 +51,7 @@ public class DefaultFragmentEventReaderTests extends TestCase {
@Override
protected void setUp() throws Exception {
Resource input = new ByteArrayResource(xml.getBytes());
eventReader = StaxUtils.createXmlInputFactory().createXMLEventReader(
eventReader = StaxUtils.createDefensiveInputFactory().createXMLEventReader(
input.getInputStream());
fragmentReader = new DefaultFragmentEventReader(eventReader);
}