001/*
002 * IzPack - Copyright 2001-2005 Julien Ponge, All Rights Reserved.
003 * 
004 * http://www.izforge.com/izpack/
005 * http://developer.berlios.de/projects/izpack/
006 * 
007 * Copyright 2005 Klaus Bartz
008 * 
009 * Licensed under the Apache License, Version 2.0 (the "License");
010 * you may not use this file except in compliance with the License.
011 * You may obtain a copy of the License at
012 * 
013 *     http://www.apache.org/licenses/LICENSE-2.0
014 *     
015 * Unless required by applicable law or agreed to in writing, software
016 * distributed under the License is distributed on an "AS IS" BASIS,
017 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
018 * See the License for the specific language governing permissions and
019 * limitations under the License.
020 */
021
022package com.izforge.izpack.util;
023
024import java.util.Iterator;
025
026import com.izforge.izpack.installer.AutomatedInstallData;
027import com.izforge.izpack.installer.IzPanel;
028
029/**
030 * A helper class which creates a summary from all panels. This class calls all declared panels for
031 * a summary To differ between caption and message, HTML is used to draw caption in bold and indent
032 * messaged a little bit.
033 * 
034 * @author Klaus Bartz
035 * 
036 */
037public class SummaryProcessor
038{
039
040    private static String HTML_HEADER;
041
042    private static String HTML_FOOTER = "</body>\n</html>\n";
043
044    private static String BODY_START = "<div class=\"body\">";
045
046    private static String BODY_END = "</div>";
047
048    private static String HEAD_START = "<h1>";
049
050    private static String HEAD_END = "</h1>\n";
051
052    static
053    {
054        // Initialize HTML header and footer.
055        StringBuffer sb = new StringBuffer(256);
056        sb.append("<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.0 Transitional//EN\">\n").append(
057                "<html>\n<head>\n<STYLE TYPE=\"text/css\" media=screen,print>\n").append(
058                "h1{\n  font-size: 100%;\n  margin: 1em 0 0 0;\n  padding: 0;\n}\n").append(
059                "div.body {\n  font-size: 100%;\n  margin: 0mm 2mm 0  8mm;\n  padding: 0;\n}\n")
060                .append("</STYLE>\n</head>\n<body>\n");
061        HTML_HEADER = sb.toString();
062    }
063
064    /**
065     * Returns a HTML formated string which contains the summary of all panels. To get the summary,
066     * the methods * {@link IzPanel#getSummaryCaption} and {@link IzPanel#getSummaryBody()} of all
067     * panels are called.
068     * 
069     * @param idata AutomatedInstallData which contains the panel references
070     * @return a HTML formated string with the summary of all panels
071     */
072    public static String getSummary(AutomatedInstallData idata)
073    {
074        Iterator iter = idata.panels.iterator();
075        StringBuffer sb = new StringBuffer(2048);
076        sb.append(HTML_HEADER);
077        while (iter.hasNext())
078        {
079            IzPanel panel = (IzPanel) iter.next();
080            String caption = panel.getSummaryCaption();
081            String msg = panel.getSummaryBody();
082            // If no caption or/and message, ignore it.
083            if (caption == null || msg == null)
084            {
085                continue;
086            }
087            sb.append(HEAD_START).append(caption).append(HEAD_END);
088            sb.append(BODY_START).append(msg).append(BODY_END);
089        }
090        sb.append(HTML_FOOTER);
091        return (sb.toString());
092    }
093
094}