Example usage for java.text DateFormat getDateTimeInstance

List of usage examples for java.text DateFormat getDateTimeInstance

Introduction

In this page you can find the example usage for java.text DateFormat getDateTimeInstance.

Prototype

public static final DateFormat getDateTimeInstance(int dateStyle, int timeStyle, Locale aLocale) 

Source Link

Document

Gets the date/time formatter with the given formatting styles for the given locale.

Usage

From source file:de.innovationgate.wga.server.api.WGA.java

/**
 * Returns an OpenWGA date format//  w  w  w. j a  v a2s  . com
 * @param pattern The date format pattern
 * @param locale A locale to use for locale-dependent date parts. Specify null to let the current WebTML context choose the locale.
 * @throws WGException
 */
public DateFormat getDateFormat(String pattern, Locale locale) throws WGException {

    // Select language for language dependent date formats
    if (locale == null) {
        locale = chooseLocale(locale);
    }

    // Language Fallback(s)

    if (WGUtils.isEmpty(pattern)) {
        return DateFormat.getDateTimeInstance(DateFormat.MEDIUM, DateFormat.MEDIUM, locale);
    }

    // For default patterns
    String lcPattern = pattern.toLowerCase();
    if (lcPattern.endsWith("date") || lcPattern.endsWith("time")) {
        int patternLength;
        if (lcPattern.startsWith("short")) {
            patternLength = DateFormat.SHORT;
        } else if (lcPattern.startsWith("medium")) {
            patternLength = DateFormat.MEDIUM;
        } else if (lcPattern.startsWith("long")) {
            patternLength = DateFormat.LONG;
        } else {
            patternLength = DateFormat.FULL;
        }

        if (lcPattern.endsWith("datetime")) {
            return new TextualDateFormat(locale,
                    DateFormat.getDateTimeInstance(patternLength, patternLength, locale));
        } else if (lcPattern.endsWith("time")) {
            return new TextualDateFormat(locale, DateFormat.getTimeInstance(patternLength, locale));
        } else {
            return new TextualDateFormat(locale, DateFormat.getDateInstance(patternLength, locale));
        }

    } else if (lcPattern.equals("iso8601")) {
        return new ISO8601DateFormat();
    }

    // For custom patterns
    SimpleDateFormat dateFormat = new SimpleDateFormat(pattern, locale);
    dateFormat.setLenient(false);
    return new TextualDateFormat(locale, dateFormat);

}

From source file:org.etudes.mneme.impl.AttachmentServiceImpl.java

/**
 * Returns date in specified format/* w  ww.ja  v  a2 s  .c om*/
 * @param date Date object
 * @return Date in specified format
 */
String formatDate(Date date) {
    if (date == null)
        return null;
    Locale userLocale = DateHelper.getPreferredLocale(null);
    TimeZone userZone = DateHelper.getPreferredTimeZone(null);
    DateFormat format = DateFormat.getDateTimeInstance(DateFormat.MEDIUM, DateFormat.MEDIUM, userLocale);
    format.setTimeZone(userZone);

    return removeSeconds(format.format(date));
}

From source file:net.spfbl.http.ServerHTTP.java

