| | |
| | | import org.forgerock.i18n.slf4j.LocalizedLogger; |
| | | import org.forgerock.opendj.ldap.ByteSequence; |
| | | import org.forgerock.opendj.ldap.ByteString; |
| | | import org.forgerock.opendj.ldap.DecodeException; |
| | | import org.opends.server.api.SubstringMatchingRule; |
| | | import org.opends.server.core.DirectoryServer; |
| | | import org.opends.server.types.DirectoryException; |
| | | import org.forgerock.opendj.ldap.ResultCode; |
| | | import org.opends.server.util.ServerConstants; |
| | | |
| | | import static org.opends.messages.SchemaMessages.*; |
| | |
| | | * |
| | | * @return The normalized version of the provided value. |
| | | * |
| | | * @throws DirectoryException If the provided value is invalid according to |
| | | * @throws DecodeException If the provided value is invalid according to |
| | | * the associated attribute syntax. |
| | | */ |
| | | @Override |
| | | public ByteString normalizeAttributeValue(ByteSequence value) |
| | | throws DirectoryException |
| | | throws DecodeException |
| | | { |
| | | StringBuilder buffer = new StringBuilder(); |
| | | buffer.append(value.toString().trim()); |
| | |
| | | switch (DirectoryServer.getSyntaxEnforcementPolicy()) |
| | | { |
| | | case REJECT: |
| | | throw new DirectoryException(ResultCode.INVALID_ATTRIBUTE_SYNTAX, |
| | | message); |
| | | throw DecodeException.error(message); |
| | | case WARN: |
| | | if (! logged) |
| | | { |
| | | logger.error(message); |
| | | logged = true; |
| | | } |
| | | |
| | | buffer.delete(pos, pos+1); |
| | | break; |
| | | |
| | | default: |
| | | buffer.delete(pos, pos+1); |
| | | break; |
| | | } |
| | | buffer.delete(pos, pos+1); |
| | | } |
| | | } |
| | | |
| | |
| | | * |
| | | * @return The normalized form of the value fragment. |
| | | * |
| | | * @throws DirectoryException If the provided value fragment is not |
| | | * @throws DecodeException If the provided value fragment is not |
| | | * acceptable according to the associated syntax. |
| | | */ |
| | | @Override |
| | | public ByteString normalizeSubstring(ByteSequence substring) |
| | | throws DirectoryException |
| | | throws DecodeException |
| | | { |
| | | // In this case, the process for normalizing a substring is the same as |
| | | // normalizing a full value with the exception that it may include an |
| | |
| | | switch (DirectoryServer.getSyntaxEnforcementPolicy()) |
| | | { |
| | | case REJECT: |
| | | throw new DirectoryException(ResultCode.INVALID_ATTRIBUTE_SYNTAX, |
| | | message); |
| | | throw DecodeException.error(message); |
| | | case WARN: |
| | | if (! logged) |
| | | { |
| | | logger.error(message); |
| | | logged = true; |
| | | } |
| | | |
| | | buffer.delete(pos, pos+1); |
| | | break; |
| | | |
| | | default: |
| | | buffer.delete(pos, pos+1); |
| | | break; |
| | | } |
| | | buffer.delete(pos, pos + 1); |
| | | } |
| | | } |
| | | |