WebImportExportLogger.java :  » Groupware » LibreSource » org » libresource » web » Java Open Source

Java Open Source » Groupware » LibreSource 
LibreSource » org » libresource » web » WebImportExportLogger.java
/**
 * LibreSource
 * Copyright (C) 2004-2008 Artenum SARL / INRIA
 * http://www.libresource.org - contact@artenum.com
 *
 * This file is part of the LibreSource software, 
 * which can be used and distributed under license conditions.
 * The license conditions are provided in the LICENSE.TXT file 
 * at the root path of the packaging that enclose this file. 
 * More information can be found at 
 * - http://dev.libresource.org/home/license
 *
 * Initial authors :
 *
 * Guillaume Bort / INRIA
 * Francois Charoy / Universite Nancy 2
 * Julien Forest / Artenum
 * Claude Godart / Universite Henry Poincare
 * Florent Jouille / INRIA
 * Sebastien Jourdain / INRIA / Artenum
 * Yves Lerumeur / Artenum
 * Pascal Molli / Universite Henry Poincare
 * Gerald Oster / INRIA
 * Mariarosa Penzi / Artenum
 * Gerard Sookahet / Artenum
 * Raphael Tani / INRIA
 *
 * Contributors :
 *
 * Stephane Bagnier / Artenum
 * Amadou Dia / Artenum-IUP Blois
 * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
 */
package org.libresource.web;

import org.libresource.xml.ImportExportLogger;

import javax.servlet.http.HttpServletResponse;


public class WebImportExportLogger implements ImportExportLogger {
    private HttpServletResponse response;

    public WebImportExportLogger(HttpServletResponse response) {
        this.response = response;
    }

    public void log(int type, String message) {
        if (response != null) {
            try {
                switch (type) {
                case ImportExportLogger.APPEND:
                    response.getWriter().println(message);
                    response.getWriter().flush();
                    response.flushBuffer();

                    break;

                case ImportExportLogger.MESSAGE:
                    response.getWriter().println("<li>" + message + "</li>");

                    for (int i = 0; i < 100; i++)
                        response.getWriter().println("                                                                                                             ");

                    response.getWriter().flush();
                    response.flushBuffer();

                    break;

                case ImportExportLogger.ERROR:
                    response.getWriter().println("<li style=\"color:red\">ERROR : " + message + "</li>");

                    for (int i = 0; i < 100; i++)
                        response.getWriter().println("                                                                                                             ");

                    response.getWriter().flush();
                    response.flushBuffer();

                    break;

                case ImportExportLogger.NOTICE:
                    response.getWriter().println("<li style=\"color:blue\">NOTICE : " + message + "</li>");

                    for (int i = 0; i < 100; i++)
                        response.getWriter().println("                                                                                                             ");

                    response.getWriter().flush();
                    response.flushBuffer();

                    break;
                }
            } catch (Exception e) {
                //
            }
        }
    }
}
java2s.com  | Contact Us | Privacy Policy
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.