in plugins/ldifparser/src/main/java/org/apache/directory/studio/ldifparser/parser/LdifParser.java [188:389]
private boolean checkAndParseRecord( LdifFile model )
{
// record starts with dn-spec
LdifToken dnSpecToken = scanner.matchDnSpec();
if ( dnSpecToken == null )
{
return false;
}
// get Dn
LdifToken dnValueTypeToken = null;
LdifToken dnToken = null;
LdifToken dnSepToken = null;
dnValueTypeToken = scanner.matchValueType();
if ( dnValueTypeToken != null )
{
dnToken = scanner.matchValue();
if ( dnToken != null )
{
dnSepToken = scanner.matchSep();
}
}
LdifDnLine dnLine = new LdifDnLine( dnSpecToken.getOffset(), getValueOrNull( dnSpecToken ),
getValueOrNull( dnValueTypeToken ), getValueOrNull( dnToken ), getValueOrNull( dnSepToken ) );
LdifToken dnErrorToken = null;
if ( dnSepToken == null )
{
dnErrorToken = scanner.matchCleanupLine();
}
// save comment lines after dns
LdifCommentLine[] commentLines = getCommentLines();
// check record type: to decide the record type we need the next token
// first check keywords 'control' and 'changetype'
LdifControlLine controlLine = getControlLine();
LdifChangeTypeLine changeTypeLine = getChangeTypeLine();
if ( controlLine != null || changeTypeLine != null )
{
LdifChangeRecord record = null;
// save all parts before changetype line
List<LdifPart> partList = new ArrayList<LdifPart>();
if ( dnErrorToken != null )
{
partList.add( new LdifInvalidPart( dnErrorToken.getOffset(), dnErrorToken.getValue() ) );
}
for ( LdifCommentLine ldifCommentLine : commentLines )
{
partList.add( ldifCommentLine );
}
if ( controlLine != null )
{
partList.add( controlLine );
if ( !controlLine.isValid() )
{
LdifToken errorToken = cleanupLine();
if ( errorToken != null )
{
partList.add( new LdifInvalidPart( errorToken.getOffset(), errorToken.getValue() ) );
}
}
}
// save comments and controls before changetype line
while ( changeTypeLine == null && ( commentLines.length > 0 || controlLine != null ) )
{
commentLines = getCommentLines();
for ( LdifCommentLine ldifCommentLine : commentLines )
{
partList.add( ldifCommentLine );
}
controlLine = getControlLine();
if ( controlLine != null )
{
partList.add( controlLine );
if ( !controlLine.isValid() )
{
LdifToken errorToken = cleanupLine();
if ( errorToken != null )
{
partList.add( new LdifInvalidPart( errorToken.getOffset(), errorToken.getValue() ) );
}
}
}
changeTypeLine = getChangeTypeLine();
}
if ( changeTypeLine != null )
{
if ( changeTypeLine.isAdd() )
{
record = new LdifChangeAddRecord( dnLine );
append( record, partList );
record.setChangeType( changeTypeLine );
if ( !changeTypeLine.isValid() )
{
this.cleanupLine( record );
}
parseAttrValRecord( record );
}
else if ( changeTypeLine.isDelete() )
{
record = new LdifChangeDeleteRecord( dnLine );
append( record, partList );
record.setChangeType( changeTypeLine );
if ( !changeTypeLine.isValid() )
{
this.cleanupLine( record );
}
parseChangeDeleteRecord( record );
}
else if ( changeTypeLine.isModify() )
{
record = new LdifChangeModifyRecord( dnLine );
append( record, partList );
record.setChangeType( changeTypeLine );
if ( !changeTypeLine.isValid() )
{
this.cleanupLine( record );
}
parseChangeModifyRecord( ( LdifChangeModifyRecord ) record );
}
else if ( changeTypeLine.isModDn() )
{
record = new LdifChangeModDnRecord( dnLine );
append( record, partList );
record.setChangeType( changeTypeLine );
if ( !changeTypeLine.isValid() )
{
this.cleanupLine( record );
}
parseChangeModDnRecord( ( LdifChangeModDnRecord ) record );
}
else
{
record = new LdifChangeRecord( dnLine );
append( record, partList );
record.setChangeType( changeTypeLine );
if ( !changeTypeLine.isValid() )
{
this.cleanupLine( record );
}
}
}
else
{
record = new LdifChangeRecord( dnLine );
append( record, partList );
}
model.addContainer( record );
}
else
{
// match attr-val-record
LdifContentRecord record = new LdifContentRecord( dnLine );
if ( dnErrorToken != null )
{
record.addInvalid( new LdifInvalidPart( dnErrorToken.getOffset(), dnErrorToken.getValue() ) );
}
for ( LdifCommentLine ldifCommentLine : commentLines )
{
record.addComment( ldifCommentLine );
}
parseAttrValRecord( record );
model.addContainer( record );
}
return true;
}