1 51 package org.apache.fop.viewer; 52 53 import org.apache.fop.messaging.MessageHandler; 54 55 import java.io.*; 56 import java.util.*; 57 58 70 public class LoadableProperties extends Hashtable { 71 72 public LoadableProperties() { 73 super(); 74 } 75 76 77 public void load(InputStream inStream) throws IOException { 78 79 BufferedReader in = new BufferedReader(new InputStreamReader(inStream, 80 "UTF-8")); 81 82 String aKey; 83 String aValue; 84 int index; 85 String line = getNextLine(in); 86 while (line != null) { 87 line = line.trim(); 88 if (isValid(line)) { 89 index = line.indexOf("="); 90 aKey = line.substring(0, index); 91 aValue = line.substring(index + 1); 92 put(aKey, aValue); 93 } 94 line = getNextLine(in); 95 } 96 } 97 98 99 private boolean isValid(String str) { 100 if (str == null) 101 return false; 102 if (str.length() > 0) { 103 if (str.startsWith("#") || str.startsWith("!")) { 104 return false; 105 } 106 } else { 107 return false; 108 } 109 110 int index = str.indexOf("="); 111 if (index > 0 && str.length() > index) { 112 return true; 113 } else { 114 MessageHandler.logln(getClass().getName() 115 + ": load(): invalid line " + str + "." 116 + " Character '=' missed."); 117 return false; 118 } 119 } 120 121 private String getNextLine(BufferedReader br) { 122 try { 123 return br.readLine(); 124 } catch (Exception e) { 125 return null; 126 } 127 128 } 129 130 131 } 132 | Popular Tags |