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 index 99ce8c38f800cbf58f0adb8b25e224bd291391cb..2178b2e43c074e7bdc8323eada550af5986a3658 100644 --- 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 @@ -3,6 +3,7 @@ package de.hdm_stuttgart.mi.sda1.saxhtml.v2; import java.io.PrintStream; import org.xml.sax.Attributes; +import org.xml.sax.ContentHandler; import org.xml.sax.Locator; import org.xml.sax.SAXException; import org.xml.sax.helpers.DefaultHandler; @@ -11,7 +12,7 @@ import org.xml.sax.helpers.DefaultHandler; * Turning <memo> documents to HTML * */ -public class Memo2HtmlHandler extends DefaultHandler { +public class Memo2HtmlHandler implements ContentHandler { private final PrintStream out; diff --git a/Sda1/Etest/SaxMemo2Html/exercise1.xhtml b/Sda1/Etest/SaxMemo2Html/exercise1.xhtml new file mode 100644 index 0000000000000000000000000000000000000000..176dbae8397089b406c2e1bc70cf309e623eb55a --- /dev/null +++ b/Sda1/Etest/SaxMemo2Html/exercise1.xhtml @@ -0,0 +1,110 @@ +<?xml version="1.0" encoding="UTF-8"?> +<!DOCTYPE html> +<html xmlns="http://www.w3.org/1999/xhtml"> + <head> + <title>Exercise 1</title> + </head> + + <body><h2>Objective</h2><p>Implementing a SAX based Java application + transforming memo documents to HTML.</p><h2>Preparations</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>Bsaxmemo2html</code>contains among + other files:</p><dl> + <dt>src/main/resources/memo.xml</dt> + + <dd>A sample memo input document.</dd> + + <dt>de.hdm_stuttgart.mi.sda1.saxhtml.v1.Memo2HtmlHandler</dt> + + <dd>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.</dd> + + <dt>de.hdm_stuttgart.mi.sda1.saxhtml.v1.Driver</dt> + + <dd>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.</dd> + + <dt>src/main/resources/memo.xml.1.sample.html</dt> + + <dd>The intended output corresponding to be generated from + <code>memo.xml</code> by <code>Memo2HtmlHandler</code>.</dd> + + <dt>de.hdm_stuttgart.de.sda1.saxhtml.v1.test.ConversionTest</dt> + + <dd>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.</dd> + </dl></li> + </ol><h2>Description</h2><p>Our sample document memo document + contains:</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>Complete the implementation of + <code>Memo2HtmlHandler</code> to generate the content of + <code>memo.xml.1.sample.html</code>:</p><pre><html> + <head> + <title>Memo message</title> + </head> + <body> + <h2>Message from <strong>M. Goik</strong></h2> + <h2>Recipients:</h2> + <ul> + <li>B. King</li> + <li>A. June</li> + </ul> + <h2>Subject: Best wishes</h2> + <p>Hi all, congratulations to your splendid party</p> + </body> +</html></pre><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>Your project contains a second set of + files intended to create more sophisticated output as being contained in + <code>memo.xml.2.sample.html</code>:</p><pre><html> + <head><title>Memo from M. Goik</title></head> + <body> + <h2>Subject:Best wishes</h2> + <dl> + <dt>Sender:</dt> + <dd>M. Goik</dd> + <dt>Recipients:</dt> + <dd> + <ul> + <li>B. King</li> + <li>A. June</li> + </ul> + </dd> + </dl> + <h2>Subject: Best wishes</h2> + <p>Hi all, congratulations to your splendid party</p> + <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 by + <code>de.hdm_stuttgart.mi.sda1.saxhtml.v2.Driver</code> and + <code>de.hdm_stuttgart.de.sda1.saxhtml.v2.test.ConversionTest</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 XML input is not being preserved. Furthermore some input + (sender's name) has to be duplicated. To deal with 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> +</html> diff --git a/Sda1/Etest/SaxMemo2Html/exercise2.xhtml b/Sda1/Etest/SaxMemo2Html/exercise2.xhtml new file mode 100644 index 0000000000000000000000000000000000000000..392b6ec3baadab87969c6ded9981f55ac68d4507 --- /dev/null +++ b/Sda1/Etest/SaxMemo2Html/exercise2.xhtml @@ -0,0 +1,90 @@ +<?xml version="1.0" encoding="UTF-8"?> +<!DOCTYPE html> +<html xmlns="http://www.w3.org/1999/xhtml"> + <head> + <title>Exercise 2</title> + </head> + + <body><h2>Objective</h2><p>Extension of the <code>Book1/book2html.xsl</code> + stylesheet from the previous exercise to accomplish additional + features.</p><h2>Preparations</h2><p>Reuse your current project from the + previous exercise. It contains a second sub folder<code> Book2</code> + offering similar files as before. Configure a second transformation scenario + named book2ToHtml accordingly.</p><h2>Description</h2><p>The current + <code><code>Book2/work.xml</code></code> and <code>Book2/book.xsd</code> + files differ from the previous exercise by:</p><ul> + <li>Allowing <strong>optional</strong> <code>id</code> attributes of + type <code>xs:ID</code> for <code><book></code>, + <code><chapter></code> and <code><para></code> elements</li> + + <li><p>Allowing para elements to be composed of mixed content involving + two new elements:</p><ol> + <li><emphasis> elements to indicate important text + sections.</li> + + <li><code><link linkend="xyz"></code> elements allowing for + document internal links being implemented by <code>xs:ID</code> / + <code>xs:IDREF</code> pairs.</li> + </ol></li> + </ul><pre style="font-family:monospace;"><book ... xsi:noNamespaceSchemaLocation="book.xsd"> + <title>Beginning XSL</title> + <chapter id="firstChapter"> + <title>Basic structure</title> + <para>An XSLT consists of a stylesheet declaration and a set of templates.</para> + <para>Do <emphasis>not forget</emphasis>: template elements must not be nested!</para> + </chapter> + <chapter> + <title>Important elements</title> + <para id="someText">Some more text.</para> + <para>The <link linkend="firstChapter">first chapter</link> explains basic structures.</para> + </chapter> +</book></pre><p>We want to transform instances like the above into HTML + by means of <code>Book2/book2html.xsl</code>. The intended result is being + shown in file <code>Book2/work.reference.html</code>:</p><pre + style="font-family:monospace;"><html> + <head> + <title>Beginning XSL</title> + </head> + <body id="top"> + <h1>Beginning XSL</h1> + <h2 id="firstChapter">Basic structure</h2> + <p>An XSLT consists of a stylesheet declaration and a set of templates.</p> + <p>Do <em>not forget</em>: template elements must not be nested!</p> + <h2>Important elements</h2> + <p id="someText">Some more text.</p> + <p>The <a href="#firstChapter">first chapter</a> explains basic structures.</p> + </body> +</html></pre><p>The following conditions shall be met:</p><ul> + <li><p>Implementing <code>id</code> attributes:</p><ul> + <li><code><book id='xyz'></code> becomes <code><body + id='xyz'></code></li> + + <li><code><chapter id='xyz'></code> becomes <code><h2 + id='xyz'></code></li> + + <li><code><para id='xyz'></code> becomes <code><p + id='xyz'></code></li> + </ul></li> + + <li><p><code>xs:IDREF</code> attributes shall be represented by local + HTML references as shown above in <code><a + href="#firstChapter"></code>.</p></li> + </ul><h2>ToDo</h2><p>Complete the implementation of + <code>Book2/book2html.xsl</code>. You may want to start from your XSL result + of the previous exercise by copying relevant content from + <code>Book1/book2html.xsl</code>.</p><p>Open the unit test file + <code>Book2/bookLinkMixedTest.xspec</code> (which imports all tests from the + previous exercise file <code>Book1/bookBasicTest.xspec</code> as well) and + hit <code>Apply transformation scenario(s) Xspec for XSLT</code> in the + Eclipse tool bar. This allows to continuously check your progress and + reminds you about possible errors. When you are finished upload your final + <code>Book2/book2html.xsl</code> result.</p><h2>Hints:</h2><ul> + <li>Use <code><xsl:attributes></code> to supply <code>id</code> + values.</li> + + <li>Optional <code>id</code> values may be handled either by + <code><xsl:if></code> statements or by <xsl:apply-templates + select='...|@id'> having a corresponding <code><xsl:template + match='@id'></code> counterpart.</li> + </ul></body> +</html>