1 16 17 package org.springframework.core.io; 18 19 import java.beans.PropertyEditorSupport ; 20 21 import org.apache.commons.logging.Log; 22 import org.apache.commons.logging.LogFactory; 23 24 37 public class AbstractPathResolvingPropertyEditor extends PropertyEditorSupport { 38 39 public static final String PLACEHOLDER_PREFIX = "${"; 40 41 public static final String PLACEHOLDER_SUFFIX = "}"; 42 43 protected static final Log logger = LogFactory.getLog(AbstractPathResolvingPropertyEditor.class); 44 45 53 protected String resolvePath(String path) { 54 StringBuffer buf = new StringBuffer (path); 55 56 60 int startIndex = path.indexOf(PLACEHOLDER_PREFIX); 61 while (startIndex != -1) { 62 int endIndex = buf.toString().indexOf(PLACEHOLDER_SUFFIX, startIndex + PLACEHOLDER_PREFIX.length()); 63 if (endIndex != -1) { 64 String placeholder = buf.substring(startIndex + PLACEHOLDER_PREFIX.length(), endIndex); 65 String propVal = System.getProperty(placeholder); 66 if (propVal != null) { 67 buf.replace(startIndex, endIndex + PLACEHOLDER_SUFFIX.length(), propVal); 68 startIndex = buf.toString().indexOf(PLACEHOLDER_PREFIX, startIndex + propVal.length()); 69 } 70 else { 71 logger.warn("Could not resolve placeholder '" + placeholder + 72 "' in resource path [" + path + "] as system property"); 73 startIndex = buf.toString().indexOf(PLACEHOLDER_PREFIX, endIndex + PLACEHOLDER_SUFFIX.length()); 74 } 75 } 76 else { 77 startIndex = -1; 78 } 79 } 80 81 return buf.toString(); 82 } 83 84 } 85 | Popular Tags |