@Test public void testLdifParserRFC2849Sample3VariousSpacing() throws LdapLdifException, Exception { String ldif = "objectclass:top\n" + "objectclass: person \n" + "objectclass:organizationalPerson\n" + "cn:Gern Jensen\n" + "cn:Gern O Jensen\n" + "sn:Jensen\n" + "uid:gernj\n" + "telephonenumber:+1 408 555 1212 \n" + "description:: V2hhdCBhIGNhcmVmdWwgcmVhZGVyIHlvdSBhcmUhICBUaGlzIHZhbHVl\n" + " IGlzIGJhc2UtNjQtZW5jb2RlZCBiZWNhdXNlIGl0IGhhcyBhIGNvbnRyb2wgY2hhcmFjdG\n" + " VyIGluIGl0IChhIENSKS4NICBCeSB0aGUgd2F5LCB5b3Ugc2hvdWxkIHJlYWxseSBnZXQg\n" + " b3V0IG1vcmUu "; LdifAttributesReader reader = new LdifAttributesReader(); Attributes attributes = reader.parseAttributes( ldif ); javax.naming.directory.Attribute attr = attributes.get( "objectclass" ); assertTrue( attr.contains( "top" ) ); assertTrue( attr.contains( "person" ) ); assertTrue( attr.contains( "organizationalPerson" ) ); attr = attributes.get( "cn" ); assertTrue( attr.contains( "Gern Jensen" ) ); assertTrue( attr.contains( "Gern O Jensen" ) ); attr = attributes.get( "sn" ); assertTrue( attr.contains( "Jensen" ) ); attr = attributes.get( "uid" ); assertTrue( attr.contains( "gernj" ) ); attr = attributes.get( "telephonenumber" ); assertTrue( attr.contains( "+1 408 555 1212" ) ); attr = attributes.get( "description" ); assertTrue( attr .contains( "What a careful reader you are! This value is base-64-encoded because it has a control character in it (a CR).\r By the way, you should really get out more." .getBytes( StandardCharsets.UTF_8 ) ) ); reader.close(); }
private Attributes parseAttributes() throws LdapLdifException { if ( ( lines == null ) || lines.isEmpty() ) { if ( LOG.isDebugEnabled() ) { LOG.debug( I18n.msg( I18n.MSG_13408_END_OF_LDIF ) ); } return null; } Attributes attributes = new BasicAttributes( true ); 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 ) { parseAttribute( attributes, 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, attributes ) ); } return attributes; }
LdifAttributesReader extends LdifReader { private Attributes parseAttributes() throws LdapLdifException { if ( ( lines == null ) || lines.isEmpty() ) { if ( LOG.isDebugEnabled() ) { LOG.debug( I18n.msg( I18n.MSG_13408_END_OF_LDIF ) ); } return null; } Attributes attributes = new BasicAttributes( true ); 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 ) { parseAttribute( attributes, 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, attributes ) ); } return attributes; } }
LdifAttributesReader extends LdifReader { private Attributes parseAttributes() throws LdapLdifException { if ( ( lines == null ) || lines.isEmpty() ) { if ( LOG.isDebugEnabled() ) { LOG.debug( I18n.msg( I18n.MSG_13408_END_OF_LDIF ) ); } return null; } Attributes attributes = new BasicAttributes( true ); 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 ) { parseAttribute( attributes, 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, attributes ) ); } return attributes; } LdifAttributesReader(); }
LdifAttributesReader extends LdifReader { private Attributes parseAttributes() throws LdapLdifException { if ( ( lines == null ) || lines.isEmpty() ) { if ( LOG.isDebugEnabled() ) { LOG.debug( I18n.msg( I18n.MSG_13408_END_OF_LDIF ) ); } return null; } Attributes attributes = new BasicAttributes( true ); 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 ) { parseAttribute( attributes, 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, attributes ) ); } return attributes; } LdifAttributesReader(); Attributes parseAttributes( String ldif ); Entry parseEntry( String ldif ); Entry parseEntry( SchemaManager schemaManager, String ldif ); }
LdifAttributesReader extends LdifReader { private Attributes parseAttributes() throws LdapLdifException { if ( ( lines == null ) || lines.isEmpty() ) { if ( LOG.isDebugEnabled() ) { LOG.debug( I18n.msg( I18n.MSG_13408_END_OF_LDIF ) ); } return null; } Attributes attributes = new BasicAttributes( true ); 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 ) { parseAttribute( attributes, 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, attributes ) ); } return attributes; } LdifAttributesReader(); Attributes parseAttributes( String ldif ); Entry parseEntry( String ldif ); Entry parseEntry( SchemaManager schemaManager, String ldif );  }