-
Notifications
You must be signed in to change notification settings - Fork 264
Expand file tree
/
Copy pathOptions.java
More file actions
130 lines (114 loc) · 2.9 KB
/
Copy pathOptions.java
File metadata and controls
130 lines (114 loc) · 2.9 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
// SPDX-License-Identifier: BSD-3-Clause
// Copyright (c) 1999-2004 Brian Wellington (bwelling@xbill.org)
package org.xbill.DNS;
import java.util.HashMap;
import java.util.Map;
import java.util.StringTokenizer;
/**
* Configuration options for dnsjava.
*
* <p>Boolean options:
*
* <ul>
* <li>BINDTTL - Print TTLs in BIND format
* <li>multiline - Print records in multiline format
* <li>noPrintIN - Don't print the class of a record if it's IN
* </ul>
*
* <p>Valued options:
*
* <ul>
* <li>tsigfudge=n - Sets the default TSIG fudge value (in seconds)
* <li>sig0validity=n - Sets the default SIG(0) validity period (in seconds)
* </ul>
*
* @author Brian Wellington
*/
public final class Options {
private static Map<String, String> table;
static {
try {
refresh();
} catch (SecurityException e) {
// Ignore
}
}
private Options() {}
public static void refresh() {
String s = System.getProperty("dnsjava.options");
if (s != null) {
StringTokenizer st = new StringTokenizer(s, ",");
while (st.hasMoreTokens()) {
String token = st.nextToken();
int index = token.indexOf('=');
if (index == -1) {
set(token);
} else {
String option = token.substring(0, index);
String value = token.substring(index + 1);
set(option, value);
}
}
}
}
/** Clears all defined options */
public static void clear() {
table = null;
}
/** Sets an option to {@code true}. */
public static void set(String option) {
if (table == null) {
table = new HashMap<>();
}
table.put(option.toLowerCase(), "true");
}
/** Sets an option to the supplied value */
public static void set(String option, String value) {
if (table == null) {
table = new HashMap<>();
}
table.put(option.toLowerCase(), value.toLowerCase());
}
/** Removes an option */
public static void unset(String option) {
if (table == null) {
return;
}
table.remove(option.toLowerCase());
}
/** Checks if an option is defined */
public static boolean check(String option) {
if (table == null) {
return false;
}
return table.get(option.toLowerCase()) != null;
}
/** Returns the value of an option */
public static String value(String option) {
if (table == null) {
return null;
}
return table.get(option.toLowerCase());
}
/** Returns the value of an option as an integer, or -1 if not defined. */
public static int intValue(String option) {
String s = value(option);
if (s != null) {
try {
int val = Integer.parseInt(s);
if (val > 0) {
return val;
}
} catch (NumberFormatException e) {
// Ignore
}
}
return -1;
}
static boolean multiline() {
if (table == null) {
return false;
}
return table.get("multiline") != null;
}
}