001: // Copyright (c) 1999-2004 Brian Wellington (bwelling@xbill.org)
002:
003: package org.xbill.DNS;
004:
005: import java.util.*;
006:
007: /**
008: * Boolean options:<BR>
009: * bindttl - Print TTLs in BIND format<BR>
010: * multiline - Print records in multiline format<BR>
011: * noprintin - Don't print the class of a record if it's IN<BR>
012: * verbose - Turn on general debugging statements<BR>
013: * verbosemsg - Print all messages sent or received by SimpleResolver<BR>
014: * verbosecompression - Print messages related to name compression<BR>
015: * verbosesec - Print messages related to signature verification<BR>
016: * verbosecache - Print messages related to cache lookups<BR>
017: * <BR>
018: * Valued options:<BR>
019: * tsigfudge=n - Sets the default TSIG fudge value (in seconds)<BR>
020: * sig0validity=n - Sets the default SIG(0) validity period (in seconds)<BR>
021: *
022: * @author Brian Wellington
023: */
024:
025: public final class Options {
026:
027: private static Map table;
028:
029: static {
030: try {
031: refresh();
032: } catch (SecurityException e) {
033: }
034: }
035:
036: private Options() {
037: }
038:
039: public static void refresh() {
040: String s = System.getProperty("dnsjava.options");
041: if (s != null) {
042: StringTokenizer st = new StringTokenizer(s, ",");
043: while (st.hasMoreTokens()) {
044: String token = st.nextToken();
045: int index = token.indexOf('=');
046: if (index == -1)
047: set(token);
048: else {
049: String option = token.substring(0, index);
050: String value = token.substring(index + 1);
051: set(option, value);
052: }
053: }
054: }
055: }
056:
057: /** Clears all defined options */
058: public static void clear() {
059: table = null;
060: }
061:
062: /** Sets an option to "true" */
063: public static void set(String option) {
064: if (table == null)
065: table = new HashMap();
066: table.put(option.toLowerCase(), "true");
067: }
068:
069: /** Sets an option to the the supplied value */
070: public static void set(String option, String value) {
071: if (table == null)
072: table = new HashMap();
073: table.put(option.toLowerCase(), value.toLowerCase());
074: }
075:
076: /** Removes an option */
077: public static void unset(String option) {
078: if (table == null)
079: return;
080: table.remove(option.toLowerCase());
081: }
082:
083: /** Checks if an option is defined */
084: public static boolean check(String option) {
085: if (table == null)
086: return false;
087: return (table.get(option.toLowerCase()) != null);
088: }
089:
090: /** Returns the value of an option */
091: public static String value(String option) {
092: if (table == null)
093: return null;
094: return ((String) table.get(option.toLowerCase()));
095: }
096:
097: /**
098: * Returns the value of an option as an integer, or -1 if not defined.
099: */
100: public static int intValue(String option) {
101: String s = value(option);
102: if (s != null) {
103: try {
104: int val = Integer.parseInt(s);
105: if (val > 0)
106: return (val);
107: } catch (NumberFormatException e) {
108: }
109: }
110: return (-1);
111: }
112:
113: }
|