Skip to content

Commit 4438248

Browse files
committed
Support XSL transformation with an ObjectOutputStream on-the-fly. Closes #201.
1 parent cde23cd commit 4438248

File tree

8 files changed

+654
-107
lines changed

8 files changed

+654
-107
lines changed

xstream-distribution/src/content/changes.html

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ <h2>Minor changes</h2>
5151
<li>GHPR:#145: FileName parameter of StackTraceElement can be used for other source code units than file,
5252
converter handles this.</li>
5353
<li>GHI:#4: Cannot add suppressed exception to unmarshalled Throwable.</li>
54+
<li>TraxSource supports the creation of an ObjectOutputStream to transform the output of XStream on-the-fly.</li>
5455
<li>StackTraceElementConverter keeps now information about the source code unit for native methods if
5556
available.</li>
5657
<li>StackTraceElementConverter keeps for Java 9 or higher information about the class loader and module name
@@ -72,7 +73,11 @@ <h2>API changes</h2>
7273
<li>Merge functionality of ExtendedHierarchicalStreamWriter into HierarchicalStreamWriter.</li>
7374
<li>HierarchicalStreamReader and HierarchicalStreamWriter extend AutoCloseable instead of Closeable now.</li>
7475
<li>Added c.t.x.io.xml.SimpleStaxDriver.</li>
75-
<li>Added c.t.x.io.HierarchicalStreamReader.getLevel()</li>
76+
<li>Added c.t.x.io.HierarchicalStreamReader.getLevel().</li>
77+
<li>Added c.t.x.io.xml.SaxWriter#OOS_SUPPLIER_PROPERTY</li>
78+
<li>Added c.t.x.io.xml.SaxWriter#SOURCE_OBJECT_QUEUE_PROPERTY.</li>
79+
<li>Deprecated c.t.x.io.xml.SaxWriter#SOURCE_OBJECT_LIST_PROPERTY.</li>
80+
<li>Added c.t.x.io.xml.TraxSource#createObjectOutputStream</li>
7681
<li>Deprecated obsolete method c.t.x.XStream.setupDefaultSecurity.</li>
7782
<li>Added c.t.x.converters.extended.ThrowableConverter.ThrowableConverter(Mapper, ConverterLookup).</li>
7883
<li>Deprecated c.t.x.converters.extended.ThrowableConverter.ThrowableConverter(ConverterLookup).</li>

xstream-distribution/src/content/faq.html

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<html>
22
<!--
33
Copyright (C) 2005, 2006 Joe Walnes.
4-
Copyright (C) 2006, 2007, 2008, 2009, 2010, 2011, 2012, 2013, 2014, 2015, 2016, 2017, 2018, 2019 XStream committers.
4+
Copyright (C) 2006, 2007, 2008, 2009, 2010, 2011, 2012, 2013, 2014, 2015, 2016, 2017, 2018, 2019, 2020 XStream committers.
55
All rights reserved.
66
77
The software in this package is published under the terms of the BSD
@@ -705,6 +705,13 @@ <h2 id="XML_entities">Does XStream support entities?</h2>
705705
<a href="javadoc/com/thoughtworks/xstream/io/HierarchicalStreamDriver.html">HierarchicalStreamDriver</a>
706706
implementation that generated the parser factory.</p>
707707

708+
<!-- ...................................................... -->
709+
<h2 id="XML_XSL">Can I use an XSL style sheet?</h2>
710+
711+
<p>XStream supports the usage of an XSL style sheet as post-processor for its output with its
712+
<a href="javadoc/com/thoughtworks/xstream/io/xml/TraxSource.html">TraxSource</a> type. It will utilize an XStream
713+
instance as direct input to the transformer.</p>
714+
708715
<!-- ****************************************************** -->
709716
<h1 id="JSON">JSON specifics</h1>
710717