private static String getControlPanel(Locale locale, Query query, long time) {
    DateFormat dateFormat = DateFormat.getDateTimeInstance(DateFormat.SHORT, DateFormat.MEDIUM, locale);
    GregorianCalendar calendar = new GregorianCalendar();
    calendar.setTimeInMillis(time);//from  w w  w .  ja v a 2  s . com
    StringBuilder builder = new StringBuilder();
    //        builder.append("<!DOCTYPE html>\n");
    builder.append("<html lang=\"");
    builder.append(locale.getLanguage());
    builder.append("\">\n");
    builder.append("  <head>\n");
    builder.append("    <meta charset=\"UTF-8\">\n");
    if (locale.getLanguage().toLowerCase().equals("pt")) {
        builder.append("    <title>Painel de controle do SPFBL</title>\n");
    } else {
        builder.append("    <title>SPFBL control panel</title>\n");
    }
    // Styled page.
    builder.append("    <style type=\"text/css\">\n");
    builder.append("      body {");
    builder.append("        background: #b4b9d2;\n");
    builder.append("      }\n");
    builder.append("      .button {\n");
    builder.append("          background-color: #4CAF50;\n");
    builder.append("          border: none;\n");
    builder.append("          color: white;\n");
    builder.append("          padding: 16px 32px;\n");
    builder.append("          text-align: center;\n");
    builder.append("          text-decoration: none;\n");
    builder.append("          display: inline-block;\n");
    builder.append("          font-size: 16px;\n");
    builder.append("          margin: 4px 2px;\n");
    builder.append("          -webkit-transition-duration: 0.4s;\n");
    builder.append("          transition-duration: 0.4s;\n");
    builder.append("          cursor: pointer;\n");
    builder.append("      }\n");
    builder.append("      .white {\n");
    builder.append("          background-color: white; \n");
    builder.append("          color: black; \n");
    builder.append("          border: 2px solid #4CAF50;\n");
    builder.append("          font-weight: bold;\n");
    builder.append("      }\n");
    builder.append("      .white:hover {\n");
    builder.append("          background-color: #4CAF50;\n");
    builder.append("          color: white;\n");
    builder.append("      }\n");
    builder.append("      .block {\n");
    builder.append("          background-color: white; \n");
    builder.append("          color: black; \n");
    builder.append("          border: 2px solid #f44336;\n");
    builder.append("          font-weight: bold;\n");
    builder.append("      }\n");
    builder.append("      .block:hover {\n");
    builder.append("          background-color: #f44336;\n");
    builder.append("          color: white;\n");
    builder.append("      }\n");
    builder.append("      .recipient {\n");
    builder.append("          background-color: white; \n");
    builder.append("          color: black; \n");
    builder.append("          border: 2px solid #555555;\n");
    builder.append("          font-weight: bold;\n");
    builder.append("      }\n");
    builder.append("      .recipient:hover {\n");
    builder.append("          background-color: #555555;\n");
    builder.append("          color: white;\n");
    builder.append("      }\n");
    builder.append("    </style>\n");
    builder.append("  </head>\n");
    // Body.
    builder.append("  <body>\n");
    if (locale.getLanguage().toLowerCase().equals("pt")) {
        builder.append("    <b>Recepo:</b> ");
    } else {
        builder.append("    <b>Reception:</b> ");
    }
    builder.append(dateFormat.format(calendar.getTime()));
    builder.append("<br>\n");
    String sender = query.getSenderSimplified(false, false);
    if (sender == null) {
        if (locale.getLanguage().toLowerCase().equals("pt")) {
            builder.append("    <b>Remetente:</b> MAILER-DAEMON");
        } else {
            builder.append("    <b>Sender:</b> MAILER-DAEMON");
        }
    } else if (query.getQualifierName().equals("PASS")) {
        if (locale.getLanguage().toLowerCase().equals("pt")) {
            builder.append("    <b>Remetente autntico:</b> ");
        } else {
            builder.append("    <b>Genuine sender:</b> ");
        }
        builder.append(sender);
    } else if (query.getQualifierName().equals("FAIL")) {
        if (locale.getLanguage().toLowerCase().equals("pt")) {
            builder.append("    <b>Remetente falso:</b> ");
        } else {
            builder.append("    <b>False sender:</b> ");
        }
        builder.append(sender);
    } else {
        if (locale.getLanguage().toLowerCase().equals("pt")) {
            builder.append("    <b>Remetente suspeito:</b> ");
        } else {
            builder.append("    <b>Suspect sender:</b> ");
        }
        builder.append(sender);
    }
    builder.append("<br>\n");
    if (locale.getLanguage().toLowerCase().equals("pt")) {
        builder.append("    <b>Recebe por:</b> ");
    } else {
        builder.append("    <b>Receives for:</b> ");
    }
    String validator = query.getValidator(true);
    Situation situationWhite = query.getSenderWhiteSituation();
    Situation situationBlock = query.getSenderBlockSituation();
    try {
        TreeSet<String> mxDomainSet = query.getSenderMXDomainSet();
        if (mxDomainSet.isEmpty()) {
            if (locale.getLanguage().toLowerCase().equals("pt")) {
                builder.append("nenhum sistema");
            } else {
                builder.append("no system");
            }
        } else {
            builder.append(mxDomainSet);
        }
    } catch (NameNotFoundException ex) {
        validator = null;
        situationWhite = query.getOriginWhiteSituation();
        situationBlock = query.getOriginBlockSituation();
        if (locale.getLanguage().toLowerCase().equals("pt")) {
            builder.append("domnio inexistente");
        } else {
            builder.append("non-existent domain");
        }
    } catch (NamingException ex) {
        if (locale.getLanguage().toLowerCase().equals("pt")) {
            builder.append("erro ao tentar consultar");
        } else {
            builder.append("error when trying to query");
        }
    }
    builder.append("<br>\n");
    URL unsubscribe = query.getUnsubscribeURL();
    if (unsubscribe == null) {
        builder.append("    <br>\n");
    } else {
        if (locale.getLanguage().toLowerCase().equals("pt")) {
            builder.append("     <b>Cancelar inscrio:</b> ");
        } else {
            builder.append("     <b>List unsubscribe:</b> ");
        }
        builder.append("<a target=\"_blank\" href=\"");
        builder.append(unsubscribe);
        builder.append("\">");
        builder.append(unsubscribe.getHost());
        builder.append(unsubscribe.getPath());
        builder.append("</a><br>\n");
    }
    if (locale.getLanguage().toLowerCase().equals("pt")) {
        builder.append("    <b>Politica vigente:</b> ");
    } else {
        builder.append("    <b>Current policy:</b> ");
    }
    String recipient = query.getRecipient();
    Long trapTime = query.getTrapTime();
    boolean blocked = false;
    if (trapTime == null && situationWhite == Situation.SAME) {
        if (locale.getLanguage().toLowerCase().equals("pt")) {
            builder.append("entrega prioritria na mesma situao, exceto malware");
        } else {
            builder.append("priority delivery of ");
            builder.append(query.getSenderSimplified(false, true));
            builder.append(" in the same situation, except malware");
        }
    } else if (trapTime == null && situationWhite == Situation.AUTHENTIC) {
        if (locale.getLanguage().toLowerCase().equals("pt")) {
            builder.append("entrega prioritria de ");
            builder.append(query.getSenderSimplified(false, true));
            builder.append(" quando comprovadamente autntico, exceto malware");
        } else {
            builder.append("priority delivery of ");
            builder.append(query.getSenderSimplified(false, true));
            builder.append(" when proven authentic, except malware");
        }
        if (query.isBlock()) {
            if (locale.getLanguage().toLowerCase().equals("pt")) {
                builder.append(", porm bloqueado para outras situaes");
            } else {
                builder.append(", however blocked to other situations");
            }
        }
    } else if (trapTime == null && situationWhite == Situation.ZONE) {
        if (locale.getLanguage().toLowerCase().equals("pt")) {
            builder.append("entrega prioritria de ");
            builder.append(query.getSenderSimplified(false, true));
            builder.append(" quando disparado por ");
        } else {
            builder.append("priority delivery of ");
            builder.append(query.getSenderSimplified(false, true));
            builder.append(" when shot by ");
        }
        builder.append(validator);
        if (query.isBlock()) {
            if (locale.getLanguage().toLowerCase().equals("pt")) {
                builder.append(", porm bloqueado para outras situaes");
            } else {
                builder.append(", however blocked to other situations");
            }
        }
    } else if (trapTime == null && situationWhite == Situation.IP) {
        if (locale.getLanguage().toLowerCase().equals("pt")) {
            builder.append("entrega prioritria de ");
            builder.append(query.getSenderSimplified(false, true));
            builder.append(" when shot by IP ");
        } else {
            builder.append("priority delivery of ");
            builder.append(query.getSenderSimplified(false, true));
            builder.append(" when coming from the IP ");
        }
        builder.append(validator);
        if (query.isBlock()) {
            if (locale.getLanguage().toLowerCase().equals("pt")) {
                builder.append(", porm bloqueado para outras situaes");
            } else {
                builder.append(", however blocked to other situations");
            }
        }
    } else if (trapTime == null && situationWhite == Situation.ORIGIN) {
        if (locale.getLanguage().toLowerCase().equals("pt")) {
            builder.append("entrega prioritria pela mesma origem");
        } else {
            builder.append("priority delivery the same origin");
        }
    } else if (situationBlock == Situation.DOMAIN) {
        blocked = true;
        String domain = query.getSenderSimplified(true, false);
        if (domain == null) {
            if (locale.getLanguage().toLowerCase().equals("pt")) {
                builder.append("bloquear na mesma situao");
            } else {
                builder.append("block in the same situation");
            }
        } else {
            if (locale.getLanguage().toLowerCase().equals("pt")) {
                builder.append("bloquear ");
                builder.append(domain);
                builder.append(" em qualquer situao");
            } else {
                builder.append("block ");
                builder.append(domain);
                builder.append(" in any situation");
            }
        }
    } else if (situationBlock == Situation.ALL) {
        blocked = true;
        String domain = query.getOriginDomain(false);
        if (domain == null) {
            if (locale.getLanguage().toLowerCase().equals("pt")) {
                builder.append("bloquear na mesma situao");
            } else {
                builder.append("block in the same situation");
            }
        } else {
            if (locale.getLanguage().toLowerCase().equals("pt")) {
                builder.append("bloquear ");
                builder.append(domain);
                builder.append(" em qualquer situao");
            } else {
                builder.append("block ");
                builder.append(domain);
                builder.append(" in any situation");
            }
        }
    } else if (situationBlock == Situation.SAME) {
        blocked = true;
        if (locale.getLanguage().toLowerCase().equals("pt")) {
            builder.append("bloquear na mesma situao");
        } else {
            builder.append("block in the same situation");
        }
    } else if ((situationBlock == Situation.ZONE || situationBlock == Situation.IP)
            && !query.getQualifierName().equals("PASS")) {
        blocked = true;
        if (locale.getLanguage().toLowerCase().equals("pt")) {
            builder.append("bloquear ");
            builder.append(query.getSenderDomain(false));
            builder.append(" quando no for autntico");
        } else {
            builder.append("block ");
            builder.append(query.getSenderDomain(false));
            builder.append(" when not authentic");
        }
    } else if (situationBlock == Situation.ORIGIN) {
        blocked = true;
        if (locale.getLanguage().toLowerCase().equals("pt")) {
            builder.append("bloquear quando disparado pela mesma origem");
        } else {
            builder.append("block when shot by the same source");
        }
    } else if (query.isFail()) {
        blocked = true;
        if (locale.getLanguage().toLowerCase().equals("pt")) {
            builder.append("rejeitar entrega por falsificao");
        } else {
            builder.append("reject delivery of forgery");
        }
    } else if (trapTime != null) {
        if (System.currentTimeMillis() > trapTime) {
            if (locale.getLanguage().toLowerCase().equals("pt")) {
                builder.append("descartar mensagem por armadilha");
            } else {
                builder.append("discard message by spamtrap");
            }
        } else {
            if (locale.getLanguage().toLowerCase().equals("pt")) {
                builder.append("rejeitar entrega por destinatrio inexistente");
            } else {
                builder.append("reject delivery by inexistent recipient");
            }
        }
    } else if (query.hasTokenRed() || query.hasClusterRed()) {
        if (locale.getLanguage().toLowerCase().equals("pt")) {
            builder.append("marcar como suspeita e entregar, sem considerar o contedo");
        } else {
            builder.append("flag as suspected and deliver, regardless of content");
        }
    } else if (query.isSoftfail() || query.hasYellow()) {
        if (locale.getLanguage().toLowerCase().equals("pt")) {
            builder.append("atrasar entrega na mesma situao, sem considerar o contedo");
        } else {
            builder.append("delay delivery in the same situation, regardless of content");
        }
    } else {
        if (locale.getLanguage().toLowerCase().equals("pt")) {
            builder.append("aceitar entrega na mesma situao, sem considerar o contedo");
        } else {
            builder.append("accept delivery in the same situation, regardless of content");
        }
    }
    builder.append(".<br>\n");
    builder.append("    <form method=\"POST\">\n");
    if (validator == null) {
        if (situationWhite != Situation.ORIGIN) {
            builder.append(
                    "      <button type=\"submit\" class=\"white\" name=\"POLICY\" value=\"WHITE_ORIGIN\">");
            if (locale.getLanguage().toLowerCase().equals("pt")) {
                builder.append("Entrega prioritria quando for da mesma origem\n");
            } else {
                builder.append("Priority delivery when the same origin\n");
            }
            builder.append("</button>\n");
        }
        if (situationWhite != Situation.NONE || situationBlock != Situation.ALL) {
            if (situationBlock != Situation.ORIGIN) {
                builder.append(
                        "      <button type=\"submit\" class=\"block\" name=\"POLICY\" value=\"BLOCK_ORIGIN\">");
                if (locale.getLanguage().toLowerCase().equals("pt")) {
                    builder.append("Bloquear se for da mesma origem");
                } else {
                    builder.append("Block if the same origin");
                }
                builder.append("</button>\n");
            }
            String domain = query.getOriginDomain(false);
            if (domain != null) {
                builder.append(
                        "      <button type=\"submit\" class=\"block\" name=\"POLICY\" value=\"BLOCK_ALL\">");
                if (locale.getLanguage().toLowerCase().equals("pt")) {
                    builder.append("Bloquear ");
                    builder.append(domain);
                    builder.append(" em qualquer situao");
                } else {
                    builder.append("Block ");
                    builder.append(domain);
                    builder.append(" in any situation");
                }
                builder.append("</button>\n");
            }
        }
    } else if (validator.equals("PASS")) {
        if (situationWhite != Situation.AUTHENTIC) {
            builder.append(
                    "      <button type=\"submit\" class=\"white\" name=\"POLICY\" value=\"WHITE_AUTHENTIC\">");
            if (locale.getLanguage().toLowerCase().equals("pt")) {
                builder.append("Entrega prioritria quando comprovadamente autntico\n");
            } else {
                builder.append("Priority delivery when proven authentic\n");
            }
            builder.append("</button>\n");
        }
    } else if (Subnet.isValidIP(validator)) {
        if (situationWhite != Situation.IP) {
            builder.append("      <button type=\"submit\" class=\"white\" name=\"POLICY\" value=\"WHITE_IP\">");
            if (locale.getLanguage().toLowerCase().equals("pt")) {
                builder.append("Entrega prioritria quando disparado pelo IP ");
            } else {
                builder.append("Priority delivery when shot by IP ");
            }
            builder.append(validator);
            builder.append("</button>\n");
        }
        if (situationBlock != Situation.IP && situationBlock != Situation.DOMAIN) {
            builder.append("      <button type=\"submit\" class=\"block\" name=\"POLICY\" value=\"BLOCK_IP\">");
            if (locale.getLanguage().toLowerCase().equals("pt")) {
                builder.append("Bloquear ");
                builder.append(query.getSenderDomain(false));
                builder.append(" quando no for autntico");
            } else {
                builder.append("Block ");
                builder.append(query.getSenderDomain(false));
                builder.append(" when not authentic");
            }
            builder.append("</button>\n");
        }
    } else if (Domain.isHostname(validator)) {
        if (situationWhite != Situation.ZONE) {
            builder.append(
                    "      <button type=\"submit\" class=\"white\" name=\"POLICY\" value=\"WHITE_ZONE\">");
            if (locale.getLanguage().toLowerCase().equals("pt")) {
                builder.append("Entrega prioritria quando disparado por ");
            } else {
                builder.append("Priority delivery when shot by ");
            }
            builder.append(validator);
            builder.append("</button>\n");
        }
        if (situationBlock != Situation.ZONE && situationBlock != Situation.DOMAIN) {
            builder.append(
                    "      <button type=\"submit\" class=\"block\" name=\"POLICY\" value=\"BLOCK_ZONE\">");
            if (locale.getLanguage().toLowerCase().equals("pt")) {
                builder.append("Bloquear ");
                builder.append(query.getSenderDomain(false));
                builder.append(" quando no for autntico");
            } else {
                builder.append("Block ");
                builder.append(query.getSenderDomain(false));
                builder.append(" when not authentic");
            }
            builder.append("</button>\n");
        }
    }
    if (situationBlock != Situation.DOMAIN && validator != null) {
        builder.append("      <button type=\"submit\" class=\"block\" name=\"POLICY\" value=\"BLOCK_DOMAIN\">");
        if (locale.getLanguage().toLowerCase().equals("pt")) {
            builder.append("Bloquear ");
            builder.append(query.getSenderSimplified(true, false));
            builder.append(" em qualquer situao");
        } else {
            builder.append("Block ");
            builder.append(query.getSenderSimplified(true, false));
            builder.append(" in any situation");
        }
        builder.append("</button>\n");
    }
    if (!blocked && recipient != null && trapTime != null && query.getUser().isPostmaster()) {
        builder.append(
                "      <button type=\"submit\" class=\"recipient\" name=\"POLICY\" value=\"WHITE_RECIPIENT\">");
        if (locale.getLanguage().toLowerCase().equals("pt")) {
            builder.append("Tornar ");
            builder.append(recipient);
            builder.append(" existente");
        } else {
            builder.append("Make ");
            builder.append(recipient);
            builder.append(" existent");
        }
        builder.append("</button>\n");
    }
    builder.append("    </form>\n");
    builder.append("  </body>\n");
    builder.append("</html>\n");
    return builder.toString();
}

