| | |
| | | |
| | | |
| | | /** |
| | | * An LDIF entry writer writes attribute value records (entries) using |
| | | * the LDAP Data Interchange Format (LDIF) to a user defined |
| | | * destination. |
| | | * An LDIF entry writer writes attribute value records (entries) using the LDAP |
| | | * Data Interchange Format (LDIF) to a user defined destination. |
| | | * |
| | | * @see <a href="http://tools.ietf.org/html/rfc2849">RFC 2849 - The LDAP |
| | | * Data Interchange Format (LDIF) - Technical Specification </a> |
| | | * @see <a href="http://tools.ietf.org/html/rfc2849">RFC 2849 - The LDAP Data |
| | | * Interchange Format (LDIF) - Technical Specification </a> |
| | | */ |
| | | public final class LDIFEntryWriter extends AbstractLDIFWriter implements |
| | | EntryWriter |
| | | { |
| | | |
| | | /** |
| | | * Creates a new LDIF entry writer which will append lines of LDIF to |
| | | * the provided list. |
| | | * Creates a new LDIF entry writer which will append lines of LDIF to the |
| | | * provided list. |
| | | * |
| | | * @param ldifLines |
| | | * The list to which lines of LDIF should be appended. |
| | | */ |
| | | public LDIFEntryWriter(List<String> ldifLines) |
| | | public LDIFEntryWriter(final List<String> ldifLines) |
| | | { |
| | | super(ldifLines); |
| | | } |
| | |
| | | |
| | | |
| | | /** |
| | | * Creates a new LDIF entry writer whose destination is the provided |
| | | * output stream. |
| | | * Creates a new LDIF entry writer whose destination is the provided output |
| | | * stream. |
| | | * |
| | | * @param out |
| | | * The output stream to use. |
| | | */ |
| | | public LDIFEntryWriter(OutputStream out) |
| | | public LDIFEntryWriter(final OutputStream out) |
| | | { |
| | | super(out); |
| | | } |
| | |
| | | |
| | | |
| | | /** |
| | | * Specifies whether or not user-friendly comments should be added |
| | | * whenever distinguished names or UTF-8 attribute values are |
| | | * encountered which contained non-ASCII characters. The default is |
| | | * {@code false}. |
| | | * Specifies whether or not user-friendly comments should be added whenever |
| | | * distinguished names or UTF-8 attribute values are encountered which |
| | | * contained non-ASCII characters. The default is {@code false}. |
| | | * |
| | | * @param addUserFriendlyComments |
| | | * {@code true} if user-friendly comments should be added, or |
| | | * {@code false} otherwise. |
| | | * {@code true} if user-friendly comments should be added, or {@code |
| | | * false} otherwise. |
| | | * @return A reference to this {@code LDIFEntryWriter}. |
| | | */ |
| | | public LDIFEntryWriter setAddUserFriendlyComments( |
| | | boolean addUserFriendlyComments) |
| | | final boolean addUserFriendlyComments) |
| | | { |
| | | this.addUserFriendlyComments = addUserFriendlyComments; |
| | | return this; |
| | |
| | | |
| | | |
| | | /** |
| | | * Specifies whether or not all operational attributes should be |
| | | * excluded from any entries that are written to LDIF. The default is |
| | | * {@code false}. |
| | | * Specifies whether or not all operational attributes should be excluded from |
| | | * any entries that are written to LDIF. The default is {@code false}. |
| | | * |
| | | * @param excludeOperationalAttributes |
| | | * {@code true} if all operational attributes should be |
| | | * excluded, or {@code false} otherwise. |
| | | * {@code true} if all operational attributes should be excluded, or |
| | | * {@code false} otherwise. |
| | | * @return A reference to this {@code LDIFEntryWriter}. |
| | | */ |
| | | public LDIFEntryWriter setExcludeAllOperationalAttributes( |
| | | boolean excludeOperationalAttributes) |
| | | final boolean excludeOperationalAttributes) |
| | | { |
| | | this.excludeOperationalAttributes = excludeOperationalAttributes; |
| | | return this; |
| | |
| | | |
| | | |
| | | /** |
| | | * Specifies whether or not all user attributes should be excluded |
| | | * from any entries that are written to LDIF. The default is {@code |
| | | * false}. |
| | | * Specifies whether or not all user attributes should be excluded from any |
| | | * entries that are written to LDIF. The default is {@code false}. |
| | | * |
| | | * @param excludeUserAttributes |
| | | * {@code true} if all user attributes should be excluded, or |
| | | * {@code false} otherwise. |
| | | * {@code true} if all user attributes should be excluded, or {@code |
| | | * false} otherwise. |
| | | * @return A reference to this {@code LDIFEntryWriter}. |
| | | */ |
| | | public LDIFEntryWriter setExcludeAllUserAttributes( |
| | | boolean excludeUserAttributes) |
| | | final boolean excludeUserAttributes) |
| | | { |
| | | this.excludeUserAttributes = excludeUserAttributes; |
| | | return this; |
| | |
| | | |
| | | |
| | | /** |
| | | * Excludes the named attribute from any entries that are written to |
| | | * LDIF. By default all attributes are included unless explicitly |
| | | * excluded. |
| | | * Excludes the named attribute from any entries that are written to LDIF. By |
| | | * default all attributes are included unless explicitly excluded. |
| | | * |
| | | * @param attributeDescription |
| | | * The name of the attribute to be excluded. |
| | | * @return A reference to this {@code LDIFEntryWriter}. |
| | | */ |
| | | public LDIFEntryWriter setExcludeAttribute( |
| | | AttributeDescription attributeDescription) |
| | | final AttributeDescription attributeDescription) |
| | | { |
| | | Validator.ensureNotNull(attributeDescription); |
| | | excludeAttributes.add(attributeDescription); |
| | |
| | | |
| | | |
| | | /** |
| | | * Excludes all entries beneath the named entry (inclusive) from being |
| | | * written to LDIF. By default all entries are written unless |
| | | * explicitly excluded or included by branches or filters. |
| | | * Excludes all entries beneath the named entry (inclusive) from being written |
| | | * to LDIF. By default all entries are written unless explicitly excluded or |
| | | * included by branches or filters. |
| | | * |
| | | * @param excludeBranch |
| | | * The distinguished name of the branch to be excluded. |
| | | * @return A reference to this {@code LDIFEntryWriter}. |
| | | */ |
| | | public LDIFEntryWriter setExcludeBranch(DN excludeBranch) |
| | | public LDIFEntryWriter setExcludeBranch(final DN excludeBranch) |
| | | { |
| | | Validator.ensureNotNull(excludeBranch); |
| | | excludeBranches.add(excludeBranch); |
| | |
| | | |
| | | |
| | | /** |
| | | * Excludes all entries which match the provided filter matcher from |
| | | * being written to LDIF. By default all entries are written unless |
| | | * explicitly excluded or included by branches or filters. |
| | | * Excludes all entries which match the provided filter matcher from being |
| | | * written to LDIF. By default all entries are written unless explicitly |
| | | * excluded or included by branches or filters. |
| | | * |
| | | * @param excludeFilter |
| | | * The filter matcher. |
| | | * @return A reference to this {@code LDIFEntryWriter}. |
| | | */ |
| | | public LDIFEntryWriter setExcludeFilter(Matcher excludeFilter) |
| | | public LDIFEntryWriter setExcludeFilter(final Matcher excludeFilter) |
| | | { |
| | | Validator.ensureNotNull(excludeFilter); |
| | | excludeFilters.add(excludeFilter); |
| | |
| | | |
| | | |
| | | /** |
| | | * Ensures that the named attribute is not excluded from any entries |
| | | * that are written to LDIF. By default all attributes are included |
| | | * unless explicitly excluded. |
| | | * Ensures that the named attribute is not excluded from any entries that are |
| | | * written to LDIF. By default all attributes are included unless explicitly |
| | | * excluded. |
| | | * |
| | | * @param attributeDescription |
| | | * The name of the attribute to be included. |
| | | * @return A reference to this {@code LDIFEntryWriter}. |
| | | */ |
| | | public LDIFEntryWriter setIncludeAttribute( |
| | | AttributeDescription attributeDescription) |
| | | final AttributeDescription attributeDescription) |
| | | { |
| | | Validator.ensureNotNull(attributeDescription); |
| | | includeAttributes.add(attributeDescription); |
| | |
| | | |
| | | |
| | | /** |
| | | * Ensures that all entries beneath the named entry (inclusive) are |
| | | * written to LDIF. By default all entries are written unless |
| | | * explicitly excluded or included by branches or filters. |
| | | * Ensures that all entries beneath the named entry (inclusive) are written to |
| | | * LDIF. By default all entries are written unless explicitly excluded or |
| | | * included by branches or filters. |
| | | * |
| | | * @param includeBranch |
| | | * The distinguished name of the branch to be included. |
| | | * @return A reference to this {@code LDIFEntryWriter}. |
| | | */ |
| | | public LDIFEntryWriter setIncludeBranch(DN includeBranch) |
| | | public LDIFEntryWriter setIncludeBranch(final DN includeBranch) |
| | | { |
| | | Validator.ensureNotNull(includeBranch); |
| | | includeBranches.add(includeBranch); |
| | |
| | | |
| | | |
| | | /** |
| | | * Ensures that all entries which match the provided filter matcher |
| | | * are written to LDIF. By default all entries are written unless |
| | | * explicitly excluded or included by branches or filters. |
| | | * Ensures that all entries which match the provided filter matcher are |
| | | * written to LDIF. By default all entries are written unless explicitly |
| | | * excluded or included by branches or filters. |
| | | * |
| | | * @param includeFilter |
| | | * The filter matcher. |
| | | * @return A reference to this {@code LDIFEntryWriter}. |
| | | */ |
| | | public LDIFEntryWriter setIncludeFilter(Matcher includeFilter) |
| | | public LDIFEntryWriter setIncludeFilter(final Matcher includeFilter) |
| | | { |
| | | Validator.ensureNotNull(includeFilter); |
| | | includeFilters.add(includeFilter); |
| | |
| | | |
| | | |
| | | /** |
| | | * Sets the schema which should be used when filtering entries (not |
| | | * required if no filtering is to be performed). The default schema is |
| | | * used if no other is specified. |
| | | * Sets the schema which should be used when filtering entries (not required |
| | | * if no filtering is to be performed). The default schema is used if no other |
| | | * is specified. |
| | | * |
| | | * @param schema |
| | | * The schema which should be used when filtering entries. |
| | | * @return A reference to this {@code LDIFEntryWriter}. |
| | | */ |
| | | public LDIFEntryWriter setSchema(Schema schema) |
| | | public LDIFEntryWriter setSchema(final Schema schema) |
| | | { |
| | | Validator.ensureNotNull(schema); |
| | | this.schema = schema; |
| | |
| | | |
| | | |
| | | /** |
| | | * Specifies the column at which long lines should be wrapped. A value |
| | | * less than or equal to zero (the default) indicates that no wrapping |
| | | * should be performed. |
| | | * Specifies the column at which long lines should be wrapped. A value less |
| | | * than or equal to zero (the default) indicates that no wrapping should be |
| | | * performed. |
| | | * |
| | | * @param wrapColumn |
| | | * The column at which long lines should be wrapped. |
| | | * @return A reference to this {@code LDIFEntryWriter}. |
| | | */ |
| | | public LDIFEntryWriter setWrapColumn(int wrapColumn) |
| | | public LDIFEntryWriter setWrapColumn(final int wrapColumn) |
| | | { |
| | | this.wrapColumn = wrapColumn; |
| | | return this; |
| | |
| | | /** |
| | | * {@inheritDoc} |
| | | */ |
| | | public LDIFEntryWriter writeComment(CharSequence comment) |
| | | public LDIFEntryWriter writeComment(final CharSequence comment) |
| | | throws IOException, NullPointerException |
| | | { |
| | | writeComment0(comment); |
| | |
| | | /** |
| | | * {@inheritDoc} |
| | | */ |
| | | public LDIFEntryWriter writeEntry(Entry entry) throws IOException, |
| | | public LDIFEntryWriter writeEntry(final Entry entry) throws IOException, |
| | | NullPointerException |
| | | { |
| | | Validator.ensureNotNull(entry); |
| | |
| | | } |
| | | |
| | | writeKeyAndValue("dn", entry.getName().toString()); |
| | | for (final Attribute attribute : entry.getAttributes()) |
| | | for (final Attribute attribute : entry.getAllAttributes()) |
| | | { |
| | | // Filter the attribute if required. |
| | | if (isAttributeExcluded(attribute.getAttributeDescription())) |
| | |
| | | continue; |
| | | } |
| | | |
| | | final String attributeDescription = |
| | | attribute.getAttributeDescriptionAsString(); |
| | | final String attributeDescription = attribute |
| | | .getAttributeDescriptionAsString(); |
| | | for (final ByteString value : attribute) |
| | | { |
| | | writeKeyAndValue(attributeDescription, value); |