Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 264243b

Browse files
committed
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 spring-projects#3779
1 parent 9449551 commit 264243b

File tree

6 files changed

+18
-12
lines changed

6 files changed

+18
-12
lines changed

spring-batch-infrastructure/src/main/java/org/springframework/batch/item/xml/StaxEventItemReader.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@
4545
import org.springframework.util.Assert;
4646
import org.springframework.util.ClassUtils;
4747
import org.springframework.util.StringUtils;
48+
import org.springframework.util.xml.StaxUtils;
4849

4950
/**
5051
* Item reader for reading XML input based on StAX.
@@ -81,7 +82,7 @@ public class StaxEventItemReader<T> extends AbstractItemCountingItemStreamItemRe
8182

8283
private boolean strict = true;
8384

84-
private XMLInputFactory xmlInputFactory = StaxUtils.createXmlInputFactory();
85+
private XMLInputFactory xmlInputFactory = StaxUtils.createDefensiveInputFactory();
8586

8687
private String encoding = DEFAULT_ENCODING;
8788

@@ -269,7 +270,7 @@ protected T doRead() throws IOException, XMLStreamException {
269270

270271
try {
271272
@SuppressWarnings("unchecked")
272-
T mappedFragment = (T) unmarshaller.unmarshal(StaxUtils.getSource(fragmentReader));
273+
T mappedFragment = (T) unmarshaller.unmarshal(StaxUtils.createStaxSource(fragmentReader));
273274
item = mappedFragment;
274275
}
275276
finally {

spring-batch-infrastructure/src/main/java/org/springframework/batch/item/xml/StaxEventItemWriter.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@
5959
import org.springframework.util.ClassUtils;
6060
import org.springframework.util.CollectionUtils;
6161
import org.springframework.util.StringUtils;
62+
import org.springframework.util.xml.StaxUtils;
6263

6364
/**
6465
* An implementation of {@link ItemWriter} which uses StAX and
@@ -578,7 +579,7 @@ protected XMLEventFactory createXmlEventFactory() throws FactoryConfigurationErr
578579
* @return a result for writing to
579580
*/
580581
protected Result createStaxResult() {
581-
return StaxUtils.getResult(eventWriter);
582+
return StaxUtils.createStaxResult(eventWriter);
582583
}
583584

