From ab6347701cbfbbe185819bf91e9a7ae5534108ef Mon Sep 17 00:00:00 2001
From: miesma <miesma@mi.fu-berlin.de>
Date: Mon, 20 Jul 2015 10:24:24 +0200
Subject: [PATCH] update code

---
 DataBaseConnectionService.java |  79 +++++++++++++
 DatabaseUpdater.jar            | Bin 0 -> 2777 bytes
 DatabaseUpdater.java           | 123 ++++++++++++++++++++
 RestServer.java                |  48 ++++++++
 quiz.css                       |  31 ++++++
 quiz.js                        |  89 +++++++++++++++
 quiz.jsp                       | 197 +++++++++++++++++++++++++++++++++
 7 files changed, 567 insertions(+)
 create mode 100644 DataBaseConnectionService.java
 create mode 100644 DatabaseUpdater.jar
 create mode 100644 DatabaseUpdater.java
 create mode 100644 RestServer.java
 create mode 100644 quiz.css
 create mode 100644 quiz.js
 create mode 100644 quiz.jsp

diff --git a/DataBaseConnectionService.java b/DataBaseConnectionService.java
new file mode 100644
index 0000000..996b2e7
--- /dev/null
+++ b/DataBaseConnectionService.java
@@ -0,0 +1,79 @@
+package myserver.example;
+
+import java.io.BufferedReader;
+import java.io.DataOutputStream;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.InputStreamReader;
+import java.net.HttpURLConnection;
+import java.net.MalformedURLException;
+import java.net.ProtocolException;
+import java.net.URL;
+import org.basex.util.Base64;
+
+public final class DataBaseConnectionService {
+	
+	public static String executeQuery(String query) {
+		StringBuffer response;
+		try {
+			// The java URL connection to the server of Thierry.
+			URL url = new URL("http://localhost:8080/BaseX821/rest/Flugzeuge");
+			
+			HttpURLConnection conn = (HttpURLConnection) url.openConnection();
+			
+			conn.setRequestMethod("POST");
+			
+			// User and password.
+			String user = "admin";
+			String pw = "admin";
+			
+			String encoded = Base64.encode(user + ":" + pw);
+			conn.setRequestProperty("Authorization", "Basic " + encoded);
+			String q = "<query xmlns=\"http://basex.org/rest\"> " + "<text><![CDATA[ " + query + " ]]></text>	" + "	  </query>";
+			conn.setRequestProperty("Content-Type", "application/x-www-form-urlencoded");
+			conn.setRequestProperty("Content-Length", "" + Integer.toString(query.getBytes().length));
+			conn.setRequestProperty("Content-Language", "en-US");
+			conn.setUseCaches(false);
+			conn.setDoInput(true);
+			conn.setDoOutput(true);
+			
+			// Send request
+			DataOutputStream wr = new DataOutputStream(conn.getOutputStream());
+			wr.writeBytes(q);
+			wr.flush();
+			wr.close();
+			
+			// get response
+			InputStream is = conn.getInputStream();
+			BufferedReader rd = new BufferedReader(new InputStreamReader(is, "UTF8"));
+			String line;
+			response = new StringBuffer();
+			while ((line = rd.readLine()) != null) {
+				response.append(line);
+				response.append('\n');
+			}
+			rd.close();
+			conn.disconnect();
+			return response.toString();
+			
+		} catch (MalformedURLException e) {
+			e.printStackTrace();
+		} catch (ProtocolException e) {
+			e.printStackTrace();
+		} catch (IOException e) {
+			e.printStackTrace();
+		}
+		
+		return "";
+	}
+	
+	// debugging.... can be deleted
+	public static void main(String[] args) throws Exception {
+		// String XPATHQUERY = "(//plane/name)[position() <= 5]";
+		
+		String XPATHQUERY = "(for $p in /planes/plane return (fn:string($p/name), fn:string($p/stueck), fn:string($p/erstflug), fn:string($p/beschreibung), fn:string($p/bild), fn:string($p/herstellerName), fn:string($p/herstellerBeschreibung)))[position() <= 28]";
+		String response = executeQuery(XPATHQUERY);
+		System.out.println(response);
+		
+	}
+}
\ No newline at end of file
diff --git a/DatabaseUpdater.jar b/DatabaseUpdater.jar
new file mode 100644
index 0000000000000000000000000000000000000000..10075b27dd8ebd5d41adf77e8bad44058414c93e
GIT binary patch
literal 2777
zcmWIWW@Zs#;Nak3*t7SO8v_y$VPIkKbq#UU_4ISo_jUC1baM?3(eritcZz}Gv+tSH
zKHj=|7kRyPwa%S6zd6X@it&S|Mdv(q^se!G=$zaTbRoFFQ^(WCOUI8_*TYlCQ@88<
zNuNvQOrMl>dU(EW66&tlStD%xx#ZxiH6mV$tG-+)`B?O^h>;<{o1G*1uXJcM0|P@I
z0|P^VH!}+t0|N&GgA1AiIT#oiN()jFOHzyUL8>6$2u4#Si=@gWu_Q4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w-(xNoW+1Gf_9J-Rafvx_~
ze9Qaq-w21Q{5!hSI_{r5sA+X;o!!S*91ILO0-&Z9Ba;XNq}c>&{UJBIK&?Nd#vlU&
z&bDBHHzN}l1MVgo!jy$bO)-!znBAZz8?w7VO*VwC<4C%&HsAuhS=m6!nHiWFK#Kox
Gf_MO}ec4k0

literal 0
HcmV?d00001

diff --git a/DatabaseUpdater.java b/DatabaseUpdater.java
new file mode 100644
index 0000000..696f672
--- /dev/null
+++ b/DatabaseUpdater.java
@@ -0,0 +1,123 @@
+package updater;
+
+import java.io.BufferedReader;
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.InputStreamReader;
+import java.io.OutputStream;
+import java.net.HttpURLConnection;
+import java.net.MalformedURLException;
+import java.net.ProtocolException;
+import java.net.URL;
+import org.basex.util.Base64;
+
+public final class DatabaseUpdater {
+	
+	public static boolean delete(String filename) {
+		try {
+			URL url = new URL("http://localhost:8080/BaseX821/rest/Flugzeuge/" + filename);
+			
+			HttpURLConnection conn = (HttpURLConnection) url.openConnection();
+			
+			conn.setRequestMethod("DELETE");
+			
+			String user = "admin";
+			String pw = "admin";
+			
+			String encoded = Base64.encode(user + ":" + pw);
+			conn.setRequestProperty("Authorization", "Basic " + encoded);
+			conn.setUseCaches(false);
+			conn.setDoInput(true);
+			conn.setDoOutput(true);
+			
+			InputStream is = null;
+			try {
+				is = conn.getInputStream();
+			} catch (IOException ioe) {
+				is = conn.getErrorStream();
+			}
+			BufferedReader rd = new BufferedReader(new InputStreamReader(is, "UTF8"));
+			while (rd.readLine() != null) {
+			}
+			rd.close();
+			conn.disconnect();
+			return conn.getResponseCode() == 200;
+			
+		} catch (MalformedURLException e) {
+			e.printStackTrace();
+		} catch (ProtocolException e) {
+			e.printStackTrace();
+		} catch (IOException e) {
+			e.printStackTrace();
+		}
+		
+		return false;
+	}
+	
+	public static boolean put(String filename) {
+		try {
+			URL url = new URL("http://localhost:8080/BaseX821/rest/Flugzeuge/" + filename);
+			
+			HttpURLConnection conn = (HttpURLConnection) url.openConnection();
+			
+			conn.setRequestMethod("PUT");
+			
+			String user = "admin";
+			String pw = "admin";
+			File f = new File(filename);
+			String encoded = Base64.encode(user + ":" + pw);
+			conn.setRequestProperty("Authorization", "Basic " + encoded);
+			conn.setRequestProperty("Content-Type", "application/xml");
+			conn.setRequestProperty("Content-Length", "" + Long.toString(f.length()));
+			conn.setRequestProperty("Content-Language", "en-US");
+			conn.setUseCaches(false);
+			conn.setDoInput(true);
+			conn.setDoOutput(true);
+			
+			FileInputStream fis = new FileInputStream(f);
+			OutputStream os = conn.getOutputStream();
+			byte[] buffer = new byte[256];
+			int bytesRead = 0;
+			while ((bytesRead = fis.read(buffer)) != -1) {
+				os.write(buffer, 0, bytesRead);
+			}
+			fis.close();
+			os.flush();
+			os.close();
+			
+			InputStream is = null;
+			try {
+				is = conn.getInputStream();
+			} catch (IOException ioe) {
+				is = conn.getErrorStream();
+			}
+			BufferedReader rd = new BufferedReader(new InputStreamReader(is, "UTF8"));
+			while (rd.readLine() != null) {
+			}
+			rd.close();
+			conn.disconnect();
+			return conn.getResponseCode() == 201;
+			
+		} catch (MalformedURLException e) {
+			e.printStackTrace();
+		} catch (ProtocolException e) {
+			e.printStackTrace();
+		} catch (IOException e) {
+			e.printStackTrace();
+		}
+		
+		return false;
+	}
+	
+	public static void main(String[] args) throws Exception {
+		if (args.length != 1) {
+			throw new IllegalArgumentException("Invalid Parameters!");
+		}
+		// xml_Database_v3.xml
+		delete(args[0]);
+		Thread.sleep(2000);
+		put(args[0]);
+	}
+}
\ No newline at end of file
diff --git a/RestServer.java b/RestServer.java
new file mode 100644
index 0000000..423f651
--- /dev/null
+++ b/RestServer.java
@@ -0,0 +1,48 @@
+package myserver.example;
+
+import java.io.UnsupportedEncodingException;
+import java.net.URLDecoder;
+import javax.ws.rs.GET;
+import javax.ws.rs.Path;
+import javax.ws.rs.PathParam;
+import javax.ws.rs.Produces;
+import javax.ws.rs.core.Application;
+import javax.ws.rs.core.MediaType;
+
+// Plain old Java Object it does not extend as class or implements
+// an interface
+
+// The class registers its methods for the HTTP GET request using the @GET annotation.
+// Using the @Produces annotation, it defines that it can deliver several MIME types,
+// text, XML and HTML.
+// http://q1k.de:8088/ /home/xml/res
+// http://q1k.de:8088/xml3/xml_Database_v3.xml
+
+// The browser requests per default the HTML MIME type.
+
+// Sets the path to base URL + /any Element
+@Path("/")
+public class RestServer extends Application {
+	
+	// This method is called if XML is request
+	@GET
+	@Path("/planes")
+	@Produces(MediaType.APPLICATION_XML)
+	public String getName() {
+		String query = "for $p in /planes\nreturn $p";
+		String result = DataBaseConnectionService.executeQuery(query);
+		return result;
+	}
+	
+	@GET
+	@Path("/plane/{name}")
+	@Produces(MediaType.APPLICATION_XML)
+	public String getStueck(@PathParam("name") String name) {
+		try {
+			name = URLDecoder.decode(name, "UTF-8");
+		} catch (UnsupportedEncodingException e1) {}
+		String query = "for $p in /planes/plane\n where $p/name = '"+name+"'\n return $p";
+		String result = DataBaseConnectionService.executeQuery(query);
+		return result;
+	}
+}
\ No newline at end of file
diff --git a/quiz.css b/quiz.css
new file mode 100644
index 0000000..13f3870
--- /dev/null
+++ b/quiz.css
@@ -0,0 +1,31 @@
+.red {
+	background: #F33
+}
+
+.green {
+	background: #3F3
+}
+
+img {
+	min-width: 300px;
+	max-height: 300px;
+}
+
+body {
+	text-align: center;
+	background-color: #FAE7B1;
+}
+
+table {
+    margin-left: auto;
+    margin-right: auto;
+}
+
+.invis {
+	display: none;
+}
+
+.trtext {
+	text-align: left;
+	max-width: 300px;
+}
\ No newline at end of file
diff --git a/quiz.js b/quiz.js
new file mode 100644
index 0000000..5d3c8f4
--- /dev/null
+++ b/quiz.js
@@ -0,0 +1,89 @@
+$(document).ready(function(){
+	$('input[type=radio]').prop('checked', false);
+});
+
+selection = [0, 0, 0, 0];
+
+function swap(number, option) {
+	if(selection[number - 1] == option) {
+		return;
+	}
+	var conflict = isSelected(option);
+	if(conflict == 0) {
+		selection[number - 1] = option;
+		return;
+	}
+	if(selection[number - 1] != 0) {
+		if(selection[number - 1] > option) {
+			var tmp = isSelected(option);
+			for(i = option; i < selection[number - 1]; i++) {
+				if(tmp == 0){
+					break;
+				}
+				var tmp2 = isSelected(i + 1);
+				selection[tmp - 1]++;
+				tmp = tmp2;
+			}
+		} else {
+			var tmp = isSelected(option);
+			for(i = option; i > selection[number - 1]; i--) {
+				if(tmp == 0){
+					break;
+				}
+				var tmp2 = isSelected(i - 1);
+				selection[tmp - 1]--;
+				tmp = tmp2;
+			}
+		}
+	} else {
+		
+	}
+	selection[number - 1] = option;
+	var list = $('input[type=radio][name=first]');
+	for(i = 4; i --> 0;) {
+		$(list[i]).prop('checked', i + 1 == selection[0]);
+	}
+	var list = $('input[type=radio][name=second]');
+	for(i = 4; i --> 0;) {
+		$(list[i]).prop('checked', i + 1 == selection[1]);
+	}
+	var list = $('input[type=radio][name=third]');
+	for(i = 4; i --> 0;) {
+		$(list[i]).prop('checked', i + 1 == selection[2]);
+	}
+	var list = $('input[type=radio][name=fourth]');
+	for(i = 4; i --> 0;) {
+		$(list[i]).prop('checked', i + 1 == selection[3]);
+	}
+}
+
+function isSelected(option) {
+	var conflict = 0;
+	for(var i = 4; i --> 0;){
+		if(selection[i] == option){
+			conflict = i + 1;
+		}
+	}
+	return conflict;
+}
+
+function checkResult() {
+	var correct = true;
+	for(var i = 4; i --> 0;){
+		if(correctList[i] != selection[i]){
+			correct = false;
+			$('.selector')[i].classList.remove('green');
+			$('.selector')[i].classList.add('red');
+		}else{
+			$('.selector')[i].classList.remove('red');
+			$('.selector')[i].classList.add('green');
+		}
+	}
+	if(!correct){
+		return;
+	}
+	var xl = $('.invis');
+	for(var i = xl.length; i --> 0;){
+		xl[i].classList.remove('invis');
+	}
+}
\ No newline at end of file
diff --git a/quiz.jsp b/quiz.jsp
new file mode 100644
index 0000000..072494e
--- /dev/null
+++ b/quiz.jsp
@@ -0,0 +1,197 @@
+<%@ page language="java" contentType="text/html; charset=UTF-8"
+    pageEncoding="UTF-8"%>
+<%@page import="org.basex.query.value.item.Item"%>
+<%@page import="org.basex.query.iter.Iter"%>
+<%@page import="org.basex.query.QueryProcessor"%>
+<%@page import="org.basex.core.Context"%>
+<%@page import="org.basex.core.cmd.XQuery"%>
+<%@page import="java.util.Date"%>
+<%@page import="java.text.SimpleDateFormat"%>
+<%@page import="java.io.BufferedReader"%>
+<%@page import="java.io.DataOutputStream"%>
+<%@page import="java.io.IOException"%>
+<%@page import="java.io.InputStream"%>
+<%@page import="java.io.InputStreamReader"%>
+<%@page import="java.net.HttpURLConnection"%>
+<%@page import="java.net.MalformedURLException"%>
+<%@page import="java.net.ProtocolException"%>
+<%@page import="java.net.URL"%>
+<%@page import="org.basex.util.Base64"%>
+<%
+	String query = "declare namespace math = \"java:java.lang.Math\";\n"
+			+ "(for $p in /planes/plane\n"
+			+ "order by math:random()\n"
+			+ "return (fn:string($p/name), fn:string($p/stueck), fn:string($p/erstflug), fn:string($p/beschreibung), fn:string($p/bild), fn:string($p/herstellerName), fn:string($p/herstellerBeschreibung)))[position() <= 28]";
+	String[] name = new String[4];
+	int[] stueck = new int[4];
+	Date[] dates = new Date[4];
+	Date never = new Date();
+	String[] abstracts = new String[4];
+	String[] imgUrls = new String[4];
+	String[] manufactor = new String[4];
+	String[] mfabstract = new String[4];
+	SimpleDateFormat sdf = new SimpleDateFormat("YYYY-MM-dd'Z'");
+	SimpleDateFormat sdf2 = new SimpleDateFormat("YYYY");
+	
+	BufferedReader br = null;
+	try {
+		// The java URL connection to the server of Thierry.
+		URL url = new URL("http://localhost:8080/BaseX821/rest/Flugzeuge");
+		
+		HttpURLConnection conn = (HttpURLConnection) url.openConnection();
+		
+		conn.setRequestMethod("POST");
+		
+		// User and password.
+		String user = "admin";
+		String pw = "admin";
+		
+		String encoded = Base64.encode(user + ":" + pw);
+		conn.setRequestProperty("Authorization", "Basic " + encoded);
+		String q = "<query xmlns=\"http://basex.org/rest\"> " + "<text><![CDATA[ " + query + " ]]></text>	" + "	  </query>";
+		conn.setRequestProperty("Content-Type", "application/x-www-form-urlencoded");
+		conn.setRequestProperty("Content-Length", "" + Integer.toString(query.getBytes().length));
+		conn.setRequestProperty("Content-Language", "en-US");
+		conn.setUseCaches(false);
+		conn.setDoInput(true);
+		conn.setDoOutput(true);
+		
+		// Send request
+		DataOutputStream wr = new DataOutputStream(conn.getOutputStream());
+		wr.writeBytes(q);
+		wr.flush();
+		wr.close();
+		
+		// get response
+		InputStream is = conn.getInputStream();
+		br = new BufferedReader(new InputStreamReader(is, "UTF8"));		
+	} catch (MalformedURLException e) {
+		//e.printStackTrace();
+	} catch (ProtocolException e) {
+		//e.printStackTrace();
+	} catch (IOException e) {
+		//e.printStackTrace();
+	}
+	
+	for (int i = 0; i < 4; i++) {
+		name[i] = br.readLine();
+		stueck[i] = Integer.parseInt(br.readLine());
+		String date = br.readLine();
+		if (date.length() == 4) {
+			dates[i] = sdf2.parse(date);
+		} else if (date.length() == 11) {
+			dates[i] = sdf.parse(date);
+		} else {
+			dates[i] = never;
+		}
+		abstracts[i] = br.readLine();
+		imgUrls[i] = br.readLine();
+		manufactor[i] = br.readLine();
+		mfabstract[i] = br.readLine();
+	}
+	br.close();
+	boolean search = Math.random() > 0.5;
+	int[] correct = new int[4];
+	for (int i = 0; i < 4; i++) {
+		correct[i] = i + 1;
+	}
+	for (int i = 0; i < 4; i++) {
+		for (int j = 0; j < 4; j++) {
+			if(i == j){
+				continue;
+			}
+			if (search) {
+				if (dates[j].after(dates[i]) == correct[j] < correct[i]) {
+					int tmp = correct[j];
+					correct[j] = correct[i];
+					correct[i] = tmp;
+				}
+			} else {
+				if (stueck[j] < stueck[i] == correct[j] < correct[i]) {
+					int tmp = correct[j];
+					correct[j] = correct[i];
+					correct[i] = tmp;
+				}
+			}
+		}
+	}
+	String searchFor = search ? "Erstflugsdatum" : "Stückzahl" ;
+%>
+<!DOCTYPE html>
+<html xmlns="http://www.w3.org/1999/xhtml" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:foaf="http://xmlns.com/foaf/0.1/">
+<head>
+<title>XML Projekt: Flugzeug-Quiz</title>
+<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
+<link rel="stylesheet" type="text/css" href="quiz.css" />
+<script src="jquery-2.1.4.min.js"></script>
+<script>
+	correctList = [
+<%=correct[0]%>
+	,
+<%=correct[1]%>
+	,
+<%=correct[2]%>
+	,
+<%=correct[3]%>
+	];
+</script>
+<script src="quiz.js"></script>
+</head>
+<body>
+	Sortiere nach: <%=searchFor%>
+	<form>
+		<table border=1>
+			<tr>
+				<td class="trtext invis"><%=name[0]%><br /><%=abstracts[0]%><br /><br />Erstflug: <%=dates[0]%><br />Stueckzahl: <%=stueck[0]%><br /><br />Hersteller: <%=manufactor[0]%><br /><%=mfabstract[0]%></td>
+				<td><img src="<%=imgUrls[0]%>" /></td>
+				<td><img src="<%=imgUrls[1]%>" /></td>
+				<td class="trtext invis"><%=name[1]%><br /><%=abstracts[1]%><br />Erstflug: <%=dates[1]%><br />Stueckzahl: <%=stueck[1]%><br /><br />Hersteller: <%=manufactor[1]%><br /><%=mfabstract[1]%></td>
+			</tr>
+			<tr>
+				<td class="invis"></td>
+				<td class="selector"><input type="radio" name="first" value="1"
+					onclick="swap(1, 1)" /> <input type="radio" name="first" value="2"
+					onclick="swap(1, 2)" /> <input type="radio" name="first" value="3"
+					onclick="swap(1, 3)" /> <input type="radio" name="first" value="4"
+					onclick="swap(1, 4)" /></td>
+				<td class="selector"><input type="radio" name="second"
+					value="1" onclick="swap(2, 1)" /> <input type="radio"
+					name="second" value="2" onclick="swap(2, 2)" /> <input
+					type="radio" name="second" value="3" onclick="swap(2, 3)" /> <input
+					type="radio" name="second" value="4" onclick="swap(2, 4)" /></td>
+				<td class="invis"></td>
+			</tr>
+			<tr>
+				<td class="invis"></td>
+				<td class="selector"><input type="radio" name="third" value="1"
+					onclick="swap(3, 1)" /> <input type="radio" name="third" value="2"
+					onclick="swap(3, 2)" /> <input type="radio" name="third" value="3"
+					onclick="swap(3, 3)" /> <input type="radio" name="third" value="4"
+					onclick="swap(3, 4)" /></td>
+				<td class="selector"><input type="radio" name="fourth"
+					value="1" onclick="swap(4, 1)" /> <input type="radio"
+					name="fourth" value="2" onclick="swap(4, 2)" /> <input
+					type="radio" name="fourth" value="3" onclick="swap(4, 3)" /> <input
+					type="radio" name="fourth" value="4" onclick="swap(4, 4)" /></td>
+				<td class="invis"></td>
+			</tr>
+			<tr>
+				<td class="trtext invis"><%=name[2]%><br /><%=abstracts[2]%><br />Erstflug: <%=dates[2]%><br />Stueckzahl: <%=stueck[2]%><br /><br />Hersteller: <%=manufactor[2]%><br /><%=mfabstract[2]%></td>
+				<td><img src="<%=imgUrls[2]%>" /></td>
+				<td><img src="<%=imgUrls[3]%>" /></td>
+				<td class="trtext invis"><%=name[3]%><br /><%=abstracts[3]%><br />Erstflug: <%=dates[3]%><br />Stueckzahl: <%=stueck[3]%><br /><br />Hersteller: <%=manufactor[3]%><br /><%=mfabstract[3]%></td>
+			</tr>
+		</table>
+		<input type="button" value="Bewerten" onclick="checkResult()" />
+	</form>
+	Made by
+	<span property="dc:creator">
+		<span typeof="foaf:Person" property="foaf:name">Timo Gielser</span>,
+		<span typeof="foaf:Person" property="foaf:name">Markus Mies</span>,
+		<span typeof="foaf:Person" property="foaf:name">Julian Petrasch</span>,
+		<span typeof="foaf:Person" property="foaf:name">Thiery Meurers</span>,
+		<span typeof="foaf:Person" property="foaf:name">Alexis Iakovenko</span> and 
+		<span typeof="foaf:Person" property="foaf:name">Shiho Onitsuka</span>
+	</span>
+</body>
+</html>
\ No newline at end of file
-- 
GitLab