From 2d4d872ad7b7809cc38adf7f0df9a704c01fe5f2 Mon Sep 17 00:00:00 2001
From: jvergara <jvergara@localhost>
Date: Tue, 23 Oct 2007 20:56:26 +0000
Subject: [PATCH] Fix for issue 2494.
---
opendj-sdk/opends/src/guitools/org/opends/guitools/statuspanel/StatusCliArgumentParser.java | 22 +++++++
opendj-sdk/opends/src/guitools/org/opends/guitools/statuspanel/StatusCli.java | 124 ++++++++++++++++++++++++++++++----------
2 files changed, 114 insertions(+), 32 deletions(-)
diff --git a/opendj-sdk/opends/src/guitools/org/opends/guitools/statuspanel/StatusCli.java b/opendj-sdk/opends/src/guitools/org/opends/guitools/statuspanel/StatusCli.java
index ffa8fc4..fbd1c7a 100644
--- a/opendj-sdk/opends/src/guitools/org/opends/guitools/statuspanel/StatusCli.java
+++ b/opendj-sdk/opends/src/guitools/org/opends/guitools/statuspanel/StatusCli.java
@@ -578,43 +578,61 @@
INFO_JAVA_VERSION_LABEL.get()
};
int labelWidth = 0;
- for (int i=0; i<labels.length; i++)
- {
- labelWidth = Math.max(labelWidth, labels[i].length());
- }
- out.println();
Message title = INFO_SERVER_STATUS_TITLE.get();
- out.println(centerTitle(title));
+ if (!isScriptFriendly())
+ {
+ for (int i=0; i<labels.length; i++)
+ {
+ labelWidth = Math.max(labelWidth, labels[i].length());
+ }
+ out.println();
+ out.println(centerTitle(title));
+ }
writeStatusContents(desc, labelWidth);
writeCurrentConnectionContents(desc, labelWidth);
- out.println();
+ if (!isScriptFriendly())
+ {
+ out.println();
+ }
title = INFO_SERVER_DETAILS_TITLE.get();
- out.println(centerTitle(title));
+ if (!isScriptFriendly())
+ {
+ out.println(centerTitle(title));
+ }
writeHostnameContents(desc, labelWidth);
writeAdministrativeUserContents(desc, labelWidth);
writeInstallPathContents(desc, labelWidth);
writeVersionContents(desc, labelWidth);
writeJavaVersionContents(desc, labelWidth);
- out.println();
+ if (!isScriptFriendly())
+ {
+ out.println();
+ }
writeListenerContents(desc);
- out.println();
+ if (!isScriptFriendly())
+ {
+ out.println();
+ }
writeDatabaseContents(desc);
writeErrorContents(desc);
- if (displayMustStartLegend)
+ if (!isScriptFriendly())
{
- out.println();
- out.println(wrap(INFO_NOT_AVAILABLE_SERVER_DOWN_CLI_LEGEND.get()));
- }
- else if (displayMustAuthenticateLegend)
- {
- out.println();
- out.println(
- wrap(INFO_NOT_AVAILABLE_AUTHENTICATION_REQUIRED_CLI_LEGEND.get()));
+ if (displayMustStartLegend)
+ {
+ out.println();
+ out.println(wrap(INFO_NOT_AVAILABLE_SERVER_DOWN_CLI_LEGEND.get()));
+ }
+ else if (displayMustAuthenticateLegend)
+ {
+ out.println();
+ out.println(
+ wrap(INFO_NOT_AVAILABLE_AUTHENTICATION_REQUIRED_CLI_LEGEND.get()));
+ }
}
out.println();
}
@@ -830,8 +848,11 @@
*/
private void writeListenerContents(ServerStatusDescriptor desc)
{
- Message title = INFO_LISTENERS_TITLE.get();
- out.println(centerTitle(title));
+ if (!isScriptFriendly())
+ {
+ Message title = INFO_LISTENERS_TITLE.get();
+ out.println(centerTitle(title));
+ }
Set<ListenerDescriptor> allListeners = desc.getListeners();
@@ -879,7 +900,10 @@
private void writeDatabaseContents(ServerStatusDescriptor desc)
{
Message title = INFO_DATABASES_TITLE.get();
- out.println(centerTitle(title));
+ if (!isScriptFriendly())
+ {
+ out.println(centerTitle(title));
+ }
Set<DatabaseDescriptor> databases = desc.getDatabases();
@@ -1039,19 +1063,30 @@
headerLine.append(" ");
}
}
- out.println(wrap(headerLine.toMessage()));
- MessageBuilder t = new MessageBuilder();
- for (int i=0; i<headerLine.length(); i++)
+ if (!isScriptFriendly())
{
- t.append("=");
+ out.println(wrap(headerLine.toMessage()));
+ MessageBuilder t = new MessageBuilder();
+ for (int i=0; i<headerLine.length(); i++)
+ {
+ t.append("=");
+ }
+ out.println(wrap(t.toMessage()));
}
- out.println(wrap(t.toMessage()));
for (int i=0; i<tableModel.getRowCount(); i++)
{
+ if (isScriptFriendly())
+ {
+ out.println("-");
+ }
MessageBuilder line = new MessageBuilder();
for (int j=0; j<tableModel.getColumnCount(); j++)
{
+ if (isScriptFriendly())
+ {
+ line.append(tableModel.getColumnName(j)+": ");
+ }
int extra = maxWidths[j];
Object v = tableModel.getValueAt(i, j);
if (v != null)
@@ -1085,14 +1120,24 @@
{
throw new IllegalStateException("Unknown object type: "+v);
}
-
+ if (isScriptFriendly())
+ {
+ out.println(wrap(line.toMessage()));
+ line = new MessageBuilder();
+ }
}
- for (int k=0; k<extra; k++)
+ if (!isScriptFriendly())
{
- line.append(" ");
+ for (int k=0; k<extra; k++)
+ {
+ line.append(" ");
+ }
}
}
- out.println(wrap(line.toMessage()));
+ if (!isScriptFriendly())
+ {
+ out.println(wrap(line.toMessage()));
+ }
}
}
@@ -1128,7 +1173,11 @@
Message replicatedLabel = INFO_BASEDN_REPLICATED_LABEL.get();
for (int i=0; i<tableModel.getRowCount(); i++)
{
- if (i > 0)
+ if (isScriptFriendly())
+ {
+ out.println("-");
+ }
+ else if (i > 0)
{
out.println();
}
@@ -1254,4 +1303,15 @@
{
return argParser.getTrustManager();
}
+
+ /**
+ * Tells whether the user specified to have a script-friendly output or not.
+ * This method must be called after calling parseArguments.
+ * @return <CODE>true</CODE> if the user specified to have a script-friendly
+ * output and <CODE>false</CODE> otherwise.
+ */
+ private boolean isScriptFriendly()
+ {
+ return argParser.isScriptFriendly();
+ }
}
diff --git a/opendj-sdk/opends/src/guitools/org/opends/guitools/statuspanel/StatusCliArgumentParser.java b/opendj-sdk/opends/src/guitools/org/opends/guitools/statuspanel/StatusCliArgumentParser.java
index 6b13f96..5e59fee 100644
--- a/opendj-sdk/opends/src/guitools/org/opends/guitools/statuspanel/StatusCliArgumentParser.java
+++ b/opendj-sdk/opends/src/guitools/org/opends/guitools/statuspanel/StatusCliArgumentParser.java
@@ -49,6 +49,11 @@
private BooleanArgument noPromptArg;
/**
+ * The 'scriptFriendly' argument.
+ */
+ private BooleanArgument scriptFriendlyArg;
+
+ /**
* Creates a new instance of this argument parser with no arguments.
*
* @param mainClassName
@@ -86,6 +91,12 @@
ToolConstants.OPTION_LONG_NO_PROMPT,
INFO_DESCRIPTION_NO_PROMPT.get());
defaultArgs.add(0, noPromptArg);
+ scriptFriendlyArg = new BooleanArgument(
+ "script-friendly",
+ 's',
+ "script-friendly",
+ INFO_DESCRIPTION_SCRIPT_FRIENDLY.get());
+ defaultArgs.add(1, scriptFriendlyArg);
initializeGlobalArguments(defaultArgs);
}
@@ -101,6 +112,17 @@
}
/**
+ * Tells whether the user specified to have a script-friendly output or not.
+ * This method must be called after calling parseArguments.
+ * @return <CODE>true</CODE> if the user specified to have a script-friendly
+ * output and <CODE>false</CODE> otherwise.
+ */
+ public boolean isScriptFriendly()
+ {
+ return scriptFriendlyArg.isPresent();
+ }
+
+ /**
* Returns the first server bind dn explicitly provided in the enable
* replication subcommand.
* @return the first server bind dn explicitly provided in the enable
--
Gitblit v1.10.0