584585
/**

spring-batch-infrastructure/src/main/java/org/springframework/batch/item/xml/StaxUtils.java

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2006-2019 the original author or authors.
2+
* Copyright 2006-2020 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -33,8 +33,11 @@
3333
*
3434
* @author Josh Long
3535
* @author Mahmoud Ben Hassine
36+
*
37+
* @deprecated in favor of {@link org.springframework.util.xml.StaxUtils}
3638
*
3739
*/
40+
@Deprecated
3841
public abstract class StaxUtils {
3942

4043
public static Source getSource(XMLEventReader r) throws XMLStreamException {

spring-batch-infrastructure/src/main/java/org/springframework/batch/item/xml/builder/StaxEventItemReaderBuilder.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,11 +22,11 @@
2222
import javax.xml.stream.XMLInputFactory;
2323

2424
import org.springframework.batch.item.xml.StaxEventItemReader;
25-
import org.springframework.batch.item.xml.StaxUtils;
2625
import org.springframework.core.io.Resource;
2726
import org.springframework.oxm.Unmarshaller;
2827
import org.springframework.util.Assert;
2928
import org.springframework.util.StringUtils;
29+
import org.springframework.util.xml.StaxUtils;
3030

3131
/**
3232
* A fluent builder for the {@link StaxEventItemReader}
@@ -54,7 +54,7 @@ public class StaxEventItemReaderBuilder<T> {
5454

5555
private int currentItemCount;
5656

57-
private XMLInputFactory xmlInputFactory = StaxUtils.createXmlInputFactory();
57+
private XMLInputFactory xmlInputFactory = StaxUtils.createDefensiveInputFactory();
5858

5959
private String encoding = StaxEventItemReader.DEFAULT_ENCODING;
6060

spring-batch-infrastructure/src/test/java/org/springframework/batch/item/xml/StaxEventItemReaderTests.java

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@
3131
import org.springframework.oxm.UnmarshallingFailureException;
3232
import org.springframework.oxm.XmlMappingException;
3333
import org.springframework.util.ClassUtils;
34+
import org.springframework.util.xml.StaxUtils;
3435

3536
import javax.xml.namespace.QName;
3637
import javax.xml.stream.FactoryConfigurationError;
@@ -356,7 +357,7 @@ public void testMultiFragmentNestedRestart() throws Exception {
356357
@Test
357358
public void testMoveCursorToNextFragment() throws XMLStreamException, FactoryConfigurationError, IOException {
358359
Resource resource = new ByteArrayResource(xml.getBytes());
359-
XMLEventReader reader = StaxUtils.createXmlInputFactory().createXMLEventReader(resource.getInputStream());
360+
XMLEventReader reader = StaxUtils.createDefensiveInputFactory().createXMLEventReader(resource.getInputStream());
360361

361362
final int EXPECTED_NUMBER_OF_FRAGMENTS = 2;
362363
for (int i = 0; i < EXPECTED_NUMBER_OF_FRAGMENTS; i++) {
@@ -373,7 +374,7 @@ public void testMoveCursorToNextFragment() throws XMLStreamException, FactoryCon
373374
@Test
374375
public void testMoveCursorToNextFragmentOnEmpty() throws XMLStreamException, FactoryConfigurationError, IOException {
375376
Resource resource = new ByteArrayResource(emptyXml.getBytes());
376-
XMLEventReader reader = StaxUtils.createXmlInputFactory().createXMLEventReader(resource.getInputStream());
377+
XMLEventReader reader = StaxUtils.createDefensiveInputFactory().createXMLEventReader(resource.getInputStream());
377378

378379
assertFalse(source.moveCursorToNextFragment(reader));
379380
}
@@ -384,7 +385,7 @@ public void testMoveCursorToNextFragmentOnEmpty() throws XMLStreamException, Fac
384385
@Test
385386
public void testMoveCursorToNextFragmentOnMissing() throws XMLStreamException, FactoryConfigurationError, IOException {
386387
Resource resource = new ByteArrayResource(missingXml.getBytes());
387-
XMLEventReader reader = StaxUtils.createXmlInputFactory().createXMLEventReader(resource.getInputStream());
388+
XMLEventReader reader = StaxUtils.createDefensiveInputFactory().createXMLEventReader(resource.getInputStream());
388389
assertFalse(source.moveCursorToNextFragment(reader));
389390
}
390391

spring-batch-infrastructure/src/test/java/org/springframework/batch/item/xml/stax/DefaultFragmentEventReaderTests.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2008-2019 the original author or authors.
2+
* Copyright 2008-2020 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -24,9 +24,9 @@
2424
import junit.framework.TestCase;
2525

2626
import org.springframework.batch.item.xml.EventHelper;
27-
import org.springframework.batch.item.xml.StaxUtils;
2827
import org.springframework.core.io.ByteArrayResource;
2928
import org.springframework.core.io.Resource;
29+
import org.springframework.util.xml.StaxUtils;
3030

3131
/**
3232
* Tests for {@link DefaultFragmentEventReader}.
@@ -51,7 +51,7 @@ public class DefaultFragmentEventReaderTests extends TestCase {
5151
@Override
5252
protected void setUp() throws Exception {
5353
Resource input = new ByteArrayResource(xml.getBytes());
54-
eventReader = StaxUtils.createXmlInputFactory().createXMLEventReader(
54+
eventReader = StaxUtils.createDefensiveInputFactory().createXMLEventReader(
5555
input.getInputStream());
5656
fragmentReader = new DefaultFragmentEventReader(eventReader);
5757
}

0 commit comments

Comments
 (0)