diff --git a/Sda1/Etest/SaxMemo2Html/SaxMemo2Hhtml_solution/src/test/java/de/hdm_stuttgart/de/testing/dom/ConversionTest.java b/Sda1/Etest/SaxMemo2Html/SaxMemo2Hhtml_solution/src/test/java/de/hdm_stuttgart/de/testing/dom/ConversionTest.java index 0192d64b082e09e34d9c4f2ff224a5e3cc0a741b..bad5fac8917716f87d5b1242a7bc8d5e264db794 100644 --- a/Sda1/Etest/SaxMemo2Html/SaxMemo2Hhtml_solution/src/test/java/de/hdm_stuttgart/de/testing/dom/ConversionTest.java +++ b/Sda1/Etest/SaxMemo2Html/SaxMemo2Hhtml_solution/src/test/java/de/hdm_stuttgart/de/testing/dom/ConversionTest.java @@ -1,7 +1,6 @@ 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; @@ -24,69 +23,74 @@ import de.hdm_stuttgart.mi.sda1.saxhtml.v1.Memo2Html; @SuppressWarnings("javadoc") public abstract class ConversionTest { - public final String xmlInputFileName, htmlOutputFileName; - final ContentRedirect saxHandler; - protected String errorInitString = null; + public final String xmlInputFileName, htmlOutputFileName; + final ContentRedirect saxHandler; + protected String errorInitString = null; - protected Element htmlRootElement = null; + protected static Element htmlRootElement = null; - protected ConversionTest(final String xmlInputFileName, - final ContentRedirect saxHandler, final String outputExtension) { - this.xmlInputFileName = xmlInputFileName; - htmlOutputFileName = xmlInputFileName + outputExtension; - this.saxHandler = saxHandler; + protected ConversionTest(final String xmlInputFileName, + final ContentRedirect saxHandler, final String outputExtension) { + this.xmlInputFileName = xmlInputFileName; + htmlOutputFileName = xmlInputFileName + outputExtension; + this.saxHandler = saxHandler; - final PrintStream out; + if (null == htmlRootElement) { - try { - out = new PrintStream(htmlOutputFileName); - } catch (FileNotFoundException e1) { - errorInitString = "Unable to open file '" + htmlOutputFileName - + "' for writing"; - return; - } - saxHandler.setOutputStream(out); - final Memo2Html memo2html; - try { - memo2html = new Memo2Html(saxHandler); - } catch (SAXException | ParserConfigurationException e2) { - e2.printStackTrace(); - return; - } - try { - memo2html.parse(xmlInputFileName); - } catch (IOException e1) { - errorInitString = "Unable parse file '" + xmlInputFileName + "'"; - return; - } catch (SAXException e) { - e.printStackTrace(); - } - final SAXBuilder parser = new SAXBuilder(); + final PrintStream out; - try { - htmlRootElement = parser.build(htmlOutputFileName).getRootElement(); - } catch (JDOMException | IOException e1) { - errorInitString = "Unable to parse file '" + htmlOutputFileName - + "', see stack trace for further information"; - e1.printStackTrace(); - } - out.close(); - printResultToStdout(); - } + try { + out = new PrintStream(htmlOutputFileName); + } catch (FileNotFoundException e1) { + errorInitString = "Unable to open file '" + htmlOutputFileName + + "' for writing"; + return; + } + saxHandler.setOutputStream(out); + final Memo2Html memo2html; + try { + memo2html = new Memo2Html(saxHandler); + } catch (SAXException | ParserConfigurationException e2) { + e2.printStackTrace(); + return; + } + try { + memo2html.parse(xmlInputFileName); + } catch (IOException e1) { + errorInitString = "Unable parse file '" + xmlInputFileName + + "'"; + return; + } catch (SAXException e) { + e.printStackTrace(); + } + final SAXBuilder parser = new SAXBuilder(); - 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(); - } - } + try { + htmlRootElement = parser.build(htmlOutputFileName) + .getRootElement(); + } catch (JDOMException | IOException e1) { + 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