1 51 package org.apache.fop.viewer; 52 53 import java.util.*; 54 import org.apache.fop.messaging.MessageHandler; 55 import java.io.*; 56 57 58 66 public class SecureResourceBundle extends ResourceBundle 67 implements Translator { 68 69 private boolean isMissingEmphasized = false; 71 72 private LoadableProperties lookup = new LoadableProperties(); 74 75 private boolean isSourceFound = true; 76 77 public void setMissingEmphasized(boolean flag) { 78 isMissingEmphasized = flag; 79 } 80 81 84 85 public SecureResourceBundle(InputStream in) { 86 try { 87 lookup.load(in); 88 } catch (Exception ex) { 89 MessageHandler.logln("Exception catched: " + ex.getMessage()); 90 isSourceFound = false; 91 } 92 } 93 94 95 96 public Enumeration getKeys() { 97 return lookup.keys(); 98 } 99 100 101 102 114 public Object handleGetObject(String key) { 115 116 if (key == null) 117 return "Key is null"; 118 119 Object obj = lookup.get(key); 120 if (obj != null) 121 return obj; 122 else { 123 if (isMissingEmphasized) { 124 MessageHandler.logln(getClass().getName() + ": missing key: " 125 + key); 126 return getMissedRepresentation(key.toString()); 127 } else 128 return key.toString(); 129 } 130 } 131 132 135 public boolean contains(String key) { 136 return (key == null || lookup.get(key) == null) ? false : true; 137 } 138 139 140 private String getMissedRepresentation(String str) { 141 return "<!" + str + "!>"; 142 } 143 144 public boolean isSourceFound() { 145 return isSourceFound; 146 } 147 148 } 149 | Popular Tags |