Skip to content

Commit

Permalink
Adds log warning to parseTemplatedStringWithObject().
Browse files Browse the repository at this point in the history
Mike Schrag wrote in a comment here, long ago: "Should we warn here?
This is awfully quiet..." Yes it is, and yes we should. I am tired of
scratching my head at unmodified templates. Adding a LOG.warn() here
seems like the least we should do.

(Also changes 'log' to 'LOG' by convention for a public static final
variable.)
  • Loading branch information
paulhoadley committed Apr 21, 2016
1 parent 6ba70a6 commit d605d00
Showing 1 changed file with 13 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ public class ERXSimpleTemplateParser {
public static final String DEFAULT_DELIMITER = "@@";

/** logging support */
private static final Logger log = LoggerFactory.getLogger(ERXSimpleTemplateParser.class);
private static final Logger LOG = LoggerFactory.getLogger(ERXSimpleTemplateParser.class);

/** holds a reference to the shared instance of the parser */
private static ERXSimpleTemplateParser _sharedInstance;
Expand Down Expand Up @@ -108,7 +108,7 @@ public NSArray keysInTemplate(String template, String delimiter) {
}
NSArray components = NSArray.componentsSeparatedByString(template, delimiter);
if (! isLoggingDisabled) {
log.debug("Components: {}", components);
LOG.debug("Components: {}", components);
}
boolean deriveElement = false; // if the template starts with delim, the first component will be a zero-length string
for (Enumeration e = components.objectEnumerator(); e.hasMoreElements();) {
Expand Down Expand Up @@ -174,14 +174,14 @@ public String parseTemplateWithObject(String template, String delimiter, Object
delimiter = DEFAULT_DELIMITER;
}
if (! isLoggingDisabled) {
log.debug("Parsing template: {} with delimiter: {} object: {}",template, delimiter, object);
log.debug("Template: {}", template);
log.debug("Delim: {}", delimiter);
log.debug("otherObject: {}", otherObject);
LOG.debug("Parsing template: {} with delimiter: {} object: {}",template, delimiter, object);
LOG.debug("Template: {}", template);
LOG.debug("Delim: {}", delimiter);
LOG.debug("otherObject: {}", otherObject);
}
NSArray components = NSArray.componentsSeparatedByString(template, delimiter);
if (! isLoggingDisabled) {
log.debug("Components: {}", components);
LOG.debug("Components: {}", components);
}
boolean deriveElement = false; // if the template starts with delim, the first component will be a zero-length string
StringBuilder sb = new StringBuilder();
Expand All @@ -194,11 +194,11 @@ public String parseTemplateWithObject(String template, String delimiter, Object
for (Enumeration e = components.objectEnumerator(); e.hasMoreElements();) {
String element = (String)e.nextElement();
if(!isLoggingDisabled) {
log.debug("Processing Element: {}", element);
LOG.debug("Processing Element: {}", element);
}
if(deriveElement) {
if(!isLoggingDisabled) {
log.debug("Deriving value ...");
LOG.debug("Deriving value ...");
}
if(element.length() == 0) {
throw new IllegalArgumentException("\"\" is not a valid keypath in template: " + template);
Expand All @@ -209,7 +209,7 @@ public String parseTemplateWithObject(String template, String delimiter, Object
if(o != null && result == _undefinedKeyLabel) {
try {
if(!isLoggingDisabled) {
log.debug("calling valueForKeyPath({}, {})", o, element);
LOG.debug("calling valueForKeyPath({}, {})", o, element);
}
result = doGetValue(element, o);
// For just in case the above doesn't throw an exception when the
Expand All @@ -229,7 +229,7 @@ public String parseTemplateWithObject(String template, String delimiter, Object
}
if(result == _undefinedKeyLabel) {
if (!isLoggingDisabled) {
log.debug("Could not find a value for '{}' of template, '{}' in either the object or extra data.", element, template);
LOG.debug("Could not find a value for '{}' of template, '{}' in either the object or extra data.", element, template);
}
}
sb.append(result.toString());
Expand All @@ -241,7 +241,7 @@ public String parseTemplateWithObject(String template, String delimiter, Object
deriveElement = true;
}
if(!isLoggingDisabled) {
log.debug("Buffer: {}", sb);
LOG.debug("Buffer: {}", sb);
}
}
return sb.toString();
Expand Down Expand Up @@ -295,8 +295,8 @@ public static String parseTemplatedStringWithObject(String templateString, Objec
convertedValue = new ERXSimpleTemplateParser("ERXSystem:KEY_NOT_FOUND").parseTemplateWithObject(convertedValue, DEFAULT_DELIMITER, templateObject, WOApplication.application());
}

// MS: Should we warn here? This is awfully quiet ...
if (convertedValue.indexOf("ERXSystem:KEY_NOT_FOUND") > -1) {
LOG.warn("Not all keys in templateString were present in templateObject, returning unmodified templateString.");
return templateString; // not all keys are present
}

Expand Down

0 comments on commit d605d00

Please sign in to comment.