Skip to content

Commit

Permalink
remove support for long deprecated delimiter '@'
Browse files Browse the repository at this point in the history
  • Loading branch information
darkv committed Feb 11, 2016
1 parent 6223050 commit a994102
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 42 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -235,7 +235,7 @@ public static class TemplatePool {
//private static final WeakHashMap templates = new WeakHashMap();
private final Map templates = new HashMap();
private static final Logger log = LoggerFactory.getLogger(TemplatePool.class);
private ERXSimpleTemplateParser templateParser = new ERXSimpleTemplateParser("?", false);
private ERXSimpleTemplateParser templateParser = new ERXSimpleTemplateParser();

protected TemplatePool() {}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,6 @@
* {@literal @}{@literal @}, then a possible template might look like: "Hello, {@literal @}{@literal @}name{@literal @}{@literal @}. How are
* you feeling today?", In this case the object will get asked for the
* value name. This works with key-paths as well.
*
* @property er.extensions.ERXSimpleTemplateParser.useOldDelimiter if false, only {@literal @}{@literal @} delimeters are supported (defaults to true)
*/
public class ERXSimpleTemplateParser {

Expand All @@ -36,18 +34,14 @@ public class ERXSimpleTemplateParser {
/** The default delimiter */
public static final String DEFAULT_DELIMITER = "@@";

/** The deprecated delimiter */
@Deprecated
private static final String DEPRECATED_DELIMITER = "@";

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

/** holds a reference to the shared instance of the parser */
private static ERXSimpleTemplateParser _sharedInstance;

/**
* Convience method to return the shared instance
* Convenience method to return the shared instance
* of the template parser.
*
* @return shared instance of the parser
Expand Down Expand Up @@ -79,10 +73,6 @@ public static synchronized void setSharedInstance(ERXSimpleTemplateParser newSha
/** The label that will be appeared where an undefined key is found */
private final String _undefinedKeyLabel;

/** Defines if @ can be used as alternative delimiter */
private Boolean _useOldDelimiter;


/**
* Returns a parser object with the default undefined label
*
Expand All @@ -103,27 +93,6 @@ public ERXSimpleTemplateParser(String undefinedKeyLabel) {
_undefinedKeyLabel = (undefinedKeyLabel == null ? DEFAULT_UNDEFINED_KEY_LABEL : undefinedKeyLabel);
}

/**
* Returns a parser object with the given string as the undefined key label.
* Depending on useOldDelimiter value @ can be used as delimiter if @@ is not present
* in the template.
*
* @param undefinedKeyLabel string as the undefined key label,
* for example, "?", "N/A"
* @param useOldDelimiter boolean defining if @ is used as delimiter if @@ is not available in the template
*/
public ERXSimpleTemplateParser(String undefinedKeyLabel, boolean useOldDelimiter) {
this(undefinedKeyLabel);
_useOldDelimiter = Boolean.valueOf(useOldDelimiter);
}

protected boolean useOldDelimiter() {
if (_useOldDelimiter == null) {
_useOldDelimiter = Boolean.valueOf(ERXProperties.booleanForKeyWithDefault("er.extensions.ERXSimpleTemplateParser.useOldDelimiter", true));
}
return _useOldDelimiter.booleanValue();
}

/**
* Calculates the set of keys used in a given template
* for a given delimiter.
Expand Down Expand Up @@ -210,12 +179,6 @@ public String parseTemplateWithObject(String template, String delimiter, Object
log.debug("Delim: {}", delimiter);
log.debug("otherObject: {}", otherObject);
}
if (useOldDelimiter() && delimiter.equals(DEFAULT_DELIMITER) && template.indexOf(delimiter) < 0 && template.indexOf(DEPRECATED_DELIMITER) >= 0) {
if (!isLoggingDisabled) {
log.warn("It seems that the template string '{}' is using the old delimiter '@' instead of '@@'. I will use '@' for now but you should fix this by updating the template.", template);
}
delimiter = DEPRECATED_DELIMITER;
}
NSArray components = NSArray.componentsSeparatedByString(template, delimiter);
if (! isLoggingDisabled) {
log.debug("Components: {}", components);
Expand Down Expand Up @@ -322,14 +285,14 @@ protected Object doGetValue(String aKeyPath, Object anObject) {
*/
public static String parseTemplatedStringWithObject(String templateString, Object templateObject) {
String convertedValue = templateString;
if (templateString == null || templateString.indexOf("@@") == -1) {
if (templateString == null || templateString.indexOf(DEFAULT_DELIMITER) == -1) {
return templateString;
}

String lastConvertedValue = null;
while (convertedValue != lastConvertedValue && convertedValue.indexOf("@@") > -1) {
while (convertedValue != lastConvertedValue && convertedValue.indexOf(DEFAULT_DELIMITER) > -1) {
lastConvertedValue = convertedValue;
convertedValue = new ERXSimpleTemplateParser("ERXSystem:KEY_NOT_FOUND").parseTemplateWithObject(convertedValue, "@@", templateObject, WOApplication.application());
convertedValue = new ERXSimpleTemplateParser("ERXSystem:KEY_NOT_FOUND").parseTemplateWithObject(convertedValue, DEFAULT_DELIMITER, templateObject, WOApplication.application());
}

// MS: Should we warn here? This is awfully quiet ...
Expand Down

0 comments on commit a994102

Please sign in to comment.