xstream/src/java/com/thoughtworks/xstream/XStream.java

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1187,6 +1187,7 @@ public <T> T fromXML(final String xml) {
11871187
*
11881188
* @throws XStreamException if the object cannot be deserialized
11891189
*/
1190+
@SuppressWarnings("resource")
11901191
public <T> T fromXML(final Reader reader) {
11911192
return unmarshal(hierarchicalStreamDriver.createReader(reader), null);
11921193
}
@@ -1196,6 +1197,7 @@ public <T> T fromXML(final Reader reader) {
11961197
*
11971198
* @throws XStreamException if the object cannot be deserialized
11981199
*/
1200+
@SuppressWarnings("resource")
11991201
public <T> T fromXML(final InputStream input) {
12001202
return unmarshal(hierarchicalStreamDriver.createReader(input), null);
12011203
}
@@ -1240,6 +1242,7 @@ public <T> T fromXML(final String xml, final T root) {
12401242
*
12411243
* @throws XStreamException if the object cannot be deserialized
12421244
*/
1245+
@SuppressWarnings("resource")
12431246
public <T> T fromXML(final Reader xml, final T root) {
12441247
return unmarshal(hierarchicalStreamDriver.createReader(xml), root);
12451248
}
@@ -1254,7 +1257,9 @@ public <T> T fromXML(final Reader xml, final T root) {
12541257
* @since 1.4
12551258
*/
12561259
public <T> T fromXML(final URL url, final T root) {
1257-
return unmarshal(hierarchicalStreamDriver.createReader(url), root);
1260+
try (HierarchicalStreamReader reader = hierarchicalStreamDriver.createReader(url)) {
1261+
return unmarshal(reader, root);
1262+
}
12581263
}
12591264

12601265
/**
@@ -1267,11 +1272,8 @@ public <T> T fromXML(final URL url, final T root) {
12671272
* @since 1.4
12681273
*/
12691274
public <T> T fromXML(final File file, final T root) {
1270-
final HierarchicalStreamReader reader = hierarchicalStreamDriver.createReader(file);
1271-
try {
1275+
try(final HierarchicalStreamReader reader = hierarchicalStreamDriver.createReader(file)) {
12721276
return unmarshal(reader, root);
1273-
} finally {
1274-
reader.close();
12751277
}
12761278
}
12771279

@@ -1282,6 +1284,7 @@ public <T> T fromXML(final File file, final T root) {
12821284
*
12831285
* @throws XStreamException if the object cannot be deserialized
12841286
*/
1287+
@SuppressWarnings("resource")
12851288
public <T> T fromXML(final InputStream input, final T root) {
12861289
return unmarshal(hierarchicalStreamDriver.createReader(input), root);
12871290
}
@@ -1817,6 +1820,7 @@ public DataHolder newDataHolder() {
18171820
* @see #createObjectInputStream(com.thoughtworks.xstream.io.HierarchicalStreamReader)
18181821
* @since 1.0.3
18191822
*/
1823+
@SuppressWarnings("resource")
18201824
public ObjectOutputStream createObjectOutputStream(final Writer writer) throws IOException {
18211825
return createObjectOutputStream(hierarchicalStreamDriver.createWriter(writer), "object-stream");
18221826
}
@@ -1843,6 +1847,7 @@ public ObjectOutputStream createObjectOutputStream(final HierarchicalStreamWrite
18431847
* @see #createObjectInputStream(com.thoughtworks.xstream.io.HierarchicalStreamReader)
18441848
* @since 1.0.3
18451849
*/
1850+
@SuppressWarnings("resource")
18461851
public ObjectOutputStream createObjectOutputStream(final Writer writer, final String rootNodeName)
18471852
throws IOException {
18481853
return createObjectOutputStream(hierarchicalStreamDriver.createWriter(writer), rootNodeName);
@@ -1859,6 +1864,7 @@ public ObjectOutputStream createObjectOutputStream(final Writer writer, final St
18591864
* @see #createObjectInputStream(com.thoughtworks.xstream.io.HierarchicalStreamReader)
18601865
* @since 1.3
18611866
*/
1867+
@SuppressWarnings("resource")
18621868
public ObjectOutputStream createObjectOutputStream(final OutputStream out) throws IOException {
18631869
return createObjectOutputStream(hierarchicalStreamDriver.createWriter(out), "object-stream");
18641870
}
@@ -1870,6 +1876,7 @@ public ObjectOutputStream createObjectOutputStream(final OutputStream out) throw
18701876
* @see #createObjectInputStream(com.thoughtworks.xstream.io.HierarchicalStreamReader)
18711877
* @since 1.3
18721878
*/
1879+
@SuppressWarnings("resource")
18731880
public ObjectOutputStream createObjectOutputStream(final OutputStream out, final String rootNodeName)
18741881
throws IOException {
18751882
return createObjectOutputStream(hierarchicalStreamDriver.createWriter(out), rootNodeName);
@@ -1956,6 +1963,7 @@ public void close() {
19561963
* @see #createObjectOutputStream(com.thoughtworks.xstream.io.HierarchicalStreamWriter, String)
19571964
* @since 1.0.3
19581965
*/
1966+
@SuppressWarnings("resource")
19591967
public ObjectInputStream createObjectInputStream(final Reader xmlReader) throws IOException {
19601968
return createObjectInputStream(hierarchicalStreamDriver.createReader(xmlReader));
19611969
}
@@ -1967,6 +1975,7 @@ public ObjectInputStream createObjectInputStream(final Reader xmlReader) throws
19671975
* @see #createObjectOutputStream(com.thoughtworks.xstream.io.HierarchicalStreamWriter, String)
19681976
* @since 1.3
19691977
*/
1978+
@SuppressWarnings("resource")
19701979
public ObjectInputStream createObjectInputStream(final InputStream in) throws IOException {
19711980
return createObjectInputStream(hierarchicalStreamDriver.createReader(in));
19721981
}
Lines changed: 126 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,126 @@
1+
/*
2+
* Copyright (C) 2020 XStream Committers.
3+
* All rights reserved.
4+
*
5+
* The software in this package is published under the terms of the BSD
6+
* style license a copy of which has been included with this distribution in
7+
* the LICENSE.txt file.
8+
*
9+
* Created on 22. Mai 2020 by Joerg Schaible
10+
*/
11+
package com.thoughtworks.xstream.core.util;
12+
13+
import java.util.Collection;
14+
import java.util.Iterator;
15+
import java.util.List;
16+
import java.util.Queue;
17+
18+
/**
19+
* A Queue wrapper for a list
20+
*
21+
* @author J&ouml;rg Schaible
22+
* @since upcoming
23+
*/
24+
public final class ListWrappingQueue<E> implements Queue<E> {
25+
private final List<E> list;
26+
27+
/**
28+
* Constructs a QueueImplementation.
29+
*
30+
* @param list
31+
* @since upcoming
32+
*/
33+
public ListWrappingQueue(final List<E> list) {
34+
this.list = list;
35+
}
36+
37+
@Override
38+
public int size() {
39+
return this.list.size();
40+
}
41+
42+
@Override
43+
public boolean isEmpty() {
44+
return this.list.isEmpty();
45+
}
46+
47+
@Override
48+
public boolean contains(final Object o) {
49+
return this.list.contains(o);
50+
}
51+
52+
@Override
53+
public Iterator<E> iterator() {
54+
return this.list.iterator();
55+
}
56+
57+
@Override
58+
public Object[] toArray() {
59+
return this.list.toArray();
60+
}
61+
62+
@Override
63+
public <T> T[] toArray(final T[] a) {
64+
return this.list.toArray(a);
65+
}
66+
67+
@Override
68+
public boolean remove(final Object o) {
69+
return this.list.remove(o);
70+
}
71+
72+
@Override
73+
public boolean containsAll(final Collection<?> c) {
74+
return this.list.containsAll(c);
75+
}
76+
77+
@Override
78+
public boolean addAll(final Collection<? extends E> c) {
79+
return this.list.addAll(c);
80+
}
81+
82+
@Override
83+
public boolean removeAll(final Collection<?> c) {
84+
return this.list.removeAll(c);
85+
}
86+
87+
@Override
88+
public boolean retainAll(final Collection<?> c) {
89+
return this.list.retainAll(c);
90+
}
91+
92+
@Override
93+
public void clear() {
94+
this.list.clear();
95+
}
96+
97+
@Override
98+
public boolean add(final E e) {
99+
return this.list.add(e);
100+
}
101+
102+
@Override
103+
public boolean offer(final E e) {
104+
return this.list.add(e);
105+
}
106+
107+
@Override
108+
public E remove() {
109+
return this.list.remove(0);
110+
}
111+
112+
@Override
113+
public E poll() {
114+
return this.list.remove(0);
115+
}
116+
117+
@Override
118+
public E element() {
119+
return this.list.get(0);
120+
}
121+
122+
@Override
123+
public E peek() {
124+
return this.list.get(0);
125+
}
126+
}

0 commit comments

Comments
 (0)