You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@commons.apache.org by jk...@apache.org on 2003/10/24 01:09:15 UTC
cvs commit: jakarta-commons-sandbox/cli/src/java/org/apache/commons/cli2/resources ResourceHelper.java
jkeyes 2003/10/23 16:09:15
Modified: cli/src/java/org/apache/commons/cli2
BadPropertyException.java
MissingValueException.java
MissingOptionException.java OptionException.java
UnexpectedOptionException.java
UnexpectedValueException.java BurstException.java
Added: cli/src/java/org/apache/commons/cli2
MessagesBundle.properties
cli/src/java/org/apache/commons/cli2/resources
ResourceHelper.java
Log:
- WIP i18n work
Revision Changes Path
1.2 +89 -82 jakarta-commons-sandbox/cli/src/java/org/apache/commons/cli2/BadPropertyException.java
Index: BadPropertyException.java
===================================================================
RCS file: /home/cvs/jakarta-commons-sandbox/cli/src/java/org/apache/commons/cli2/BadPropertyException.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- BadPropertyException.java 18 Oct 2003 22:00:04 -0000 1.1
+++ BadPropertyException.java 23 Oct 2003 23:09:15 -0000 1.2
@@ -1,82 +1,89 @@
-/*
- * $Header$
- * $Revision$
- * $Date$
- *
- * ====================================================================
- *
- * The Apache Software License, Version 1.1
- *
- * Copyright (c) 2003 The Apache Software Foundation. All rights
- * reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- *
- * 1. Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- *
- * 2. Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in
- * the documentation and/or other materials provided with the
- * distribution.
- *
- * 3. The end-user documentation included with the redistribution, if
- * any, must include the following acknowlegement:
- * "This product includes software developed by the
- * Apache Software Foundation (http://www.apache.org/)."
- * Alternately, this acknowlegement may appear in the software itself,
- * if and wherever such third-party acknowlegements normally appear.
- *
- * 4. The names "The Jakarta Project", "Commons", and "Apache Software
- * Foundation" must not be used to endorse or promote products derived
- * from this software without prior written permission. For written
- * permission, please contact apache@apache.org.
- *
- * 5. Products derived from this software may not be called "Apache"
- * nor may "Apache" appear in their names without prior written
- * permission of the Apache GroupImpl.
- *
- * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
- * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
- * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
- * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
- * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
- * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
- * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
- * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
- * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
- * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
- * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
- * SUCH DAMAGE.
- * ====================================================================
- *
- * This software consists of voluntary contributions made by many
- * individuals on behalf of the Apache Software Foundation. For more
- * information on the Apache Software Foundation, please see
- * <http://www.apache.org/>.
- *
- */
-package org.apache.commons.cli2;
-
-/**
- * Thrown if a PropertyOption failed to parse a property correctly.
- * @author Rob Oxspring
- */
-public class BadPropertyException extends OptionException {
- private final String value;
-
- public BadPropertyException(final Option option, final String value) {
- super(option);
- this.value = value;
- }
-
- public String getMessage() {
- final StringBuffer buffer = new StringBuffer();
- buffer.append("Could not understand property: ");
- buffer.append(value);
- return buffer.toString();
- }
-
-}
+/*
+ * $Header$
+ * $Revision$
+ * $Date$
+ *
+ * ====================================================================
+ *
+ * The Apache Software License, Version 1.1
+ *
+ * Copyright (c) 2003 The Apache Software Foundation. All rights
+ * reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ *
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in
+ * the documentation and/or other materials provided with the
+ * distribution.
+ *
+ * 3. The end-user documentation included with the redistribution, if
+ * any, must include the following acknowlegement:
+ * "This product includes software developed by the
+ * Apache Software Foundation (http://www.apache.org/)."
+ * Alternately, this acknowlegement may appear in the software itself,
+ * if and wherever such third-party acknowlegements normally appear.
+ *
+ * 4. The names "The Jakarta Project", "Commons", and "Apache Software
+ * Foundation" must not be used to endorse or promote products derived
+ * from this software without prior written permission. For written
+ * permission, please contact apache@apache.org.
+ *
+ * 5. Products derived from this software may not be called "Apache"
+ * nor may "Apache" appear in their names without prior written
+ * permission of the Apache GroupImpl.
+ *
+ * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
+ * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
+ * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
+ * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
+ * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
+ * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
+ * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ * ====================================================================
+ *
+ * This software consists of voluntary contributions made by many
+ * individuals on behalf of the Apache Software Foundation. For more
+ * information on the Apache Software Foundation, please see
+ * <http://www.apache.org/>.
+ *
+ */
+package org.apache.commons.cli2;
+
+import org.apache.commons.cli2.resources.ResourceHelper;
+
+/**
+ * Thrown if a PropertyOption failed to parse a property correctly.
+ * @author Rob Oxspring
+ */
+public class BadPropertyException extends OptionException {
+ private final String value;
+
+ /** resource helper instance */
+ private static final ResourceHelper helper =
+ ResourceHelper.getResourceHelper(BadPropertyException.class);
+
+ public BadPropertyException(final Option option, final String value) {
+ super(option);
+ this.value = value;
+ }
+
+ public String getMessage() {
+ final StringBuffer buffer = new StringBuffer();
+
+ buffer.append(helper.getMessage("cli.error.badproperty", value));
+
+ return buffer.toString();
+ }
+
+}
1.4 +15 -7 jakarta-commons-sandbox/cli/src/java/org/apache/commons/cli2/MissingValueException.java
Index: MissingValueException.java
===================================================================
RCS file: /home/cvs/jakarta-commons-sandbox/cli/src/java/org/apache/commons/cli2/MissingValueException.java,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -r1.3 -r1.4
--- MissingValueException.java 22 Oct 2003 16:32:14 -0000 1.3
+++ MissingValueException.java 23 Oct 2003 23:09:15 -0000 1.4
@@ -60,21 +60,29 @@
*/
package org.apache.commons.cli2;
+import org.apache.commons.cli2.resources.ResourceHelper;
+
/**
* @author Rob Oxspring
- *
- * To change the template for this generated type comment go to
- * Window>Preferences>Java>Code Generation>Code and Comments
*/
public class MissingValueException extends OptionException {
+
+ /** resource helper instance */
+ private static final ResourceHelper helper =
+ ResourceHelper.getResourceHelper(MissingValueException.class);
+
public MissingValueException(final Option option) {
super(option);
}
public String getMessage() {
final StringBuffer buffer = new StringBuffer();
- buffer.append("Missing value(s) ");
+
+ buffer.append(helper.getMessage("cli.error.missing.values"));
+ buffer.append(" ");
+
option.appendUsage(buffer, HELP_SETTINGS, null);
+
return buffer.toString();
}
}
1.3 +15 -4 jakarta-commons-sandbox/cli/src/java/org/apache/commons/cli2/MissingOptionException.java
Index: MissingOptionException.java
===================================================================
RCS file: /home/cvs/jakarta-commons-sandbox/cli/src/java/org/apache/commons/cli2/MissingOptionException.java,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -r1.2 -r1.3
--- MissingOptionException.java 22 Oct 2003 16:32:14 -0000 1.2
+++ MissingOptionException.java 23 Oct 2003 23:09:15 -0000 1.3
@@ -60,18 +60,29 @@
*/
package org.apache.commons.cli2;
+import org.apache.commons.cli2.resources.ResourceHelper;
+
/**
* @author Rob Oxspring
*/
public class MissingOptionException extends OptionException {
+
+ /** resource helper instance */
+ private static final ResourceHelper helper =
+ ResourceHelper.getResourceHelper(MissingOptionException.class);
+
public MissingOptionException(final Option option) {
super(option);
}
public String getMessage() {
final StringBuffer buffer = new StringBuffer();
- buffer.append("Missing option ");
+
+ buffer.append(helper.getMessage("cli.error.missing.option"));
+ buffer.append(" ");
+
option.appendUsage(buffer, HELP_SETTINGS, null);
+
return buffer.toString();
}
}
1.3 +3 -4 jakarta-commons-sandbox/cli/src/java/org/apache/commons/cli2/OptionException.java
Index: OptionException.java
===================================================================
RCS file: /home/cvs/jakarta-commons-sandbox/cli/src/java/org/apache/commons/cli2/OptionException.java,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -r1.2 -r1.3
--- OptionException.java 22 Oct 2003 16:32:14 -0000 1.2
+++ OptionException.java 23 Oct 2003 23:09:15 -0000 1.3
@@ -61,7 +61,6 @@
package org.apache.commons.cli2;
import java.util.Collections;
-import java.util.Comparator;
import java.util.HashSet;
import java.util.Set;
1.3 +23 -6 jakarta-commons-sandbox/cli/src/java/org/apache/commons/cli2/UnexpectedOptionException.java
Index: UnexpectedOptionException.java
===================================================================
RCS file: /home/cvs/jakarta-commons-sandbox/cli/src/java/org/apache/commons/cli2/UnexpectedOptionException.java,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -r1.2 -r1.3
--- UnexpectedOptionException.java 22 Oct 2003 16:32:14 -0000 1.2
+++ UnexpectedOptionException.java 23 Oct 2003 23:09:15 -0000 1.3
@@ -60,6 +60,8 @@
*/
package org.apache.commons.cli2;
+import org.apache.commons.cli2.resources.ResourceHelper;
+
/**
* @author Rob Oxspring
*/
@@ -68,9 +70,14 @@
private final Option unexpected;
private final String argument;
+ /** resource helper instance */
+ private static final ResourceHelper helper =
+ ResourceHelper.getResourceHelper(UnexpectedOptionException.class);
+
public UnexpectedOptionException(
final Option option,
final Option unexpected) {
+
super(option);
this.unexpected = unexpected;
this.argument = null;
@@ -79,6 +86,7 @@
public UnexpectedOptionException(
final Option option,
final String argument) {
+
super(option);
this.unexpected = null;
this.argument = argument;
@@ -86,15 +94,24 @@
public String getMessage() {
final StringBuffer buffer = new StringBuffer();
- buffer.append("Unexpected ");
+
+ buffer.append(helper.getMessage("cli.error.unexpected"));
+ buffer.append(" ");
+
if (unexpected != null) {
unexpected.appendUsage(buffer, HELP_SETTINGS, null);
}
+
if (argument != null) {
buffer.append(argument);
}
- buffer.append(" while processing ");
+
+ buffer.append(" ");
+ buffer.append(helper.getMessage("cli.error.processing"));
+ buffer.append(" ");
+
option.appendUsage(buffer, HELP_SETTINGS, null);
- return buffer.toString();
+
+ return buffer.toString();
}
}
1.3 +17 -5 jakarta-commons-sandbox/cli/src/java/org/apache/commons/cli2/UnexpectedValueException.java
Index: UnexpectedValueException.java
===================================================================
RCS file: /home/cvs/jakarta-commons-sandbox/cli/src/java/org/apache/commons/cli2/UnexpectedValueException.java,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -r1.2 -r1.3
--- UnexpectedValueException.java 22 Oct 2003 16:32:14 -0000 1.2
+++ UnexpectedValueException.java 23 Oct 2003 23:09:15 -0000 1.3
@@ -60,6 +60,8 @@
*/
package org.apache.commons.cli2;
+import org.apache.commons.cli2.resources.ResourceHelper;
+
/**
* @author Rob Oxspring
*
@@ -67,18 +69,28 @@
* Window>Preferences>Java>Code Generation>Code and Comments
*/
public class UnexpectedValueException extends OptionException {
- private final String argument;
+ /** argument value */
+ private final String argument;
+
+ /** resource helper instance */
+ private static final ResourceHelper helper =
+ ResourceHelper.getResourceHelper(UnexpectedValueException.class);
+
public UnexpectedValueException(
final Option option,
final String argument) {
+
super(option);
this.argument = argument;
}
public String getMessage() {
final StringBuffer buffer = new StringBuffer();
- buffer.append("Unexpected value " + argument + " while processing ");
+
+ buffer.append(
+ helper.getMessage("cli.error.unexpected.value", argument));
+
option.appendUsage(buffer, HELP_SETTINGS, null);
return buffer.toString();
}
1.3 +14 -4 jakarta-commons-sandbox/cli/src/java/org/apache/commons/cli2/BurstException.java
Index: BurstException.java
===================================================================
RCS file: /home/cvs/jakarta-commons-sandbox/cli/src/java/org/apache/commons/cli2/BurstException.java,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -r1.2 -r1.3
--- BurstException.java 22 Oct 2003 16:32:14 -0000 1.2
+++ BurstException.java 23 Oct 2003 23:09:15 -0000 1.3
@@ -60,13 +60,20 @@
*/
package org.apache.commons.cli2;
+import org.apache.commons.cli2.resources.ResourceHelper;
+
/**
* Thrown when a DefaultOption fails to burst options correctly.
* @author Rob Oxspring
*/
public class BurstException extends OptionException {
+
private final String value;
+ /** resource helper instance */
+ private static final ResourceHelper helper =
+ ResourceHelper.getResourceHelper(BurstException.class);
+
public BurstException(final Option option, final String value) {
super(option);
this.value = value;
@@ -74,8 +81,11 @@
public String getMessage() {
final StringBuffer buffer = new StringBuffer();
- buffer.append("Could not burst " + value + " while processing ");
+
+ buffer.append(helper.getMessage("cli.error.burst", value));
+
option.appendUsage(buffer, HELP_SETTINGS, null);
+
return buffer.toString();
}
}
1.1 jakarta-commons-sandbox/cli/src/java/org/apache/commons/cli2/MessagesBundle.properties
Index: MessagesBundle.properties
===================================================================
cli.error.unexpected.value = Unexpected value "{0}" found while processing
cli.error.unexpected = Unexpected
cli.error.processing = while processing
cli.error.missing.values = Missing value(s)
cli.error.burst = Could not burst "{0}" while processing
cli.error.badproperty = Could not understand property: {0}
1.1 jakarta-commons-sandbox/cli/src/java/org/apache/commons/cli2/resources/ResourceHelper.java
Index: ResourceHelper.java
===================================================================
/*
* $Header: /home/cvs/jakarta-commons-sandbox/cli/src/java/org/apache/commons/cli2/resources/ResourceHelper.java,v 1.1 2003/10/23 23:09:15 jkeyes Exp $
* $Revision: 1.1 $
* $Date: 2003/10/23 23:09:15 $
*
* ====================================================================
*
* The Apache Software License, Version 1.1
*
* Copyright (c) 2003 The Apache Software Foundation. All rights
* reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* 3. The end-user documentation included with the redistribution, if
* any, must include the following acknowlegement:
* "This product includes software developed by the
* Apache Software Foundation (http://www.apache.org/)."
* Alternately, this acknowlegement may appear in the software itself,
* if and wherever such third-party acknowlegements normally appear.
*
* 4. The names "The Jakarta Project", "Commons", and "Apache Software
* Foundation" must not be used to endorse or promote products derived
* from this software without prior written permission. For written
* permission, please contact apache@apache.org.
*
* 5. Products derived from this software may not be called "Apache"
* nor may "Apache" appear in their names without prior written
* permission of the Apache GroupImpl.
*
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
* ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
* USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
* ====================================================================
*
* This software consists of voluntary contributions made by many
* individuals on behalf of the Apache Software Foundation. For more
* information on the Apache Software Foundation, please see
* <http://www.apache.org/>.
*
*/
package org.apache.commons.cli2.resources;
import java.text.MessageFormat;
import java.util.HashMap;
import java.util.Map;
import java.util.ResourceBundle;
/**
* @author John Keyes
*/
public class ResourceHelper {
/** resource bundle */
private ResourceBundle bundle;
/** cache */
private static Map cache = new HashMap(13);
public static ResourceHelper getResourceHelper(final Class clazz) {
if (cache.containsKey(clazz)) {
return (ResourceHelper) cache.get(clazz);
}
return new ResourceHelper(clazz);
}
/**
* Create a new ResourceHelper for the specified class.
*
* @param clazz
* the Class that requires some resources
*/
private ResourceHelper(final Class clazz) {
// get the name of the class
final String className = clazz.getName();
// discover the package name
final String packageName =
className.substring(0, className.lastIndexOf(".") + 1);
final String bundleName =
packageName + "MessagesBundle";
// initialize the bundle
bundle = ResourceBundle.getBundle(bundleName);
// cache bundle
cache.put(bundleName, bundle);
}
/**
* Returns the message for the specified key.
*
* @param key
* the unique identifier of the message
*
* @return String
* the formatted String
*/
public String getMessage(final String key) {
return getMessage(
key,
new Object[] {
}
);
}
/**
* Returns the message for the specified key and argument.
*
* @param key
* the unique identifier of the message
*
* @param value
* the argument value
*
* @return String
* the formatted String
*/
public String getMessage(
final String key,
final Object value) {
return getMessage(
key,
new Object[] {
value
}
);
}
/**
* Returns the message for the specified key and arguments.
*
* @param key
* the unique identifier of the message
*
* @param value1
* an argument value
*
* @param value2
* an argument value
*
* @return String
* the formatted String
*/
public String getMessage(
final String key,
final Object value1,
final Object value2) {
return getMessage(
key,
new Object[] {
value1,
value2
}
);
}
/**
* Returns the message for the specified key and arguments.
*
* @param key
* the unique identifier of the message
*
* @param value1
* an argument value
*
* @param value2
* an argument value
*
* @param value3
* an argument value
*
* @return String
* the formatted String
*/
public String getMessage(
final String key,
final Object value1,
final Object value2,
final Object value3) {
return getMessage(
key,
new Object[] {
value1,
value2,
value3
}
);
}
/**
* Returns the message for the specified key and arguments.
*
* @param key
* the unique identifier of the message
*
* @param values
* argument values
*
* @return String
* the formatted String
*/
public String getMessage(
final String key,
final Object[] values) {
final String msgFormatStr = bundle.getString(key);
final MessageFormat msgFormat = new MessageFormat(msgFormatStr);
return msgFormat.format((Object) values);
}
}
---------------------------------------------------------------------
To unsubscribe, e-mail: commons-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: commons-dev-help@jakarta.apache.org