Example usage for javax.mail.internet MailDateFormat format

List of usage examples for javax.mail.internet MailDateFormat format

Introduction

In this page you can find the example usage for javax.mail.internet MailDateFormat format.

Prototype

public final String format(Date date) 

Source Link

Document

Formats a Date into a date-time string.

Usage

From source file:org.methodize.nntprss.admin.AdminServlet.java

private void cmdExportOpmlChannelConfig(HttpServletResponse response) throws ServletException, IOException {

    //      response.setContentType("text/xml");
    response.setContentType("application/octet-stream; charset=UTF-8");
    response.setHeader("Content-Disposition", "attachment; filename=\"nntprss-channels-opml.xml\"");
    PrintWriter writer = new PrintWriter(response.getWriter());
    writer.println("<?xml version='1.0' encoding='UTF-8'?>");
    writer.println();//from www .j  ava2  s.  c om
    writer.println("<!-- Generated on " + new Date().toString() + " -->");
    writer.println("<!-- nntp//rss v" + XMLHelper.escapeString(AppConstants.VERSION)
            + " - http://www.methodize.org/nntprss/ -->");

    writer.println("<opml version='1.1'>");
    writer.println(" <head>");
    writer.println("  <title>My nntp//rss Subscriptions</title>");

    MailDateFormat mailDateFormat = new MailDateFormat();
    String currentDateTime = mailDateFormat.format(new Date());
    writer.println("  <dateCreated>" + currentDateTime + "</dateCreated>");
    writer.println("  <dateModified>" + currentDateTime + "</dateModified>");
    writer.println(" </head>");
    writer.println(" <body>");

    ChannelManager channelManager = (ChannelManager) getServletContext()
            .getAttribute(AdminServer.SERVLET_CTX_RSS_MANAGER);

    Iterator channelIter = channelManager.channels();
    while (channelIter.hasNext()) {
        Channel channel = (Channel) channelIter.next();
        writer.print("  <outline text='");
        writer.print(channel.getTitle() != null ? XMLHelper.escapeString(channel.getTitle()) : "");
        writer.print("' description='");
        writer.print(channel.getDescription() != null ? XMLHelper.escapeString(channel.getDescription()) : "");
        writer.print("' htmlUrl='");
        writer.print(channel.getLink() != null ? XMLHelper.escapeString(channel.getLink()) : "");
        writer.print("' title='");
        writer.print(channel.getTitle() != null ? XMLHelper.escapeString(channel.getTitle()) : "");
        writer.print("' ");
        if (channel.getRssVersion() != null) {
            if (channel.getRssVersion().toUpperCase().startsWith("RSS")
                    || channel.getRssVersion().startsWith("RDF")) {
                writer.print("type='rss' version='RSS' ");
            } else if (channel.getRssVersion().toUpperCase().startsWith("ATOM")) {
                writer.print("type='atom' version='ATOM' ");
            }
        }
        writer.print("xmlUrl='");
        writer.print(XMLHelper.escapeString(channel.getUrl()));
        writer.println("'/>");
    }

    writer.println(" </body>");
    writer.println("</opml>");
}