Skip to content
Snippets Groups Projects
Commit d7419ce6 authored by Goik Martin's avatar Goik Martin
Browse files

SAX output to stdout

parent 932b4fff
No related branches found
No related tags found
No related merge requests found
package de.hdm_stuttgart.de.testing.dom;
import java.io.BufferedReader;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;
import java.io.PrintStream;
......@@ -15,31 +18,31 @@ import de.hdm_stuttgart.mi.sda1.saxhtml.tools.ContentRedirect;
import de.hdm_stuttgart.mi.sda1.saxhtml.v1.Memo2Html;
/**
* Turning <memo> documents to HTML as being shown in sample document memo.xml.2.sample.html
* Turning <memo> documents to HTML as being shown in sample document
* memo.xml.2.sample.html
*/
@SuppressWarnings("javadoc")
public abstract class ConversionTest {
public final String xmlInputFileName, htmlOutputFileName;
public final String xmlInputFileName, htmlOutputFileName;
final ContentRedirect saxHandler;
protected String errorInitString = null;
protected Element htmlRootElement;
protected Element htmlRootElement = null;
protected ConversionTest(final String xmlInputFileName, final ContentRedirect saxHandler, final String outputExtension) {
this.saxHandler = saxHandler;
protected ConversionTest(final String xmlInputFileName,
final ContentRedirect saxHandler, final String outputExtension) {
this.xmlInputFileName = xmlInputFileName;
this.htmlOutputFileName = xmlInputFileName + outputExtension;
htmlOutputFileName = xmlInputFileName + outputExtension;
this.saxHandler = saxHandler;
final PrintStream out;
try {
out = new PrintStream(htmlOutputFileName);
} catch (FileNotFoundException e1) {
errorInitString = "Unable to open file '" + htmlOutputFileName + "' for writing";
errorInitString = "Unable to open file '" + htmlOutputFileName
+ "' for writing";
return;
}
saxHandler.setOutputStream(out);
......@@ -59,13 +62,31 @@ public abstract class ConversionTest {
e.printStackTrace();
}
final SAXBuilder parser = new SAXBuilder();
try {
htmlRootElement = parser.build(htmlOutputFileName).getRootElement();
} catch (JDOMException | IOException e1) {
errorInitString = "Unable to parse file '" + htmlOutputFileName + "', see stack trace for further information";
errorInitString = "Unable to parse file '" + htmlOutputFileName
+ "', see stack trace for further information";
e1.printStackTrace();
}
out.close();
printResultToStdout();
}
private void printResultToStdout() {
try {
BufferedReader saxResult = new BufferedReader(new FileReader(
htmlOutputFileName));
String line;
while (null != (line = saxResult.readLine())) {
System.out.println(line);
}
saxResult.close();
} catch (IOException e) {
errorInitString = "Unable to open expected result output file '"
+ htmlOutputFileName + "' :" + e.getLocalizedMessage();
}
}
}
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment