01: /*
02: * IzPack - Copyright 2001-2008 Julien Ponge, All Rights Reserved.
03: *
04: * http://izpack.org/
05: * http://izpack.codehaus.org/
06: *
07: * Copyright 2005 Klaus Bartz
08: *
09: * 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;
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: private static String HTML_HEADER;
40:
41: private static String HTML_FOOTER = "</body>\n</html>\n";
42:
43: private static String BODY_START = "<div class=\"body\">";
44:
45: private static String BODY_END = "</div>";
46:
47: private static String HEAD_START = "<h1>";
48:
49: private static String HEAD_END = "</h1>\n";
50:
51: static {
52: // Initialize HTML header and footer.
53: StringBuffer sb = new StringBuffer(256);
54: sb
55: .append(
56: "<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.0 Transitional//EN\">\n")
57: .append(
58: "<html>\n"
59: + "<meta http-equiv=\"content-type\" content=\"text/html; charset=UTF-8\">"
60: + "<head>\n<STYLE TYPE=\"text/css\" media=screen,print>\n")
61: .append(
62: "h1{\n font-size: 100%;\n margin: 1em 0 0 0;\n padding: 0;\n}\n")
63: .append(
64: "div.body {\n font-size: 100%;\n margin: 0mm 2mm 0 8mm;\n padding: 0;\n}\n")
65: .append("</STYLE>\n</head>\n<body>\n");
66: HTML_HEADER = sb.toString();
67: }
68:
69: /**
70: * Returns a HTML formated string which contains the summary of all panels. To get the summary,
71: * the methods * {@link IzPanel#getSummaryCaption} and {@link IzPanel#getSummaryBody()} of all
72: * panels are called.
73: *
74: * @param idata AutomatedInstallData which contains the panel references
75: * @return a HTML formated string with the summary of all panels
76: */
77: public static String getSummary(AutomatedInstallData idata) {
78: Iterator<IzPanel> iter = idata.panels.iterator();
79: StringBuffer sb = new StringBuffer(2048);
80: sb.append(HTML_HEADER);
81: while (iter.hasNext()) {
82: IzPanel panel = iter.next();
83: String caption = panel.getSummaryCaption();
84: String msg = panel.getSummaryBody();
85: // If no caption or/and message, ignore it.
86: if (caption == null || msg == null) {
87: continue;
88: }
89: sb.append(HEAD_START).append(caption).append(HEAD_END);
90: sb.append(BODY_START).append(msg).append(BODY_END);
91: }
92: sb.append(HTML_FOOTER);
93: return (sb.toString());
94: }
95:
96: }
|