You are viewing a plain text version of this content. The canonical link for it is here.
Posted to scm@geronimo.apache.org by jd...@apache.org on 2008/09/14 15:47:50 UTC
svn commit: r695221 - in /geronimo/gshell/trunk:
gshell-commands/gshell-builtins/src/main/java/org/apache/geronimo/gshell/commands/builtins/
gshell-support/gshell-clp/src/main/java/org/apache/geronimo/gshell/clp/
gshell-support/gshell-clp/src/main/java...
Author: jdillon
Date: Sun Sep 14 06:47:49 2008
New Revision: 695221
URL: http://svn.apache.org/viewvc?rev=695221&view=rev
Log:
Cleaned up the clp stuff a little, now supports automatic i18n message code generation
Added:
geronimo/gshell/trunk/gshell-support/gshell-i18n/src/main/java/org/apache/geronimo/gshell/i18n/PrefixingMessageSource.java (contents, props changed)
- copied, changed from r695140, geronimo/gshell/trunk/gshell-support/gshell-i18n/src/main/java/org/apache/geronimo/gshell/i18n/MessageSource.java
Modified:
geronimo/gshell/trunk/gshell-commands/gshell-builtins/src/main/java/org/apache/geronimo/gshell/commands/builtins/EchoCommand.java
geronimo/gshell/trunk/gshell-support/gshell-clp/src/main/java/org/apache/geronimo/gshell/clp/ArgumentDescriptor.java
geronimo/gshell/trunk/gshell-support/gshell-clp/src/main/java/org/apache/geronimo/gshell/clp/CommandLineProcessor.java
geronimo/gshell/trunk/gshell-support/gshell-clp/src/main/java/org/apache/geronimo/gshell/clp/Descriptor.java
geronimo/gshell/trunk/gshell-support/gshell-clp/src/main/java/org/apache/geronimo/gshell/clp/OptionDescriptor.java
geronimo/gshell/trunk/gshell-support/gshell-clp/src/main/java/org/apache/geronimo/gshell/clp/Printer.java
geronimo/gshell/trunk/gshell-support/gshell-clp/src/main/java/org/apache/geronimo/gshell/clp/handler/Handlers.java
geronimo/gshell/trunk/gshell-support/gshell-clp/src/main/java/org/apache/geronimo/gshell/clp/setter/FieldSetter.java
geronimo/gshell/trunk/gshell-support/gshell-clp/src/main/java/org/apache/geronimo/gshell/clp/setter/MethodSetter.java
geronimo/gshell/trunk/gshell-support/gshell-clp/src/main/java/org/apache/geronimo/gshell/clp/setter/Setter.java
geronimo/gshell/trunk/gshell-support/gshell-clp/src/main/resources/org/apache/geronimo/gshell/clp/setter/Messages.properties
geronimo/gshell/trunk/gshell-wisdom/gshell-wisdom-core/src/main/java/org/apache/geronimo/gshell/wisdom/command/CommandDocumenterImpl.java
Modified: geronimo/gshell/trunk/gshell-commands/gshell-builtins/src/main/java/org/apache/geronimo/gshell/commands/builtins/EchoCommand.java
URL: http://svn.apache.org/viewvc/geronimo/gshell/trunk/gshell-commands/gshell-builtins/src/main/java/org/apache/geronimo/gshell/commands/builtins/EchoCommand.java?rev=695221&r1=695220&r2=695221&view=diff
==============================================================================
--- geronimo/gshell/trunk/gshell-commands/gshell-builtins/src/main/java/org/apache/geronimo/gshell/commands/builtins/EchoCommand.java (original)
+++ geronimo/gshell/trunk/gshell-commands/gshell-builtins/src/main/java/org/apache/geronimo/gshell/commands/builtins/EchoCommand.java Sun Sep 14 06:47:49 2008
@@ -24,27 +24,22 @@
import org.apache.geronimo.gshell.command.CommandAction;
import org.apache.geronimo.gshell.command.CommandContext;
import org.apache.geronimo.gshell.io.IO;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
import java.util.List;
/**
- * A simple command to <em>echo</em> all given arguments to the commands standard output.
+ * A simple command to print all arguments to the commands standard output.
*
* @version $Rev$ $Date$
*/
public class EchoCommand
implements CommandAction
{
- private final Logger log = LoggerFactory.getLogger(getClass());
-
- @Option(name="-n", description="command.option.trailingNewline")
+ @Option(name="-n")
private boolean trailingNewline = true;
- @SuppressWarnings({"MismatchedQueryAndUpdateOfCollection"})
- @Argument(description="command.argument.args")
- private List<String> args;
+ @Argument()
+ private List<String> args = null;
public Object execute(final CommandContext context) throws Exception {
assert context != null;
Modified: geronimo/gshell/trunk/gshell-support/gshell-clp/src/main/java/org/apache/geronimo/gshell/clp/ArgumentDescriptor.java
URL: http://svn.apache.org/viewvc/geronimo/gshell/trunk/gshell-support/gshell-clp/src/main/java/org/apache/geronimo/gshell/clp/ArgumentDescriptor.java?rev=695221&r1=695220&r2=695221&view=diff
==============================================================================
--- geronimo/gshell/trunk/gshell-support/gshell-clp/src/main/java/org/apache/geronimo/gshell/clp/ArgumentDescriptor.java (original)
+++ geronimo/gshell/trunk/gshell-support/gshell-clp/src/main/java/org/apache/geronimo/gshell/clp/ArgumentDescriptor.java Sun Sep 14 06:47:49 2008
@@ -27,13 +27,13 @@
public class ArgumentDescriptor
extends Descriptor
{
- public ArgumentDescriptor(Argument argument, boolean forceMultiValued) {
- super(argument.description(), argument.metaVar(), argument.required(), argument.handler(), argument.multiValued() || forceMultiValued);
+ public ArgumentDescriptor(final String id, final Argument argument, final boolean forceMultiValued) {
+ super(id, argument.description(), argument.metaVar(), argument.required(), argument.handler(), argument.multiValued() || forceMultiValued);
}
@Override
public String toString() {
- String tmp = metaVar();
+ String tmp = getMetaVar();
if (tmp != null && tmp.length() != 0) {
return tmp;
}
Modified: geronimo/gshell/trunk/gshell-support/gshell-clp/src/main/java/org/apache/geronimo/gshell/clp/CommandLineProcessor.java
URL: http://svn.apache.org/viewvc/geronimo/gshell/trunk/gshell-support/gshell-clp/src/main/java/org/apache/geronimo/gshell/clp/CommandLineProcessor.java?rev=695221&r1=695220&r2=695221&view=diff
==============================================================================
--- geronimo/gshell/trunk/gshell-support/gshell-clp/src/main/java/org/apache/geronimo/gshell/clp/CommandLineProcessor.java (original)
+++ geronimo/gshell/trunk/gshell-support/gshell-clp/src/main/java/org/apache/geronimo/gshell/clp/CommandLineProcessor.java Sun Sep 14 06:47:49 2008
@@ -30,7 +30,6 @@
import java.util.Set;
import java.util.TreeMap;
-import org.apache.geronimo.gshell.i18n.MessageSource;
import org.apache.geronimo.gshell.clp.handler.Handler;
import org.apache.geronimo.gshell.clp.handler.Handlers;
import org.apache.geronimo.gshell.clp.handler.Parameters;
@@ -139,7 +138,7 @@
}
private void addArgument(final Setter setter, final Argument argument) {
- Handler handler = Handlers.create(new ArgumentDescriptor(argument, setter.isMultiValued()), setter);
+ Handler handler = Handlers.create(new ArgumentDescriptor(setter.getName(), argument, setter.isMultiValued()), setter);
int index = argument.index();
// Make sure the argument will fit in the list
@@ -155,7 +154,7 @@
}
private void addOption(final Setter setter, final Option option) {
- Handler handler = Handlers.create(new OptionDescriptor(option, setter.isMultiValued()), setter);
+ Handler handler = Handlers.create(new OptionDescriptor(setter.getName(), option, setter.isMultiValued()), setter);
checkOptionNotInMap(option.name());
for (String alias : option.aliases()) {
@@ -296,14 +295,14 @@
// Ensure that all required option handlers are present, unless a processed option has overridden requirments
if (!requireOverride) {
for (Handler handler : optionHandlers) {
- if (handler.descriptor.required() && !present.contains(handler)) {
+ if (handler.descriptor.isRequired() && !present.contains(handler)) {
throw new ProcessingException(Messages.REQUIRED_OPTION_MISSING.format(handler.descriptor.toString()));
}
}
// Ensure that all required argument handlers are present
for (Handler handler : argumentHandlers) {
- if (handler.descriptor.required() && !present.contains(handler)) {
+ if (handler.descriptor.isRequired() && !present.contains(handler)) {
throw new ProcessingException(Messages.REQUIRED_ARGUMENT_MISSING.format(handler.descriptor.toString()));
}
}
@@ -339,14 +338,14 @@
for (Handler handler : handlers) {
if (keyFilter.contains("--")) {
- for (String alias : ((OptionDescriptor)handler.descriptor).aliases()) {
+ for (String alias : ((OptionDescriptor)handler.descriptor).getAliases()) {
if (alias.startsWith(keyFilter)) {
map.put(alias, handler);
}
}
} else {
- if (((OptionDescriptor)handler.descriptor).name().startsWith(keyFilter)) {
- map.put(((OptionDescriptor)handler.descriptor).name(), handler);
+ if (((OptionDescriptor)handler.descriptor).getName().startsWith(keyFilter)) {
+ map.put(((OptionDescriptor)handler.descriptor).getName(), handler);
}
}
}
@@ -358,11 +357,11 @@
for (Handler handler : optionHandlers) {
OptionDescriptor option = (OptionDescriptor)handler.descriptor;
- if (name.equals(option.name())) {
+ if (name.equals(option.getName())) {
return handler;
}
- for (String alias : option.aliases()) {
+ for (String alias : option.getAliases()) {
if (name.equals(alias)) {
return handler;
}
Modified: geronimo/gshell/trunk/gshell-support/gshell-clp/src/main/java/org/apache/geronimo/gshell/clp/Descriptor.java
URL: http://svn.apache.org/viewvc/geronimo/gshell/trunk/gshell-support/gshell-clp/src/main/java/org/apache/geronimo/gshell/clp/Descriptor.java?rev=695221&r1=695220&r2=695221&view=diff
==============================================================================
--- geronimo/gshell/trunk/gshell-support/gshell-clp/src/main/java/org/apache/geronimo/gshell/clp/Descriptor.java (original)
+++ geronimo/gshell/trunk/gshell-support/gshell-clp/src/main/java/org/apache/geronimo/gshell/clp/Descriptor.java Sun Sep 14 06:47:49 2008
@@ -28,6 +28,8 @@
*/
public abstract class Descriptor
{
+ private final String id;
+
private final String description;
private final String metaVar;
@@ -38,27 +40,48 @@
private final Class<? extends Handler> handler;
- protected Descriptor(final String description, final String metaVar, final boolean required, final Class<? extends Handler> handler, final boolean multiValued) {
- this.description = description;
- this.metaVar = metaVar;
+ protected Descriptor(final String id, final String description, final String metaVar, final boolean required, final Class<? extends Handler> handler, final boolean multiValued) {
+ assert id != null;
+
+ this.id = id;
+
+ // Handle "" = null, since default values in annotations can be set to null
+ if (description != null && description.length() == 0) {
+ this.description = null;
+ }
+ else {
+ this.description = description;
+ }
+
+ if (metaVar != null && metaVar.length() == 0) {
+ this.metaVar = null;
+ }
+ else {
+ this.metaVar = metaVar;
+ }
+
this.required = required;
this.handler = handler;
this.multiValued = multiValued;
}
- public String description() {
+ public String getId() {
+ return id;
+ }
+
+ public String getDescription() {
return description;
}
- public String metaVar() {
+ public String getMetaVar() {
return metaVar;
}
- public boolean required() {
+ public boolean isRequired() {
return required;
}
- public Class<? extends Handler> handler() {
+ public Class<? extends Handler> getHandler() {
return handler;
}
Modified: geronimo/gshell/trunk/gshell-support/gshell-clp/src/main/java/org/apache/geronimo/gshell/clp/OptionDescriptor.java
URL: http://svn.apache.org/viewvc/geronimo/gshell/trunk/gshell-support/gshell-clp/src/main/java/org/apache/geronimo/gshell/clp/OptionDescriptor.java?rev=695221&r1=695220&r2=695221&view=diff
==============================================================================
--- geronimo/gshell/trunk/gshell-support/gshell-clp/src/main/java/org/apache/geronimo/gshell/clp/OptionDescriptor.java (original)
+++ geronimo/gshell/trunk/gshell-support/gshell-clp/src/main/java/org/apache/geronimo/gshell/clp/OptionDescriptor.java Sun Sep 14 06:47:49 2008
@@ -31,24 +31,24 @@
private final String[] aliases;
- private boolean argumentRequired;
+ private final boolean argumentRequired;
- private boolean requireOverride;
+ private final boolean requireOverride;
- public OptionDescriptor(final Option option, final boolean forceMultiValued) {
- super(option.description(), option.metaVar(), option.required(), option.handler(), option.multiValued() || forceMultiValued);
+ public OptionDescriptor(final String id, final Option option, final boolean forceMultiValued) {
+ super(id, option.description(), option.metaVar(), option.required(), option.handler(), option.multiValued() || forceMultiValued);
this.name = option.name();
this.aliases = option.aliases();
this.argumentRequired = option.argumentRequired();
this.requireOverride = option.requireOverride();
}
-
- public String name() {
+
+ public String getName() {
return name;
}
- public String[] aliases() {
+ public String[] getAliases() {
return aliases;
}
@@ -72,9 +72,9 @@
str += alias;
}
- return name() + " (" + str + ")";
+ return getName() + " (" + str + ")";
}
- return name();
+ return getName();
}
}
Modified: geronimo/gshell/trunk/gshell-support/gshell-clp/src/main/java/org/apache/geronimo/gshell/clp/Printer.java
URL: http://svn.apache.org/viewvc/geronimo/gshell/trunk/gshell-support/gshell-clp/src/main/java/org/apache/geronimo/gshell/clp/Printer.java?rev=695221&r1=695220&r2=695221&view=diff
==============================================================================
--- geronimo/gshell/trunk/gshell-support/gshell-clp/src/main/java/org/apache/geronimo/gshell/clp/Printer.java (original)
+++ geronimo/gshell/trunk/gshell-support/gshell-clp/src/main/java/org/apache/geronimo/gshell/clp/Printer.java Sun Sep 14 06:47:49 2008
@@ -25,7 +25,6 @@
import java.util.Collections;
import java.util.Comparator;
import java.util.List;
-import java.util.ResourceBundle;
import org.apache.geronimo.gshell.clp.handler.Handler;
import org.apache.geronimo.gshell.i18n.MessageSource;
@@ -54,11 +53,45 @@
this.messages = messages;
}
- private String getMetaVariable(final Handler handler, final ResourceBundle bundle) {
+ /**
+ * Get the help text for the given descriptor, using any configured messages for i18n support.
+ */
+ private String getHelpText(final Descriptor descriptor) {
+ assert descriptor != null;
+
+ String message = descriptor.getDescription();
+
+ // If we have i18n messages for the command, then try to resolve the message further using the message as the code
+ if (messages != null) {
+ String code = message;
+
+ // If there is no code, then generate one
+ if (code == null) {
+ if (descriptor instanceof ArgumentDescriptor) {
+ code = "argument." + descriptor.getId();
+ }
+ else {
+ code = "option." + descriptor.getId();
+ }
+ }
+
+ // Resolve the text in the message source
+ try {
+ message = messages.getMessage(code);
+ }
+ catch (ResourceNotFoundException e) {
+ // Just use the code as the message
+ }
+ }
+
+ return message;
+ }
+
+ private String getMetaVariable(final Handler handler) {
assert handler != null;
- String token = handler.descriptor.metaVar();
- if (token.length() == 0) {
+ String token = handler.descriptor.getMetaVar();
+ if (token == null) {
token = handler.getDefaultMetaVariable();
}
@@ -66,22 +99,14 @@
return null;
}
- if (bundle != null) {
- String localized = bundle.getString(token);
-
- if (localized != null) {
- token = localized;
- }
- }
-
return token;
}
- private String getNameAndMeta(final Handler handler, final ResourceBundle bundle) {
+ private String getNameAndMeta(final Handler handler) {
assert handler != null;
String str = (handler.descriptor instanceof ArgumentDescriptor) ? "" : handler.descriptor.toString();
- String meta = getMetaVariable(handler, bundle);
+ String meta = getMetaVariable(handler);
if (meta != null) {
if (str.length() > 0) {
@@ -93,17 +118,18 @@
return str;
}
- private int getPrefixLen(final Handler handler, final ResourceBundle bundle) {
+ private int getPrefixLen(final Handler handler) {
assert handler != null;
- if (handler.descriptor.description().length() == 0) {
+ String helpText = getHelpText(handler.descriptor);
+ if (helpText == null) {
return 0;
}
- return getNameAndMeta(handler, bundle).length();
+ return getNameAndMeta(handler).length();
}
- public void printUsage(final Writer writer, final ResourceBundle bundle, final String name) {
+ public void printUsage(final Writer writer, final String name) {
assert writer != null;
PrintWriter out = new PrintWriter(writer);
@@ -139,15 +165,14 @@
// Compute the maximum length of the syntax column
int len = 0;
-
for (Handler handler : optionHandlers) {
- int curLen = getPrefixLen(handler, bundle);
+ int curLen = getPrefixLen(handler);
len = Math.max(len, curLen);
}
for (Handler handler : argumentHandlers) {
- int curLen = getPrefixLen(handler, bundle);
+ int curLen = getPrefixLen(handler);
len = Math.max(len, curLen);
}
@@ -156,7 +181,7 @@
out.println("arguments:");
}
for (Handler handler : argumentHandlers) {
- printHandler(out, handler, len, bundle);
+ printHandler(out, handler, len);
}
if (!optionHandlers.isEmpty()) {
@@ -164,41 +189,17 @@
out.println("options:");
}
for (Handler handler : optionHandlers) {
- printHandler(out, handler, len, bundle);
+ printHandler(out, handler, len);
}
out.flush();
}
public void printUsage(final Writer writer) {
- printUsage(writer, null, null);
- }
-
- public void printUsage(final Writer writer, final String name) {
- printUsage(writer, null, name);
+ printUsage(writer, null);
}
- /**
- * Get the description for the given descriptor, using any configured messages for i18n support.
- */
- private String getDescription(final Descriptor descriptor) {
- assert descriptor != null;
-
- String message = descriptor.description();
-
- if (message != null && messages != null) {
- try {
- message = messages.getMessage(message);
- }
- catch (ResourceNotFoundException e) {
- // Just use the code
- }
- }
-
- return message;
- }
-
- private void printHandler(final PrintWriter out, final Handler handler, final int len, final ResourceBundle bundle) {
+ private void printHandler(final PrintWriter out, final Handler handler, final int len) {
assert out != null;
assert handler != null;
@@ -212,14 +213,14 @@
int prefixSeperatorWidth = prefix.length() + separator.length();
int descriptionWidth = terminalWidth - len - prefixSeperatorWidth;
- // Only render if their is a discription, else its hidden
- String desc = getDescription(handler.descriptor);
- if (desc.length() == 0) {
+ // Only render if there is help-text, else its hidden
+ String desc = getHelpText(handler.descriptor);
+ if (desc == null) {
return;
}
// Render the prefix and syntax
- String nameAndMeta = getNameAndMeta(handler, bundle);
+ String nameAndMeta = getNameAndMeta(handler);
out.print(prefix);
out.print(nameAndMeta);
@@ -229,11 +230,6 @@
}
out.print(separator);
- // Localize the description if we can
- if (bundle != null) {
- desc = bundle.getString(desc);
- }
-
// Render the description splitting it over multipule lines if its longer than column size
while (desc != null && desc.length() > 0) {
//
Modified: geronimo/gshell/trunk/gshell-support/gshell-clp/src/main/java/org/apache/geronimo/gshell/clp/handler/Handlers.java
URL: http://svn.apache.org/viewvc/geronimo/gshell/trunk/gshell-support/gshell-clp/src/main/java/org/apache/geronimo/gshell/clp/handler/Handlers.java?rev=695221&r1=695220&r2=695221&view=diff
==============================================================================
--- geronimo/gshell/trunk/gshell-support/gshell-clp/src/main/java/org/apache/geronimo/gshell/clp/handler/Handlers.java (original)
+++ geronimo/gshell/trunk/gshell-support/gshell-clp/src/main/java/org/apache/geronimo/gshell/clp/handler/Handlers.java Sun Sep 14 06:47:49 2008
@@ -68,7 +68,7 @@
assert setter != null;
Constructor<? extends Handler> factory;
- Class<? extends Handler> handlerType = desc.handler();
+ Class<? extends Handler> handlerType = desc.getHandler();
if (handlerType == Handler.class) {
Class valueType = setter.getType();
Modified: geronimo/gshell/trunk/gshell-support/gshell-clp/src/main/java/org/apache/geronimo/gshell/clp/setter/FieldSetter.java
URL: http://svn.apache.org/viewvc/geronimo/gshell/trunk/gshell-support/gshell-clp/src/main/java/org/apache/geronimo/gshell/clp/setter/FieldSetter.java?rev=695221&r1=695220&r2=695221&view=diff
==============================================================================
--- geronimo/gshell/trunk/gshell-support/gshell-clp/src/main/java/org/apache/geronimo/gshell/clp/setter/FieldSetter.java (original)
+++ geronimo/gshell/trunk/gshell-support/gshell-clp/src/main/java/org/apache/geronimo/gshell/clp/setter/FieldSetter.java Sun Sep 14 06:47:49 2008
@@ -41,6 +41,10 @@
this.field = field;
}
+ public String getName() {
+ return field.getName();
+ }
+
public Class getType() {
return field.getType();
}
Modified: geronimo/gshell/trunk/gshell-support/gshell-clp/src/main/java/org/apache/geronimo/gshell/clp/setter/MethodSetter.java
URL: http://svn.apache.org/viewvc/geronimo/gshell/trunk/gshell-support/gshell-clp/src/main/java/org/apache/geronimo/gshell/clp/setter/MethodSetter.java?rev=695221&r1=695220&r2=695221&view=diff
==============================================================================
--- geronimo/gshell/trunk/gshell-support/gshell-clp/src/main/java/org/apache/geronimo/gshell/clp/setter/MethodSetter.java (original)
+++ geronimo/gshell/trunk/gshell-support/gshell-clp/src/main/java/org/apache/geronimo/gshell/clp/setter/MethodSetter.java Sun Sep 14 06:47:49 2008
@@ -49,6 +49,10 @@
}
}
+ public String getName() {
+ return method.getName();
+ }
+
public Class getType() {
return method.getParameterTypes()[0];
}
Modified: geronimo/gshell/trunk/gshell-support/gshell-clp/src/main/java/org/apache/geronimo/gshell/clp/setter/Setter.java
URL: http://svn.apache.org/viewvc/geronimo/gshell/trunk/gshell-support/gshell-clp/src/main/java/org/apache/geronimo/gshell/clp/setter/Setter.java?rev=695221&r1=695220&r2=695221&view=diff
==============================================================================
--- geronimo/gshell/trunk/gshell-support/gshell-clp/src/main/java/org/apache/geronimo/gshell/clp/setter/Setter.java (original)
+++ geronimo/gshell/trunk/gshell-support/gshell-clp/src/main/java/org/apache/geronimo/gshell/clp/setter/Setter.java Sun Sep 14 06:47:49 2008
@@ -37,6 +37,8 @@
*/
void set(T value) throws ProcessingException;
+ String getName();
+
/**
* Gets the type of the underlying method/field.
*/
Modified: geronimo/gshell/trunk/gshell-support/gshell-clp/src/main/resources/org/apache/geronimo/gshell/clp/setter/Messages.properties
URL: http://svn.apache.org/viewvc/geronimo/gshell/trunk/gshell-support/gshell-clp/src/main/resources/org/apache/geronimo/gshell/clp/setter/Messages.properties?rev=695221&r1=695220&r2=695221&view=diff
==============================================================================
--- geronimo/gshell/trunk/gshell-support/gshell-clp/src/main/resources/org/apache/geronimo/gshell/clp/setter/Messages.properties (original)
+++ geronimo/gshell/trunk/gshell-support/gshell-clp/src/main/resources/org/apache/geronimo/gshell/clp/setter/Messages.properties Sun Sep 14 06:47:49 2008
@@ -23,4 +23,4 @@
ILLEGAL_METHOD_SIGNATURE=Method {0} takes more than one parameter
-ILLEGAL_FIELD_SIGNATURE=Field of type {0} isn't supported
\ No newline at end of file
+ILLEGAL_FIELD_SIGNATURE=Field of type {0} is not supported
\ No newline at end of file
Copied: geronimo/gshell/trunk/gshell-support/gshell-i18n/src/main/java/org/apache/geronimo/gshell/i18n/PrefixingMessageSource.java (from r695140, geronimo/gshell/trunk/gshell-support/gshell-i18n/src/main/java/org/apache/geronimo/gshell/i18n/MessageSource.java)
URL: http://svn.apache.org/viewvc/geronimo/gshell/trunk/gshell-support/gshell-i18n/src/main/java/org/apache/geronimo/gshell/i18n/PrefixingMessageSource.java?p2=geronimo/gshell/trunk/gshell-support/gshell-i18n/src/main/java/org/apache/geronimo/gshell/i18n/PrefixingMessageSource.java&p1=geronimo/gshell/trunk/gshell-support/gshell-i18n/src/main/java/org/apache/geronimo/gshell/i18n/MessageSource.java&r1=695140&r2=695221&rev=695221&view=diff
==============================================================================
--- geronimo/gshell/trunk/gshell-support/gshell-i18n/src/main/java/org/apache/geronimo/gshell/i18n/MessageSource.java (original)
+++ geronimo/gshell/trunk/gshell-support/gshell-i18n/src/main/java/org/apache/geronimo/gshell/i18n/PrefixingMessageSource.java Sun Sep 14 06:47:49 2008
@@ -20,13 +20,36 @@
package org.apache.geronimo.gshell.i18n;
/**
- * Provides simple access to i18n messages.
+ * A message source which prefixes message codes.
*
* @version $Rev$ $Date$
*/
-public interface MessageSource
+public class PrefixingMessageSource
+ implements MessageSource
{
- String getMessage(String code);
+ private final MessageSource messages;
- String format(String code, Object... args);
-}
+ private final String prefix;
+
+ public PrefixingMessageSource(final MessageSource messages, final String prefix) {
+ assert messages != null;
+ assert prefix != null;
+
+ this.messages = messages;
+ this.prefix = prefix;
+ }
+
+ protected String createCode(final String code) {
+ assert code != null;
+
+ return prefix + code;
+ }
+
+ public String getMessage(final String code) {
+ return messages.getMessage(createCode(code));
+ }
+
+ public String format(final String code, final Object... args) {
+ return messages.format(createCode(code), args);
+ }
+}
\ No newline at end of file
Propchange: geronimo/gshell/trunk/gshell-support/gshell-i18n/src/main/java/org/apache/geronimo/gshell/i18n/PrefixingMessageSource.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: geronimo/gshell/trunk/gshell-support/gshell-i18n/src/main/java/org/apache/geronimo/gshell/i18n/PrefixingMessageSource.java
------------------------------------------------------------------------------
svn:keywords = Date Author Id Revision HeadURL
Propchange: geronimo/gshell/trunk/gshell-support/gshell-i18n/src/main/java/org/apache/geronimo/gshell/i18n/PrefixingMessageSource.java
------------------------------------------------------------------------------
svn:mergeinfo =
Propchange: geronimo/gshell/trunk/gshell-support/gshell-i18n/src/main/java/org/apache/geronimo/gshell/i18n/PrefixingMessageSource.java
------------------------------------------------------------------------------
svn:mime-type = text/plain
Modified: geronimo/gshell/trunk/gshell-wisdom/gshell-wisdom-core/src/main/java/org/apache/geronimo/gshell/wisdom/command/CommandDocumenterImpl.java
URL: http://svn.apache.org/viewvc/geronimo/gshell/trunk/gshell-wisdom/gshell-wisdom-core/src/main/java/org/apache/geronimo/gshell/wisdom/command/CommandDocumenterImpl.java?rev=695221&r1=695220&r2=695221&view=diff
==============================================================================
--- geronimo/gshell/trunk/gshell-wisdom/gshell-wisdom-core/src/main/java/org/apache/geronimo/gshell/wisdom/command/CommandDocumenterImpl.java (original)
+++ geronimo/gshell/trunk/gshell-wisdom/gshell-wisdom-core/src/main/java/org/apache/geronimo/gshell/wisdom/command/CommandDocumenterImpl.java Sun Sep 14 06:47:49 2008
@@ -25,6 +25,7 @@
import org.apache.geronimo.gshell.command.CommandDocumenter;
import org.apache.geronimo.gshell.command.CommandInfo;
import org.apache.geronimo.gshell.i18n.MessageSource;
+import org.apache.geronimo.gshell.i18n.PrefixingMessageSource;
import java.io.PrintWriter;
@@ -103,7 +104,7 @@
out.println();
Printer printer = new Printer(clp);
- printer.setMessageSource(getContainer().getMessages());
+ printer.setMessageSource(new PrefixingMessageSource(getContainer().getMessages(), "command."));
printer.printUsage(out, name);
out.println();