aboutsummaryrefslogtreecommitdiff
path: root/juick-server/src/main/java/com
diff options
context:
space:
mode:
authorGravatar Alexander Alexeev2016-11-28 20:04:05 +0700
committerGravatar Vitaly Takmazov2016-11-28 16:11:10 +0300
commit915e804c097ed97e39eebc498f1339cab53109cd (patch)
tree875ddc9572df97af55934cce597bd4b0c25f7f90 /juick-server/src/main/java/com
parent91554cb30eefd48e85ebb744aea0be7efff13e11 (diff)
WebUtils utilite class ; some inprovements; tests now run successfully
Diffstat (limited to 'juick-server/src/main/java/com')
-rw-r--r--juick-server/src/main/java/com/juick/util/WebUtils.java45
1 files changed, 45 insertions, 0 deletions
diff --git a/juick-server/src/main/java/com/juick/util/WebUtils.java b/juick-server/src/main/java/com/juick/util/WebUtils.java
new file mode 100644
index 00000000..8e240c5d
--- /dev/null
+++ b/juick-server/src/main/java/com/juick/util/WebUtils.java
@@ -0,0 +1,45 @@
+package com.juick.util;
+
+import java.util.regex.Pattern;
+
+/**
+ * Created by aalexeev on 11/28/16.
+ */
+public class WebUtils {
+ private WebUtils() {
+ throw new IllegalStateException();
+ }
+
+ private static final Pattern USER_NAME_PATTERN = Pattern.compile("[a-zA-Z-_\\d]{2,16}");
+
+ private static final Pattern POST_NUMBER_PATTERN = Pattern.compile("-?\\d+");
+
+ private static final Pattern JID_PATTERN = Pattern.compile("^[a-zA-Z0-9\\\\-\\\\_\\\\@\\\\.]{6,64}$");
+
+
+ public static boolean isPostNumber(final String aString) {
+ return aString != null && POST_NUMBER_PATTERN.matcher(aString).matches();
+ }
+
+ public static boolean isNotPostNumber(final String aString) {
+ return !isPostNumber(aString);
+ }
+
+ public static boolean isUserName(final String aString) {
+ return aString != null && USER_NAME_PATTERN.matcher(aString).matches();
+ }
+
+ public static boolean isNotUserName(final String aString) {
+ return !isUserName(aString);
+ }
+
+ public static boolean isJid(final String aString) {
+ return aString != null && JID_PATTERN.matcher(aString).matches();
+ }
+
+ public static boolean isNotJid(final String aString) {
+ return !isJid(aString);
+ }
+
+
+}