@Test public void testLdifParserRFC2849Sample4() throws NamingException, Exception { String ldif = "# dn:: ou=���������,o=Airius\n" + "objectclass: top\n" + "objectclass: organizationalUnit\n" + "ou:: 5Za25qWt6YOo\n" + "# ou:: ���������\n" + "ou;lang-ja:: 5Za25qWt6YOo\n" + "# ou;lang-ja:: ���������\n" + "ou;lang-ja;phonetic:: 44GI44GE44GO44KH44GG44G2\n" + "# ou;lang-ja:: ������������������\n" + "ou;lang-en: Sales\n" + "description: Japanese office\n"; LdifAttributesReader reader = new LdifAttributesReader(); Attributes attributes = reader.parseAttributes( ldif ); String[][] values = { { "objectclass", "top" }, { "objectclass", "organizationalUnit" }, { "ou", "\u55b6\u696d\u90e8" }, { "ou;lang-ja", "\u55b6\u696d\u90e8" }, { "ou;lang-ja;phonetic", "\u3048\u3044\u304e\u3087\u3046\u3076" }, { "ou;lang-en", "Sales" }, { "description", "Japanese office" } }; for ( int j = 0; j < values.length; j++ ) { javax.naming.directory.Attribute attr = attributes.get( values[j][0] ); if ( attr.contains( values[j][1] ) ) { assertTrue( true ); } else { assertTrue( attr.contains( values[j][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 );  }