From source file:com.sonicle.webtop.mail.Service.java

public void processGetMessage(HttpServletRequest request, HttpServletResponse response, PrintWriter out) {
    MailAccount account = getAccount(request);
    String pfoldername = request.getParameter("folder");
    String puidmessage = request.getParameter("idmessage");
    String pidattach = request.getParameter("idattach");
    String providername = request.getParameter("provider");
    String providerid = request.getParameter("providerid");
    String nopec = request.getParameter("nopec");
    int idattach = 0;
    boolean isEditor = request.getParameter("editor") != null;
    boolean setSeen = ServletUtils.getBooleanParameter(request, "setseen", true);

    if (df == null) {
        df = DateFormat.getDateTimeInstance(DateFormat.LONG, DateFormat.MEDIUM,
                environment.getProfile().getLocale());
    }//  w  ww .j a  v a2s  .c o  m
    try {
        FolderCache mcache = null;
        Message m = null;
        IMAPMessage im = null;
        int recs = 0;
        long msguid = -1;
        String vheader[] = null;
        boolean wasseen = false;
        boolean isPECView = false;
        String sout = "{\nmessage: [\n";
        if (providername == null) {
            account.checkStoreConnected();
            mcache = account.getFolderCache(pfoldername);
            msguid = Long.parseLong(puidmessage);
            m = mcache.getMessage(msguid);
            im = (IMAPMessage) m;
            im.setPeek(us.isManualSeen());
            if (m.isExpunged())
                throw new MessagingException("Message " + puidmessage + " expunged");
            vheader = m.getHeader("Disposition-Notification-To");
            wasseen = m.isSet(Flags.Flag.SEEN);
            if (pidattach != null) {

                HTMLMailData mailData = mcache.getMailData((MimeMessage) m);
                Part part = mailData.getAttachmentPart(Integer.parseInt(pidattach));
                m = (Message) part.getContent();
                idattach = Integer.parseInt(pidattach) + 1;
            } else if (nopec == null && mcache.isPEC()) {
                String hdrs[] = m.getHeader(HDR_PEC_TRASPORTO);
                if (hdrs != null && hdrs.length > 0 && hdrs[0].equals("posta-certificata")) {
                    HTMLMailData mailData = mcache.getMailData((MimeMessage) m);
                    int parts = mailData.getAttachmentPartCount();
                    for (int i = 0; i < parts; ++i) {
                        Part p = mailData.getAttachmentPart(i);
                        if (p.isMimeType("message/rfc822")) {
                            m = (Message) p.getContent();
                            idattach = i + 1;
                            isPECView = true;
                            break;
                        }
                    }
                }
            }
        } else {
            // TODO: provider get message!!!!
            /*                WebTopService provider=wts.getServiceByName(providername);
                         MessageContentProvider mcp=provider.getMessageContentProvider(providerid);
                         m=new MimeMessage(session,mcp.getSource());
                         mcache=fcProvided;
                         mcache.addProvidedMessage(providername, providerid, m);*/
        }
        String messageid = getMessageID(m);
        String subject = m.getSubject();
        if (subject == null) {
            subject = "";
        } else {
            try {
                subject = MailUtils.decodeQString(subject);
            } catch (Exception exc) {

            }
        }
        java.util.Date d = m.getSentDate();
        if (d == null) {
            d = m.getReceivedDate();
        }
        if (d == null) {
            d = new java.util.Date(0);
        }
        String date = df.format(d).replaceAll("\\.", ":");
        String fromName = "";
        String fromEmail = "";
        Address as[] = m.getFrom();
        InternetAddress iafrom = null;
        if (as != null && as.length > 0) {
            iafrom = (InternetAddress) as[0];
            fromName = iafrom.getPersonal();
            fromEmail = adjustEmail(iafrom.getAddress());
            if (fromName == null) {
                fromName = fromEmail;
            }
        }
        sout += "{iddata:'from',value1:'" + StringEscapeUtils.escapeEcmaScript(MailUtils.htmlescape(fromName))
                + "',value2:'" + StringEscapeUtils.escapeEcmaScript(fromEmail) + "',value3:0},\n";
        recs += 2;
        Address tos[] = m.getRecipients(RecipientType.TO);
        if (tos != null) {
            for (Address to : tos) {
                InternetAddress ia = (InternetAddress) to;
                String toName = ia.getPersonal();
                String toEmail = adjustEmail(ia.getAddress());
                if (toName == null) {
                    toName = toEmail;
                }
                sout += "{iddata:'to',value1:'"
                        + StringEscapeUtils.escapeEcmaScript(MailUtils.htmlescape(toName)) + "',value2:'"
                        + StringEscapeUtils.escapeEcmaScript(toEmail) + "',value3:0},\n";
                ++recs;
            }
        }
        Address ccs[] = m.getRecipients(RecipientType.CC);
        if (ccs != null) {
            for (Address cc : ccs) {
                InternetAddress ia = (InternetAddress) cc;
                String ccName = ia.getPersonal();
                String ccEmail = adjustEmail(ia.getAddress());
                if (ccName == null) {
                    ccName = ccEmail;
                }
                sout += "{iddata:'cc',value1:'" + StringEscapeUtils.escapeEcmaScript(ccName) + "',value2:'"
                        + StringEscapeUtils.escapeEcmaScript(ccEmail) + "',value3:0},\n";
                ++recs;
            }
        }
        Address bccs[] = m.getRecipients(RecipientType.BCC);
        if (bccs != null)
            for (Address bcc : bccs) {
                InternetAddress ia = (InternetAddress) bcc;
                String bccName = ia.getPersonal();
                String bccEmail = adjustEmail(ia.getAddress());
                if (bccName == null) {
                    bccName = bccEmail;
                }
                sout += "{iddata:'bcc',value1:'" + StringEscapeUtils.escapeEcmaScript(bccName) + "',value2:'"
                        + StringEscapeUtils.escapeEcmaScript(bccEmail) + "',value3:0},\n";
                ++recs;
            }
        ArrayList<String> htmlparts = null;
        boolean balanceTags = isPreviewBalanceTags(iafrom);
        if (providername == null) {
            htmlparts = mcache.getHTMLParts((MimeMessage) m, msguid, false, balanceTags);
        } else {
            htmlparts = mcache.getHTMLParts((MimeMessage) m, providername, providerid, balanceTags);
        }
        HTMLMailData mailData = mcache.getMailData((MimeMessage) m);
        ICalendarRequest ir = mailData.getICalRequest();
        if (ir != null) {
            if (htmlparts.size() > 0)
                sout += "{iddata:'html',value1:'" + StringEscapeUtils.escapeEcmaScript(htmlparts.get(0))
                        + "',value2:'',value3:0},\n";
        } else {
            for (String html : htmlparts) {
                //sout += "{iddata:'html',value1:'" + OldUtils.jsEscape(html) + "',value2:'',value3:0},\n";
                sout += "{iddata:'html',value1:'" + StringEscapeUtils.escapeEcmaScript(html)
                        + "',value2:'',value3:0},\n";
                ++recs;
            }
        }

        /*if (!wasseen) {
           //if (us.isManualSeen()) {
           if (!setSeen) {
              m.setFlag(Flags.Flag.SEEN, false);
           } else {
              //if no html part, flag seen is not set
              if (htmlparts.size()==0) m.setFlag(Flags.Flag.SEEN, true);
           }
        }*/
        if (!us.isManualSeen()) {
            if (htmlparts.size() == 0)
                m.setFlag(Flags.Flag.SEEN, true);
        } else {
            if (setSeen)
                m.setFlag(Flags.Flag.SEEN, true);
        }

        int acount = mailData.getAttachmentPartCount();
        for (int i = 0; i < acount; ++i) {
            Part p = mailData.getAttachmentPart(i);
            String ctype = p.getContentType();
            Service.logger.debug("attachment " + i + " is " + ctype);
            int ix = ctype.indexOf(';');
            if (ix > 0) {
                ctype = ctype.substring(0, ix);
            }
            String cidnames[] = p.getHeader("Content-ID");
            String cidname = null;
            if (cidnames != null && cidnames.length > 0)
                cidname = mcache.normalizeCidFileName(cidnames[0]);
            boolean isInlineable = isInlineableMime(ctype);
            boolean inline = ((p.getHeader("Content-Location") != null) || (cidname != null)) && isInlineable;
            if (inline && cidname != null)
                inline = mailData.isReferencedCid(cidname);
            if (p.getDisposition() != null && p.getDisposition().equalsIgnoreCase(Part.INLINE) && inline) {
                continue;
            }

            String imgname = null;
            boolean isCalendar = ctype.equalsIgnoreCase("text/calendar")
                    || ctype.equalsIgnoreCase("text/icalendar");
            if (isCalendar) {
                imgname = "resources/" + getManifest().getId() + "/laf/" + cus.getLookAndFeel()
                        + "/ical_16.png";
            }

            String pname = getPartName(p);
            try {
                pname = MailUtils.decodeQString(pname);
            } catch (Exception exc) {
            }
            if (pname == null) {
                ix = ctype.indexOf("/");
                String fname = ctype;
                if (ix > 0) {
                    fname = ctype.substring(ix + 1);
                }
                //String ext = WT.getMediaTypeExtension(ctype);
                //if (ext == null) {
                pname = fname;
                //} else {
                //   pname = fname + "." + ext;
                //}
                if (isCalendar)
                    pname += ".ics";
            } else {
                if (isCalendar && !StringUtils.endsWithIgnoreCase(pname, ".ics"))
                    pname += ".ics";
            }
            int size = p.getSize();
            int lines = (size / 76);
            int rsize = size - (lines * 2);//(p.getSize()/4)*3;
            String iddata = ctype.equalsIgnoreCase("message/rfc822") ? "eml"
                    : (inline ? "inlineattach" : "attach");
            boolean editable = isFileEditableInDocEditor(pname);

            sout += "{iddata:'" + iddata + "',value1:'" + (i + idattach) + "',value2:'"
                    + StringEscapeUtils.escapeEcmaScript(MailUtils.htmlescape(pname)) + "',value3:" + rsize
                    + ",value4:"
                    + (imgname == null ? "null" : "'" + StringEscapeUtils.escapeEcmaScript(imgname) + "'")
                    + ", editable: " + editable + " },\n";
        }
        if (!mcache.isDrafts() && !mcache.isSent() && !mcache.isSpam() && !mcache.isTrash()
                && !mcache.isArchive()) {
            if (vheader != null && vheader[0] != null && !wasseen) {
                sout += "{iddata:'receipt',value1:'" + us.getReadReceiptConfirmation() + "',value2:'"
                        + StringEscapeUtils.escapeEcmaScript(vheader[0]) + "',value3:0},\n";
            }
        }

        String h = getSingleHeaderValue(m, "Sonicle-send-scheduled");
        if (h != null && h.equals("true")) {
            java.util.Calendar scal = parseScheduleHeader(getSingleHeaderValue(m, "Sonicle-send-date"),
                    getSingleHeaderValue(m, "Sonicle-send-time"));
            if (scal != null) {
                java.util.Date sd = scal.getTime();
                String sdate = df.format(sd).replaceAll("\\.", ":");
                sout += "{iddata:'scheddate',value1:'" + StringEscapeUtils.escapeEcmaScript(sdate)
                        + "',value2:'',value3:0},\n";
            }
        }

        if (ir != null) {

            /*
            ICalendarManager calMgr = (ICalendarManager)WT.getServiceManager("com.sonicle.webtop.calendar",environment.getProfileId());
            if (calMgr != null) {
               if (ir.getMethod().equals("REPLY")) {
                  calMgr.updateEventFromICalReply(ir.getCalendar());
                  //TODO: gestire lato client una notifica di avvenuto aggiornamento
               } else {
                  Event evt = calMgr..getEvent(GetEventScope.PERSONAL_AND_INCOMING, false, ir.getUID())
                  if (evt != null) {
             UserProfileId pid = getEnv().getProfileId();
             UserProfile.Data ud = WT.getUserData(pid);
             boolean iAmOrganizer = StringUtils.equalsIgnoreCase(evt.getOrganizerAddress(), ud.getEmailAddress());
             boolean iAmOwner = pid.equals(calMgr.getCalendarOwner(evt.getCalendarId()));
                     
             if (!iAmOrganizer && !iAmOwner) {
                //TODO: gestire lato client l'aggiornamento: Accetta/Rifiuta, Aggiorna e20 dopo update/request
             }
                  }
               }
            }
            */

            ICalendarManager cm = (ICalendarManager) WT.getServiceManager("com.sonicle.webtop.calendar", true,
                    environment.getProfileId());
            if (cm != null) {
                int eid = -1;
                //Event ev=cm.getEventByScope(EventScope.PERSONAL_AND_INCOMING, ir.getUID());
                Event ev = null;
                if (ir.getMethod().equals("REPLY")) {
                    // Previous impl. forced (forceOriginal == true)
                    ev = cm.getEvent(GetEventScope.PERSONAL_AND_INCOMING, ir.getUID());
                } else {
                    ev = cm.getEvent(GetEventScope.PERSONAL_AND_INCOMING, ir.getUID());
                }

                UserProfileId pid = getEnv().getProfileId();
                UserProfile.Data ud = WT.getUserData(pid);

                if (ev != null) {
                    InternetAddress organizer = InternetAddressUtils.toInternetAddress(ev.getOrganizer());
                    boolean iAmOwner = pid.equals(cm.getCalendarOwner(ev.getCalendarId()));
                    boolean iAmOrganizer = (organizer != null)
                            && StringUtils.equalsIgnoreCase(organizer.getAddress(), ud.getEmailAddress());

                    //TODO: in reply controllo se mail combacia con quella dell'attendee che risponde...
                    //TODO: rimuovere controllo su data? dovrebbe sempre aggiornare?

                    if (iAmOwner || iAmOrganizer) {
                        eid = 0;
                        //TODO: troviamo un modo per capire se la risposta si riverisce all'ultima versione dell'evento? Nuovo campo timestamp?
                        /*
                        DateTime dtEvt = ev.getRevisionTimestamp().withMillisOfSecond(0).withZone(DateTimeZone.UTC);
                        DateTime dtICal = ICal4jUtils.fromICal4jDate(ir.getLastModified(), ICal4jUtils.getTimeZone(DateTimeZone.UTC));
                        if (dtICal.isAfter(dtEvt)) {
                           eid = 0;
                        } else {
                           eid = ev.getEventId();
                        }
                        */
                    }
                }
                sout += "{iddata:'ical',value1:'" + ir.getMethod() + "',value2:'" + ir.getUID() + "',value3:'"
                        + eid + "'},\n";
            }
        }

        sout += "{iddata:'date',value1:'" + StringEscapeUtils.escapeEcmaScript(date)
                + "',value2:'',value3:0},\n";
        sout += "{iddata:'subject',value1:'" + StringEscapeUtils.escapeEcmaScript(MailUtils.htmlescape(subject))
                + "',value2:'',value3:0},\n";
        sout += "{iddata:'messageid',value1:'" + StringEscapeUtils.escapeEcmaScript(messageid)
                + "',value2:'',value3:0}\n";

        if (providername == null && !mcache.isSpecial()) {
            mcache.refreshUnreads();
        }
        long millis = System.currentTimeMillis();
        sout += "\n],\n";

        String svtags = getJSTagsArray(m.getFlags());
        if (svtags != null)
            sout += "tags: " + svtags + ",\n";

        if (isPECView) {
            sout += "pec: true,\n";
        }

        sout += "total:" + recs + ",\nmillis:" + millis + "\n}\n";
        out.println(sout);

        if (im != null)
            im.setPeek(false);

        //            if (!wasopen) folder.close(false);
    } catch (Exception exc) {
        Service.logger.error("Exception", exc);
    }
}

