@Test public void testLdifParserRFC2849Sample5() throws NamingException, Exception { String ldif = "objectclass: top\n" + "objectclass: person\n" + "objectclass: organizationalPerson\n" + "cn: Horatio Jensen\n" + "cn: Horatio N Jensen\n" + "sn: Jensen\n" + "uid: hjensen\n" + "telephonenumber: +1 408 555 1212\n" + "jpegphoto:< file:" + HJENSEN_JPEG_FILE.getAbsolutePath() + "\n"; LdifAttributesReader reader = new LdifAttributesReader(); Attributes attributes = reader.parseAttributes( ldif ); String[][] values = { { "objectclass", "top" }, { "objectclass", "person" }, { "objectclass", "organizationalPerson" }, { "cn", "Horatio Jensen" }, { "cn", "Horatio N Jensen" }, { "sn", "Jensen" }, { "uid", "hjensen" }, { "telephonenumber", "+1 408 555 1212" }, { "jpegphoto", null } }; for ( int i = 0; i < values.length; i++ ) { if ( "jpegphoto".equalsIgnoreCase( values[i][0] ) ) { javax.naming.directory.Attribute attr = attributes.get( values[i][0] ); assertEquals( Strings.dumpBytes( data ), Strings.dumpBytes( ( byte[] ) attr.get() ) ); } else { javax.naming.directory.Attribute attr = attributes.get( values[i][0] ); if ( attr.contains( values[i][1] ) ) { assertTrue( true ); } else { assertTrue( attr.contains( values[i][1].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 );  }