1 23 24 package org.infoglue.deliver.util; 25 26 import java.io.ByteArrayInputStream ; 27 import java.util.HashMap ; 28 import java.util.Map ; 29 import java.util.Properties ; 30 import java.util.StringTokenizer ; 31 32 36 public class Support 37 { 38 39 46 47 public static Map convertTextToMap( String text ) 48 { 49 return convertTextToMap( text, "=", "\n" ); 50 } 51 52 62 public static Map convertTextToMap( String text, String propertyValueDelim, String rowDelim ) 63 { 64 Map map = new HashMap (); 65 if ( text != null ) 66 { 67 StringTokenizer rowTok = new StringTokenizer ( text, rowDelim, false ); 68 while ( rowTok.hasMoreTokens() ) 69 { 70 String propVal = rowTok.nextToken(); 71 int index = propVal.indexOf( propertyValueDelim ); 72 if ( index > 0 ) 73 { 74 map.put( propVal.substring( 0, index ).trim(), propVal.substring( index + 1 ).trim() ); 75 } 76 } 77 } 78 return map; 79 } 80 81 87 public static Map convertTextToProperties( String text ) 88 { 89 Properties properties = new Properties (); 90 try 91 { 92 ByteArrayInputStream is = new ByteArrayInputStream ( text.getBytes("ISO-8859-1") ); 93 properties.load( is ); 94 is.close(); 95 } 96 catch ( Exception ignore ) 97 { 98 } 100 101 return properties; 102 } 103 104 107 public static void main( String [] args ) 108 { 109 111 } 112 113 } 114 | Popular Tags |