aboutsummaryrefslogtreecommitdiff
path: root/src/java/com
diff options
context:
space:
mode:
Diffstat (limited to 'src/java/com')
-rw-r--r--src/java/com/juick/http/www/Discover.java4
-rw-r--r--src/java/com/juick/http/www/Errors.java47
-rw-r--r--src/java/com/juick/http/www/Help.java8
-rw-r--r--src/java/com/juick/http/www/Home.java2
-rw-r--r--src/java/com/juick/http/www/Main.java14
-rw-r--r--src/java/com/juick/http/www/SignUp.java2
-rw-r--r--src/java/com/juick/http/www/User.java4
7 files changed, 64 insertions, 17 deletions
diff --git a/src/java/com/juick/http/www/Discover.java b/src/java/com/juick/http/www/Discover.java
index 7fd232a2..d80bffdc 100644
--- a/src/java/com/juick/http/www/Discover.java
+++ b/src/java/com/juick/http/www/Discover.java
@@ -47,7 +47,7 @@ public class Discover {
paramTag = TagQueries.getTag(sql, paramTagStr, false);
}
if (paramTag == null) {
- response.sendError(404);
+ Errors.doGet404(sql, request, response);
return;
}
@@ -68,7 +68,7 @@ public class Discover {
response.setContentType("text/html; charset=UTF-8");
PrintWriter out = response.getWriter();
try {
- String canonical = "";
+ String canonical = null;
if (!paramTag.Name.equals(paramTagStr) && paramBefore == 0) {
canonical = "<link rel=\"canonical\" href=\"http://juick.com/tag/" + URLEncoder.encode(paramTag.Name, "UTF-8") + "\"/>";
}
diff --git a/src/java/com/juick/http/www/Errors.java b/src/java/com/juick/http/www/Errors.java
new file mode 100644
index 00000000..c1ffc2e8
--- /dev/null
+++ b/src/java/com/juick/http/www/Errors.java
@@ -0,0 +1,47 @@
+package com.juick.http.www;
+
+import java.io.IOException;
+import java.io.PrintWriter;
+import java.sql.Connection;
+import javax.servlet.ServletException;
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+
+/**
+ *
+ * @author ugnich
+ */
+public class Errors {
+
+ public static String tagsHTML = null;
+
+ public static void doGet404(Connection sql, HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
+ com.juick.User visitor = Utils.getVisitorUser(sql, request, response);
+
+ if (tagsHTML == null) {
+ tagsHTML = PageTemplates.getPopularTags(sql, 80);
+ }
+
+ response.setStatus(404);
+ response.setContentType("text/html; charset=UTF-8");
+ PrintWriter out = response.getWriter();
+ try {
+ PageTemplates.pageHead(out, "404 Страница не найдена", null);
+ PageTemplates.pageNavigation(out, visitor, null);
+
+ out.println("<aside id=\"column\">");
+ out.println(" <p class=\"tags\">" + tagsHTML + "</p>");
+ out.println("</aside>");
+
+ out.println("<section id=\"content\">");
+ out.println("<h1>Страница не найдена</h1>");
+ out.println("<p>Сожалеем, но страницу с этим адресом удалил её автор, либо её никогда не существовало.</p>");
+ out.println("</section>");
+
+ PageTemplates.pageFooter(request, out, visitor, false);
+ PageTemplates.pageEnd(out);
+ } finally {
+ out.close();
+ }
+ }
+}
diff --git a/src/java/com/juick/http/www/Help.java b/src/java/com/juick/http/www/Help.java
index e69b93a7..eed62efa 100644
--- a/src/java/com/juick/http/www/Help.java
+++ b/src/java/com/juick/http/www/Help.java
@@ -43,14 +43,14 @@ public class Help {
String path[] = request.getRequestURI().split("/");
String page;
if (path.length < 3 || path.length > 4 || path[2].length() != 2 || !path[2].matches("^[a-z]+$")) {
- response.sendError(404);
+ Errors.doGet404(sql, request, response);
return;
}
if (path.length == 4) {
page = path[3];
if (!page.matches("^[a-zA-Z0-9\\-]*$") || page.equals("navigation") || page.equals("index")) {
- response.sendError(404);
+ Errors.doGet404(sql, request, response);
return;
}
} else {
@@ -59,14 +59,14 @@ public class Help {
File f = new File("/var/www/juick.com/help/" + path[2] + "/" + page);
if (!f.isFile()) {
- response.sendError(404);
+ Errors.doGet404(sql, request, response);
return;
}
response.setContentType("text/html; charset=UTF-8");
PrintWriter out = response.getWriter();
try {
- PageTemplates.pageHead(out, "Помощь", "");
+ PageTemplates.pageHead(out, "Помощь", null);
PageTemplates.pageNavigation(out, visitor, null);
out.println("<aside id=\"column\">");
diff --git a/src/java/com/juick/http/www/Home.java b/src/java/com/juick/http/www/Home.java
index a49c2a53..f7b4ca2a 100644
--- a/src/java/com/juick/http/www/Home.java
+++ b/src/java/com/juick/http/www/Home.java
@@ -86,7 +86,7 @@ public class Home {
mids = MessagesQueries.getAll(sql, 0, paramBefore);
}
} else {
- response.sendError(404);
+ Errors.doGet404(sql, request, response);
return;
}
diff --git a/src/java/com/juick/http/www/Main.java b/src/java/com/juick/http/www/Main.java
index 98034359..2c51456e 100644
--- a/src/java/com/juick/http/www/Main.java
+++ b/src/java/com/juick/http/www/Main.java
@@ -173,7 +173,7 @@ public class Main extends HttpServlet implements Stream.StreamListener {
} else if (uri.equals("/pm/sent")) {
pm.doGetSent(sql, request, response, visitor);
} else {
- response.sendError(404);
+ Errors.doGet404(sql, request, response);
}
}
} else if (uri.equals("/logout")) {
@@ -206,13 +206,13 @@ public class Main extends HttpServlet implements Stream.StreamListener {
return;
}
}
- response.sendError(404);
+ Errors.doGet404(sql, request, response);
} else if (uri.matches("^/[^/]+$")) {
com.juick.User user = com.juick.server.UserQueries.getUserByName(sql, request.getRequestURI().substring(1));
if (user != null) {
Utils.sendPermanentRedirect(response, "/" + user.UName + "/");
} else {
- response.sendError(404);
+ Errors.doGet404(sql, request, response);
}
} else if (uri.matches("^/.+/.*")) {
String uriparts[] = uri.split("/");
@@ -241,19 +241,19 @@ public class Main extends HttpServlet implements Stream.StreamListener {
pagesUserThread.doGetThread(sql, request, response, mid);
}
} else {
- response.sendError(404);
+ Errors.doGet404(sql, request, response);
}
} else {
- response.sendError(404);
+ Errors.doGet404(sql, request, response);
}
}
} else if (user != null) {
Utils.sendPermanentRedirect(response, "/" + user.UName + "/" + (uriparts.length > 2 ? uriparts[2] : ""));
} else {
- response.sendError(404);
+ Errors.doGet404(sql, request, response);
}
} else {
- response.sendError(404);
+ Errors.doGet404(sql, request, response);
}
}
diff --git a/src/java/com/juick/http/www/SignUp.java b/src/java/com/juick/http/www/SignUp.java
index cf6679ce..395232a6 100644
--- a/src/java/com/juick/http/www/SignUp.java
+++ b/src/java/com/juick/http/www/SignUp.java
@@ -61,7 +61,7 @@ public class SignUp {
response.setContentType("text/html; charset=UTF-8");
PrintWriter out = response.getWriter();
try {
- PageTemplates.pageHead(out, "Новый пользователь", "");
+ PageTemplates.pageHead(out, "Новый пользователь", null);
PageTemplates.pageNavigation(out, visitor, null);
out.println("<section id=\"content\">");
diff --git a/src/java/com/juick/http/www/User.java b/src/java/com/juick/http/www/User.java
index b517af8e..e969f856 100644
--- a/src/java/com/juick/http/www/User.java
+++ b/src/java/com/juick/http/www/User.java
@@ -55,7 +55,7 @@ public class User {
paramTag = TagQueries.getTag(sql, paramTagStr, false);
}
if (paramTag == null) {
- response.sendError(404);
+ Errors.doGet404(sql, request, response);
return;
}
}
@@ -102,7 +102,7 @@ public class User {
title = "Фотографии " + user.UName;
mids = MessagesQueries.getUserPhotos(sql, user.UID, privacy, paramBefore);
} else {
- response.sendError(404);
+ Errors.doGet404(sql, request, response);
return;
}