From 9f04857f46200f98cfe4d57e6a874822bfff8616 Mon Sep 17 00:00:00 2001
From: neil_a_wilson <neil_a_wilson@localhost>
Date: Wed, 16 Aug 2006 19:45:25 +0000
Subject: [PATCH] Add a getFileForPath method to the StaticUtils class, and update several server components to use it.  This can help ensure that relative paths are evaluated relative to the server root rather than whatever happened to be the current working directory when the start script was launched.

---
 opendj-sdk/opends/src/server/org/opends/server/util/StaticUtils.java |   47 +++++++++++++++++++++++++++++++++++++++++++++++
 1 files changed, 47 insertions(+), 0 deletions(-)

diff --git a/opendj-sdk/opends/src/server/org/opends/server/util/StaticUtils.java b/opendj-sdk/opends/src/server/org/opends/server/util/StaticUtils.java
index 7b2c21a..92a4965 100644
--- a/opendj-sdk/opends/src/server/org/opends/server/util/StaticUtils.java
+++ b/opendj-sdk/opends/src/server/org/opends/server/util/StaticUtils.java
@@ -3180,6 +3180,53 @@
 
 
   /**
+   * Indicates whether the provided path refers to a relative path rather than
+   * an absolute path.
+   *
+   * @param  path  The path string for which to make the determination.
+   *
+   * @return  <CODE>true</CODE> if the provided path is relative, or
+   *          <CODE>false</CODE> if it is absolute.
+   */
+  public static boolean isRelativePath(String path)
+  {
+    assert debugEnter(CLASS_NAME, "isRelativePath", String.valueOf(path));
+
+    File f = new File(path);
+    return (! f.isAbsolute());
+  }
+
+
+
+  /**
+   * Retrieves a <CODE>File</CODE> object corresponding to the specified path.
+   * If the given path is an absolute path, then it will be used.  If the path
+   * is relative, then it will be interpreted as if it were relative to the
+   * Directory Server root.
+   *
+   * @param  path  The path string to be retrieved as a <CODE>File</CODE>
+   *
+   * @return  A <CODE>File</CODE> object that corresponds to the specified path.
+   */
+  public static File getFileForPath(String path)
+  {
+    assert debugEnter(CLASS_NAME, "getFileForPath", String.valueOf(path));
+
+    File f = new File (path);
+
+    if (f.isAbsolute())
+    {
+      return f;
+    }
+    else
+    {
+      return new File(DirectoryServer.getServerRoot() + File.separator + path);
+    }
+  }
+
+
+
+  /**
    * Creates a new, blank entry with the given DN.  It will contain only the
    * attributes contained in the RDN, and it will be based on the untypedObject
    * objectclass.  If the entry contains one or more attributes that are not

--
Gitblit v1.10.0