From 915e804c097ed97e39eebc498f1339cab53109cd Mon Sep 17 00:00:00 2001 From: Alexander Alexeev Date: Mon, 28 Nov 2016 20:04:05 +0700 Subject: WebUtils utilite class ; some inprovements; tests now run successfully --- .../src/main/java/com/juick/util/WebUtils.java | 45 ++++++++++++++++++++++ 1 file changed, 45 insertions(+) create mode 100644 juick-server/src/main/java/com/juick/util/WebUtils.java (limited to 'juick-server/src/main/java/com/juick') 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); + } + + +} -- cgit v1.2.3