From 4dfb0a8cfaced73346ec5dd6455813e83014b016 Mon Sep 17 00:00:00 2001
From: jvergara <jvergara@localhost>
Date: Tue, 21 Nov 2006 19:44:41 +0000
Subject: [PATCH] The following modifications are done to extract the code that provides the HTML formatting of the messages that appear in the progress panel.
---
opends/src/quicksetup/org/opends/quicksetup/ui/CurrentStepPanel.java | 10
opends/src/quicksetup/org/opends/quicksetup/installer/offline/OfflineInstaller.java | 27 +-
opends/src/quicksetup/org/opends/quicksetup/ui/QuickSetupDialog.java | 12 +
opends/src/quicksetup/org/opends/quicksetup/installer/webstart/WebStartInstaller.java | 37 +-
opends/src/quicksetup/org/opends/quicksetup/QuickSetup.java | 8
opends/src/quicksetup/org/opends/quicksetup/ui/ProgressPanel.java | 23 +
opends/src/quicksetup/org/opends/quicksetup/installer/Installer.java | 529 +++++++++--------------------------------------
7 files changed, 178 insertions(+), 468 deletions(-)
diff --git a/opends/src/quicksetup/org/opends/quicksetup/QuickSetup.java b/opends/src/quicksetup/org/opends/quicksetup/QuickSetup.java
index d156a3b..cea1060 100644
--- a/opends/src/quicksetup/org/opends/quicksetup/QuickSetup.java
+++ b/opends/src/quicksetup/org/opends/quicksetup/QuickSetup.java
@@ -53,6 +53,8 @@
import org.opends.quicksetup.ui.UIFactory;
import org.opends.quicksetup.uninstaller.Uninstaller;
import org.opends.quicksetup.util.BackgroundTask;
+import org.opends.quicksetup.util.HtmlProgressMessageFormatter;
+import org.opends.quicksetup.util.ProgressMessageFormatter;
import org.opends.quicksetup.util.Utils;
/**
@@ -767,12 +769,14 @@
*/
private void launchInstallation()
{
+ ProgressMessageFormatter formatter = new HtmlProgressMessageFormatter();
if (isWebStart())
{
- installer = new WebStartInstaller(getUserData(), jnlpDownloader);
+ installer = new WebStartInstaller(getUserData(), jnlpDownloader,
+ formatter);
} else
{
- installer = new OfflineInstaller(getUserData());
+ installer = new OfflineInstaller(getUserData(), formatter);
}
installer.addProgressUpdateListener(this);
installer.start();
diff --git a/opends/src/quicksetup/org/opends/quicksetup/installer/Installer.java b/opends/src/quicksetup/org/opends/quicksetup/installer/Installer.java
index c80d437..046804c 100644
--- a/opends/src/quicksetup/org/opends/quicksetup/installer/Installer.java
+++ b/opends/src/quicksetup/org/opends/quicksetup/installer/Installer.java
@@ -32,9 +32,6 @@
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintStream;
-import java.io.UnsupportedEncodingException;
-import java.net.URLDecoder;
-import java.net.URLEncoder;
import java.util.ArrayList;
import java.util.HashSet;
import java.util.Map;
@@ -42,7 +39,7 @@
import org.opends.quicksetup.event.ProgressUpdateEvent;
import org.opends.quicksetup.event.ProgressUpdateListener;
import org.opends.quicksetup.i18n.ResourceProvider;
-import org.opends.quicksetup.ui.UIFactory;
+import org.opends.quicksetup.util.ProgressMessageFormatter;
import org.opends.quicksetup.util.Utils;
import org.opends.server.util.CreateTemplate;
@@ -57,13 +54,6 @@
* will send a ProgressUpdateEvent.
*
* This class is supposed to be fully independent of the graphical layout.
- * However it is the most appropriate part of the code to generate well
- * formatted messages. So it generates HTML messages in the
- * ProgressUpdateEvent and to do so uses the UIFactory method.
- *
- * TODO pass an object in the constructor that would generate the messages.
- * The problem of this approach is that the resulting interface of this object
- * may be quite complex and could impact the lisibility of the code.
*
*/
public abstract class Installer
@@ -90,26 +80,20 @@
private UserInstallData userData;
- private String doneHtml;
-
- /**
- * The line break in HTML.
- */
- protected static String LINE_BREAK = "<br>";
-
- /**
- * The space in HTML.
- */
- protected static String SPACE = " ";
+ private ProgressMessageFormatter formatter;
/**
* Constructor to be used by the subclasses.
* @param userData the user data definining the parameters of the
* installation.
+ * @param formatter the message formatter to be used to generate the text of
+ * the ProgressUpdateEvent
*/
- protected Installer(UserInstallData userData)
+ protected Installer(UserInstallData userData,
+ ProgressMessageFormatter formatter)
{
this.userData = userData;
+ this.formatter = formatter;
}
/**
@@ -258,71 +242,63 @@
}
/**
- * Returns the HTML representation of an error for a given text.
- * @param text the source text from which we want to get the HTML
+ * Returns the formatted representation of the text that is the summary of the
+ * installation process (the one that goes in the UI next to the progress
+ * bar).
+ * @param text the source text from which we want to get the formatted
* representation
- * @return the HTML representation of an error for the given text.
+ * @return the formatted representation of an error for the given text.
*/
- protected String getHtmlError(String text)
+ protected String getFormattedSummary(String text)
{
- String html =
- UIFactory.getIconHtml(UIFactory.IconType.ERROR)
- + SPACE
- + SPACE
- + UIFactory.applyFontToHtml(getHtml(text),
- UIFactory.PROGRESS_ERROR_FONT);
-
- String result = UIFactory.applyErrorBackgroundToHtml(html);
- return result;
+ return formatter.getFormattedSummary(text);
}
/**
- * Returns the HTML representation of an warning for a given text.
- * @param text the source text from which we want to get the HTML
+ * Returns the formatted representation of an error for a given text.
+ * @param text the source text from which we want to get the formatted
* representation
- * @return the HTML representation of an warning for the given text.
+ * @return the formatted representation of an error for the given text.
*/
- protected String getHtmlWarning(String text)
+ protected String getFormattedError(String text)
{
- String html =
- UIFactory.getIconHtml(UIFactory.IconType.WARNING)
- + SPACE
- + SPACE
- + UIFactory.applyFontToHtml(getHtml(text),
- UIFactory.PROGRESS_WARNING_FONT);
-
- String result = UIFactory.applyWarningBackgroundToHtml(html);
- return result;
+ return formatter.getFormattedError(text);
}
/**
- * Returns the HTML representation of a success message for a given text.
- * @param text the source text from which we want to get the HTML
+ * Returns the formatted representation of an warning for a given text.
+ * @param text the source text from which we want to get the formatted
* representation
- * @return the HTML representation of an success message for the given text.
+ * @return the formatted representation of an warning for the given text.
*/
- protected String getHtmlSuccess(String text)
+ public String getFormattedWarning(String text)
{
- // Note: the text we get already is in HTML form
- String html =
- UIFactory.getIconHtml(UIFactory.IconType.INFORMATION) + SPACE
- + SPACE + UIFactory.applyFontToHtml(text, UIFactory.PROGRESS_FONT);
-
- String result = UIFactory.applySuccessfulBackgroundToHtml(html);
- return result;
+ return formatter.getFormattedWarning(text);
}
/**
- * Returns the HTML representation of a log error message for a given text.
- * @param text the source text from which we want to get the HTML
+ * Returns the formatted representation of a success message for a given text.
+ * @param text the source text from which we want to get the formatted
* representation
- * @return the HTML representation of a log error message for the given text.
+ * @return the formatted representation of an success message for the given
+ * text.
*/
- protected String getHtmlLogError(String text)
+ public String getFormattedSuccess(String text)
{
- String html = getHtml(text);
- return UIFactory.applyFontToHtml(html,
- UIFactory.PROGRESS_LOG_ERROR_FONT);
+ return formatter.getFormattedSuccess(text);
+ }
+
+ /**
+ * Returns the formatted representation of a log error message for a given
+ * text.
+ * @param text the source text from which we want to get the formatted
+ * representation
+ * @return the formatted representation of a log error message for the given
+ * text.
+ */
+ protected String getFormattedLogError(String text)
+ {
+ return formatter.getFormattedLogError(text);
}
/**
@@ -331,71 +307,30 @@
* representation
* @return the HTML representation of a log message for the given text.
*/
- protected String getHtmlLog(String text)
+ protected String getFormattedLog(String text)
{
- String html = getHtml(text);
- return UIFactory.applyFontToHtml(html, UIFactory.PROGRESS_LOG_FONT);
+ return formatter.getFormattedLog(text);
}
/**
- * Returns the HTML representation of the 'Done' text string.
- * @return the HTML representation of the 'Done' text string.
+ * Returns the formatted representation of the 'Done' text string.
+ * @return the formatted representation of the 'Done' text string.
*/
- protected String getHtmlDone()
+ protected String getFormattedDone()
{
- if (doneHtml == null)
- {
- String html = getHtml(getMsg("progress-done"));
- doneHtml = UIFactory.applyFontToHtml(html,
- UIFactory.PROGRESS_DONE_FONT);
- }
- return doneHtml;
+ return formatter.getFormattedDone();
}
/**
- * Returns the HTML representation of the argument text to which we add
+ * Returns the formatted representation of the argument text to which we add
* points. For instance if we pass as argument 'Configuring Server' the
- * return value will be 'Configuring Server <B>.....</B>'.
+ * return value will be 'Configuring Server .....'.
* @param text the String to which add points.
- * @return the HTML representation of the '.....' text string.
+ * @return the formatted representation of the '.....' text string.
*/
- protected String getHtmlWithPoints(String text)
+ protected String getFormattedWithPoints(String text)
{
- String html = getHtml(text);
- String points = SPACE + getHtml(getMsg("progress-points")) + SPACE;
-
- StringBuffer buf = new StringBuffer();
- buf.append(UIFactory.applyFontToHtml(html, UIFactory.PROGRESS_FONT))
- .append(
- UIFactory.applyFontToHtml(points, UIFactory.PROGRESS_POINTS_FONT));
-
- return buf.toString();
- }
-
- /**
- * Returns the HTML representation for a given text. without adding any kind
- * of font or style elements. Just escapes the problematic characters
- * (like '<') and transform the break lines into '\n' characters.
- *
- * @param text the source text from which we want to get the HTML
- * representation
- * @return the HTML representation for the given text.
- */
- protected String getHtml(String text)
- {
- StringBuffer buffer = new StringBuffer();
- text = text.replaceAll("\r\n", "\n");
- String[] lines = text.split("[\n\r\u0085\u2028\u2029]");
- for (int i = 0; i < lines.length; i++)
- {
- if (i != 0)
- {
- buffer.append("<br>");
- }
- buffer.append(escape(lines[i]));
- }
-
- return buffer.toString();
+ return formatter.getFormattedWithPoints(text);
}
/**
@@ -404,298 +339,43 @@
* representation
* @return the HTML representation of a progress message for the given text.
*/
- protected String getHtmlProgress(String text)
+ protected String getFormattedProgress(String text)
{
- return UIFactory.applyFontToHtml(getHtml(text),
- UIFactory.PROGRESS_FONT);
+ return formatter.getFormattedProgress(text);
}
/**
- * Returns the HTML representation of an error message for a given exception.
+ * Returns the formatted representation of an error message for a given
+ * exception.
* This method applies a margin if the applyMargin parameter is
* <CODE>true</CODE>.
* @param ex the exception.
* @param applyMargin specifies whether we apply a margin or not to the
- * resulting HTML.
- * @return the HTML representation of an error message for the given
+ * resulting formatted text.
+ * @return the formatted representation of an error message for the given
* exception.
*/
- protected String getHtmlError(Exception ex, boolean applyMargin)
+ protected String getFormattedError(Exception ex, boolean applyMargin)
{
- String openDiv = "<div style=\"margin-left:5px; margin-top:10px\">";
- String hideText =
- UIFactory.applyFontToHtml(getMsg("hide-exception-details"),
- UIFactory.PROGRESS_FONT);
- String showText =
- UIFactory.applyFontToHtml(getMsg("show-exception-details"),
- UIFactory.PROGRESS_FONT);
- String closeDiv = "</div>";
-
- StringBuffer stackBuf = new StringBuffer();
- stackBuf.append(getHtmlStack(ex));
- Throwable root = ex.getCause();
- while (root != null)
- {
- stackBuf.append(getHtml(getMsg("exception-root-cause")) + LINE_BREAK);
- stackBuf.append(getHtmlStack(root));
- root = root.getCause();
- }
- String stackText =
- UIFactory.applyFontToHtml(stackBuf.toString(), UIFactory.STACK_FONT);
-
- StringBuffer buf = new StringBuffer();
-
- String msg = ex.getMessage();
- if (msg != null)
- {
- buf.append(UIFactory.applyFontToHtml(getHtml(ex.getMessage()),
- UIFactory.PROGRESS_ERROR_FONT)
- + LINE_BREAK);
- } else
- {
- buf.append(ex.toString() + LINE_BREAK);
- }
- buf.append(getErrorWithStackHtml(openDiv, hideText, showText, stackText,
- closeDiv, false));
-
- String html =
- UIFactory.getIconHtml(UIFactory.IconType.ERROR) + SPACE + SPACE
- + buf.toString();
-
- String result;
- if (applyMargin)
- {
- result =
- UIFactory.applyMargin(UIFactory.applyErrorBackgroundToHtml(html),
- UIFactory.TOP_INSET_ERROR_MESSAGE, 0, 0, 0);
- } else
- {
- result = UIFactory.applyErrorBackgroundToHtml(html);
- }
- return result;
+ return formatter.getFormattedError(ex, applyMargin);
}
/**
- * Returns a HTML representation of the stack trace of a Throwable object.
- * @param ex the throwable object from which we want to obtain the stack
- * trace HTML representation.
- * @return a HTML representation of the stack trace of a Throwable object.
+ * Returns the line break formatted.
+ * @return the line break formatted.
*/
- private String getHtmlStack(Throwable ex)
+ protected String getLineBreak()
{
- StringBuffer buf = new StringBuffer();
- StackTraceElement[] stack = ex.getStackTrace();
- for (int i = 0; i < stack.length; i++)
- {
- buf.append(SPACE + SPACE + SPACE + SPACE + SPACE + SPACE + SPACE +
- SPACE + SPACE + SPACE + getHtml(stack[i].toString()) + LINE_BREAK);
- }
- return buf.toString();
+ return formatter.getLineBreak();
}
/**
- * Returns the HTML representation of a plain text string which is obtained
- * by converting some special characters (like '<') into its equivalent
- * escaped HTML representation.
- *
- * @param rawString the String from which we want to obtain the HTML
- * representation.
- * @return the HTML representation of the plain text string.
+ * Returns the task separator formatted.
+ * @return the task separator formatted.
*/
- private String escape(String rawString)
+ protected String getTaskSeparator()
{
- int toto;
- StringBuffer buffer = new StringBuffer();
- for (int i = 0; i < rawString.length(); i++)
- {
- char c = rawString.charAt(i);
- switch (c)
- {
- case '<':
- buffer.append("<");
- break;
-
- case '>':
- buffer.append(">");
- break;
-
- case '&':
- buffer.append("&");
- break;
-
- case '"':
- buffer.append(""");
- break;
-
- default:
- buffer.append(c);
- break;
- }
- }
-
- return buffer.toString();
- }
-
- /**
- * Returns the HTML representation of an exception in the
- * progress log.<BR>
- * We can have something of type:<BR><BR>
- *
- * An error occurred. java.io.IOException could not connect to server.<BR>
- * <A HREF="">Show Details</A>
- *
- * When the user clicks on 'Show Details' the whole stack will be displayed.
- *
- * An error occurred. java.io.IOException could not connect to server.<BR>
- * <A HREF="">Hide Details</A><BR>
- * ... And here comes all the stack trace representation<BR>
- *
- *
- * As the object that listens to this hyperlink events is not here (it is
- * QuickSetupStepPanel) we must include all the information somewhere. The
- * chosen solution is to include everything in the URL using parameters.
- * This everything consists of:
- * The open div tag for the text.
- * The text that we display when we do not display the exception.
- * The text that we display when we display the exception.
- * The stack trace text.
- * The closing div.
- * A boolean informing if we are hiding the exception or not (to know in the
- * next event what must be displayed).
- *
- * @param openDiv the open div tag for the text.
- * @param hideText the text that we display when we do not display the
- * exception.
- * @param showText the text that we display when we display the exception.
- * @param stackText the stack trace text.
- * @param closeDiv the closing div.
- * @param hide a boolean informing if we are hiding the exception or not.
- * @return the HTML representation of an error message with an stack trace.
- */
- private static String getErrorWithStackHtml(String openDiv, String hideText,
- String showText, String stackText, String closeDiv, boolean hide)
- {
- StringBuffer buf = new StringBuffer();
-
- String params =
- getUrlParams(openDiv, hideText, showText, stackText, closeDiv, hide);
- try
- {
- String text = hide ? hideText : showText;
- buf.append(openDiv + "<a href=\"http://").append(
- URLEncoder.encode(params, "UTF-8") + "\">" + text + "</a>");
- if (hide)
- {
- buf.append(LINE_BREAK + stackText);
- }
- buf.append(closeDiv);
-
- } catch (UnsupportedEncodingException uee)
- {
- // Bug
- throw new IllegalStateException("UTF-8 is not supported ", uee);
- }
-
- return buf.toString();
- }
-
- private static String PARAM_SEPARATOR = "&&&&";
-
- /**
- * Gets the url parameters of the href we construct in getErrorWithStackHtml.
- * @see getErrorWithStackHtml
- * @param openDiv the open div tag for the text.
- * @param hideText the text that we display when we do not display the
- * exception.
- * @param showText the text that we display when we display the exception.
- * @param stackText the stack trace text.
- * @param closeDiv the closing div.
- * @param hide a boolean informing if we are hiding the exception or not.
- * @return the url parameters of the href we construct in getHrefString.
- */
- private static String getUrlParams(String openDiv, String hideText,
- String showText, String stackText, String closeDiv, boolean hide)
- {
- StringBuffer buf = new StringBuffer();
- buf.append(openDiv + PARAM_SEPARATOR);
- buf.append(hideText + PARAM_SEPARATOR);
- buf.append(showText + PARAM_SEPARATOR);
- buf.append(stackText + PARAM_SEPARATOR);
- buf.append(closeDiv + PARAM_SEPARATOR);
- buf.append(hide);
- return buf.toString();
- }
-
- /**
- * Returns the log HTML representation after the user has clicked on a url.
- *
- * @see getErrorWithStackHtml
- * @param url that has been clicked
- * @param lastText the HTML representation of the log before clicking on the
- * url.
- * @return the log HTML representation after the user has clicked on a url.
- */
- public static String getHtmlAfterUrlClick(String url, String lastText)
- {
- String urlText = getErrorWithStackHtml(url, false);
- String newUrlText = getErrorWithStackHtml(url, true);
-
- int index = lastText.indexOf(urlText);
- if (index == -1)
- {
- System.out.println("lastText: " + lastText);
- System.out.println("does not contain: " + urlText);
- } else
- {
- lastText =
- lastText.substring(0, index) + newUrlText
- + lastText.substring(index + urlText.length());
- }
- return lastText;
- }
-
- /**
- * Returns the HTML representation of an exception in the
- * progress log for a given url.
- * @see getHrefString
- * @param url the url containing all the information required to retrieve
- * the HTML representation.
- * @param inverse indicates whether we want to 'inverse' the representation
- * or not. For instance if the url specifies that the stack is being hidden
- * and this parameter is <CODE>true</CODE> the resulting HTML will display
- * the stack.
- * @return the HTML representation of an exception in the progress log for a
- * given url.
- */
- private static String getErrorWithStackHtml(String url, boolean inverse)
- {
- String p = url.substring("http://".length());
- try
- {
- p = URLDecoder.decode(p, "UTF-8");
- } catch (UnsupportedEncodingException uee)
- {
- // Bug
- throw new IllegalStateException("UTF-8 is not supported ", uee);
- }
- String params[] = p.split(PARAM_SEPARATOR);
- int i = 0;
- String openDiv = params[i++];
- String hideText = params[i++];
- String showText = params[i++];
- String stackText = params[i++];
- String closeDiv = params[i++];
- boolean isHide = new Boolean(params[i]);
-
- if (isHide)
- {
- return getErrorWithStackHtml(openDiv, hideText, showText, stackText,
- closeDiv, !inverse);
- } else
- {
- return getErrorWithStackHtml(openDiv, hideText, showText, stackText,
- closeDiv, inverse);
- }
+ return formatter.getTaskSeparator();
}
/**
@@ -803,14 +483,14 @@
StringBuffer buf = new StringBuffer();
if (!isFirstLine)
{
- buf.append(LINE_BREAK);
+ buf.append(formatter.getLineBreak());
}
if (isError)
{
- buf.append(getHtmlLogError(line));
+ buf.append(getFormattedLogError(line));
} else
{
- buf.append(getHtmlLog(line));
+ buf.append(getFormattedLog(line));
}
notifyListeners(buf.toString());
isFirstLine = false;
@@ -934,10 +614,10 @@
{
if (isFirstLine)
{
- notifyListeners(getHtmlLogError(msg));
+ notifyListeners(getFormattedLogError(msg));
} else
{
- notifyListeners(LINE_BREAK + getHtmlLogError(msg));
+ notifyListeners(formatter.getLineBreak() + getFormattedLogError(msg));
}
isFirstLine = false;
}
@@ -993,10 +673,10 @@
{
if (isFirstLine)
{
- notifyListeners(getHtmlLog(msg));
+ notifyListeners(getFormattedLog(msg));
} else
{
- notifyListeners(LINE_BREAK + getHtmlLog(msg));
+ notifyListeners(formatter.getLineBreak() + getFormattedLog(msg));
}
isFirstLine = false;
}
@@ -1028,7 +708,7 @@
*/
protected void configureServer() throws InstallException
{
- notifyListeners(getHtmlWithPoints(getMsg("progress-configuring")));
+ notifyListeners(getFormattedWithPoints(getMsg("progress-configuring")));
ArrayList<String> argList = new ArrayList<String>();
argList.add("-C");
@@ -1078,8 +758,8 @@
{
String[] arg =
{ getUserData().getDataOptions().getBaseDn() };
- notifyListeners(getHtmlWithPoints(getMsg("progress-creating-base-entry",
- arg)));
+ notifyListeners(getFormattedWithPoints(
+ getMsg("progress-creating-base-entry", arg)));
InstallerHelper helper = new InstallerHelper();
String baseDn = getUserData().getDataOptions().getBaseDn();
@@ -1120,7 +800,7 @@
getExceptionMsg("error-creating-base-entry", null, re), re);
}
- notifyListeners(getHtmlDone());
+ notifyListeners(getFormattedDone());
}
/**
@@ -1132,8 +812,8 @@
{
String[] arg =
{ getUserData().getDataOptions().getLDIFPath() };
- notifyListeners(getHtmlProgress(getMsg("progress-importing-ldif", arg))
- + LINE_BREAK);
+ notifyListeners(getFormattedProgress(getMsg("progress-importing-ldif", arg))
+ + formatter.getLineBreak());
ArrayList<String> argList = new ArrayList<String>();
argList.add("-C");
@@ -1179,9 +859,9 @@
int nEntries = getUserData().getDataOptions().getNumberEntries();
String[] arg =
{ String.valueOf(nEntries) };
- notifyListeners(getHtmlProgress(getMsg(
+ notifyListeners(getFormattedProgress(getMsg(
"progress-import-automatically-generated", arg))
- + LINE_BREAK);
+ + formatter.getLineBreak());
ArrayList<String> argList = new ArrayList<String>();
argList.add("-C");
@@ -1225,7 +905,8 @@
*/
protected void startServer() throws InstallException
{
- notifyListeners(getHtmlProgress(getMsg("progress-starting")) + LINE_BREAK);
+ notifyListeners(getFormattedProgress(getMsg("progress-starting")) +
+ getLineBreak());
ArrayList<String> argList = new ArrayList<String>();
@@ -1320,35 +1001,27 @@
Map<InstallProgressStep, String> hmSummary)
{
hmSummary.put(InstallProgressStep.NOT_STARTED,
- UIFactory.applyFontToHtml(
- getMsg("summary-not-started"), UIFactory.PROGRESS_FONT));
+ getFormattedSummary(getMsg("summary-not-started")));
hmSummary.put(InstallProgressStep.DOWNLOADING,
- UIFactory.applyFontToHtml(
- getMsg("summary-downloading"), UIFactory.PROGRESS_FONT));
+ getFormattedSummary(getMsg("summary-downloading")));
hmSummary.put(InstallProgressStep.EXTRACTING,
- UIFactory.applyFontToHtml(
- getMsg("summary-extracting"), UIFactory.PROGRESS_FONT));
+ getFormattedSummary(getMsg("summary-extracting")));
hmSummary.put(InstallProgressStep.CONFIGURING_SERVER,
- UIFactory.applyFontToHtml(getMsg("summary-configuring"),
- UIFactory.PROGRESS_FONT));
- hmSummary.put(InstallProgressStep.CREATING_BASE_ENTRY, UIFactory
- .applyFontToHtml(getMsg("summary-creating-base-entry"),
- UIFactory.PROGRESS_FONT));
- hmSummary.put(InstallProgressStep.IMPORTING_LDIF, UIFactory
- .applyFontToHtml(getMsg("summary-importing-ldif"),
- UIFactory.PROGRESS_FONT));
+ getFormattedSummary(getMsg("summary-configuring")));
+ hmSummary.put(InstallProgressStep.CREATING_BASE_ENTRY,
+ getFormattedSummary(getMsg("summary-creating-base-entry")));
+ hmSummary.put(InstallProgressStep.IMPORTING_LDIF,
+ getFormattedSummary(getMsg("summary-importing-ldif")));
hmSummary.put(
InstallProgressStep.IMPORTING_AUTOMATICALLY_GENERATED,
- UIFactory.applyFontToHtml(
- getMsg("summary-importing-automatically-generated"),
- UIFactory.PROGRESS_FONT));
- hmSummary.put(InstallProgressStep.STARTING_SERVER, UIFactory
- .applyFontToHtml(getMsg("summary-starting"),
- UIFactory.PROGRESS_FONT));
+ getFormattedSummary(
+ getMsg("summary-importing-automatically-generated")));
+ hmSummary.put(InstallProgressStep.STARTING_SERVER,
+ getFormattedSummary(getMsg("summary-starting")));
hmSummary.put(InstallProgressStep.FINISHED_SUCCESSFULLY, "<html>"
- + getHtmlSuccess(getMsg("summary-finished-successfully")));
+ + getFormattedSuccess(getMsg("summary-finished-successfully")));
hmSummary.put(InstallProgressStep.FINISHED_WITH_ERROR, "<html>"
- + getHtmlError(getMsg("summary-finished-with-error")));
+ + getFormattedError(getMsg("summary-finished-with-error")));
}
/**
diff --git a/opends/src/quicksetup/org/opends/quicksetup/installer/offline/OfflineInstaller.java b/opends/src/quicksetup/org/opends/quicksetup/installer/offline/OfflineInstaller.java
index 8f5de38..8582eb8 100644
--- a/opends/src/quicksetup/org/opends/quicksetup/installer/offline/OfflineInstaller.java
+++ b/opends/src/quicksetup/org/opends/quicksetup/installer/offline/OfflineInstaller.java
@@ -36,7 +36,7 @@
import org.opends.quicksetup.installer.InstallProgressStep;
import org.opends.quicksetup.installer.Installer;
import org.opends.quicksetup.installer.UserInstallData;
-import org.opends.quicksetup.ui.UIFactory;
+import org.opends.quicksetup.util.ProgressMessageFormatter;
import org.opends.quicksetup.util.Utils;
/**
@@ -51,13 +51,6 @@
* will send a ProgressUpdateEvent.
*
* This class is supposed to be fully independent of the graphical layout.
- * However it is the most appropriate part of the code to generate well
- * formatted messages. So it generates HTML messages in the
- * ProgressUpdateEvent and to do so uses the UIFactory method.
- *
- * TODO pass an object in the constructor that would generate the messages.
- * The problem of this approach is that the resulting interface of this object
- * may be quite complex and could impact the lisibility of the code.
*
*/
public class OfflineInstaller extends Installer
@@ -111,10 +104,14 @@
* OfflineInstaller constructor.
* @param userData the UserInstallData with the parameters provided by the
* user.
+ * @param formatter the message formatter to be used to generate the text of
+ * the ProgressUpdateEvent.
+ *
*/
- public OfflineInstaller(UserInstallData userData)
+ public OfflineInstaller(UserInstallData userData,
+ ProgressMessageFormatter formatter)
{
- super(userData);
+ super(userData, formatter);
initMaps();
status = InstallProgressStep.NOT_STARTED;
}
@@ -162,24 +159,24 @@
{
case CREATE_BASE_ENTRY:
status = InstallProgressStep.CREATING_BASE_ENTRY;
- notifyListeners(UIFactory.HTML_SEPARATOR);
+ notifyListeners(getTaskSeparator());
createBaseEntry();
break;
case IMPORT_FROM_LDIF_FILE:
status = InstallProgressStep.IMPORTING_LDIF;
- notifyListeners(UIFactory.HTML_SEPARATOR);
+ notifyListeners(getTaskSeparator());
importLDIF();
break;
case IMPORT_AUTOMATICALLY_GENERATED_DATA:
status = InstallProgressStep.IMPORTING_AUTOMATICALLY_GENERATED;
- notifyListeners(UIFactory.HTML_SEPARATOR);
+ notifyListeners(getTaskSeparator());
importAutomaticallyGenerated();
break;
}
if (getUserData().getStartServer())
{
- notifyListeners(UIFactory.HTML_SEPARATOR);
+ notifyListeners(getTaskSeparator());
status = InstallProgressStep.STARTING_SERVER;
startServer();
}
@@ -197,7 +194,7 @@
ex.getCause().printStackTrace();
}
status = InstallProgressStep.FINISHED_WITH_ERROR;
- String html = getHtmlError(ex, true);
+ String html = getFormattedError(ex, true);
notifyListeners(html);
}
}
diff --git a/opends/src/quicksetup/org/opends/quicksetup/installer/webstart/WebStartInstaller.java b/opends/src/quicksetup/org/opends/quicksetup/installer/webstart/WebStartInstaller.java
index cfd350f..1e69c29 100644
--- a/opends/src/quicksetup/org/opends/quicksetup/installer/webstart/WebStartInstaller.java
+++ b/opends/src/quicksetup/org/opends/quicksetup/installer/webstart/WebStartInstaller.java
@@ -41,7 +41,7 @@
import org.opends.quicksetup.installer.InstallProgressStep;
import org.opends.quicksetup.installer.Installer;
import org.opends.quicksetup.installer.UserInstallData;
-import org.opends.quicksetup.ui.UIFactory;
+import org.opends.quicksetup.util.ProgressMessageFormatter;
import org.opends.quicksetup.util.Utils;
/**
@@ -68,13 +68,6 @@
* will send a ProgressUpdateEvent.
*
* This class is supposed to be fully independent of the graphical layout.
- * However it is the most appropriate part of the code to generate well
- * formatted messages. So it generates HTML messages in the
- * ProgressUpdateEvent and to do so uses the UIFactory method.
- *
- * TODO pass an object in the constructor that would generate the messages.
- * The problem of this approach is that the resulting interface of this object
- * may be quite complex and could impact the lisibility of the code.
*
*/
public class WebStartInstaller extends Installer implements JnlpProperties
@@ -95,11 +88,13 @@
* user.
* @param loader the WebStartLoader that is used to download the remote jar
* files.
+ * @param formatter the message formatter to be used to generate the text of
+ * the ProgressUpdateEvent
*/
public WebStartInstaller(UserInstallData userData,
- WebStartDownloader loader)
+ WebStartDownloader loader, ProgressMessageFormatter formatter)
{
- super(userData);
+ super(userData, formatter);
this.loader = loader;
initMaps();
status = InstallProgressStep.NOT_STARTED;
@@ -145,12 +140,12 @@
InputStream in =
getZipInputStream(getRatio(InstallProgressStep.EXTRACTING));
- notifyListeners(UIFactory.HTML_SEPARATOR);
+ notifyListeners(getTaskSeparator());
status = InstallProgressStep.EXTRACTING;
extractZipFiles(in, getRatio(InstallProgressStep.EXTRACTING),
getRatio(InstallProgressStep.CONFIGURING_SERVER));
- notifyListeners(UIFactory.HTML_SEPARATOR);
+ notifyListeners(getTaskSeparator());
status = InstallProgressStep.CONFIGURING_SERVER;
configureServer();
@@ -159,24 +154,24 @@
{
case CREATE_BASE_ENTRY:
status = InstallProgressStep.CREATING_BASE_ENTRY;
- notifyListeners(UIFactory.HTML_SEPARATOR);
+ notifyListeners(getTaskSeparator());
createBaseEntry();
break;
case IMPORT_FROM_LDIF_FILE:
status = InstallProgressStep.IMPORTING_LDIF;
- notifyListeners(UIFactory.HTML_SEPARATOR);
+ notifyListeners(getTaskSeparator());
importLDIF();
break;
case IMPORT_AUTOMATICALLY_GENERATED_DATA:
status = InstallProgressStep.IMPORTING_AUTOMATICALLY_GENERATED;
- notifyListeners(UIFactory.HTML_SEPARATOR);
+ notifyListeners(getTaskSeparator());
importAutomaticallyGenerated();
break;
}
if (getUserData().getStartServer())
{
- notifyListeners(UIFactory.HTML_SEPARATOR);
+ notifyListeners(getTaskSeparator());
status = InstallProgressStep.STARTING_SERVER;
startServer();
}
@@ -187,7 +182,7 @@
} catch (InstallException ex)
{
status = InstallProgressStep.FINISHED_WITH_ERROR;
- String html = getHtmlError(ex, true);
+ String html = getFormattedError(ex, true);
notifyListeners(html);
}
}
@@ -282,7 +277,7 @@
private InputStream getZipInputStream(Integer maxRatio)
throws InstallException
{
- notifyListeners(getHtmlWithPoints(getMsg("progress-downloading")));
+ notifyListeners(getFormattedWithPoints(getMsg("progress-downloading")));
InputStream in = null;
waitForLoader(maxRatio);
@@ -297,7 +292,7 @@
}
- notifyListeners(getHtmlDone());
+ notifyListeners(getFormattedDone());
return in;
}
@@ -499,7 +494,7 @@
String path = Utils.getPath(basePath, entryName);
notifyListeners(ratioBeforeCompleted, getSummary(getStatus()),
- getHtmlWithPoints(getMsg("progress-extracting", new String[]
+ getFormattedWithPoints(getMsg("progress-extracting", new String[]
{ path })));
if (Utils.createParentPath(path))
{
@@ -534,7 +529,7 @@
throw new IOException("Could not create parent path: " + path);
}
notifyListeners(ratioWhenCompleted, getSummary(getStatus()),
- getHtmlDone() + LINE_BREAK);
+ getFormattedDone() + getLineBreak());
}
/**
diff --git a/opends/src/quicksetup/org/opends/quicksetup/ui/CurrentStepPanel.java b/opends/src/quicksetup/org/opends/quicksetup/ui/CurrentStepPanel.java
index 97f6e26..906f4c3 100644
--- a/opends/src/quicksetup/org/opends/quicksetup/ui/CurrentStepPanel.java
+++ b/opends/src/quicksetup/org/opends/quicksetup/ui/CurrentStepPanel.java
@@ -108,6 +108,16 @@
}
/**
+ * Returns the panel we use to display the progress. This method is used
+ * to be able to retrieve the message formatter.
+ * @return the panel we use to display the progress.
+ */
+ ProgressPanel getProgressPanel()
+ {
+ return (ProgressPanel)hmPanels.get(Step.PROGRESS);
+ }
+
+ /**
* Create the layout of the panel.
* @param isUninstall whether this is an install or uninstall panel.
*/
diff --git a/opends/src/quicksetup/org/opends/quicksetup/ui/ProgressPanel.java b/opends/src/quicksetup/org/opends/quicksetup/ui/ProgressPanel.java
index 5b3a03d..71ece54 100644
--- a/opends/src/quicksetup/org/opends/quicksetup/ui/ProgressPanel.java
+++ b/opends/src/quicksetup/org/opends/quicksetup/ui/ProgressPanel.java
@@ -42,7 +42,8 @@
import org.opends.quicksetup.installer.InstallProgressDescriptor;
import org.opends.quicksetup.installer.InstallProgressStep;
-import org.opends.quicksetup.installer.Installer;
+import org.opends.quicksetup.util.HtmlProgressMessageFormatter;
+import org.opends.quicksetup.util.ProgressMessageFormatter;
/**
* This panel is used to show the progress of the install or the uninstall.
@@ -62,6 +63,8 @@
private String lastText;
+ private ProgressMessageFormatter formatter;
+
/**
* ProgressPanel constructor.
*/
@@ -116,7 +119,8 @@
if (e.getEventType() == HyperlinkEvent.EventType.ACTIVATED)
{
String url = e.getURL().toString();
- String newText = Installer.getHtmlAfterUrlClick(url, lastText);
+ String newText = getFormatter().getFormattedAfterUrlClick(url,
+ lastText);
lastText = newText;
detailsTextArea.setText(lastText);
}
@@ -208,4 +212,19 @@
return panel;
}
+
+ /**
+ * Returns the formatter that will be used to display the messages in this
+ * panel.
+ * @return the formatter that will be used to display the messages in this
+ * panel.
+ */
+ ProgressMessageFormatter getFormatter()
+ {
+ if (formatter == null)
+ {
+ formatter = new HtmlProgressMessageFormatter();
+ }
+ return formatter;
+ }
}
diff --git a/opends/src/quicksetup/org/opends/quicksetup/ui/QuickSetupDialog.java b/opends/src/quicksetup/org/opends/quicksetup/ui/QuickSetupDialog.java
index 4d85afd..f166232 100644
--- a/opends/src/quicksetup/org/opends/quicksetup/ui/QuickSetupDialog.java
+++ b/opends/src/quicksetup/org/opends/quicksetup/ui/QuickSetupDialog.java
@@ -48,6 +48,7 @@
import org.opends.quicksetup.installer.InstallProgressDescriptor;
import org.opends.quicksetup.installer.InstallProgressStep;
import org.opends.quicksetup.installer.UserInstallData;
+import org.opends.quicksetup.util.ProgressMessageFormatter;
import org.opends.quicksetup.util.Utils;
/**
@@ -338,6 +339,17 @@
}
/**
+ * Return the progress message formatter that will be used in the dialog
+ * to display the messages.
+ * @return the progress message formatter that will be used in the dialog
+ * to display the messages.
+ */
+ public ProgressMessageFormatter getFormatter()
+ {
+ return getCurrentStepPanel().getProgressPanel().getFormatter();
+ }
+
+ /**
* Marks as invalid (or valid depending on the value of the invalid parameter)
* a field corresponding to FieldName. This basically implies udpating the
* style of the JLabel associated with fieldName (the association is done
--
Gitblit v1.10.0