/* * Juick * Copyright (C) 2008-2011, Ugnich Anton * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU Affero General Public License as * published by the Free Software Foundation, either version 3 of the * License, or (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU Affero General Public License for more details. * * You should have received a copy of the GNU Affero General Public License * along with this program. If not, see . */ package com.juick.http.www; import com.juick.Tag; import com.juick.server.TagQueries; import java.io.IOException; import java.io.PrintWriter; import java.io.UnsupportedEncodingException; import java.net.URLEncoder; import java.sql.Connection; import java.util.ArrayList; import java.util.Locale; import java.util.ResourceBundle; import javax.servlet.ServletException; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; /** * * @author Ugnich Anton */ public class NewMessage { protected void doGetNewMessage(Connection sql, HttpServletRequest request, HttpServletResponse response, com.juick.User visitor) throws ServletException, IOException { Locale locale = request.getLocale(); ResourceBundle rbnm = ResourceBundle.getBundle("NewMessage", locale); response.setContentType("text/html; charset=UTF-8"); PrintWriter out = response.getWriter(); try { PageTemplates.pageHead(out, rbnm.getString("New message"), "" + "" + "" + ""); PageTemplates.pageNavigation(out, locale, visitor); out.println("
"); out.println("
"); out.println("

" + rbnm.getString("Location") + ": " + rbnm.getString("Clear") + "

"); out.println("

" + rbnm.getString("Attachment") + ": " + rbnm.getString("or") + " " + rbnm.getString("from webcam") + "
"); out.println("" + rbnm.getString("Photo_JPG") + "
" + rbnm.getString("Webcam photo") + " — " + rbnm.getString("Clear") + "

"); out.println("
"); String body = request.getParameter("body"); if (body == null) { body = ""; } else { if (body.length() > 4096) { body = body.substring(0, 4096); } body = Utils.encodeHTML(body); } out.println("


"); out.println("" + "" + "

"); out.println("
"); out.println("
"); out.println("

" + rbnm.getString("Tags") + ":

"); printUserTags(sql, out, visitor.UID); out.println("
"); out.println("
"); PageTemplates.pageFooter(request, out, locale, visitor); } finally { out.close(); } } void printUserTags(Connection sql, PrintWriter out, int uid) { ArrayList tags = TagQueries.getUserTagsAll(sql, uid); if (tags.isEmpty()) { return; } int min = tags.get(0).UsageCnt; int max = tags.get(0).UsageCnt; for (int i = 1; i < tags.size(); i++) { int usagecnt = tags.get(i).UsageCnt; if (usagecnt < min) { min = usagecnt; } if (usagecnt > max) { max = usagecnt; } } max -= min; out.print("

"); for (int i = 0; i < tags.size(); i++) { if (i > 0) { out.print(" "); } String taglink = ""; try { taglink = "" + Utils.encodeHTML(tags.get(i).Name) + ""; } catch (UnsupportedEncodingException e) { } int usagecnt = tags.get(i).UsageCnt; if (usagecnt <= max / 5 + min) { out.print("" + taglink + ""); } else if (usagecnt <= max / 5 * 2 + min) { out.print(taglink); } else if (usagecnt <= max / 5 * 3 + min) { out.print("" + taglink + ""); } else if (usagecnt <= max / 5 * 4 + min) { out.print("" + taglink + ""); } else { out.print("" + taglink + ""); } } out.println("

"); } protected void doPostNewMessage(Connection sql, HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { } }