Title | CommentedProperties |
Date | 12-Jun-2007 16:09:25 EEST |
Version | |
Submitter | 62.97.110.253 |
Bug criticality | MediumBug |
Browser version | |
Bug status | NewBug |
PageProvider used | |
Servlet Container | |
Operating System | |
URL | |
Java version |
Error with similar keys
properties.aKey=value properties.aKey.other=otherValue
The method 'private void writeProperty(Object arg0, Object arg1)' don't see the diference between 'properties.aKey' and 'properties.aKey.other'.
A posible solution: private void writeProperty(Object arg0, Object arg1) { // Get key and value if (arg0 == null) { throw new IllegalArgumentException("Key cannot be null."); } if (arg1 == null) { arg1 = ""; } String key = arg0.toString(); String value = native2Ascii(arg1.toString());
// Iterate through each line and replace anything matching our key int idx = 0; while ((idx < m_propertyString.length()) && ((idx = m_propertyString.indexOf(key, idx)) != -1)) { int prevret = m_propertyString.lastIndexOf("\n", idx); if (prevret != -1) { // Commented lines are skipped if (m_propertyString.charAt(prevret + 1) == '#') { idx += key.length(); continue; } }
// If "=" present, replace everything in line after it int eqsign = m_propertyString.indexOf("=", idx); if (eqsign != -1) { //AFN:The solution String evaluateprop = m_propertyString.substring(idx,eqsign); if(evaluateprop != null && evaluateprop.trim().equals(key)){ //AFN:End of solution int ret = m_propertyString.indexOf("\n", eqsign); if (ret == -1) { ret = m_propertyString.length(); } m_propertyString = replaceString(m_propertyString, eqsign + 1, ret, value); return; }else{ continue; } } }
// If it was not found, we'll add it to the end. m_propertyString += "\n" + key + " = " + value + "\n"; }
Alex Fernández Nogueira alex.fernandez@opentrends.net