public String parseTemplateWithObject(String template, String delimiter, Object object, Object otherObject) { if (template == null) throw new RuntimeException("Attempting to parse null template!"); if (object == null) throw new RuntimeException("Attempting to parse template with null object!"); if(delimiter == null) delimiter = "@@"; if (! isLoggingDisabled  &&  log.isDebugEnabled()) { log.debug("Parsing template: " + template + " with delimiter: " + delimiter + " object: " + object); log.debug("Template: " + template); log.debug("Delim: " + delimiter); log.debug("otherObject: " + otherObject); } StringBuffer buffer = new StringBuffer(); boolean deriveElement = false; NSArray components = NSArray.componentsSeparatedByString(template, delimiter); if (! isLoggingDisabled  &&  log.isDebugEnabled()) log.debug("Components: " + components); for (Enumeration e = components.objectEnumerator(); e.hasMoreElements();) { String element = (String)e.nextElement(); if (! isLoggingDisabled)  log.debug("Processing Element: " + element); if (deriveElement) { if (! isLoggingDisabled)  log.debug("Deriving value ..."); if (element.length() == 0) throw new RuntimeException("\"\" is not a valid keypath in template: " + template); Object obj; try { obj = NSKeyValueCodingAdditions.Utility.valueForKeyPath(object, element);   if (obj == null  &&  otherObject != null) throw new NSKeyValueCoding.UnknownKeyException("The key is not defined in the object.", null, element); } catch (Throwable t) { try { if (otherObject != null) { obj = NSKeyValueCodingAdditions.Utility.valueForKeyPath(otherObject, element); } else { throw new RuntimeException("Could not find a value for \"" + element + "\" of a template in either the object or extra data: " + t.getMessage()); } } catch (Throwable t1) { throw new RuntimeException("An exception occured while parsing element, " + element + ", of template, " + template + ": " + t1.getMessage()); } } buffer.append(obj == null ? _undefinedKeyLabel : obj.toString()); deriveElement = false; } else { if (element.length() > 0) buffer.append(element); deriveElement = true; } if (! isLoggingDisabled  && log.isDebugEnabled()) log.debug("Buffer: " + buffer); } return buffer.toString();
public String parseTemplateWithObject(String template, String delimiter, Object object) { return parseTemplateWithObject(template, delimiter, object, null);
    public String parseTemplateWithObject(String template, String delimiter, Object object, Object otherObject) {        if (template == null)            throw new RuntimeException("Attempting to parse null template!");        if (object == null)            throw new RuntimeException("Attempting to parse template with null object!");        if(delimiter == null) delimiter = "@@";        if (! isLoggingDisabled  &&  log.isDebugEnabled()) {            log.debug("Parsing template: " + template + " with delimiter: " + delimiter + " object: " + object);            log.debug("Template: " + template);            log.debug("Delim: " + delimiter);            log.debug("otherObject: " + otherObject);        }        StringBuffer buffer = new StringBuffer();        boolean deriveElement = false; // if the template starts with delim, the first component will be a zero-length string        NSArray components = NSArray.componentsSeparatedByString(template, delimiter);        if (! isLoggingDisabled  &&  log.isDebugEnabled())            log.debug("Components: " + components);        for (Enumeration e = components.objectEnumerator(); e.hasMoreElements();) {            String element = (String)e.nextElement();            if (! isLoggingDisabled)  log.debug("Processing Element: " + element);            if (deriveElement) {                if (! isLoggingDisabled)  log.debug("Deriving value ...");                if (element.length() == 0)                    throw new RuntimeException("\"\" is not a valid keypath in template: " + template);                Object obj;                try {                    obj = NSKeyValueCodingAdditions.Utility.valueForKeyPath(object, element);                     // For just in case the above doesn't throw an exception when the                     // key is not defined. (NSDictionary doesn't seem to throw the exception.)                    if (obj == null  &&  otherObject != null)                        throw new NSKeyValueCoding.UnknownKeyException("The key is not defined in the object.", null, element);               } catch (Throwable t) {                    try {                        if (otherObject != null) {                            obj = NSKeyValueCodingAdditions.Utility.valueForKeyPath(otherObject, element);                        } else {                            throw new RuntimeException("Could not find a value for \"" + element + "\" of a template in either the object or extra data: " + t.getMessage());                        }                    } catch (Throwable t1) {                        throw new RuntimeException("An exception occured while parsing element, " + element + ", of template, " + template + ": " + t1.getMessage());                    }                }                buffer.append(obj == null ? _undefinedKeyLabel : obj.toString());                                deriveElement = false;            } else {                if (element.length() > 0)                    buffer.append(element);                deriveElement = true;            }            if (! isLoggingDisabled  && log.isDebugEnabled())                log.debug("Buffer: " + buffer);        }        return buffer.toString();    }