From 83b2ceb3e8bb3a2183e0ee4685fa482ea7bc98c3 Mon Sep 17 00:00:00 2001
From: neil_a_wilson <neil_a_wilson@localhost>
Date: Mon, 09 Oct 2006 22:53:54 +0000
Subject: [PATCH] Update the LDAP client tools to avoid explicit calls to System.err instead of using the defined print stream for error messages.

---
 opendj-sdk/opends/src/server/org/opends/server/tools/LDAPSearch.java        |    6 +++---
 opendj-sdk/opends/src/server/org/opends/server/tools/LDAPToolUtils.java     |   21 +++++++++++++--------
 opendj-sdk/opends/src/server/org/opends/server/tools/LDAPModify.java        |    2 +-
 opendj-sdk/opends/src/server/org/opends/server/tools/LDAPSearchOptions.java |   16 +++++++++++-----
 opendj-sdk/opends/src/server/org/opends/server/tools/LDAPCompare.java       |    4 ++--
 opendj-sdk/opends/src/server/org/opends/server/tools/LDAPDelete.java        |    2 +-
 6 files changed, 31 insertions(+), 20 deletions(-)

diff --git a/opendj-sdk/opends/src/server/org/opends/server/tools/LDAPCompare.java b/opendj-sdk/opends/src/server/org/opends/server/tools/LDAPCompare.java
index 4973675..4f6b766 100644
--- a/opendj-sdk/opends/src/server/org/opends/server/tools/LDAPCompare.java
+++ b/opendj-sdk/opends/src/server/org/opends/server/tools/LDAPCompare.java
@@ -548,7 +548,7 @@
         try
         {
           String filePath = remainder.substring(1, remainder.length());
-          attributeVal = LDAPToolUtils.readBytesFromFile(filePath);
+          attributeVal = LDAPToolUtils.readBytesFromFile(filePath, err);
         }
         catch (Exception e)
         {
@@ -631,7 +631,7 @@
     if(controlStr.hasValue())
     {
       String ctrlString = controlStr.getValue();
-      LDAPControl ctrl = LDAPToolUtils.getControl(ctrlString);
+      LDAPControl ctrl = LDAPToolUtils.getControl(ctrlString, err);
       if(ctrl == null)
       {
         err.println("Invalid control specified:" + ctrlString);
diff --git a/opendj-sdk/opends/src/server/org/opends/server/tools/LDAPDelete.java b/opendj-sdk/opends/src/server/org/opends/server/tools/LDAPDelete.java
index 88fad65..d5b04e0 100644
--- a/opendj-sdk/opends/src/server/org/opends/server/tools/LDAPDelete.java
+++ b/opendj-sdk/opends/src/server/org/opends/server/tools/LDAPDelete.java
@@ -528,7 +528,7 @@
     if(controlStr.hasValue())
     {
       String ctrlString = controlStr.getValue();
-      LDAPControl ctrl = LDAPToolUtils.getControl(ctrlString);
+      LDAPControl ctrl = LDAPToolUtils.getControl(ctrlString, err);
       if(ctrl == null)
       {
         err.println("Invalid control specified:" + ctrlString);
diff --git a/opendj-sdk/opends/src/server/org/opends/server/tools/LDAPModify.java b/opendj-sdk/opends/src/server/org/opends/server/tools/LDAPModify.java
index d5441c4..7cd8f0c 100644
--- a/opendj-sdk/opends/src/server/org/opends/server/tools/LDAPModify.java
+++ b/opendj-sdk/opends/src/server/org/opends/server/tools/LDAPModify.java
@@ -810,7 +810,7 @@
     if(controlStr.hasValue())
     {
       String ctrlString = controlStr.getValue();
-      LDAPControl ctrl = LDAPToolUtils.getControl(ctrlString);
+      LDAPControl ctrl = LDAPToolUtils.getControl(ctrlString, err);
       if(ctrl == null)
       {
         err.println("Invalid control specified:" + ctrlString);
diff --git a/opendj-sdk/opends/src/server/org/opends/server/tools/LDAPSearch.java b/opendj-sdk/opends/src/server/org/opends/server/tools/LDAPSearch.java
index a0faa5f..29aa566 100644
--- a/opendj-sdk/opends/src/server/org/opends/server/tools/LDAPSearch.java
+++ b/opendj-sdk/opends/src/server/org/opends/server/tools/LDAPSearch.java
@@ -839,12 +839,12 @@
       err.println(ex1.getMessage());
       return 1;
     }
-    boolean val = searchOptions.setSearchScope(searchScope.getValue());
+    boolean val = searchOptions.setSearchScope(searchScope.getValue(), err);
     if(val == false)
     {
       return 1;
     }
-    val = searchOptions.setDereferencePolicy(dereferencePolicy.getValue());
+    val = searchOptions.setDereferencePolicy(dereferencePolicy.getValue(), err);
     if(val == false)
     {
       return 1;
@@ -853,7 +853,7 @@
     if(controlStr.hasValue())
     {
       String ctrlString = controlStr.getValue();
-      LDAPControl ctrl = LDAPToolUtils.getControl(ctrlString);
+      LDAPControl ctrl = LDAPToolUtils.getControl(ctrlString, err);
       if(ctrl == null)
       {
         err.println("Invalid control specified:" + ctrlString);
diff --git a/opendj-sdk/opends/src/server/org/opends/server/tools/LDAPSearchOptions.java b/opendj-sdk/opends/src/server/org/opends/server/tools/LDAPSearchOptions.java
index 4e4b359..0d84db0 100644
--- a/opendj-sdk/opends/src/server/org/opends/server/tools/LDAPSearchOptions.java
+++ b/opendj-sdk/opends/src/server/org/opends/server/tools/LDAPSearchOptions.java
@@ -26,6 +26,8 @@
  */
 package org.opends.server.tools;
 
+import java.io.PrintStream;
+
 import org.opends.server.types.DereferencePolicy;
 import org.opends.server.types.SearchScope;
 
@@ -112,12 +114,14 @@
    * Set the search scope .
    *
    * @param  scope  The search scope string.
+   * @param  err    A print stream to which error messages should be written if
+   *                a problem occurs.
    *
    * @return  <CODE>true</CODE> if the scope was set properly, or
    *          <CODE>false</CODE> if not.
    */
 
-  public boolean setSearchScope(String scope)
+  public boolean setSearchScope(String scope, PrintStream err)
   {
       if(scope == null)
       {
@@ -138,7 +142,7 @@
       } else
       {
         int msgID = MSGID_SEARCH_INVALID_SEARCH_SCOPE;
-        System.err.println(getMessage(msgID, scope));
+        err.println(getMessage(msgID, scope));
         return false;
       }
       return true;
@@ -157,13 +161,15 @@
   /**
    * Set the dereference policy.
    *
-   * @param policy    The dereference policy.
+   * @param policy  The dereference policy.
+   * @param  err    A print stream to which error messages should be written if
+   *                a problem occurs.
    *
    * @return  <CODE>true</CODE> if the dereference policy was set properly, or
    *          <CODE>false</CODE> if not.
    */
 
-  public boolean setDereferencePolicy(String policy)
+  public boolean setDereferencePolicy(String policy, PrintStream err)
   {
       if(policy == null)
       {
@@ -182,7 +188,7 @@
         dereferencePolicy = DEREF_FINDING_BASE_OBJECT;
       } else
       {
-        System.err.println("Invalid deref alias specified:" + policy);
+        err.println("Invalid deref alias specified:" + policy);
         return false;
       }
       return true;
diff --git a/opendj-sdk/opends/src/server/org/opends/server/tools/LDAPToolUtils.java b/opendj-sdk/opends/src/server/org/opends/server/tools/LDAPToolUtils.java
index 418d268..5dfcabf 100644
--- a/opendj-sdk/opends/src/server/org/opends/server/tools/LDAPToolUtils.java
+++ b/opendj-sdk/opends/src/server/org/opends/server/tools/LDAPToolUtils.java
@@ -29,6 +29,7 @@
 import java.io.File;
 import java.io.FileInputStream;
 import java.io.IOException;
+import java.io.PrintStream;
 
 import org.opends.server.protocols.asn1.ASN1OctetString;
 import org.opends.server.protocols.ldap.LDAPControl;
@@ -56,11 +57,13 @@
    *
    * @param  argString  The argument string containing the encoded control
    *                    information.
+   * @param  err        A print stream to which error messages should be
+   *                    written if a problem occurs.
    *
    * @return  The control decoded from the provided string, or <CODE>null</CODE>
    *          if an error occurs while parsing the argument value.
    */
-  public static LDAPControl getControl(String argString)
+  public static LDAPControl getControl(String argString, PrintStream err)
   {
     LDAPControl control = null;
     String controlOID = null;
@@ -88,7 +91,7 @@
         controlCriticality = false;
       } else
       {
-        System.err.println("Invalid format for criticality value:" + remainder);
+        err.println("Invalid format for criticality value:" + remainder);
         return null;
       }
       control = new LDAPControl(controlOID, controlCriticality);
@@ -105,7 +108,7 @@
       controlCriticality = false;
     } else
     {
-      System.err.println("Invalid format for criticality value:" + critical);
+      err.println("Invalid format for criticality value:" + critical);
       return null;
     }
 
@@ -117,10 +120,10 @@
     } else if(valString.charAt(0) == '<')
     {
       // Read data from the file.
-      String fileURL = valString.substring(1, valString.length());
+      String filePath = valString.substring(1, valString.length());
       try
       {
-        byte[] val = readBytesFromFile(fileURL);
+        byte[] val = readBytesFromFile(filePath, err);
         controlValue = new ASN1OctetString(val);
       }
       catch (Exception e)
@@ -140,14 +143,16 @@
   /**
    * Read the data from the specified file and return it in a byte array.
    *
-   * @param  filePath  The path to the file that should be read.
+   * @param  filePath   The path to the file that should be read.
+   * @param  err        A print stream to which error messages should be
+   *                    written if a problem occurs.
    *
    * @return  A byte array containing the contents of the requested file.
    *
    * @throws  IOException  If a problem occurs while trying to read the
    *                       specified file.
    */
-  public static byte[] readBytesFromFile(String filePath)
+  public static byte[] readBytesFromFile(String filePath, PrintStream err)
          throws IOException
   {
       byte[] val = null;
@@ -169,7 +174,7 @@
         // Ensure all the bytes have been read in
         if (offset < val.length)
         {
-          System.err.println("Could not completely read file "+filePath);
+          err.println("Could not completely read file "+filePath);
           return null;
         }
 

--
Gitblit v1.10.0