1 // Copyright (c) 1999-2004 Brian Wellington (bwelling@xbill.org) 2 3 package org.xbill.DNS; 4 5 import java.util.*; 6 7 /** 8 * Boolean options:<BR> 9 * bindttl - Print TTLs in BIND format<BR> 10 * multiline - Print records in multiline format<BR> 11 * noprintin - Don't print the class of a record if it's IN<BR> 12 * verbose - Turn on general debugging statements<BR> 13 * verbosemsg - Print all messages sent or received by SimpleResolver<BR> 14 * verbosecompression - Print messages related to name compression<BR> 15 * verbosesec - Print messages related to signature verification<BR> 16 * verbosecache - Print messages related to cache lookups<BR> 17 * <BR> 18 * Valued options:<BR> 19 * tsigfudge=n - Sets the default TSIG fudge value (in seconds)<BR> 20 * sig0validity=n - Sets the default SIG(0) validity period (in seconds)<BR> 21 * 22 * @author Brian Wellington 23 */ 24 25 public final class Options { 26 27 private static Map table; 28 29 static { 30 try { refresh()31 refresh(); 32 } 33 catch (SecurityException e) { 34 } 35 } 36 37 private Options()38Options() {} 39 40 public static void refresh()41refresh() { 42 String s = System.getProperty("dnsjava.options"); 43 if (s != null) { 44 StringTokenizer st = new StringTokenizer(s, ","); 45 while (st.hasMoreTokens()) { 46 String token = st.nextToken(); 47 int index = token.indexOf('='); 48 if (index == -1) 49 set(token); 50 else { 51 String option = token.substring(0, index); 52 String value = token.substring(index + 1); 53 set(option, value); 54 } 55 } 56 } 57 } 58 59 /** Clears all defined options */ 60 public static void clear()61clear() { 62 table = null; 63 } 64 65 /** Sets an option to "true" */ 66 public static void set(String option)67set(String option) { 68 if (table == null) 69 table = new HashMap(); 70 table.put(option.toLowerCase(), "true"); 71 } 72 73 /** Sets an option to the the supplied value */ 74 public static void set(String option, String value)75set(String option, String value) { 76 if (table == null) 77 table = new HashMap(); 78 table.put(option.toLowerCase(), value.toLowerCase()); 79 } 80 81 /** Removes an option */ 82 public static void unset(String option)83unset(String option) { 84 if (table == null) 85 return; 86 table.remove(option.toLowerCase()); 87 } 88 89 /** Checks if an option is defined */ 90 public static boolean check(String option)91check(String option) { 92 if (table == null) 93 return false; 94 return (table.get(option.toLowerCase()) != null); 95 } 96 97 /** Returns the value of an option */ 98 public static String value(String option)99value(String option) { 100 if (table == null) 101 return null; 102 return ((String)table.get(option.toLowerCase())); 103 } 104 105 /** 106 * Returns the value of an option as an integer, or -1 if not defined. 107 */ 108 public static int intValue(String option)109intValue(String option) { 110 String s = value(option); 111 if (s != null) { 112 try { 113 int val = Integer.parseInt(s); 114 if (val > 0) 115 return (val); 116 } 117 catch (NumberFormatException e) { 118 } 119 } 120 return (-1); 121 } 122 123 } 124