| | |
| | | * |
| | | * |
| | | * Copyright 2009 Sun Microsystems, Inc. |
| | | * Portions copyright 2011 ForgeRock AS |
| | | * Portions copyright 2011-2013 ForgeRock AS |
| | | */ |
| | | |
| | | package org.forgerock.opendj.ldif; |
| | |
| | | * Common LDIF reader/writer functionality. |
| | | */ |
| | | abstract class AbstractLDIFStream { |
| | | |
| | | final Set<AttributeDescription> excludeAttributes = new HashSet<AttributeDescription>(); |
| | | |
| | | boolean excludeOperationalAttributes = false; |
| | | |
| | | boolean excludeUserAttributes = false; |
| | | |
| | | final Set<AttributeDescription> includeAttributes = new HashSet<AttributeDescription>(); |
| | | |
| | | final Set<DN> includeBranches = new HashSet<DN>(); |
| | | |
| | | final Set<DN> excludeBranches = new HashSet<DN>(); |
| | | |
| | | final List<Matcher> excludeFilters = new LinkedList<Matcher>(); |
| | | boolean excludeOperationalAttributes = false; |
| | | boolean excludeUserAttributes = false; |
| | | final Set<AttributeDescription> includeAttributes = new HashSet<AttributeDescription>(); |
| | | final Set<DN> includeBranches = new HashSet<DN>(); |
| | | final List<Matcher> includeFilters = new LinkedList<Matcher>(); |
| | | |
| | | final List<Matcher> excludeFilters = new LinkedList<Matcher>(); |
| | | |
| | | /** |
| | | * Creates a new abstract LDIF stream. |
| | | */ |
| | | AbstractLDIFStream() { |
| | | // Nothing to do. |
| | | } |
| | | |
| | | final boolean isAttributeExcluded(final AttributeDescription attributeDescription) { |
| | | // Let explicit include override more general exclude. |
| | | if (!excludeAttributes.isEmpty() && excludeAttributes.contains(attributeDescription)) { |
| | | return true; |
| | | } |
| | | |
| | | // Let explicit include override more general exclude. |
| | | if (!includeAttributes.isEmpty()) { |
| | | } else if (!includeAttributes.isEmpty()) { |
| | | return !includeAttributes.contains(attributeDescription); |
| | | } else { |
| | | final AttributeType type = attributeDescription.getAttributeType(); |
| | | return (excludeOperationalAttributes && type.isOperational()) |
| | | || (excludeUserAttributes && !type.isOperational()); |
| | | } |
| | | |
| | | final AttributeType type = attributeDescription.getAttributeType(); |
| | | |
| | | if (excludeOperationalAttributes && type.isOperational()) { |
| | | return true; |
| | | } |
| | | |
| | | if (excludeUserAttributes && !type.isOperational()) { |
| | | return true; |
| | | } |
| | | |
| | | return false; |
| | | } |
| | | |
| | | final boolean isBranchExcluded(final DN dn) { |
| | |
| | | } |
| | | } |
| | | } |
| | | |
| | | if (!includeBranches.isEmpty()) { |
| | | for (final DN includeBranch : includeBranches) { |
| | | if (includeBranch.isSuperiorOrEqualTo(dn)) { |
| | |
| | | } |
| | | } |
| | | return true; |
| | | } else { |
| | | return false; |
| | | } |
| | | |
| | | return false; |
| | | } |
| | | |
| | | final boolean isEntryExcluded(final Entry entry) { |
| | |
| | | } |
| | | } |
| | | } |
| | | |
| | | if (!includeFilters.isEmpty()) { |
| | | for (final Matcher includeFilter : includeFilters) { |
| | | if (includeFilter.matches(entry).toBoolean()) { |
| | |
| | | } |
| | | } |
| | | return true; |
| | | } else { |
| | | return false; |
| | | } |
| | | |
| | | return false; |
| | | } |
| | | |
| | | } |