4 * Copyright (c) 2005 VeriSign. All rights reserved.
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions are met:
9 * 1. Redistributions of source code must retain the above copyright notice,
10 * this list of conditions and the following disclaimer. 2. Redistributions in
11 * binary form must reproduce the above copyright notice, this list of
12 * conditions and the following disclaimer in the documentation and/or other
13 * materials provided with the distribution. 3. The name of the author may not
14 * be used to endorse or promote products derived from this software without
15 * specific prior written permission.
17 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
18 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
19 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN
20 * NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
21 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED
22 * TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
23 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
24 * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
25 * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
26 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
30 package com.versign.tat.dnssec;
34 import org.xbill.DNS.Name;
37 * Some basic utility functions.
43 * Convert a DNS name into a string suitable for use as a cache key.
45 * @param name The name to convert.
46 * @return A string representing the name. This isn't ever meant to be
47 * converted back into a DNS name.
49 public static String nameToString(Name name)
51 if (name.equals(Name.root)) return ".";
53 String n = name.toString().toLowerCase();
54 if (n.endsWith(".")) n = n.substring(0, n.length() - 1);
59 public static int parseInt(String s, int def)
61 if (s == null) return def;
64 return Integer.parseInt(s);
66 catch (NumberFormatException e)
72 public static long parseLong(String s, long def)
74 if (s == null) return def;
77 return Long.parseLong(s);
79 catch (NumberFormatException e)
85 public static class ConfigEntry
90 public ConfigEntry(String key, String value)
92 this.key = key; this.value = value;
96 public static List<ConfigEntry> parseConfigPrefix(Properties config, String prefix)
98 if (! prefix.endsWith("."))
100 prefix = prefix + ".";
103 List<ConfigEntry> res = new ArrayList<ConfigEntry>();
105 for (Map.Entry<Object, Object> entry : config.entrySet()) {
106 String key = (String) entry.getKey();
107 if (key.startsWith(prefix)) {
108 key = key.substring(prefix.length());
109 res.add(new ConfigEntry(key, (String) entry.getValue()));