/** * Convert a LDIF String to a JNDI attributes. * * @param ldif The LDIF string containing an attribute value * @return An Attributes instance * @exception LdapLdifException If the LDIF String cannot be converted to an Attributes */ public static Attributes getJndiAttributesFromLdif( String ldif ) throws LdapLdifException { try ( LdifAttributesReader reader = new LdifAttributesReader() ) { return AttributeUtils.toAttributes( reader.parseEntry( ldif ) ); } catch ( IOException ioe ) { throw new LdapLdifException( ioe.getMessage(), ioe ); } }
/** * Parse an AttributeType/AttributeValue * * @param attributes The entry where to store the value * @param line The line to parse * @param lowerLine The same line, lowercased * @throws LdapLdifException If anything goes wrong */ private void parseAttribute( Attributes attributes, String line, String lowerLine ) throws LdapLdifException { int colonIndex = line.indexOf( ':' ); String attributeType = lowerLine.substring( 0, colonIndex ); // We should *not* have a Dn twice if ( "dn".equals( attributeType ) ) { LOG.error( I18n.err( I18n.ERR_13400_ENTRY_WITH_TWO_DNS ) ); throw new LdapLdifException( I18n.err( I18n.ERR_13439_LDIF_ENTRY_WITH_TWO_DNS ) ); } Object attributeValue = parseValue( attributeType, line, colonIndex ); // Update the entry javax.naming.directory.Attribute attribute = attributes.get( attributeType ); if ( attribute == null ) { attributes.put( attributeType, attributeValue ); } else { attribute.add( attributeValue ); } }
readLines(); Entry entry = parseEntry( schemaManager );
readLines(); Attributes attributes = parseAttributes();
parseEntryAttribute( schemaManager, entry, line, lowerLine );
parseAttribute( attributes, line, lowerLine );
readLines(); Entry entry = parseEntry( ( SchemaManager ) null );
readLines(); Attributes attributes = parseAttributes();
parseEntryAttribute( schemaManager, entry, line, lowerLine );
parseAttribute( attributes, line, lowerLine );
/** * Convert a LDIF String to a JNDI attributes. * * @param ldif The LDIF string containing an attribute value * @return An Attributes instance * @exception LdapLdifException If the LDIF String cannot be converted to an Attributes */ public static Attributes getJndiAttributesFromLdif( String ldif ) throws LdapLdifException { try ( LdifAttributesReader reader = new LdifAttributesReader() ) { return AttributeUtils.toAttributes( reader.parseEntry( ldif ) ); } catch ( IOException ioe ) { throw new LdapLdifException( ioe.getMessage(), ioe ); } }
readLines(); Entry entry = parseEntry( ( SchemaManager ) null );
readLines(); Attributes attributes = parseAttributes();
/** * Parse an AttributeType/AttributeValue * * @param attributes The entry where to store the value * @param line The line to parse * @param lowerLine The same line, lowercased * @throws LdapLdifException If anything goes wrong */ private void parseAttribute( Attributes attributes, String line, String lowerLine ) throws LdapLdifException { int colonIndex = line.indexOf( ':' ); String attributeType = lowerLine.substring( 0, colonIndex ); // We should *not* have a Dn twice if ( "dn".equals( attributeType ) ) { LOG.error( I18n.err( I18n.ERR_13400_ENTRY_WITH_TWO_DNS ) ); throw new LdapLdifException( I18n.err( I18n.ERR_13439_LDIF_ENTRY_WITH_TWO_DNS ) ); } Object attributeValue = parseValue( attributeType, line, colonIndex ); // Update the entry javax.naming.directory.Attribute attribute = attributes.get( attributeType ); if ( attribute == null ) { attributes.put( attributeType, attributeValue ); } else { attribute.add( attributeValue ); } }
parseEntryAttribute( schemaManager, entry, line, lowerLine );
parseAttribute( attributes, line, lowerLine );
/** * Convert a LDIF String to a JNDI attributes. * * @param ldif The LDIF string containing an attribute value * @return An Attributes instance * @exception LdapLdifException If the LDIF String cannot be converted to an Attributes */ public static Attributes getJndiAttributesFromLdif( String ldif ) throws LdapLdifException { try ( LdifAttributesReader reader = new LdifAttributesReader() ) { return AttributeUtils.toAttributes( reader.parseEntry( ldif ) ); } catch ( IOException ioe ) { throw new LdapLdifException( ioe.getMessage(), ioe ); } }
readLines(); Entry entry = parseEntry( ( SchemaManager ) null );
/** * Parse an AttributeType/AttributeValue * * @param attributes The entry where to store the value * @param line The line to parse * @param lowerLine The same line, lowercased * @throws LdapLdifException If anything goes wrong */ private void parseAttribute( Attributes attributes, String line, String lowerLine ) throws LdapLdifException { int colonIndex = line.indexOf( ':' ); String attributeType = lowerLine.substring( 0, colonIndex ); // We should *not* have a Dn twice if ( "dn".equals( attributeType ) ) { LOG.error( I18n.err( I18n.ERR_13400_ENTRY_WITH_TWO_DNS ) ); throw new LdapLdifException( I18n.err( I18n.ERR_13439_LDIF_ENTRY_WITH_TWO_DNS ) ); } Object attributeValue = parseValue( attributeType, line, colonIndex ); // Update the entry javax.naming.directory.Attribute attribute = attributes.get( attributeType ); if ( attribute == null ) { attributes.put( attributeType, attributeValue ); } else { attribute.add( attributeValue ); } }
try ( LdifAttributesReader reader = new LdifAttributesReader() ) return reader.parseEntry( schemaManager, sb.toString() );