exportConfig.setWrapColumn(75);
}
// Create the LDIF reader/writer from the import/export config.
LDIFReader reader;
LDIFWriter writer;
try
{
reader = new LDIFReader(importConfig);
}
catch (Exception e)
{
Message message = ERR_LDIFSEARCH_CANNOT_CREATE_READER.get(
String.valueOf(e));
err.println(message);
return 1;
}
try
{
writer = new LDIFWriter(exportConfig);
}
catch (Exception e)
{
try
{
reader.close();
} catch (Exception e2) {}
Message message = ERR_LDIFSEARCH_CANNOT_CREATE_WRITER.get(
String.valueOf(e));
err.println(message);
return 1;
}
// Start reading data from the LDIF reader.
long startTime = System.currentTimeMillis();
long stopTime = startTime + timeLimitMillis;
long matchCount = 0;
int resultCode = LDAPResultCode.SUCCESS;
while (true)
{
// If the time limit has been reached, then stop now.
if ((timeLimitMillis > 0) && (System.currentTimeMillis() > stopTime))
{
resultCode = LDAPResultCode.TIME_LIMIT_EXCEEDED;
Message message = WARN_LDIFSEARCH_TIME_LIMIT_EXCEEDED.get();
err.println(message);
break;
}
try
{
Entry entry = reader.readEntry(checkSchema);
if (entry == null)
{
break;
}
// Check to see if the entry has an acceptable base and scope.
boolean matchesBaseAndScope = false;
for (DN baseDN : baseDNs)
{
if (entry.matchesBaseAndScope(baseDN, searchScope))
{
matchesBaseAndScope = true;
break;
}
}
if (! matchesBaseAndScope)
{
continue;
}
// Check to see if the entry matches any of the filters.
boolean matchesFilter = false;
for (SearchFilter filter : searchFilters)
{
if (filter.matchesEntry(entry))
{
matchesFilter = true;
break;
}
}
if (! matchesFilter)
{
continue;
}
// Prepare the entry to return to the client.
if (! allUserAttrs)
{
Iterator<AttributeType> iterator =
entry.getUserAttributes().keySet().iterator();
while (iterator.hasNext())
{
if (! userAttributeTypes.contains(iterator.next()))
{
iterator.remove();
}
}
}
if (! allOperationalAttrs)
{
Iterator<AttributeType> iterator =
entry.getOperationalAttributes().keySet().iterator();
while (iterator.hasNext())
{
if (! operationalAttributeTypes.contains(iterator.next()))
{
iterator.remove();
}
}
}
// Write the entry to the client and increase the count.
// FIXME -- Should we include a comment about which base+filter matched?
writer.writeEntry(entry);
writer.flush();
matchCount++;
if ((sizeLimitValue > 0) && (matchCount >= sizeLimitValue))
{
resultCode = LDAPResultCode.SIZE_LIMIT_EXCEEDED;
Message message = WARN_LDIFSEARCH_SIZE_LIMIT_EXCEEDED.get();
err.println(message);
break;
}
}
catch (LDIFException le)
{
if (le.canContinueReading())
{
Message message = ERR_LDIFSEARCH_CANNOT_READ_ENTRY_RECOVERABLE.get(
le.getMessage());
err.println(message);
}
else
{
Message message = ERR_LDIFSEARCH_CANNOT_READ_ENTRY_FATAL.get(
le.getMessage());
err.println(message);
resultCode = LDAPResultCode.CLIENT_SIDE_LOCAL_ERROR;
break;
}
}
catch (Exception e)
{
Message message = ERR_LDIFSEARCH_ERROR_DURING_PROCESSING.get(
String.valueOf(e));
err.println(message);
resultCode = LDAPResultCode.CLIENT_SIDE_LOCAL_ERROR;
break;
}
}
// Close the reader and writer.
try
{
reader.close();
} catch (Exception e) {}
try
{
writer.close();