From f2329cf426d950f3b9e1ff1ce1354cb5de28b498 Mon Sep 17 00:00:00 2001 From: Arjen Poutsma Date: Fri, 9 Jan 2009 12:37:41 +0000 Subject: [PATCH] Aded createStaxResult --- .../springframework/util/xml/StaxUtils.java | 41 +++++++++++++++++++ 1 file changed, 41 insertions(+) diff --git a/org.springframework.core/src/main/java/org/springframework/util/xml/StaxUtils.java b/org.springframework.core/src/main/java/org/springframework/util/xml/StaxUtils.java index 0b87fdf4178..71ce0abbbf1 100644 --- a/org.springframework.core/src/main/java/org/springframework/util/xml/StaxUtils.java +++ b/org.springframework.core/src/main/java/org/springframework/util/xml/StaxUtils.java @@ -75,6 +75,39 @@ public abstract class StaxUtils { } } + /** + * Creates a StAX {@link Result} for the given {@link XMLStreamWriter}. Returns a {@link StAXResult} under JAXP 1.4 or + * higher, or a {@link StaxResult} otherwise. + * + * @param streamWriter the StAX stream writer + * @return a result wrapping streamWriter + */ + public static Result createStaxResult(XMLStreamWriter streamWriter) { + if (JaxpVersion.isAtLeastJaxp14()) { + return Jaxp14StaxHandler.createStaxResult(streamWriter); + } + else { + return new StaxResult(streamWriter); + } + } + + /** + * Creates a StAX {@link Result} for the given {@link XMLEventWriter}. Returns a {@link StAXResult} under JAXP 1.4 or + * higher, or a {@link StaxResult} otherwise. + * + * @param eventWriter the StAX event writer + * @return a result wrapping streamReader + * @throws XMLStreamException in case of StAX errors + */ + public static Result createStaxResult(XMLEventWriter eventWriter) throws XMLStreamException { + if (JaxpVersion.isAtLeastJaxp14()) { + return Jaxp14StaxHandler.createStaxResult(eventWriter); + } + else { + return new StaxResult(eventWriter); + } + } + /** * Indicates whether the given {@link javax.xml.transform.Source} is a StAX Source. * @@ -252,6 +285,14 @@ public abstract class StaxUtils { return new StAXSource(eventReader); } + private static Result createStaxResult(XMLStreamWriter streamWriter) { + return new StAXResult(streamWriter); + } + + private static Result createStaxResult(XMLEventWriter eventWriter) { + return new StAXResult(eventWriter); + } + private static boolean isStaxSource(Source source) { return source instanceof StAXSource; }