From 1b8a6f2db14da72a6c1678e932ca857b711d6399 Mon Sep 17 00:00:00 2001 From: Martin Goik <goik@hdm-stuttgart.de> Date: Tue, 16 Dec 2014 18:22:46 +0100 Subject: [PATCH] Testing duplicate handler execution --- .../.gitignore | 0 .../SaxMemo2Html/SaxMemo2Hhtml/pom.exam.xml | 101 +++++++++++++ Sda1/Etest/SaxMemo2Html/SaxMemo2Hhtml/pom.xml | 107 +++++++++++++ .../mi/sda1/saxhtml/v1/Memo2HtmlHandler.java | 61 ++++++++ .../mi/sda1/saxhtml/v2/Memo2HtmlHandler.java | 61 ++++++++ .../src/main/resources/.gitignore | 0 .../src/main/resources/log4j2.xml | 0 .../src/main/resources/memo.xml | 0 .../main/resources/memo.xml.1.expected.html} | 0 .../main/resources/memo.xml.2.expected.html} | 0 .../mi/sda1/saxhtml/v2/Memo2HtmlHandler.java | 2 +- .../v2/test/TestComplexSaxTransform.java | 9 ++ Sda1/Etest/SaxMemo2Html/Saxmemo2html/pom.xml | 98 ------------ .../sda1/saxhtml/tools/ContentRedirect.java | 15 -- .../mi/sda1/saxhtml/v1/Driver.java | 15 -- .../mi/sda1/saxhtml/v1/Memo2Html.java | 49 ------ .../mi/sda1/saxhtml/v1/Memo2HtmlHandler.java | 69 --------- .../mi/sda1/saxhtml/v1/MyErrorHandler.java | 25 ---- .../mi/sda1/saxhtml/v2/Driver.java | 17 --- .../mi/sda1/saxhtml/v2/Memo2Html.java | 51 ------- .../mi/sda1/saxhtml/v2/Memo2HtmlHandler.java | 69 --------- .../v1/test/TestSimpleSaxTransform.java | 46 ------ .../v2/test/TestComplexSaxTransform.java | 46 ------ .../de/testing/dom/AssertXpathResult.java | 18 --- .../de/testing/dom/ConversionTest.java | 71 --------- .../de/testing/dom/DomAssert.java | 91 ----------- Sda1/Etest/SaxMemo2Html/exercise1.xhtml | 141 ++++++++++-------- .../de/mi/exam/test/sax/SaxFilterTest.java | 4 + 28 files changed, 424 insertions(+), 742 deletions(-) rename Sda1/Etest/SaxMemo2Html/{Saxmemo2html => SaxMemo2Hhtml}/.gitignore (100%) create mode 100644 Sda1/Etest/SaxMemo2Html/SaxMemo2Hhtml/pom.exam.xml create mode 100644 Sda1/Etest/SaxMemo2Html/SaxMemo2Hhtml/pom.xml create mode 100644 Sda1/Etest/SaxMemo2Html/SaxMemo2Hhtml/src/main/java/de/hdm_stuttgart/mi/sda1/saxhtml/v1/Memo2HtmlHandler.java create mode 100644 Sda1/Etest/SaxMemo2Html/SaxMemo2Hhtml/src/main/java/de/hdm_stuttgart/mi/sda1/saxhtml/v2/Memo2HtmlHandler.java rename Sda1/Etest/SaxMemo2Html/{Saxmemo2html => SaxMemo2Hhtml}/src/main/resources/.gitignore (100%) rename Sda1/Etest/SaxMemo2Html/{Saxmemo2html => SaxMemo2Hhtml}/src/main/resources/log4j2.xml (100%) rename Sda1/Etest/SaxMemo2Html/{Saxmemo2html => SaxMemo2Hhtml}/src/main/resources/memo.xml (100%) rename Sda1/Etest/SaxMemo2Html/{Saxmemo2html/src/main/resources/memo.xml.1.sample.html => SaxMemo2Hhtml/src/main/resources/memo.xml.1.expected.html} (100%) rename Sda1/Etest/SaxMemo2Html/{Saxmemo2html/src/main/resources/memo.xml.2.sample.html => SaxMemo2Hhtml/src/main/resources/memo.xml.2.expected.html} (100%) delete mode 100644 Sda1/Etest/SaxMemo2Html/Saxmemo2html/pom.xml delete mode 100644 Sda1/Etest/SaxMemo2Html/Saxmemo2html/src/main/java/de/hdm_stuttgart/mi/sda1/saxhtml/tools/ContentRedirect.java delete mode 100644 Sda1/Etest/SaxMemo2Html/Saxmemo2html/src/main/java/de/hdm_stuttgart/mi/sda1/saxhtml/v1/Driver.java delete mode 100644 Sda1/Etest/SaxMemo2Html/Saxmemo2html/src/main/java/de/hdm_stuttgart/mi/sda1/saxhtml/v1/Memo2Html.java delete mode 100644 Sda1/Etest/SaxMemo2Html/Saxmemo2html/src/main/java/de/hdm_stuttgart/mi/sda1/saxhtml/v1/Memo2HtmlHandler.java delete mode 100644 Sda1/Etest/SaxMemo2Html/Saxmemo2html/src/main/java/de/hdm_stuttgart/mi/sda1/saxhtml/v1/MyErrorHandler.java delete mode 100644 Sda1/Etest/SaxMemo2Html/Saxmemo2html/src/main/java/de/hdm_stuttgart/mi/sda1/saxhtml/v2/Driver.java delete mode 100644 Sda1/Etest/SaxMemo2Html/Saxmemo2html/src/main/java/de/hdm_stuttgart/mi/sda1/saxhtml/v2/Memo2Html.java delete mode 100644 Sda1/Etest/SaxMemo2Html/Saxmemo2html/src/main/java/de/hdm_stuttgart/mi/sda1/saxhtml/v2/Memo2HtmlHandler.java delete mode 100644 Sda1/Etest/SaxMemo2Html/Saxmemo2html/src/test/java/de/hdm_stuttgart/de/sda1/saxhtml/v1/test/TestSimpleSaxTransform.java delete mode 100644 Sda1/Etest/SaxMemo2Html/Saxmemo2html/src/test/java/de/hdm_stuttgart/de/sda1/saxhtml/v2/test/TestComplexSaxTransform.java delete mode 100644 Sda1/Etest/SaxMemo2Html/Saxmemo2html/src/test/java/de/hdm_stuttgart/de/testing/dom/AssertXpathResult.java delete mode 100644 Sda1/Etest/SaxMemo2Html/Saxmemo2html/src/test/java/de/hdm_stuttgart/de/testing/dom/ConversionTest.java delete mode 100644 Sda1/Etest/SaxMemo2Html/Saxmemo2html/src/test/java/de/hdm_stuttgart/de/testing/dom/DomAssert.java diff --git a/Sda1/Etest/SaxMemo2Html/Saxmemo2html/.gitignore b/Sda1/Etest/SaxMemo2Html/SaxMemo2Hhtml/.gitignore similarity index 100% rename from Sda1/Etest/SaxMemo2Html/Saxmemo2html/.gitignore rename to Sda1/Etest/SaxMemo2Html/SaxMemo2Hhtml/.gitignore diff --git a/Sda1/Etest/SaxMemo2Html/SaxMemo2Hhtml/pom.exam.xml b/Sda1/Etest/SaxMemo2Html/SaxMemo2Hhtml/pom.exam.xml new file mode 100644 index 000000000..3b4027081 --- /dev/null +++ b/Sda1/Etest/SaxMemo2Html/SaxMemo2Hhtml/pom.exam.xml @@ -0,0 +1,101 @@ +<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" + xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> + <modelVersion>4.0.0</modelVersion> + + <groupId>de.hdm_stuttgart.mi.sda1.saxhtml</groupId> + <artifactId>saxmemo2html</artifactId> + <version>1.0</version> + + <packaging>jar</packaging> + + <name>saxmemo2html</name> + + <!--Fixme: Add a sensible project related domain here --> + <url>http://www.mi.hdm-stuttgart.de/freedocs</url> + + <properties> + <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> + </properties> + + <dependencies> + + <dependency> + <groupId>junit</groupId> + <artifactId>junit</artifactId> + <version>4.11</version> + <scope>test</scope> + </dependency> + + <dependency> + <groupId>org.jdom</groupId> + <artifactId>jdom2</artifactId> + <version>2.0.5</version> + </dependency> + + <dependency> + <groupId>jaxen</groupId> + <artifactId>jaxen</artifactId> + <version>1.1.4</version> + </dependency> + + <dependency> + <groupId>org.apache.logging.log4j</groupId> + <artifactId>log4j-api</artifactId> + <version>2.1</version> + </dependency> + + <dependency> + <groupId>org.apache.logging.log4j</groupId> + <artifactId>log4j-core</artifactId> + <version>2.1</version> + </dependency> + + </dependencies> + + <build> + <plugins> + + <plugin> + <groupId>org.apache.maven.plugins</groupId> + <artifactId>maven-compiler-plugin</artifactId> + <version>3.1</version> + <configuration> + <source>1.8</source> + <target>1.8</target> + </configuration> + </plugin> + + <plugin> + <groupId>org.apache.maven.plugins</groupId> + <artifactId>maven-javadoc-plugin</artifactId> + <version>2.10.1</version> + <configuration /> + </plugin> + + <plugin> + <groupId>org.apache.maven.plugins</groupId> + <artifactId>maven-shade-plugin</artifactId> + <version>2.3</version> + <configuration> + <transformers> + <transformer + implementation="org.apache.maven.plugins.shade.resource.ManifestResourceTransformer"> + <manifestEntries> + <Main-Class>de.hdm_stuttgart.de.saxstandard.App</Main-Class> + </manifestEntries> + </transformer> + </transformers> + </configuration> + <executions> + <execution> + <phase>package</phase> + <goals> + <goal>shade</goal> + </goals> + </execution> + </executions> + </plugin> + + </plugins> + </build> +</project> diff --git a/Sda1/Etest/SaxMemo2Html/SaxMemo2Hhtml/pom.xml b/Sda1/Etest/SaxMemo2Html/SaxMemo2Hhtml/pom.xml new file mode 100644 index 000000000..619c123a4 --- /dev/null +++ b/Sda1/Etest/SaxMemo2Html/SaxMemo2Hhtml/pom.xml @@ -0,0 +1,107 @@ +<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" + xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> + <modelVersion>4.0.0</modelVersion> + + <groupId>de.hdm_stuttgart.mi.sda1.saxhtml</groupId> + <artifactId>saxmemo2html</artifactId> + <version>1.0</version> + + <packaging>jar</packaging> + + <name>saxmemo2html</name> + + <!--Fixme: Add a sensible project related domain here --> + <url>http://www.mi.hdm-stuttgart.de/freedocs</url> + + <properties> + <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> + </properties> + + <dependencies> + + <dependency> + <groupId>junit</groupId> + <artifactId>junit</artifactId> + <version>4.11</version> + <scope>test</scope> + </dependency> + + <dependency> + <groupId>org.jdom</groupId> + <artifactId>jdom2</artifactId> + <version>2.0.5</version> + </dependency> + + <dependency> + <groupId>jaxen</groupId> + <artifactId>jaxen</artifactId> + <version>1.1.4</version> + </dependency> + + <dependency> + <groupId>org.apache.logging.log4j</groupId> + <artifactId>log4j-api</artifactId> + <version>2.1</version> + </dependency> + + <dependency> + <groupId>org.apache.logging.log4j</groupId> + <artifactId>log4j-core</artifactId> + <version>2.1</version> + </dependency> + + <dependency> + <groupId>de.hdm_stuttgart.mi.exam</groupId> + <artifactId>examtesting</artifactId> + <version>1.0</version> + </dependency> + + </dependencies> + + <build> + <plugins> + + <plugin> + <groupId>org.apache.maven.plugins</groupId> + <artifactId>maven-compiler-plugin</artifactId> + <version>3.1</version> + <configuration> + <source>1.8</source> + <target>1.8</target> + </configuration> + </plugin> + + <plugin> + <groupId>org.apache.maven.plugins</groupId> + <artifactId>maven-javadoc-plugin</artifactId> + <version>2.10.1</version> + <configuration /> + </plugin> + + <plugin> + <groupId>org.apache.maven.plugins</groupId> + <artifactId>maven-shade-plugin</artifactId> + <version>2.3</version> + <configuration> + <transformers> + <transformer + implementation="org.apache.maven.plugins.shade.resource.ManifestResourceTransformer"> + <manifestEntries> + <Main-Class>de.hdm_stuttgart.de.saxstandard.App</Main-Class> + </manifestEntries> + </transformer> + </transformers> + </configuration> + <executions> + <execution> + <phase>package</phase> + <goals> + <goal>shade</goal> + </goals> + </execution> + </executions> + </plugin> + + </plugins> + </build> +</project> diff --git a/Sda1/Etest/SaxMemo2Html/SaxMemo2Hhtml/src/main/java/de/hdm_stuttgart/mi/sda1/saxhtml/v1/Memo2HtmlHandler.java b/Sda1/Etest/SaxMemo2Html/SaxMemo2Hhtml/src/main/java/de/hdm_stuttgart/mi/sda1/saxhtml/v1/Memo2HtmlHandler.java new file mode 100644 index 000000000..95a38f8dc --- /dev/null +++ b/Sda1/Etest/SaxMemo2Html/SaxMemo2Hhtml/src/main/java/de/hdm_stuttgart/mi/sda1/saxhtml/v1/Memo2HtmlHandler.java @@ -0,0 +1,61 @@ +package de.hdm_stuttgart.mi.sda1.saxhtml.v1; + +import java.io.PrintStream; + +import org.xml.sax.Attributes; +import org.xml.sax.SAXException; +import org.xml.sax.helpers.DefaultHandler; + +import de.hdm_stuttgart.mi.exam.SaxFilter; + +/** + * Turning <memo> documents to HTML + * + */ +public class Memo2HtmlHandler extends DefaultHandler implements SaxFilter { + + private PrintStream out; + + @Override + public void setOutputStream(final PrintStream out) { + this.out = out; + } + + /** + * + * Output will be written to standard output unless redefined by {@link #setOutputStream(PrintStream)} + */ + public Memo2HtmlHandler() { + setOutputStream(System.out); + } + + @Override + public void startDocument() throws SAXException { + // TODO: complete my implementation! + out.print("<html>"); + } + + @Override + public void startElement(String uri, String localName, String tagName, + Attributes attributes) throws SAXException { + // TODO: implement me! + } + + @Override + public void characters(char[] ch, int start, int length) + throws SAXException { + // TODO: implement me! + } + + @Override + public void endElement(String uri, String localName, String tagName) + throws SAXException { + // TODO: implement me! + } + + @Override + public void endDocument() throws SAXException { + // TODO: complete my implementation! + out.print("</html>"); + } +} \ No newline at end of file diff --git a/Sda1/Etest/SaxMemo2Html/SaxMemo2Hhtml/src/main/java/de/hdm_stuttgart/mi/sda1/saxhtml/v2/Memo2HtmlHandler.java b/Sda1/Etest/SaxMemo2Html/SaxMemo2Hhtml/src/main/java/de/hdm_stuttgart/mi/sda1/saxhtml/v2/Memo2HtmlHandler.java new file mode 100644 index 000000000..50a1d87a5 --- /dev/null +++ b/Sda1/Etest/SaxMemo2Html/SaxMemo2Hhtml/src/main/java/de/hdm_stuttgart/mi/sda1/saxhtml/v2/Memo2HtmlHandler.java @@ -0,0 +1,61 @@ +package de.hdm_stuttgart.mi.sda1.saxhtml.v2; + +import java.io.PrintStream; + +import org.xml.sax.Attributes; +import org.xml.sax.SAXException; +import org.xml.sax.helpers.DefaultHandler; + +import de.hdm_stuttgart.mi.exam.SaxFilter; + +/** + * Turning <memo> documents to HTML + * + */ +public class Memo2HtmlHandler extends DefaultHandler implements SaxFilter { + + private PrintStream out; + + @Override + public void setOutputStream(final PrintStream out) { + this.out = out; + } + + /** + * + * Output will be written to standard output unless redefined by {@link #setOutputStream(PrintStream)} + */ + public Memo2HtmlHandler() { + setOutputStream(System.out); + } + + @Override + public void startDocument() throws SAXException { + // TODO: complete my implementation! + out.print("<html>"); + } + + @Override + public void startElement(String uri, String localName, String tagName, + Attributes attributes) throws SAXException { + // TODO: implement me! + } + + @Override + public void characters(char[] ch, int start, int length) + throws SAXException { + // TODO: implement me! + } + + @Override + public void endElement(String uri, String localName, String tagName) + throws SAXException { + // TODO: implement me! + } + + @Override + public void endDocument() throws SAXException { + // TODO: complete my implementation! + out.print("</html>"); + } +} \ No newline at end of file diff --git a/Sda1/Etest/SaxMemo2Html/Saxmemo2html/src/main/resources/.gitignore b/Sda1/Etest/SaxMemo2Html/SaxMemo2Hhtml/src/main/resources/.gitignore similarity index 100% rename from Sda1/Etest/SaxMemo2Html/Saxmemo2html/src/main/resources/.gitignore rename to Sda1/Etest/SaxMemo2Html/SaxMemo2Hhtml/src/main/resources/.gitignore diff --git a/Sda1/Etest/SaxMemo2Html/Saxmemo2html/src/main/resources/log4j2.xml b/Sda1/Etest/SaxMemo2Html/SaxMemo2Hhtml/src/main/resources/log4j2.xml similarity index 100% rename from Sda1/Etest/SaxMemo2Html/Saxmemo2html/src/main/resources/log4j2.xml rename to Sda1/Etest/SaxMemo2Html/SaxMemo2Hhtml/src/main/resources/log4j2.xml diff --git a/Sda1/Etest/SaxMemo2Html/Saxmemo2html/src/main/resources/memo.xml b/Sda1/Etest/SaxMemo2Html/SaxMemo2Hhtml/src/main/resources/memo.xml similarity index 100% rename from Sda1/Etest/SaxMemo2Html/Saxmemo2html/src/main/resources/memo.xml rename to Sda1/Etest/SaxMemo2Html/SaxMemo2Hhtml/src/main/resources/memo.xml diff --git a/Sda1/Etest/SaxMemo2Html/Saxmemo2html/src/main/resources/memo.xml.1.sample.html b/Sda1/Etest/SaxMemo2Html/SaxMemo2Hhtml/src/main/resources/memo.xml.1.expected.html similarity index 100% rename from Sda1/Etest/SaxMemo2Html/Saxmemo2html/src/main/resources/memo.xml.1.sample.html rename to Sda1/Etest/SaxMemo2Html/SaxMemo2Hhtml/src/main/resources/memo.xml.1.expected.html diff --git a/Sda1/Etest/SaxMemo2Html/Saxmemo2html/src/main/resources/memo.xml.2.sample.html b/Sda1/Etest/SaxMemo2Html/SaxMemo2Hhtml/src/main/resources/memo.xml.2.expected.html similarity index 100% rename from Sda1/Etest/SaxMemo2Html/Saxmemo2html/src/main/resources/memo.xml.2.sample.html rename to Sda1/Etest/SaxMemo2Html/SaxMemo2Hhtml/src/main/resources/memo.xml.2.expected.html diff --git a/Sda1/Etest/SaxMemo2Html/SaxMemo2Hhtml_solution/src/main/java/de/hdm_stuttgart/mi/sda1/saxhtml/v2/Memo2HtmlHandler.java b/Sda1/Etest/SaxMemo2Html/SaxMemo2Hhtml_solution/src/main/java/de/hdm_stuttgart/mi/sda1/saxhtml/v2/Memo2HtmlHandler.java index 698035324..8bca1733e 100644 --- a/Sda1/Etest/SaxMemo2Html/SaxMemo2Hhtml_solution/src/main/java/de/hdm_stuttgart/mi/sda1/saxhtml/v2/Memo2HtmlHandler.java +++ b/Sda1/Etest/SaxMemo2Html/SaxMemo2Hhtml_solution/src/main/java/de/hdm_stuttgart/mi/sda1/saxhtml/v2/Memo2HtmlHandler.java @@ -31,7 +31,7 @@ public class Memo2HtmlHandler extends DefaultHandler implements SaxFilter { @Override public void startDocument() throws SAXException { - // Clear + // Clear recipients being left over from a previous run recipients.clear(); } diff --git a/Sda1/Etest/SaxMemo2Html/SaxMemo2Hhtml_solution/src/test/java/de/hdm_stuttgart/de/sda1/saxhtml/v2/test/TestComplexSaxTransform.java b/Sda1/Etest/SaxMemo2Html/SaxMemo2Hhtml_solution/src/test/java/de/hdm_stuttgart/de/sda1/saxhtml/v2/test/TestComplexSaxTransform.java index 61859cce2..f8eeebb37 100644 --- a/Sda1/Etest/SaxMemo2Html/SaxMemo2Hhtml_solution/src/test/java/de/hdm_stuttgart/de/sda1/saxhtml/v2/test/TestComplexSaxTransform.java +++ b/Sda1/Etest/SaxMemo2Html/SaxMemo2Hhtml_solution/src/test/java/de/hdm_stuttgart/de/sda1/saxhtml/v2/test/TestComplexSaxTransform.java @@ -1,6 +1,9 @@ package de.hdm_stuttgart.de.sda1.saxhtml.v2.test; +import org.junit.Assert; +import org.junit.FixMethodOrder; import org.junit.Test; +import org.junit.runners.MethodSorters; import de.hdm_stuttgart.de.mi.exam.test.sax.DomAssert; import de.hdm_stuttgart.de.mi.exam.test.sax.SaxFilterTest; @@ -11,6 +14,7 @@ import de.hdm_stuttgart.mi.sda1.saxhtml.v2.Memo2HtmlHandler; */ @SuppressWarnings("javadoc") +@FixMethodOrder(MethodSorters.NAME_ASCENDING) public class TestComplexSaxTransform extends SaxFilterTest { static { @@ -43,4 +47,9 @@ public class TestComplexSaxTransform extends SaxFilterTest { DomAssert.assertSingleNodeContent("<strong>M. Goik</strong> must appear inside a <p> immediately following the list of recipients", htmlRootElement, "body/dl/following-sibling::*[1]", "h2", "Subject: Best wishes"); } + @Test public void testXduplicateHandlerInvocation() { + SaxFilterTest.processAndParseResult();// Execute handler a second time. + Assert.assertNull(SaxFilterTest.initializationErrorString, SaxFilterTest.initializationErrorString); + DomAssert.assertNumberOfNodes("Invoking SAX handler two times in succession: There should be two <li> elements matching two recipients", htmlRootElement, "body/dl/dd/ul/li", 2); + } } \ No newline at end of file diff --git a/Sda1/Etest/SaxMemo2Html/Saxmemo2html/pom.xml b/Sda1/Etest/SaxMemo2Html/Saxmemo2html/pom.xml deleted file mode 100644 index c04167eb8..000000000 --- a/Sda1/Etest/SaxMemo2Html/Saxmemo2html/pom.xml +++ /dev/null @@ -1,98 +0,0 @@ -<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> - <modelVersion>4.0.0</modelVersion> - - <groupId>de.hdm_stuttgart.mi.sda1.saxhtml</groupId> - <artifactId>saxmemo2html</artifactId> - <version>1.0</version> - - <packaging>jar</packaging> - - <name>SaxMemo2Hhtml</name> - - <!--Fixme: Add a sensible project related domain here --> - <url>http://www.mi.hdm-stuttgart.de/freedocs</url> - - <properties> - <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> - </properties> - - <dependencies> - - <dependency> - <groupId>junit</groupId> - <artifactId>junit</artifactId> - <version>4.11</version> - <scope>test</scope> - </dependency> - - <dependency> - <groupId>org.jdom</groupId> - <artifactId>jdom2</artifactId> - <version>2.0.5</version> - </dependency> - - <dependency> - <groupId>jaxen</groupId> - <artifactId>jaxen</artifactId> - <version>1.1.4</version> - </dependency> - - <dependency> - <groupId>org.apache.logging.log4j</groupId> - <artifactId>log4j-api</artifactId> - <version>2.1</version> - </dependency> - <dependency> - <groupId>org.apache.logging.log4j</groupId> - <artifactId>log4j-core</artifactId> - <version>2.1</version> - </dependency> - - </dependencies> - - <build> - <plugins> - - <plugin> - <groupId>org.apache.maven.plugins</groupId> - <artifactId>maven-compiler-plugin</artifactId> - <version>3.1</version> - <configuration> - <source>1.8</source> - <target>1.8</target> - </configuration> - </plugin> - - <plugin> - <groupId>org.apache.maven.plugins</groupId> - <artifactId>maven-javadoc-plugin</artifactId> - <version>2.10.1</version> - <configuration/> - </plugin> - - <plugin> - <groupId>org.apache.maven.plugins</groupId> - <artifactId>maven-shade-plugin</artifactId> - <version>2.3</version> - <configuration> - <transformers> - <transformer implementation="org.apache.maven.plugins.shade.resource.ManifestResourceTransformer"> - <manifestEntries> - <Main-Class>de.hdm_stuttgart.de.saxstandard.App</Main-Class> - </manifestEntries> - </transformer> - </transformers> - </configuration> - <executions> - <execution> - <phase>package</phase> - <goals> - <goal>shade</goal> - </goals> - </execution> - </executions> - </plugin> - - </plugins> - </build> -</project> diff --git a/Sda1/Etest/SaxMemo2Html/Saxmemo2html/src/main/java/de/hdm_stuttgart/mi/sda1/saxhtml/tools/ContentRedirect.java b/Sda1/Etest/SaxMemo2Html/Saxmemo2html/src/main/java/de/hdm_stuttgart/mi/sda1/saxhtml/tools/ContentRedirect.java deleted file mode 100644 index 8c27ccce0..000000000 --- a/Sda1/Etest/SaxMemo2Html/Saxmemo2html/src/main/java/de/hdm_stuttgart/mi/sda1/saxhtml/tools/ContentRedirect.java +++ /dev/null @@ -1,15 +0,0 @@ -package de.hdm_stuttgart.mi.sda1.saxhtml.tools; - -import java.io.PrintStream; - -import org.xml.sax.ContentHandler; - -public interface ContentRedirect extends ContentHandler { - - /** - * Allow output redirection. - * @param out Output will be redirected here. - */ - public void setOutputStream(PrintStream out); - -} diff --git a/Sda1/Etest/SaxMemo2Html/Saxmemo2html/src/main/java/de/hdm_stuttgart/mi/sda1/saxhtml/v1/Driver.java b/Sda1/Etest/SaxMemo2Html/Saxmemo2html/src/main/java/de/hdm_stuttgart/mi/sda1/saxhtml/v1/Driver.java deleted file mode 100644 index 1a3cd8f29..000000000 --- a/Sda1/Etest/SaxMemo2Html/Saxmemo2html/src/main/java/de/hdm_stuttgart/mi/sda1/saxhtml/v1/Driver.java +++ /dev/null @@ -1,15 +0,0 @@ -package de.hdm_stuttgart.mi.sda1.saxhtml.v1; - -/** Driver */ -public class Driver { - /** @param argv unused */ - public static void main(String argv[]) { - try{ - Memo2Html memo2html = new Memo2Html(new Memo2HtmlHandler()); - memo2html.parse("src/main/resources/memo.xml"); - - } catch (Exception e){ - e.printStackTrace(System.err); - } - } -} \ No newline at end of file diff --git a/Sda1/Etest/SaxMemo2Html/Saxmemo2html/src/main/java/de/hdm_stuttgart/mi/sda1/saxhtml/v1/Memo2Html.java b/Sda1/Etest/SaxMemo2Html/Saxmemo2html/src/main/java/de/hdm_stuttgart/mi/sda1/saxhtml/v1/Memo2Html.java deleted file mode 100644 index ef3ccc554..000000000 --- a/Sda1/Etest/SaxMemo2Html/Saxmemo2html/src/main/java/de/hdm_stuttgart/mi/sda1/saxhtml/v1/Memo2Html.java +++ /dev/null @@ -1,49 +0,0 @@ -package de.hdm_stuttgart.mi.sda1.saxhtml.v1; - -import java.io.IOException; - -import javax.xml.parsers.ParserConfigurationException; -import javax.xml.parsers.SAXParser; -import javax.xml.parsers.SAXParserFactory; - -import org.xml.sax.ContentHandler; -import org.xml.sax.SAXException; -import org.xml.sax.XMLReader; - -/** Parser, content- and error handler assembly */ -public class Memo2Html { - - private final XMLReader xmlReader; - private final MyErrorHandler errorHandler = new MyErrorHandler(); - - /** - * @param out - * @throws SAXException - * Parsing may fail. - * @throws ParserConfigurationException - * Unable to instantiate parser. - */ - public Memo2Html(final ContentHandler handler) throws SAXException, - ParserConfigurationException { - final SAXParserFactory saxPf = SAXParserFactory.newInstance(); - final SAXParser saxParser = saxPf.newSAXParser(); - xmlReader = saxParser.getXMLReader(); - - xmlReader.setContentHandler(handler); - xmlReader.setErrorHandler(errorHandler); - } - - /** - * Parse an existing memo instance and create HTML output. - * - * @param uri - * The resource to be parsed - * @throws IOException - * Access related problems - * @throws SAXException - * Parsing may fail - */ - public void parse(final String uri) throws IOException, SAXException { - xmlReader.parse(uri); - } -} \ No newline at end of file diff --git a/Sda1/Etest/SaxMemo2Html/Saxmemo2html/src/main/java/de/hdm_stuttgart/mi/sda1/saxhtml/v1/Memo2HtmlHandler.java b/Sda1/Etest/SaxMemo2Html/Saxmemo2html/src/main/java/de/hdm_stuttgart/mi/sda1/saxhtml/v1/Memo2HtmlHandler.java deleted file mode 100644 index 36b6088b4..000000000 --- a/Sda1/Etest/SaxMemo2Html/Saxmemo2html/src/main/java/de/hdm_stuttgart/mi/sda1/saxhtml/v1/Memo2HtmlHandler.java +++ /dev/null @@ -1,69 +0,0 @@ -package de.hdm_stuttgart.mi.sda1.saxhtml.v1; - -import java.io.PrintStream; - -import org.xml.sax.Attributes; -import org.xml.sax.Locator; -import org.xml.sax.SAXException; - -import de.hdm_stuttgart.mi.sda1.saxhtml.tools.ContentRedirect; - -/** - * Turning <memo> documents to HTML as being shown in sample document memo.xml.1.sample.html - * - */ -public class Memo2HtmlHandler implements ContentRedirect { - - private PrintStream out; - - /** - * Output will be written to stdout - */ - public Memo2HtmlHandler() { - setOutputStream(System.out); - } - - @Override - public void startDocument() throws SAXException { - // TODO Auto-generated method stub - out.print("<html>"); - } - - @Override - public void endDocument() throws SAXException { - // TODO Auto-generated method stub - out.print("</html>"); - } - - @Override - public void startElement(String uri, String localName, String qName, - Attributes atts) throws SAXException { - // TODO Auto-generated method stub - } - - @Override - public void endElement(String uri, String localName, String qName) - throws SAXException { - // TODO Auto-generated method stub - } - - @Override - public void characters(char[] ch, int start, int length) - throws SAXException { - // TODO Auto-generated method stub - } - - // You probably don't need the following callbacks. - // - @Override public void setDocumentLocator(Locator locator) {} - @Override public void startPrefixMapping(String prefix, String uri) throws SAXException {} - @Override public void endPrefixMapping(String prefix) throws SAXException {} - @Override public void ignorableWhitespace(char[] ch, int start, int length) throws SAXException {} - @Override public void processingInstruction(String target, String data) throws SAXException {} - @Override public void skippedEntity(String name) throws SAXException {} - - @Override - public void setOutputStream(final PrintStream out) { - this.out = out; - } -} \ No newline at end of file diff --git a/Sda1/Etest/SaxMemo2Html/Saxmemo2html/src/main/java/de/hdm_stuttgart/mi/sda1/saxhtml/v1/MyErrorHandler.java b/Sda1/Etest/SaxMemo2Html/Saxmemo2html/src/main/java/de/hdm_stuttgart/mi/sda1/saxhtml/v1/MyErrorHandler.java deleted file mode 100644 index 1fce5e72b..000000000 --- a/Sda1/Etest/SaxMemo2Html/Saxmemo2html/src/main/java/de/hdm_stuttgart/mi/sda1/saxhtml/v1/MyErrorHandler.java +++ /dev/null @@ -1,25 +0,0 @@ -package de.hdm_stuttgart.mi.sda1.saxhtml.v1; - -import org.xml.sax.SAXException; -import org.xml.sax.SAXParseException; -import org.xml.sax.ErrorHandler; - -/** Handle parsing errors */ -public class MyErrorHandler implements ErrorHandler { - /** @see ErrorHandler#warning(SAXParseException) */ - public void warning(SAXParseException e) { - System.err.println("[Warning]" + getLocationString(e)); - } - /** @see ErrorHandler#error(SAXParseException) */ - public void error(SAXParseException e) { - System.err.println("[Error]" + getLocationString(e)); - } - /** @see ErrorHandler#fatalError(SAXParseException) */ - public void fatalError(SAXParseException e) throws SAXException{ - System.err.println("[Fatal Error]" + getLocationString(e)); - } - private String getLocationString(SAXParseException e) { - return " line " + e.getLineNumber() + - ", column " + e.getColumnNumber()+ ":" + e.getMessage(); - } -} \ No newline at end of file diff --git a/Sda1/Etest/SaxMemo2Html/Saxmemo2html/src/main/java/de/hdm_stuttgart/mi/sda1/saxhtml/v2/Driver.java b/Sda1/Etest/SaxMemo2Html/Saxmemo2html/src/main/java/de/hdm_stuttgart/mi/sda1/saxhtml/v2/Driver.java deleted file mode 100644 index 99616e0b9..000000000 --- a/Sda1/Etest/SaxMemo2Html/Saxmemo2html/src/main/java/de/hdm_stuttgart/mi/sda1/saxhtml/v2/Driver.java +++ /dev/null @@ -1,17 +0,0 @@ -package de.hdm_stuttgart.mi.sda1.saxhtml.v2; - -import de.hdm_stuttgart.mi.sda1.saxhtml.v1.Memo2HtmlHandler; - -/** Driver */ -public class Driver { - /** @param argv unused */ - public static void main(String argv[]) { - try{ - Memo2Html memo2html = new Memo2Html(new Memo2HtmlHandler()); - memo2html.parse("src/main/resources/memo.xml"); - - } catch (Exception e){ - e.printStackTrace(System.err); - } - } -} \ No newline at end of file diff --git a/Sda1/Etest/SaxMemo2Html/Saxmemo2html/src/main/java/de/hdm_stuttgart/mi/sda1/saxhtml/v2/Memo2Html.java b/Sda1/Etest/SaxMemo2Html/Saxmemo2html/src/main/java/de/hdm_stuttgart/mi/sda1/saxhtml/v2/Memo2Html.java deleted file mode 100644 index c575ecd00..000000000 --- a/Sda1/Etest/SaxMemo2Html/Saxmemo2html/src/main/java/de/hdm_stuttgart/mi/sda1/saxhtml/v2/Memo2Html.java +++ /dev/null @@ -1,51 +0,0 @@ -package de.hdm_stuttgart.mi.sda1.saxhtml.v2; - -import java.io.IOException; - -import javax.xml.parsers.ParserConfigurationException; -import javax.xml.parsers.SAXParser; -import javax.xml.parsers.SAXParserFactory; - -import org.xml.sax.ContentHandler; -import org.xml.sax.SAXException; -import org.xml.sax.XMLReader; - -import de.hdm_stuttgart.mi.sda1.saxhtml.v1.MyErrorHandler; - -/** Parser, content- and error handler assembly */ -public class Memo2Html { - - private final XMLReader xmlReader; - private final MyErrorHandler errorHandler = new MyErrorHandler(); - - /** - * @param out Write output to stream - * @throws SAXException - * Parsing may fail. - * @throws ParserConfigurationException - * Unable to instantiate parser. - */ - public Memo2Html(final ContentHandler handler) throws SAXException, - ParserConfigurationException { - final SAXParserFactory saxPf = SAXParserFactory.newInstance(); - final SAXParser saxParser = saxPf.newSAXParser(); - xmlReader = saxParser.getXMLReader(); - - xmlReader.setContentHandler(handler); - xmlReader.setErrorHandler(errorHandler); - } - - /** - * Parse an existing memo instance and create HTML output. - * - * @param uri - * The resource to be parsed - * @throws IOException - * Access related problems - * @throws SAXException - * Parsing may fail - */ - public void parse(final String uri) throws IOException, SAXException { - xmlReader.parse(uri); - } -} \ No newline at end of file diff --git a/Sda1/Etest/SaxMemo2Html/Saxmemo2html/src/main/java/de/hdm_stuttgart/mi/sda1/saxhtml/v2/Memo2HtmlHandler.java b/Sda1/Etest/SaxMemo2Html/Saxmemo2html/src/main/java/de/hdm_stuttgart/mi/sda1/saxhtml/v2/Memo2HtmlHandler.java deleted file mode 100644 index 7b640068f..000000000 --- a/Sda1/Etest/SaxMemo2Html/Saxmemo2html/src/main/java/de/hdm_stuttgart/mi/sda1/saxhtml/v2/Memo2HtmlHandler.java +++ /dev/null @@ -1,69 +0,0 @@ -package de.hdm_stuttgart.mi.sda1.saxhtml.v2; - -import java.io.PrintStream; - -import org.xml.sax.Attributes; -import org.xml.sax.Locator; -import org.xml.sax.SAXException; - -import de.hdm_stuttgart.mi.sda1.saxhtml.tools.ContentRedirect; - -/** - * Turning <memo> documents to HTML - * - */ -public class Memo2HtmlHandler implements ContentRedirect { - - private PrintStream out; - - /** - * Output will be written to stdout - */ - public Memo2HtmlHandler() { - setOutputStream(System.out); - } - - @Override - public void startDocument() throws SAXException { - // TODO Auto-generated method stub - out.print("<html>"); - } - - @Override - public void endDocument() throws SAXException { - // TODO Auto-generated method stub - out.print("</html>"); - } - - @Override - public void startElement(String uri, String localName, String qName, - Attributes atts) throws SAXException { - // TODO Auto-generated method stub - } - - @Override - public void endElement(String uri, String localName, String qName) - throws SAXException { - // TODO Auto-generated method stub - } - - @Override - public void characters(char[] ch, int start, int length) - throws SAXException { - // TODO Auto-generated method stub - } - - // You probably don't need the following callbacks. - // - @Override public void setDocumentLocator(Locator locator) {} - @Override public void startPrefixMapping(String prefix, String uri) throws SAXException {} - @Override public void endPrefixMapping(String prefix) throws SAXException {} - @Override public void ignorableWhitespace(char[] ch, int start, int length) throws SAXException {} - @Override public void processingInstruction(String target, String data) throws SAXException {} - @Override public void skippedEntity(String name) throws SAXException {} - - @Override - public void setOutputStream(final PrintStream out) { - this.out = out; - } -} \ No newline at end of file diff --git a/Sda1/Etest/SaxMemo2Html/Saxmemo2html/src/test/java/de/hdm_stuttgart/de/sda1/saxhtml/v1/test/TestSimpleSaxTransform.java b/Sda1/Etest/SaxMemo2Html/Saxmemo2html/src/test/java/de/hdm_stuttgart/de/sda1/saxhtml/v1/test/TestSimpleSaxTransform.java deleted file mode 100644 index f8bbf56bc..000000000 --- a/Sda1/Etest/SaxMemo2Html/Saxmemo2html/src/test/java/de/hdm_stuttgart/de/sda1/saxhtml/v1/test/TestSimpleSaxTransform.java +++ /dev/null @@ -1,46 +0,0 @@ -package de.hdm_stuttgart.de.sda1.saxhtml.v1.test; - -import org.junit.Assert; -import org.junit.Test; - -import de.hdm_stuttgart.de.testing.dom.ConversionTest; -import de.hdm_stuttgart.de.testing.dom.DomAssert; -import de.hdm_stuttgart.mi.sda1.saxhtml.v1.Memo2HtmlHandler; - -/** - * Unit testing XML to HTML output - */ -@SuppressWarnings("javadoc") -public class TestSimpleSaxTransform extends ConversionTest { - - public TestSimpleSaxTransform() { - super("src/main/resources/memo.xml", new Memo2HtmlHandler(), ".1.html"); - } - - @Test public void checkWellFormedness() { - Assert.assertNull("Unable to parse generated file:" + errorInitString, errorInitString); - } - - @Test public void testSenderInHeader() { - DomAssert.assertSingleNodeContent("<title>Memo message</title> must be the only child of <head>", htmlRootElement, "head/*", "title", "Memo message"); - } - @Test public void testFrom() { - DomAssert.assertSingleNodeContent("<strong>M. Goik</strong> must appear within first <h2> child of <body>", - htmlRootElement, "body/h2[1]/strong", "strong", "M. Goik"); - } - @Test public void testNumberfRecipients() { - DomAssert.assertNumberOfNodes("Two <li> elements required matching two recipients", htmlRootElement, "body/ul/li", 2); - } - @Test public void testSecondRecipient() { - DomAssert.assertSingleNodeContent("Second recipient must be <li>A. June</li>", - htmlRootElement, "body/ul/li[2]", "li", "A. June"); - } - @Test public void testSubject() { - DomAssert.assertSingleNodeContent("<h2>Subject: Best wishes</h2> must appear as first child of <body>", - htmlRootElement, "body/*[4]", "h2", "Subject: Best wishes"); - } - @Test public void testContent() { - DomAssert.assertSingleNodeContent("Last child of <body> must be content", - htmlRootElement, "body/*[5]", "p", "Hi all, congratulations to your splendid party"); - } -} \ No newline at end of file diff --git a/Sda1/Etest/SaxMemo2Html/Saxmemo2html/src/test/java/de/hdm_stuttgart/de/sda1/saxhtml/v2/test/TestComplexSaxTransform.java b/Sda1/Etest/SaxMemo2Html/Saxmemo2html/src/test/java/de/hdm_stuttgart/de/sda1/saxhtml/v2/test/TestComplexSaxTransform.java deleted file mode 100644 index 9f981640c..000000000 --- a/Sda1/Etest/SaxMemo2Html/Saxmemo2html/src/test/java/de/hdm_stuttgart/de/sda1/saxhtml/v2/test/TestComplexSaxTransform.java +++ /dev/null @@ -1,46 +0,0 @@ -package de.hdm_stuttgart.de.sda1.saxhtml.v2.test; - -import org.junit.Test; - -import de.hdm_stuttgart.de.testing.dom.ConversionTest; -import de.hdm_stuttgart.de.testing.dom.DomAssert; -import de.hdm_stuttgart.mi.sda1.saxhtml.v2.Memo2HtmlHandler; - -/** - * Turning <memo> documents to HTML as being shown in sample document memo.xml.2.sample.html - - */ -@SuppressWarnings("javadoc") -public class TestComplexSaxTransform extends ConversionTest { - - public TestComplexSaxTransform() { - super("src/main/resources/memo.xml", new Memo2HtmlHandler(), ".2.html"); - } - - @Test public void testSenderInHeader() { - DomAssert.assertSingleNodeContent("<title>Memo from M. Goik</title> must be child of <head>", htmlRootElement, "head/title", "Memo from M. Goik"); - } - @Test public void testNumberfRecipients() { - DomAssert.assertNumberOfNodes("There should be two <li> elements matching two recipients", htmlRootElement, "body/dl/dd/ul/li", 2); - } - @Test public void testH1MemoSubjectMessage() { - DomAssert.assertSingleNodeContent("<h2>Subject:Best wishes</h2> must appear as first child of <body>", - htmlRootElement, "body/*[1]", "h2", "Subject:Best wishes"); - } - @Test public void testSenderBeforeRecipientList() { - DomAssert.assertSingleNodeContent("<dd>M. Goik</dd> must appear as second child of the list of recipients", - htmlRootElement, "body/dl/*[2]", "dd", "M. Goik"); - } - @Test public void testMemoContent() { - DomAssert.assertSingleNodeContent("content must appear as second <p> child after recipient list in <body>", - htmlRootElement, "body/dl/following-sibling::*[2]", "p", "Hi all, congratulations to your splendid party"); - } - @Test public void testLastParagraph() { - DomAssert.assertNumberOfNodes("Expecting two <p> children of <body>", - htmlRootElement, "body/*[name(.)='p']", 2); - } - @Test public void testSenderAtFoot() { - DomAssert.assertSingleNodeContent("<strong>M. Goik</strong> must appear inside a <p> immediately following the list of recipients", - htmlRootElement, "body/dl/following-sibling::*[1]", "h2", "Subject: Best wishes"); - } -} \ No newline at end of file diff --git a/Sda1/Etest/SaxMemo2Html/Saxmemo2html/src/test/java/de/hdm_stuttgart/de/testing/dom/AssertXpathResult.java b/Sda1/Etest/SaxMemo2Html/Saxmemo2html/src/test/java/de/hdm_stuttgart/de/testing/dom/AssertXpathResult.java deleted file mode 100644 index d36d86304..000000000 --- a/Sda1/Etest/SaxMemo2Html/Saxmemo2html/src/test/java/de/hdm_stuttgart/de/testing/dom/AssertXpathResult.java +++ /dev/null @@ -1,18 +0,0 @@ -package de.hdm_stuttgart.de.testing.dom; - -/** - * @author goik - * - */ -public class AssertXpathResult extends AssertionError { - - private static final long serialVersionUID = -1369600480719379445L; - - /** - * @param msg - */ - public AssertXpathResult(String msg) { - super(msg); - } - -} diff --git a/Sda1/Etest/SaxMemo2Html/Saxmemo2html/src/test/java/de/hdm_stuttgart/de/testing/dom/ConversionTest.java b/Sda1/Etest/SaxMemo2Html/Saxmemo2html/src/test/java/de/hdm_stuttgart/de/testing/dom/ConversionTest.java deleted file mode 100644 index 25bad0821..000000000 --- a/Sda1/Etest/SaxMemo2Html/Saxmemo2html/src/test/java/de/hdm_stuttgart/de/testing/dom/ConversionTest.java +++ /dev/null @@ -1,71 +0,0 @@ -package de.hdm_stuttgart.de.testing.dom; - -import java.io.FileNotFoundException; -import java.io.IOException; -import java.io.PrintStream; - -import javax.xml.parsers.ParserConfigurationException; - -import org.jdom2.Element; -import org.jdom2.JDOMException; -import org.jdom2.input.SAXBuilder; -import org.xml.sax.SAXException; - -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 - - */ -@SuppressWarnings("javadoc") -public abstract class ConversionTest { - - public final String xmlInputFileName, htmlOutputFileName; - final ContentRedirect saxHandler; - protected String errorInitString = null; - - protected Element htmlRootElement; - - protected ConversionTest(final String xmlInputFileName, final ContentRedirect saxHandler, final String outputExtension) { - - this.saxHandler = saxHandler; - - this.xmlInputFileName = xmlInputFileName; - this.htmlOutputFileName = xmlInputFileName + outputExtension; - - final PrintStream out; - - 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(); - - 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(); - } -} \ No newline at end of file diff --git a/Sda1/Etest/SaxMemo2Html/Saxmemo2html/src/test/java/de/hdm_stuttgart/de/testing/dom/DomAssert.java b/Sda1/Etest/SaxMemo2Html/Saxmemo2html/src/test/java/de/hdm_stuttgart/de/testing/dom/DomAssert.java deleted file mode 100644 index 02f9ba854..000000000 --- a/Sda1/Etest/SaxMemo2Html/Saxmemo2html/src/test/java/de/hdm_stuttgart/de/testing/dom/DomAssert.java +++ /dev/null @@ -1,91 +0,0 @@ -package de.hdm_stuttgart.de.testing.dom; - -import java.util.List; - -import org.jdom2.Element; -import org.jdom2.xpath.XPathExpression; -import org.jdom2.xpath.XPathFactory; - -/** - * @author goik - * - */ -public class DomAssert { - - - final static XPathFactory xpf = XPathFactory.instance(); - - /** - * @param msg - * @param context - * @param xpath - * @param expectedNodeCount - */ -public static void assertNumberOfNodes(final String msg, final Element context, final String xpath, int expectedNodeCount) { - - @SuppressWarnings({ "unchecked", "rawtypes" }) - final XPathExpression<Element> xpathExpr = (XPathExpression<Element>) (XPathExpression) xpf.compile(xpath); - - final List<Element> matchedNodes = xpathExpr.evaluate(context); - - if (expectedNodeCount != matchedNodes.size()) { - throw new AssertXpathResult(msg + "\nExpected " + expectedNodeCount + " node" + (expectedNodeCount == 1? "":"s") + " for xpath '" + xpath + - "' but found " + matchedNodes.size()); - } - } - - /** - * @param msg - * @param context - * @param xpath - * @param expectedContent - */ -public static void assertSingleNodeContent(final String msg, final Element context, final String xpath, String expectedContent) { - - @SuppressWarnings({ "unchecked", "rawtypes" }) - final XPathExpression<Element> xpathExpr = (XPathExpression<Element>) (XPathExpression) xpf.compile(xpath); - - final List<Element> matchedNodes = xpathExpr.evaluate(context); - if (1 == matchedNodes.size()) { - final String content = matchedNodes.get(0).getValue(); - if (!content.equals(expectedContent)) { - throw new AssertXpathResult(msg + "\nExpected content '" + expectedContent + "' for xpath '" + xpath + "' but found '" + content + "'"); - } - } else { - throw new AssertXpathResult("\nExactly one node expected for xpath '" + xpath + "' but found " + matchedNodes.size()); - } - } - - /** - * @param msg - * @param context - * @param xpath - * @param expectedTagName - * @param expectedContent - */ -public static void assertSingleNodeContent(final String msg, final Element context, final String xpath, final String expectedTagName, String expectedContent) { - - @SuppressWarnings({ "unchecked", "rawtypes" }) - final XPathExpression<Element> xpathExpr = (XPathExpression<Element>) (XPathExpression) xpf.compile(xpath); - - final List<Element> matchedNodes = xpathExpr.evaluate(context); - if (1 == matchedNodes.size()) { - - final Element element = matchedNodes.get(0); - - final String elementTagName = element.getName(); - if (!expectedTagName.equals(elementTagName)) { - throw new AssertXpathResult(msg + "\nExpected <" + expectedTagName + "> for xpath '" + xpath + "' but found <" + - elementTagName + ">"); - } - final String content = element.getValue(); - if (!expectedContent.equals(content)) { - throw new AssertXpathResult(msg + "\nExpected element content '" + expectedContent + "' for xpath '" + xpath + "' but found '" + - content + "'"); - } - - } else { - throw new AssertXpathResult("Exactly node expected for xpath '" + xpath + "' but found " + matchedNodes.size()); - } - } -} diff --git a/Sda1/Etest/SaxMemo2Html/exercise1.xhtml b/Sda1/Etest/SaxMemo2Html/exercise1.xhtml index 2f98a36e1..018d4d0bc 100644 --- a/Sda1/Etest/SaxMemo2Html/exercise1.xhtml +++ b/Sda1/Etest/SaxMemo2Html/exercise1.xhtml @@ -6,50 +6,32 @@ </head> <body><h2>Objective</h2><p>Implementing two SAX based Java applications - transforming memo documents to HTML.</p><h2>Preparations</h2><ol> + transforming memo documents to HTML.</p><h2>Preparations / + Description</h2><ol> <li>Download <a href="/iliasData/goik/sax_hahHzh66-99DDDwsq/saxmemo2html.zip">saxmemo2html.zip</a> and import it as a project into your Eclipse workspace.</li> - <li><p>Your resulting Project <code>saxmemo2html</code>contains among - other files:</p><ul> - <li><p><strong>src/main/resources/memo.xml</strong></p><p>A sample - memo input document.</p></li> - - <li><p><strong>de.hdm_stuttgart.mi.sda1.saxhtml.v1.Memo2HtmlHandler</strong></p><p>A - SAX event handler which currently just creates static - <code><html></html></code> output. The non-default - constructor expects a <a - href="http://docs.oracle.com/javase/8/docs/api/java/io/PrintStream.html">java.io.PrintStream</a> - allowing unit tests to redirect output to a file for subsequent - result analysis.</p></li> - - <li><p><strong>de.hdm_stuttgart.mi.sda1.saxhtml.v1.Driver</strong></p><p>Executing - this class converts <code>memo.xml</code> to - <code>src/main/resources/memo.xml.1.html</code> by using - <code>de.hdm_stuttgart.mi.sda1.saxhtml.v1.Memo2HtmlHandler</code> - and writing to output console.</p></li> - - <li><p><strong>src/main/resources/memo.xml.1.sample.html</strong></p><p>The - intended output corresponding to be generated from </p></li> - - <li><p><strong>de.hdm_stuttgart.de.sda1.saxhtml.v1.test.TestSimpleSaxTransform</strong></p><p>This - Junit class executes your handler and writes the corresponding - output to src/main/resources/memo.xml.1.html. The latter file then - becomes subject to a series of XPath expression tests checking for - correctness of your output.</p></li> - </ul></li> - </ol><h2>Description</h2><p>Our sample document memo document - contains:</p><pre style="font-family:monospace;"><memo> + <li><p>Your imported project <code>saxmemo2html</code> contains:</p><ul> + <li><p><strong>src/main/resources/memo.xml, a sample memo input + document:</strong></p><pre style="font-family:monospace;"><memo> <from>M. Goik</from> <to>B. King</to> <to>A. June</to> <subject>Best wishes</subject> <content>Hi all, congratulations to your splendid party</content> -</memo></pre><h2>ToDo, Part 1</h2><p>This exercise deals with Java - classes from packages containing the string <strong>v1</strong> in their - names. Complete the implementation of <code>Memo2HtmlHandler</code> to - generate the content of <code>memo.xml.1.sample.html</code>:</p><pre><html> +</memo></pre></li> + + <li><p><strong>de.hdm_stuttgart.mi.sda1.saxhtml.v1.Memo2HtmlHandler</strong></p><p>A + SAX event handler currently just creating + '<code><html></html></code>' as output. The method + <code>setOutputStream(final PrintStream out)</code> allows for Junit + tests redirecting output to a file and subsequently analyzing the + result.</p></li> + + <li><p><strong>src/main/resources/memo.xml.1.expected.html, the + intended output to be generated from + <code>memo.xml:</code></strong></p><pre><html> <head> <title>Memo message</title> </head> @@ -63,19 +45,50 @@ <h2>Subject: Best wishes</h2> <p>Hi all, congratulations to your splendid party</p> </body> -</html></pre><p>Your SAX handler shall allow for processing of multiple - XML input documents in sequence. </p><p>Watch your output being generated by - executing <code>de.hdm_stuttgart.mi.sda1.saxhtml.v1.Driver</code>. When you - are satisfied with your result execute the Junit test - <code>de.hdm_stuttgart.de.sda1.saxhtml.v1.test.ConversionTest</code>. When - you are finished export your Maven project as a compressed .zip archive and - upload it.</p><h2>ToDo, Part 2</h2><p>This second exercise deals with Java - classes from packages containing the string <strong>v2</strong> in their - names. So you might want to close <strong>all</strong> file tabs in your - current Eclipse project to avoid confusing yourself with files from the - first part of this exercise.</p><p>Your project contains a second set of - files intended to create more sophisticated output. A sample result is being - contained in <code>memo.xml.2.sample.html</code>:</p><pre><html> +</html></pre><p>.</p></li> + + <li><p><strong>de.hdm_stuttgart.de.sda1.saxhtml.v1.test.TestSimpleSaxTransform</strong></p><p>Running + this class as a Junit test in turn executes an instance of + <code>Memo2HtmlHandler</code> and writes the corresponding output to + <code>src/main/resources/memo.xml.1.html</code>. This output will + subsequently be duplicated to your eclipse's console as well. The + latter file then becomes subject to the series of XPath expression + tests checking your output for various aspects of + correctness.</p><h3 style="color:red;">Caution!</h3><ul> + <li><p>When implementing your SAX handler <b>always</b> use the + predefined output stream <code>private PrintStream out</code> in + class <code>Memo2HtmlHandler</code> which will direct your + output to <code>memo.xml.1.html</code>. In contrast calls using + System.out.println(...) will only create text on standard output + i.e. in your (Eclipse's) console but not in + <code>memo.xml.1.html</code>.</p></li> + + <li>Test execution requires your Xhtml output to be well-formed. + In case of doubt inspect the generated file + <code>src/main/resources/memo.xml.1.html</code>.</li> + </ul></li> + </ul></li> + </ol><h2>ToDo, Part 1</h2><p>This exercise deals with Java classes from + packages containing the string <strong>v1</strong> in their names.</p><ol> + <li>Complete the implementation of + <code>de.hdm_stuttgart.mi.sda1.saxhtml.v1.Memo2HtmlHandler</code> to + generate output as in <code>memo.xml.1.sample.html</code>.</li> + + <li>Your SAX handler shall allow for processing multiple XML input + documents in sequence. </li> + </ol><p>Watch your output being generated by executing the Junit test. On + completion export your Maven project as a compressed .zip archive (.tar.gz + export format may not work!) and upload it.</p><h3 + style="color:red;">Caution:</h3><p>Marking will happen semi automatically + based on the Junit test results. Thus uploading projects containing Java + syntax errors or producing non well-formed Xhtml output is a waste of time + (your's and mine).</p><h2>ToDo, Part 2</h2><p>This second exercise deals + with Java classes from packages containing the string <strong>v2</strong> in + their names. So you might want to close <strong>all</strong> file tabs in + your current Eclipse project to avoid getting confused with the first part + of this exercise.</p><p>Your project contains a second set of files intended + to create more sophisticated output. The intended result is being contained + in <code>memo.xml.2.expected.html</code>:</p><pre><html> <head><title>Memo from M. Goik</title></head> <body> <h2>Subject:Best wishes</h2> @@ -95,17 +108,23 @@ <p>End of message from <strong>M. Goik</strong></p> </body> </html></pre><p>Complete the implementation of - <code>de.hdm_stuttgart.mi.sda1.saxhtml.v2.Memo2HtmlHandler</code>. - Corresponding Driver and Junit classes are being supplied as - <code>de.hdm_stuttgart.mi.sda1.saxhtml.v2.Driver</code> and - <code>de.hdm_stuttgart.de.sda1.saxhtml.v2.test.TestComplexSaxTransform</code>.</p><p>When - you are finished zip your project again and upload it. Only the last .zip - file will become subject to marking.</p><h3>Hint:</h3><p>In this second part - the order of content from your XML input is not being preserved. The subject - for example is to be shown before both sender and recipients. Furthermore - some input (sender's name) has to be shown multiple times. To tackle these - challenges you may first collect all relevant input during the SAX parsing - process and completely defer HTML output generation to the <a - href="http://docs.oracle.com/javase/8/docs/api/org/xml/sax/ContentHandler.html#endDocument--">endDocument()</a> - method.</p></body> + <code>de.hdm_stuttgart.mi.sda1.saxhtml.v2.Memo2HtmlHandler</code>. A + Corresponding Junit Test class is being provided by + <code>de.hdm_stuttgart.de.sda1.saxhtml.v2.test.TestComplexSaxTransform</code>.</p><p>O + completion export your project as a .zip file again and upload it. Only the + last project export file containing both projects will become subject to + marking.</p><h3>Hint:</h3><p>In this second part the order of content being + generated from <code>memo.xml</code> is not being preserved. The + <code><subject></code>'s content for example is to be shown before + both sender and recipients. Furthermore the sender's name being contained in + <code><from></code> has to be shown multiple times in different + positions. To tackle these challenges you may implement two distinct + processing phases:</p><ol> + <li>Collect all relevant input during the SAX parsing process by + providing appropriate containers.</li> + + <li>Completely defer XHTML output generation to the <a + href="http://docs.oracle.com/javase/8/docs/api/org/xml/sax/ContentHandler.html#endDocument--">endDocument()</a> + method.</li> + </ol></body> </html> diff --git a/ws/eclipse/ExamTesting/src/main/java/de/hdm_stuttgart/de/mi/exam/test/sax/SaxFilterTest.java b/ws/eclipse/ExamTesting/src/main/java/de/hdm_stuttgart/de/mi/exam/test/sax/SaxFilterTest.java index 16ec754c6..4590f8601 100644 --- a/ws/eclipse/ExamTesting/src/main/java/de/hdm_stuttgart/de/mi/exam/test/sax/SaxFilterTest.java +++ b/ws/eclipse/ExamTesting/src/main/java/de/hdm_stuttgart/de/mi/exam/test/sax/SaxFilterTest.java @@ -41,6 +41,10 @@ public abstract class SaxFilterTest { SaxFilterTest.htmlOutputFileName = xmlInputFileName + resultFileExtension; SaxFilterTest.saxHandler = saxHandler; + processAndParseResult(); + } + + static protected void processAndParseResult() { final PrintStream out; try { -- GitLab