private void parseModify( LdifEntry entry, Iterator<String> iter ) throws LdapLdifException
{
int state = MOD_SPEC;
String modified = null;
ModificationOperation modificationType = ModificationOperation.ADD_ATTRIBUTE;
EntryAttribute attribute = null;
// The following flag is used to deal with empty modifications
boolean isEmptyValue = true;
while ( iter.hasNext() )
{
String line = iter.next();
String lowerLine = line.toLowerCase();
if ( lowerLine.startsWith( "-" ) )
{
if ( state != ATTRVAL_SPEC_OR_SEP )
{
LOG.error( I18n.err( I18n.ERR_12040_BAD_MODIFY_SEPARATOR ) );
throw new LdapLdifException( I18n.err( I18n.ERR_12040_BAD_MODIFY_SEPARATOR ) );
}
else
{
if ( isEmptyValue )
{
// Update the entry
entry.addModificationItem( modificationType, modified, null );
}
else
{
// Update the entry with the attribute
entry.addModificationItem( modificationType, attribute );
}
state = MOD_SPEC;
isEmptyValue = true;
}
}
else if ( lowerLine.startsWith( "add:" ) )
{
if ( ( state != MOD_SPEC ) && ( state != ATTRVAL_SPEC ) )
{
LOG.error( I18n.err( I18n.ERR_12042_BAD_MODIFY_SEPARATOR_2 ) );
throw new LdapLdifException( I18n.err( I18n.ERR_12042_BAD_MODIFY_SEPARATOR_2 ) );
}
modified = Strings.trim(line.substring("add:".length()));
modificationType = ModificationOperation.ADD_ATTRIBUTE;
attribute = new DefaultEntryAttribute( modified );
state = ATTRVAL_SPEC;
}
else if ( lowerLine.startsWith( "delete:" ) )
{
if ( ( state != MOD_SPEC ) && ( state != ATTRVAL_SPEC ) )
{
LOG.error( I18n.err( I18n.ERR_12042_BAD_MODIFY_SEPARATOR_2 ) );
throw new LdapLdifException( I18n.err( I18n.ERR_12042_BAD_MODIFY_SEPARATOR_2 ) );
}
modified = Strings.trim(line.substring("delete:".length()));
modificationType = ModificationOperation.REMOVE_ATTRIBUTE;
attribute = new DefaultEntryAttribute( modified );
state = ATTRVAL_SPEC_OR_SEP;
}
else if ( lowerLine.startsWith( "replace:" ) )
{
if ( ( state != MOD_SPEC ) && ( state != ATTRVAL_SPEC ) )
{
LOG.error( I18n.err( I18n.ERR_12042_BAD_MODIFY_SEPARATOR_2 ) );
throw new LdapLdifException( I18n.err( I18n.ERR_12042_BAD_MODIFY_SEPARATOR_2 ) );
}
modified = Strings.trim(line.substring("replace:".length()));
modificationType = ModificationOperation.REPLACE_ATTRIBUTE;
attribute = new DefaultEntryAttribute( modified );
state = ATTRVAL_SPEC_OR_SEP;
}
else
{
if ( ( state != ATTRVAL_SPEC ) && ( state != ATTRVAL_SPEC_OR_SEP ) )
{
LOG.error( I18n.err( I18n.ERR_12040_BAD_MODIFY_SEPARATOR ) );
throw new LdapLdifException( I18n.err( I18n.ERR_12040_BAD_MODIFY_SEPARATOR ) );
}
// A standard AttributeType/AttributeValue pair
int colonIndex = line.indexOf( ':' );
String attributeType = line.substring( 0, colonIndex );
if ( !attributeType.equalsIgnoreCase( modified ) )
{
LOG.error( I18n.err( I18n.ERR_12044 ) );
throw new LdapLdifException( I18n.err( I18n.ERR_12045 ) );
}
// We should *not* have a Dn twice
if ( attributeType.equalsIgnoreCase( "dn" ) )
{
LOG.error( I18n.err( I18n.ERR_12002_ENTRY_WITH_TWO_DNS ) );
throw new LdapLdifException( I18n.err( I18n.ERR_12003_LDIF_ENTRY_WITH_TWO_DNS ) );
}
Object attributeValue = parseValue( line, colonIndex );
if ( attributeValue instanceof String )
{
attribute.add( ( String ) attributeValue );
}
else
{
attribute.add( ( byte[] ) attributeValue );
}
isEmptyValue = false;
state = ATTRVAL_SPEC_OR_SEP;