/*
* CDDL HEADER START
*
* The contents of this file are subject to the terms of the
* Common Development and Distribution License, Version 1.0 only
* (the "License"). You may not use this file except in compliance
* with the License.
*
* You can obtain a copy of the license at
* See the License for the specific language governing permissions
* and limitations under the License.
*
* When distributing Covered Code, include this CDDL HEADER in each
* file and include the License file at
* trunk/opends/resource/legal-notices/OpenDS.LICENSE. If applicable,
* add the following below this CDDL HEADER, with the fields enclosed
* by brackets "[]" replaced with your own identifying information:
* Portions Copyright [yyyy] [name of copyright owner]
*
* CDDL HEADER END
*
*
* Copyright 2006-2008 Sun Microsystems, Inc.
* Portions Copyright 2012-2013 ForgeRock AS
*/
/**
* This class provides a program that may be used to apply a set of changes (in
* LDIF change format) to an LDIF file. It will first read all of the changes
* into memory, and then will iterate through an LDIF file and apply them to the
* entries contained in it. Note that because of the manner in which it
* processes the changes, certain types of operations will not be allowed,
* including:
* <BR>
* <UL>
* <LI>Modify DN operations</LI>
* <LI>Deleting an entry that has been added</LI>
* <LI>Modifying an entry that has been added</LI>
* </UL>
*/
public class LDIFModify
{
/**
* The fully-qualified name of this class.
*/
/**
* Applies the specified changes to the source LDIF, writing the modified
* file to the specified target. Neither the readers nor the writer will be
* closed.
*
* @param sourceReader The LDIF reader that will be used to read the LDIF
* content to be modified.
* @param changeReader The LDIF reader that will be used to read the changes
* to be applied.
* @param targetWriter The LDIF writer that will be used to write the
* modified LDIF.
* @param errorList A list into which any error messages generated while
* processing changes may be added.
*
* @return <CODE>true</CODE> if all updates were successfully applied, or
* <CODE>false</CODE> if any errors were encountered.
*
* @throws IOException If a problem occurs while attempting to read the
* source or changes, or write the target.
*
* @throws LDIFException If a problem occurs while attempting to decode the
* source or changes, or trying to determine whether
* to include the entry in the output.
*/
throws IOException, LDIFException
{
// Read the changes into memory.
while (true)
{
try
{
}
catch (LDIFException le)
{
if (le.canContinueReading())
{
continue;
}
else
{
throw le;
}
}
if (changeRecord == null)
{
break;
}
switch (changeRecord.getChangeOperationType())
{
case ADD:
// The entry must not exist in the add list.
{
continue;
}
else
{
}
break;
case DELETE:
// The entry must not exist in the add list. If it exists in the
// modify list, then remove the changes since we won't need to apply
// them.
{
continue;
}
else
{
}
break;
case MODIFY:
// The entry must not exist in the add or delete lists.
{
continue;
}
else
{
{
}
for (RawModification mod :
{
try
{
}
catch (LDAPException le)
{
continue;
}
}
}
break;
case MODIFY_DN:
continue;
default:
continue;
}
}
// Read the source an entry at a time and apply any appropriate changes
// before writing to the target LDIF.
while (true)
{
try
{
}
catch (LDIFException le)
{
if (le.canContinueReading())
{
continue;
}
else
{
throw le;
}
}
{
break;
}
// If the entry is to be deleted, then just skip over it without writing
// it to the output.
{
continue;
}
// If the entry is to be added, then that's an error, since it already
// exists.
{
continue;
}
// If the entry is to be modified, then process the changes.
{
try
{
}
catch (DirectoryException de)
{
continue;
}
}
// If we've gotten here, then the (possibly updated) entry should be
// written to the LDIF entry Map.
}
// Perform any adds that may be necessary.
{
{
AttributeType t = a.getAttributeType();
if (t.isObjectClassType())
{
for (AttributeValue v : a)
{
}
}
else if (t.isOperational())
{
{
}
}
else
{
{
}
}
}
//Put the entry to be added into the LDIF entry map.
}
// If there are any entries left in the delete or modify lists, then that's
// a problem because they didn't exist.
{
{
}
}
if (! modifications.isEmpty())
{
{
}
}
}
/**
* Invokes <CODE>ldifModifyMain</CODE> to perform the appropriate processing.
*
* @param args The command-line arguments provided to the client.
*/
{
if (returnCode != 0)
{
}
}
/**
* Processes the command-line arguments and makes the appropriate updates to
* the LDIF file.
*
* @param args The command line arguments provided to this
* program.
* @param serverInitialized Indicates whether the Directory Server has
* already been initialized (and therefore should
* not be initialized a second time).
* @param outStream The output stream to use for standard output, or
* {@code null} if standard output is not needed.
* @param errStream The output stream to use for standard error, or
* {@code null} if standard error is not needed.
*
* @return A value of zero if everything completed properly, or nonzero if
* any problem(s) occurred.
*/
{
{
}
else
{
}
// Prepare the argument parser.
false);
try
{
false, true,
null,
configFile.setHidden(true);
OPTION_LONG_CONFIG_CLASS, false,
false, true, INFO_CONFIGCLASS_PLACEHOLDER.get(),
configClass.setHidden(true);
false, true,
null,
false, true, INFO_LDIFFILE_PLACEHOLDER.get(),
false, true,
null,
}
catch (ArgumentException ae)
{
return 1;
}
// Parse the command-line arguments provided to the program.
try
{
}
catch (ArgumentException ae)
{
}
// If we should just display usage or version information,
// then print it and exit.
if (argParser.usageOrVersionDisplayed())
{
return 0;
}
// Checks the version - if upgrade required, the tool is unusable
try
{
}
catch (InitializationException e)
{
return 1;
}
if (! serverInitialized)
{
// Bootstrap the Directory Server configuration for use as a client.
// If we're to use the configuration then initialize it, along with the
// schema.
if (checkSchema)
{
try
{
}
catch (Exception e)
{
e.getMessage());
return 1;
}
try
{
configFile.getValue());
}
catch (Exception e)
{
e.getMessage());
return 1;
}
try
{
}
catch (Exception e)
{
e.getMessage());
return 1;
}
}
}
// Create the LDIF readers and writer from the arguments.
{
sourceFile.getValue());
}
try
{
}
catch (IOException ioe)
{
}
{
changesFile.getValue());
}
try
{
}
catch (IOException ioe)
{
}
try
{
}
catch (IOException ioe)
{
}
// Actually invoke the LDIF procesing.
boolean successful;
try
{
}
catch (Exception e)
{
successful = false;
}
try
{
} catch (Exception e) {}
try
{
} catch (Exception e) {}
try
{
} catch (Exception e) {}
{
}
}
}