From 1806d40d5bd46de56bce0e3bbb8de71bfa614d40 Mon Sep 17 00:00:00 2001 From: Martin Goik <goik@hdm-stuttgart.de> Date: Thu, 18 Dec 2014 14:53:02 +0100 Subject: [PATCH] JDOM unit test asserted exercise --- Sda1/Etest/JdomTable/Exercise/.gitignore | 5 - Sda1/Etest/JdomTable/Exercise/pom.xml | 38 ------ .../sda1/jdom/common/MySaxErrorHandler.java | 44 ------ .../mi/sda1/jdom/common/package-info.java | 4 - .../mi/sda1/jdom/table/Driver.java | 23 ---- .../mi/sda1/jdom/table/TablePresentation.java | 84 ------------ Sda1/Etest/JdomTable/Solution/.gitignore | 5 - Sda1/Etest/JdomTable/Solution/pom.xml | 38 ------ .../mi/sda1/jdom/background/Driver.java | 27 ---- .../jdom/background/TablePresentation.java | 90 ------------- .../sda1/jdom/common/MySaxErrorHandler.java | 44 ------ .../mi/sda1/jdom/common/package-info.java | 5 - .../mi/sda1/usercolumns/Driver.java | 25 ---- Sda1/Etest/JdomTable/exercise.xhtml | 125 ++++++++++++++++++ Sda1/Etest/JdomTable/jdomtable/.gitignore | 4 + Sda1/Etest/JdomTable/jdomtable/pom.exam.xml | 106 +++++++++++++++ Sda1/Etest/JdomTable/jdomtable/pom.xml | 112 ++++++++++++++++ .../sda1/jdom/background/RowHighlighting.java | 30 +++++ .../jdom/background/TableRowColumnSwitch.java | 27 ++++ .../jdomtable/src/main/resources/.gitignore | 4 + .../jdomtable/src/main/resources/log4j2.xml | 21 +++ .../src/main/resources}/persons.xml | 0 .../persons.xml.highlight.expected.html | 19 +++ .../persons.xml.switch.expected.html | 15 +++ .../JdomTable/jdomtable_solution/.gitignore | 4 + .../JdomTable/jdomtable_solution/build.sh | 45 +++++++ .../JdomTable/jdomtable_solution/pom.xml | 112 ++++++++++++++++ .../sda1/jdom/background/RowHighlighting.java | 72 ++++++++++ .../background/TableRowColumnSwitch.java} | 32 +---- .../src/main/resources/.gitignore | 2 + .../src/main/resources/log4j2.xml | 21 +++ .../src/main/resources}/persons.xml | 0 .../domhtml/test/TestRowHighlighting.java | 73 ++++++++++ .../test/TestTableRowColumnSwitch.java | 57 ++++++++ .../de/mi/exam/test/dom/DomFilterTest.java | 71 ++++++++++ .../de/hdm_stuttgart/mi/exam/DomFilter.java | 19 +++ 36 files changed, 946 insertions(+), 457 deletions(-) delete mode 100644 Sda1/Etest/JdomTable/Exercise/.gitignore delete mode 100644 Sda1/Etest/JdomTable/Exercise/pom.xml delete mode 100644 Sda1/Etest/JdomTable/Exercise/src/de/hdm_stuttgart/mi/sda1/jdom/common/MySaxErrorHandler.java delete mode 100644 Sda1/Etest/JdomTable/Exercise/src/de/hdm_stuttgart/mi/sda1/jdom/common/package-info.java delete mode 100644 Sda1/Etest/JdomTable/Exercise/src/de/hdm_stuttgart/mi/sda1/jdom/table/Driver.java delete mode 100644 Sda1/Etest/JdomTable/Exercise/src/de/hdm_stuttgart/mi/sda1/jdom/table/TablePresentation.java delete mode 100644 Sda1/Etest/JdomTable/Solution/.gitignore delete mode 100644 Sda1/Etest/JdomTable/Solution/pom.xml delete mode 100644 Sda1/Etest/JdomTable/Solution/src/de/hdm_stuttgart/mi/sda1/jdom/background/Driver.java delete mode 100644 Sda1/Etest/JdomTable/Solution/src/de/hdm_stuttgart/mi/sda1/jdom/background/TablePresentation.java delete mode 100644 Sda1/Etest/JdomTable/Solution/src/de/hdm_stuttgart/mi/sda1/jdom/common/MySaxErrorHandler.java delete mode 100644 Sda1/Etest/JdomTable/Solution/src/de/hdm_stuttgart/mi/sda1/jdom/common/package-info.java delete mode 100644 Sda1/Etest/JdomTable/Solution/src/de/hdm_stuttgart/mi/sda1/usercolumns/Driver.java create mode 100644 Sda1/Etest/JdomTable/exercise.xhtml create mode 100644 Sda1/Etest/JdomTable/jdomtable/.gitignore create mode 100644 Sda1/Etest/JdomTable/jdomtable/pom.exam.xml create mode 100644 Sda1/Etest/JdomTable/jdomtable/pom.xml create mode 100644 Sda1/Etest/JdomTable/jdomtable/src/main/java/de/hdm_stuttgart/mi/sda1/jdom/background/RowHighlighting.java create mode 100644 Sda1/Etest/JdomTable/jdomtable/src/main/java/de/hdm_stuttgart/mi/sda1/jdom/background/TableRowColumnSwitch.java create mode 100644 Sda1/Etest/JdomTable/jdomtable/src/main/resources/.gitignore create mode 100644 Sda1/Etest/JdomTable/jdomtable/src/main/resources/log4j2.xml rename Sda1/Etest/JdomTable/{Exercise => jdomtable/src/main/resources}/persons.xml (100%) create mode 100644 Sda1/Etest/JdomTable/jdomtable/src/main/resources/persons.xml.highlight.expected.html create mode 100644 Sda1/Etest/JdomTable/jdomtable/src/main/resources/persons.xml.switch.expected.html create mode 100644 Sda1/Etest/JdomTable/jdomtable_solution/.gitignore create mode 100644 Sda1/Etest/JdomTable/jdomtable_solution/build.sh create mode 100644 Sda1/Etest/JdomTable/jdomtable_solution/pom.xml create mode 100644 Sda1/Etest/JdomTable/jdomtable_solution/src/main/java/de/hdm_stuttgart/mi/sda1/jdom/background/RowHighlighting.java rename Sda1/Etest/JdomTable/{Solution/src/de/hdm_stuttgart/mi/sda1/usercolumns/TablePresentation.java => jdomtable_solution/src/main/java/de/hdm_stuttgart/mi/sda1/jdom/background/TableRowColumnSwitch.java} (62%) create mode 100644 Sda1/Etest/JdomTable/jdomtable_solution/src/main/resources/.gitignore create mode 100644 Sda1/Etest/JdomTable/jdomtable_solution/src/main/resources/log4j2.xml rename Sda1/Etest/JdomTable/{Solution => jdomtable_solution/src/main/resources}/persons.xml (100%) create mode 100644 Sda1/Etest/JdomTable/jdomtable_solution/src/test/java/de/hdm_stuttgart/sda1/domhtml/test/TestRowHighlighting.java create mode 100644 Sda1/Etest/JdomTable/jdomtable_solution/src/test/java/de/hdm_stuttgart/sda1/domhtml/test/TestTableRowColumnSwitch.java create mode 100644 ws/eclipse/ExamTesting/src/main/java/de/hdm_stuttgart/de/mi/exam/test/dom/DomFilterTest.java create mode 100644 ws/eclipse/ExamTesting/src/main/java/de/hdm_stuttgart/mi/exam/DomFilter.java diff --git a/Sda1/Etest/JdomTable/Exercise/.gitignore b/Sda1/Etest/JdomTable/Exercise/.gitignore deleted file mode 100644 index f7619e395..000000000 --- a/Sda1/Etest/JdomTable/Exercise/.gitignore +++ /dev/null @@ -1,5 +0,0 @@ -/bin -/target -/.settings -/.classpath -/.project diff --git a/Sda1/Etest/JdomTable/Exercise/pom.xml b/Sda1/Etest/JdomTable/Exercise/pom.xml deleted file mode 100644 index 719c77907..000000000 --- a/Sda1/Etest/JdomTable/Exercise/pom.xml +++ /dev/null @@ -1,38 +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.jdom</groupId> - <artifactId>addressbook</artifactId> - <version>1.0</version> - <build> - <sourceDirectory>src</sourceDirectory> - <plugins> - <plugin> - <artifactId>maven-compiler-plugin</artifactId> - <version>3.1</version> - <configuration> - <source>1.7</source> - <target>1.7</target> - </configuration> - </plugin> - </plugins> - </build> - <dependencies> - <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>junit</groupId> - <artifactId>junit</artifactId> - <version>4.11</version> - <scope>test</scope> - </dependency> - </dependencies> -</project> diff --git a/Sda1/Etest/JdomTable/Exercise/src/de/hdm_stuttgart/mi/sda1/jdom/common/MySaxErrorHandler.java b/Sda1/Etest/JdomTable/Exercise/src/de/hdm_stuttgart/mi/sda1/jdom/common/MySaxErrorHandler.java deleted file mode 100644 index bba459418..000000000 --- a/Sda1/Etest/JdomTable/Exercise/src/de/hdm_stuttgart/mi/sda1/jdom/common/MySaxErrorHandler.java +++ /dev/null @@ -1,44 +0,0 @@ -package de.hdm_stuttgart.mi.sda1.jdom.common; - -import java.io.PrintStream; - -import org.xml.sax.ErrorHandler; -import org.xml.sax.SAXException; -import org.xml.sax.SAXParseException; - -/** - * Simple error handling for SAX Events. - * - */ -public class MySaxErrorHandler implements ErrorHandler { - - private PrintStream out; //The error handler's output goes here - - private String getParseExceptionInfo //Returns a string describing - (SAXParseException ex) { //parse exception details. - return "Error '" + ex.getMessage() + "' at line " + - ex.getLineNumber() + ", column " + - ex.getColumnNumber(); - } - - /** - * Error and warning messages may be written to selected output channels. - * - * @param out The desired output channel. - */ - public MySaxErrorHandler(final PrintStream out) { - this.out = out; - } - @Override - public void warning(SAXParseException exception) throws SAXException { - out.print("Warning:" + getParseExceptionInfo(exception)); - } - @Override - public void error(SAXParseException exception) throws SAXException { - out.print("Error:" + getParseExceptionInfo(exception)); - } - @Override - public void fatalError(SAXParseException exception) throws SAXException { - out.print("Fatal error:" + getParseExceptionInfo(exception)); - } -} \ No newline at end of file diff --git a/Sda1/Etest/JdomTable/Exercise/src/de/hdm_stuttgart/mi/sda1/jdom/common/package-info.java b/Sda1/Etest/JdomTable/Exercise/src/de/hdm_stuttgart/mi/sda1/jdom/common/package-info.java deleted file mode 100644 index 2535e4e4f..000000000 --- a/Sda1/Etest/JdomTable/Exercise/src/de/hdm_stuttgart/mi/sda1/jdom/common/package-info.java +++ /dev/null @@ -1,4 +0,0 @@ -/** - * common project resources like SAX error handler. - */ -package de.hdm_stuttgart.mi.sda1.jdom.common; \ No newline at end of file diff --git a/Sda1/Etest/JdomTable/Exercise/src/de/hdm_stuttgart/mi/sda1/jdom/table/Driver.java b/Sda1/Etest/JdomTable/Exercise/src/de/hdm_stuttgart/mi/sda1/jdom/table/Driver.java deleted file mode 100644 index 364fded52..000000000 --- a/Sda1/Etest/JdomTable/Exercise/src/de/hdm_stuttgart/mi/sda1/jdom/table/Driver.java +++ /dev/null @@ -1,23 +0,0 @@ -package de.hdm_stuttgart.mi.sda1.jdom.table; - -import java.io.IOException; - -import org.jdom2.JDOMException; - -/** - * Printing address book data. - * - */ -public class Driver { - - /** - * @param args unused - * @throws JDOMException Internal errors. - * @throws IOException IO related errors. - */ - public static void main(String[] args) throws JDOMException, IOException { - final TablePresentation ao = new TablePresentation(); - - ao.process("persons.xml"); - } -} \ No newline at end of file diff --git a/Sda1/Etest/JdomTable/Exercise/src/de/hdm_stuttgart/mi/sda1/jdom/table/TablePresentation.java b/Sda1/Etest/JdomTable/Exercise/src/de/hdm_stuttgart/mi/sda1/jdom/table/TablePresentation.java deleted file mode 100644 index 0baea84d2..000000000 --- a/Sda1/Etest/JdomTable/Exercise/src/de/hdm_stuttgart/mi/sda1/jdom/table/TablePresentation.java +++ /dev/null @@ -1,84 +0,0 @@ -package de.hdm_stuttgart.mi.sda1.jdom.table; - -import java.io.IOException; -import java.util.List; - -import org.jdom2.Document; -import org.jdom2.Element; -import org.jdom2.JDOMException; -import org.jdom2.input.SAXBuilder; -import org.jdom2.output.Format; -import org.jdom2.output.XMLOutputter; -import org.jdom2.xpath.XPathExpression; -import org.jdom2.xpath.XPathFactory; - -import de.hdm_stuttgart.mi.sda1.jdom.common.MySaxErrorHandler; - -/** - * Handling address book data. - * - */ -public class TablePresentation { - private final SAXBuilder builder = new SAXBuilder(); - - /** - * Write errors and warnings to {@link System#err}. - */ - public TablePresentation() { - builder.setErrorHandler(new MySaxErrorHandler(System.err)); - } - - /** - * Read XML file data and create corresponding HTML output. - * - * @param xmlFilename The XML input file containing address book data. - * @throws JDOMException Internal error. - * @throws IOException IO related errors. - */ - public void process(final String xmlFilename) throws JDOMException, - IOException { - - // Create html <table> skeleton: - // <table> - // <tr> - // <th>Name</th> - // <th>Birthday</th> - // </tr> - // </table> - final Element table = new Element("table"), - trHead = new Element("tr"); - table.addContent(trHead); - trHead.addContent(new Element("th").addContent("Name")); - trHead.addContent(new Element("th").addContent("Birthday")); - - // Read address book from XML input file - final Document addressbook = builder.build(xmlFilename); - // Search for <person> elements - @SuppressWarnings({ "unchecked", "rawtypes" }) - final XPathExpression<Element> xpath = (XPathExpression<Element>) (XPathExpression) XPathFactory - .instance().compile("/addressbook/person"); - final List<Element> persons = xpath.evaluate(addressbook); - - // Now append a <tr> for each <person> input element: - // <table> - // ... table's column head entries, see above - // <tr> - // <td>Scott Geoffrey</td> - // <td>1942-07-22</td> - // </tr> - // <tr>...</tr> ... - // </table> - - for (final Element person : persons) { - final Element tr = new Element("tr"); - table.addContent(tr); - tr.addContent(new Element("td").addContent(person.getChild("name").getText())); - tr.addContent(new Element("td").addContent(person.getChild("birthday").getText())); - } - - // Serialize the <html> tree to standard output. - final Format outFormat = Format.getPrettyFormat(); - final XMLOutputter printer = new XMLOutputter(outFormat); - printer.output(table, System.out); - } -} \ No newline at end of file diff --git a/Sda1/Etest/JdomTable/Solution/.gitignore b/Sda1/Etest/JdomTable/Solution/.gitignore deleted file mode 100644 index f7619e395..000000000 --- a/Sda1/Etest/JdomTable/Solution/.gitignore +++ /dev/null @@ -1,5 +0,0 @@ -/bin -/target -/.settings -/.classpath -/.project diff --git a/Sda1/Etest/JdomTable/Solution/pom.xml b/Sda1/Etest/JdomTable/Solution/pom.xml deleted file mode 100644 index eaa7b4e9f..000000000 --- a/Sda1/Etest/JdomTable/Solution/pom.xml +++ /dev/null @@ -1,38 +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.jdom</groupId> - <artifactId>addressbook_solution</artifactId> - <version>1.0</version> - <build> - <sourceDirectory>src</sourceDirectory> - <plugins> - <plugin> - <artifactId>maven-compiler-plugin</artifactId> - <version>3.1</version> - <configuration> - <source>1.7</source> - <target>1.7</target> - </configuration> - </plugin> - </plugins> - </build> - <dependencies> - <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>junit</groupId> - <artifactId>junit</artifactId> - <version>4.11</version> - <scope>test</scope> - </dependency> - </dependencies> -</project> diff --git a/Sda1/Etest/JdomTable/Solution/src/de/hdm_stuttgart/mi/sda1/jdom/background/Driver.java b/Sda1/Etest/JdomTable/Solution/src/de/hdm_stuttgart/mi/sda1/jdom/background/Driver.java deleted file mode 100644 index e207e0bc6..000000000 --- a/Sda1/Etest/JdomTable/Solution/src/de/hdm_stuttgart/mi/sda1/jdom/background/Driver.java +++ /dev/null @@ -1,27 +0,0 @@ -package de.hdm_stuttgart.mi.sda1.jdom.background; - -import java.io.IOException; - -import org.jdom2.JDOMException; - - -/** - * Handling personal data. - * - */ -public class Driver { - - /** - * Reading from data from persons.xml and - * processing them by a {@link TablePresentation} instance. - * - * @param args unused - * @throws IOException IO related problems. - * @throws JDOMException internal error. - */ - public static void main(String[] args) throws JDOMException, IOException { - final TablePresentation ao = new TablePresentation(); - - ao.process("persons.xml"); - } -} \ No newline at end of file diff --git a/Sda1/Etest/JdomTable/Solution/src/de/hdm_stuttgart/mi/sda1/jdom/background/TablePresentation.java b/Sda1/Etest/JdomTable/Solution/src/de/hdm_stuttgart/mi/sda1/jdom/background/TablePresentation.java deleted file mode 100644 index 0c7f0b1b6..000000000 --- a/Sda1/Etest/JdomTable/Solution/src/de/hdm_stuttgart/mi/sda1/jdom/background/TablePresentation.java +++ /dev/null @@ -1,90 +0,0 @@ -package de.hdm_stuttgart.mi.sda1.jdom.background; - -import java.io.IOException; -import java.util.List; - -import org.jdom2.Document; -import org.jdom2.Element; -import org.jdom2.JDOMException; -import org.jdom2.input.SAXBuilder; -import org.jdom2.output.Format; -import org.jdom2.output.XMLOutputter; -import org.jdom2.xpath.XPathExpression; -import org.jdom2.xpath.XPathFactory; - -import de.hdm_stuttgart.mi.sda1.jdom.common.MySaxErrorHandler; - - -/** - * Handling address book data. - * - */ -public class TablePresentation { - private final SAXBuilder builder = new SAXBuilder(); - - /** - * Write errors and warnings to {@link System#err}. - */ - public TablePresentation() { - builder.setErrorHandler(new MySaxErrorHandler(System.err)); - } - - /** - * Read XML file data and create corresponding HTML output. - * - * @param xmlFilename The XML input file containing address book data. - * @throws JDOMException Internal error. - * @throws IOException IO related errors. - */ - public void process(final String xmlFilename) throws JDOMException, - IOException { - - // Create html <table> skeleton: - // <table> - // <tr> - // <th>Name</th> - // <th>Birthday</th> - // </tr> - // </table> - final Element table = new Element("table"), - trHead = new Element("tr"); - table.addContent(trHead); - trHead.addContent(new Element("th").addContent("Name")); - trHead.addContent(new Element("th").addContent("Birthday")); - - // Read address book from XML input file - final Document addressbook = builder.build(xmlFilename); - // Search for <person> elements - @SuppressWarnings({ "unchecked", "rawtypes" }) - final XPathExpression<Element> xpath = (XPathExpression<Element>) (XPathExpression) XPathFactory - .instance().compile("/addressbook/person"); - final List<Element> persons = xpath.evaluate(addressbook); - - // Now append a <tr> for each <person> input element: - // <table> - // ... table's column head entries, see above - // <tr> - // <td>Scott Geoffrey</td> - // <td>1942-07-22</td> - // </tr> - // <tr>...</tr> ... - // </table> - boolean setBackground = true; // keep track of table row background state. - - for (final Element person : persons) { - final Element tr = new Element("tr"); - if (setBackground) { - tr.setAttribute("style", "background-color: #FFFF88;"); - } - setBackground = !setBackground; - table.addContent(tr); - tr.addContent(new Element("td").addContent(person.getChild("name").getText())); - tr.addContent(new Element("td").addContent(person.getChild("birthday").getText())); - } - - // Serialize the <html> tree to standard output. - final Format outFormat = Format.getPrettyFormat(); - final XMLOutputter printer = new XMLOutputter(outFormat); - printer.output(table, System.out); - } -} \ No newline at end of file diff --git a/Sda1/Etest/JdomTable/Solution/src/de/hdm_stuttgart/mi/sda1/jdom/common/MySaxErrorHandler.java b/Sda1/Etest/JdomTable/Solution/src/de/hdm_stuttgart/mi/sda1/jdom/common/MySaxErrorHandler.java deleted file mode 100644 index bba459418..000000000 --- a/Sda1/Etest/JdomTable/Solution/src/de/hdm_stuttgart/mi/sda1/jdom/common/MySaxErrorHandler.java +++ /dev/null @@ -1,44 +0,0 @@ -package de.hdm_stuttgart.mi.sda1.jdom.common; - -import java.io.PrintStream; - -import org.xml.sax.ErrorHandler; -import org.xml.sax.SAXException; -import org.xml.sax.SAXParseException; - -/** - * Simple error handling for SAX Events. - * - */ -public class MySaxErrorHandler implements ErrorHandler { - - private PrintStream out; //The error handler's output goes here - - private String getParseExceptionInfo //Returns a string describing - (SAXParseException ex) { //parse exception details. - return "Error '" + ex.getMessage() + "' at line " + - ex.getLineNumber() + ", column " + - ex.getColumnNumber(); - } - - /** - * Error and warning messages may be written to selected output channels. - * - * @param out The desired output channel. - */ - public MySaxErrorHandler(final PrintStream out) { - this.out = out; - } - @Override - public void warning(SAXParseException exception) throws SAXException { - out.print("Warning:" + getParseExceptionInfo(exception)); - } - @Override - public void error(SAXParseException exception) throws SAXException { - out.print("Error:" + getParseExceptionInfo(exception)); - } - @Override - public void fatalError(SAXParseException exception) throws SAXException { - out.print("Fatal error:" + getParseExceptionInfo(exception)); - } -} \ No newline at end of file diff --git a/Sda1/Etest/JdomTable/Solution/src/de/hdm_stuttgart/mi/sda1/jdom/common/package-info.java b/Sda1/Etest/JdomTable/Solution/src/de/hdm_stuttgart/mi/sda1/jdom/common/package-info.java deleted file mode 100644 index 02848788e..000000000 --- a/Sda1/Etest/JdomTable/Solution/src/de/hdm_stuttgart/mi/sda1/jdom/common/package-info.java +++ /dev/null @@ -1,5 +0,0 @@ -/** - * common project resources like SAX error handler. - */ - -package de.hdm_stuttgart.mi.sda1.jdom.common; \ No newline at end of file diff --git a/Sda1/Etest/JdomTable/Solution/src/de/hdm_stuttgart/mi/sda1/usercolumns/Driver.java b/Sda1/Etest/JdomTable/Solution/src/de/hdm_stuttgart/mi/sda1/usercolumns/Driver.java deleted file mode 100644 index 70fd4315b..000000000 --- a/Sda1/Etest/JdomTable/Solution/src/de/hdm_stuttgart/mi/sda1/usercolumns/Driver.java +++ /dev/null @@ -1,25 +0,0 @@ -package de.hdm_stuttgart.mi.sda1.usercolumns; - -import java.io.IOException; - -import org.jdom2.JDOMException; - -/** - * Handling personal data. - * - */ -public class Driver { - - /** - * Reading from data from persons.xml and - * processing them by a {@link TablePresentation} instance. - * - * @param args unused - * @throws IOException IO related problems. - * @throws JDOMException internal error. - */ - public static void main(String[] args) throws JDOMException, IOException { - final TablePresentation ao = new TablePresentation(); - ao.process("persons.xml"); - } -} \ No newline at end of file diff --git a/Sda1/Etest/JdomTable/exercise.xhtml b/Sda1/Etest/JdomTable/exercise.xhtml new file mode 100644 index 000000000..60051dd73 --- /dev/null +++ b/Sda1/Etest/JdomTable/exercise.xhtml @@ -0,0 +1,125 @@ +<?xml version="1.0" encoding="UTF-8"?> +<!DOCTYPE html> +<html xmlns="http://www.w3.org/1999/xhtml"> + <head> + <title></title> + </head> + + <body><h1>Part 1 of 2</h1><h2>Objective</h2><p>Implementing a DOM based + applications transforming address book data into a HTML table + structure.</p><h2>Preparations / Description</h2>Start Eclipse Luna. + Download and unzip the archive file <a + href="goto.php?target=file_2895_download&client_id=iliasclient1" + target="_blank"><span>jdomtable.</span>zip</a>. Then import the resulting + sub folder <strong>jdomtable</strong> as a Maven project into eclipse. This + project contains:<ol> + <li><p>An address book example file <code>persons.xml</code>:</p><pre><addressbook> + <person> + <name>Scott Geoffrey</name> + <birthday>1942-07-22</birthday> + </person> + <person> + ... +</addressbook></pre></li> + + <li><p>A yet not functional class + <code>de.hdm_stuttgart.mi.sda1.jdom.background.RowHighlighting</code> + transforming a given Jdom input tree into an output tree:</p><pre>public class RowHighlighting implements DomFilter { + + /** explanations omitted here for brevity */ + + public Document process(Document addressbook) { + // TODO: complete my implementation! + return new Document(new Element("table")); + }</pre></li> + + <li>A Junit test class + <code>de.hdm_stuttgart.sda1.domhtml.test.TestRowHighlighting</code> + which uses an instance of <code>RowHighlighting</code> to transform + <code>persons.xml</code> into a html <code><table></code> by + executing the <code>process(Document addressbook)</code> method . Due to + the unfinished implementation when running as a Junit Test the only + output so far is just <code><table></table></code>.</li> + + <li><p>File + <code>src/main/resources/persons.xml.highlight.expected.html</code> + contains the expected output to be generated from + <code>persons.xml</code>:</p><table border="1"> + <tr> + <td><pre><table> + <tr> + <th>Name</th> + <th>Birthday</th> + </tr> + <tr style="background-color: #FFFF88;"> + <td>Scott Geoffrey</td> + <td>1942-07-22</td> + </tr> + <tr> + <td>Julia Duncan</td> + <td>2001-11-07</td> + </tr> + <tr style="background-color: #FFFF88;"> + <td>Jim Smith</td> + <td>1981-04-13</td> + </tr> +</table></pre></td> + + <td><img height="295" + src="data/iliasclient1/mobs/mm_5429/table1.png" + width="490" /></td> + </tr> + </table></li> + </ol><h2>ToDo</h2><p>Complete the implementation of class + <code>RowHighlighting</code>. The supplied Junit test will guide you towards + perfection. Don't bother about the missing <html>...</html> + skeleton. Web browsers will handle this anyway.</p><p>On completion export + your Maven project as a compressed .zip archive (.tar.gz export format may + not work!) and upload it.</p><p>Hints: <span>The Jdom API at </span><a + href="http://www.jdom.org/docs/apidocs">http://www.jdom.org/docs/apidocs</a><span> may + be helpful.</span></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><h1>Part 2 of 2</h1><p>This + second task is part of the same Maven Project except:</p><ol> + <li><p>Your department manager asks you to exchange rows and columns to + appear as in file + <code>persons.xml.switch.expected.html</code>:</p><table border="1"> + <tr> + <td><pre><table> + <tr> + <th>Name</th> + <td>Scott Geoffrey</td> + <td>Julia Duncan</td> + <td>Jim Smith</td> + </tr> + <tr> + <th>Birthday</th> + <td>1942-07-22</td> + <td>2001-11-07</td> + <td>1981-04-13</td> + </tr> +</table></pre></td> + + <td><img height="295" + src="data/iliasclient1/mobs/mm_5430/table2.png" + width="490" /></td> + </tr> + </table></li> + + <li><p>Another yet not functional class + <code>de.hdm_stuttgart.mi.sda1.jdom.background.TableRowColumnSwitch</code> + transforming a given Jdom input tree into an output tree.</p></li> + + <li>A Junit test class + <code>de.hdm_stuttgart.sda1.domhtml.test.TestTableRowColumnSwitch</code> + which uses an instance of <code>TableRowColumnSwitch</code> to transform + <code>persons.xml</code> into a html <code><table></code>. Due to + the unfinished implementation when running as Junit Test the only output + so far is just <code><table></table></code>.</li> + </ol><h2>ToDo</h2><p>Complete the implementation of class + <code>TableRowColumnSwitch using t</code>he supplied Junit test.</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></body> +</html> diff --git a/Sda1/Etest/JdomTable/jdomtable/.gitignore b/Sda1/Etest/JdomTable/jdomtable/.gitignore new file mode 100644 index 000000000..a1c3ab4d0 --- /dev/null +++ b/Sda1/Etest/JdomTable/jdomtable/.gitignore @@ -0,0 +1,4 @@ +/target/ +/.settings/ +.classpath +.project diff --git a/Sda1/Etest/JdomTable/jdomtable/pom.exam.xml b/Sda1/Etest/JdomTable/jdomtable/pom.exam.xml new file mode 100644 index 000000000..71c9ef662 --- /dev/null +++ b/Sda1/Etest/JdomTable/jdomtable/pom.exam.xml @@ -0,0 +1,106 @@ +<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"> + + <description>Test execution requires 'mvn install' in the maven sub project + 'GoikLectures/ws/eclipse/ExamTesting' within + https://version.mi.hdm-stuttgart.de/git/GoikLectures + to resolve the 'examtesting' dependency.</description> + + <modelVersion>4.0.0</modelVersion> + + <groupId>de.hdm_stuttgart.mi.sda1.exam</groupId> + <artifactId>jdomtable</artifactId> + <version>1.0</version> + + <packaging>jar</packaging> + + <name>jdomtable</name> + + <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/JdomTable/jdomtable/pom.xml b/Sda1/Etest/JdomTable/jdomtable/pom.xml new file mode 100644 index 000000000..d4186ab38 --- /dev/null +++ b/Sda1/Etest/JdomTable/jdomtable/pom.xml @@ -0,0 +1,112 @@ +<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"> + + <description>Test execution requires 'mvn install' in the maven sub project + 'GoikLectures/ws/eclipse/ExamTesting' within + https://version.mi.hdm-stuttgart.de/git/GoikLectures + to resolve the 'examtesting' dependency.</description> + + <modelVersion>4.0.0</modelVersion> + + <groupId>de.hdm_stuttgart.mi.sda1.exam</groupId> + <artifactId>jdomtable</artifactId> + <version>1.0</version> + + <packaging>jar</packaging> + + <name>jdomtable</name> + + <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/JdomTable/jdomtable/src/main/java/de/hdm_stuttgart/mi/sda1/jdom/background/RowHighlighting.java b/Sda1/Etest/JdomTable/jdomtable/src/main/java/de/hdm_stuttgart/mi/sda1/jdom/background/RowHighlighting.java new file mode 100644 index 000000000..d0515e2c4 --- /dev/null +++ b/Sda1/Etest/JdomTable/jdomtable/src/main/java/de/hdm_stuttgart/mi/sda1/jdom/background/RowHighlighting.java @@ -0,0 +1,30 @@ +package de.hdm_stuttgart.mi.sda1.jdom.background; + +import java.io.IOException; + +import org.jdom2.Document; +import org.jdom2.Element; +import org.jdom2.JDOMException; + +import de.hdm_stuttgart.mi.exam.DomFilter; + + +/** + * Handling address book data. + * + */ +public class RowHighlighting implements DomFilter { + + /** + * Read XML file data and create corresponding HTML output. + * + * @param xmlFilename The XML input file containing address book data. + * @throws JDOMException Internal error. + * @throws IOException IO related errors. + */ + @Override + public Document process(Document addressbook) { + // TODO: complete my implementation! + return new Document(new Element("table")); + } +} \ No newline at end of file diff --git a/Sda1/Etest/JdomTable/jdomtable/src/main/java/de/hdm_stuttgart/mi/sda1/jdom/background/TableRowColumnSwitch.java b/Sda1/Etest/JdomTable/jdomtable/src/main/java/de/hdm_stuttgart/mi/sda1/jdom/background/TableRowColumnSwitch.java new file mode 100644 index 000000000..caaddfd5f --- /dev/null +++ b/Sda1/Etest/JdomTable/jdomtable/src/main/java/de/hdm_stuttgart/mi/sda1/jdom/background/TableRowColumnSwitch.java @@ -0,0 +1,27 @@ +package de.hdm_stuttgart.mi.sda1.jdom.background; + +import java.io.IOException; + +import org.jdom2.Document; +import org.jdom2.Element; +import org.jdom2.JDOMException; + +import de.hdm_stuttgart.mi.exam.DomFilter; + +/** + * Address book data. + * + */ +public class TableRowColumnSwitch implements DomFilter { + /** + * Reading XML input an create corresponding HTML output + * @param xmlFilename XML file input data + * @throws JDOMException Internal errors + * @throws IOException IO related errors. + */ + @Override + public Document process(Document addressbook) { + // TODO: complete my implementation! + return new Document(new Element("table")); + } +} \ No newline at end of file diff --git a/Sda1/Etest/JdomTable/jdomtable/src/main/resources/.gitignore b/Sda1/Etest/JdomTable/jdomtable/src/main/resources/.gitignore new file mode 100644 index 000000000..23fdc6278 --- /dev/null +++ b/Sda1/Etest/JdomTable/jdomtable/src/main/resources/.gitignore @@ -0,0 +1,4 @@ +/memo.xml.1.html +/memo.xml.2.html +/persons.xml.highlight.html +/persons.xml.switch.html diff --git a/Sda1/Etest/JdomTable/jdomtable/src/main/resources/log4j2.xml b/Sda1/Etest/JdomTable/jdomtable/src/main/resources/log4j2.xml new file mode 100644 index 000000000..ffeb6ae18 --- /dev/null +++ b/Sda1/Etest/JdomTable/jdomtable/src/main/resources/log4j2.xml @@ -0,0 +1,21 @@ +<?xml version="1.0" encoding="UTF-8"?> +<Configuration> + <Appenders> + <File name="A1" fileName="A1.log" append="false"> + <PatternLayout pattern="%t %-5p %c{2} - %m%n"/> + </File> + <Console name="STDOUT" target="SYSTEM_OUT"> + <PatternLayout pattern="%C{2} (%F:%L) - %m%n"/> + </Console> + </Appenders> + <Loggers> + + <!-- You my want to define class or package level per-logger rules --> + <Logger name="de.hdm_stuttgart.de.saxstandard.App" level="debug"> + <AppenderRef ref="A1"/> + </Logger> + <Root level="debug"> + <AppenderRef ref="STDOUT"/> + </Root> + </Loggers> +</Configuration> \ No newline at end of file diff --git a/Sda1/Etest/JdomTable/Exercise/persons.xml b/Sda1/Etest/JdomTable/jdomtable/src/main/resources/persons.xml similarity index 100% rename from Sda1/Etest/JdomTable/Exercise/persons.xml rename to Sda1/Etest/JdomTable/jdomtable/src/main/resources/persons.xml diff --git a/Sda1/Etest/JdomTable/jdomtable/src/main/resources/persons.xml.highlight.expected.html b/Sda1/Etest/JdomTable/jdomtable/src/main/resources/persons.xml.highlight.expected.html new file mode 100644 index 000000000..1f1df3b6d --- /dev/null +++ b/Sda1/Etest/JdomTable/jdomtable/src/main/resources/persons.xml.highlight.expected.html @@ -0,0 +1,19 @@ +<?xml version="1.0" encoding="UTF-8"?> +<table> + <tr> + <th>Name</th> + <th>Birthday</th> + </tr> + <tr style="background-color: #FFFF88;"> + <td>Scott Geoffrey</td> + <td>1942-07-22</td> + </tr> + <tr> + <td>Julia Duncan</td> + <td>2001-11-07</td> + </tr> + <tr style="background-color: #FFFF88;"> + <td>Jim Smith</td> + <td>1981-04-13</td> + </tr> +</table> diff --git a/Sda1/Etest/JdomTable/jdomtable/src/main/resources/persons.xml.switch.expected.html b/Sda1/Etest/JdomTable/jdomtable/src/main/resources/persons.xml.switch.expected.html new file mode 100644 index 000000000..9fc846f07 --- /dev/null +++ b/Sda1/Etest/JdomTable/jdomtable/src/main/resources/persons.xml.switch.expected.html @@ -0,0 +1,15 @@ +<?xml version="1.0" encoding="UTF-8"?> +<table> + <tr> + <th>Name</th> + <td>Scott Geoffrey</td> + <td>Julia Duncan</td> + <td>Jim Smith</td> + </tr> + <tr> + <th>Birthday</th> + <td>1942-07-22</td> + <td>2001-11-07</td> + <td>1981-04-13</td> + </tr> +</table> diff --git a/Sda1/Etest/JdomTable/jdomtable_solution/.gitignore b/Sda1/Etest/JdomTable/jdomtable_solution/.gitignore new file mode 100644 index 000000000..a1c3ab4d0 --- /dev/null +++ b/Sda1/Etest/JdomTable/jdomtable_solution/.gitignore @@ -0,0 +1,4 @@ +/target/ +/.settings/ +.classpath +.project diff --git a/Sda1/Etest/JdomTable/jdomtable_solution/build.sh b/Sda1/Etest/JdomTable/jdomtable_solution/build.sh new file mode 100644 index 000000000..192b72f6e --- /dev/null +++ b/Sda1/Etest/JdomTable/jdomtable_solution/build.sh @@ -0,0 +1,45 @@ +#!/bin/bash + +# Execute from top of this directory +# + +export BASEDIRNAME=jdomtable +export EXTRADELETE="src/main/resources/persons.xml.highlight.html src/main/resources/persons.xml.switch.html" + +# +#No changes beyond this line +#################################################################### +# + +rm -rf /tmp/${BASEDIRNAME} +tar -c ${BASEDIRNAME} | tar -x -C /tmp +cp -f ${BASEDIRNAME}/pom.exam.xml /tmp/${BASEDIRNAME}/pom.xml + +pushd ${BASEDIRNAME}_solution/src/test/java +tar c- de|tar -x -C /tmp/${BASEDIRNAME}/src/test/java +popd +echo ${BASEDIRNAME}_solution/src/test/java + +pushd ../../../ws/eclipse/ExamTesting/src/main/java +tar c- de |tar -x -C /tmp/${BASEDIRNAME}/src/test/java +tar c- de |tar -x -C /tmp/${BASEDIRNAME}_solution/src/test/java +popd + +pushd /tmp/${BASEDIRNAME} +mvn clean eclipse:clean +rm -rf .settings pom.exam.xml .gitignore src/main/resources/.gitignore ${EXTRADELETE} +cd ..; rm -f ${BASEDIRNAME}.zip; zip -r ${BASEDIRNAME}.zip ${BASEDIRNAME} +popd + +tar c- ${BASEDIRNAME}_solution| tar -x -C /tmp + +pushd /tmp/${BASEDIRNAME}_solution +mvn clean eclipse:clean +rm -rf .settings .gitignore build.sh* src/main/resources/memo.xml.* src/main/resources/.gitignore +cd ..; rm -f ${BASEDIRNAME}_solution.zip; zip -r ${BASEDIRNAME}_solution.zip ${BASEDIRNAME}_solution +popd + + +echo Compressed Maven archives ${BASEDIRNAME}.zip and ${BASEDIRNAME}_solution.zip have been generated at /tmp + +#end diff --git a/Sda1/Etest/JdomTable/jdomtable_solution/pom.xml b/Sda1/Etest/JdomTable/jdomtable_solution/pom.xml new file mode 100644 index 000000000..84c5bb7ba --- /dev/null +++ b/Sda1/Etest/JdomTable/jdomtable_solution/pom.xml @@ -0,0 +1,112 @@ +<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"> + + <description>Test execution requires 'mvn install' in the maven sub project + 'GoikLectures/ws/eclipse/ExamTesting' within + https://version.mi.hdm-stuttgart.de/git/GoikLectures + to resolve the 'examtesting' dependency.</description> + + <modelVersion>4.0.0</modelVersion> + + <groupId>de.hdm_stuttgart.mi.sda1.exam</groupId> + <artifactId>jdomtable_solution</artifactId> + <version>1.0</version> + + <packaging>jar</packaging> + + <name>jdomtable_solution</name> + + <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/JdomTable/jdomtable_solution/src/main/java/de/hdm_stuttgart/mi/sda1/jdom/background/RowHighlighting.java b/Sda1/Etest/JdomTable/jdomtable_solution/src/main/java/de/hdm_stuttgart/mi/sda1/jdom/background/RowHighlighting.java new file mode 100644 index 000000000..a22f0d2d0 --- /dev/null +++ b/Sda1/Etest/JdomTable/jdomtable_solution/src/main/java/de/hdm_stuttgart/mi/sda1/jdom/background/RowHighlighting.java @@ -0,0 +1,72 @@ +package de.hdm_stuttgart.mi.sda1.jdom.background; + +import java.io.IOException; +import java.util.List; + +import org.jdom2.Document; +import org.jdom2.Element; +import org.jdom2.JDOMException; +import org.jdom2.xpath.XPathExpression; +import org.jdom2.xpath.XPathFactory; + +import de.hdm_stuttgart.mi.exam.DomFilter; + +/** + * Handling address book data. + * + */ +public class RowHighlighting implements DomFilter { + + /** + * Read XML file data and create corresponding HTML output. + * + * @param xmlFilename The XML input file containing address book data. + * @throws JDOMException Internal error. + * @throws IOException IO related errors. + */ + @Override + public Document process(Document addressbook) { + + // Create <table> skeleton: + // <table> + // <tr> + // <th>Name</th> + // <th>Birthday</th> + // </tr> + // </table> + + final Element table = new Element("table"), + trHead = new Element("tr"); + table.addContent(trHead); + trHead.addContent(new Element("th").addContent("Name")); + trHead.addContent(new Element("th").addContent("Birthday")); + + // Search address book for <person> elements + @SuppressWarnings({ "unchecked", "rawtypes" }) // Uuuuuugly!!! + final XPathExpression<Element> xpath = (XPathExpression<Element>) (XPathExpression) XPathFactory + .instance().compile("/addressbook/person"); + final List<Element> persons = xpath.evaluate(addressbook); + + // Now append a <tr> for each <person> input element: + // <table> + // ... table's column head entries, see above + // <tr> + // <td>Scott Geoffrey</td> + // <td>1942-07-22</td> + // </tr> + // <tr>...</tr> ... + // </table> + boolean setBackground = false; // keep track of table row background state. + + for (final Element person : persons) { + final Element tr = new Element("tr"); + if ((setBackground =! setBackground)) { + tr.setAttribute("style", "background-color: #FFFF88;"); + } + table.addContent(tr); + tr.addContent(new Element("td").addContent(person.getChild("name").getText())); + tr.addContent(new Element("td").addContent(person.getChild("birthday").getText())); + } + return new Document(table); + } +} \ No newline at end of file diff --git a/Sda1/Etest/JdomTable/Solution/src/de/hdm_stuttgart/mi/sda1/usercolumns/TablePresentation.java b/Sda1/Etest/JdomTable/jdomtable_solution/src/main/java/de/hdm_stuttgart/mi/sda1/jdom/background/TableRowColumnSwitch.java similarity index 62% rename from Sda1/Etest/JdomTable/Solution/src/de/hdm_stuttgart/mi/sda1/usercolumns/TablePresentation.java rename to Sda1/Etest/JdomTable/jdomtable_solution/src/main/java/de/hdm_stuttgart/mi/sda1/jdom/background/TableRowColumnSwitch.java index 50f63e717..bfd5751b3 100644 --- a/Sda1/Etest/JdomTable/Solution/src/de/hdm_stuttgart/mi/sda1/usercolumns/TablePresentation.java +++ b/Sda1/Etest/JdomTable/jdomtable_solution/src/main/java/de/hdm_stuttgart/mi/sda1/jdom/background/TableRowColumnSwitch.java @@ -1,4 +1,4 @@ -package de.hdm_stuttgart.mi.sda1.usercolumns; +package de.hdm_stuttgart.mi.sda1.jdom.background; import java.io.IOException; import java.util.List; @@ -6,40 +6,25 @@ import java.util.List; import org.jdom2.Document; import org.jdom2.Element; import org.jdom2.JDOMException; -import org.jdom2.input.SAXBuilder; -import org.jdom2.output.Format; -import org.jdom2.output.XMLOutputter; import org.jdom2.xpath.XPathExpression; import org.jdom2.xpath.XPathFactory; -import de.hdm_stuttgart.mi.sda1.jdom.common.MySaxErrorHandler; +import de.hdm_stuttgart.mi.exam.DomFilter; /** * Address book data. * */ -public class TablePresentation { - private final SAXBuilder builder = new SAXBuilder(); - - /** - * - */ - public TablePresentation() { - builder.setErrorHandler(new MySaxErrorHandler(System.err)); - } +public class TableRowColumnSwitch implements DomFilter { /** * Reading XML input an create corresponding HTML output * @param xmlFilename XML file input data * @throws JDOMException Internal errors * @throws IOException IO related errors. */ - public void process(final String xmlFilename) throws JDOMException, - IOException { - - // Read address book from XML input file - final Document addressbook = builder.build(xmlFilename); + @Override + public Document process(Document addressbook) { - // Create HTML <table/> final Element table = new Element("table"); // Search for <person> elements @@ -62,9 +47,6 @@ public class TablePresentation { nameRow.addContent(new Element("td").addContent(person.getChild("name").getText())); birthdayRow.addContent(new Element("td").addContent(person.getChild("birthday").getText())); } - // Serialize the <html> tree to standard output. - final Format outFormat = Format.getPrettyFormat(); - final XMLOutputter printer = new XMLOutputter(outFormat); - printer.output(table, System.out); - } + return new Document(table); + } } \ No newline at end of file diff --git a/Sda1/Etest/JdomTable/jdomtable_solution/src/main/resources/.gitignore b/Sda1/Etest/JdomTable/jdomtable_solution/src/main/resources/.gitignore new file mode 100644 index 000000000..472b549de --- /dev/null +++ b/Sda1/Etest/JdomTable/jdomtable_solution/src/main/resources/.gitignore @@ -0,0 +1,2 @@ +/memo.xml.1.html +/memo.xml.2.html diff --git a/Sda1/Etest/JdomTable/jdomtable_solution/src/main/resources/log4j2.xml b/Sda1/Etest/JdomTable/jdomtable_solution/src/main/resources/log4j2.xml new file mode 100644 index 000000000..ffeb6ae18 --- /dev/null +++ b/Sda1/Etest/JdomTable/jdomtable_solution/src/main/resources/log4j2.xml @@ -0,0 +1,21 @@ +<?xml version="1.0" encoding="UTF-8"?> +<Configuration> + <Appenders> + <File name="A1" fileName="A1.log" append="false"> + <PatternLayout pattern="%t %-5p %c{2} - %m%n"/> + </File> + <Console name="STDOUT" target="SYSTEM_OUT"> + <PatternLayout pattern="%C{2} (%F:%L) - %m%n"/> + </Console> + </Appenders> + <Loggers> + + <!-- You my want to define class or package level per-logger rules --> + <Logger name="de.hdm_stuttgart.de.saxstandard.App" level="debug"> + <AppenderRef ref="A1"/> + </Logger> + <Root level="debug"> + <AppenderRef ref="STDOUT"/> + </Root> + </Loggers> +</Configuration> \ No newline at end of file diff --git a/Sda1/Etest/JdomTable/Solution/persons.xml b/Sda1/Etest/JdomTable/jdomtable_solution/src/main/resources/persons.xml similarity index 100% rename from Sda1/Etest/JdomTable/Solution/persons.xml rename to Sda1/Etest/JdomTable/jdomtable_solution/src/main/resources/persons.xml diff --git a/Sda1/Etest/JdomTable/jdomtable_solution/src/test/java/de/hdm_stuttgart/sda1/domhtml/test/TestRowHighlighting.java b/Sda1/Etest/JdomTable/jdomtable_solution/src/test/java/de/hdm_stuttgart/sda1/domhtml/test/TestRowHighlighting.java new file mode 100644 index 000000000..0a6686bd5 --- /dev/null +++ b/Sda1/Etest/JdomTable/jdomtable_solution/src/test/java/de/hdm_stuttgart/sda1/domhtml/test/TestRowHighlighting.java @@ -0,0 +1,73 @@ +package de.hdm_stuttgart.sda1.domhtml.test; + +import org.junit.Test; + +import de.hdm_stuttgart.de.mi.exam.test.dom.DomFilterTest; +import de.hdm_stuttgart.de.mi.exam.test.sax.DomAssert; +import de.hdm_stuttgart.mi.sda1.jdom.background.RowHighlighting; + +/** + * Unit testing DOM HTML output + */ +@SuppressWarnings("javadoc") +public class TestRowHighlighting extends DomFilterTest { + + static { + init("src/main/resources/persons.xml", new RowHighlighting(), ".highlight.html"); + } + @Test public void testNumberOfColumnHeaders() { + DomAssert.assertNumberOfNodes( + "Two column headers expected", + xmlRootElement, + "tr", 4); + } + @Test public void testColumnHeader_Name() { + DomAssert.assertSingleNodeContent("Checking first <th>", + xmlRootElement, + "tr/th[1]", + "th", "Name"); + } + @Test public void testColumnHeader_Birthday() { + DomAssert.assertSingleNodeContent("Checking second <th>", + xmlRootElement, + "tr/th[2]", + "th", "Birthday"); + } + @Test public void testNumberOfHeaderRows() { + DomAssert.assertNumberOfNodes( + "1 <tr> element containing <th> expected", + xmlRootElement, + "tr[th]", 1); + } + @Test public void testNumberOfDataRows() { + DomAssert.assertNumberOfNodes( + "3 <tr> element containing <td> expected", + xmlRootElement, + "tr[td]", 3); + } + + @Test public void testNumberOfHighlightedRows() { + DomAssert.assertNumberOfNodes( + "2 <tr style='background-color: #FFFF88;> elements expected", + xmlRootElement, + "tr[@style='background-color: #FFFF88;']", 2); + } + @Test public void testRowWithoutHighlighing() { + DomAssert.assertNumberOfNodes( + "Middle data row shall not contain highlighting", + xmlRootElement, + "tr[not(@style) and position() = 3]", 1); + } + @Test public void testLastRecord_Name() { + DomAssert.assertSingleNodeContent("Last record must start with <td>Jim Smith</td>", + xmlRootElement, + "tr[last()]/td[1]", + "td", "Jim Smith"); + } + @Test public void testLastRecord_Date() { + DomAssert.assertSingleNodeContent("Last record must end with <td>1981-04-13</td>", + xmlRootElement, + "tr[last()]/td[2]", + "td", "1981-04-13"); + } +} \ No newline at end of file diff --git a/Sda1/Etest/JdomTable/jdomtable_solution/src/test/java/de/hdm_stuttgart/sda1/domhtml/test/TestTableRowColumnSwitch.java b/Sda1/Etest/JdomTable/jdomtable_solution/src/test/java/de/hdm_stuttgart/sda1/domhtml/test/TestTableRowColumnSwitch.java new file mode 100644 index 000000000..38991469a --- /dev/null +++ b/Sda1/Etest/JdomTable/jdomtable_solution/src/test/java/de/hdm_stuttgart/sda1/domhtml/test/TestTableRowColumnSwitch.java @@ -0,0 +1,57 @@ +package de.hdm_stuttgart.sda1.domhtml.test; + +import org.junit.Test; + +import de.hdm_stuttgart.de.mi.exam.test.dom.DomFilterTest; +import de.hdm_stuttgart.de.mi.exam.test.sax.DomAssert; +import de.hdm_stuttgart.mi.sda1.jdom.background.TableRowColumnSwitch; + +/** + * Unit testing dom HTML output + */ +@SuppressWarnings("javadoc") +public class TestTableRowColumnSwitch extends DomFilterTest { + + static { + init("src/main/resources/persons.xml", new TableRowColumnSwitch(), ".switch.html"); + } + @Test public void testNumberOfColumnHeaders() { + DomAssert.assertNumberOfNodes( + "Two <tr> expected", + xmlRootElement, + "tr", 2); + } + @Test public void testColumnHeader_Name() { + DomAssert.assertSingleNodeContent("Checking 'Name' <th>", + xmlRootElement, + "tr[1]/th", + "th", "Name"); + } + + @Test public void testColumnHeader_Birthday() { + DomAssert.assertSingleNodeContent("Checking 'Birthday' <th>", + xmlRootElement, + "tr[2]/th", + "th", "Birthday"); + } + + @Test public void testNumberOfTd() { + DomAssert.assertNumberOfNodes( + "6 <td> in two groups of 3 expected", + xmlRootElement, + "tr[1]/td[0 < position() and position() < 4]|tr[2]/td[0 < position() and position() < 4]", 6); + } + + @Test public void testNameFirstDataRecord() { + DomAssert.assertSingleNodeContent("Checking Name of first data record", + xmlRootElement, + "tr[1]/*[2]", + "td", "Scott Geoffrey"); + } + @Test public void testBirthdayLastDataRecord() { + DomAssert.assertSingleNodeContent("Checking birthday of last data record", + xmlRootElement, + "tr[2]/*[last()]", + "td", "1981-04-13"); + } +} \ No newline at end of file diff --git a/ws/eclipse/ExamTesting/src/main/java/de/hdm_stuttgart/de/mi/exam/test/dom/DomFilterTest.java b/ws/eclipse/ExamTesting/src/main/java/de/hdm_stuttgart/de/mi/exam/test/dom/DomFilterTest.java new file mode 100644 index 000000000..7add54f9d --- /dev/null +++ b/ws/eclipse/ExamTesting/src/main/java/de/hdm_stuttgart/de/mi/exam/test/dom/DomFilterTest.java @@ -0,0 +1,71 @@ +package de.hdm_stuttgart.de.mi.exam.test.dom; + +import java.io.FileNotFoundException; +import java.io.IOException; +import java.io.PrintStream; + +import org.jdom2.Document; +import org.jdom2.Element; +import org.jdom2.JDOMException; +import org.jdom2.input.SAXBuilder; +import org.jdom2.output.Format; +import org.jdom2.output.XMLOutputter; + +import de.hdm_stuttgart.mi.exam.DomFilter; + +public abstract class DomFilterTest { + + public static String xmlInputFileName, xmlOutputFileName; + static DomFilter domFilter; + protected static String initializationErrorString = null; + + protected static Element xmlRootElement = null; + + static protected void init (final String xmlInputFileName, + final DomFilter domFilter, + final String resultFileExtension) { + DomFilterTest.xmlInputFileName = xmlInputFileName; + DomFilterTest.xmlOutputFileName = xmlInputFileName + resultFileExtension; + DomFilterTest.domFilter = domFilter; + processAndParseResult(); + } + + static protected void processAndParseResult() { + + final SAXBuilder builder = new SAXBuilder(); + final Document input; + try { + input = builder.build(xmlInputFileName); + } catch (JDOMException | IOException e) { + initializationErrorString = "Error parsing input:" + e.getLocalizedMessage(); + return; + } + + final PrintStream out; + try { + out = new PrintStream(xmlOutputFileName); + } catch (FileNotFoundException e1) { + initializationErrorString = "Unable to open result file '" + xmlOutputFileName + + "' for writing"; + return; + } + + // Print to file + final Document result = domFilter.process(input); + xmlRootElement = result.getRootElement(); + final Format outFormat = Format.getPrettyFormat(); + final XMLOutputter printer = new XMLOutputter(outFormat); + try { + printer.output(result, out); + } catch (IOException e) { + initializationErrorString = "Error serializing result document to file '" + xmlOutputFileName + "': " + e.getLocalizedMessage(); + return; + } + // Print to standard out as well + try { + printer.output(result, System.out); + } catch (IOException e) { + initializationErrorString = "Error serializing result document to standard output: " + e.getLocalizedMessage(); + } + } +} diff --git a/ws/eclipse/ExamTesting/src/main/java/de/hdm_stuttgart/mi/exam/DomFilter.java b/ws/eclipse/ExamTesting/src/main/java/de/hdm_stuttgart/mi/exam/DomFilter.java new file mode 100644 index 000000000..c15ca35f4 --- /dev/null +++ b/ws/eclipse/ExamTesting/src/main/java/de/hdm_stuttgart/mi/exam/DomFilter.java @@ -0,0 +1,19 @@ +package de.hdm_stuttgart.mi.exam; + +import org.jdom2.Document; + +/** + * Transform a given Dom Tree + * + */ +public interface DomFilter { + + /** + * transform DOM input to output + * + * @param input Input DOM tree + * @return output DOM tree + */ + public Document process(final Document input); + +} -- GitLab