KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > izforge > izpack > util > SummaryProcessor


1 /*
2  * IzPack - Copyright 2001-2007 Julien Ponge, All Rights Reserved.
3  *
4  * http://www.izforge.com/izpack/
5  * http://developer.berlios.de/projects/izpack/
6  *
7  * Copyright 2005 Klaus Bartz
8  *
9  * Licensed under the Apache License, Version 2.0 (the "License");
10  * you may not use this file except in compliance with the License.
11  * You may obtain a copy of the License at
12  *
13  * http://www.apache.org/licenses/LICENSE-2.0
14  *
15  * Unless required by applicable law or agreed to in writing, software
16  * distributed under the License is distributed on an "AS IS" BASIS,
17  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
18  * See the License for the specific language governing permissions and
19  * limitations under the License.
20  */

21
22 package com.izforge.izpack.util;
23
24 import java.util.Iterator JavaDoc;
25
26 import com.izforge.izpack.installer.AutomatedInstallData;
27 import com.izforge.izpack.installer.IzPanel;
28
29 /**
30  * A helper class which creates a summary from all panels. This class calls all declared panels for
31  * a summary To differ between caption and message, HTML is used to draw caption in bold and indent
32  * messaged a little bit.
33  *
34  * @author Klaus Bartz
35  *
36  */

37 public class SummaryProcessor
38 {
39
40     private static String JavaDoc HTML_HEADER;
41
42     private static String JavaDoc HTML_FOOTER = "</body>\n</html>\n";
43
44     private static String JavaDoc BODY_START = "<div class=\"body\">";
45
46     private static String JavaDoc BODY_END = "</div>";
47
48     private static String JavaDoc HEAD_START = "<h1>";
49
50     private static String JavaDoc HEAD_END = "</h1>\n";
51
52     static
53     {
54         // Initialize HTML header and footer.
55
StringBuffer JavaDoc sb = new StringBuffer JavaDoc(256);
56         sb.append("<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.0 Transitional//EN\">\n").append(
57                 "<html>\n" + "<meta http-equiv=\"content-type\" content=\"text/html; charset=UTF-8\">" +
58                 "<head>\n<STYLE TYPE=\"text/css\" media=screen,print>\n").append(
59                 "h1{\n font-size: 100%;\n margin: 1em 0 0 0;\n padding: 0;\n}\n").append(
60                 "div.body {\n font-size: 100%;\n margin: 0mm 2mm 0 8mm;\n padding: 0;\n}\n")
61                 .append("</STYLE>\n</head>\n<body>\n");
62         HTML_HEADER = sb.toString();
63     }
64
65     /**
66      * Returns a HTML formated string which contains the summary of all panels. To get the summary,
67      * the methods * {@link IzPanel#getSummaryCaption} and {@link IzPanel#getSummaryBody()} of all
68      * panels are called.
69      *
70      * @param idata AutomatedInstallData which contains the panel references
71      * @return a HTML formated string with the summary of all panels
72      */

73     public static String JavaDoc getSummary(AutomatedInstallData idata)
74     {
75         Iterator JavaDoc iter = idata.panels.iterator();
76         StringBuffer JavaDoc sb = new StringBuffer JavaDoc(2048);
77         sb.append(HTML_HEADER);
78         while (iter.hasNext())
79         {
80             IzPanel panel = (IzPanel) iter.next();
81             String JavaDoc caption = panel.getSummaryCaption();
82             String JavaDoc msg = panel.getSummaryBody();
83             // If no caption or/and message, ignore it.
84
if (caption == null || msg == null)
85             {
86                 continue;
87             }
88             sb.append(HEAD_START).append(caption).append(HEAD_END);
89             sb.append(BODY_START).append(msg).append(BODY_END);
90         }
91         sb.append(HTML_FOOTER);
92         return (sb.toString());
93     }
94
95 }
96
Popular Tags