diff options
author | 2013-01-29 23:45:00 +0700 | |
---|---|---|
committer | 2013-01-29 23:45:00 +0700 | |
commit | cdbf949013fe140fed0e5ad79ad6111c97ea07ad (patch) | |
tree | f6ce3225d78eacca649fe219f0aded18f718d864 /src/java/com/juick/http/www/Blogs.java | |
parent | 6a6b574cd010f01b4d26907707a28e70d3e384c6 (diff) |
Sape optimization
Diffstat (limited to 'src/java/com/juick/http/www/Blogs.java')
-rw-r--r-- | src/java/com/juick/http/www/Blogs.java | 66 |
1 files changed, 33 insertions, 33 deletions
diff --git a/src/java/com/juick/http/www/Blogs.java b/src/java/com/juick/http/www/Blogs.java index 527009a1..5acc8947 100644 --- a/src/java/com/juick/http/www/Blogs.java +++ b/src/java/com/juick/http/www/Blogs.java @@ -41,9 +41,9 @@ import javax.servlet.http.HttpServletResponse; * @author Ugnich Anton */ public class Blogs { - + private int relatedTagsStartMID = 0; - + public Blogs(Connection sql) { PreparedStatement stmt = null; ResultSet rs = null; @@ -59,7 +59,7 @@ public class Blogs { Utils.finishSQL(rs, stmt); } } - + protected void doGet(Connection sql, Connection sqlSearch, HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { String paramTagStrQuery = request.getParameter("tag"); if (paramTagStrQuery != null) { @@ -70,18 +70,18 @@ public class Blogs { } Utils.sendPermanentRedirect(response, url); } - + com.juick.User visitor = Utils.getVisitorUser(sql, request); Locale locale = request.getLocale(); ResourceBundle rb = ResourceBundle.getBundle("Blogs", locale); - + String title; ArrayList<Integer> mids; - + String paramShow = request.getParameter("show"); - + String requesturi = request.getRequestURI(); - + int paramTag = 0; String paramTagStr = null; if (requesturi.startsWith("/tag/")) { @@ -94,7 +94,7 @@ public class Blogs { } else if (requesturi.startsWith("/places/")) { //TODO перенести сюда блок, который страницей ниже } - + int paramBefore = 0; String paramBeforeStr = request.getParameter("before"); if (paramBeforeStr != null) { @@ -103,15 +103,15 @@ public class Blogs { } catch (NumberFormatException e) { } } - + String paramSearch = request.getParameter("search"); if (paramSearch != null && paramSearch.length() > 64) { paramSearch = null; } - + com.juick.Place place = null; int visitor_uid = visitor != null ? visitor.UID : 0; - + if (paramShow == null) { if (paramTag > 0) { title = "*" + Utils.encodeHTML(paramTagStr); @@ -179,27 +179,27 @@ public class Blogs { response.sendError(404); return; } - + response.setContentType("text/html; charset=UTF-8"); PrintWriter out = response.getWriter(); try { PageTemplates.pageHead(out, title, null); PageTemplates.pageNavigation(out, locale, visitor, paramSearch); - + out.println("<div id=\"topwrapper\">"); out.println("<div id=\"wrapper\">"); out.println("<div id=\"content\">"); - + if (place != null) { out.println("<div id=\"geomap\"><img src=\"http://maps.google.com/maps/api/staticmap?center=" + place.lat + "," + place.lon + "&markers=color:orange|" + place.lat + "," + place.lon + "&zoom=14&size=600x300&maptype=hybrid&sensor=false\" width=\"600\" height=\"300\" alt=\"Map\"/></div>"); } - + if (mids.size() > 0) { out.println("<ul>"); PageTemplates.printMessages(out, sql, null, mids, visitor, locale); out.println("</ul>"); } - + if (mids.size() == 20) { String nextpage = "?before=" + mids.get(mids.size() - 1); if (paramShow != null) { @@ -210,11 +210,11 @@ public class Blogs { } out.println("<p class=\"page\"><a href=\"" + nextpage + "\">Older →</a></p>"); } - + PageTemplates.pageFooter(request, out, locale, visitor, true); out.println("</div>"); out.println("</div>"); // wrapper - + out.println("<div id=\"column\" class=\"abs\">"); if (visitor != null) { out.println(" <ul>"); @@ -231,33 +231,33 @@ public class Blogs { out.println(" <li><a href=\"/?show=photos\">" + rb.getString("With photos") + "</a></li>"); out.println(" </ul>"); out.println(" <hr/>"); - out.println(" <p>" + getTags(sql, 36) + "</p>"); + out.println(" <p>" + getTags(sql, 40) + "</p>"); out.println("</div>"); - + out.println("<div id=\"rcol\" class=\"abs\">"); PageTemplates.pageYandexAd(out, visitor == null ? 2 : 3); // разный ID для залогиненых и нет if (paramTag > 0 && relatedTagsStartMID > 0) { - String related = getRelatedTags(sql, paramTag, 10); + String related = getRelatedTags(sql, paramTag, 15); if (!related.isEmpty()) { out.println("<h3>Related tags:</h3>"); out.println("<ul id=\"reltags\">" + related + "</ul>"); } } out.println("</div>"); - + out.println("</div>"); // topwrapper PageTemplates.pageDialogTemplate(out, locale); - PageTemplates.pageFooter(request, out, locale, visitor, true); + PageTemplates.pageEnd(out); } finally { out.close(); } } - + private String getTags(Connection sql, int cnt) { String ret = ""; com.juick.Tag tags[] = new com.juick.Tag[cnt]; - + int maxUsageCnt = 0; PreparedStatement stmt = null; ResultSet rs = null; @@ -281,16 +281,16 @@ public class Blogs { } finally { Utils.finishSQL(rs, stmt); } - + Arrays.sort(tags, 0, cnt); - + for (int i = 0; i < cnt; i++) { String tag = Utils.encodeHTML(tags[i].Name); try { tag = "<a href=\"/tag/" + URLEncoder.encode(tags[i].Name, "UTF-8") + "\">" + tag + "</a>"; } catch (UnsupportedEncodingException e) { } - + if (tags[i].UsageCnt > maxUsageCnt / 3 * 2) { ret += "<big>" + tag + "</big> "; } else if (tags[i].UsageCnt > maxUsageCnt / 3) { @@ -299,13 +299,13 @@ public class Blogs { ret += tag + " "; } } - + return ret; } - + private String getRelatedTags(Connection sql, int tag_id, int cnt) { String ret = ""; - + PreparedStatement stmt = null; ResultSet rs = null; try { @@ -325,7 +325,7 @@ public class Blogs { } finally { Utils.finishSQL(rs, stmt); } - + return ret; } } |