mirror of https://github.com/OpenIdentityPlatform/OpenDJ.git

neil_a_wilson
16.32.2006 5097fbda6e7c1b26da60721455eae79e1cf1920e
opends/src/server/org/opends/server/tools/LDAPSearch.java
@@ -130,18 +130,24 @@
   * @param searchOptions  The constraints for the search.
   * @param wrapColumn     The column at which to wrap long lines.
   *
   * @return  The number of matching entries returned by the server.  If there
   *          were multiple search filters provided, then this will be the
   *          total number of matching entries for all searches.
   *
   * @throws  IOException  If a problem occurs while attempting to communicate
   *                       with the Directory Server.
   *
   * @throws  LDAPException  If the Directory Server returns an error response.
   */
  public void executeSearch(LDAPConnection connection, String baseDN,
                            ArrayList<LDAPFilter> filters,
                            LinkedHashSet<String> attributes,
                            LDAPSearchOptions searchOptions,
                            int wrapColumn )
  public int executeSearch(LDAPConnection connection, String baseDN,
                           ArrayList<LDAPFilter> filters,
                           LinkedHashSet<String> attributes,
                           LDAPSearchOptions searchOptions,
                           int wrapColumn )
         throws IOException, LDAPException
  {
    int matchingEntries = 0;
    for (LDAPFilter filter: filters)
    {
      ASN1OctetString asn1OctetStr = new ASN1OctetString(baseDN);
@@ -267,6 +273,7 @@
              StringBuilder sb = new StringBuilder();
              toLDIF(searchEntryOp, sb, wrapColumn, typesOnly);
              out.println(sb.toString());
              matchingEntries++;
              break;
            case OP_TYPE_SEARCH_RESULT_REFERENCE:
@@ -312,6 +319,15 @@
        throw new IOException(ae.getMessage());
      }
    }
    if (searchOptions.countMatchingEntries())
    {
      int    msgID   = MSGID_LDAPSEARCH_MATCHING_ENTRY_COUNT;
      String message = getMessage(msgID, matchingEntries);
      out.println(message);
      out.println();
    }
    return matchingEntries;
  }
  /**
@@ -522,6 +538,7 @@
    LinkedHashSet<String> attributes = new LinkedHashSet<String>();
    BooleanArgument   continueOnError          = null;
    BooleanArgument   countEntries             = null;
    BooleanArgument   dontWrap                 = null;
    BooleanArgument   noop                     = null;
    BooleanArgument   reportAuthzID            = null;
@@ -741,6 +758,10 @@
                                     MSGID_DESCRIPTION_DONT_WRAP);
      argParser.addArgument(dontWrap);
      countEntries = new BooleanArgument("countentries", null, "countEntries",
                                         MSGID_DESCRIPTION_COUNT_ENTRIES);
      argParser.addArgument(countEntries);
      continueOnError =
           new BooleanArgument("continueOnError", 'c', "continueOnError",
                               MSGID_DESCRIPTION_CONTINUE_ON_ERROR);
@@ -935,6 +956,7 @@
    searchOptions.setVerbose(verbose.isPresent());
    searchOptions.setContinueOnError(continueOnError.isPresent());
    searchOptions.setEncoding(encodingStr.getValue());
    searchOptions.setCountMatchingEntries(countEntries.isPresent());
    try
    {
      searchOptions.setTimeLimit(timeLimit.getIntValue());
@@ -1276,8 +1298,17 @@
      connection.connectToHost(bindDNValue, bindPasswordValue, nextMessageID);
      LDAPSearch ldapSearch = new LDAPSearch(nextMessageID, out, err);
      ldapSearch.executeSearch(connection, baseDNValue, filters, attributes,
                               searchOptions, wrapColumn);
      int matchingEntries = ldapSearch.executeSearch(connection, baseDNValue,
                                                     filters, attributes,
                                                     searchOptions, wrapColumn);
      if (countEntries.isPresent())
      {
        return matchingEntries;
      }
      else
      {
        return 0;
      }
    } catch(LDAPException le)
    {
@@ -1303,7 +1334,6 @@
        connection.close();
      }
    }
    return 0;
  }
}