1 31 32 package org.opencms.util; 33 34 import java.io.File ; 35 import java.io.FileInputStream ; 36 import java.io.IOException ; 37 import java.util.Arrays ; 38 import java.util.Iterator ; 39 import java.util.Vector ; 40 41 import org.apache.commons.collections.ExtendedProperties; 42 43 52 public final class CmsPropertyUtils { 53 54 57 private CmsPropertyUtils() { 58 59 } 61 62 69 public static ExtendedProperties loadProperties(String file) throws IOException { 70 71 FileInputStream input = null; 72 ExtendedProperties properties = null; 73 74 try { 75 input = new FileInputStream (new File (file)); 76 properties = new ExtendedProperties(); 77 properties.load(input); 78 input.close(); 79 } catch (IOException e) { 80 try { 81 input.close(); 82 } catch (Exception ex) { 83 } 85 throw e; 86 } 87 88 for (Iterator i = properties.keySet().iterator(); i.hasNext();) { 89 String key = (String )i.next(); 90 Object obj = properties.get(key); 91 String [] value = {}; 92 93 if (obj instanceof Vector ) { 94 value = (String [])((Vector )obj).toArray(value); 95 } else { 96 String [] v = {(String )obj}; 97 value = v; 98 } 99 100 for (int j = 0; j < value.length; j++) { 101 value[j] = CmsStringUtil.substitute(value[j], "\\,", ","); 102 value[j] = CmsStringUtil.substitute(value[j], "\\=", "="); 103 } 104 105 if (value.length > 1) { 106 properties.put(key, new Vector (Arrays.asList(value))); 107 } else { 108 properties.put(key, value[0]); 109 } 110 } 111 112 return properties; 113 } 114 } 115 | Popular Tags |