-
Notifications
You must be signed in to change notification settings - Fork 118
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Issue #119 - Extend the StAX Handling (again).
More work to come
- Loading branch information
Showing
10 changed files
with
178 additions
and
31 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
49 changes: 49 additions & 0 deletions
49
test/src/java/org/jdom2/test/cases/output/TestStAXReader2Writer.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
package org.jdom2.test.cases.output; | ||
|
||
import java.util.Iterator; | ||
|
||
import javax.xml.transform.Transformer; | ||
import javax.xml.transform.TransformerFactory; | ||
import javax.xml.transform.stax.StAXResult; | ||
import javax.xml.transform.stax.StAXSource; | ||
|
||
import org.jdom2.Content; | ||
import org.jdom2.Document; | ||
import org.jdom2.Element; | ||
import org.jdom2.input.StAXStreamWriter; | ||
import org.jdom2.output.StAXStreamReader; | ||
|
||
@SuppressWarnings("javadoc") | ||
public class TestStAXReader2Writer extends AbstractTestRoundTrip { | ||
|
||
@Override | ||
Document prepare(Document doc) { | ||
Document ret = doc.clone(); | ||
for (Iterator<Content> it = ret.getContent().iterator(); it.hasNext(); ) { | ||
Content c = it.next(); | ||
if (!(c instanceof Element)) { | ||
it.remove(); | ||
} | ||
} | ||
return ret; | ||
} | ||
|
||
@Override | ||
Document roundTrip(final Document doc) { | ||
try { | ||
final StAXStreamWriter sw = new StAXStreamWriter(); | ||
final StAXStreamReader sr = new StAXStreamReader(); | ||
final TransformerFactory tf = TransformerFactory.newInstance( | ||
"com.sun.org.apache.xalan.internal.xsltc.trax.TransformerFactoryImpl", | ||
this.getClass().getClassLoader()); | ||
final Transformer t = tf.newTransformer(); | ||
StAXSource source = new StAXSource(sr.output(doc)); | ||
StAXResult result = new StAXResult(sw); | ||
t.transform(source, result); | ||
return sw.getDocument(); | ||
} catch (Exception e) { | ||
throw new IllegalStateException("Failed to identity-trasform...", e); | ||
} | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters