@Test public void testLdifParserRootDSE() throws Exception { String ldif = "version: 1\n" + "dn:\n" + "cn:: YXBwMQ==\n" + "objectClass: top\n" + "objectClass: apApplication\n" + "displayName: app1 \n" + "dependencies:\n" + "envVars:"; try ( LdifReader reader = new LdifReader() ) { List<LdifEntry> entries = reader.parseLdif( ldif ); assertNotNull( entries ); LdifEntry entry = entries.get( 0 ); assertTrue( entry.isLdifContent() ); assertEquals( "", entry.getDn().getName() ); Attribute attr = entry.get( "cn" ); assertTrue( attr.contains( "app1" ) ); attr = entry.get( "objectclass" ); assertTrue( attr.contains( "top" ) ); assertTrue( attr.contains( "apApplication" ) ); attr = entry.get( "displayname" ); assertTrue( attr.contains( "app1" ) ); attr = entry.get( "dependencies" ); assertEquals( "", attr.get().getString() ); attr = entry.get( "envvars" ); assertEquals( "", attr.get().getString() ); } }
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();  }