sync with external work.
[captive-validator.git] / src / com / versign / tat / dnssec / Util.java
index 967be77..40890fb 100644 (file)
-/*
- * $Id$
- * 
- * Copyright (c) 2005 VeriSign. All rights reserved.
- * 
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions are met:
- * 
- * 1. Redistributions of source code must retain the above copyright notice,
- * this list of conditions and the following disclaimer. 2. Redistributions in
- * binary form must reproduce the above copyright notice, this list of
- * conditions and the following disclaimer in the documentation and/or other
- * materials provided with the distribution. 3. The name of the author may not
- * be used to endorse or promote products derived from this software without
- * specific prior written permission.
- * 
- * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
- * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
- * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN
- * NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
- * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED
- * TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
- * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
- * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
- * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
- * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- *  
- */
+/***************************** -*- Java -*- ********************************\
+ *                                                                         *
+ *   Copyright (c) 2009 VeriSign, Inc. All rights reserved.                *
+ *                                                                         *
+ * This software is provided solely in connection with the terms of the    *
+ * license agreement.  Any other use without the prior express written     *
+ * permission of VeriSign is completely prohibited.  The software and      *
+ * documentation are "Commercial Items", as that term is defined in 48     *
+ * C.F.R.  section 2.101, consisting of "Commercial Computer Software" and *
+ * "Commercial Computer Software Documentation" as such terms are defined  *
+ * in 48 C.F.R. section 252.227-7014(a)(5) and 48 C.F.R. section           *
+ * 252.227-7014(a)(1), and used in 48 C.F.R. section 12.212 and 48 C.F.R.  *
+ * section 227.7202, as applicable.  Pursuant to the above and other       *
+ * relevant sections of the Code of Federal Regulations, as applicable,    *
+ * VeriSign's publications, commercial computer software, and commercial   *
+ * computer software documentation are distributed and licensed to United  *
+ * States Government end users with only those rights as granted to all    *
+ * other end users, according to the terms and conditions contained in the *
+ * license agreement(s) that accompany the products and software           *
+ * documentation.                                                          *
+ *                                                                         *
+\***************************************************************************/
+
+package com.verisign.tat.dnssec;
 
-package com.versign.tat.dnssec;
+import org.xbill.DNS.Name;
 
 import java.util.*;
 
-import org.xbill.DNS.Name;
 
 /**
  * Some basic utility functions.
  */
-public class Util
-{
-
-  /**
-   * Convert a DNS name into a string suitable for use as a cache key.
-   * 
-   * @param name The name to convert.
-   * @return A string representing the name. This isn't ever meant to be
-   *         converted back into a DNS name.
-   */
-  public static String nameToString(Name name)
-  {
-    if (name.equals(Name.root)) return ".";
-
-    String n = name.toString().toLowerCase();
-    if (n.endsWith(".")) n = n.substring(0, n.length() - 1);
-
-    return n;
-  }
-
-  public static int parseInt(String s, int def)
-  {
-    if (s == null) return def;
-    try
-    {
-      return Integer.parseInt(s);
-    }
-    catch (NumberFormatException e)
-    {
-      return def;
-    }
-  }
-
-  public static long parseLong(String s, long def)
-  {
-    if (s == null) return def;
-    try
-    {
-      return Long.parseLong(s);
+public class Util {
+    /**
+     * Convert a DNS name into a string suitable for use as a cache key.
+     *
+     * @param name The name to convert.
+     * @return A string representing the name. This isn't ever meant to be
+     *         converted back into a DNS name.
+     */
+    public static String nameToString(Name name) {
+        if (name.equals(Name.root)) {
+            return ".";
+        }
+
+        String n = name.toString().toLowerCase();
+
+        if (n.endsWith(".")) {
+            n = n.substring(0, n.length() - 1);
+        }
+
+        return n;
     }
-    catch (NumberFormatException e)
-    {
-      return def;
+
+    public static int parseInt(String s, int def) {
+        if (s == null) {
+            return def;
+        }
+
+        try {
+            return Integer.parseInt(s);
+        } catch (NumberFormatException e) {
+            return def;
+        }
     }
-  }
-  
-  public static class ConfigEntry
-  {
-    public String key;
-    public String value;
-    
-    public ConfigEntry(String key, String value)
-    {
-      this.key = key; this.value = value;
+
+    public static long parseLong(String s, long def) {
+        if (s == null) {
+            return def;
+        }
+
+        try {
+            return Long.parseLong(s);
+        } catch (NumberFormatException e) {
+            return def;
+        }
     }
-  }
-  
-  public static List<ConfigEntry> parseConfigPrefix(Properties config, String prefix)
-  {
-    if (! prefix.endsWith("."))
-    {
-      prefix = prefix + ".";
+
+    public static List<ConfigEntry> parseConfigPrefix(Properties config,
+        String prefix) {
+        if (!prefix.endsWith(".")) {
+            prefix = prefix + ".";
+        }
+
+        List<ConfigEntry> res = new ArrayList<ConfigEntry>();
+
+        for (Map.Entry<Object, Object> entry : config.entrySet()) {
+            String key = (String) entry.getKey();
+
+            if (key.startsWith(prefix)) {
+                key = key.substring(prefix.length());
+                res.add(new ConfigEntry(key, (String) entry.getValue()));
+            }
+        }
+
+        return res;
     }
-    
-    List<ConfigEntry> res = new ArrayList<ConfigEntry>();
-    
-    for (Map.Entry<Object, Object> entry : config.entrySet()) {
-        String key = (String) entry.getKey();
-        if (key.startsWith(prefix)) {
-            key = key.substring(prefix.length());
-            res.add(new ConfigEntry(key, (String) entry.getValue()));
+
+    public static class ConfigEntry {
+        public String key;
+        public String value;
+
+        public ConfigEntry(String key, String value) {
+            this.key       = key;
+            this.value     = value;
         }
     }
-    
-    return res;
-  }
 }