Mercurial > dive4elements > river
annotate flys-client/src/main/java/de/intevation/flys/client/shared/FieldVerifier.java @ 62:faf565d22c9a
Moved image sources to an own directory to avoid that those files are included in the web application archive.
flys-client/trunk@1528 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author | Ingo Weinzierl <ingo.weinzierl@intevation.de> |
---|---|
date | Mon, 21 Mar 2011 09:56:00 +0000 |
parents | 4e8be5e7855f |
children | ba1b27b7d282 |
rev | line source |
---|---|
0
4e8be5e7855f
Start of a GWT based client for FLYS-3.0
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
1 package de.intevation.flys.client.shared; |
4e8be5e7855f
Start of a GWT based client for FLYS-3.0
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
2 |
4e8be5e7855f
Start of a GWT based client for FLYS-3.0
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
3 /** |
4e8be5e7855f
Start of a GWT based client for FLYS-3.0
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
4 * <p> |
4e8be5e7855f
Start of a GWT based client for FLYS-3.0
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
5 * FieldVerifier validates that the name the user enters is valid. |
4e8be5e7855f
Start of a GWT based client for FLYS-3.0
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
6 * </p> |
4e8be5e7855f
Start of a GWT based client for FLYS-3.0
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
7 * <p> |
4e8be5e7855f
Start of a GWT based client for FLYS-3.0
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
8 * This class is in the <code>shared</code> package because we use it in both |
4e8be5e7855f
Start of a GWT based client for FLYS-3.0
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
9 * the client code and on the server. On the client, we verify that the name is |
4e8be5e7855f
Start of a GWT based client for FLYS-3.0
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
10 * valid before sending an RPC request so the user doesn't have to wait for a |
4e8be5e7855f
Start of a GWT based client for FLYS-3.0
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
11 * network round trip to get feedback. On the server, we verify that the name is |
4e8be5e7855f
Start of a GWT based client for FLYS-3.0
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
12 * correct to ensure that the input is correct regardless of where the RPC |
4e8be5e7855f
Start of a GWT based client for FLYS-3.0
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
13 * originates. |
4e8be5e7855f
Start of a GWT based client for FLYS-3.0
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
14 * </p> |
4e8be5e7855f
Start of a GWT based client for FLYS-3.0
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
15 * <p> |
4e8be5e7855f
Start of a GWT based client for FLYS-3.0
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
16 * When creating a class that is used on both the client and the server, be sure |
4e8be5e7855f
Start of a GWT based client for FLYS-3.0
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
17 * that all code is translatable and does not use native JavaScript. Code that |
4e8be5e7855f
Start of a GWT based client for FLYS-3.0
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
18 * is note translatable (such as code that interacts with a database or the file |
4e8be5e7855f
Start of a GWT based client for FLYS-3.0
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
19 * system) cannot be compiled into client side JavaScript. Code that uses native |
4e8be5e7855f
Start of a GWT based client for FLYS-3.0
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
20 * JavaScript (such as Widgets) cannot be run on the server. |
4e8be5e7855f
Start of a GWT based client for FLYS-3.0
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
21 * </p> |
4e8be5e7855f
Start of a GWT based client for FLYS-3.0
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
22 */ |
4e8be5e7855f
Start of a GWT based client for FLYS-3.0
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
23 public class FieldVerifier { |
4e8be5e7855f
Start of a GWT based client for FLYS-3.0
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
24 |
4e8be5e7855f
Start of a GWT based client for FLYS-3.0
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
25 /** |
4e8be5e7855f
Start of a GWT based client for FLYS-3.0
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
26 * Verifies that the specified name is valid for our service. |
4e8be5e7855f
Start of a GWT based client for FLYS-3.0
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
27 * |
4e8be5e7855f
Start of a GWT based client for FLYS-3.0
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
28 * In this example, we only require that the name is at least four |
4e8be5e7855f
Start of a GWT based client for FLYS-3.0
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
29 * characters. In your application, you can use more complex checks to ensure |
4e8be5e7855f
Start of a GWT based client for FLYS-3.0
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
30 * that usernames, passwords, email addresses, URLs, and other fields have the |
4e8be5e7855f
Start of a GWT based client for FLYS-3.0
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
31 * proper syntax. |
4e8be5e7855f
Start of a GWT based client for FLYS-3.0
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
32 * |
4e8be5e7855f
Start of a GWT based client for FLYS-3.0
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
33 * @param name the name to validate |
4e8be5e7855f
Start of a GWT based client for FLYS-3.0
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
34 * @return true if valid, false if invalid |
4e8be5e7855f
Start of a GWT based client for FLYS-3.0
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
35 */ |
4e8be5e7855f
Start of a GWT based client for FLYS-3.0
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
36 public static boolean isValidName(String name) { |
4e8be5e7855f
Start of a GWT based client for FLYS-3.0
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
37 if (name == null) { |
4e8be5e7855f
Start of a GWT based client for FLYS-3.0
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
38 return false; |
4e8be5e7855f
Start of a GWT based client for FLYS-3.0
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
39 } |
4e8be5e7855f
Start of a GWT based client for FLYS-3.0
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
40 return name.length() > 3; |
4e8be5e7855f
Start of a GWT based client for FLYS-3.0
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
41 } |
4e8be5e7855f
Start of a GWT based client for FLYS-3.0
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
42 } |