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

Test description

parent c7531ef1
No related branches found
No related tags found
No related merge requests found
......@@ -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;
......
<?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>&lt;html&gt;&lt;/html&gt;</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;">&lt;memo&gt;
&lt;from&gt;M. Goik&lt;/from&gt;
&lt;to&gt;B. King&lt;/to&gt;
&lt;to&gt;A. June&lt;/to&gt;
&lt;subject&gt;Best wishes&lt;/subject&gt;
&lt;content&gt;Hi all, congratulations to your splendid party&lt;/content&gt;
&lt;/memo&gt;</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>&lt;html&gt;
&lt;head&gt;
&lt;title&gt;Memo message&lt;/title&gt;
&lt;/head&gt;
&lt;body&gt;
&lt;h2&gt;Message from &lt;strong&gt;M. Goik&lt;/strong&gt;&lt;/h2&gt;
&lt;h2&gt;Recipients:&lt;/h2&gt;
&lt;ul&gt;
&lt;li&gt;B. King&lt;/li&gt;
&lt;li&gt;A. June&lt;/li&gt;
&lt;/ul&gt;
&lt;h2&gt;Subject: Best wishes&lt;/h2&gt;
&lt;p&gt;Hi all, congratulations to your splendid party&lt;/p&gt;
&lt;/body&gt;
&lt;/html&gt;</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>&lt;html&gt;
&lt;head&gt;&lt;title&gt;Memo from M. Goik&lt;/title&gt;&lt;/head&gt;
&lt;body&gt;
&lt;h2&gt;Subject:Best wishes&lt;/h2&gt;
&lt;dl&gt;
&lt;dt&gt;Sender:&lt;/dt&gt;
&lt;dd&gt;M. Goik&lt;/dd&gt;
&lt;dt&gt;Recipients:&lt;/dt&gt;
&lt;dd&gt;
&lt;ul&gt;
&lt;li&gt;B. King&lt;/li&gt;
&lt;li&gt;A. June&lt;/li&gt;
&lt;/ul&gt;
&lt;/dd&gt;
&lt;/dl&gt;
&lt;h2&gt;Subject: Best wishes&lt;/h2&gt;
&lt;p&gt;Hi all, congratulations to your splendid party&lt;/p&gt;
&lt;p&gt;End of message from &lt;strong&gt;M. Goik&lt;/strong&gt;&lt;/p&gt;
&lt;/body&gt;
&lt;/html&gt;</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>
<?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>&lt;book&gt;</code>,
<code>&lt;chapter&gt;</code> and <code>&lt;para&gt;</code> elements</li>
<li><p>Allowing para elements to be composed of mixed content involving
two new elements:</p><ol>
<li>&lt;emphasis&gt; elements to indicate important text
sections.</li>
<li><code>&lt;link linkend="xyz"&gt;</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;">&lt;book ... xsi:noNamespaceSchemaLocation="book.xsd"&gt;
&lt;title&gt;Beginning XSL&lt;/title&gt;
&lt;chapter id="firstChapter"&gt;
&lt;title&gt;Basic structure&lt;/title&gt;
&lt;para&gt;An XSLT consists of a stylesheet declaration and a set of templates.&lt;/para&gt;
&lt;para&gt;Do &lt;emphasis&gt;not forget&lt;/emphasis&gt;: template elements must not be nested!&lt;/para&gt;
&lt;/chapter&gt;
&lt;chapter&gt;
&lt;title&gt;Important elements&lt;/title&gt;
&lt;para id="someText"&gt;Some more text.&lt;/para&gt;
&lt;para&gt;The &lt;link linkend="firstChapter"&gt;first chapter&lt;/link&gt; explains basic structures.&lt;/para&gt;
&lt;/chapter&gt;
&lt;/book&gt;</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;">&lt;html&gt;
&lt;head&gt;
&lt;title&gt;Beginning XSL&lt;/title&gt;
&lt;/head&gt;
&lt;body id="top"&gt;
&lt;h1&gt;Beginning XSL&lt;/h1&gt;
&lt;h2 id="firstChapter"&gt;Basic structure&lt;/h2&gt;
&lt;p&gt;An XSLT consists of a stylesheet declaration and a set of templates.&lt;/p&gt;
&lt;p&gt;Do &lt;em&gt;not forget&lt;/em&gt;: template elements must not be nested!&lt;/p&gt;
&lt;h2&gt;Important elements&lt;/h2&gt;
&lt;p id="someText"&gt;Some more text.&lt;/p&gt;
&lt;p&gt;The &lt;a href="#firstChapter"&gt;first chapter&lt;/a&gt; explains basic structures.&lt;/p&gt;
&lt;/body&gt;
&lt;/html&gt;</pre><p>The following conditions shall be met:</p><ul>
<li><p>Implementing <code>id</code> attributes:</p><ul>
<li><code>&lt;book id='xyz'&gt;</code> becomes <code>&lt;body
id='xyz'&gt;</code></li>
<li><code>&lt;chapter id='xyz'&gt;</code> becomes <code>&lt;h2
id='xyz'&gt;</code></li>
<li><code>&lt;para id='xyz'&gt;</code> becomes <code>&lt;p
id='xyz'&gt;</code></li>
</ul></li>
<li><p><code>xs:IDREF</code> attributes shall be represented by local
HTML references as shown above in <code>&lt;a
href="#firstChapter"&gt;</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>&lt;xsl:attributes&gt;</code> to supply <code>id</code>
values.</li>
<li>Optional <code>id</code> values may be handled either by
<code>&lt;xsl:if&gt;</code> statements or by &lt;xsl:apply-templates
select='...|@id'&gt; having a corresponding <code>&lt;xsl:template
match='@id'&gt;</code> counterpart.</li>
</ul></body>
</html>
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment