From 59db0c72ece1e6ad24cd64616609faa0a3eb001b Mon Sep 17 00:00:00 2001
From: ulrich <not disclosed>
Date: Sat, 17 Dec 2016 10:08:45 +0000
Subject: [PATCH] Merge origin/master

---
 src/java/de/uhilger/um/web/NiceFilter.java |   43 ++++++++++
 web/WEB-INF/web.xml                        |   28 +++++++
 web/ui/user.jsp                            |   14 +++
 src/java/de/uhilger/um/api/UserMgr.java    |    4 +
 web/show.jsp                               |   26 ++++++
 web/ui/ui.js                               |  102 +++++++++++++-----------
 6 files changed, 168 insertions(+), 49 deletions(-)

diff --git a/src/java/de/uhilger/um/api/UserMgr.java b/src/java/de/uhilger/um/api/UserMgr.java
index 17a4210..3ae67bf 100644
--- a/src/java/de/uhilger/um/api/UserMgr.java
+++ b/src/java/de/uhilger/um/api/UserMgr.java
@@ -24,4 +24,8 @@
     return user;
   }
   
+  public String hallo() {
+    return "Hallo Welt";
+  }
+  
 }
diff --git a/src/java/de/uhilger/um/web/NiceFilter.java b/src/java/de/uhilger/um/web/NiceFilter.java
new file mode 100644
index 0000000..61d5a39
--- /dev/null
+++ b/src/java/de/uhilger/um/web/NiceFilter.java
@@ -0,0 +1,43 @@
+/*
+ * To change this license header, choose License Headers in Project Properties.
+ * To change this template file, choose Tools | Templates
+ * and open the template in the editor.
+ */
+package de.uhilger.um.web;
+
+import java.io.IOException;
+import javax.servlet.Filter;
+import javax.servlet.FilterChain;
+import javax.servlet.FilterConfig;
+import javax.servlet.ServletException;
+import javax.servlet.ServletRequest;
+import javax.servlet.ServletResponse;
+import javax.servlet.http.HttpServletRequest;
+
+/**
+ *
+ * @author hilgeru
+ */
+public class NiceFilter implements Filter {
+
+  @Override
+  public void init(FilterConfig filterConfig) throws ServletException {
+    // ...
+  }
+
+  @Override
+  public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException {
+    if(request instanceof HttpServletRequest) {
+      HttpServletRequest hr = (HttpServletRequest) request;
+      String servletPath = hr.getServletPath();
+      String[] path = servletPath.split("/");
+      request.getRequestDispatcher("../api?c=de.uhilger.um.api.UserMgr&m=" + path[2]).forward(request, response);
+    }
+  }
+
+  @Override
+  public void destroy() {
+    // ...
+  }
+  
+}
diff --git a/web/WEB-INF/web.xml b/web/WEB-INF/web.xml
index e61873f..eb731ab 100644
--- a/web/WEB-INF/web.xml
+++ b/web/WEB-INF/web.xml
@@ -5,9 +5,37 @@
         <param-name>dsname</param-name>
         <param-value>jdbc/NewUserDB</param-value>
     </context-param>
