@Test public void testLdifParserRFC2849Sample1() throws LdapLdifException, IOException { String ldif = "objectclass: top\n" + "objectclass: person\n" + "objectclass: organizationalPerson\n" + "cn: Barbara Jensen\n" + "cn: Barbara J Jensen\n" + "cn: Babs Jensen\n" + "sn: Jensen\n" + "uid: bjensen\n" + "telephonenumber: +1 408 555 1212\n" + "description: A big sailing fan.\n"; LdifAttributesReader reader = new LdifAttributesReader(); Entry entry = reader.parseEntry( ldif ); Attribute attr = entry.get( "objectclass" ); assertTrue( attr.contains( "top" ) ); assertTrue( attr.contains( "person" ) ); assertTrue( attr.contains( "organizationalPerson" ) ); attr = entry.get( "cn" ); assertTrue( attr.contains( "Barbara Jensen" ) ); assertTrue( attr.contains( "Barbara J Jensen" ) ); assertTrue( attr.contains( "Babs Jensen" ) ); attr = entry.get( "sn" ); assertTrue( attr.contains( "Jensen" ) ); attr = entry.get( "uid" ); assertTrue( attr.contains( "bjensen" ) ); attr = entry.get( "telephonenumber" ); assertTrue( attr.contains( "+1 408 555 1212" ) ); attr = entry.get( "description" ); assertTrue( attr.contains( "A big sailing fan." ) ); reader.close(); }
private Entry parseEntry( SchemaManager schemaManager ) throws LdapLdifException { if ( ( lines == null ) || lines.isEmpty() ) { if ( LOG.isDebugEnabled() ) { LOG.debug( I18n.msg( I18n.MSG_13408_END_OF_LDIF ) ); } return null; } Entry entry = new DefaultEntry( schemaManager ); for ( String line : lines ) { String lowerLine = Strings.toLowerCaseAscii( line ); if ( lowerLine.startsWith( "control:" ) ) { LOG.error( I18n.err( I18n.ERR_13401_CHANGE_NOT_ALLOWED ) ); throw new LdapLdifException( I18n.err( I18n.ERR_13440_NO_CHANGE ) ); } else if ( lowerLine.startsWith( "changetype:" ) ) { LOG.error( I18n.err( I18n.ERR_13401_CHANGE_NOT_ALLOWED ) ); throw new LdapLdifException( I18n.err( I18n.ERR_13440_NO_CHANGE ) ); } else if ( line.indexOf( ':' ) > 0 ) { parseEntryAttribute( schemaManager, entry, line, lowerLine ); } else { LOG.error( I18n.err( I18n.ERR_13402_EXPECTING_ATTRIBUTE_TYPE ) ); throw new LdapLdifException( I18n.err( I18n.ERR_13441_BAD_ATTRIBUTE ) ); } } if ( LOG.isDebugEnabled() ) { LOG.debug( I18n.msg( I18n.MSG_13405_READ_ATTR, entry ) ); } return entry; }
LdifAttributesReader extends LdifReader { private Entry parseEntry( SchemaManager schemaManager ) throws LdapLdifException { if ( ( lines == null ) || lines.isEmpty() ) { if ( LOG.isDebugEnabled() ) { LOG.debug( I18n.msg( I18n.MSG_13408_END_OF_LDIF ) ); } return null; } Entry entry = new DefaultEntry( schemaManager ); for ( String line : lines ) { String lowerLine = Strings.toLowerCaseAscii( line ); if ( lowerLine.startsWith( "control:" ) ) { LOG.error( I18n.err( I18n.ERR_13401_CHANGE_NOT_ALLOWED ) ); throw new LdapLdifException( I18n.err( I18n.ERR_13440_NO_CHANGE ) ); } else if ( lowerLine.startsWith( "changetype:" ) ) { LOG.error( I18n.err( I18n.ERR_13401_CHANGE_NOT_ALLOWED ) ); throw new LdapLdifException( I18n.err( I18n.ERR_13440_NO_CHANGE ) ); } else if ( line.indexOf( ':' ) > 0 ) { parseEntryAttribute( schemaManager, entry, line, lowerLine ); } else { LOG.error( I18n.err( I18n.ERR_13402_EXPECTING_ATTRIBUTE_TYPE ) ); throw new LdapLdifException( I18n.err( I18n.ERR_13441_BAD_ATTRIBUTE ) ); } } if ( LOG.isDebugEnabled() ) { LOG.debug( I18n.msg( I18n.MSG_13405_READ_ATTR, entry ) ); } return entry; } }
LdifAttributesReader extends LdifReader { private Entry parseEntry( SchemaManager schemaManager ) throws LdapLdifException { if ( ( lines == null ) || lines.isEmpty() ) { if ( LOG.isDebugEnabled() ) { LOG.debug( I18n.msg( I18n.MSG_13408_END_OF_LDIF ) ); } return null; } Entry entry = new DefaultEntry( schemaManager ); for ( String line : lines ) { String lowerLine = Strings.toLowerCaseAscii( line ); if ( lowerLine.startsWith( "control:" ) ) { LOG.error( I18n.err( I18n.ERR_13401_CHANGE_NOT_ALLOWED ) ); throw new LdapLdifException( I18n.err( I18n.ERR_13440_NO_CHANGE ) ); } else if ( lowerLine.startsWith( "changetype:" ) ) { LOG.error( I18n.err( I18n.ERR_13401_CHANGE_NOT_ALLOWED ) ); throw new LdapLdifException( I18n.err( I18n.ERR_13440_NO_CHANGE ) ); } else if ( line.indexOf( ':' ) > 0 ) { parseEntryAttribute( schemaManager, entry, line, lowerLine ); } else { LOG.error( I18n.err( I18n.ERR_13402_EXPECTING_ATTRIBUTE_TYPE ) ); throw new LdapLdifException( I18n.err( I18n.ERR_13441_BAD_ATTRIBUTE ) ); } } if ( LOG.isDebugEnabled() ) { LOG.debug( I18n.msg( I18n.MSG_13405_READ_ATTR, entry ) ); } return entry; } LdifAttributesReader(); }
LdifAttributesReader extends LdifReader { private Entry parseEntry( SchemaManager schemaManager ) throws LdapLdifException { if ( ( lines == null ) || lines.isEmpty() ) { if ( LOG.isDebugEnabled() ) { LOG.debug( I18n.msg( I18n.MSG_13408_END_OF_LDIF ) ); } return null; } Entry entry = new DefaultEntry( schemaManager ); for ( String line : lines ) { String lowerLine = Strings.toLowerCaseAscii( line ); if ( lowerLine.startsWith( "control:" ) ) { LOG.error( I18n.err( I18n.ERR_13401_CHANGE_NOT_ALLOWED ) ); throw new LdapLdifException( I18n.err( I18n.ERR_13440_NO_CHANGE ) ); } else if ( lowerLine.startsWith( "changetype:" ) ) { LOG.error( I18n.err( I18n.ERR_13401_CHANGE_NOT_ALLOWED ) ); throw new LdapLdifException( I18n.err( I18n.ERR_13440_NO_CHANGE ) ); } else if ( line.indexOf( ':' ) > 0 ) { parseEntryAttribute( schemaManager, entry, line, lowerLine ); } else { LOG.error( I18n.err( I18n.ERR_13402_EXPECTING_ATTRIBUTE_TYPE ) ); throw new LdapLdifException( I18n.err( I18n.ERR_13441_BAD_ATTRIBUTE ) ); } } if ( LOG.isDebugEnabled() ) { LOG.debug( I18n.msg( I18n.MSG_13405_READ_ATTR, entry ) ); } return entry; } LdifAttributesReader(); Attributes parseAttributes( String ldif ); Entry parseEntry( String ldif ); Entry parseEntry( SchemaManager schemaManager, String ldif ); }
LdifAttributesReader extends LdifReader { private Entry parseEntry( SchemaManager schemaManager ) throws LdapLdifException { if ( ( lines == null ) || lines.isEmpty() ) { if ( LOG.isDebugEnabled() ) { LOG.debug( I18n.msg( I18n.MSG_13408_END_OF_LDIF ) ); } return null; } Entry entry = new DefaultEntry( schemaManager ); for ( String line : lines ) { String lowerLine = Strings.toLowerCaseAscii( line ); if ( lowerLine.startsWith( "control:" ) ) { LOG.error( I18n.err( I18n.ERR_13401_CHANGE_NOT_ALLOWED ) ); throw new LdapLdifException( I18n.err( I18n.ERR_13440_NO_CHANGE ) ); } else if ( lowerLine.startsWith( "changetype:" ) ) { LOG.error( I18n.err( I18n.ERR_13401_CHANGE_NOT_ALLOWED ) ); throw new LdapLdifException( I18n.err( I18n.ERR_13440_NO_CHANGE ) ); } else if ( line.indexOf( ':' ) > 0 ) { parseEntryAttribute( schemaManager, entry, line, lowerLine ); } else { LOG.error( I18n.err( I18n.ERR_13402_EXPECTING_ATTRIBUTE_TYPE ) ); throw new LdapLdifException( I18n.err( I18n.ERR_13441_BAD_ATTRIBUTE ) ); } } if ( LOG.isDebugEnabled() ) { LOG.debug( I18n.msg( I18n.MSG_13405_READ_ATTR, entry ) ); } return entry; } LdifAttributesReader(); Attributes parseAttributes( String ldif ); Entry parseEntry( String ldif ); Entry parseEntry( SchemaManager schemaManager, String ldif );  }