aboutsummaryrefslogtreecommitdiff
path: root/juick-spring-www
diff options
context:
space:
mode:
Diffstat (limited to 'juick-spring-www')
-rw-r--r--juick-spring-www/src/main/java/com/juick/www/controllers/ShowMessageController.java20
1 files changed, 8 insertions, 12 deletions
diff --git a/juick-spring-www/src/main/java/com/juick/www/controllers/ShowMessageController.java b/juick-spring-www/src/main/java/com/juick/www/controllers/ShowMessageController.java
index 59ab52c2..e95bd7cf 100644
--- a/juick-spring-www/src/main/java/com/juick/www/controllers/ShowMessageController.java
+++ b/juick-spring-www/src/main/java/com/juick/www/controllers/ShowMessageController.java
@@ -3,6 +3,7 @@ package com.juick.www.controllers;
import com.juick.User;
import com.juick.service.MessagesService;
import com.juick.service.UserService;
+import com.juick.util.WebUtils;
import org.apache.commons.lang3.StringUtils;
import org.apache.commons.lang3.math.NumberUtils;
import org.springframework.stereotype.Controller;
@@ -12,17 +13,12 @@ import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import javax.inject.Inject;
-import java.util.regex.Pattern;
/**
* Created by aalexeev on 11/21/16.
*/
@Controller
public class ShowMessageController {
- 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+");
-
@Inject
private UserService userService;
@Inject
@@ -48,7 +44,7 @@ public class ShowMessageController {
}
if (before == 0) {
- boolean isPostNumber = POST_NUMBER_PATTERN.matcher(anything).matches();
+ boolean isPostNumber = WebUtils.isPostNumber(anything);
int messageId = isPostNumber ?
NumberUtils.toInt(anything) : 0;
@@ -84,7 +80,7 @@ public class ShowMessageController {
int before,
Model model) {
// Check validity of user name before quering from database
- if (!USER_NAME_PATTERN.matcher(userName).matches()) {
+ if (WebUtils.isNotUserName(userName)) {
model.addAttribute("userName", userName);
return "userNotFound";
}
@@ -103,7 +99,7 @@ public class ShowMessageController {
@PathVariable String userName,
Model model) {
// Check validity of user name before quering from database
- if (!USER_NAME_PATTERN.matcher(userName).matches()) {
+ if (WebUtils.isNotUserName(userName)) {
model.addAttribute("userName", userName);
return "userNotFound";
}
@@ -122,7 +118,7 @@ public class ShowMessageController {
@PathVariable String userName,
Model model) {
// Check validity of user name before quering from database
- if (!USER_NAME_PATTERN.matcher(userName).matches()) {
+ if (WebUtils.isNotUserName(userName)) {
model.addAttribute("userName", userName);
return "userNotFound";
}
@@ -141,7 +137,7 @@ public class ShowMessageController {
@PathVariable String userName,
Model model) {
// Check validity of user name before quering from database
- if (!USER_NAME_PATTERN.matcher(userName).matches()) {
+ if (WebUtils.isNotUserName(userName)) {
model.addAttribute("userName", userName);
return "userNotFound";
}
@@ -161,13 +157,13 @@ public class ShowMessageController {
@PathVariable String postNumber,
Model model) {
// Check validity of post number before quering from database
- if (!POST_NUMBER_PATTERN.matcher(postNumber).matches()) {
+ if (WebUtils.isNotPostNumber(postNumber)) {
model.addAttribute("messageId", postNumber);
return "postNotFound";
}
// Check validity of user name before quering from database
- if (!USER_NAME_PATTERN.matcher(userName).matches()) {
+ if (WebUtils.isNotUserName(userName)) {
model.addAttribute("userName", userName);
return "userNotFound";
}