+    <filter>
+        <filter-name>NiceFilter</filter-name>
+        <filter-class>de.uhilger.um.web.NiceFilter</filter-class>
+    </filter>
+    <filter-mapping>
+        <filter-name>NiceFilter</filter-name>
+        <url-pattern>/svc/*</url-pattern>
+    </filter-mapping>
     <listener>
         <listener-class>de.uhilger.um.App</listener-class>
     </listener>
+    <servlet>
+        <servlet-name>TransitServlet</servlet-name>
+        <servlet-class>de.uhilger.transit.web.TransitServlet</servlet-class>
+        <init-param>
+            <param-name>klassen</param-name>
+            <param-value>de.uhilger.um.api</param-value>
+        </init-param>
+    </servlet>
+    <servlet>
+        <servlet-name>TestServlet</servlet-name>
+        <jsp-file>/show.jsp</jsp-file>
+    </servlet>
+    <servlet-mapping>
+        <servlet-name>TransitServlet</servlet-name>
+        <url-pattern>/api</url-pattern>
+    </servlet-mapping>
+    <servlet-mapping>
+        <servlet-name>TestServlet</servlet-name>
+        <url-pattern>/test/*</url-pattern>
+    </servlet-mapping>
     <session-config>
         <session-timeout>
             30
diff --git a/web/show.jsp b/web/show.jsp
new file mode 100644
index 0000000..47eea25
--- /dev/null
+++ b/web/show.jsp
@@ -0,0 +1,26 @@
+<%@page contentType="text/html" pageEncoding="UTF-8"%>
+<!DOCTYPE html>
+<html>
+  <head>
+    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
+    <title>um Werte</title>
+  </head>
+  <body>
+    <p>Werte</p>
+    <p>pathInfo: <%=request.getPathInfo()%></p>
+    <p>requestURL <%=request.getRequestURL()%></p>
+    <p>contextPath <%=request.getContextPath()%></p>
+    <p>servletPath <%=request.getServletPath()%></p>
+    <p>
+      <%
+        String pathInfo = request.getPathInfo();
+        String[] path = pathInfo.split("/");
+        for(int i = 0; i < path.length; i++) {
+       %>
+        <p>path[<%=i%>]: <%=path[i]%></p>
+       <%
+        }
+       %>
+    </p>
+  </body>
+</html>
diff --git a/web/ui/ui.js b/web/ui/ui.js
index e567e34..cb2f979 100644
--- a/web/ui/ui.js
+++ b/web/ui/ui.js
@@ -1,49 +1,57 @@
-/*
 
-  Beispiel aus Spot fuer den Post eines Coordinates-Objektes
-
-    var coord = new Coordinates(
-                    c.latitude, 
-                    c.longitude, 
-                    self.nummer(c.altitude), 
-                    self.nummer(c.accuracy), 
-                    self.nummer(c.altitudeAccuracy), 
-                    self.nummer(c.heading), 
-                    self.nummer(c.speed));
-            var cObj = self.serialisieren(coord);
-
-
-            $.ajax({
-              url: '../rpc?c=de.uhilger.spot.api.NutzerApi&m=ortSpeichern',
-              data: {
-                p: cObj
-              },
-              type: "POST",
-              dataType : "html",
-              //success: function( resp ) {
-                //$('#fehler').html('Antwort: ' + resp);
-              //},
-              error: function( xhr, status, errorThrown ) {
-                $('#fehler').html("Error: " + errorThrown + " Status: " + status);
-              },
-              complete: function( xhr, status ) {
-                //alert( "The request is complete!" );
-              }
-            });      
-            usw.
-
- 
-  function Coordinates(la, lo, al, ac, aa, hd, sp) {
-   this.latitude = la;
-   this.longitude = lo;
-   this.altitude = al;
-   this.accuracy = ac;
-   this.altitudeAccuracy = aa;
-   this.heading = hd;
-   this.speed = sp;
+function um_init() {
+  $('.user-save-btn').click(um_user_save);
 }
- 
- 
- 
- 
- */
\ No newline at end of file
+
+function um_user_save() {
+  var user = um_user_form_lesen();
+  var kww = $('#kennwortw').val();
+  if(user.pw != kww) {
+    alert('Kennworte stimmen nicht ueberein.');
+  } else {
+    alert('user-save ' + user.id);
+    um_apicall(self.serialisieren(user));
+  }
+}
+
+function um_apicall(obj) {
+  var c = 'de.uhilger.um.api.UserMgr';
+  var m = 'createUser';
+  var u = '../api?c=' + c + '&m=' + m;
+  $.ajax({
+    url: u,
+    data: {
+      p: obj
+    },
+    type: "POST",
+    dataType : "html",
+    //success: function( resp ) {
+      //$('#fehler').html('Antwort: ' + resp);
+    //},
+    error: function( xhr, status, errorThrown ) {
+      $('#fehler').html("Error: " + errorThrown + " Status: " + status);
+    },
+    complete: function( xhr, status ) {
+      //alert( "The request is complete!" );
+    }
+  });      
+}
+
+function um_user_form_lesen() {
+  var userId = $('#anmeldename').val();
+  var kw = $('#kennwort').val();
+  var user = new User(userId, kw, '-', '-', '-');
+  return user;
+}
+
+function serialisieren(obj) {
+  return '{"' + obj.constructor.name + '":' + JSON.stringify(obj) + '}';
+};
+
+function User(i, p, fn, ln, em) {
+  this.id = i;
+  this.pw = p;
+  this.firstName = fn;
+  this.lastName = ln;
+  this.email = em;
+}
\ No newline at end of file
diff --git a/web/ui/user.jsp b/web/ui/user.jsp
index 09a13bc..8952c94 100644
--- a/web/ui/user.jsp
+++ b/web/ui/user.jsp
@@ -10,15 +10,25 @@
   <head>
     <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
     <title>Benutzer</title>
+    <link rel="stylesheet" href="/jslib/skeleton-2.0.4/css/normalize.css">
+    <link rel="stylesheet" href="/jslib/skeleton-2.0.4/css/skeleton.css">
     <link rel="stylesheet" type="text/css" href="stile.css">
   </head>
   <body>
     <h1>Benutzer</h1>
-    <div>
+    <div id="user-form">
       <input type="text" size="20" maxlength="20" placeholder="Anmeldename" name="anmeldename" id="anmeldename">
       <input type="password" size="20" maxlength="20" placeholder="Kennwort" name="kennwort" id="kennwort">
       <input type="password" size="20" maxlength="20" placeholder="Wiederholung" name="kennwortw" id="kennwortw">
-      <button>OK</button>
+      <button class="user-save-btn">OK</button>
     </div>
+    <script src="/jslib/jquery-1.11.1/jquery-1.11.1.min.js"></script>
+    <script src="ui.js"></script>
+    <script type="text/javascript" charset="utf-8">
+      //var ui;
+      $(document).ready(function() {
+        um_init();
+      });
+    </script>
   </body>
 </html>

--
Gitblit v1.9.3