From b2279806e337fff5ee9368b2b399db8e009b0f42 Mon Sep 17 00:00:00 2001
From: Timo Jeremy Pinzauti <timo.pinzauti@smail.inf.h-brs.de>
Date: Tue, 23 May 2017 11:18:19 +0200
Subject: [PATCH] Control angelegt und erste Versuche zur E-Mail Validierung

---
 .../java/org/s4s/gui/views/ContactView.java   |  2 +
 .../s4s/process/control/ContactControl.java   | 14 +++++++
 .../org/s4s/services/util/EmailValidator.java | 41 +++++++++++++++++++
 target/classes/README                         |  1 -
 4 files changed, 57 insertions(+), 1 deletion(-)
 create mode 100644 src/main/java/org/s4s/process/control/ContactControl.java
 create mode 100644 src/main/java/org/s4s/services/util/EmailValidator.java
 delete mode 100644 target/classes/README

diff --git a/src/main/java/org/s4s/gui/views/ContactView.java b/src/main/java/org/s4s/gui/views/ContactView.java
index 3cd89d9..8f10ba8 100644
--- a/src/main/java/org/s4s/gui/views/ContactView.java
+++ b/src/main/java/org/s4s/gui/views/ContactView.java
@@ -10,6 +10,7 @@ import com.vaadin.ui.Panel;
 import com.vaadin.ui.TextArea;
 import com.vaadin.ui.TextField;
 import com.vaadin.ui.VerticalLayout;
+import org.s4s.services.util.EmailValidator;
 
 /**
  * Created by Max-Desktop on 16.05.2017.
@@ -25,6 +26,7 @@ public class ContactView extends TemplateView{
         setMargin(true);
         
         final TextField tfEMail = new TextField("E-Mail");
+        tfEMail.addValidator(new EmailValidator());
         final TextField tfBetreff = new TextField("Betreff");
         final TextArea taNachricht = new TextArea("Ihr Anliegen");
         final Button bSenden = new Button("Senden", FontAwesome.SEND);
diff --git a/src/main/java/org/s4s/process/control/ContactControl.java b/src/main/java/org/s4s/process/control/ContactControl.java
new file mode 100644
index 0000000..b53a22b
--- /dev/null
+++ b/src/main/java/org/s4s/process/control/ContactControl.java
@@ -0,0 +1,14 @@
+/*
+ * 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 org.s4s.process.control;
+
+/**
+ *
+ * @author synot
+ */
+public class ContactControl {
+    
+}
diff --git a/src/main/java/org/s4s/services/util/EmailValidator.java b/src/main/java/org/s4s/services/util/EmailValidator.java
new file mode 100644
index 0000000..921ff34
--- /dev/null
+++ b/src/main/java/org/s4s/services/util/EmailValidator.java
@@ -0,0 +1,41 @@
+/*
+ * 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 org.s4s.services.util;
+
+import com.vaadin.data.Validator;
+
+/**
+ *
+ * @author synot
+ */
+public class EmailValidator implements Validator {
+    /**
+     * Tests if the given value is valid
+     * @param value the value to test
+     */
+    public boolean isValid(Object value) {
+        try {
+            validate(value);
+        } catch (Validator.InvalidValueException ive) {
+            return false;
+        }
+        return true;
+    }
+    
+    /**
+     * Validates
+     * @param value the value to test
+     */
+    public void validate(Object value) throws Validator.InvalidValueException {
+        // Here value is a String containing what *should* be an e-mail address
+        if (value instanceof String) {
+            String email = (String)value;
+            // Match the email string against a (simplistic) regular expression matching e-mail addresses
+            if (!email.matches("^[_\\w\\.\\-]+@[\\w\\.-]+\\.[a-z]{2,6}$"))
+                throw new Validator.InvalidValueException("The e-mail address provided is not valid!");
+        }
+    }
+}
diff --git a/target/classes/README b/target/classes/README
deleted file mode 100644
index faabc74..0000000
--- a/target/classes/README
+++ /dev/null
@@ -1 +0,0 @@
-Please add your static resources here
-- 
GitLab