diff --git a/Klausuren/Sd1/WS2014/Klausur/pom.xml b/Klausuren/Sd1/WS2014/Klausur/pom.xml new file mode 100644 index 0000000000000000000000000000000000000000..4d22479ac775845134b3041701d6a3ff1354bbb6 --- /dev/null +++ b/Klausuren/Sd1/WS2014/Klausur/pom.xml @@ -0,0 +1,38 @@ +<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.sw1.klausur</groupId> + <artifactId>sw1klausur</artifactId> + <version>0.8</version> + <packaging>jar</packaging> + + <name>sw1klausur</name> + <url>http://maven.apache.org</url> + + <properties> + <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> + </properties> + <build> + <plugins> + <plugin> + <groupId>org.apache.maven.plugins</groupId> + <artifactId>maven-compiler-plugin</artifactId> + <version>3.2</version> + <configuration> + <source>1.8</source> + <target>1.8</target> + </configuration> + </plugin> + </plugins> + </build> + + <dependencies> + <dependency> + <groupId>junit</groupId> + <artifactId>junit</artifactId> + <version>4.11</version> + <scope>test</scope> + </dependency> + </dependencies> +</project> diff --git a/Klausuren/Sd1/WS2014/Klausur/src/main/java/de/hdm_stuttgart/sw1/klausur/book/Book.java b/Klausuren/Sd1/WS2014/Klausur/src/main/java/de/hdm_stuttgart/sw1/klausur/book/Book.java new file mode 100644 index 0000000000000000000000000000000000000000..23a69e5ef7e1554c00f6dad1545544baae76b30f --- /dev/null +++ b/Klausuren/Sd1/WS2014/Klausur/src/main/java/de/hdm_stuttgart/sw1/klausur/book/Book.java @@ -0,0 +1,12 @@ +package de.hdm_stuttgart.sw1.klausur.book; + +public class Book { + + public Book(final int jahr, final String titel) { + this.jahr = jahr; + this.titel = titel; + } + + public final int jahr; + public final String titel; +} diff --git a/Klausuren/Sd1/WS2014/Klausur/src/main/java/de/hdm_stuttgart/sw1/klausur/book/Driver.java b/Klausuren/Sd1/WS2014/Klausur/src/main/java/de/hdm_stuttgart/sw1/klausur/book/Driver.java new file mode 100644 index 0000000000000000000000000000000000000000..053a873548c70de3ee0dc82937a4e984dad53c22 --- /dev/null +++ b/Klausuren/Sd1/WS2014/Klausur/src/main/java/de/hdm_stuttgart/sw1/klausur/book/Driver.java @@ -0,0 +1,21 @@ +package de.hdm_stuttgart.sw1.klausur.book; + +import java.util.List; +import java.util.Vector; + +public class Driver { + + public static void main(String[] args) { + + final List<Book> buecher = new Vector<Book>(); + + buecher.add(new Book(1967, "100 Jahre Einsamkeit")); + buecher.add(new Book(1999, "Ein Spiel")); + buecher.add(new Book(1866, "Schuld und Sühne")); + buecher.add(new Book(1999, "Das Verbrechen")); + + for (final Book b: buecher) { + System.out.println(b.jahr + ": " + b.titel); + } + } +} diff --git a/Klausuren/Sd1/WS2014/Klausur/src/main/java/de/hdm_stuttgart/sw1/klausur/string/StringHelper.java b/Klausuren/Sd1/WS2014/Klausur/src/main/java/de/hdm_stuttgart/sw1/klausur/string/StringHelper.java new file mode 100644 index 0000000000000000000000000000000000000000..154daa31b6ab15fe668881017d731833823c80f1 --- /dev/null +++ b/Klausuren/Sd1/WS2014/Klausur/src/main/java/de/hdm_stuttgart/sw1/klausur/string/StringHelper.java @@ -0,0 +1,88 @@ +package de.hdm_stuttgart.sw1.klausur.string; + + +/** + * Hilfsklasse zur Bereitstellung String-bezogener Methoden. + * + */ +public class StringHelper { + + /** + * Bestimmung der Geamtlänge einer Folge von Worten. Beispiel: + * + * <code>{"Dies", " ist ", " kurz.", null} ist ein Array aus drei Strings und einem null Wert mit in Summe + * 4 + 5 + 6 + 0 = 15 Zeichen.</code> + * + * @param words + * Ein Array aus Strings. Kann null sein, null Werte enthalten + * oder die Länge 0 haben. + * + * @return Die Gesamtlänge aller Worte. Enthaltene null Werte werden als + * Länge 0 gewertet. Falls null == words, ist der Rückgabewert 0. + */ + public static int summierteWortLaenge(final String[] words) { + + return 0; //TODO + } + + /** + * Bestimmung der Anzahl von Ziffern in einer gegebenen Zeichenkette. + * + * Beispiele: + * + * "Anton" enthält 0 Ziffern. "4Laufen 1-2-3" enthält vier Ziffern. + * + * @param s + * Die zu untersuchende Zeichenkette. + * @return Die Anzahl der in s enthaltenen Ziffern. Für null == s soll der + * Wert 0 zurückgegeben werden. + */ + public static int anzahlZiffern(final String s) { + return 0; //TODO + } + + /** + * Korrespondierende Methode zu {@link #anzahlZiffern(String)}: Die + * Ziffernsuche wird auf alle in einem Array enthaltenen Strings ausgedehnt. + * + * @param strings + * Liste übergebener Strings. + * + * @return Die Anzahl aller Ziffern aus allen im Array übergebenen Strings. + * Enthaltene null Werte werden ignoriert. + * Ein null Array liefert 0 Ziffern. Ein leeres Array liefert den Wert 0 + */ + public static int anzahlZiffern(final String strings[]) { + return 0; //TODO + } + + /** + * Entferne alle doppelt auftretenden Zeichenketten und null Werte aus einem + * String Array mit Unterscheidung von Groß- und Kleinschreibung und ordne + * das Ergebnis alphabetisch gemäß {@link String#compareTo(String)}. + * Beispiel: + * + * {"Haus", "Wiese", null, "laufen", null, "Wiese", "Kiste"} + * + * Das erwartete Ergebnis ist: + * + * {"Haus", "Kiste", "Wiese", "laufen"} + * + * Die Reihenfolge ergibt sich aus der alphabetischen Sortierung gemäß + * {@link String#compareTo(String)} unter Beachtung von Groß- und + * Kleinschreibung. + * + * @param inputStrings + * Eine Array aus Strings mit möglichen Duplikaten und null + * Werten. Ein Argument inputStrings == null wird wie ein Array + * der Länge 0, also als {}, gewertet. + * + * @return Die enthaltenen Strings ohne Duplikate und null Werte in + * alphabetisch aufsteigender Reihenfolge. Der Rückgabewert ist + * garantiert von null verschieden. + */ + public static String[] filterUndSortiereDuplikate(final String[] inputStrings) { + + return null; //TODO + } +} \ No newline at end of file diff --git a/Klausuren/Sd1/WS2014/Klausur/src/test/java/de/hdm_stuttgart/mi/exam/Marking.java b/Klausuren/Sd1/WS2014/Klausur/src/test/java/de/hdm_stuttgart/mi/exam/Marking.java new file mode 100644 index 0000000000000000000000000000000000000000..b53caa5f804a616889ec538f42acba56a672b622 --- /dev/null +++ b/Klausuren/Sd1/WS2014/Klausur/src/test/java/de/hdm_stuttgart/mi/exam/Marking.java @@ -0,0 +1,14 @@ +package de.hdm_stuttgart.mi.exam; + +import java.lang.annotation.ElementType; +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; +import java.lang.annotation.Target; + + +@Retention( value = RetentionPolicy.RUNTIME) +@Target( value = { ElementType.METHOD}) +public @interface Marking { + + int points (); +} diff --git a/Klausuren/Sd1/WS2014/Klausur/src/test/java/de/hdm_stuttgart/mi/exam/MarkingTest.java b/Klausuren/Sd1/WS2014/Klausur/src/test/java/de/hdm_stuttgart/mi/exam/MarkingTest.java new file mode 100644 index 0000000000000000000000000000000000000000..1e8bd4cf4829b79501ca8e1d2337e021ed6cc9c2 --- /dev/null +++ b/Klausuren/Sd1/WS2014/Klausur/src/test/java/de/hdm_stuttgart/mi/exam/MarkingTest.java @@ -0,0 +1,16 @@ +package de.hdm_stuttgart.mi.exam; + +import org.junit.AfterClass; +import org.junit.Rule; + +public class MarkingTest { + + final static ResultCollector globalresultCollector = new ResultCollector(); + + @Rule + public ResultCollector collectedResults = globalresultCollector; + + @AfterClass public static void showResults() { + System.out.println(globalresultCollector); + } +} diff --git a/Klausuren/Sd1/WS2014/Klausur/src/test/java/de/hdm_stuttgart/mi/exam/ResultCollector.java b/Klausuren/Sd1/WS2014/Klausur/src/test/java/de/hdm_stuttgart/mi/exam/ResultCollector.java new file mode 100644 index 0000000000000000000000000000000000000000..fe2480c2fb98e89636b8d08fe2ce2c4e64010449 --- /dev/null +++ b/Klausuren/Sd1/WS2014/Klausur/src/test/java/de/hdm_stuttgart/mi/exam/ResultCollector.java @@ -0,0 +1,79 @@ +package de.hdm_stuttgart.mi.exam; + +import java.lang.annotation.Annotation; +import java.util.List; +import java.util.Vector; + +import org.junit.rules.TestWatcher; +import org.junit.runner.Description; + +public class ResultCollector extends TestWatcher { + + public final List<TestResult> failedTests = new Vector<TestResult>(), + successfulTests = new Vector<TestResult>(); + + @Override + protected void failed(final Throwable e, final Description description) { + failedTests.add(new TestResult(description.getDisplayName(), + getMarking(description), false)); + } + + @Override + protected void succeeded(final Description description) { + successfulTests.add(new TestResult(description.getDisplayName(), + getMarking(description), true)); + } + + private static Marking getMarking(final Description description) { + + final Marking marking = description.getAnnotation(Marking.class); + if (null == marking) { // Default values: 1 point + return new Marking() { + + @Override + public Class<? extends Annotation> annotationType() { + return Marking.class; + } + + @Override + public int points() { + return 1; + } + }; + + } + return marking; + } + + @Override + public String toString() { + + int reachablePoints = 0, reachedPoints = 0; + + for (final TestResult t : successfulTests) { + reachablePoints += t.marking.points(); + reachedPoints += t.marking.points(); + } + for (final TestResult t : failedTests) { + reachablePoints += t.marking.points(); + } + + final StringBuffer buffer = new StringBuffer(); + + buffer.append("You have reached " + reachedPoints + " of " + + reachablePoints + " possible points in " + + successfulTests.size() + " successful tests\n"); + if (1 == failedTests.size()) { + buffer.append("The following test still fails:\n"); + buffer.append(" - " + failedTests.get(0).testMethodDisplayName + + "\n"); + } else if (1 < failedTests.size()) { + buffer.append("The following " + failedTests.size() + + " tests still fail:\n"); + for (final TestResult t : failedTests) { + buffer.append(" - " + t.testMethodDisplayName + "\n"); + } + } + return buffer.toString(); + } +} \ No newline at end of file diff --git a/Klausuren/Sd1/WS2014/Klausur/src/test/java/de/hdm_stuttgart/mi/exam/TestResult.java b/Klausuren/Sd1/WS2014/Klausur/src/test/java/de/hdm_stuttgart/mi/exam/TestResult.java new file mode 100644 index 0000000000000000000000000000000000000000..6627fa2c15f3aa74637a935ce53ccc48390d4fbd --- /dev/null +++ b/Klausuren/Sd1/WS2014/Klausur/src/test/java/de/hdm_stuttgart/mi/exam/TestResult.java @@ -0,0 +1,17 @@ +package de.hdm_stuttgart.mi.exam; + +public class TestResult { + + public final String testMethodDisplayName; + public final Marking marking; + public final boolean success; + + public TestResult(final String testName, + final Marking marking, + final boolean success) { + + this.testMethodDisplayName = testName; + this.marking = marking; + this.success = success; + } +} diff --git a/Klausuren/Sd1/WS2014/Klausur/src/test/java/de/hdm_stuttgart/sw1/klausur/test/Helper.java b/Klausuren/Sd1/WS2014/Klausur/src/test/java/de/hdm_stuttgart/sw1/klausur/test/Helper.java new file mode 100644 index 0000000000000000000000000000000000000000..b965dc7339f0003efb1cc15e6c842fdca622d954 --- /dev/null +++ b/Klausuren/Sd1/WS2014/Klausur/src/test/java/de/hdm_stuttgart/sw1/klausur/test/Helper.java @@ -0,0 +1,27 @@ +package de.hdm_stuttgart.sw1.klausur.test; + +/** + * String related helper methods + * + */ +public class Helper { + /** + * Turn an array of strings into a readable set . + * @param words Words to be joined into a single string + * @return A String like "{word_1, word_2, ..., word_n}" + */ + public static String toString(final String[] words) { + if (null == words) { + return "null"; + } else { + final StringBuffer retValue = new StringBuffer("{"); + String sep=""; + for(final String w: words) { + retValue.append(sep + "\"" + w + "\""); + sep = ", "; + } + retValue.append("}"); + return retValue.toString(); + } + } +} diff --git a/Klausuren/Sd1/WS2014/Klausur/src/test/java/de/hdm_stuttgart/sw1/klausur/test/TestAnzahlZiffernString.java b/Klausuren/Sd1/WS2014/Klausur/src/test/java/de/hdm_stuttgart/sw1/klausur/test/TestAnzahlZiffernString.java new file mode 100644 index 0000000000000000000000000000000000000000..af8416dabd086215198137f60db33811f7cd4ca9 --- /dev/null +++ b/Klausuren/Sd1/WS2014/Klausur/src/test/java/de/hdm_stuttgart/sw1/klausur/test/TestAnzahlZiffernString.java @@ -0,0 +1,40 @@ +package de.hdm_stuttgart.sw1.klausur.test; + +import org.junit.Assert; +import org.junit.Test; + +import de.hdm_stuttgart.mi.exam.Marking; +import de.hdm_stuttgart.mi.exam.MarkingTest; +import de.hdm_stuttgart.sw1.klausur.string.StringHelper; + +@SuppressWarnings({"static-method", "javadoc"}) +public class TestAnzahlZiffernString extends MarkingTest { + + private static void pruefeErwarteteZiffernAnzahl(final String s, final int erwarteteZiffernanzahl) { + Assert.assertEquals( + "String '" + s + "' enthält " + erwarteteZiffernanzahl + " Ziffern", + erwarteteZiffernanzahl, + StringHelper.anzahlZiffern(s)); + } + + @Test + public void anzahlZiffernNull() { + Assert.assertEquals("Ein null String enthält 0 Ziffern", + 0, StringHelper.anzahlZiffern((String)null)); + } + + @Test + @Marking(points=5) + public void anzahlZiffernDiverse() { + + pruefeErwarteteZiffernAnzahl("", 0); + pruefeErwarteteZiffernAnzahl("Tim", 0); + pruefeErwarteteZiffernAnzahl(" ", 0); + pruefeErwarteteZiffernAnzahl("1hulgigzgzu", 1); + pruefeErwarteteZiffernAnzahl("wsefresd2", 1); + pruefeErwarteteZiffernAnzahl("0123456789", 10); + pruefeErwarteteZiffernAnzahl("vdfgd123jhztf", 3); + pruefeErwarteteZiffernAnzahl("1a2b3", 3); + pruefeErwarteteZiffernAnzahl("dsfcd1234frsfe", 4); + } +} diff --git a/Klausuren/Sd1/WS2014/Klausur/src/test/java/de/hdm_stuttgart/sw1/klausur/test/TestAnzahlZiffernStringArray.java b/Klausuren/Sd1/WS2014/Klausur/src/test/java/de/hdm_stuttgart/sw1/klausur/test/TestAnzahlZiffernStringArray.java new file mode 100644 index 0000000000000000000000000000000000000000..b4777384370cff81890c4b65c57c5d38e9154367 --- /dev/null +++ b/Klausuren/Sd1/WS2014/Klausur/src/test/java/de/hdm_stuttgart/sw1/klausur/test/TestAnzahlZiffernStringArray.java @@ -0,0 +1,47 @@ +package de.hdm_stuttgart.sw1.klausur.test; + +import org.junit.Assert; +import org.junit.Test; + +import de.hdm_stuttgart.mi.exam.Marking; +import de.hdm_stuttgart.mi.exam.MarkingTest; +import de.hdm_stuttgart.sw1.klausur.string.StringHelper; + +/** + * String Tests. + */ +@SuppressWarnings({ "static-method", "javadoc" }) +public class TestAnzahlZiffernStringArray extends MarkingTest { + + private static void pruefeErwarteteZiffernAnzahl(final String s[], final int erwarteteZiffernzahl) { + Assert.assertEquals( + "String array " + Helper.toString(s) + " enthält " + erwarteteZiffernzahl + " Ziffern.", + erwarteteZiffernzahl, + StringHelper.anzahlZiffern(s)); + } + + @Test + public void testAnzahlZiffernNull() { + final String t = null; + Assert.assertEquals("Ein null String[] enthält 0 Ziffern", + 0, + StringHelper.anzahlZiffern(t)); + } + + @Test + @Marking(points=2) + public void testAnzahlZiffernNotNull() { + + pruefeErwarteteZiffernAnzahl(new String[]{}, 0); + pruefeErwarteteZiffernAnzahl(new String[]{""}, 0); + pruefeErwarteteZiffernAnzahl(new String[]{"1", " and", "33 plus 4"}, 4); + } + + @Test + @Marking(points=2) + public void testAnzahlZiffernMixedNull() { + pruefeErwarteteZiffernAnzahl(new String[]{null}, 0); + pruefeErwarteteZiffernAnzahl(new String[]{null, null}, 0); + pruefeErwarteteZiffernAnzahl(new String[]{"1", null, " and", "337 plus 4", null, null}, 5); + } +} diff --git a/Klausuren/Sd1/WS2014/Klausur/src/test/java/de/hdm_stuttgart/sw1/klausur/test/TestFilterSortiere.java b/Klausuren/Sd1/WS2014/Klausur/src/test/java/de/hdm_stuttgart/sw1/klausur/test/TestFilterSortiere.java new file mode 100644 index 0000000000000000000000000000000000000000..260540e0afcd0bec306bf2f88bd3e46c6ead291e --- /dev/null +++ b/Klausuren/Sd1/WS2014/Klausur/src/test/java/de/hdm_stuttgart/sw1/klausur/test/TestFilterSortiere.java @@ -0,0 +1,90 @@ +package de.hdm_stuttgart.sw1.klausur.test; + +import org.junit.Assert; +import org.junit.Test; + +import de.hdm_stuttgart.mi.exam.MarkingTest; +import de.hdm_stuttgart.sw1.klausur.string.StringHelper; + +@SuppressWarnings({"static-method", "javadoc"}) +public class TestFilterSortiere extends MarkingTest { + + @Test + public void nullArray() { + + final String[] result = StringHelper.filterUndSortiereDuplikate(null); + assertArrayEquals(new String[0], result); + } + + @Test + public void einzelnerNullWert() { + + final String[] result = StringHelper.filterUndSortiereDuplikate(new String[]{null}); + assertArrayEquals(new String[0], result); + } + + @Test + public void mehrereNullWerte() { + + final String[] result = StringHelper.filterUndSortiereDuplikate(new String[]{null}); + assertArrayEquals(new String[0], result); + } + + @Test + public void einzelnNotNull() { + + final String testWert = "Hans"; + final String[] result = StringHelper.filterUndSortiereDuplikate(new String[]{testWert}); + assertArrayEquals(new String[]{testWert}, result); + } + + @Test + public void mehrfachIdentischNotNull() { + + final String testWert = "Hans"; + final String[] result = StringHelper.filterUndSortiereDuplikate(new String[]{testWert, testWert, testWert}); + assertArrayEquals(new String[]{testWert}, result); + } + + @Test + public void mehrfachIdentischNull() { + + final String testWert = "Hans"; + final String[] result = StringHelper.filterUndSortiereDuplikate(new String[]{testWert, null, testWert}); + + assertArrayEquals(new String[]{testWert}, result); + } + + @Test + public void verschieden() { + + final String[] result = StringHelper.filterUndSortiereDuplikate(new String[]{"eins", "Zwei", "Drei"}) + , expected = new String[]{"Drei", "Zwei", "eins"}; + assertArrayEquals(expected, result); + + } + + @Test + public void duplikate() { + + final String[] result = StringHelper.filterUndSortiereDuplikate(new String[]{"eins", "Zwei", "Drei"}) + , expected = new String[]{"Drei", "Zwei", "eins"}; + assertArrayEquals(expected, result); + + } + + /** + * Hilfsmethode zum Test der Gleichheit zweier String arrays. + * + * @param expected Erwartetes Array + * @param result Erhaltenes Array + */ + public static void assertArrayEquals(final String[] expected, final String[] result) { + Assert.assertEquals("String Länge verschieden: " + expected.length + " != " + result.length, expected.length, result.length); + for (int i = 0; i < expected.length; i++) { + Assert.assertEquals("Array Komponenten sind verschieden: " + expected[i] + " != " + result[i], expected[i], result[i]); + } + } + + +} diff --git a/Klausuren/Sd1/WS2014/Klausur/src/test/java/de/hdm_stuttgart/sw1/klausur/test/TestSummierteWortlaenge.java b/Klausuren/Sd1/WS2014/Klausur/src/test/java/de/hdm_stuttgart/sw1/klausur/test/TestSummierteWortlaenge.java new file mode 100644 index 0000000000000000000000000000000000000000..041596eab05ef83d7e484892d2c2cf24c5758736 --- /dev/null +++ b/Klausuren/Sd1/WS2014/Klausur/src/test/java/de/hdm_stuttgart/sw1/klausur/test/TestSummierteWortlaenge.java @@ -0,0 +1,45 @@ +package de.hdm_stuttgart.sw1.klausur.test; + +import org.junit.Assert; +import org.junit.Test; + +import de.hdm_stuttgart.mi.exam.MarkingTest; +import de.hdm_stuttgart.sw1.klausur.string.StringHelper; + +@SuppressWarnings({ "static-method", "javadoc" }) +public class TestSummierteWortlaenge extends MarkingTest { + + private static void pruefeErwarteteLaenge(final String[] s, int erwarteteLaenge) { + Assert.assertEquals("Wortliste '" + Helper.toString(s) + "' hat erwartete Gesamtlänge " + erwarteteLaenge, + erwarteteLaenge, + StringHelper.summierteWortLaenge(s)); + } + + @Test + public void testNull() { + Assert.assertEquals("Ein null String hat die Länge 0", 0, + StringHelper.summierteWortLaenge(null)); + } + + @Test + public void summierteWortLaengeNonNull() { + + pruefeErwarteteLaenge(new String[] {}, 0); + pruefeErwarteteLaenge(new String[] { "" }, 0); + pruefeErwarteteLaenge(new String[] { "Einfach" }, 7); + pruefeErwarteteLaenge(new String[] { "Einfach, ", ", doppelt" }, 18); + pruefeErwarteteLaenge(new String[] { "Einfach, ", ", doppelt", ", dreifach" }, 28); + } + + @Test + public void testMixedNull() { + + pruefeErwarteteLaenge(new String[] { null }, 0); + pruefeErwarteteLaenge(new String[] { null, null }, 0); + pruefeErwarteteLaenge(new String[] { "Einfach", null }, 7); + pruefeErwarteteLaenge(new String[] { "Einfach, ", null, ", doppelt" }, 18); + pruefeErwarteteLaenge(new String[] { null, "Einfach, ", null, ", doppelt"}, 18); + pruefeErwarteteLaenge(new String[] { null, "Einfach, ", null, ", doppelt", ", dreifach", null }, 28); + pruefeErwarteteLaenge(new String[] { "Dies", " ist ", " kurz.", null }, 15); + } +} diff --git a/Klausuren/Sd1/WS2014/Solution/beschreibung.xhtml b/Klausuren/Sd1/WS2014/Solution/beschreibung.xhtml new file mode 100644 index 0000000000000000000000000000000000000000..31a7bfe300d69b58893f61bc5916aa707af4cbfc --- /dev/null +++ b/Klausuren/Sd1/WS2014/Solution/beschreibung.xhtml @@ -0,0 +1,84 @@ +<?xml version="1.0" encoding="UTF-8"?> +<!DOCTYPE html> +<html xml:lang="de" xmlns="http://www.w3.org/1999/xhtml"> + <head> + <title></title> + </head> + + <body> + + <h1>Beschreibung</h1><p>In dieser Aufgabe sollen mehrere Methoden zur + Verarbeitung von Zeichenketten (Strings) implementiert + werden.</p><h1>Vorbereitung</h1><p>Importieren Sie <a href="/files/goik/Klausur/WS2014/cwerhfhasfcfzchefherbfer/sw1.zip">sw1.zip</a> als + Maven Projekt in Ihren Eclipse workspace. Ignorieren Sie bitte das darin enthaltene + Package <code>de.hdm_stuttgart.mi.exam</code>.</p> + + <h1>Aufgabe</h1><p>Vervollständigen Sie die Implementierung der folgenden Methoden in der Klasse + <code>de.hdm_stuttgart.sw1.klausur.stringlength.StringHelper</code>:</p><ol> + <li><code>int summierteWortLaenge(final String[] words)</code></li> + + <li><code>int anzahlZiffern(final String s)</code></li> + + <li><code>int anzahlZiffern(final String strings[])</code></li> + <li><code>public static String[] filterUndSortiereDuplikate(final String[] inputStrings)</code></li> + + + </ol><p>Die Javadoc Kommentare der jeweiligen Methoden beschreiben das + gewünschte Verhalten.</p><h1>Allgemeine Hinweise</h1><ul> + <li><p>Für jede Methode aus der Klasse <code>StringHelper</code> steht + eine korrespondierende Junit Testklasse zur Verfügung:</p> + <table style="border: 1px solid black;"> + + <tr> + <td>Methode in <code>StringHelper</code></td> + + <td>Korrespondierende Testklasse</td> + </tr> + + <tr> + <td><hr/><code>int summierteWortLaenge(final String[] words)</code><p + style="color:red;">Das Array übergebener Worte kann null sein, + leer sein oder null Werte enthalten. Die Länge eines Strings + erhalten Sie über die Methode <code>int length()</code> aus der + Klasse <code>java.lang.String</code>.</p></td> + + <td><hr/><code>TestSummierteWortlaenge</code></td> + </tr> + + <tr> + <td><hr/><code>int anzahlZiffern(final String s)</code><p + style="color:red;">Beachten Sie die Methode + <code><code>java.lang.Character.isDigit(char)</code></code>.</p></td> + + <td><hr/><code>TestAnzahlZiffernString</code></td> + </tr> + + <tr> + <td><hr/><code>int anzahlZiffern(final String strings[])</code><p + style="color:red;">Die Implementierung kann unter Verwendung der + Methode <code>int anzahlZiffern(final String s)</code> + erfolgen.</p></td> + + <td><hr/><code>TestAnzahlZiffernStringArray</code></td> + </tr> + <tr> + <td><hr/><code>String[] filterUndSortiereDuplikate(final String[] inputStrings)</code><p + style="color:red;">Es gibt sehr verschiedene Lösungsansätze. Sie dürfen Instanzen von + <a href="http://docs.oracle.com/javase/8/docs/api/java/util/List.html">List</a> oder + <a href="http://docs.oracle.com/javase/8/docs/api/java/util/SortedSet.html">SortedSet</a> verwenden.</p></td> + + <td><hr/><code>TestFilterSortiere</code></td> + </tr> + </table></li> + + <li><p>Beachten Sie alle Sonderfälle. Dazu zählen insbesondere <code><code>null</code></code> Werte + übergebener Variablen oder enthaltene null Werte in übergebenen Arrays. Lesen Sie die + Beschreibung der einzelnen Methoden in den Kommentarköpfen <b>sehr genau</b>.</p></li> + </ul> + + <p>Sobald Sie die Aufgabe beendet haben, exportieren Sie Ihre Implementierung per Rechtclick auf das Eclipse Projekt über + »Export-->General-->Archive file« und laden Sie die resultierende .zip Datei in das Ilias Klausursystem hoch. + Zur Kontrolle: Die hochgeladene .zip Datei muss im Klausursystem sichtbar sein.</p> + + </body> +</html> diff --git a/Klausuren/Sd1/WS2014/Solution/pom.xml b/Klausuren/Sd1/WS2014/Solution/pom.xml new file mode 100644 index 0000000000000000000000000000000000000000..313e1595cc6234a3181af04caaceb47d18986d7a --- /dev/null +++ b/Klausuren/Sd1/WS2014/Solution/pom.xml @@ -0,0 +1,38 @@ +<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.sw1.klausur</groupId> + <artifactId>sw1klausur</artifactId> + <version>0.9</version> + <packaging>jar</packaging> + + <name>sw1klausur</name> + <url>http://maven.apache.org</url> + + <properties> + <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> + </properties> + <build> + <plugins> + <plugin> + <groupId>org.apache.maven.plugins</groupId> + <artifactId>maven-compiler-plugin</artifactId> + <version>3.2</version> + <configuration> + <source>1.8</source> + <target>1.8</target> + </configuration> + </plugin> + </plugins> + </build> + + <dependencies> + <dependency> + <groupId>junit</groupId> + <artifactId>junit</artifactId> + <version>4.11</version> + <scope>test</scope> + </dependency> + </dependencies> +</project> diff --git a/Klausuren/Sd1/WS2014/Solution/src/main/java/de/hdm_stuttgart/sw1/klausur/book/Book.java b/Klausuren/Sd1/WS2014/Solution/src/main/java/de/hdm_stuttgart/sw1/klausur/book/Book.java new file mode 100644 index 0000000000000000000000000000000000000000..c17bcae8d176521f619d446ea0c4a6a02a696ebd --- /dev/null +++ b/Klausuren/Sd1/WS2014/Solution/src/main/java/de/hdm_stuttgart/sw1/klausur/book/Book.java @@ -0,0 +1,22 @@ +package de.hdm_stuttgart.sw1.klausur.book; + +public class Book { + + public Book(final int jahr, final String titel) { + this.jahr = jahr; + this.titel = titel; + } + + public final int jahr; + public final String titel; + + @Override + public boolean equals(final Object book) { + if (book instanceof Book) { + final Book other = (Book) book; + return titel.equals(other.titel) && jahr == other.jahr; + } else { + return false; + } + } +} diff --git a/Klausuren/Sd1/WS2014/Solution/src/main/java/de/hdm_stuttgart/sw1/klausur/book/Driver.java b/Klausuren/Sd1/WS2014/Solution/src/main/java/de/hdm_stuttgart/sw1/klausur/book/Driver.java new file mode 100644 index 0000000000000000000000000000000000000000..cff7a1ce08287da72629f21aa9614309f06b9f6e --- /dev/null +++ b/Klausuren/Sd1/WS2014/Solution/src/main/java/de/hdm_stuttgart/sw1/klausur/book/Driver.java @@ -0,0 +1,23 @@ +package de.hdm_stuttgart.sw1.klausur.book; + +import java.util.List; +import java.util.Vector; + +public class Driver { + + public static void main(String[] args) { + + final List<Book> buecher = new Vector<Book>(); + + buecher.add(new Book(1967, "100 Jahre Einsamkeit")); + buecher.add(new Book(1999, "Ein Spiel")); + buecher.add(new Book(1866, "Schuld und Sühne")); + buecher.add(new Book(1999, "Das Verbrechen")); + + buecher.sort(new SortYearAuthor()); + + for (final Book b: buecher) { + System.out.println(b.jahr + ": " + b.titel); + } + } +} diff --git a/Klausuren/Sd1/WS2014/Solution/src/main/java/de/hdm_stuttgart/sw1/klausur/book/SortYearAuthor.java b/Klausuren/Sd1/WS2014/Solution/src/main/java/de/hdm_stuttgart/sw1/klausur/book/SortYearAuthor.java new file mode 100644 index 0000000000000000000000000000000000000000..d239b75666f59dc04cd1f710eef1df788a028839 --- /dev/null +++ b/Klausuren/Sd1/WS2014/Solution/src/main/java/de/hdm_stuttgart/sw1/klausur/book/SortYearAuthor.java @@ -0,0 +1,16 @@ +package de.hdm_stuttgart.sw1.klausur.book; + +import java.util.Comparator; + +public class SortYearAuthor implements Comparator<Book>{ + + @Override + public int compare(final Book a, final Book b) { + if (a.jahr == b.jahr) { + return a.titel.compareTo(b.titel); + } else { + return a.jahr - b.jahr; + } + } + +} diff --git a/Klausuren/Sd1/WS2014/Solution/src/main/java/de/hdm_stuttgart/sw1/klausur/book/equal/Driver.java b/Klausuren/Sd1/WS2014/Solution/src/main/java/de/hdm_stuttgart/sw1/klausur/book/equal/Driver.java new file mode 100644 index 0000000000000000000000000000000000000000..c72d7e1c954a374d2772dae4bce2a37e6d06c10e --- /dev/null +++ b/Klausuren/Sd1/WS2014/Solution/src/main/java/de/hdm_stuttgart/sw1/klausur/book/equal/Driver.java @@ -0,0 +1,22 @@ +package de.hdm_stuttgart.sw1.klausur.book.equal; + +import java.util.List; +import java.util.Vector; + +import de.hdm_stuttgart.sw1.klausur.book.Book; + +public class Driver { + + public static void main(String[] args) { + + final List<Book> buecher = new Vector<Book>(); + + final Book marquez = new Book(1967, "100 Jahre Einsamkeit"), + marquezKopie = new Book(1967, "100 Jahre Einsamkeit"); + + buecher.add(marquez); + + System.out.println("Buch schon vorhanden:" + buecher.contains(marquezKopie)); + + } +} diff --git a/Klausuren/Sd1/WS2014/Solution/src/main/java/de/hdm_stuttgart/sw1/klausur/string/StringHelper.java b/Klausuren/Sd1/WS2014/Solution/src/main/java/de/hdm_stuttgart/sw1/klausur/string/StringHelper.java new file mode 100644 index 0000000000000000000000000000000000000000..2df6d9c4b0994cea0f6b0ebcd09ceb4931e22b53 --- /dev/null +++ b/Klausuren/Sd1/WS2014/Solution/src/main/java/de/hdm_stuttgart/sw1/klausur/string/StringHelper.java @@ -0,0 +1,121 @@ +package de.hdm_stuttgart.sw1.klausur.string; + +import java.util.SortedSet; +import java.util.TreeSet; + +/** + * Hilfsklasse zur Bereitstellung String-bezogener Methoden. + * + */ +public class StringHelper { + + /** + * Bestimmung der Geamtlänge einer Folge von Worten. Beispiel: + * + * <code>{"Dies", " ist ", " kurz.", null} ist ein Array aus drei Strings und einem null Wert mit in Summe + * 4 + 5 + 6 + 0 = 15 Zeichen.</code> + * + * @param words + * Ein Array aus Strings. Kann null sein, null Werte enthalten + * oder die Länge 0 haben. + * + * @return Die Gesamtlänge aller Worte. Enthaltene null Werte werden als + * Länge 0 gewertet. Falls null == words, ist der Rückgabewert 0. + */ + public static int summierteWortLaenge(final String[] words) { + int gesamtLaenge = 0; + if (null != words) { + for (final String w : words) { + if (null != w) { + gesamtLaenge += w.length(); + } + } + } + return gesamtLaenge; + } + + /** + * Bestimmung der Anzahl von Ziffern in einer gegebenen Zeichenkette. + * + * Beispiele: + * + * "Anton" enthält 0 Ziffern. "4Laufen 1-2-3" enthält vier Ziffern. + * + * @param s + * Die zu untersuchende Zeichenkette. + * @return Die Anzahl der in s enthaltenen Ziffern. Für null == s soll der + * Wert 0 zurückgegeben werden. + */ + public static int anzahlZiffern(final String s) { + int numAsciiCharacters = 0; + if (null != s) { + for (int i = 0; i < s.length(); i++) { + if (Character.isDigit(s.charAt(i))) { + numAsciiCharacters++; + } + } + } + return numAsciiCharacters; + } + + /** + * Korrespondierende Methode zu {@link #anzahlZiffern(String)}: Die + * Ziffernsuche wird auf alle in einem Array enthaltenen Strings ausgedehnt. + * + * @param strings + * Liste übergebener Strings. + * + * @return Die Anzahl aller Ziffern aus allen im Array übergebenen Strings. + * Enthaltene null Werte werden ignoriert. + * Ein null Array liefert 0 Ziffern. Ein leeres Array liefert den Wert 0 + */ + public static int anzahlZiffern(final String strings[]) { + int numAsciiCharacters = 0; + if (null != strings) { + for (final String s : strings) { + numAsciiCharacters += anzahlZiffern(s); + } + } + return numAsciiCharacters; + } + + /** + * Entferne alle doppelt auftretenden Zeichenketten und null Werte aus einem + * String Array mit Unterscheidung von Groß- und Kleinschreibung und ordne + * das Ergebnis alphabetisch gemäß {@link String#compareTo(String)}. + * Beispiel: + * + * {"Haus", "Wiese", null, "laufen", null, "Wiese", "Kiste"} + * + * Das erwartete Ergebnis ist: + * + * {"Haus", "Kiste", "Wiese", "laufen"} + * + * Die Reihenfolge ergibt sich aus der alphabetischen Sortierung gemäß + * {@link String#compareTo(String)} unter Beachtung von Groß- und + * Kleinschreibung. + * + * @param inputStrings + * Eine Array aus Strings mit möglichen Duplikaten und null + * Werten. Ein Argument inputStrings == null wird wie ein Array + * der Länge 0, also als {}, gewertet. + * + * @return Die enthaltenen Strings ohne Duplikate und null Werte in + * alphabetisch aufsteigender Reihenfolge. Der Rückgabewert ist + * garantiert von null verschieden. + */ + public static String[] filterUndSortiereDuplikate(final String[] inputStrings) { + + if (null == inputStrings) { + return new String[0]; + } else { + final SortedSet<String> uniqueNonNullValues = new TreeSet<String>(); + for (final String s : inputStrings) { + if (null != s) { + uniqueNonNullValues.add(s); + } + } + return uniqueNonNullValues.toArray(new String[0]); + } + } +} \ No newline at end of file diff --git a/Klausuren/Sd1/WS2014/Solution/src/test/java/de/hdm_stuttgart/mi/exam/Marking.java b/Klausuren/Sd1/WS2014/Solution/src/test/java/de/hdm_stuttgart/mi/exam/Marking.java new file mode 100644 index 0000000000000000000000000000000000000000..b53caa5f804a616889ec538f42acba56a672b622 --- /dev/null +++ b/Klausuren/Sd1/WS2014/Solution/src/test/java/de/hdm_stuttgart/mi/exam/Marking.java @@ -0,0 +1,14 @@ +package de.hdm_stuttgart.mi.exam; + +import java.lang.annotation.ElementType; +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; +import java.lang.annotation.Target; + + +@Retention( value = RetentionPolicy.RUNTIME) +@Target( value = { ElementType.METHOD}) +public @interface Marking { + + int points (); +} diff --git a/Klausuren/Sd1/WS2014/Solution/src/test/java/de/hdm_stuttgart/mi/exam/MarkingTest.java b/Klausuren/Sd1/WS2014/Solution/src/test/java/de/hdm_stuttgart/mi/exam/MarkingTest.java new file mode 100644 index 0000000000000000000000000000000000000000..e10dab03f313523833ca14504d6286751c52b305 --- /dev/null +++ b/Klausuren/Sd1/WS2014/Solution/src/test/java/de/hdm_stuttgart/mi/exam/MarkingTest.java @@ -0,0 +1,25 @@ +package de.hdm_stuttgart.mi.exam; + +import org.junit.AfterClass; +import org.junit.Rule; +import org.junit.runner.Description; + +public class MarkingTest { + + public static Description currentTestClass = null; + + public final static ResultCollector globalresultCollector = new ResultCollector(); + + @Rule + public ResultCollector collectedResults = globalresultCollector; + + @AfterClass public static void showResults() { + System.out.println("Local:----------------------------------"); + System.out.println(globalresultCollector.currentToString()); + System.out.println("Global:++++++++++++++++++++++++++++++++++"); + System.out.println("Global:++++++++++++++++++++++++++++++++++"); + System.out.println(globalresultCollector.toString()); + System.out.println("Global:++++++++++++++++++++++++++++++++++"); + System.out.println("Global:++++++++++++++++++++++++++++++++++"); + } +} diff --git a/Klausuren/Sd1/WS2014/Solution/src/test/java/de/hdm_stuttgart/mi/exam/ResultCollector.java b/Klausuren/Sd1/WS2014/Solution/src/test/java/de/hdm_stuttgart/mi/exam/ResultCollector.java new file mode 100644 index 0000000000000000000000000000000000000000..69f74dfdf83b8c8154d0623d5e95da724b7b0780 --- /dev/null +++ b/Klausuren/Sd1/WS2014/Solution/src/test/java/de/hdm_stuttgart/mi/exam/ResultCollector.java @@ -0,0 +1,147 @@ +package de.hdm_stuttgart.mi.exam; + +import java.lang.annotation.Annotation; +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import java.util.Map.Entry; +import java.util.Vector; + +import org.junit.rules.TestWatcher; +import org.junit.runner.Description; + +public class ResultCollector extends TestWatcher { + + public final Map<String, List<TestResult>> + failedByDescription = new HashMap<String, List<TestResult>>(), + successByDescription = new HashMap<String, List<TestResult>>(); + + @Override + protected void starting(Description description) { + MarkingTest.currentTestClass = description; + } + + @Override + protected void failed(final Throwable e, final Description description) { + putAppend(failedByDescription, description.getClassName(), new TestResult(description, + getMarking(description), false)); + } + + @Override + protected void succeeded(final Description description) { + putAppend(successByDescription, description.getClassName(), new TestResult(description, + getMarking(description), true)); + } + + private static void putAppend(final Map<String, List<TestResult>> map, final String key, final TestResult testresult) { + List<TestResult> results = map.get(key); + if (null == results) { + results = new Vector<TestResult>(); + map.put(key, results); + } + results.add(testresult); + } + private static Marking getMarking(final Description description) { + + final Marking marking = description.getAnnotation(Marking.class); + if (null == marking) { // Default values: 1 point + return new Marking() { + + @Override + public Class<? extends Annotation> annotationType() { + return Marking.class; + } + + @Override + public int points() { + return 1; + } + }; + + } + return marking; + } + + public String currentToString() { + + final String currentTestClassName = MarkingTest.currentTestClass.getClassName(); + + int reachablePoints = 0, reachedPoints = 0, numSuccessfulTests = 0; + + final List<TestResult> successfulTestResults = successByDescription.get(currentTestClassName); + + if (null != successfulTestResults) { + for (final TestResult t : successfulTestResults) { + reachablePoints += t.marking.points(); + reachedPoints += t.marking.points(); + numSuccessfulTests++; + } + } + + final StringBuffer failBuffer = new StringBuffer(); + + final List<TestResult> failedTestResults = failedByDescription.get(currentTestClassName); + + if (null != failedTestResults) { + for (final TestResult t : failedTestResults) { + reachablePoints += t.marking.points(); + failBuffer.append(" -" + t.testMethodDisplayName + "\n"); + } + } + + final StringBuffer buffer = new StringBuffer(); + + buffer.append(currentTestClassName + ":\nYou have reached " + reachedPoints + " of " + + reachablePoints + " possible points in " + numSuccessfulTests + " successful tests. "); + + if (null != failedTestResults) { + + final int numFailed = failedTestResults.size(); + if (1 == numFailed) { + buffer.append(" The following test still fails:\n"); + } else if (1 < numFailed) { + buffer.append("\n\nThe following " + numFailed + " tests still fail:\n"); + } + buffer.append(failBuffer + "\n"); + } + buffer.append("\n"); + return buffer.toString(); + } + + @Override + public String toString() { + + int reachablePoints = 0, reachedPoints = 0, successfulTests = 0, failedTests = 0; + + for (final Entry<String, List<TestResult>> successEntries: successByDescription.entrySet()) { + for (final TestResult t : successEntries.getValue()) { + successfulTests++; + reachablePoints += t.marking.points(); + reachedPoints += t.marking.points(); + } + } + + final StringBuffer failBuffer = new StringBuffer(); + for (final Entry<String, List<TestResult>> failEntries: failedByDescription.entrySet()) { + for (final TestResult t : failEntries.getValue()) { + failedTests++; + reachablePoints += t.marking.points(); + failBuffer.append(" -" + t.testMethodDisplayName + "\n"); + } + } + + final StringBuffer buffer = new StringBuffer(); + + buffer.append("You have reached " + reachedPoints + " of " + + reachablePoints + " possible points in " + + successfulTests + " successful tests\n"); + if (1 == failedTests) { + buffer.append("\n\nThe following test still fails:\n"); + } else if (1 < failedTests) { + buffer.append("\n\nThe following " + failedTests + + " tests still fail:\n"); + } + buffer.append(failBuffer + "\n"); + return buffer.toString(); + } +} \ No newline at end of file diff --git a/Klausuren/Sd1/WS2014/Solution/src/test/java/de/hdm_stuttgart/mi/exam/TestResult.java b/Klausuren/Sd1/WS2014/Solution/src/test/java/de/hdm_stuttgart/mi/exam/TestResult.java new file mode 100644 index 0000000000000000000000000000000000000000..0b0d872364d026fcd378a1512c695a4c6002afde --- /dev/null +++ b/Klausuren/Sd1/WS2014/Solution/src/test/java/de/hdm_stuttgart/mi/exam/TestResult.java @@ -0,0 +1,19 @@ +package de.hdm_stuttgart.mi.exam; + +import org.junit.runner.Description; + +public class TestResult { + + public final Description testMethodDisplayName; + public final Marking marking; + public final boolean success; + + public TestResult(final Description testMethodDisplayName, + final Marking marking, + final boolean success) { + + this.testMethodDisplayName = testMethodDisplayName; + this.marking = marking; + this.success = success; + } +} diff --git a/Klausuren/Sd1/WS2014/Solution/src/test/java/de/hdm_stuttgart/sw1/klausur/test/Helper.java b/Klausuren/Sd1/WS2014/Solution/src/test/java/de/hdm_stuttgart/sw1/klausur/test/Helper.java new file mode 100644 index 0000000000000000000000000000000000000000..b965dc7339f0003efb1cc15e6c842fdca622d954 --- /dev/null +++ b/Klausuren/Sd1/WS2014/Solution/src/test/java/de/hdm_stuttgart/sw1/klausur/test/Helper.java @@ -0,0 +1,27 @@ +package de.hdm_stuttgart.sw1.klausur.test; + +/** + * String related helper methods + * + */ +public class Helper { + /** + * Turn an array of strings into a readable set . + * @param words Words to be joined into a single string + * @return A String like "{word_1, word_2, ..., word_n}" + */ + public static String toString(final String[] words) { + if (null == words) { + return "null"; + } else { + final StringBuffer retValue = new StringBuffer("{"); + String sep=""; + for(final String w: words) { + retValue.append(sep + "\"" + w + "\""); + sep = ", "; + } + retValue.append("}"); + return retValue.toString(); + } + } +} diff --git a/Klausuren/Sd1/WS2014/Solution/src/test/java/de/hdm_stuttgart/sw1/klausur/test/RunAllTests.java b/Klausuren/Sd1/WS2014/Solution/src/test/java/de/hdm_stuttgart/sw1/klausur/test/RunAllTests.java new file mode 100644 index 0000000000000000000000000000000000000000..a4945892dafe11cc28e610dbdab10966bcca20f5 --- /dev/null +++ b/Klausuren/Sd1/WS2014/Solution/src/test/java/de/hdm_stuttgart/sw1/klausur/test/RunAllTests.java @@ -0,0 +1,25 @@ +package de.hdm_stuttgart.sw1.klausur.test; + +import org.junit.AfterClass; +import org.junit.runner.RunWith; +import org.junit.runners.Suite; + +import de.hdm_stuttgart.mi.exam.MarkingTest; + +@RunWith(Suite.class) +@Suite.SuiteClasses({ + TestAnzahlZiffernString.class, + TestAnzahlZiffernStringArray.class, + TestFilterSortiere.class, + TestSummierteWortlaenge.class +}) + +public class RunAllTests { + + + @AfterClass public static void showResults() { + System.out.println("---final------------------"); + System.out.println(MarkingTest.globalresultCollector.toString()); + } + +} diff --git a/Klausuren/Sd1/WS2014/Solution/src/test/java/de/hdm_stuttgart/sw1/klausur/test/TestAnzahlZiffernString.java b/Klausuren/Sd1/WS2014/Solution/src/test/java/de/hdm_stuttgart/sw1/klausur/test/TestAnzahlZiffernString.java new file mode 100644 index 0000000000000000000000000000000000000000..af8416dabd086215198137f60db33811f7cd4ca9 --- /dev/null +++ b/Klausuren/Sd1/WS2014/Solution/src/test/java/de/hdm_stuttgart/sw1/klausur/test/TestAnzahlZiffernString.java @@ -0,0 +1,40 @@ +package de.hdm_stuttgart.sw1.klausur.test; + +import org.junit.Assert; +import org.junit.Test; + +import de.hdm_stuttgart.mi.exam.Marking; +import de.hdm_stuttgart.mi.exam.MarkingTest; +import de.hdm_stuttgart.sw1.klausur.string.StringHelper; + +@SuppressWarnings({"static-method", "javadoc"}) +public class TestAnzahlZiffernString extends MarkingTest { + + private static void pruefeErwarteteZiffernAnzahl(final String s, final int erwarteteZiffernanzahl) { + Assert.assertEquals( + "String '" + s + "' enthält " + erwarteteZiffernanzahl + " Ziffern", + erwarteteZiffernanzahl, + StringHelper.anzahlZiffern(s)); + } + + @Test + public void anzahlZiffernNull() { + Assert.assertEquals("Ein null String enthält 0 Ziffern", + 0, StringHelper.anzahlZiffern((String)null)); + } + + @Test + @Marking(points=5) + public void anzahlZiffernDiverse() { + + pruefeErwarteteZiffernAnzahl("", 0); + pruefeErwarteteZiffernAnzahl("Tim", 0); + pruefeErwarteteZiffernAnzahl(" ", 0); + pruefeErwarteteZiffernAnzahl("1hulgigzgzu", 1); + pruefeErwarteteZiffernAnzahl("wsefresd2", 1); + pruefeErwarteteZiffernAnzahl("0123456789", 10); + pruefeErwarteteZiffernAnzahl("vdfgd123jhztf", 3); + pruefeErwarteteZiffernAnzahl("1a2b3", 3); + pruefeErwarteteZiffernAnzahl("dsfcd1234frsfe", 4); + } +} diff --git a/Klausuren/Sd1/WS2014/Solution/src/test/java/de/hdm_stuttgart/sw1/klausur/test/TestAnzahlZiffernStringArray.java b/Klausuren/Sd1/WS2014/Solution/src/test/java/de/hdm_stuttgart/sw1/klausur/test/TestAnzahlZiffernStringArray.java new file mode 100644 index 0000000000000000000000000000000000000000..b4777384370cff81890c4b65c57c5d38e9154367 --- /dev/null +++ b/Klausuren/Sd1/WS2014/Solution/src/test/java/de/hdm_stuttgart/sw1/klausur/test/TestAnzahlZiffernStringArray.java @@ -0,0 +1,47 @@ +package de.hdm_stuttgart.sw1.klausur.test; + +import org.junit.Assert; +import org.junit.Test; + +import de.hdm_stuttgart.mi.exam.Marking; +import de.hdm_stuttgart.mi.exam.MarkingTest; +import de.hdm_stuttgart.sw1.klausur.string.StringHelper; + +/** + * String Tests. + */ +@SuppressWarnings({ "static-method", "javadoc" }) +public class TestAnzahlZiffernStringArray extends MarkingTest { + + private static void pruefeErwarteteZiffernAnzahl(final String s[], final int erwarteteZiffernzahl) { + Assert.assertEquals( + "String array " + Helper.toString(s) + " enthält " + erwarteteZiffernzahl + " Ziffern.", + erwarteteZiffernzahl, + StringHelper.anzahlZiffern(s)); + } + + @Test + public void testAnzahlZiffernNull() { + final String t = null; + Assert.assertEquals("Ein null String[] enthält 0 Ziffern", + 0, + StringHelper.anzahlZiffern(t)); + } + + @Test + @Marking(points=2) + public void testAnzahlZiffernNotNull() { + + pruefeErwarteteZiffernAnzahl(new String[]{}, 0); + pruefeErwarteteZiffernAnzahl(new String[]{""}, 0); + pruefeErwarteteZiffernAnzahl(new String[]{"1", " and", "33 plus 4"}, 4); + } + + @Test + @Marking(points=2) + public void testAnzahlZiffernMixedNull() { + pruefeErwarteteZiffernAnzahl(new String[]{null}, 0); + pruefeErwarteteZiffernAnzahl(new String[]{null, null}, 0); + pruefeErwarteteZiffernAnzahl(new String[]{"1", null, " and", "337 plus 4", null, null}, 5); + } +} diff --git a/Klausuren/Sd1/WS2014/Solution/src/test/java/de/hdm_stuttgart/sw1/klausur/test/TestFilterSortiere.java b/Klausuren/Sd1/WS2014/Solution/src/test/java/de/hdm_stuttgart/sw1/klausur/test/TestFilterSortiere.java new file mode 100644 index 0000000000000000000000000000000000000000..260540e0afcd0bec306bf2f88bd3e46c6ead291e --- /dev/null +++ b/Klausuren/Sd1/WS2014/Solution/src/test/java/de/hdm_stuttgart/sw1/klausur/test/TestFilterSortiere.java @@ -0,0 +1,90 @@ +package de.hdm_stuttgart.sw1.klausur.test; + +import org.junit.Assert; +import org.junit.Test; + +import de.hdm_stuttgart.mi.exam.MarkingTest; +import de.hdm_stuttgart.sw1.klausur.string.StringHelper; + +@SuppressWarnings({"static-method", "javadoc"}) +public class TestFilterSortiere extends MarkingTest { + + @Test + public void nullArray() { + + final String[] result = StringHelper.filterUndSortiereDuplikate(null); + assertArrayEquals(new String[0], result); + } + + @Test + public void einzelnerNullWert() { + + final String[] result = StringHelper.filterUndSortiereDuplikate(new String[]{null}); + assertArrayEquals(new String[0], result); + } + + @Test + public void mehrereNullWerte() { + + final String[] result = StringHelper.filterUndSortiereDuplikate(new String[]{null}); + assertArrayEquals(new String[0], result); + } + + @Test + public void einzelnNotNull() { + + final String testWert = "Hans"; + final String[] result = StringHelper.filterUndSortiereDuplikate(new String[]{testWert}); + assertArrayEquals(new String[]{testWert}, result); + } + + @Test + public void mehrfachIdentischNotNull() { + + final String testWert = "Hans"; + final String[] result = StringHelper.filterUndSortiereDuplikate(new String[]{testWert, testWert, testWert}); + assertArrayEquals(new String[]{testWert}, result); + } + + @Test + public void mehrfachIdentischNull() { + + final String testWert = "Hans"; + final String[] result = StringHelper.filterUndSortiereDuplikate(new String[]{testWert, null, testWert}); + + assertArrayEquals(new String[]{testWert}, result); + } + + @Test + public void verschieden() { + + final String[] result = StringHelper.filterUndSortiereDuplikate(new String[]{"eins", "Zwei", "Drei"}) + , expected = new String[]{"Drei", "Zwei", "eins"}; + assertArrayEquals(expected, result); + + } + + @Test + public void duplikate() { + + final String[] result = StringHelper.filterUndSortiereDuplikate(new String[]{"eins", "Zwei", "Drei"}) + , expected = new String[]{"Drei", "Zwei", "eins"}; + assertArrayEquals(expected, result); + + } + + /** + * Hilfsmethode zum Test der Gleichheit zweier String arrays. + * + * @param expected Erwartetes Array + * @param result Erhaltenes Array + */ + public static void assertArrayEquals(final String[] expected, final String[] result) { + Assert.assertEquals("String Länge verschieden: " + expected.length + " != " + result.length, expected.length, result.length); + for (int i = 0; i < expected.length; i++) { + Assert.assertEquals("Array Komponenten sind verschieden: " + expected[i] + " != " + result[i], expected[i], result[i]); + } + } + + +} diff --git a/Klausuren/Sd1/WS2014/Solution/src/test/java/de/hdm_stuttgart/sw1/klausur/test/TestSummierteWortlaenge.java b/Klausuren/Sd1/WS2014/Solution/src/test/java/de/hdm_stuttgart/sw1/klausur/test/TestSummierteWortlaenge.java new file mode 100644 index 0000000000000000000000000000000000000000..5d96885355bcc959fd3b3f02977359ffb2bed548 --- /dev/null +++ b/Klausuren/Sd1/WS2014/Solution/src/test/java/de/hdm_stuttgart/sw1/klausur/test/TestSummierteWortlaenge.java @@ -0,0 +1,49 @@ +package de.hdm_stuttgart.sw1.klausur.test; + +import org.junit.Assert; +import org.junit.Test; + +import de.hdm_stuttgart.mi.exam.Marking; +import de.hdm_stuttgart.mi.exam.MarkingTest; +import de.hdm_stuttgart.sw1.klausur.string.StringHelper; + +@SuppressWarnings({ "static-method", "javadoc" }) +public class TestSummierteWortlaenge extends MarkingTest { + + private static void pruefeErwarteteLaenge(final String[] s, int erwarteteLaenge) { + Assert.assertEquals("Wortliste '" + Helper.toString(s) + "' hat erwartete Gesamtlänge " + erwarteteLaenge, + erwarteteLaenge, + StringHelper.summierteWortLaenge(s)); + } + + @Test + + public void testNull() { + Assert.assertEquals("Ein null String hat die Länge 0", 0, + StringHelper.summierteWortLaenge(null)); + } + + @Test + @Marking(points=3) + public void summierteWortLaengeNonNull() { + + pruefeErwarteteLaenge(new String[] {}, 0); + pruefeErwarteteLaenge(new String[] { "" }, 0); + pruefeErwarteteLaenge(new String[] { "Einfach" }, 7); + pruefeErwarteteLaenge(new String[] { "Einfach, ", ", doppelt" }, 18); + pruefeErwarteteLaenge(new String[] { "Einfach, ", ", doppelt", ", dreifach" }, 28); + } + + @Test + @Marking(points=3) + public void testMixedNull() { + + pruefeErwarteteLaenge(new String[] { null }, 0); + pruefeErwarteteLaenge(new String[] { null, null }, 0); + pruefeErwarteteLaenge(new String[] { "Einfach", null }, 7); + pruefeErwarteteLaenge(new String[] { "Einfach, ", null, ", doppelt" }, 18); + pruefeErwarteteLaenge(new String[] { null, "Einfach, ", null, ", doppelt"}, 18); + pruefeErwarteteLaenge(new String[] { null, "Einfach, ", null, ", doppelt", ", dreifach", null }, 28); + pruefeErwarteteLaenge(new String[] { "Dies", " ist ", " kurz.", null }, 15); + } +} diff --git a/Klausuren/Sda1/SS2013/.classpath b/Klausuren/Sda1/SoSe2013/.classpath similarity index 100% rename from Klausuren/Sda1/SS2013/.classpath rename to Klausuren/Sda1/SoSe2013/.classpath diff --git a/Klausuren/Sda1/SS2013/.project b/Klausuren/Sda1/SoSe2013/.project similarity index 100% rename from Klausuren/Sda1/SS2013/.project rename to Klausuren/Sda1/SoSe2013/.project diff --git a/Klausuren/Sda1/SS2013/.settings/org.eclipse.jdt.core.prefs b/Klausuren/Sda1/SoSe2013/.settings/org.eclipse.jdt.core.prefs similarity index 100% rename from Klausuren/Sda1/SS2013/.settings/org.eclipse.jdt.core.prefs rename to Klausuren/Sda1/SoSe2013/.settings/org.eclipse.jdt.core.prefs diff --git a/Klausuren/Sda1/SS2013/Ex1/1.xhtml b/Klausuren/Sda1/SoSe2013/Ex1/1.xhtml similarity index 100% rename from Klausuren/Sda1/SS2013/Ex1/1.xhtml rename to Klausuren/Sda1/SoSe2013/Ex1/1.xhtml diff --git a/Klausuren/Sda1/SS2013/Ex1/1loes.xhtml b/Klausuren/Sda1/SoSe2013/Ex1/1loes.xhtml similarity index 100% rename from Klausuren/Sda1/SS2013/Ex1/1loes.xhtml rename to Klausuren/Sda1/SoSe2013/Ex1/1loes.xhtml diff --git a/Klausuren/Sda1/SS2013/Ex1/book.dtd b/Klausuren/Sda1/SoSe2013/Ex1/book.dtd similarity index 100% rename from Klausuren/Sda1/SS2013/Ex1/book.dtd rename to Klausuren/Sda1/SoSe2013/Ex1/book.dtd diff --git a/Klausuren/Sda1/SS2013/Ex1/bookSimple.dtd b/Klausuren/Sda1/SoSe2013/Ex1/bookSimple.dtd similarity index 100% rename from Klausuren/Sda1/SS2013/Ex1/bookSimple.dtd rename to Klausuren/Sda1/SoSe2013/Ex1/bookSimple.dtd diff --git a/Klausuren/Sda1/SS2013/Ex1/simple.xml b/Klausuren/Sda1/SoSe2013/Ex1/simple.xml similarity index 100% rename from Klausuren/Sda1/SS2013/Ex1/simple.xml rename to Klausuren/Sda1/SoSe2013/Ex1/simple.xml diff --git a/Klausuren/Sda1/SS2013/Ex2/2.xhtml b/Klausuren/Sda1/SoSe2013/Ex2/2.xhtml similarity index 100% rename from Klausuren/Sda1/SS2013/Ex2/2.xhtml rename to Klausuren/Sda1/SoSe2013/Ex2/2.xhtml diff --git a/Klausuren/Sda1/SS2013/Ex2/2loes.xhtml b/Klausuren/Sda1/SoSe2013/Ex2/2loes.xhtml similarity index 100% rename from Klausuren/Sda1/SS2013/Ex2/2loes.xhtml rename to Klausuren/Sda1/SoSe2013/Ex2/2loes.xhtml diff --git a/Klausuren/Sda1/SS2013/Ex2/example.txt b/Klausuren/Sda1/SoSe2013/Ex2/example.txt similarity index 100% rename from Klausuren/Sda1/SS2013/Ex2/example.txt rename to Klausuren/Sda1/SoSe2013/Ex2/example.txt diff --git a/Klausuren/Sda1/SS2013/Ex2/example.xhtml b/Klausuren/Sda1/SoSe2013/Ex2/example.xhtml similarity index 100% rename from Klausuren/Sda1/SS2013/Ex2/example.xhtml rename to Klausuren/Sda1/SoSe2013/Ex2/example.xhtml diff --git a/Klausuren/Sda1/SS2013/Ex2/xpath.txt b/Klausuren/Sda1/SoSe2013/Ex2/xpath.txt similarity index 100% rename from Klausuren/Sda1/SS2013/Ex2/xpath.txt rename to Klausuren/Sda1/SoSe2013/Ex2/xpath.txt diff --git a/Klausuren/Sda1/SS2013/Ex3/3.xhtml b/Klausuren/Sda1/SoSe2013/Ex3/3.xhtml similarity index 100% rename from Klausuren/Sda1/SS2013/Ex3/3.xhtml rename to Klausuren/Sda1/SoSe2013/Ex3/3.xhtml diff --git a/Klausuren/Sda1/SS2013/Ex3/3loes.xhtml b/Klausuren/Sda1/SoSe2013/Ex3/3loes.xhtml similarity index 100% rename from Klausuren/Sda1/SS2013/Ex3/3loes.xhtml rename to Klausuren/Sda1/SoSe2013/Ex3/3loes.xhtml diff --git a/Klausuren/Sda1/SS2013/Ex3/html2meta.xsl b/Klausuren/Sda1/SoSe2013/Ex3/html2meta.xsl similarity index 100% rename from Klausuren/Sda1/SS2013/Ex3/html2meta.xsl rename to Klausuren/Sda1/SoSe2013/Ex3/html2meta.xsl diff --git a/Klausuren/Sda1/SS2013/Ex4/4.xhtml b/Klausuren/Sda1/SoSe2013/Ex4/4.xhtml similarity index 100% rename from Klausuren/Sda1/SS2013/Ex4/4.xhtml rename to Klausuren/Sda1/SoSe2013/Ex4/4.xhtml diff --git a/Klausuren/Sda1/SS2013/Ex4/4loes.xhtml b/Klausuren/Sda1/SoSe2013/Ex4/4loes.xhtml similarity index 100% rename from Klausuren/Sda1/SS2013/Ex4/4loes.xhtml rename to Klausuren/Sda1/SoSe2013/Ex4/4loes.xhtml diff --git a/Klausuren/Sda1/SS2013/bin/sax/mixed/book.xml b/Klausuren/Sda1/SoSe2013/bin/sax/mixed/book.xml similarity index 100% rename from Klausuren/Sda1/SS2013/bin/sax/mixed/book.xml rename to Klausuren/Sda1/SoSe2013/bin/sax/mixed/book.xml diff --git a/Klausuren/Sda1/SS2013/bin/sax/mixed/mixed.xml b/Klausuren/Sda1/SoSe2013/bin/sax/mixed/mixed.xml similarity index 100% rename from Klausuren/Sda1/SS2013/bin/sax/mixed/mixed.xml rename to Klausuren/Sda1/SoSe2013/bin/sax/mixed/mixed.xml diff --git a/Klausuren/Sda1/SS2013/dummy.xsl b/Klausuren/Sda1/SoSe2013/dummy.xsl similarity index 100% rename from Klausuren/Sda1/SS2013/dummy.xsl rename to Klausuren/Sda1/SoSe2013/dummy.xsl diff --git a/Klausuren/Sda1/SS2013/src/sax/mixed/A.java b/Klausuren/Sda1/SoSe2013/src/sax/mixed/A.java similarity index 100% rename from Klausuren/Sda1/SS2013/src/sax/mixed/A.java rename to Klausuren/Sda1/SoSe2013/src/sax/mixed/A.java diff --git a/Klausuren/Sda1/SS2013/src/sax/mixed/AuthorFindHandler.java b/Klausuren/Sda1/SoSe2013/src/sax/mixed/AuthorFindHandler.java similarity index 100% rename from Klausuren/Sda1/SS2013/src/sax/mixed/AuthorFindHandler.java rename to Klausuren/Sda1/SoSe2013/src/sax/mixed/AuthorFindHandler.java diff --git a/Klausuren/Sda1/SS2013/src/sax/mixed/Driver.java b/Klausuren/Sda1/SoSe2013/src/sax/mixed/Driver.java similarity index 100% rename from Klausuren/Sda1/SS2013/src/sax/mixed/Driver.java rename to Klausuren/Sda1/SoSe2013/src/sax/mixed/Driver.java diff --git a/Klausuren/Sda1/SS2013/src/sax/mixed/MixedCount.java b/Klausuren/Sda1/SoSe2013/src/sax/mixed/MixedCount.java similarity index 100% rename from Klausuren/Sda1/SS2013/src/sax/mixed/MixedCount.java rename to Klausuren/Sda1/SoSe2013/src/sax/mixed/MixedCount.java diff --git a/Klausuren/Sda1/SS2013/src/sax/mixed/MyErrorHandler.java b/Klausuren/Sda1/SoSe2013/src/sax/mixed/MyErrorHandler.java similarity index 100% rename from Klausuren/Sda1/SS2013/src/sax/mixed/MyErrorHandler.java rename to Klausuren/Sda1/SoSe2013/src/sax/mixed/MyErrorHandler.java diff --git a/Klausuren/Sda1/SS2013/src/sax/mixed/book.xml b/Klausuren/Sda1/SoSe2013/src/sax/mixed/book.xml similarity index 100% rename from Klausuren/Sda1/SS2013/src/sax/mixed/book.xml rename to Klausuren/Sda1/SoSe2013/src/sax/mixed/book.xml diff --git a/Klausuren/Sda1/SS2013/src/sax/mixed/mixed.xml b/Klausuren/Sda1/SoSe2013/src/sax/mixed/mixed.xml similarity index 100% rename from Klausuren/Sda1/SS2013/src/sax/mixed/mixed.xml rename to Klausuren/Sda1/SoSe2013/src/sax/mixed/mixed.xml diff --git a/Klausuren/Sda1/WS2014/Letter/.project b/Klausuren/Sda1/WS2014/Letter/.project new file mode 100644 index 0000000000000000000000000000000000000000..52ba926d8f2d584de36b3d303c20dabc3b87b787 --- /dev/null +++ b/Klausuren/Sda1/WS2014/Letter/.project @@ -0,0 +1,17 @@ +<?xml version="1.0" encoding="UTF-8"?> +<projectDescription> + <name>Letter</name> + <comment></comment> + <projects> + </projects> + <buildSpec> + <buildCommand> + <name>com.oxygenxml.editor.xmlbuilder</name> + <arguments> + </arguments> + </buildCommand> + </buildSpec> + <natures> + <nature>com.oxygenxml.editor.xmlnature</nature> + </natures> +</projectDescription> diff --git a/Klausuren/Sda1/WS2014/Letter/letter.xsd b/Klausuren/Sda1/WS2014/Letter/letter.xsd new file mode 100644 index 0000000000000000000000000000000000000000..2dc51a90a567481f9850a68636298ab70fa13ab0 --- /dev/null +++ b/Klausuren/Sda1/WS2014/Letter/letter.xsd @@ -0,0 +1,8 @@ +<?xml version="1.0" encoding="UTF-8"?> +<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" elementFormDefault="qualified"> + + + <xs:element name="letter"> + </xs:element> + +</xs:schema> diff --git a/Klausuren/Sda1/WS2014/Letter/letter2html.xsl b/Klausuren/Sda1/WS2014/Letter/letter2html.xsl new file mode 100644 index 0000000000000000000000000000000000000000..5c39aa673a03f31a73bf4029d7df57da3bf4bfc6 --- /dev/null +++ b/Klausuren/Sda1/WS2014/Letter/letter2html.xsl @@ -0,0 +1,14 @@ +<?xml version="1.0" encoding="UTF-8"?> +<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" + xmlns:xs="http://www.w3.org/2001/XMLSchema" + xmlns="http://www.w3.org/1999/xhtml" + exclude-result-prefixes="xs" + version="2.0"> + + <xsl:output method="xhtml" indent="yes" /> + + <xsl:template match="/"> + <html></html> + </xsl:template> + +</xsl:stylesheet> \ No newline at end of file diff --git a/Klausuren/Sda1/WS2014/Letter/lettersample.xhtml b/Klausuren/Sda1/WS2014/Letter/lettersample.xhtml new file mode 100644 index 0000000000000000000000000000000000000000..baad117af20cf52145ee32d2e06b65eae34d9da1 --- /dev/null +++ b/Klausuren/Sda1/WS2014/Letter/lettersample.xhtml @@ -0,0 +1,27 @@ +<?xml version="1.0" encoding="UTF-8"?><html xmlns="http://www.w3.org/1999/xhtml"> + <head> + <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /> + <title>Content: Order inquiry confirmation</title> + </head> + <body> + <address>Smith & Company Ltd.<br />John Smith<br />Baker Street<br />6651<br />Smithtown<br /></address> + <dl> + <dt>Date:</dt> + <dd><b>2015-02-19</b></dd> + <dt>From:</dt> + <dd><b>Paul Smith</b></dd> + <dt>Content:</dt> + <dd><b>Order inquiry confirmation</b></dd> + </dl> + <p>Thank you for sending us the information on <em style="color:red;">SDL Trados Studio 2009</em>. + We like your products and think they certainly represent the most powerful translation + solution on the market. + We especially like the <em style="color:red;">XML Parser rules</em> options in the + <em style="color:red;">XML</em> filter. It has helped us to set up support for our XML files in a flash. + We have already downloaded the latest version from your Customer Center. + </p> + <p>We would like to order 50 licenses. Please send us a quote. Keep up the good work!</p> + <p>Yours sincerely,</p> + <p style="text-align: center;"><b>Paul Smith</b></p> + </body> +</html> \ No newline at end of file diff --git a/Klausuren/Sda1/WS2014/Letter/lettersample.xml b/Klausuren/Sda1/WS2014/Letter/lettersample.xml new file mode 100644 index 0000000000000000000000000000000000000000..13aeb3d3d2054e1f554cf86e0258b29a8460a61c --- /dev/null +++ b/Klausuren/Sda1/WS2014/Letter/lettersample.xml @@ -0,0 +1,60 @@ +<?xml version="1.0" encoding="UTF-8"?> +<letter xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" + xsi:noNamespaceSchemaLocation="letter.xsd"> + + <!-- A description of the letter's primary intent.--> + <!-- Restriction: maximum length <= 30 characters --> + <!-- Required --> + <about>Order inquiry confirmation</about> + + + <!-- The letter's composition date.--> + <!-- XML schema date type --> + <!-- Required --> + <date>2015-02-19</date> + + <!-- The author's salutation.--> + <!-- Restriction: maximum length <= 30 characters --> + <!-- Required --> + <salutation>Dear Daniel,</salutation> + + <!-- A paragraph within the letter--> + <!-- At least on paragraph must be present --> + <!-- Mixed content of optional "emphasis" and "component" pure text elements --> + + <paragraph>Thank you for sending us the information on <emphasis>SDL Trados Studio 2009</emphasis>. + We like your products and think they certainly represent the most powerful translation solution on the market. + We especially like the <component>XML Parser rules</component> options in the + <component>XML</component> filter. It has helped us to set up support for our XML files in a flash. + We have already downloaded the latest version from your Customer Center.</paragraph> + + <paragraph>We would like to order 50 licenses. Please send us a quote. Keep up the good work!</paragraph> + + <!-- The letter's closing phrase.--> + <!-- Restriction: maximum length <= 30 characters --> + <!-- Required --> + <complimentaryClose>Yours sincerely,</complimentaryClose> + + <!-- The author's name.--> + <!-- Restriction: maximum length <= 30 characters --> + <!-- Required --> + <signature>Paul Smith</signature> + + + <!-- The recipient's address.--> + <!-- Required --> + <!-- attribute display may either be true or false --> + <!-- Restriction: company, name, street, zip and town all have maximum length <= 30 characters --> + <address display="false"> + + <!-- Optional field--> + <company>Smith & Company Ltd.</company> + + <!-- name, street, zip and town are required --> + <name>John Smith</name> + <street>Baker Street</street> + <zip>6651</zip> + <town>Smithtown</town> + </address> + +</letter> \ No newline at end of file diff --git a/Klausuren/Sda1/WS2014/Letter_solution/.project b/Klausuren/Sda1/WS2014/Letter_solution/.project new file mode 100644 index 0000000000000000000000000000000000000000..3a4e5214918ffdba258eceb39605a405321458b5 --- /dev/null +++ b/Klausuren/Sda1/WS2014/Letter_solution/.project @@ -0,0 +1,17 @@ +<?xml version="1.0" encoding="UTF-8"?> +<projectDescription> + <name>Letter_solution</name> + <comment></comment> + <projects> + </projects> + <buildSpec> + <buildCommand> + <name>com.oxygenxml.editor.xmlbuilder</name> + <arguments> + </arguments> + </buildCommand> + </buildSpec> + <natures> + <nature>com.oxygenxml.editor.xmlnature</nature> + </natures> +</projectDescription> diff --git a/Klausuren/Sda1/WS2014/Letter_solution/Test/Negative/displayNoBoolean.xml b/Klausuren/Sda1/WS2014/Letter_solution/Test/Negative/displayNoBoolean.xml new file mode 100644 index 0000000000000000000000000000000000000000..15eb2e4544853ba1bb80197ef5f010b1887fd853 --- /dev/null +++ b/Klausuren/Sda1/WS2014/Letter_solution/Test/Negative/displayNoBoolean.xml @@ -0,0 +1,60 @@ +<?xml version="1.0" encoding="UTF-8"?> +<letter xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" + xsi:noNamespaceSchemaLocation="../letter.xsd"> + + <!-- A description of the letter's primary intent.--> + <!-- Restriction: maximum length <= 30 characters --> + <!-- Required --> + <about>Order inquiry confirmation</about> + + + <!-- The letter's composition date.--> + <!-- XML schema date type --> + <!-- Required --> + <date>2015-02-19</date> + + <!-- The author's salutation.--> + <!-- Restriction: maximum length <= 30 characters --> + <!-- Required --> + <salutation>Dear Daniel,</salutation> + + <!-- A paragraph within the letter--> + <!-- At least on paragraph must be present --> + <!-- Mixed content of optional "emphasis" and "component" pure text elements --> + + <paragraph>Thank you for sending us the information on <emphasis>SDL Trados Studio 2009</emphasis>. + We like your products and think they certainly represent the most powerful translation solution on the market. + We especially like the <component>XML Parser rules</component> options in the + <component>XML</component> filter. It has helped us to set up support for our XML files in a flash. + We have already downloaded the latest version from your Customer Center.</paragraph> + + <paragraph>We would like to order 50 licenses. Please send us a quote. Keep up the good work!</paragraph> + + <!-- The letter's closing phrase.--> + <!-- Restriction: maximum length <= 30 characters --> + <!-- Required --> + <complimentaryClose>Yours sincerely,</complimentaryClose> + + <!-- The author's name.--> + <!-- Restriction: maximum length <= 30 characters --> + <!-- Required --> + <signature>Paul Smith</signature> + + + <!-- The recipient's address.--> + <!-- Required --> + <!-- attribute display may either be true or false --> + <!-- Restriction: company, name, street, zip and town all have maximum length <= 30 characters --> + <address display="no"> + + <!-- Optional field--> + <company>Smith & Company Ltd.</company> + + <!-- name, street, zip and town are required --> + <name>John Smith</name> + <street>Baker Street</street> + <zip>6651</zip> + <town>Smithtown</town> + </address> + +</letter> diff --git a/Klausuren/Sda1/WS2014/Letter_solution/Test/Negative/displayNoBoolean.xml.log b/Klausuren/Sda1/WS2014/Letter_solution/Test/Negative/displayNoBoolean.xml.log new file mode 100644 index 0000000000000000000000000000000000000000..fe2d548cd015508ada2641406c6d8916c8ea762e --- /dev/null +++ b/Klausuren/Sda1/WS2014/Letter_solution/Test/Negative/displayNoBoolean.xml.log @@ -0,0 +1,2 @@ +file:///ma/goik/Klausur/Letter_solution/Test/Negative/displayNoBoolean.xml:48:27: parse error org.xml.sax.SAXParseException; systemId: file:///ma/goik/Klausur/Letter_solution/Test/Negative/displayNoBoolean.xml; lineNumber: 48; columnNumber: 27; cvc-pattern-valid: Value 'no' is not facet-valid with respect to pattern 'false|true' for type '#AnonType_displayaddressletter'. +parsing error diff --git a/Klausuren/Sda1/WS2014/Letter_solution/Test/Negative/missingAbout.xml b/Klausuren/Sda1/WS2014/Letter_solution/Test/Negative/missingAbout.xml new file mode 100644 index 0000000000000000000000000000000000000000..b4010144a7b53110b118e68935d58cbb629dad37 --- /dev/null +++ b/Klausuren/Sda1/WS2014/Letter_solution/Test/Negative/missingAbout.xml @@ -0,0 +1,54 @@ +<?xml version="1.0" encoding="UTF-8"?> +<letter xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" + xsi:noNamespaceSchemaLocation="../letter.xsd"> + + <!-- The letter's composition date.--> + <!-- XML schema date type --> + <!-- Required --> + <date>2015-02-19</date> + + <!-- The author's salutation.--> + <!-- Restriction: maximum length <= 30 characters --> + <!-- Required --> + <salutation>Dear Daniel,</salutation> + + <!-- A paragraph within the letter--> + <!-- At least on paragraph must be present --> + <!-- Mixed content of optional "emphasis" and "component" pure text elements --> + + <paragraph>Thank you for sending us the information on <emphasis>SDL Trados Studio 2009</emphasis>. + We like your products and think they certainly represent the most powerful translation solution on the market. + We especially like the <component>XML Parser rules</component> options in the + <component>XML</component> filter. It has helped us to set up support for our XML files in a flash. + We have already downloaded the latest version from your Customer Center.</paragraph> + + <paragraph>We would like to order 50 licenses. Please send us a quote. Keep up the good work!</paragraph> + + <!-- The letter's closing phrase.--> + <!-- Restriction: maximum length <= 30 characters --> + <!-- Required --> + <complimentaryClose>Yours sincerely,</complimentaryClose> + + <!-- The author's name.--> + <!-- Restriction: maximum length <= 30 characters --> + <!-- Required --> + <signature>Paul Smith</signature> + + + <!-- The recipient's address.--> + <!-- Required --> + <!-- attribute display may either be true or false --> + <!-- Restriction: company, name, street, zip and town all have maximum length <= 30 characters --> + <address display="false"> + + <!-- Optional field--> + <company>Smith & Company Ltd.</company> + + <!-- name, street, zip and town are required --> + <name>John Smith</name> + <street>Baker Street</street> + <zip>6651</zip> + <town>Smithtown</town> + </address> + +</letter> diff --git a/Klausuren/Sda1/WS2014/Letter_solution/Test/Negative/missingAbout.xml.log b/Klausuren/Sda1/WS2014/Letter_solution/Test/Negative/missingAbout.xml.log new file mode 100644 index 0000000000000000000000000000000000000000..2b17d44a77a7f7d29e956d20dc9b5c8f49b3c7cf --- /dev/null +++ b/Klausuren/Sda1/WS2014/Letter_solution/Test/Negative/missingAbout.xml.log @@ -0,0 +1,2 @@ +file:///ma/goik/Klausur/Letter_solution/Test/Negative/missingAbout.xml:8:11: parse error org.xml.sax.SAXParseException; systemId: file:///ma/goik/Klausur/Letter_solution/Test/Negative/missingAbout.xml; lineNumber: 8; columnNumber: 11; cvc-complex-type.2.4.a: Invalid content was found starting with element 'date'. One of '{about}' is expected. +parsing error diff --git a/Klausuren/Sda1/WS2014/Letter_solution/Test/Negative/missingSignature.xml b/Klausuren/Sda1/WS2014/Letter_solution/Test/Negative/missingSignature.xml new file mode 100644 index 0000000000000000000000000000000000000000..6a72170acb0cc79277024a550656eb120b093327 --- /dev/null +++ b/Klausuren/Sda1/WS2014/Letter_solution/Test/Negative/missingSignature.xml @@ -0,0 +1,55 @@ +<?xml version="1.0" encoding="UTF-8"?> +<letter xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" + xsi:noNamespaceSchemaLocation="../letter.xsd"> + + <!-- A description of the letter's primary intent.--> + <!-- Restriction: maximum length <= 30 characters --> + <!-- Required --> + <about>Order inquiry confirmation</about> + + + <!-- The letter's composition date.--> + <!-- XML schema date type --> + <!-- Required --> + <date>2015-02-19</date> + + <!-- The author's salutation.--> + <!-- Restriction: maximum length <= 30 characters --> + <!-- Required --> + <salutation>Dear Daniel,</salutation> + + <!-- A paragraph within the letter--> + <!-- At least on paragraph must be present --> + <!-- Mixed content of optional "emphasis" and "component" pure text elements --> + + <paragraph>Thank you for sending us the information on <emphasis>SDL Trados Studio 2009</emphasis>. + We like your products and think they certainly represent the most powerful translation solution on the market. + We especially like the <component>XML Parser rules</component> options in the + <component>XML</component> filter. It has helped us to set up support for our XML files in a flash. + We have already downloaded the latest version from your Customer Center.</paragraph> + + <paragraph>We would like to order 50 licenses. Please send us a quote. Keep up the good work!</paragraph> + + <!-- The letter's closing phrase.--> + <!-- Restriction: maximum length <= 30 characters --> + <!-- Required --> + <complimentaryClose>Yours sincerely,</complimentaryClose> + + + <!-- The recipient's address.--> + <!-- Required --> + <!-- attribute display may either be true or false --> + <!-- Restriction: company, name, street, zip and town all have maximum length <= 30 characters --> + <address display="false"> + + <!-- Optional field--> + <company>Smith & Company Ltd.</company> + + <!-- name, street, zip and town are required --> + <name>John Smith</name> + <street>Baker Street</street> + <zip>6651</zip> + <town>Smithtown</town> + </address> + +</letter> diff --git a/Klausuren/Sda1/WS2014/Letter_solution/Test/Negative/missingSignature.xml.log b/Klausuren/Sda1/WS2014/Letter_solution/Test/Negative/missingSignature.xml.log new file mode 100644 index 0000000000000000000000000000000000000000..ab61dc49d2d8f81649545292f3f0283420964d95 --- /dev/null +++ b/Klausuren/Sda1/WS2014/Letter_solution/Test/Negative/missingSignature.xml.log @@ -0,0 +1,2 @@ +file:///ma/goik/Klausur/Letter_solution/Test/Negative/missingSignature.xml:43:30: parse error org.xml.sax.SAXParseException; systemId: file:///ma/goik/Klausur/Letter_solution/Test/Negative/missingSignature.xml; lineNumber: 43; columnNumber: 30; cvc-complex-type.2.4.a: Invalid content was found starting with element 'address'. One of '{signature}' is expected. +parsing error diff --git a/Klausuren/Sda1/WS2014/Letter_solution/Test/Negative/missingZip.xml b/Klausuren/Sda1/WS2014/Letter_solution/Test/Negative/missingZip.xml new file mode 100644 index 0000000000000000000000000000000000000000..44ca45ba927d3bbb64ec685e124da1509977f951 --- /dev/null +++ b/Klausuren/Sda1/WS2014/Letter_solution/Test/Negative/missingZip.xml @@ -0,0 +1,59 @@ +<?xml version="1.0" encoding="UTF-8"?> +<letter xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" + xsi:noNamespaceSchemaLocation="../letter.xsd"> + + <!-- A description of the letter's primary intent.--> + <!-- Restriction: maximum length <= 30 characters --> + <!-- Required --> + <about>Order inquiry confirmation</about> + + + <!-- The letter's composition date.--> + <!-- XML schema date type --> + <!-- Required --> + <date>2015-02-19</date> + + <!-- The author's salutation.--> + <!-- Restriction: maximum length <= 30 characters --> + <!-- Required --> + <salutation>Dear Daniel,</salutation> + + <!-- A paragraph within the letter--> + <!-- At least on paragraph must be present --> + <!-- Mixed content of optional "emphasis" and "component" pure text elements --> + + <paragraph>Thank you for sending us the information on <emphasis>SDL Trados Studio 2009</emphasis>. + We like your products and think they certainly represent the most powerful translation solution on the market. + We especially like the <component>XML Parser rules</component> options in the + <component>XML</component> filter. It has helped us to set up support for our XML files in a flash. + We have already downloaded the latest version from your Customer Center.</paragraph> + + <paragraph>We would like to order 50 licenses. Please send us a quote. Keep up the good work!</paragraph> + + <!-- The letter's closing phrase.--> + <!-- Restriction: maximum length <= 30 characters --> + <!-- Required --> + <complimentaryClose>Yours sincerely,</complimentaryClose> + + <!-- The author's name.--> + <!-- Restriction: maximum length <= 30 characters --> + <!-- Required --> + <signature>Paul Smith</signature> + + + <!-- The recipient's address.--> + <!-- Required --> + <!-- attribute display may either be true or false --> + <!-- Restriction: company, name, street, zip and town all have maximum length <= 30 characters --> + <address display="false"> + + <!-- Optional field--> + <company>Smith & Company Ltd.</company> + + <!-- name, street, zip and town are required --> + <name>John Smith</name> + <street>Baker Street</street> + <town>Smithtown</town> + </address> + +</letter> diff --git a/Klausuren/Sda1/WS2014/Letter_solution/Test/Negative/missingZip.xml.log b/Klausuren/Sda1/WS2014/Letter_solution/Test/Negative/missingZip.xml.log new file mode 100644 index 0000000000000000000000000000000000000000..f7aafdc2520b9e16509f4b1f2a2bd982c92f400e --- /dev/null +++ b/Klausuren/Sda1/WS2014/Letter_solution/Test/Negative/missingZip.xml.log @@ -0,0 +1,2 @@ +file:///ma/goik/Klausur/Letter_solution/Test/Negative/missingZip.xml:56:15: parse error org.xml.sax.SAXParseException; systemId: file:///ma/goik/Klausur/Letter_solution/Test/Negative/missingZip.xml; lineNumber: 56; columnNumber: 15; cvc-complex-type.2.4.a: Invalid content was found starting with element 'town'. One of '{zip}' is expected. +parsing error diff --git a/Klausuren/Sda1/WS2014/Letter_solution/Test/Negative/noParagraph.xml b/Klausuren/Sda1/WS2014/Letter_solution/Test/Negative/noParagraph.xml new file mode 100644 index 0000000000000000000000000000000000000000..736e6fada342e146c3337a0d7c6b95dbdd276002 --- /dev/null +++ b/Klausuren/Sda1/WS2014/Letter_solution/Test/Negative/noParagraph.xml @@ -0,0 +1,48 @@ +<?xml version="1.0" encoding="UTF-8"?> +<letter xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" + xsi:noNamespaceSchemaLocation="../letter.xsd"> + + <!-- A description of the letter's primary intent.--> + <!-- Restriction: maximum length <= 30 characters --> + <!-- Required --> + <about>Order inquiry confirmation</about> + + + <!-- The letter's composition date.--> + <!-- XML schema date type --> + <!-- Required --> + <date>2015-02-19</date> + + <!-- The author's salutation.--> + <!-- Restriction: maximum length <= 30 characters --> + <!-- Required --> + <salutation>Dear Daniel,</salutation> + + <!-- The letter's closing phrase.--> + <!-- Restriction: maximum length <= 30 characters --> + <!-- Required --> + <complimentaryClose>Yours sincerely,</complimentaryClose> + + <!-- The author's name.--> + <!-- Restriction: maximum length <= 30 characters --> + <!-- Required --> + <signature>Paul Smith</signature> + + + <!-- The recipient's address.--> + <!-- Required --> + <!-- attribute display may either be true or false --> + <!-- Restriction: company, name, street, zip and town all have maximum length <= 30 characters --> + <address display="false"> + + <!-- Optional field--> + <company>Smith & Company Ltd.</company> + + <!-- name, street, zip and town are required --> + <name>John Smith</name> + <street>Baker Street</street> + <zip>6651</zip> + <town>Smithtown</town> + </address> + +</letter> diff --git a/Klausuren/Sda1/WS2014/Letter_solution/Test/Negative/noParagraph.xml.log b/Klausuren/Sda1/WS2014/Letter_solution/Test/Negative/noParagraph.xml.log new file mode 100644 index 0000000000000000000000000000000000000000..8613cc22c964e6f44fba0e7cbb258027bcc63dc5 --- /dev/null +++ b/Klausuren/Sda1/WS2014/Letter_solution/Test/Negative/noParagraph.xml.log @@ -0,0 +1,2 @@ +file:///ma/goik/Klausur/Letter_solution/Test/Negative/noParagraph.xml:24:25: parse error org.xml.sax.SAXParseException; systemId: file:///ma/goik/Klausur/Letter_solution/Test/Negative/noParagraph.xml; lineNumber: 24; columnNumber: 25; cvc-complex-type.2.4.a: Invalid content was found starting with element 'complimentaryClose'. One of '{paragraph}' is expected. +parsing error diff --git a/Klausuren/Sda1/WS2014/Letter_solution/Test/Negative/salutation31.xml b/Klausuren/Sda1/WS2014/Letter_solution/Test/Negative/salutation31.xml new file mode 100644 index 0000000000000000000000000000000000000000..f96959a76c06afac5e367b50688f6b947de335b6 --- /dev/null +++ b/Klausuren/Sda1/WS2014/Letter_solution/Test/Negative/salutation31.xml @@ -0,0 +1,60 @@ +<?xml version="1.0" encoding="UTF-8"?> +<letter xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" + xsi:noNamespaceSchemaLocation="../letter.xsd"> + + <!-- A description of the letter's primary intent.--> + <!-- Restriction: maximum length <= 30 characters --> + <!-- Required --> + <about>Order inquiry confirmation</about> + + + <!-- The letter's composition date.--> + <!-- XML schema date type --> + <!-- Required --> + <date>2015-02-19</date> + + <!-- The author's salutation.--> + <!-- Restriction: maximum length <= 30 characters --> + <!-- Required --> + <salutation>012345678901234567890123456789X</salutation> + + <!-- A paragraph within the letter--> + <!-- At least on paragraph must be present --> + <!-- Mixed content of optional "emphasis" and "component" pure text elements --> + + <paragraph>Thank you for sending us the information on <emphasis>SDL Trados Studio 2009</emphasis>. + We like your products and think they certainly represent the most powerful translation solution on the market. + We especially like the <component>XML Parser rules</component> options in the + <component>XML</component> filter. It has helped us to set up support for our XML files in a flash. + We have already downloaded the latest version from your Customer Center.</paragraph> + + <paragraph>We would like to order 50 licenses. Please send us a quote. Keep up the good work!</paragraph> + + <!-- The letter's closing phrase.--> + <!-- Restriction: maximum length <= 30 characters --> + <!-- Required --> + <complimentaryClose>Yours sincerely,</complimentaryClose> + + <!-- The author's name.--> + <!-- Restriction: maximum length <= 30 characters --> + <!-- Required --> + <signature>Paul Smith</signature> + + + <!-- The recipient's address.--> + <!-- Required --> + <!-- attribute display may either be true or false --> + <!-- Restriction: company, name, street, zip and town all have maximum length <= 30 characters --> + <address display="false"> + + <!-- Optional field--> + <company>Smith & Company Ltd.</company> + + <!-- name, street, zip and town are required --> + <name>John Smith</name> + <street>Baker Street</street> + <zip>6651</zip> + <town>Smithtown</town> + </address> + +</letter> diff --git a/Klausuren/Sda1/WS2014/Letter_solution/Test/Negative/salutation31.xml.log b/Klausuren/Sda1/WS2014/Letter_solution/Test/Negative/salutation31.xml.log new file mode 100644 index 0000000000000000000000000000000000000000..bf66f9848603593985cba78689c21f23b09f6410 --- /dev/null +++ b/Klausuren/Sda1/WS2014/Letter_solution/Test/Negative/salutation31.xml.log @@ -0,0 +1,2 @@ +file:///ma/goik/Klausur/Letter_solution/Test/Negative/salutation31.xml:19:61: parse error org.xml.sax.SAXParseException; systemId: file:///ma/goik/Klausur/Letter_solution/Test/Negative/salutation31.xml; lineNumber: 19; columnNumber: 61; cvc-maxLength-valid: Value '012345678901234567890123456789X' with length = '31' is not facet-valid with respect to maxLength '30' for type '#AnonType_salutationletter'. +parsing error diff --git a/Klausuren/Sda1/WS2014/Letter_solution/Test/Negative/wrongDate.xml b/Klausuren/Sda1/WS2014/Letter_solution/Test/Negative/wrongDate.xml new file mode 100644 index 0000000000000000000000000000000000000000..f0b39285b1ad1ac18ef5278a03b6beb72936ae3f --- /dev/null +++ b/Klausuren/Sda1/WS2014/Letter_solution/Test/Negative/wrongDate.xml @@ -0,0 +1,60 @@ +<?xml version="1.0" encoding="UTF-8"?> +<letter xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" + xsi:noNamespaceSchemaLocation="../letter.xsd"> + + <!-- A description of the letter's primary intent.--> + <!-- Restriction: maximum length <= 30 characters --> + <!-- Required --> + <about>Order inquiry confirmation</about> + + + <!-- The letter's composition date.--> + <!-- XML schema date type --> + <!-- Required --> + <date>20.04.2015</date> + + <!-- The author's salutation.--> + <!-- Restriction: maximum length <= 30 characters --> + <!-- Required --> + <salutation>Dear Daniel,</salutation> + + <!-- A paragraph within the letter--> + <!-- At least on paragraph must be present --> + <!-- Mixed content of optional "emphasis" and "component" pure text elements --> + + <paragraph>Thank you for sending us the information on <emphasis>SDL Trados Studio 2009</emphasis>. + We like your products and think they certainly represent the most powerful translation solution on the market. + We especially like the <component>XML Parser rules</component> options in the + <component>XML</component> filter. It has helped us to set up support for our XML files in a flash. + We have already downloaded the latest version from your Customer Center.</paragraph> + + <paragraph>We would like to order 50 licenses. Please send us a quote. Keep up the good work!</paragraph> + + <!-- The letter's closing phrase.--> + <!-- Restriction: maximum length <= 30 characters --> + <!-- Required --> + <complimentaryClose>Yours sincerely,</complimentaryClose> + + <!-- The author's name.--> + <!-- Restriction: maximum length <= 30 characters --> + <!-- Required --> + <signature>Paul Smith</signature> + + + <!-- The recipient's address.--> + <!-- Required --> + <!-- attribute display may either be true or false --> + <!-- Restriction: company, name, street, zip and town all have maximum length <= 30 characters --> + <address display="false"> + + <!-- Optional field--> + <company>Smith & Company Ltd.</company> + + <!-- name, street, zip and town are required --> + <name>John Smith</name> + <street>Baker Street</street> + <zip>6651</zip> + <town>Smithtown</town> + </address> + +</letter> diff --git a/Klausuren/Sda1/WS2014/Letter_solution/Test/Negative/wrongDate.xml.log b/Klausuren/Sda1/WS2014/Letter_solution/Test/Negative/wrongDate.xml.log new file mode 100644 index 0000000000000000000000000000000000000000..d9d7ef50a0db47189ec2ad8a1fb2d38fe015f9eb --- /dev/null +++ b/Klausuren/Sda1/WS2014/Letter_solution/Test/Negative/wrongDate.xml.log @@ -0,0 +1,2 @@ +file:///ma/goik/Klausur/Letter_solution/Test/Negative/wrongDate.xml:14:28: parse error org.xml.sax.SAXParseException; systemId: file:///ma/goik/Klausur/Letter_solution/Test/Negative/wrongDate.xml; lineNumber: 14; columnNumber: 28; cvc-datatype-valid.1.2.1: '20.04.2015' is not a valid value for 'date'. +parsing error diff --git a/Klausuren/Sda1/WS2014/Letter_solution/Test/Positive/displayTrue.xml b/Klausuren/Sda1/WS2014/Letter_solution/Test/Positive/displayTrue.xml new file mode 100644 index 0000000000000000000000000000000000000000..3c28eadaa37c81957866480824e163ad1eda5e04 --- /dev/null +++ b/Klausuren/Sda1/WS2014/Letter_solution/Test/Positive/displayTrue.xml @@ -0,0 +1,60 @@ +<?xml version="1.0" encoding="UTF-8"?> +<letter xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" + xsi:noNamespaceSchemaLocation="../letter.xsd"> + + <!-- A description of the letter's primary intent.--> + <!-- Restriction: maximum length <= 30 characters --> + <!-- Required --> + <about>Order inquiry confirmation</about> + + + <!-- The letter's composition date.--> + <!-- XML schema date type --> + <!-- Required --> + <date>2015-02-19</date> + + <!-- The author's salutation.--> + <!-- Restriction: maximum length <= 30 characters --> + <!-- Required --> + <salutation>Dear Daniel,</salutation> + + <!-- A paragraph within the letter--> + <!-- At least on paragraph must be present --> + <!-- Mixed content of optional "emphasis" and "component" pure text elements --> + + <paragraph>Thank you for sending us the information on <emphasis>SDL Trados Studio 2009</emphasis>. + We like your products and think they certainly represent the most powerful translation solution on the market. + We especially like the <component>XML Parser rules</component> options in the + <component>XML</component> filter. It has helped us to set up support for our XML files in a flash. + We have already downloaded the latest version from your Customer Center.</paragraph> + + <paragraph>We would like to order 50 licenses. Please send us a quote. Keep up the good work!</paragraph> + + <!-- The letter's closing phrase.--> + <!-- Restriction: maximum length <= 30 characters --> + <!-- Required --> + <complimentaryClose>Yours sincerely,</complimentaryClose> + + <!-- The author's name.--> + <!-- Restriction: maximum length <= 30 characters --> + <!-- Required --> + <signature>Paul Smith</signature> + + + <!-- The recipient's address.--> + <!-- Required --> + <!-- attribute display may either be true or false --> + <!-- Restriction: company, name, street, zip and town all have maximum length <= 30 characters --> + <address display="true"> + + <!-- Optional field--> + <company>Smith & Company Ltd.</company> + + <!-- name, street, zip and town are required --> + <name>John Smith</name> + <street>Baker Street</street> + <zip>6651</zip> + <town>Smithtown</town> + </address> + +</letter> diff --git a/Klausuren/Sda1/WS2014/Letter_solution/Test/Positive/lettersample.xml b/Klausuren/Sda1/WS2014/Letter_solution/Test/Positive/lettersample.xml new file mode 100644 index 0000000000000000000000000000000000000000..9e20400975b8992b861b1f8ac5c89d6ed30d8748 --- /dev/null +++ b/Klausuren/Sda1/WS2014/Letter_solution/Test/Positive/lettersample.xml @@ -0,0 +1,60 @@ +<?xml version="1.0" encoding="UTF-8"?> +<letter xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" + xsi:noNamespaceSchemaLocation="../letter.xsd"> + + <!-- A description of the letter's primary intent.--> + <!-- Restriction: maximum length <= 30 characters --> + <!-- Required --> + <about>Order inquiry confirmation</about> + + + <!-- The letter's composition date.--> + <!-- XML schema date type --> + <!-- Required --> + <date>2015-02-19</date> + + <!-- The author's salutation.--> + <!-- Restriction: maximum length <= 30 characters --> + <!-- Required --> + <salutation>Dear Daniel,</salutation> + + <!-- A paragraph within the letter--> + <!-- At least on paragraph must be present --> + <!-- Mixed content of optional "emphasis" and "component" pure text elements --> + + <paragraph>Thank you for sending us the information on <emphasis>SDL Trados Studio 2009</emphasis>. + We like your products and think they certainly represent the most powerful translation solution on the market. + We especially like the <component>XML Parser rules</component> options in the + <component>XML</component> filter. It has helped us to set up support for our XML files in a flash. + We have already downloaded the latest version from your Customer Center.</paragraph> + + <paragraph>We would like to order 50 licenses. Please send us a quote. Keep up the good work!</paragraph> + + <!-- The letter's closing phrase.--> + <!-- Restriction: maximum length <= 30 characters --> + <!-- Required --> + <complimentaryClose>Yours sincerely,</complimentaryClose> + + <!-- The author's name.--> + <!-- Restriction: maximum length <= 30 characters --> + <!-- Required --> + <signature>Paul Smith</signature> + + + <!-- The recipient's address.--> + <!-- Required --> + <!-- attribute display may either be true or false --> + <!-- Restriction: company, name, street, zip and town all have maximum length <= 30 characters --> + <address display="false"> + + <!-- Optional field--> + <company>Smith & Company Ltd.</company> + + <!-- name, street, zip and town are required --> + <name>John Smith</name> + <street>Baker Street</street> + <zip>6651</zip> + <town>Smithtown</town> + </address> + +</letter> diff --git a/Klausuren/Sda1/WS2014/Letter_solution/Test/Positive/missingCompany.xml b/Klausuren/Sda1/WS2014/Letter_solution/Test/Positive/missingCompany.xml new file mode 100644 index 0000000000000000000000000000000000000000..8edb4659a7357b9ee4ac675ff6bfcaf39ded3cc9 --- /dev/null +++ b/Klausuren/Sda1/WS2014/Letter_solution/Test/Positive/missingCompany.xml @@ -0,0 +1,57 @@ +<?xml version="1.0" encoding="UTF-8"?> +<letter xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" + xsi:noNamespaceSchemaLocation="../letter.xsd"> + + <!-- A description of the letter's primary intent.--> + <!-- Restriction: maximum length <= 30 characters --> + <!-- Required --> + <about>Order inquiry confirmation</about> + + + <!-- The letter's composition date.--> + <!-- XML schema date type --> + <!-- Required --> + <date>2015-02-19</date> + + <!-- The author's salutation.--> + <!-- Restriction: maximum length <= 30 characters --> + <!-- Required --> + <salutation>Dear Daniel,</salutation> + + <!-- A paragraph within the letter--> + <!-- At least on paragraph must be present --> + <!-- Mixed content of optional "emphasis" and "component" pure text elements --> + + <paragraph>Thank you for sending us the information on <emphasis>SDL Trados Studio 2009</emphasis>. + We like your products and think they certainly represent the most powerful translation solution on the market. + We especially like the <component>XML Parser rules</component> options in the + <component>XML</component> filter. It has helped us to set up support for our XML files in a flash. + We have already downloaded the latest version from your Customer Center.</paragraph> + + <paragraph>We would like to order 50 licenses. Please send us a quote. Keep up the good work!</paragraph> + + <!-- The letter's closing phrase.--> + <!-- Restriction: maximum length <= 30 characters --> + <!-- Required --> + <complimentaryClose>Yours sincerely,</complimentaryClose> + + <!-- The author's name.--> + <!-- Restriction: maximum length <= 30 characters --> + <!-- Required --> + <signature>Paul Smith</signature> + + + <!-- The recipient's address.--> + <!-- Required --> + <!-- attribute display may either be true or false --> + <!-- Restriction: company, name, street, zip and town all have maximum length <= 30 characters --> + <address display="false"> + + <!-- name, street, zip and town are required --> + <name>John Smith</name> + <street>Baker Street</street> + <zip>6651</zip> + <town>Smithtown</town> + </address> + +</letter> diff --git a/Klausuren/Sda1/WS2014/Letter_solution/Test/report.log b/Klausuren/Sda1/WS2014/Letter_solution/Test/report.log new file mode 100644 index 0000000000000000000000000000000000000000..5cf8fb98804a834854926213ac7c4abecd182294 --- /dev/null +++ b/Klausuren/Sda1/WS2014/Letter_solution/Test/report.log @@ -0,0 +1,36 @@ +Testing invalid file Negative/displayNoBoolean.xml +file:///ma/goik/Klausur/Letter_solution/Test/Negative/displayNoBoolean.xml:48:27: parse error org.xml.sax.SAXParseException; systemId: file:///ma/goik/Klausur/Letter_solution/Test/Negative/displayNoBoolean.xml; lineNumber: 48; columnNumber: 27; cvc-datatype-valid.1.2.1: 'no' is not a valid value for 'boolean'. +parsing error +File expectedly flagged as invalid, adding 1 point +____________________________________________________ +Testing invalid file Negative/missingSignature.xml +file:///ma/goik/Klausur/Letter_solution/Test/Negative/missingSignature.xml:43:30: parse error org.xml.sax.SAXParseException; systemId: file:///ma/goik/Klausur/Letter_solution/Test/Negative/missingSignature.xml; lineNumber: 43; columnNumber: 30; cvc-complex-type.2.4.a: Invalid content was found starting with element 'address'. One of '{signature}' is expected. +parsing error +File expectedly flagged as invalid, adding 1 point +____________________________________________________ +Testing invalid file Negative/noParagraph.xml +file:///ma/goik/Klausur/Letter_solution/Test/Negative/noParagraph.xml:24:25: parse error org.xml.sax.SAXParseException; systemId: file:///ma/goik/Klausur/Letter_solution/Test/Negative/noParagraph.xml; lineNumber: 24; columnNumber: 25; cvc-complex-type.2.4.a: Invalid content was found starting with element 'complimentaryClose'. One of '{paragraph}' is expected. +parsing error +File expectedly flagged as invalid, adding 1 point +____________________________________________________ +Testing invalid file Negative/wrongDate.xml +file:///ma/goik/Klausur/Letter_solution/Test/Negative/wrongDate.xml:14:28: parse error org.xml.sax.SAXParseException; systemId: file:///ma/goik/Klausur/Letter_solution/Test/Negative/wrongDate.xml; lineNumber: 14; columnNumber: 28; cvc-datatype-valid.1.2.1: '20.04.2015' is not a valid value for 'date'. +parsing error +File expectedly flagged as invalid, adding 1 point +____________________________________________________ +Testing invalid file Negative/missingAbout.xml +file:///ma/goik/Klausur/Letter_solution/Test/Negative/missingAbout.xml:8:11: parse error org.xml.sax.SAXParseException; systemId: file:///ma/goik/Klausur/Letter_solution/Test/Negative/missingAbout.xml; lineNumber: 8; columnNumber: 11; cvc-complex-type.2.4.a: Invalid content was found starting with element 'date'. One of '{about}' is expected. +parsing error +File expectedly flagged as invalid, adding 1 point +____________________________________________________ +Testing invalid file Negative/missingZip.xml +file:///ma/goik/Klausur/Letter_solution/Test/Negative/missingZip.xml:56:15: parse error org.xml.sax.SAXParseException; systemId: file:///ma/goik/Klausur/Letter_solution/Test/Negative/missingZip.xml; lineNumber: 56; columnNumber: 15; cvc-complex-type.2.4.a: Invalid content was found starting with element 'town'. One of '{zip}' is expected. +parsing error +File expectedly flagged as invalid, adding 1 point +____________________________________________________ +Testing invalid file Negative/salutation31.xml +file:///ma/goik/Klausur/Letter_solution/Test/Negative/salutation31.xml:19:61: parse error org.xml.sax.SAXParseException; systemId: file:///ma/goik/Klausur/Letter_solution/Test/Negative/salutation31.xml; lineNumber: 19; columnNumber: 61; cvc-maxLength-valid: Value '012345678901234567890123456789X' with length = '31' is not facet-valid with respect to maxLength '30' for type 'shortString'. +parsing error +File expectedly flagged as invalid, adding 1 point +____________________________________________________ +Summary: 7 out of 10 points have been reached diff --git a/Klausuren/Sda1/WS2014/Letter_solution/Test/xsdcheck.pl b/Klausuren/Sda1/WS2014/Letter_solution/Test/xsdcheck.pl new file mode 100755 index 0000000000000000000000000000000000000000..ef3fc6217736563f2757038411f5c12a60a1aa43 --- /dev/null +++ b/Klausuren/Sda1/WS2014/Letter_solution/Test/xsdcheck.pl @@ -0,0 +1,73 @@ +#!/usr/bin/perl + +my $xsdFile = $ARGV[0]; +my $reportFile = $xsdFile . ".log"; + +system("ln -sf $xsdFile letter.xsd"); + + + +my %negatives = ( +"displayNoBoolean", "'no' is not a valid value for 'boolean'.", +"missingSignature", "Invalid content was found starting with element 'address'. One of '{signature}' is expected.", +"noParagraph", "Invalid content was found starting with element 'complimentaryClose'. One of '{paragraph}' is expected.", +"wrongDate", "'20.04.2015' is not a valid value for 'date'.", +"missingAbout", "Invalid content was found starting with element 'date'. One of '{about}' is expected.", +"missingZip", "Invalid content was found starting with element 'town'. One of '{zip}' is expected.", +"salutation31", "Value '012345678901234567890123456789X' with length = '31' is not facet-valid with respect to maxLength '30' " +); + +my @positive = ("missingCompany", "displayTrue", "lettersample"); + +system("rm -f $reportFile"); + +my $points = 0; + +foreach my $negTest (keys(%negatives)) { + my $xmlInputFile = "Negative/" . $negTest . ".xml"; + my $xmlInputLogFile = $xmlInputFile . ".log"; + + system ("echo Testing invalid file $xmlInputFile >> $reportFile"); + system("xmlparse -V -s $xmlInputFile > $xmlInputLogFile 2>&1"); + my $exitValue = $? >> 8; + if (0 != $exitValue) { + my $errOutput = `cat $xmlInputLogFile|head -1`; + chop($errOutput); + my @errMsgComponents = split("[ \t]*:[ \t]*", $errOutput); + my $errMsg = @errMsgComponents[$#errMsgComponents]; + my $expectedErrorMessage = $negatives{$negTest}; + if (index($errMsg, $expectedErrorMessage) != -1) { + system ("echo Expected error message: $errMsg, adding 1 point >> $reportFile"); + $points++ + } else { + system ("echo expected $expectedErrorMessage not found in $errMsg >> $reportFile"); + } + + } else { + system ("echo Invalid file not being flagged as invalid, schema error >> $reportFile"); + } + +# system("cat $xmlInputLogFile >> $reportFile"); + + system ("echo ____________________________________________________ >> $reportFile"); +} + +foreach my $posTest (@positive) { + my $xmlInputFile = "Positive/" . $posTest . ".xml"; + + system ("echo Testing valid file $xmlInputFile >> $reportFile"); + system("xmlparse -V -s $xmlInputFile >> $reportFile 2>> $reportFile"); + my $exitValue = $? >> 8; + if (0 == $exitValue) { + system ("echo Validity confirmed expectedly, adding 1 point >> $reportFile"); + $points++ + } else { + system ("echo Valid File flagged as invalid, schema error >> $reportFile"); + } + system ("echo ____________________________________________________ >> $reportFile"); +} + +system ("echo Summary: $points out of 10 points have been reached >> $reportFile"); + + +#end diff --git a/Klausuren/Sda1/WS2014/Letter_solution/description.xhtml b/Klausuren/Sda1/WS2014/Letter_solution/description.xhtml new file mode 100644 index 0000000000000000000000000000000000000000..0ed096c6512c5ff357fb152b979049ceb14f0598 --- /dev/null +++ b/Klausuren/Sda1/WS2014/Letter_solution/description.xhtml @@ -0,0 +1,47 @@ +<?xml version="1.0" encoding="UTF-8"?> +<!DOCTYPE html> +<html xml:lang="en" xmlns="http://www.w3.org/1999/xhtml"> + <head> + <title></title> + </head> + + <body><h1>Description</h1><p>This exercise deals with business letters. You + are expected to solve two independent tasks:</p><ol type="i"> + <li><p>Infer an XML schema describing letters.</p></li> + + <li><p>Provide an XSLT file transforming letter instances to + Xhtml.</p></li> + </ol><h1>Preparations</h1><p>Download <a + href="/files/goik/letter_6tuzgFF+kQxxYKKf3/letter.zip" + target="_blank">letter.zip</a> and import it as an Eclipse project <span + style="color:red;">(Not Maven!)</span> into your workspace. This project + contains:</p><ol> + <li><p>A yet incomplete schema skeleton file <code>letter.xsd</code> + describing business letters.</p></li> + + <li><p>A file <code>lettersample.xml</code> to give you an idea + regarding the intended schema.</p></li> + + <li><p>A skeleton XSLT file <code>letter2html.xsl</code> transforming + instances of <code>letter.xsd</code> to Xhtml.</p></li> + + <li><p>A file <code>lettersample.xhtml</code> showing the intended + outcome from <code>lettersample.xml</code>.</p></li> + </ol><h1>Task 1</h1><p>Complete the implementation of + <code>letter.xsd</code>.</p><p><span style="color:red;">Hint:</span> The + sample instance <code>lettersample.xml</code> does contain detailed XML + comments regarding data types, multiplicity and so on.</p><h1>Task + 2</h1><p>Complete the implementation of <code>letter2html.xsl</code>. The + file <code>lettersample.xml</code> shows the intended output. Your XSLT is + expected to transform other instances in a corresponding + fashion.</p><p><addresses> shall be excluded if both the following two + conditions hold simultaneously:</p><ul> + <li><code><address display="false"></code></li> + + <li>An <code><address></code> does not contain the optional + <code><company></code> child element.</li> + </ul><p>Upon completion zip up your project directory and upload it to the + E-learning system. Mind the remaining time! <b style="color:red;">When the + examination terminates no subsequent uploads will be + possible!</b></p></body> +</html> diff --git a/Klausuren/Sda1/WS2014/Letter_solution/letter-result.html b/Klausuren/Sda1/WS2014/Letter_solution/letter-result.html new file mode 100644 index 0000000000000000000000000000000000000000..1179d90d964070ce0524d323a05547844cefc2d3 --- /dev/null +++ b/Klausuren/Sda1/WS2014/Letter_solution/letter-result.html @@ -0,0 +1,79 @@ +<?xml version="1.0" encoding="UTF-8"?><html xmlns:test="http://www.jenitennison.com/xslt/unit-test" xmlns="http://www.w3.org/1999/xhtml"> + <head> + <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /> + <title>Test Report for ma/goik/Klausur/Letter_solution/letter2html.xsl (passed:2 / pending:0 / failed:0 / total:2)</title> + <link rel="stylesheet" type="text/css" href="file:/usr/share/eclipseLunaErmaster/dropins/oxygenxml.oxygen_16.1/plugins/com.oxygenxml.editor_16.1.0.v2014100319/frameworks/xspec/src/reporter/test-report.css" /> + </head> + <body> + <h1>Test Report</h1> + <p xmlns:oxy="http://www.oxygenxml.com/xslt/xspec">Stylesheet: <a href="file:/ma/goik/Klausur/Letter_solution/letter2html.xsl">ma/goik/Klausur/Letter_solution/letter2html.xsl</a></p> + <p xmlns:oxy="http://www.oxygenxml.com/xslt/xspec">Tested: 17 February 2015 at 16:45</p> + <h2 xmlns:oxy="http://www.oxygenxml.com/xslt/xspec">Contents</h2> + <table xmlns:oxy="http://www.oxygenxml.com/xslt/xspec" class="xspec"> + <col width="80%" /> + <col width="5%" /> + <col width="5%" /> + <col width="5%" /> + <col width="5%" /> + <thead> + <tr> + <th></th> + <th class="result">passed:2</th> + <th class="result">pending:0</th> + <th class="result">failed:0</th> + <th class="result">total:2</th> + </tr> + </thead> + <tbody> + <tr class="successful"> + <th><a href="#d4e4">testing address to be included</a></th> + <th class="result">1</th> + <th class="result">0</th> + <th class="result">0</th> + <th class="result">1</th> + </tr> + <tr class="successful"> + <th><a href="#d4e72">testing address to be included</a></th> + <th class="result">1</th> + <th class="result">0</th> + <th class="result">0</th> + <th class="result">1</th> + </tr> + </tbody> + </table> + <div xmlns:oxy="http://www.oxygenxml.com/xslt/xspec" id="d4e4"> + <h2 class="successful">testing address to be included<span class="scenario-totals">passed:1 / pending:0 / failed:0 / total:1</span></h2> + <table class="xspec" id="t-d4e4"> + <col width="80%" /> + <col width="20%" /> + <tbody> + <tr class="successful"> + <th>testing address to be included</th> + <th>passed:1 / pending:0 / failed:0 / total:1</th> + </tr> + <tr class="successful"> + <td>The sender's address</td> + <td>Success</td> + </tr> + </tbody> + </table> + </div> + <div xmlns:oxy="http://www.oxygenxml.com/xslt/xspec" id="d4e72"> + <h2 class="successful">testing address to be included<span class="scenario-totals">passed:1 / pending:0 / failed:0 / total:1</span></h2> + <table class="xspec" id="t-d4e72"> + <col width="80%" /> + <col width="20%" /> + <tbody> + <tr class="successful"> + <th>testing address to be included</th> + <th>passed:1 / pending:0 / failed:0 / total:1</th> + </tr> + <tr class="successful"> + <td>The sender's address</td> + <td>Success</td> + </tr> + </tbody> + </table> + </div> + </body> +</html> \ No newline at end of file diff --git a/Klausuren/Sda1/WS2014/Letter_solution/letter.xsd b/Klausuren/Sda1/WS2014/Letter_solution/letter.xsd new file mode 100644 index 0000000000000000000000000000000000000000..a20ca38aa2b72df9f20569146a9fcb76574edd3d --- /dev/null +++ b/Klausuren/Sda1/WS2014/Letter_solution/letter.xsd @@ -0,0 +1,47 @@ +<?xml version="1.0" encoding="UTF-8"?> +<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" elementFormDefault="qualified"> + + + <xs:simpleType name="shortString"> + <xs:restriction base="xs:string"> + <xs:maxLength value="30"/> + </xs:restriction> + </xs:simpleType> + + <xs:element name="paragraph"> + <xs:complexType mixed="true"> + <xs:choice minOccurs="0" maxOccurs="unbounded"> + <xs:element name="emphasis" type="xs:string"/> + <xs:element name="component" type="xs:string"/> + </xs:choice> + </xs:complexType> + </xs:element> + + <xs:element name="address"> + <xs:complexType> + <xs:sequence> + <xs:element name="company" type="shortString" minOccurs="0"/> + <xs:element name="name" type="shortString"/> + <xs:element name="street" type="shortString"/> + <xs:element name="zip" type="shortString"/> + <xs:element name="town" type="shortString"/> + </xs:sequence> + <xs:attribute name="display" type="xs:boolean"/> + </xs:complexType> + </xs:element> + + <xs:element name="letter"> + <xs:complexType> + <xs:sequence> + <xs:element name="about" type="shortString"/> + <xs:element name="date" type="xs:date"/> + <xs:element name="salutation" type="shortString"/> + <xs:element ref="paragraph" maxOccurs="unbounded"/> + <xs:element name="complimentaryClose" type="shortString"/> + <xs:element name="signature" type="shortString"/> + <xs:element ref="address"/> + </xs:sequence> + </xs:complexType> + </xs:element> + +</xs:schema> diff --git a/Klausuren/Sda1/WS2014/Letter_solution/letter.xsd.log b/Klausuren/Sda1/WS2014/Letter_solution/letter.xsd.log new file mode 100644 index 0000000000000000000000000000000000000000..c0b8e7e90da91f90ec3cbee381d40164d1cac5b8 --- /dev/null +++ b/Klausuren/Sda1/WS2014/Letter_solution/letter.xsd.log @@ -0,0 +1,34 @@ +Testing invalid file Negative/missingZip.xml +Expected error message: Invalid content was found starting with element town. One of {zip} is expected., adding 1 point +____________________________________________________ +Testing invalid file Negative/salutation31.xml +Expected error message: Value 012345678901234567890123456789X with length = 31 is not facet-valid with respect to maxLength 30 for type shortString., adding 1 point +____________________________________________________ +Testing invalid file Negative/missingSignature.xml +Expected error message: Invalid content was found starting with element address. One of {signature} is expected., adding 1 point +____________________________________________________ +Testing invalid file Negative/displayNoBoolean.xml +Expected error message: no is not a valid value for boolean., adding 1 point +____________________________________________________ +Testing invalid file Negative/wrongDate.xml +Expected error message: 20.04.2015 is not a valid value for date., adding 1 point +____________________________________________________ +Testing invalid file Negative/noParagraph.xml +Expected error message: Invalid content was found starting with element complimentaryClose. One of {paragraph} is expected., adding 1 point +____________________________________________________ +Testing invalid file Negative/missingAbout.xml +Expected error message: Invalid content was found starting with element date. One of {about} is expected., adding 1 point +____________________________________________________ +Testing valid file Positive/missingCompany.xml +Parsing was successfull +Valid File flagged expectedly, adding 1 point +____________________________________________________ +Testing valid file Positive/displayTrue.xml +Parsing was successfull +Valid File flagged expectedly, adding 1 point +____________________________________________________ +Testing valid file Positive/lettersample.xml +Parsing was successfull +Valid File flagged expectedly, adding 1 point +____________________________________________________ +Summary: 10 out of 10 points have been reached diff --git a/Klausuren/Sda1/WS2014/Letter_solution/letter2html.xsl b/Klausuren/Sda1/WS2014/Letter_solution/letter2html.xsl new file mode 100644 index 0000000000000000000000000000000000000000..c91be6a9c71fcb36fc6a838b5d62f5d84006cdf2 --- /dev/null +++ b/Klausuren/Sda1/WS2014/Letter_solution/letter2html.xsl @@ -0,0 +1,83 @@ +<?xml version="1.0" encoding="UTF-8"?> +<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" + xmlns:xs="http://www.w3.org/2001/XMLSchema" + xmlns="http://www.w3.org/1999/xhtml" + exclude-result-prefixes="xs" + version="2.0"> + + <xsl:output method="xhtml" indent="yes" /> + + <xsl:template match="/letter"> + + <html > + <head> + <title> + <xsl:text>Content: </xsl:text> + <xsl:value-of select="about"/> + </title> + </head> + <body> + + + <xsl:apply-templates select="address[@display='true' or company]"/> + + <dl> + <dt>Date:</dt> + <dd> + <b> + <xsl:value-of select="date"/> + </b> + </dd> + <dt>From:</dt> + <dd> + <b> + <xsl:value-of select="signature"/> + </b> + </dd> + <dt>Content:</dt> + <dd> + <b> + <xsl:value-of select="about"/> + </b> + </dd> + </dl> + + <xsl:apply-templates select="paragraph|complimentaryClose|signature"/> + + </body> + </html> + </xsl:template> + + <xsl:template match="address"> + <address> + <xsl:for-each select="*"> + <xsl:value-of select="."/> + <br/> + </xsl:for-each> + + </address> + </xsl:template> + + <xsl:template match="signature"> + <p style="text-align: center;"><b> + <xsl:value-of select="."/> + </b></p> + </xsl:template> + + <xsl:template match="paragraph|complimentaryClose"> + <p><xsl:apply-templates select="text()|*"/></p> + </xsl:template> + + <xsl:template match="emphasis"> + <em style="color:red;"> + <xsl:value-of select="."/> + </em> + </xsl:template> + + <xsl:template match="component"> + <em style="color:red;"> + <xsl:value-of select="."/> + </em> + </xsl:template> + +</xsl:stylesheet> \ No newline at end of file diff --git a/Klausuren/Sda1/WS2014/Letter_solution/lettersample.xhtml b/Klausuren/Sda1/WS2014/Letter_solution/lettersample.xhtml new file mode 100644 index 0000000000000000000000000000000000000000..baad117af20cf52145ee32d2e06b65eae34d9da1 --- /dev/null +++ b/Klausuren/Sda1/WS2014/Letter_solution/lettersample.xhtml @@ -0,0 +1,27 @@ +<?xml version="1.0" encoding="UTF-8"?><html xmlns="http://www.w3.org/1999/xhtml"> + <head> + <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /> + <title>Content: Order inquiry confirmation</title> + </head> + <body> + <address>Smith & Company Ltd.<br />John Smith<br />Baker Street<br />6651<br />Smithtown<br /></address> + <dl> + <dt>Date:</dt> + <dd><b>2015-02-19</b></dd> + <dt>From:</dt> + <dd><b>Paul Smith</b></dd> + <dt>Content:</dt> + <dd><b>Order inquiry confirmation</b></dd> + </dl> + <p>Thank you for sending us the information on <em style="color:red;">SDL Trados Studio 2009</em>. + We like your products and think they certainly represent the most powerful translation + solution on the market. + We especially like the <em style="color:red;">XML Parser rules</em> options in the + <em style="color:red;">XML</em> filter. It has helped us to set up support for our XML files in a flash. + We have already downloaded the latest version from your Customer Center. + </p> + <p>We would like to order 50 licenses. Please send us a quote. Keep up the good work!</p> + <p>Yours sincerely,</p> + <p style="text-align: center;"><b>Paul Smith</b></p> + </body> +</html> \ No newline at end of file diff --git a/Klausuren/Sda1/WS2014/Letter_solution/lettersample.xml b/Klausuren/Sda1/WS2014/Letter_solution/lettersample.xml new file mode 100644 index 0000000000000000000000000000000000000000..13aeb3d3d2054e1f554cf86e0258b29a8460a61c --- /dev/null +++ b/Klausuren/Sda1/WS2014/Letter_solution/lettersample.xml @@ -0,0 +1,60 @@ +<?xml version="1.0" encoding="UTF-8"?> +<letter xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" + xsi:noNamespaceSchemaLocation="letter.xsd"> + + <!-- A description of the letter's primary intent.--> + <!-- Restriction: maximum length <= 30 characters --> + <!-- Required --> + <about>Order inquiry confirmation</about> + + + <!-- The letter's composition date.--> + <!-- XML schema date type --> + <!-- Required --> + <date>2015-02-19</date> + + <!-- The author's salutation.--> + <!-- Restriction: maximum length <= 30 characters --> + <!-- Required --> + <salutation>Dear Daniel,</salutation> + + <!-- A paragraph within the letter--> + <!-- At least on paragraph must be present --> + <!-- Mixed content of optional "emphasis" and "component" pure text elements --> + + <paragraph>Thank you for sending us the information on <emphasis>SDL Trados Studio 2009</emphasis>. + We like your products and think they certainly represent the most powerful translation solution on the market. + We especially like the <component>XML Parser rules</component> options in the + <component>XML</component> filter. It has helped us to set up support for our XML files in a flash. + We have already downloaded the latest version from your Customer Center.</paragraph> + + <paragraph>We would like to order 50 licenses. Please send us a quote. Keep up the good work!</paragraph> + + <!-- The letter's closing phrase.--> + <!-- Restriction: maximum length <= 30 characters --> + <!-- Required --> + <complimentaryClose>Yours sincerely,</complimentaryClose> + + <!-- The author's name.--> + <!-- Restriction: maximum length <= 30 characters --> + <!-- Required --> + <signature>Paul Smith</signature> + + + <!-- The recipient's address.--> + <!-- Required --> + <!-- attribute display may either be true or false --> + <!-- Restriction: company, name, street, zip and town all have maximum length <= 30 characters --> + <address display="false"> + + <!-- Optional field--> + <company>Smith & Company Ltd.</company> + + <!-- name, street, zip and town are required --> + <name>John Smith</name> + <street>Baker Street</street> + <zip>6651</zip> + <town>Smithtown</town> + </address> + +</letter> \ No newline at end of file diff --git a/Klausuren/Sda1/WS2014/Rewriteprepared/.gitignore b/Klausuren/Sda1/WS2014/Rewriteprepared/.gitignore new file mode 100644 index 0000000000000000000000000000000000000000..a1c3ab4d08c0f9f91918f21c730272a4711885e8 --- /dev/null +++ b/Klausuren/Sda1/WS2014/Rewriteprepared/.gitignore @@ -0,0 +1,4 @@ +/target/ +/.settings/ +.classpath +.project diff --git a/Klausuren/Sda1/WS2014/Rewriteprepared/Sql/schema.sql b/Klausuren/Sda1/WS2014/Rewriteprepared/Sql/schema.sql new file mode 100644 index 0000000000000000000000000000000000000000..205cd9918ab7aa9b89b8dbd413c99b455963bfb5 --- /dev/null +++ b/Klausuren/Sda1/WS2014/Rewriteprepared/Sql/schema.sql @@ -0,0 +1,10 @@ +DROP TABLE IF EXISTS Customers; + +CREATE TABLE Customers ( + uidNumber INTEGER NOT NULL AUTO_INCREMENT PRIMARY KEY, + uid CHAR(20) NOT NULL UNIQUE, + cname VARCHAR(255) NOT NULL +); + +INSERT INTO Customers (uid, cname) VALUES ('jim', 'Jim Bone'); +INSERT INTO Customers (uid, cname) VALUES ('eve', 'Eve Stone'); diff --git a/Klausuren/Sda1/WS2014/Rewriteprepared/pom.xml b/Klausuren/Sda1/WS2014/Rewriteprepared/pom.xml new file mode 100644 index 0000000000000000000000000000000000000000..ca5f956fb44fd604333316951ce1a64e1ee00f38 --- /dev/null +++ b/Klausuren/Sda1/WS2014/Rewriteprepared/pom.xml @@ -0,0 +1,67 @@ +<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</groupId> + <artifactId>rewriteprepared</artifactId> + <version>0.8</version> + <packaging>jar</packaging> + + <name>rewriteprepared</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.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>mysql</groupId> + <artifactId>mysql-connector-java</artifactId> + <version>5.1.34</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> + + </plugins> + </build> +</project> diff --git a/Klausuren/Sda1/WS2014/Rewriteprepared/src/main/resources/log4j2.xml b/Klausuren/Sda1/WS2014/Rewriteprepared/src/main/resources/log4j2.xml new file mode 100644 index 0000000000000000000000000000000000000000..56a4914d9da50f3e03cc307aeda9dc0d5fd51aab --- /dev/null +++ b/Klausuren/Sda1/WS2014/Rewriteprepared/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="%d %-5p [%t] %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.mi.sda1.reewriteprepared.App" level="debug"> + <AppenderRef ref="A1"/> + </Logger> + <Root level="info"> + <AppenderRef ref="STDOUT"/> + </Root> + </Loggers> +</Configuration> \ No newline at end of file diff --git a/Klausuren/Sda1/WS2014/reewriteprepared_solution/.gitignore b/Klausuren/Sda1/WS2014/reewriteprepared_solution/.gitignore new file mode 100644 index 0000000000000000000000000000000000000000..a1c3ab4d08c0f9f91918f21c730272a4711885e8 --- /dev/null +++ b/Klausuren/Sda1/WS2014/reewriteprepared_solution/.gitignore @@ -0,0 +1,4 @@ +/target/ +/.settings/ +.classpath +.project diff --git a/Klausuren/Sda1/WS2014/reewriteprepared_solution/Sql/schema.sql b/Klausuren/Sda1/WS2014/reewriteprepared_solution/Sql/schema.sql new file mode 100644 index 0000000000000000000000000000000000000000..205cd9918ab7aa9b89b8dbd413c99b455963bfb5 --- /dev/null +++ b/Klausuren/Sda1/WS2014/reewriteprepared_solution/Sql/schema.sql @@ -0,0 +1,10 @@ +DROP TABLE IF EXISTS Customers; + +CREATE TABLE Customers ( + uidNumber INTEGER NOT NULL AUTO_INCREMENT PRIMARY KEY, + uid CHAR(20) NOT NULL UNIQUE, + cname VARCHAR(255) NOT NULL +); + +INSERT INTO Customers (uid, cname) VALUES ('jim', 'Jim Bone'); +INSERT INTO Customers (uid, cname) VALUES ('eve', 'Eve Stone'); diff --git a/Klausuren/Sda1/WS2014/reewriteprepared_solution/description.xhtml b/Klausuren/Sda1/WS2014/reewriteprepared_solution/description.xhtml new file mode 100644 index 0000000000000000000000000000000000000000..6010c5ffd143756af8a9073b6f6d14744e5c4341 --- /dev/null +++ b/Klausuren/Sda1/WS2014/reewriteprepared_solution/description.xhtml @@ -0,0 +1,98 @@ +<?xml version="1.0" encoding="UTF-8"?> +<!DOCTYPE html> +<html xml:lang="de" xmlns="http://www.w3.org/1999/xhtml"> + <head> + <title></title> + </head> + + <body><h1>Description</h1><p>Your boss returns from a week-end seminar + related to software security. He was taught about SQL injection attacks und + is now very concerned about possible security flaws. As a result you get + assigned to a new task force: </p><ol type="i"> + <li>replacing all <a + href="http://docs.oracle.com/javase/8/docs/api/java/sql/Statement.html" + target="_blank">java.sql.Statement</a> instances by <a + href="http://docs.oracle.com/javase/8/docs/api/java/sql/PreparedStatement.html" + target="_blank">java.sql.PreparedStatement</a> instances within the + company's codebase.</li> + + <li>Correcting transactional behaviour.</li> + </ol><h1>Preparations</h1><p>Download and unzip <a + href="/files/goik/rewriteprepared_uzewfdzc532JJg+_WWaq/rewriteprepared.zip" + target="_blank">rewriteprepared.zip</a> into your Eclipse workspace. Import + the resulting Directory <code>Rewriteprepared</code> as a Maven project into + Eclipse. This project contains:</p><ol> + <li><p>A class + <code>de.hdm_stuttgart.mi.sda1.reewriteprepared.rdbms.CustomerInsert</code>. + The method <code>boolean conditionallyInserCustomer (final String uid, + final String cname)</code>contains a Javadoc comment describing its + semantics.</p><p>Read this description until you fully understand its + meaning.</p></li> + + <li><p>A SQL file <code>Sql/schema.sql</code> containing a database + table definition plus some sample data <code>INSERT</code> + statements.</p><p>These SQL statements may initialize your local Mysql + server using Eclipse's database tools.</p></li> + + <li><p>An executable de.hdm_stuttgart.mi.sda1.reewriteprepared.Driver + class for manual insertion of customers.</p><p><span + style="color:red;">Beware: </span>Executing this one twice will result + in an error when trying to insert the same customer record for a second + time.</p></li> + + <li><p>A simple Junit test + <code>de.hdm_stuttgart.mi.sda1.reewriteprepared.CustomerInsertTest</code>.</p><p><span + style="color:red;">Beware:</span> Test execution will completely erase + and initialize any database state to a standard quite similar as being + defined by <code>Sql/schema.sql</code>.</p></li> + </ol><h1>Tasks</h1><p>The following two tasks correspond to the initial + description above.</p><ol type="i"> + <li><p>Replace all <a + href="http://docs.oracle.com/javase/8/docs/api/java/sql/Statement.html" + target="_blank">java.sql.Statement</a> instances within the + implementation of <code>boolean conditionallyInserCustomer (final String + uid, final String cname)</code> by <a + href="http://docs.oracle.com/javase/8/docs/api/java/sql/PreparedStatement.html" + target="_blank">java.sql.PreparedStatement</a> instances + accordingly.</p><p><span style="color:red;">Hint:</span> Before actually + changing the method's code you may want make a copy <code>boolean + conditionallyInserCustomer<b style="color:red;">Backup</b> (final String + uid, final String cname)</code> of this method in order to avoid + confusion when changing the implementation. </p></li> + + <li><p>This part is independent from the first exercise: You may start + either from the original implementation containing <a + href="http://docs.oracle.com/javase/8/docs/api/java/sql/Statement.html">java.sql.Statement</a> + instances or from your security enhanced implementation. In both cases + copy your choosen method to a new method <code>boolean + conditionallyInserCustomer<b style="color:red;">Transact</b> (final + String uid, final String cname)</code> and <b>subsequently</b> change + its implementation.</p><p>The current implementation may become subject + to a subtle flaw: When inserting a customer record a <code>SELECT</code> + will be followed by an <code>INSERT</code> statement. Another + transaction may commit its <code>INSERT</code> of a second customer + record having a conflicting name by coincidence. In this case the + <code>INSERT</code> will raise a key constraint violation + exception.</p><p>Correct this behaviour by grouping both SQL statements + into a single transaction.</p><p><span style="color:red;">Hints:</span> + You may want to consider void <a + href="http://docs.oracle.com/javase/8/docs/api/java/sql/Connection.html#setAutoCommit-boolean-" + target="_blank">setAutoCommit(boolean autoCommit)</a>, <a + href="http://docs.oracle.com/javase/8/docs/api/java/sql/Connection.html#commit--" + target="_blank">void commit()</a> and <a + href="http://docs.oracle.com/javase/8/docs/api/java/sql/Connection.html#rollback--" + target="_blank">void rollback()</a>. Setting tehe connection's aut + commit value may affect your Junit test initializer as well. Take care + to avoid getting stuck in polling by issuing appropriate <a + href="http://docs.oracle.com/javase/8/docs/api/java/sql/Connection.html#commit--" + target="_blank">void commit()</a> or <a + href="http://docs.oracle.com/javase/8/docs/api/java/sql/Connection.html#rollback--" + target="_blank">void rollback()</a> calls.</p></li> + </ol><p>Upon completion zip up just your project directory + <code>Rewriteprepared</code> and upload it to the E-learning system. Mind + the remaining time! <b style="color:red;">When the examination terminates no + subsequent uploads will be possible!</b></p><h1>General hints</h1><p>The + Junit test + <code>de.hdm_stuttgart.mi.sda1.reewriteprepared.CustomerInsertTest</code> + may be helpful to assure correct application behaviour.</p></body> +</html> diff --git a/Klausuren/Sda1/WS2014/reewriteprepared_solution/pom.xml b/Klausuren/Sda1/WS2014/reewriteprepared_solution/pom.xml new file mode 100644 index 0000000000000000000000000000000000000000..78c167f0ac822e5e406309bfd86f314f84b11b19 --- /dev/null +++ b/Klausuren/Sda1/WS2014/reewriteprepared_solution/pom.xml @@ -0,0 +1,67 @@ +<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</groupId> + <artifactId>rewriteprepared</artifactId> + <version>0.9</version> + <packaging>jar</packaging> + + <name>rewriteprepared</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.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>mysql</groupId> + <artifactId>mysql-connector-java</artifactId> + <version>5.1.34</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> + + </plugins> + </build> +</project> diff --git a/Klausuren/Sda1/WS2014/reewriteprepared_solution/src/main/resources/log4j2.xml b/Klausuren/Sda1/WS2014/reewriteprepared_solution/src/main/resources/log4j2.xml new file mode 100644 index 0000000000000000000000000000000000000000..56a4914d9da50f3e03cc307aeda9dc0d5fd51aab --- /dev/null +++ b/Klausuren/Sda1/WS2014/reewriteprepared_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="%d %-5p [%t] %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.mi.sda1.reewriteprepared.App" level="debug"> + <AppenderRef ref="A1"/> + </Logger> + <Root level="info"> + <AppenderRef ref="STDOUT"/> + </Root> + </Loggers> +</Configuration> \ No newline at end of file diff --git a/Klausuren/Sda2/SoSe2013/Catalog/XmlData/groups.xsd b/Klausuren/Sda2/SoSe2013/Catalog/XmlData/groups.xsd new file mode 100644 index 0000000000000000000000000000000000000000..fae9fa6d8f6266efe1ef7a612ae142c65c06d233 --- /dev/null +++ b/Klausuren/Sda2/SoSe2013/Catalog/XmlData/groups.xsd @@ -0,0 +1,10 @@ +<?xml version="1.0" encoding="UTF-8"?> +<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" elementFormDefault="qualified"> + + + + <xs:element name="productGroups"> + + </xs:element> + +</xs:schema> diff --git a/Klausuren/Sda2/SoSe2013/Catalog/XmlData/samplegroups.xml b/Klausuren/Sda2/SoSe2013/Catalog/XmlData/samplegroups.xml new file mode 100644 index 0000000000000000000000000000000000000000..bac71cb68bfa0aadab6ffd20137c4aacf174ef77 --- /dev/null +++ b/Klausuren/Sda2/SoSe2013/Catalog/XmlData/samplegroups.xml @@ -0,0 +1,17 @@ +<?xml version="1.0" encoding="UTF-8"?> +<productGroups xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" + xsi:noNamespaceSchemaLocation="groups.xsd"> + + <group> + <title>Best offers</title> + <article productNumber="32"/> + <article productNumber="36"/> + </group> + + <group> + <title>Discontinued stuff</title> + <article productNumber="36"/> + <article productNumber="17"/> + </group> + +</productGroups> \ No newline at end of file diff --git a/Klausuren/Sda2/SoSe2013/Catalog/pom.xml b/Klausuren/Sda2/SoSe2013/Catalog/pom.xml new file mode 100644 index 0000000000000000000000000000000000000000..02987f1ebff438983810b0b3e0048b494aca423b --- /dev/null +++ b/Klausuren/Sda2/SoSe2013/Catalog/pom.xml @@ -0,0 +1,59 @@ +<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.sda2</groupId> + <artifactId>catalog</artifactId> + <version>0.8</version> + <packaging>jar</packaging> + + <name>Catalog</name> + + <dependencies> + + <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>mysql</groupId> + <artifactId>mysql-connector-java</artifactId> + <version>5.1.33</version> + </dependency> + + <dependency> + <groupId>org.eclipse.persistence</groupId> + <artifactId>eclipselink</artifactId> + <version>2.5.2</version> + </dependency> + + <dependency> + <groupId>junit</groupId> + <artifactId>junit</artifactId> + <version>4.12</version> + </dependency> + + </dependencies> + + <build> + <plugins> + <plugin> + <groupId>org.apache.maven.plugins</groupId> + <artifactId>maven-compiler-plugin</artifactId> + <version>3.2</version> + <configuration> + <source>1.8</source> + <target>1.8</target> + </configuration> + </plugin> + + </plugins> + </build> +</project> diff --git a/Klausuren/Sda2/SoSe2013/Catalog/src/main/resources/META-INF/persistence.xml b/Klausuren/Sda2/SoSe2013/Catalog/src/main/resources/META-INF/persistence.xml new file mode 100644 index 0000000000000000000000000000000000000000..162537d63d1cd22eafd21314919b358fe4d7dcff --- /dev/null +++ b/Klausuren/Sda2/SoSe2013/Catalog/src/main/resources/META-INF/persistence.xml @@ -0,0 +1,49 @@ +<?xml version="1.0" encoding="UTF-8" ?> +<persistence xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" + xsi:schemaLocation="http://java.sun.com/xml/ns/persistence http://java.sun.com/xml/ns/persistence/persistence_2_0.xsd" + version="2.0" xmlns="http://java.sun.com/xml/ns/persistence"> + <persistence-unit name="persistenceUnit" transaction-type="RESOURCE_LOCAL"> + <!-- shouldn't be valid for java SE per specification, but it works for EclipseLink ... --> + <exclude-unlisted-classes>false</exclude-unlisted-classes> + <properties> + + <property name="javax.persistence.jdbc.driver" value="com.mysql.jdbc.Driver" /> + <property name="javax.persistence.jdbc.url" value="jdbc:mysql://localhost:3306/hdm" /> + <property name="javax.persistence.jdbc.user" value="hdmuser" /> + <property name="javax.persistence.jdbc.password" value="XYZ" /> + + <!-- EclipseLink should create the database schema automatically --> + <property name="eclipselink.ddl-generation" value="drop-and-create-tables" /> + <property name="eclipselink.ddl-generation.output-mode" value="database" /> + <property name="eclipselink.logging.level" value="SEVERE"/> + + <!-- Logging SQL operations --> + <property name="eclipselink.logging.level.sql" value="FINE"/> + <property name="eclipselink.logging.parameters" value="true"/> + </properties> + + </persistence-unit> + + + <persistence-unit name="persistenceUnitNoDrop" transaction-type="RESOURCE_LOCAL"> + <!-- shouldn't be valid for java SE per specification, but it works for EclipseLink ... --> + <exclude-unlisted-classes>false</exclude-unlisted-classes> + <properties> + + <property name="javax.persistence.jdbc.driver" value="com.mysql.jdbc.Driver" /> + <property name="javax.persistence.jdbc.url" value="jdbc:mysql://localhost:3306/hdm" /> + <property name="javax.persistence.jdbc.user" value="hdmuser" /> + <property name="javax.persistence.jdbc.password" value="XYZ" /> + + <!-- EclipseLink should create the database schema automatically --> + <property name="eclipselink.ddl-generation" value="none" /> + <property name="eclipselink.ddl-generation.output-mode" value="database" /> + <property name="eclipselink.logging.level" value="SEVERE"/> + + <!-- Logging SQL operations --> + <property name="eclipselink.logging.level.sql" value="OFF"/> + <property name="eclipselink.logging.parameters" value="false"/> + </properties> + + </persistence-unit> +</persistence> \ No newline at end of file diff --git a/Klausuren/Sda2/SoSe2013/Catalog/src/main/resources/log4j2.xml b/Klausuren/Sda2/SoSe2013/Catalog/src/main/resources/log4j2.xml new file mode 100644 index 0000000000000000000000000000000000000000..378492e373afd340270e1987be6e53353312e7bb --- /dev/null +++ b/Klausuren/Sda2/SoSe2013/Catalog/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="%-5p [%t] %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.mi.sda2.jpa.cd.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/Klausuren/Sda2/SoSe2013/Catalog_solution/XmlData/groups.xsd b/Klausuren/Sda2/SoSe2013/Catalog_solution/XmlData/groups.xsd new file mode 100644 index 0000000000000000000000000000000000000000..b06ba988afa3bbccb6beb5f543f67ef8e8403f53 --- /dev/null +++ b/Klausuren/Sda2/SoSe2013/Catalog_solution/XmlData/groups.xsd @@ -0,0 +1,31 @@ +<?xml version="1.0" encoding="UTF-8"?> +<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" elementFormDefault="qualified"> + + <xs:element name="productGroups"> + <xs:complexType> + <xs:sequence> + <xs:element ref="group" minOccurs="0" maxOccurs="unbounded"/> + </xs:sequence> + </xs:complexType> + </xs:element> + + <xs:element name="group"> + <xs:complexType> + <xs:sequence> + <xs:element name="title" type="xs:string"/> + <xs:element ref="article" minOccurs="0" maxOccurs="unbounded"/> + </xs:sequence> + </xs:complexType> + <xs:key name="uniqueProductNumber"> + <xs:selector xpath="article"/> + <xs:field xpath="@productNumber"/> + </xs:key> + </xs:element> + + <xs:element name="article"> + <xs:complexType> + <xs:attribute name="productNumber" type="xs:int" use="required"/> + </xs:complexType> + </xs:element> + +</xs:schema> diff --git a/Klausuren/Sda2/SoSe2013/Catalog_solution/XmlData/samplegroups.xml b/Klausuren/Sda2/SoSe2013/Catalog_solution/XmlData/samplegroups.xml new file mode 100644 index 0000000000000000000000000000000000000000..bac71cb68bfa0aadab6ffd20137c4aacf174ef77 --- /dev/null +++ b/Klausuren/Sda2/SoSe2013/Catalog_solution/XmlData/samplegroups.xml @@ -0,0 +1,17 @@ +<?xml version="1.0" encoding="UTF-8"?> +<productGroups xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" + xsi:noNamespaceSchemaLocation="groups.xsd"> + + <group> + <title>Best offers</title> + <article productNumber="32"/> + <article productNumber="36"/> + </group> + + <group> + <title>Discontinued stuff</title> + <article productNumber="36"/> + <article productNumber="17"/> + </group> + +</productGroups> \ No newline at end of file diff --git a/Klausuren/Sda2/SoSe2013/Catalog_solution/description.xhtml b/Klausuren/Sda2/SoSe2013/Catalog_solution/description.xhtml new file mode 100644 index 0000000000000000000000000000000000000000..95609324ae55e97399e588e8d742bc28b570a2c9 --- /dev/null +++ b/Klausuren/Sda2/SoSe2013/Catalog_solution/description.xhtml @@ -0,0 +1,138 @@ +<?xml version="1.0" encoding="UTF-8"?> +<!DOCTYPE html> +<html xml:lang="en" xmlns="http://www.w3.org/1999/xhtml"> + <head> + <title></title> + </head> + + <body><h1 id="toc">Description</h1><p>This exercise deals with product data, + suppliers and catalogs. You are expected to solve the following + tasks:</p><ol> + <li id="toc_t1"><p><a href="#t1">Creating a JPA annotated + model</a></p></li> + + <li id="toc_t2"><p><a href="#t2">Create an XSD describing XML document + instances</a></p></li> + + <li id="toc_t3"><p><a href="#t3">Load XML data into Java</a></p></li> + + <li id="toc_t4"><p><a href="#t4">Combine reading XML and relational + Data</a></p></li> + </ol><h1>Preparations</h1><p>Download <a + href="/files/goik/Sda2/calalog_rucFkhE4QPG-d/catalog.zip" + target="_blank">catalog.zip</a> and unzip it into your Eclipse workspace. + Subsequently import it as a Maven project to Eclipse.</p><h1 id="t1"><a + href="#toc">1 Creating a JPA annotated model</a></h1><p>We want to model + grocery store products among with their corresponding suppliers by JPA + annotated classes. Our Model will contain the following entities:</p><ul> + <li><code>Product</code><p>An abstract base class having two mandatory + attributes:</p><ul> + <li><p><code>productNumber:</code> An integer value uniquely + identifying a given product</p></li> + + <li><p><code>name:</code> The product's name like e.g. "Tennis + Racket"</p></li> + </ul></li> + + <li><code>FoodProduct</code><p>Derived from base class + <code>Product</code>. Since storage time for food is generally limited + this class adds another mandatory integer attribute + <code>daysOfShelfLife</code>.</p></li> + + <li><code>NonFoodProduct</code><p>Derived from base class + <code>Product</code>. Since storage time for food is generally limited + this class adds another mandatory integer attribute + <code>daysOfShelfLife</code>.</p></li> + + <li><code>ProductProvider</code><p>Providers deliver products to our + grocery store company and have just one mandatory attribute + <code>name</code> (the company's name).</p></li> + </ul><p>In addition we need to link products and suppliers. Each product + may have exactly one primary supplier. Vice versa each supplier will provide + a set of products to the store. </p><p>When persisting either product or + supplier instances connected objects shall be automatically persisted as + well.</p><p>Finish the implementation in + <code>de.hdm_stuttgart.mi.sda2.catalog.domain</code> and extend the driver + class <code>de.hdm_stuttgart.mi.sda2.catalog.CreateSampleData</code> to + creates some sample test data.</p><p><span style="color:red;">Hint:</span> + All entities shall have a synthetic (surrogate) database supplied identifier + attribute carrying no business logic. Your project has already been set up + for Eclipse Link, see src/main/resources/META-INF/persistence.xml and the + skeleton driver in + <code>de.hdm_stuttgart.mi.sda2.catalog.CreateSampleData</code> .</p><h1 + id="t2"><a href="#toc">2 Create an XSD describing XML document + instances</a></h1><p>The file <code>XmlData/samplegroups.xml</code> contains + legacy data from older implementations providing groups of products + represented by their unique numbers. Create an XML schema file implementing + the following integrity constraints:</p><ul> + <li>The number of <group> elements shall be arbitrary</li> + + <li>Each <group> must have exactly one title</li> + + <li>Each <group> may have an arbitrary number of <article> + child nodes</li> + + <li>Each <article> must have a number being unique within the + given <group></li> + </ul><a><a><h1 id="t3"><a href="#toc">3 Load XML data into + Java</a></h1></a></a><p>Write a JAXB application loading XML data like being + represented by <code>XmlData/samplegroups.xml</code> to generate the + following output:</p><pre>2 product groups: +Group title: "Best offers" containing 2 article(s) +Article no. 32 +Article no. 36 +---------------- +Group title: "Discontinued stuff" containing 1 article(s) +Article no. 36 +----------------</pre><p style="color:red;">Technical hints:</p><ul> + <li><p>Generating JAXB Java classes from your XSD file may be achieved + starting from your project root directory by executing:</p><code>xjc + XmlData/groups.xsd -p ... -d src/main/java</code><p>xjc is self + explanatory when being called without any parameter.</p></li> + + <li><p>From the lecture you may remember code being required to JAXB + load XML data</p><pre>final JAXBContext cdContext = JAXBContext.newInstance("de.hdm_stuttgart.mi.sda2.jpa.cd.domain"); +final Unmarshaller u = cdContext.createUnmarshaller(); +final Catalog catalog = (Catalog) u.unmarshal(new File("cdData.xml")); + +for (final Cd cd : catalog.getCd()) { + log.debug("CD:" + cd.getArtist()); +}</pre></li> + </ul><h1 id="t4"><a href="#toc">4 Combine reading XML and relational + Data</a></h1><p>Enrich the output obtained in Task 3 by supplying product + data from your JPA accessible relational test data. Bear in mind that some + product numbers may not exist within the RDBMS. The intended output shall + read like:</p><pre>2 product group(s): +Group title:Best offers containing 2 article(s) +Article no. 32 +Food product , productNo. =32, id=1, days shelf life=43, primary provider:Smith & Sons +Article no. 36 +Food product , productNo. =36, id=2, days shelf life=12 +---------------- +Group title:Discontinued stuff containing 2 article(s) +Article no. 36 +Food product , productNo. =36, id=2, days shelf life=12 +Article no. 17 +<b>No product data available</b> +----------------</pre><p>Reuse your sample generating application from + exercise 2. Your project's + <code>src/main/resources/META-INF/persistence.xml</code> file contains the + definition of a second persistence unit <code>persistenceUnitNoDrop</code> + which will not alter a database's schema on application startup. Mind the + following details:</p><ul> + <li>A product may not exist within your relational data, see above + output</li> + + <li>A product may have no supplier being assigned</li> + </ul><p>The following snippet may be helpful:</p><pre>public List<Country> getCountryByName(EntityManager em, String name) { + TypedQuery<Country> query = em.createQuery( + "SELECT c FROM Country c WHERE c.name = :name", Country.class); + return query.setParameter("name", name).getResultList(); + } </pre><p><span style="color:red;">Hint:</span> In case you were unable to + solve the previous task 3 just provide sample product number values by a + static array containing both existing and non-existing product numbers to + simulate the XML data.</p><p>Upon completion zip up your project directory + and upload it to the E-learning system. Mind the remaining time! <b + style="color:red;">When the examination terminates no subsequent uploads + will be possible!</b></p></body> +</html> diff --git a/Klausuren/Sda2/SoSe2013/Catalog_solution/pom.xml b/Klausuren/Sda2/SoSe2013/Catalog_solution/pom.xml new file mode 100644 index 0000000000000000000000000000000000000000..e1848180d2306e28b065e5469c89af36e3d0f93e --- /dev/null +++ b/Klausuren/Sda2/SoSe2013/Catalog_solution/pom.xml @@ -0,0 +1,59 @@ +<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.sda2</groupId> + <artifactId>catalog_solution</artifactId> + <version>0.9</version> + <packaging>jar</packaging> + + <name>Catalog_Solution</name> + + <dependencies> + + <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>mysql</groupId> + <artifactId>mysql-connector-java</artifactId> + <version>5.1.33</version> + </dependency> + + <dependency> + <groupId>org.eclipse.persistence</groupId> + <artifactId>eclipselink</artifactId> + <version>2.5.2</version> + </dependency> + + <dependency> + <groupId>junit</groupId> + <artifactId>junit</artifactId> + <version>4.12</version> + </dependency> + + </dependencies> + + <build> + <plugins> + <plugin> + <groupId>org.apache.maven.plugins</groupId> + <artifactId>maven-compiler-plugin</artifactId> + <version>3.2</version> + <configuration> + <source>1.8</source> + <target>1.8</target> + </configuration> + </plugin> + + </plugins> + </build> +</project> diff --git a/Klausuren/Sda2/SoSe2013/Catalog_solution/src/main/resources/META-INF/persistence.xml b/Klausuren/Sda2/SoSe2013/Catalog_solution/src/main/resources/META-INF/persistence.xml new file mode 100644 index 0000000000000000000000000000000000000000..162537d63d1cd22eafd21314919b358fe4d7dcff --- /dev/null +++ b/Klausuren/Sda2/SoSe2013/Catalog_solution/src/main/resources/META-INF/persistence.xml @@ -0,0 +1,49 @@ +<?xml version="1.0" encoding="UTF-8" ?> +<persistence xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" + xsi:schemaLocation="http://java.sun.com/xml/ns/persistence http://java.sun.com/xml/ns/persistence/persistence_2_0.xsd" + version="2.0" xmlns="http://java.sun.com/xml/ns/persistence"> + <persistence-unit name="persistenceUnit" transaction-type="RESOURCE_LOCAL"> + <!-- shouldn't be valid for java SE per specification, but it works for EclipseLink ... --> + <exclude-unlisted-classes>false</exclude-unlisted-classes> + <properties> + + <property name="javax.persistence.jdbc.driver" value="com.mysql.jdbc.Driver" /> + <property name="javax.persistence.jdbc.url" value="jdbc:mysql://localhost:3306/hdm" /> + <property name="javax.persistence.jdbc.user" value="hdmuser" /> + <property name="javax.persistence.jdbc.password" value="XYZ" /> + + <!-- EclipseLink should create the database schema automatically --> + <property name="eclipselink.ddl-generation" value="drop-and-create-tables" /> + <property name="eclipselink.ddl-generation.output-mode" value="database" /> + <property name="eclipselink.logging.level" value="SEVERE"/> + + <!-- Logging SQL operations --> + <property name="eclipselink.logging.level.sql" value="FINE"/> + <property name="eclipselink.logging.parameters" value="true"/> + </properties> + + </persistence-unit> + + + <persistence-unit name="persistenceUnitNoDrop" transaction-type="RESOURCE_LOCAL"> + <!-- shouldn't be valid for java SE per specification, but it works for EclipseLink ... --> + <exclude-unlisted-classes>false</exclude-unlisted-classes> + <properties> + + <property name="javax.persistence.jdbc.driver" value="com.mysql.jdbc.Driver" /> + <property name="javax.persistence.jdbc.url" value="jdbc:mysql://localhost:3306/hdm" /> + <property name="javax.persistence.jdbc.user" value="hdmuser" /> + <property name="javax.persistence.jdbc.password" value="XYZ" /> + + <!-- EclipseLink should create the database schema automatically --> + <property name="eclipselink.ddl-generation" value="none" /> + <property name="eclipselink.ddl-generation.output-mode" value="database" /> + <property name="eclipselink.logging.level" value="SEVERE"/> + + <!-- Logging SQL operations --> + <property name="eclipselink.logging.level.sql" value="OFF"/> + <property name="eclipselink.logging.parameters" value="false"/> + </properties> + + </persistence-unit> +</persistence> \ No newline at end of file diff --git a/Klausuren/Sda2/SoSe2013/Catalog_solution/src/main/resources/log4j2.xml b/Klausuren/Sda2/SoSe2013/Catalog_solution/src/main/resources/log4j2.xml new file mode 100644 index 0000000000000000000000000000000000000000..378492e373afd340270e1987be6e53353312e7bb --- /dev/null +++ b/Klausuren/Sda2/SoSe2013/Catalog_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="%-5p [%t] %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.mi.sda2.jpa.cd.App" level="debug"> + <AppenderRef ref="A1"/> + </Logger> + <Root level="debug"> + <AppenderRef ref="STDOUT"/> + </Root> + </Loggers> +</Configuration> \ No newline at end of file