1 18 package org.objectweb.util.monolog.wrapper.common; 19 20 import org.objectweb.util.monolog.Monolog; 21 22 31 public abstract class RelatifEnvironmentPathGetter { 32 static final String START = "${"; 33 static final String END = "}"; 34 39 public static String getRealPath(final String path) { 40 if (0>path.indexOf(START)) { 41 return path; 43 } 44 45 String realPath = ""; 46 int pathIndex = path.indexOf(START); 47 for (int i=0; i<path.length(); i++) { 48 if (pathIndex>=i) { 49 realPath += path.substring(i,pathIndex); 50 i = pathIndex; 51 int endIndex = path.indexOf(END, pathIndex); 52 if (0>endIndex) { 53 Monolog.error("Error during getting the path '" 54 + path + "'", new Exception ("Bad file path conformance")); 55 return path; 56 } 57 final String name = path.substring(pathIndex + START.length(), endIndex); 58 final String value = System.getProperty(name); 59 if (null==value) { 60 Monolog.error("Error during getting the path '" 61 + path + "'", new Exception ("Unknown environment variable '" + name + "'")); 62 return path; 63 } 64 realPath += value; 65 i = endIndex; 66 pathIndex = path.indexOf(START, i); 67 } else { 68 realPath += path.substring(i); 69 i = path.length(); 70 } 71 } 72 return realPath; 73 } 74 } 75 | Popular Tags |