Skip to content
This repository has been archived by the owner on Jan 12, 2021. It is now read-only.

Hackathon changes on 07/19/2014 #59

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -59,19 +59,53 @@ public GUIHierarchyConcatenationProperties(String... files) {
* Concatenation of property names is done from high index to low. That is
* to say, for the array {@code ["a", "b", "c"]}, the names searched will be
* {@code "cba"}, {@code "cb"}, {@code "c"} in that order.
*
*
* @param propertyNames
* names to be concatenated and searched for
* @param parameters
* instances of the {@code String} literal <code>"{n}"</code> in
* the retrieved value will be replaced by {@code params[n]}
* @return the first property found associated with a concatenation of the
* given names
* @throws Exception
*/
public String getPropertyValue(String[] propertyNames) throws Exception {
return getPropertyValue(propertyNames, (String[]) null);
public String getPropertyValue(String[] propertyNames, String... parameters) throws Exception {
// Create possible combinations of property names
String value;
List<String> possiblePropertyName = new ArrayList<String>();
StringBuffer fullName = new StringBuffer();
for (int i = 0; i < propertyNames.length; i++) {
fullName.append(propertyNames[propertyNames.length - i - 1]);
possiblePropertyName.add(fullName.toString());
}

// Try to find the property
for (int i = 0; i < possiblePropertyName.size(); i++) {
String propertyNameCurrent = possiblePropertyName.get(possiblePropertyName.size() - i
- 1);

for (int y = 0; y < propertyFiles.size(); y++) {
try {
GUIProperties propertyFile = propertyFiles.get(y);
if (parameters != null && parameters.length > 0) {
value = propertyFile.getPropertyValue(propertyNameCurrent, parameters);
} else {
value = propertyFile.getPropertyValue(propertyNameCurrent);
}
return value;
} catch (MissingResourceException e) {
// Ignore and continue searching
}
}
}

throw new Exception("Can't find '" + StringUtils.join(possiblePropertyName, ",")
+ "' property(ies) in '" + StringUtils.join(propertyFilesNames, ",")
+ "' property file(s)");
}

/**
* Searches over the group of {@code GUIProperties} for a property list
* Searches over the group of {@code GUIProperties} for a property
* corresponding to a hierarchical concatenation of the given names.
* <p>
* Concatenation of property names is done from high index to low. That is
Expand All @@ -80,18 +114,18 @@ public String getPropertyValue(String[] propertyNames) throws Exception {
*
* @param propertyNames
* names to be concatenated and searched for
* @return the first property list found associated with a concatenation of
* the given names
* @return the first property found associated with a concatenation of the
* given names
* @throws Exception
*/
public List<String> getPropertyValueAsList(String[] propertyNames) throws Exception {
return getPropertyValueAsList(propertyNames, (String[]) null);
public String getPropertyValue(String[] propertyNames) throws Exception {
return getPropertyValue(propertyNames, (String[]) null);
}

/**
* Searches over the group of {@code GUIProperties} for a property
* corresponding to the given name.
*
*
* @param propertyName
* property name to be found
* @return the first property found associated with a concatenation of the
Expand All @@ -106,24 +140,53 @@ public String getPropertyValue(String propertyName) throws Exception {
}

/**
* Searches over the group of {@code GUIProperties} for a property list
* corresponding to the given name.
*
* @param propertyName
* property name to be found
* @return the first property list found associated with a concatenation of
* the given names
* Searches over the group of {@code GUIProperties} for a property
* corresponding to the given key.
*
* @param key
* key to be found
* @param parameters
* instances of the {@code String} literal <code>"{n}"</code> in
* the retrieved value will be replaced by the {@code String}
* representation of {@code params[n]}
* @return the first property found associated with a concatenation of the
* given names
* @throws Exception
*/
public List<String> getPropertyValueAsList(String propertyName) throws Exception {
String[] propertyNames = new String[1];
propertyNames[0] = propertyName;

return getPropertyValueAsList(propertyNames);
public String getPropertyValue(String key, Object[] parameters) throws Exception {
if (parameters != null && parameters.length > 0) {
String parameters2[] = new String[parameters.length];
for (int i = 0; i < parameters.length; i++) {
Object parameter = parameters[i];
if (parameter != null) {
parameters2[i] = String.valueOf(parameter);
}
}
return getPropertyValue(new String[] { key }, parameters2);
} else {
return getPropertyValue(key);
}
}

/**
* Searches over the group of {@code GUIProperties} for a property
* corresponding to the given key.
*
* @param key
* key to be found
* @param parameters
* instances of the {@code String} literal <code>"{n}"</code> in
* the retrieved value will be replaced by {@code params[n]}
* @return the first property found associated with a concatenation of the
* given names
* @throws Exception
*/
public String getPropertyValue(String key, String... parameters) throws Exception {
return getPropertyValue(new String[] { key }, parameters);
}

/**
* Searches over the group of {@code GUIProperties} for a property list
* corresponding to a hierarchical concatenation of the given names.
* <p>
* Concatenation of property names is done from high index to low. That is
Expand All @@ -132,46 +195,29 @@ public List<String> getPropertyValueAsList(String propertyName) throws Exception
*
* @param propertyNames
* names to be concatenated and searched for
* @param parameters
* instances of the {@code String} literal <code>"{n}"</code> in
* the retrieved value will be replaced by {@code params[n]}
* @return the first property found associated with a concatenation of the
* given names
* @return the first property list found associated with a concatenation of
* the given names
* @throws Exception
*/
public String getPropertyValue(String[] propertyNames, String... parameters) throws Exception {
// Create possible combinations of property names
String value;
List<String> possiblePropertyName = new ArrayList<String>();
StringBuffer fullName = new StringBuffer();
for (int i = 0; i < propertyNames.length; i++) {
fullName.append(propertyNames[propertyNames.length - i - 1]);
possiblePropertyName.add(fullName.toString());
}

// Try to find the property
for (int i = 0; i < possiblePropertyName.size(); i++) {
String propertyNameCurrent = possiblePropertyName.get(possiblePropertyName.size() - i
- 1);
public List<String> getPropertyValueAsList(String[] propertyNames, String delimiter) throws Exception {
return getPropertyValueAsList(propertyNames,delimiter, (String[]) null);
}

for (int y = 0; y < propertyFiles.size(); y++) {
try {
GUIProperties propertyFile = propertyFiles.get(y);
if (parameters != null && parameters.length > 0) {
value = propertyFile.getPropertyValue(propertyNameCurrent, parameters);
} else {
value = propertyFile.getPropertyValue(propertyNameCurrent);
}
return value;
} catch (MissingResourceException e) {
// Ignore and continue searching
}
}
}
/**
* Searches over the group of {@code GUIProperties} for a property list
* corresponding to the given name.
*
* @param propertyName
* property name to be found
* @return the first property list found associated with a concatenation of
* the given names
* @throws Exception
*/
public List<String> getPropertyValueAsList(String propertyName, String delimiter) throws Exception {
String[] propertyNames = new String[1];
propertyNames[0] = propertyName;

throw new Exception("Can't find '" + StringUtils.join(possiblePropertyName, ",")
+ "' property(ies) in '" + StringUtils.join(propertyFilesNames, ",")
+ "' property file(s)");
return getPropertyValueAsList(propertyNames,delimiter);
}

/**
Expand All @@ -191,7 +237,7 @@ public String getPropertyValue(String[] propertyNames, String... parameters) thr
* the given names
* @throws Exception
*/
public List<String> getPropertyValueAsList(String[] propertyNames, String... parameters)
public List<String> getPropertyValueAsList(String[] propertyNames, String delimiter, String... parameters)
throws Exception {
// Create possible combinations of property names
List<String> value;
Expand All @@ -212,9 +258,9 @@ public List<String> getPropertyValueAsList(String[] propertyNames, String... par
GUIProperties propertyFile = propertyFiles.get(y);
if (parameters != null && parameters.length > 0) {
value = propertyFile
.getPropertyValueAsList(propertyNameCurrent, parameters);
.getPropertyValueAsList(propertyNameCurrent,delimiter, parameters);
} else {
value = propertyFile.getPropertyValueAsList(propertyNameCurrent);
value = propertyFile.getPropertyValueAsList(propertyNameCurrent,delimiter);
}
return value;
} catch (MissingResourceException e) {
Expand All @@ -228,23 +274,6 @@ public List<String> getPropertyValueAsList(String[] propertyNames, String... par
+ "' property file(s)");
}

/**
* Searches over the group of {@code GUIProperties} for a property
* corresponding to the given key.
*
* @param key
* key to be found
* @param parameters
* instances of the {@code String} literal <code>"{n}"</code> in
* the retrieved value will be replaced by {@code params[n]}
* @return the first property found associated with a concatenation of the
* given names
* @throws Exception
*/
public String getPropertyValue(String key, String... parameters) throws Exception {
return getPropertyValue(new String[] { key }, parameters);
}

/**
* Searches over the group of {@code GUIProperties} for a property list
* corresponding to the given key.
Expand All @@ -258,37 +287,8 @@ public String getPropertyValue(String key, String... parameters) throws Exceptio
* the given names
* @throws Exception
*/
public List<String> getPropertyValueAsList(String key, String... parameters) throws Exception {
return getPropertyValueAsList(new String[] { key }, parameters);
}

/**
* Searches over the group of {@code GUIProperties} for a property
* corresponding to the given key.
*
* @param key
* key to be found
* @param parameters
* instances of the {@code String} literal <code>"{n}"</code> in
* the retrieved value will be replaced by the {@code String}
* representation of {@code params[n]}
* @return the first property found associated with a concatenation of the
* given names
* @throws Exception
*/
public String getPropertyValue(String key, Object[] parameters) throws Exception {
if (parameters != null && parameters.length > 0) {
String parameters2[] = new String[parameters.length];
for (int i = 0; i < parameters.length; i++) {
Object parameter = parameters[i];
if (parameter != null) {
parameters2[i] = String.valueOf(parameter);
}
}
return getPropertyValue(new String[] { key }, parameters2);
} else {
return getPropertyValue(key);
}
public List<String> getPropertyValueAsList(String key, String delimiter, String... parameters) throws Exception {
return getPropertyValueAsList(new String[] { key }, delimiter, parameters);
}

/**
Expand All @@ -305,7 +305,7 @@ public String getPropertyValue(String key, Object[] parameters) throws Exception
* the given names
* @throws Exception
*/
public List<String> getPropertyValueAsList(String key, Object[] parameters) throws Exception {
public List<String> getPropertyValueAsList(String key,String delimiter, Object[] parameters) throws Exception {
if (parameters != null && parameters.length > 0) {
String parameters2[] = new String[parameters.length];
for (int i = 0; i < parameters.length; i++) {
Expand All @@ -314,9 +314,9 @@ public List<String> getPropertyValueAsList(String key, Object[] parameters) thro
parameters2[i] = String.valueOf(parameter);
}
}
return getPropertyValueAsList(new String[] { key }, parameters2);
return getPropertyValueAsList(new String[] { key },delimiter, parameters2);
} else {
return getPropertyValueAsList(key);
return getPropertyValueAsList(key, delimiter);
}
}
}
48 changes: 39 additions & 9 deletions src/main/java/org/finra/jtaf/ewd/properties/GUIProperties.java
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,24 @@ private String getString(String key, Object params[]) throws Exception {
}
}

private String getStringOrDefault(String key, Object params[]) throws Exception {
String defaultValue = "Default value";
try {
if ((params != null) && (params.length > 0)) {
defaultValue = MessageFormat.format(RESOURCE_BUNDLE.getString(key), params).trim();
} else {
defaultValue = RESOURCE_BUNDLE.getString(key).trim();
}
} catch (MissingResourceException e) {
throw e;
} catch (IllegalArgumentException ie) {
throw ie;
}
finally {
return defaultValue;
}
}

/**
* Retrieves the property associated with the given key as a {@code String}.
*
Expand All @@ -101,6 +119,22 @@ public String getPropertyValue(String key, String... params) throws Exception {
return getString(key, params);
}

/**
* Retrieves the property associated with the given key as a {@code String}.
*
* @param key
* the key to be retrieved
* @param params
* instances of the {@code String} literal <code>"{n}"</code> in
* the retrieved value will be replaced by {@code params[n]}
* @return the parameterized property associated with the given key, o
* If no value is found, it return "default value" string;
* @throws Exception
*/
public String getPropertyValueOrDefault(String key, String... params) throws Exception {
return getStringOrDefault(key, params);
}

/**
* Retrieves the property associated with the given key as a {@code List} of
* {@code String}s.
Expand All @@ -113,18 +147,14 @@ public String getPropertyValue(String key, String... params) throws Exception {
* @return the parameterized property list associated with the given key
* @throws Exception
*/
public List<String> getPropertyValueAsList(String key, String... params) throws Exception {
public List<String> getPropertyValueAsList(String key, String delimiter, String... params) throws Exception {
try {
String properties[] = RESOURCE_BUNDLE.getStringArray(key);
if ((params != null) && (params.length > 0)) {
List<String> returnProperties = new ArrayList<String>();
for (String property : properties) {
returnProperties.add(MessageFormat.format(property, (Object[]) params).trim());
}
return returnProperties;
} else {
String properties[] = getString(key, params).split(delimiter);
if (properties.length > 0) {
return Arrays.asList(properties);
}
else
return null;
} catch (MissingResourceException e) {
throw e;
} catch (IllegalArgumentException ie) {
Expand Down
Loading