From c5740d7b39334af983957a9c284ddd792d598f6c Mon Sep 17 00:00:00 2001
From: Jean-Noel Rouvignac <jean-noel.rouvignac@forgerock.com>
Date: Fri, 10 Jul 2015 15:13:20 +0000
Subject: [PATCH] Code cleanup

---
 opendj-server-legacy/src/main/java/org/opends/server/tools/ExportLDIF.java |   48 +++++++++++++++---------------------------------
 1 files changed, 15 insertions(+), 33 deletions(-)

diff --git a/opendj-server-legacy/src/main/java/org/opends/server/tools/ExportLDIF.java b/opendj-server-legacy/src/main/java/org/opends/server/tools/ExportLDIF.java
index 103d16d..b986439 100644
--- a/opendj-server-legacy/src/main/java/org/opends/server/tools/ExportLDIF.java
+++ b/opendj-server-legacy/src/main/java/org/opends/server/tools/ExportLDIF.java
@@ -38,6 +38,7 @@
 import java.util.ArrayList;
 import java.util.HashSet;
 import java.util.List;
+import java.util.Set;
 
 import org.forgerock.i18n.LocalizableMessage;
 import org.forgerock.i18n.slf4j.LocalizedLogger;
@@ -569,35 +570,8 @@
 
     // See if there were any user-defined sets of include/exclude attributes or
     // filters.  If so, then process them.
-    HashSet<AttributeType> excludeAttributes;
-    if (excludeAttributeStrings == null)
-    {
-      excludeAttributes = null;
-    }
-    else
-    {
-      excludeAttributes = new HashSet<>();
-      for (String attrName : excludeAttributeStrings.getValues())
-      {
-        excludeAttributes.add(
-            DirectoryServer.getAttributeType(attrName.toLowerCase(), attrName));
-      }
-    }
-
-    HashSet<AttributeType> includeAttributes;
-    if (includeAttributeStrings == null)
-    {
-      includeAttributes = null;
-    }
-    else
-    {
-      includeAttributes = new HashSet<>();
-      for (String attrName : includeAttributeStrings.getValues())
-      {
-        includeAttributes.add(
-            DirectoryServer.getAttributeType(attrName.toLowerCase(), attrName));
-      }
-    }
+    Set<AttributeType> excludeAttributes = toAttributeTypes(excludeAttributeStrings);
+    Set<AttributeType> includeAttributes = toAttributeTypes(includeAttributeStrings);
 
     ArrayList<SearchFilter> excludeFilters;
     if (excludeFilterStrings == null)
@@ -866,14 +840,22 @@
 
     // Clean up after the export by closing the export config.
     exportConfig.close();
-    if (!errorOccurred)
+    return !errorOccurred ? 0 : 1;
+  }
+
+  private Set<AttributeType> toAttributeTypes(StringArgument attributeArg)
+  {
+    if (attributeArg == null)
     {
-      return 0;
+      return null;
     }
-    else
+
+    Set<AttributeType> results = new HashSet<>();
+    for (String attrName : attributeArg.getValues())
     {
-      return 1;
+      results.add(DirectoryServer.getAttributeTypeOrDefault(attrName.toLowerCase(), attrName));
     }
+    return results;
   }
 
   /** {@inheritDoc} */

--
Gitblit v1.10.0