001/* 002 * Copyright 2006-2019 the original author or authors. 003 * 004 * Licensed under the Apache License, Version 2.0 (the "License"); 005 * you may not use this file except in compliance with the License. 006 * You may obtain a copy of the License at 007 * 008 * https://www.apache.org/licenses/LICENSE-2.0 009 * 010 * Unless required by applicable law or agreed to in writing, software 011 * distributed under the License is distributed on an "AS IS" BASIS, 012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 013 * See the License for the specific language governing permissions and 014 * limitations under the License. 015 */ 016 017package org.springframework.batch.item.xml; 018 019import javax.xml.stream.XMLEventReader; 020import javax.xml.stream.XMLEventWriter; 021import javax.xml.stream.XMLInputFactory; 022import javax.xml.stream.XMLStreamException; 023import javax.xml.transform.Result; 024import javax.xml.transform.Source; 025import javax.xml.transform.stax.StAXResult; 026import javax.xml.transform.stax.StAXSource; 027 028 029/** 030 * StAX utility methods. 031 * <br> 032 * This class is thread-safe. 033 * 034 * @author Josh Long 035 * @author Mahmoud Ben Hassine 036 * 037 */ 038public abstract class StaxUtils { 039 040 public static Source getSource(XMLEventReader r) throws XMLStreamException { 041 return new StAXSource(r); 042 } 043 044 public static Result getResult(XMLEventWriter w) { 045 return new StAXResult(w); 046 } 047 048 public static XMLInputFactory createXmlInputFactory() { 049 XMLInputFactory xmlInputFactory = XMLInputFactory.newInstance(); 050 xmlInputFactory.setProperty(XMLInputFactory.SUPPORT_DTD, false); 051 xmlInputFactory.setProperty(XMLInputFactory.IS_SUPPORTING_EXTERNAL_ENTITIES, false); 052 return xmlInputFactory; 053 } 054}