@Test public void testLdifParserWithNullDn() throws Exception, Exception { String ldif1 = "dn: ads-authenticatorid=anonymousauthenticator,ou=authenticators,ads-interceptorId=authenticationInterceptor,ou=interceptors,ads-directoryServiceId=default,ou=config\n" + "ads-authenticatorid: anonymousauthenticator\n" + "objectclass: top\n" + "objectclass: ads-base\n" + "objectClass: ads-authenticator\n" + "objectClass: ads-authenticatorImpl\n" + "ads-authenticatorClass: org.apache.directory.server.core.authn.AnonymousAuthenticator\n" + "ads-baseDn: \n" + "ads-enabled: TRUE"; String ldif2 = "dn: ads-authenticatorid=anonymousauthenticator,ou=authenticators,ads-interceptorId=authenticationInterceptor,ou=interceptors,ads-directoryServiceId=default,ou=config\n" + "ads-authenticatorid: anonymousauthenticator\n" + "objectclass: top\n" + "objectclass: ads-base\n" + "objectClass: ads-authenticator\n" + "objectClass: ads-authenticatorImpl\n" + "ads-authenticatorClass: org.apache.directory.server.core.authn.AnonymousAuthenticator\n" + "ads-baseDn:\n" + "ads-enabled: TRUE"; try ( LdifReader reader = new LdifReader() ) { List<LdifEntry> entries1 = reader.parseLdif( ldif1 ); LdifEntry entry1 = entries1.get( 0 ); List<LdifEntry> entries2 = reader.parseLdif( ldif2 ); LdifEntry entry2 = entries2.get( 0 ); assertEquals( entry1, entry2 ); } }
public List<LdifEntry> parseLdif( String ldif ) throws LdapLdifException { if ( LOG.isDebugEnabled() ) { LOG.debug( I18n.msg( I18n.MSG_13407_STARTS_PARSING_LDIF ) ); } if ( Strings.isEmpty( ldif ) ) { return new ArrayList<>(); } try ( BufferedReader bufferReader = new BufferedReader( new StringReader( ldif ) ) ) { List<LdifEntry> entries = parseLdif( bufferReader ); if ( LOG.isDebugEnabled() ) { LOG.debug( I18n.msg( I18n.MSG_13403_PARSED_N_ENTRIES, Integer.valueOf( entries.size() ) ) ); } return entries; } catch ( LdapLdifException ne ) { LOG.error( I18n.err( I18n.ERR_13428_CANNOT_PARSE_LDIF, ne.getLocalizedMessage() ) ); throw new LdapLdifException( I18n.err( I18n.ERR_13442_ERROR_PARSING_LDIF_BUFFER ), ne ); } catch ( LdapException le ) { throw new LdapLdifException( le.getMessage(), le ); } catch ( IOException ioe ) { throw new LdapLdifException( I18n.err( I18n.ERR_13450_CANNOT_CLOSE_FILE ), ioe ); } }
LdifReader implements Iterable<LdifEntry>, Closeable { public List<LdifEntry> parseLdif( String ldif ) throws LdapLdifException { if ( LOG.isDebugEnabled() ) { LOG.debug( I18n.msg( I18n.MSG_13407_STARTS_PARSING_LDIF ) ); } if ( Strings.isEmpty( ldif ) ) { return new ArrayList<>(); } try ( BufferedReader bufferReader = new BufferedReader( new StringReader( ldif ) ) ) { List<LdifEntry> entries = parseLdif( bufferReader ); if ( LOG.isDebugEnabled() ) { LOG.debug( I18n.msg( I18n.MSG_13403_PARSED_N_ENTRIES, Integer.valueOf( entries.size() ) ) ); } return entries; } catch ( LdapLdifException ne ) { LOG.error( I18n.err( I18n.ERR_13428_CANNOT_PARSE_LDIF, ne.getLocalizedMessage() ) ); throw new LdapLdifException( I18n.err( I18n.ERR_13442_ERROR_PARSING_LDIF_BUFFER ), ne ); } catch ( LdapException le ) { throw new LdapLdifException( le.getMessage(), le ); } catch ( IOException ioe ) { throw new LdapLdifException( I18n.err( I18n.ERR_13450_CANNOT_CLOSE_FILE ), ioe ); } } }
LdifReader implements Iterable<LdifEntry>, Closeable { public List<LdifEntry> parseLdif( String ldif ) throws LdapLdifException { if ( LOG.isDebugEnabled() ) { LOG.debug( I18n.msg( I18n.MSG_13407_STARTS_PARSING_LDIF ) ); } if ( Strings.isEmpty( ldif ) ) { return new ArrayList<>(); } try ( BufferedReader bufferReader = new BufferedReader( new StringReader( ldif ) ) ) { List<LdifEntry> entries = parseLdif( bufferReader ); if ( LOG.isDebugEnabled() ) { LOG.debug( I18n.msg( I18n.MSG_13403_PARSED_N_ENTRIES, Integer.valueOf( entries.size() ) ) ); } return entries; } catch ( LdapLdifException ne ) { LOG.error( I18n.err( I18n.ERR_13428_CANNOT_PARSE_LDIF, ne.getLocalizedMessage() ) ); throw new LdapLdifException( I18n.err( I18n.ERR_13442_ERROR_PARSING_LDIF_BUFFER ), ne ); } catch ( LdapException le ) { throw new LdapLdifException( le.getMessage(), le ); } catch ( IOException ioe ) { throw new LdapLdifException( I18n.err( I18n.ERR_13450_CANNOT_CLOSE_FILE ), ioe ); } } LdifReader();  LdifReader( SchemaManager schemaManager );  LdifReader( String ldifFileName );  LdifReader( Reader in );  LdifReader( InputStream in );  LdifReader( File file );  LdifReader( File file, SchemaManager schemaManager ); }
LdifReader implements Iterable<LdifEntry>, Closeable { public List<LdifEntry> parseLdif( String ldif ) throws LdapLdifException { if ( LOG.isDebugEnabled() ) { LOG.debug( I18n.msg( I18n.MSG_13407_STARTS_PARSING_LDIF ) ); } if ( Strings.isEmpty( ldif ) ) { return new ArrayList<>(); } try ( BufferedReader bufferReader = new BufferedReader( new StringReader( ldif ) ) ) { List<LdifEntry> entries = parseLdif( bufferReader ); if ( LOG.isDebugEnabled() ) { LOG.debug( I18n.msg( I18n.MSG_13403_PARSED_N_ENTRIES, Integer.valueOf( entries.size() ) ) ); } return entries; } catch ( LdapLdifException ne ) { LOG.error( I18n.err( I18n.ERR_13428_CANNOT_PARSE_LDIF, ne.getLocalizedMessage() ) ); throw new LdapLdifException( I18n.err( I18n.ERR_13442_ERROR_PARSING_LDIF_BUFFER ), ne ); } catch ( LdapException le ) { throw new LdapLdifException( le.getMessage(), le ); } catch ( IOException ioe ) { throw new LdapLdifException( I18n.err( I18n.ERR_13450_CANNOT_CLOSE_FILE ), ioe ); } } LdifReader();  LdifReader( SchemaManager schemaManager );  LdifReader( String ldifFileName );  LdifReader( Reader in );  LdifReader( InputStream in );  LdifReader( File file );  LdifReader( File file, SchemaManager schemaManager ); void init(); int getVersion(); long getSizeLimit(); void setSizeLimit( long sizeLimit ); static Attribute parseAttributeValue( String line ); void parseAttributeValue( LdifEntry entry, String line, String lowerLine ); List<LdifEntry> parseLdifFile( String fileName ); List<LdifEntry> parseLdifFile( String fileName, String encoding ); List<LdifEntry> parseLdif( String ldif ); LdifEntry next(); LdifEntry fetch(); boolean hasNext(); void remove(); @Override Iterator<LdifEntry> iterator(); boolean hasError(); Exception getError(); List<LdifEntry> parseLdif( BufferedReader reader ); boolean containsEntries(); int getLineNumber(); boolean isValidateDn(); void setValidateDn( boolean validateDn ); void setSchemaManager( SchemaManager schemaManager ); @Override void close(); }
LdifReader implements Iterable<LdifEntry>, Closeable { public List<LdifEntry> parseLdif( String ldif ) throws LdapLdifException { if ( LOG.isDebugEnabled() ) { LOG.debug( I18n.msg( I18n.MSG_13407_STARTS_PARSING_LDIF ) ); } if ( Strings.isEmpty( ldif ) ) { return new ArrayList<>(); } try ( BufferedReader bufferReader = new BufferedReader( new StringReader( ldif ) ) ) { List<LdifEntry> entries = parseLdif( bufferReader ); if ( LOG.isDebugEnabled() ) { LOG.debug( I18n.msg( I18n.MSG_13403_PARSED_N_ENTRIES, Integer.valueOf( entries.size() ) ) ); } return entries; } catch ( LdapLdifException ne ) { LOG.error( I18n.err( I18n.ERR_13428_CANNOT_PARSE_LDIF, ne.getLocalizedMessage() ) ); throw new LdapLdifException( I18n.err( I18n.ERR_13442_ERROR_PARSING_LDIF_BUFFER ), ne ); } catch ( LdapException le ) { throw new LdapLdifException( le.getMessage(), le ); } catch ( IOException ioe ) { throw new LdapLdifException( I18n.err( I18n.ERR_13450_CANNOT_CLOSE_FILE ), ioe ); } } LdifReader();  LdifReader( SchemaManager schemaManager );  LdifReader( String ldifFileName );  LdifReader( Reader in );  LdifReader( InputStream in );  LdifReader( File file );  LdifReader( File file, SchemaManager schemaManager ); void init(); int getVersion(); long getSizeLimit(); void setSizeLimit( long sizeLimit ); static Attribute parseAttributeValue( String line ); void parseAttributeValue( LdifEntry entry, String line, String lowerLine ); List<LdifEntry> parseLdifFile( String fileName ); List<LdifEntry> parseLdifFile( String fileName, String encoding ); List<LdifEntry> parseLdif( String ldif ); LdifEntry next(); LdifEntry fetch(); boolean hasNext(); void remove(); @Override Iterator<LdifEntry> iterator(); boolean hasError(); Exception getError(); List<LdifEntry> parseLdif( BufferedReader reader ); boolean containsEntries(); int getLineNumber(); boolean isValidateDn(); void setValidateDn( boolean validateDn ); void setSchemaManager( SchemaManager schemaManager ); @Override void close();  }