0N/A/*
0N/A * CDDL HEADER START
0N/A *
0N/A * The contents of this file are subject to the terms of the
0N/A * Common Development and Distribution License, Version 1.0 only
0N/A * (the "License"). You may not use this file except in compliance
0N/A * with the License.
0N/A *
0N/A * You can obtain a copy of the license at
0N/A * trunk/opends/resource/legal-notices/OpenDS.LICENSE
0N/A * or https://OpenDS.dev.java.net/OpenDS.LICENSE.
0N/A * See the License for the specific language governing permissions
0N/A * and limitations under the License.
0N/A *
0N/A * When distributing Covered Code, include this CDDL HEADER in each
0N/A * file and include the License file at
0N/A * trunk/opends/resource/legal-notices/OpenDS.LICENSE. If applicable,
0N/A * add the following below this CDDL HEADER, with the fields enclosed
873N/A * by brackets "[]" replaced with your own identifying information:
0N/A * Portions Copyright [yyyy] [name of copyright owner]
0N/A *
0N/A * CDDL HEADER END
0N/A *
0N/A *
4134N/A * Copyright 2006-2009 Sun Microsystems, Inc.
0N/A */
0N/Apackage org.opends.server.schema;
4015N/A
0N/A
0N/A
4134N/Aimport static org.opends.messages.SchemaMessages.*;
4134N/Aimport static org.opends.server.schema.SchemaConstants.*;
4134N/Aimport static org.opends.server.util.StaticUtils.*;
4292N/Aimport static org.opends.server.schema.StringPrepProfile.*;
0N/A
4134N/Aimport java.util.Collection;
4134N/Aimport java.util.Collections;
4134N/A
4134N/Aimport org.opends.messages.Message;
0N/Aimport org.opends.server.api.SubstringMatchingRule;
0N/Aimport org.opends.server.core.DirectoryServer;
4134N/Aimport org.opends.server.loggers.ErrorLogger;
4134N/Aimport org.opends.server.types.ByteSequence;
0N/Aimport org.opends.server.types.ByteString;
338N/Aimport org.opends.server.types.DirectoryException;
0N/Aimport org.opends.server.types.ResultCode;
0N/A
0N/A
0N/A
0N/A/**
0N/A * This class implements the numericStringSubstringsMatch matching rule defined
0N/A * in X.520 and referenced in RFC 2252.
0N/A */
4015N/Aclass NumericStringSubstringMatchingRule
0N/A extends SubstringMatchingRule
0N/A{
0N/A /**
0N/A * Creates a new instance of this numericStringSubstringsMatch matching rule.
0N/A */
0N/A public NumericStringSubstringMatchingRule()
0N/A {
0N/A super();
0N/A }
0N/A
0N/A
0N/A
0N/A /**
1618N/A * {@inheritDoc}
0N/A */
4134N/A @Override
4015N/A public Collection<String> getAllNames()
0N/A {
4015N/A return Collections.singleton(getName());
0N/A }
0N/A
0N/A
0N/A
0N/A /**
0N/A * Retrieves the common name for this matching rule.
0N/A *
0N/A * @return The common name for this matching rule, or <CODE>null</CODE> if
0N/A * it does not have a name.
0N/A */
4134N/A @Override
0N/A public String getName()
0N/A {
0N/A return SMR_NUMERIC_STRING_NAME;
0N/A }
0N/A
0N/A
0N/A
0N/A /**
0N/A * Retrieves the OID for this matching rule.
0N/A *
0N/A * @return The OID for this matching rule.
0N/A */
4134N/A @Override
0N/A public String getOID()
0N/A {
0N/A return SMR_NUMERIC_STRING_OID;
0N/A }
0N/A
0N/A
0N/A
0N/A /**
0N/A * Retrieves the description for this matching rule.
0N/A *
0N/A * @return The description for this matching rule, or <CODE>null</CODE> if
0N/A * there is none.
0N/A */
4134N/A @Override
0N/A public String getDescription()
0N/A {
0N/A // There is no standard description for this matching rule.
0N/A return null;
0N/A }
0N/A
0N/A
0N/A
0N/A /**
0N/A * Retrieves the OID of the syntax with which this matching rule is
0N/A * associated.
0N/A *
0N/A * @return The OID of the syntax with which this matching rule is associated.
0N/A */
4134N/A @Override
0N/A public String getSyntaxOID()
0N/A {
0N/A return SYNTAX_SUBSTRING_ASSERTION_OID;
0N/A }
0N/A
0N/A
0N/A
0N/A /**
0N/A * Retrieves the normalized form of the provided value, which is best suited
0N/A * for efficiently performing matching operations on that value.
0N/A *
0N/A * @param value The value to be normalized.
0N/A *
0N/A * @return The normalized version of the provided value.
0N/A *
0N/A * @throws DirectoryException If the provided value is invalid according to
0N/A * the associated attribute syntax.
0N/A */
4134N/A @Override
4134N/A public ByteString normalizeValue(ByteSequence value)
0N/A throws DirectoryException
0N/A {
4292N/A StringBuilder buffer = new StringBuilder();
4292N/A prepareUnicode(buffer, value, TRIM, NO_CASE_FOLD);
4292N/A int bufferLength = buffer.length();
0N/A
0N/A boolean logged = false;
4292N/A for (int pos = bufferLength-1; pos > 0; pos--)
0N/A {
4292N/A char c = buffer.charAt(pos);
4292N/A if (!isDigit(c))
0N/A {
4292N/A if (c == ' ')
4292N/A {
4292N/A buffer.delete(pos, pos+1);
4292N/A }
4292N/A else
4292N/A {
4292N/A // This is an illegal character. Either log it or reject it.
4292N/A Message message = WARN_ATTR_SYNTAX_NUMERIC_STRING_ILLEGAL_CHAR.get(
4292N/A value.toString(), String.valueOf(c), pos);
2086N/A
4292N/A switch (DirectoryServer.getSyntaxEnforcementPolicy())
4292N/A {
4292N/A case REJECT:
4292N/A throw new DirectoryException(ResultCode.INVALID_ATTRIBUTE_SYNTAX,
4292N/A message);
4292N/A case WARN:
4292N/A if (! logged)
4292N/A {
4292N/A ErrorLogger.logError(message);
4292N/A logged = true;
4292N/A }
4292N/A }
0N/A }
0N/A }
0N/A }
4292N/A if(buffer.length() == 0)
4292N/A {
4292N/A return ByteString.empty();
4292N/A }
4292N/A return ByteString.valueOf(value.toString());
0N/A }
0N/A
0N/A
0N/A
0N/A /**
0N/A * Normalizes the provided value fragment into a form that can be used to
0N/A * efficiently compare values.
0N/A *
0N/A * @param substring The value fragment to be normalized.
0N/A *
0N/A * @return The normalized form of the value fragment.
0N/A *
0N/A * @throws DirectoryException If the provided value fragment is not
0N/A * acceptable according to the associated syntax.
0N/A */
4134N/A @Override
4134N/A public ByteString normalizeSubstring(ByteSequence substring)
0N/A throws DirectoryException
0N/A {
4292N/A return normalizeValue(substring);
0N/A }
0N/A}
0N/A