PropertiesHelper.resolvePlaceHolders( copy );
public static String resolvePlaceHolder(String property) { if ( property.indexOf( PLACEHOLDER_START ) < 0 ) { return property; } StringBuffer buff = new StringBuffer(); char[] chars = property.toCharArray(); for ( int pos = 0; pos < chars.length; pos++ ) { if ( chars[pos] == '$' ) { // peek ahead if ( chars[pos+1] == '{' ) { // we have a placeholder, spin forward till we find the end String systemPropertyName = ""; int x = pos + 2; for ( ; x < chars.length && chars[x] != '}'; x++ ) { systemPropertyName += chars[x]; // if we reach the end of the string w/o finding the // matching end, that is an exception if ( x == chars.length - 1 ) { throw new IllegalArgumentException( "unmatched placeholder start [" + property + "]" ); } } String systemProperty = extractFromSystem( systemPropertyName ); buff.append( systemProperty == null ? "" : systemProperty ); pos = x + 1; // make sure spinning forward did not put us past the end of the buffer... if ( pos >= chars.length ) { break; } } } buff.append( chars[pos] ); } String rtn = buff.toString(); return StringHelper.isEmpty( rtn ) ? null : rtn; |
extractFromSystem( systemPropertyName )
private static String extractFromSystem(String systemPropertyName) { try { return System.getProperty( systemPropertyName ); } catch( Throwable t ) { return null; } }
|
this properties can use in
hibernate.cfg.xml
posted on 2006-11-07 17:25
R.Zeus 阅读(486)
评论(0) 编辑 收藏 所属分类:
Hibernate