From source file:net.spfbl.http.ServerHTTP.java

private static String getControlPanel(Locale locale, User user, Long begin, String filter) {
    StringBuilder builder = new StringBuilder();
    if (begin == null && filter == null) {
        //            builder.append("<!DOCTYPE html>\n");
        builder.append("<html lang=\"");
        builder.append(locale.getLanguage());
        builder.append("\">\n");
        builder.append("  <head>\n");
        builder.append("    <meta charset=\"UTF-8\">\n");
        if (locale.getLanguage().toLowerCase().equals("pt")) {
            builder.append("    <title>Painel de controle do SPFBL</title>\n");
        } else {/*from  w  w  w.  j  a  v a2 s . c  o  m*/
            builder.append("    <title>SPFBL control panel</title>\n");
        }
        // Styled page.
        builder.append("    <style type=\"text/css\">\n");
        builder.append("      body {\n");
        builder.append("        margin:180px 0px 30px 0px;\n");
        builder.append("        background:lightgray;\n");
        builder.append("      }\n");
        builder.append("      iframe {\n");
        builder.append("        border-width: 0px 0px 0px 0px;\n");
        builder.append("        width:100%;\n");
        builder.append("        height:150px;\n");
        builder.append("      }\n");
        builder.append("      .header {\n");
        builder.append("        background-color:lightgray;\n");
        builder.append("        border-width: 0px 0px 0px 0px;\n");
        builder.append("        position:fixed;\n");
        builder.append("        top:0px;\n");
        builder.append("        margin:auto;\n");
        builder.append("        z-index:1;\n");
        builder.append("        width:100%;\n");
        builder.append("        height:180px;\n");
        builder.append("      }\n");
        builder.append("      .bottom {\n");
        builder.append("        background-color:lightgray;\n");
        builder.append("        border-width: 0px 0px 0px 0px;\n");
        builder.append("        position:fixed;\n");
        builder.append("        bottom:0px;\n");
        builder.append("        margin:auto;\n");
        builder.append("        z-index:1;\n");
        builder.append("        width:100%;\n");
        builder.append("        height:30px;\n");
        builder.append("      }\n");
        builder.append("      .button {\n");
        builder.append("          background-color: #4CAF50;\n");
        builder.append("          border: none;\n");
        builder.append("          color: white;\n");
        builder.append("          padding: 16px 32px;\n");
        builder.append("          text-align: center;\n");
        builder.append("          text-decoration: none;\n");
        builder.append("          display: inline-block;\n");
        builder.append("          font-size: 16px;\n");
        builder.append("          margin: 4px 2px;\n");
        builder.append("          -webkit-transition-duration: 0.4s;\n");
        builder.append("          transition-duration: 0.4s;\n");
        builder.append("          cursor: pointer;\n");
        builder.append("      }\n");
        builder.append("      .sender {\n");
        builder.append("          background-color: white; \n");
        builder.append("          color: black; \n");
        builder.append("          border: 2px solid #008CBA;\n");
        builder.append("          width: 100%;\n");
        builder.append("          word-wrap: break-word;\n");
        builder.append("      }\n");
        builder.append("      .sender:hover {\n");
        builder.append("          background-color: #008CBA;\n");
        builder.append("          color: white;\n");
        builder.append("      }\n");
        builder.append("      .highlight {\n");
        builder.append("        background: #b4b9d2;\n");
        builder.append("        color:black;\n");
        builder.append("        border-top: 1px solid #22262e;\n");
        builder.append("        border-bottom: 1px solid #22262e;\n");
        builder.append("      }\n");
        builder.append("      .highlight:nth-child(odd) td {\n");
        builder.append("        background: #b4b9d2;\n");
        builder.append("      }\n");
        builder.append("      .click {\n");
        builder.append("        cursor:pointer;\n");
        builder.append("        cursor:hand;\n");
        builder.append("      }\n");
        builder.append("      table {\n");
        builder.append("        background: white;\n");
        builder.append("        table-layout:fixed;\n");
        builder.append("        border-collapse: collapse;\n");
        builder.append("        word-wrap:break-word;\n");
        builder.append("        border-radius:3px;\n");
        builder.append("        border-collapse: collapse;\n");
        builder.append("        margin: auto;\n");
        builder.append("        padding:2px;\n");
        builder.append("        width: 100%;\n");
        builder.append("        box-shadow: 0 5px 10px rgba(0, 0, 0, 0.1);\n");
        builder.append("        animation: float 5s infinite;\n");
        builder.append("      }\n");
        builder.append("      th {\n");
        builder.append("        color:#FFFFFF;;\n");
        builder.append("        background:#1b1e24;\n");
        builder.append("        border-bottom:4px solid #9ea7af;\n");
        builder.append("        border-right: 0px;\n");
        builder.append("        font-size:16px;\n");
        builder.append("        font-weight: bold;\n");
        builder.append("        padding:4px;\n");
        builder.append("        text-align:left;\n");
        builder.append("        text-shadow: 0 1px 1px rgba(0, 0, 0, 0.1);\n");
        builder.append("        vertical-align:middle;\n");
        builder.append("        height:30px;\n");
        builder.append("      }\n");
        builder.append("      tr {\n");
        builder.append("        border-top: 1px solid #C1C3D1;\n");
        builder.append("        border-bottom-: 1px solid #C1C3D1;\n");
        builder.append("        font-size:16px;\n");
        builder.append("        font-weight:normal;\n");
        builder.append("        text-shadow: 0 1px 1px rgba(256, 256, 256, 0.1);\n");
        builder.append("      }\n");
        builder.append("      tr:nth-child(odd) td {\n");
        builder.append("        background:#EBEBEB;\n");
        builder.append("      }\n");
        builder.append("      td {\n");
        builder.append("        padding:2px;\n");
        builder.append("        vertical-align:middle;\n");
        builder.append("        font-size:16px;\n");
        builder.append("        text-shadow: -1px -1px 1px rgba(0, 0, 0, 0.1);\n");
        builder.append("        border-right: 1px solid #C1C3D1;\n");
        builder.append("      }\n");
        builder.append("      input[type=text], select {\n");
        builder.append("        width: 400px;\n");
        builder.append("        padding: 0px 4px;\n");
        builder.append("        margin: 1px 0;\n");
        builder.append("        display: inline-block;\n");
        builder.append("        background: #b4b9d2;\n");
        builder.append("        border: 1px solid #ccc;\n");
        builder.append("        border-radius: 4px;\n");
        builder.append("        box-sizing: border-box;\n");
        builder.append("      }\n");
        builder.append("    </style>\n");
        // JavaScript functions.
        TreeMap<Long, Query> queryMap = user.getQueryMap(null, null);
        builder.append(
                "    <script type=\"text/javascript\" src=\"https://ajax.googleapis.com/ajax/libs/jquery/2.1.3/jquery.min.js\"></script>\n");
        builder.append("    <script type=\"text/javascript\">\n");
        builder.append("      window.onbeforeunload = function () {\n");
        builder.append("        document.getElementById('filterField').value = '';\n");
        builder.append("        window.scrollTo(0, 0);\n");
        builder.append("      }\n");
        builder.append("      var last = ");
        if (queryMap.isEmpty()) {
            builder.append(0);
        } else {
            builder.append(queryMap.lastKey());
        }
        builder.append(";\n");
        builder.append("      var filterText = '';\n");
        builder.append("      function view(query) {\n");
        builder.append("        if (query == undefined || query == 0) {\n");
        builder.append("          var viewer = document.getElementById('viewer');\n");
        builder.append("          viewer.src = 'about:blank';\n");
        builder.append("          last = 0;\n");
        builder.append("        } else if (last != query) {\n");
        builder.append("          var viewer = document.getElementById('viewer');\n");
        builder.append("          viewer.addEventListener('load', function() {\n");
        builder.append("            if (document.getElementById(last)) {\n");
        builder.append("              document.getElementById(last).className = 'tr';\n");
        builder.append("              document.getElementById(last).className = 'click';\n");
        builder.append("            }\n");
        builder.append("            document.getElementById(query).className = 'highlight';\n");
        builder.append("            last = query;\n");
        builder.append("          });\n");
        builder.append("          viewer.src = '");
        builder.append(Core.getURL());
        builder.append("' + query;\n");
        builder.append("        }\n");
        builder.append("      }\n");
        builder.append("      function more(query) {\n");
        builder.append("        var rowMore = document.getElementById('rowMore');\n");
        builder.append("        rowMore.onclick = '';\n");
        builder.append("        rowMore.className = 'tr';\n");
        builder.append("        var columnMore = document.getElementById('columnMore');\n");
        if (locale.getLanguage().toLowerCase().equals("pt")) {
            builder.append("        columnMore.innerHTML = 'carregando mais registros';\n");
        } else {
            builder.append("        columnMore.innerHTML = 'loading more records';\n");
        }
        builder.append("        $.post(\n");
        builder.append("          '");
        builder.append(Core.getURL());
        builder.append(user.getEmail());
        builder.append("',\n");
        builder.append("          {filter:filterText,begin:query},\n");
        builder.append("          function(data, status) {\n");
        builder.append("            if (status == 'success') {\n");
        builder.append("              rowMore.parentNode.removeChild(rowMore);\n");
        builder.append("              $('#tableBody').append(data);\n");
        builder.append("            } else {\n");
        if (locale.getLanguage().toLowerCase().equals("pt")) {
            builder.append(
                    "              alert('Houve uma falha de sistema ao tentar realizar esta operao.');\n");
        } else {
            builder.append(
                    "              alert('There was a system crash while trying to perform this operation.');\n");
        }
        builder.append("            }\n");
        builder.append("          }\n");
        builder.append("        );\n");
        builder.append("      }\n");
        builder.append("      function refresh() {\n");
        builder.append("        filterText = document.getElementById('filterField').value;\n");
        builder.append("        $.post(\n");
        builder.append("          '");
        builder.append(Core.getURL());
        builder.append(user.getEmail());
        builder.append("',\n");
        builder.append("          {filter:filterText},\n");
        builder.append("          function(data, status) {\n");
        builder.append("            if (status == 'success') {\n");
        builder.append("              $('#tableBody').html(data);\n");
        builder.append("              view($('#tableBody tr').attr('id'));\n");
        builder.append("            } else {\n");
        if (locale.getLanguage().toLowerCase().equals("pt")) {
            builder.append(
                    "              alert('Houve uma falha de sistema ao tentar realizar esta operao.');\n");
        } else {
            builder.append(
                    "              alert('There was a system crash while trying to perform this operation.');\n");
        }
        builder.append("            }\n");
        builder.append("          }\n");
        builder.append("        );\n");
        builder.append("      }\n");
        builder.append("    </script>\n");
        builder.append("  </head>\n");
        // Body.
        builder.append("  <body>\n");
        builder.append("    <div class=\"header\">\n");
        if (queryMap.isEmpty()) {
            builder.append("      <iframe id=\"viewer\" src=\"about:blank\"></iframe>\n");
        } else {
            builder.append("      <iframe id=\"viewer\" src=\"");
            builder.append(Core.getURL());
            builder.append(queryMap.lastKey());
            builder.append("\"></iframe>\n");
        }
        // Construo da tabela de consultas.
        builder.append("      <table>\n");
        builder.append("        <thead>\n");
        builder.append("          <tr>\n");
        if (locale.getLanguage().toLowerCase().equals("pt")) {
            builder.append("            <th style=\"width:120px;\">Recepo</th>\n");
            builder.append("            <th>Origem</th>\n");
            builder.append("            <th>Remetente</th>\n");
            builder.append("            <th>Contedo</th>\n");
            builder.append("            <th>Entrega</th>\n");
        } else {
            builder.append("            <th style=\"width:160px;\">Reception</th>\n");
            builder.append("            <th style=\"width:auto;\">Source</th>\n");
            builder.append("            <th style=\"width:auto;\">Sender</th>\n");
            builder.append("            <th style=\"width:auto;\">Content</th>\n");
            builder.append("            <th style=\"width:auto;\">Delivery</th>\n");
        }
        builder.append("          </tr>\n");
        builder.append("        </thead>\n");
        builder.append("      </table>\n");
        builder.append("    </div>\n");
        if (queryMap.isEmpty()) {
            builder.append("    <table>\n");
            builder.append("      <tbody>\n");
            builder.append("        <tr>\n");
            if (locale.getLanguage().toLowerCase().equals("pt")) {
                builder.append(
                        "          <td colspan=\"5\" align=\"center\">nenhum registro encontrado</td>\n");
            } else {
                builder.append("          <td colspan=\"5\" align=\"center\">no records found</td>\n");
            }
            builder.append("        </tr>\n");
            builder.append("      </tbody>\n");
            builder.append("    </table>\n");
        } else {
            DateFormat dateFormat = DateFormat.getDateTimeInstance(DateFormat.SHORT, DateFormat.MEDIUM, locale);
            GregorianCalendar calendar = new GregorianCalendar();
            Long nextQuery = null;
            while (queryMap.size() > User.QUERY_MAX_ROWS) {
                nextQuery = queryMap.pollFirstEntry().getKey();
            }
            builder.append("    <table>\n");
            builder.append("      <tbody id=\"tableBody\">\n");
            for (Long time : queryMap.descendingKeySet()) {
                User.Query query = queryMap.get(time);
                boolean highlight = time.equals(queryMap.lastKey());
                buildQueryRow(locale, builder, dateFormat, calendar, time, query, highlight);
            }
            if (nextQuery == null) {
                builder.append("      <tr>\n");
                if (locale.getLanguage().toLowerCase().equals("pt")) {
                    builder.append(
                            "        <td colspan=\"5\" align=\"center\">no foram encontrados outros registros</td>\n");
                } else {
                    builder.append("        <td colspan=\"5\" align=\"center\">no more records found</td>\n");
                }
                builder.append("      </tr>\n");
            } else {
                builder.append("        <tr id=\"rowMore\" class=\"click\" onclick=\"more('");
                builder.append(nextQuery);
                builder.append("')\">\n");
                if (locale.getLanguage().toLowerCase().equals("pt")) {
                    builder.append(
                            "          <td id=\"columnMore\" colspan=\"5\" align=\"center\">clique para ver mais registros</td>\n");
                } else {
                    builder.append(
                            "          <td id=\"columnMore\" colspan=\"5\" align=\"center\">click to see more records</td>\n");
                }
                builder.append("        </tr>\n");
            }
            builder.append("      </tbody>\n");
            builder.append("    </table>\n");
        }
        builder.append("    <div class=\"bottom\">\n");
        builder.append("      <table>\n");
        builder.append("        <tr>\n");
        if (locale.getLanguage().toLowerCase().equals("pt")) {
            builder.append(
                    "          <th>Pesquisar <input type=\"text\" id=\"filterField\" name=\"filterField\" onkeydown=\"if (event.keyCode == 13) refresh();\" autofocus></th>\n");
        } else {
            builder.append(
                    "          <th>Search <input type=\"text\" id=\"filterField\" name=\"filterField\" onkeydown=\"if (event.keyCode == 13) refresh();\" autofocus></th>\n");
        }
        builder.append("          <th style=\"text-align:right;\"><small>");
        builder.append(
                "Powered by <a target=\"_blank\" href=\"http://spfbl.net/\" style=\"color: #b4b9d2;\">SPFBL.net</a></small>");
        builder.append("</th>\n");
        builder.append("        </tr>\n");
        builder.append("      <table>\n");
        builder.append("    </div>\n");
        builder.append("  </body>\n");
        builder.append("</html>\n");
    } else {
        TreeMap<Long, Query> queryMap = user.getQueryMap(begin, filter);
        if (queryMap.isEmpty()) {
            builder.append("        <tr>\n");
            if (locale.getLanguage().toLowerCase().equals("pt")) {
                builder.append(
                        "          <td colspan=\"5\" align=\"center\">nenhum registro encontrado</td>\n");
            } else {
                builder.append("          <td colspan=\"5\" align=\"center\">no records found</td>\n");
            }
            builder.append("        </tr>\n");
        } else {
            DateFormat dateFormat = DateFormat.getDateTimeInstance(DateFormat.SHORT, DateFormat.MEDIUM, locale);
            GregorianCalendar calendar = new GregorianCalendar();
            Long nextQuery = null;
            while (queryMap.size() > User.QUERY_MAX_ROWS) {
                nextQuery = queryMap.pollFirstEntry().getKey();
            }
            for (Long time : queryMap.descendingKeySet()) {
                User.Query query = queryMap.get(time);
                buildQueryRow(locale, builder, dateFormat, calendar, time, query, false);
            }
            if (nextQuery == null) {
                builder.append("        <tr>\n");
                if (locale.getLanguage().toLowerCase().equals("pt")) {
                    builder.append(
                            "          <td colspan=\"5\" align=\"center\">no foram encontrados outros registros</td>\n");
                } else {
                    builder.append("          <td colspan=\"5\" align=\"center\">no more records found</td>\n");
                }
                builder.append("        </tr>\n");
            } else {
                builder.append("        <tr id=\"rowMore\" class=\"click\" onclick=\"more('");
                builder.append(nextQuery);
                builder.append("')\">\n");
                if (locale.getLanguage().toLowerCase().equals("pt")) {
                    builder.append(
                            "          <td id=\"columnMore\" colspan=\"5\" align=\"center\">clique para ver mais registros</td>\n");
                } else {
                    builder.append(
                            "          <td id=\"columnMore\" colspan=\"5\" align=\"center\">click to see more records</td>\n");
                }
                builder.append("        </tr>\n");
            }
        }
    }
    return builder.toString();
}