OPENDJ-1308 (CR-3121) Migrate schema support
Factorized duplicated code from org.forgerock.opendj.ldap.schema into SchemaUtils.java
| | |
| | | throws DecodeException { |
| | | return UNDEFINED_ASSERTION; |
| | | } |
| | | |
| | | static void trimConsecutiveSpaces(StringBuilder buffer) { |
| | | for (int pos = buffer.length() - 1; pos > 0; pos--) { |
| | | if (buffer.charAt(pos) == ' ' |
| | | && buffer.charAt(pos - 1) == ' ') { |
| | | buffer.delete(pos, pos + 1); |
| | | } |
| | | } |
| | | } |
| | | } |
| | |
| | | */ |
| | | package org.forgerock.opendj.ldap.schema; |
| | | |
| | | import static com.forgerock.opendj.util.StringPrepProfile.NO_CASE_FOLD; |
| | | import static com.forgerock.opendj.util.StringPrepProfile.TRIM; |
| | | import static com.forgerock.opendj.util.StringPrepProfile.prepareUnicode; |
| | | |
| | | import org.forgerock.opendj.ldap.ByteSequence; |
| | | import org.forgerock.opendj.ldap.ByteString; |
| | | |
| | | import static com.forgerock.opendj.util.StringPrepProfile.*; |
| | | |
| | | /** |
| | | * This class defines the caseExactMatch matching rule defined in X.520 and |
| | | * referenced in RFC 4519. |
| | | */ |
| | | final class CaseExactEqualityMatchingRuleImpl extends AbstractEqualityMatchingRuleImpl { |
| | | @Override |
| | | public ByteString normalizeAttributeValue(final Schema schema, final ByteSequence value) { |
| | | final StringBuilder buffer = new StringBuilder(); |
| | | prepareUnicode(buffer, value, TRIM, NO_CASE_FOLD); |
| | | |
| | | final int bufferLength = buffer.length(); |
| | | if (bufferLength == 0) { |
| | | if (value.length() > 0) { |
| | | // This should only happen if the value is composed entirely of |
| | | // spaces. In that case, the normalized value is a single space. |
| | | return SchemaConstants.SINGLE_SPACE_VALUE; |
| | | } else { |
| | | // The value is empty, so it is already normalized. |
| | | return ByteString.empty(); |
| | | } |
| | | } |
| | | |
| | | trimConsecutiveSpaces(buffer); |
| | | |
| | | return ByteString.valueOf(buffer.toString()); |
| | | return SchemaUtils.normalizeStringAttributeValue(value, TRIM, NO_CASE_FOLD); |
| | | } |
| | | } |
| | |
| | | */ |
| | | package org.forgerock.opendj.ldap.schema; |
| | | |
| | | import static com.forgerock.opendj.util.StringPrepProfile.NO_CASE_FOLD; |
| | | import static com.forgerock.opendj.util.StringPrepProfile.TRIM; |
| | | import static com.forgerock.opendj.util.StringPrepProfile.prepareUnicode; |
| | | import static com.forgerock.opendj.ldap.CoreMessages.WARN_ATTR_SYNTAX_IA5_ILLEGAL_CHARACTER; |
| | | |
| | | import org.forgerock.i18n.LocalizableMessage; |
| | | import org.forgerock.opendj.ldap.ByteSequence; |
| | | import org.forgerock.opendj.ldap.ByteString; |
| | | import org.forgerock.opendj.ldap.DecodeException; |
| | | |
| | | import static com.forgerock.opendj.util.StringPrepProfile.*; |
| | | |
| | | /** |
| | | * This class implements the caseExactIA5Match matching rule defined in RFC |
| | | * 2252. |
| | |
| | | final class CaseExactIA5EqualityMatchingRuleImpl extends AbstractEqualityMatchingRuleImpl { |
| | | public ByteString normalizeAttributeValue(final Schema schema, final ByteSequence value) |
| | | throws DecodeException { |
| | | final StringBuilder buffer = new StringBuilder(); |
| | | prepareUnicode(buffer, value, TRIM, NO_CASE_FOLD); |
| | | |
| | | final int bufferLength = buffer.length(); |
| | | if (bufferLength == 0) { |
| | | if (value.length() > 0) { |
| | | // This should only happen if the value is composed entirely of |
| | | // spaces. In that case, the normalized value is a single space. |
| | | return SchemaConstants.SINGLE_SPACE_VALUE; |
| | | } else { |
| | | // The value is empty, so it is already normalized. |
| | | return ByteString.empty(); |
| | | } |
| | | } |
| | | |
| | | // Replace any consecutive spaces with a single space and watch out |
| | | // for non-ASCII characters. |
| | | for (int pos = bufferLength - 1; pos > 0; pos--) { |
| | | final char c = buffer.charAt(pos); |
| | | if (c == ' ') { |
| | | if (buffer.charAt(pos - 1) == ' ') { |
| | | buffer.delete(pos, pos + 1); |
| | | } |
| | | } else if ((c & 0x7F) != c) { |
| | | // This is not a valid character for an IA5 string. If strict |
| | | // syntax enforcement is enabled, then we'll throw an exception. |
| | | // Otherwise, we'll get rid of the character. |
| | | final LocalizableMessage message = |
| | | WARN_ATTR_SYNTAX_IA5_ILLEGAL_CHARACTER.get(value.toString(), String |
| | | .valueOf(c)); |
| | | throw DecodeException.error(message); |
| | | } |
| | | } |
| | | |
| | | return ByteString.valueOf(buffer.toString()); |
| | | return SchemaUtils.normalizeIA5StringAttributeValue(value, TRIM, NO_CASE_FOLD); |
| | | } |
| | | } |
| | |
| | | * |
| | | * |
| | | * Copyright 2009 Sun Microsystems, Inc. |
| | | * Portions copyright 2014 ForgeRock AS |
| | | */ |
| | | package org.forgerock.opendj.ldap.schema; |
| | | |
| | | import static com.forgerock.opendj.util.StringPrepProfile.NO_CASE_FOLD; |
| | | import static com.forgerock.opendj.util.StringPrepProfile.TRIM; |
| | | import static com.forgerock.opendj.util.StringPrepProfile.prepareUnicode; |
| | | import static com.forgerock.opendj.ldap.CoreMessages.WARN_ATTR_SYNTAX_IA5_ILLEGAL_CHARACTER; |
| | | |
| | | import org.forgerock.i18n.LocalizableMessage; |
| | | import org.forgerock.opendj.ldap.ByteSequence; |
| | | import org.forgerock.opendj.ldap.ByteString; |
| | | import org.forgerock.opendj.ldap.DecodeException; |
| | | |
| | | import static com.forgerock.opendj.util.StringPrepProfile.*; |
| | | |
| | | /** |
| | | * This class implements the caseExactIA5SubstringsMatch matching rule. This |
| | | * matching rule actually isn't defined in any official specification, but some |
| | |
| | | * private namespace. |
| | | */ |
| | | final class CaseExactIA5SubstringMatchingRuleImpl extends AbstractSubstringMatchingRuleImpl { |
| | | @Override |
| | | public ByteString normalizeAttributeValue(final Schema schema, final ByteSequence value) |
| | | throws DecodeException { |
| | | return normalize(TRIM, value); |
| | |
| | | |
| | | private ByteString normalize(final boolean trim, final ByteSequence value) |
| | | throws DecodeException { |
| | | final StringBuilder buffer = new StringBuilder(); |
| | | prepareUnicode(buffer, value, trim, NO_CASE_FOLD); |
| | | |
| | | final int bufferLength = buffer.length(); |
| | | if (bufferLength == 0) { |
| | | if (value.length() > 0) { |
| | | // This should only happen if the value is composed entirely of |
| | | // spaces. In that case, the normalized value is a single space. |
| | | return SchemaConstants.SINGLE_SPACE_VALUE; |
| | | } else { |
| | | // The value is empty, so it is already normalized. |
| | | return ByteString.empty(); |
| | | } |
| | | } |
| | | |
| | | // Replace any consecutive spaces with a single space and watch out |
| | | // for non-ASCII characters. |
| | | for (int pos = bufferLength - 1; pos > 0; pos--) { |
| | | final char c = buffer.charAt(pos); |
| | | if (c == ' ') { |
| | | if (buffer.charAt(pos - 1) == ' ') { |
| | | buffer.delete(pos, pos + 1); |
| | | } |
| | | } else if ((c & 0x7F) != c) { |
| | | // This is not a valid character for an IA5 string. If strict |
| | | // syntax enforcement is enabled, then we'll throw an exception. |
| | | // Otherwise, we'll get rid of the character. |
| | | final LocalizableMessage message = |
| | | WARN_ATTR_SYNTAX_IA5_ILLEGAL_CHARACTER.get(value.toString(), String |
| | | .valueOf(c)); |
| | | throw DecodeException.error(message); |
| | | } |
| | | } |
| | | |
| | | return ByteString.valueOf(buffer.toString()); |
| | | return SchemaUtils.normalizeIA5StringAttributeValue(value, trim, NO_CASE_FOLD); |
| | | } |
| | | } |
| | |
| | | */ |
| | | package org.forgerock.opendj.ldap.schema; |
| | | |
| | | import static com.forgerock.opendj.util.StringPrepProfile.NO_CASE_FOLD; |
| | | import static com.forgerock.opendj.util.StringPrepProfile.TRIM; |
| | | import static com.forgerock.opendj.util.StringPrepProfile.prepareUnicode; |
| | | |
| | | import org.forgerock.opendj.ldap.ByteSequence; |
| | | import org.forgerock.opendj.ldap.ByteString; |
| | | |
| | | import static com.forgerock.opendj.util.StringPrepProfile.*; |
| | | |
| | | /** |
| | | * This class defines the caseExactOrderingMatch matching rule defined in X.520 |
| | | * and referenced in RFC 4519. |
| | | */ |
| | | final class CaseExactOrderingMatchingRuleImpl extends AbstractOrderingMatchingRuleImpl { |
| | | public ByteString normalizeAttributeValue(final Schema schema, final ByteSequence value) { |
| | | final StringBuilder buffer = new StringBuilder(); |
| | | prepareUnicode(buffer, value, TRIM, NO_CASE_FOLD); |
| | | |
| | | final int bufferLength = buffer.length(); |
| | | if (bufferLength == 0) { |
| | | if (value.length() > 0) { |
| | | // This should only happen if the value is composed entirely of |
| | | // spaces. In that case, the normalized value is a single space. |
| | | return SchemaConstants.SINGLE_SPACE_VALUE; |
| | | } else { |
| | | // The value is empty, so it is already normalized. |
| | | return ByteString.empty(); |
| | | } |
| | | } |
| | | |
| | | trimConsecutiveSpaces(buffer); |
| | | |
| | | return ByteString.valueOf(buffer.toString()); |
| | | return SchemaUtils.normalizeStringAttributeValue(value, TRIM, NO_CASE_FOLD); |
| | | } |
| | | } |
| | |
| | | */ |
| | | package org.forgerock.opendj.ldap.schema; |
| | | |
| | | import static com.forgerock.opendj.util.StringPrepProfile.NO_CASE_FOLD; |
| | | import static com.forgerock.opendj.util.StringPrepProfile.TRIM; |
| | | import static com.forgerock.opendj.util.StringPrepProfile.prepareUnicode; |
| | | |
| | | import org.forgerock.opendj.ldap.ByteSequence; |
| | | import org.forgerock.opendj.ldap.ByteString; |
| | | import org.forgerock.opendj.ldap.DecodeException; |
| | | |
| | | import static com.forgerock.opendj.util.StringPrepProfile.*; |
| | | |
| | | /** |
| | | * This class defines the caseExactSubstringsMatch matching rule defined in |
| | | * X.520 and referenced in RFC 2252. |
| | |
| | | } |
| | | |
| | | private ByteString normalize(final boolean trim, final ByteSequence value) { |
| | | final StringBuilder buffer = new StringBuilder(); |
| | | prepareUnicode(buffer, value, trim, NO_CASE_FOLD); |
| | | |
| | | final int bufferLength = buffer.length(); |
| | | if (bufferLength == 0) { |
| | | if (value.length() > 0) { |
| | | // This should only happen if the value is composed entirely of |
| | | // spaces. In that case, the normalized value is a single space. |
| | | return SchemaConstants.SINGLE_SPACE_VALUE; |
| | | } else { |
| | | // The value is empty, so it is already normalized. |
| | | return ByteString.empty(); |
| | | } |
| | | } |
| | | |
| | | trimConsecutiveSpaces(buffer); |
| | | |
| | | return ByteString.valueOf(buffer.toString()); |
| | | return SchemaUtils.normalizeStringAttributeValue(value, trim, NO_CASE_FOLD); |
| | | } |
| | | } |
| | |
| | | */ |
| | | package org.forgerock.opendj.ldap.schema; |
| | | |
| | | import static com.forgerock.opendj.util.StringPrepProfile.CASE_FOLD; |
| | | import static com.forgerock.opendj.util.StringPrepProfile.TRIM; |
| | | import static com.forgerock.opendj.util.StringPrepProfile.prepareUnicode; |
| | | import static com.forgerock.opendj.util.StringPrepProfile.*; |
| | | |
| | | import org.forgerock.opendj.ldap.ByteSequence; |
| | | import org.forgerock.opendj.ldap.ByteString; |
| | |
| | | * referenced in RFC 2252. |
| | | */ |
| | | final class CaseIgnoreEqualityMatchingRuleImpl extends AbstractEqualityMatchingRuleImpl { |
| | | @Override |
| | | public ByteString normalizeAttributeValue(final Schema schema, final ByteSequence value) { |
| | | final StringBuilder buffer = new StringBuilder(); |
| | | prepareUnicode(buffer, value, TRIM, CASE_FOLD); |
| | | |
| | | final int bufferLength = buffer.length(); |
| | | if (bufferLength == 0) { |
| | | if (value.length() > 0) { |
| | | // This should only happen if the value is composed entirely of |
| | | // spaces. In that case, the normalized value is a single space. |
| | | return SchemaConstants.SINGLE_SPACE_VALUE; |
| | | } else { |
| | | // The value is empty, so it is already normalized. |
| | | return ByteString.empty(); |
| | | } |
| | | } |
| | | |
| | | trimConsecutiveSpaces(buffer); |
| | | |
| | | return ByteString.valueOf(buffer.toString()); |
| | | return SchemaUtils.normalizeStringAttributeValue(value, TRIM, CASE_FOLD); |
| | | } |
| | | } |
| | |
| | | */ |
| | | package org.forgerock.opendj.ldap.schema; |
| | | |
| | | import static com.forgerock.opendj.util.StringPrepProfile.CASE_FOLD; |
| | | import static com.forgerock.opendj.util.StringPrepProfile.TRIM; |
| | | import static com.forgerock.opendj.util.StringPrepProfile.prepareUnicode; |
| | | import static com.forgerock.opendj.ldap.CoreMessages.WARN_ATTR_SYNTAX_IA5_ILLEGAL_CHARACTER; |
| | | |
| | | import org.forgerock.i18n.LocalizableMessage; |
| | | import org.forgerock.opendj.ldap.ByteSequence; |
| | | import org.forgerock.opendj.ldap.ByteString; |
| | | import org.forgerock.opendj.ldap.DecodeException; |
| | | |
| | | import static com.forgerock.opendj.util.StringPrepProfile.*; |
| | | |
| | | /** |
| | | * This class implements the caseIgnoreIA5Match matching rule defined in RFC |
| | | * 2252. |
| | | */ |
| | | final class CaseIgnoreIA5EqualityMatchingRuleImpl extends AbstractEqualityMatchingRuleImpl { |
| | | @Override |
| | | public ByteString normalizeAttributeValue(final Schema schema, final ByteSequence value) |
| | | throws DecodeException { |
| | | final StringBuilder buffer = new StringBuilder(); |
| | | prepareUnicode(buffer, value, TRIM, CASE_FOLD); |
| | | |
| | | final int bufferLength = buffer.length(); |
| | | if (bufferLength == 0) { |
| | | if (value.length() > 0) { |
| | | // This should only happen if the value is composed entirely of |
| | | // spaces. In that case, the normalized value is a single space. |
| | | return SchemaConstants.SINGLE_SPACE_VALUE; |
| | | } else { |
| | | // The value is empty, so it is already normalized. |
| | | return ByteString.empty(); |
| | | } |
| | | } |
| | | |
| | | // Replace any consecutive spaces with a single space and watch out |
| | | // for non-ASCII characters. |
| | | for (int pos = bufferLength - 1; pos > 0; pos--) { |
| | | final char c = buffer.charAt(pos); |
| | | if (c == ' ') { |
| | | if (buffer.charAt(pos - 1) == ' ') { |
| | | buffer.delete(pos, pos + 1); |
| | | } |
| | | } else if ((c & 0x7F) != c) { |
| | | // This is not a valid character for an IA5 string. If strict |
| | | // syntax enforcement is enabled, then we'll throw an exception. |
| | | // Otherwise, we'll get rid of the character. |
| | | final LocalizableMessage message = |
| | | WARN_ATTR_SYNTAX_IA5_ILLEGAL_CHARACTER.get(value.toString(), String |
| | | .valueOf(c)); |
| | | throw DecodeException.error(message); |
| | | } |
| | | } |
| | | |
| | | return ByteString.valueOf(buffer.toString()); |
| | | return SchemaUtils.normalizeIA5StringAttributeValue(value, TRIM, CASE_FOLD); |
| | | } |
| | | } |
| | |
| | | * |
| | | * |
| | | * Copyright 2009 Sun Microsystems, Inc. |
| | | * Portions copyright 2014 ForgeRock AS |
| | | */ |
| | | package org.forgerock.opendj.ldap.schema; |
| | | |
| | | import static com.forgerock.opendj.util.StringPrepProfile.CASE_FOLD; |
| | | import static com.forgerock.opendj.util.StringPrepProfile.TRIM; |
| | | import static com.forgerock.opendj.util.StringPrepProfile.prepareUnicode; |
| | | import static com.forgerock.opendj.ldap.CoreMessages.WARN_ATTR_SYNTAX_IA5_ILLEGAL_CHARACTER; |
| | | |
| | | import org.forgerock.i18n.LocalizableMessage; |
| | | import org.forgerock.opendj.ldap.ByteSequence; |
| | | import org.forgerock.opendj.ldap.ByteString; |
| | | import org.forgerock.opendj.ldap.DecodeException; |
| | | |
| | | import static com.forgerock.opendj.util.StringPrepProfile.*; |
| | | |
| | | /** |
| | | * This class implements the caseIgnoreIA5SubstringsMatch matching rule defined |
| | | * in RFC 2252. |
| | |
| | | |
| | | private ByteString normalize(final boolean trim, final ByteSequence value) |
| | | throws DecodeException { |
| | | final StringBuilder buffer = new StringBuilder(); |
| | | prepareUnicode(buffer, value, trim, CASE_FOLD); |
| | | |
| | | final int bufferLength = buffer.length(); |
| | | if (bufferLength == 0) { |
| | | if (value.length() > 0) { |
| | | // This should only happen if the value is composed entirely of |
| | | // spaces. In that case, the normalized value is a single space. |
| | | return SchemaConstants.SINGLE_SPACE_VALUE; |
| | | } else { |
| | | // The value is empty, so it is already normalized. |
| | | return ByteString.empty(); |
| | | } |
| | | } |
| | | |
| | | // Replace any consecutive spaces with a single space and watch out |
| | | // for non-ASCII characters. |
| | | for (int pos = bufferLength - 1; pos > 0; pos--) { |
| | | final char c = buffer.charAt(pos); |
| | | if (c == ' ') { |
| | | if (buffer.charAt(pos - 1) == ' ') { |
| | | buffer.delete(pos, pos + 1); |
| | | } |
| | | } else if ((c & 0x7F) != c) { |
| | | // This is not a valid character for an IA5 string. If strict |
| | | // syntax enforcement is enabled, then we'll throw an exception. |
| | | // Otherwise, we'll get rid of the character. |
| | | final LocalizableMessage message = |
| | | WARN_ATTR_SYNTAX_IA5_ILLEGAL_CHARACTER.get(value.toString(), String |
| | | .valueOf(c)); |
| | | throw DecodeException.error(message); |
| | | } |
| | | } |
| | | |
| | | return ByteString.valueOf(buffer.toString()); |
| | | return SchemaUtils.normalizeIA5StringAttributeValue(value, trim, CASE_FOLD); |
| | | } |
| | | } |
| | |
| | | package org.forgerock.opendj.ldap.schema; |
| | | |
| | | import static com.forgerock.opendj.util.StringPrepProfile.CASE_FOLD; |
| | | import static com.forgerock.opendj.util.StringPrepProfile.TRIM; |
| | | import static com.forgerock.opendj.util.StringPrepProfile.prepareUnicode; |
| | | |
| | | import org.forgerock.opendj.ldap.ByteSequence; |
| | | import org.forgerock.opendj.ldap.ByteString; |
| | | |
| | | import static com.forgerock.opendj.util.StringPrepProfile.*; |
| | | |
| | | /** |
| | | * This class implements the caseIgnoreListMatch matching rule defined in X.520 |
| | | * and referenced in RFC 2252. |
| | | */ |
| | | final class CaseIgnoreListEqualityMatchingRuleImpl extends AbstractEqualityMatchingRuleImpl { |
| | | public ByteString normalizeAttributeValue(final Schema schema, final ByteSequence value) { |
| | | final StringBuilder buffer = new StringBuilder(); |
| | | prepareUnicode(buffer, value, TRIM, CASE_FOLD); |
| | | |
| | | final int bufferLength = buffer.length(); |
| | | if (bufferLength == 0) { |
| | | if (value.length() > 0) { |
| | | // This should only happen if the value is composed entirely of |
| | | // spaces. In that case, the normalized value is a single space. |
| | | return SchemaConstants.SINGLE_SPACE_VALUE; |
| | | } else { |
| | | // The value is empty, so it is already normalized. |
| | | return ByteString.empty(); |
| | | } |
| | | } |
| | | |
| | | // Replace any consecutive spaces with a single space. Any spaces |
| | | // around a dollar sign will also be removed. |
| | | for (int pos = bufferLength - 1; pos > 0; pos--) { |
| | | if (buffer.charAt(pos) == ' ') { |
| | | final char c = buffer.charAt(pos - 1); |
| | | if (c == ' ') { |
| | | buffer.delete(pos, pos + 1); |
| | | } else if (c == '$') { |
| | | if (pos <= 1 || buffer.charAt(pos - 2) != '\\') { |
| | | buffer.delete(pos, pos + 1); |
| | | } |
| | | } else if (buffer.charAt(pos + 1) == '$') { |
| | | buffer.delete(pos, pos + 1); |
| | | } |
| | | } |
| | | } |
| | | |
| | | return ByteString.valueOf(buffer.toString()); |
| | | return SchemaUtils.normalizeStringListAttributeValue(value, TRIM, CASE_FOLD); |
| | | } |
| | | } |
| | |
| | | */ |
| | | package org.forgerock.opendj.ldap.schema; |
| | | |
| | | import static com.forgerock.opendj.util.StringPrepProfile.CASE_FOLD; |
| | | import static com.forgerock.opendj.util.StringPrepProfile.prepareUnicode; |
| | | |
| | | import org.forgerock.opendj.ldap.ByteSequence; |
| | | import org.forgerock.opendj.ldap.ByteString; |
| | | import org.forgerock.opendj.ldap.DecodeException; |
| | | |
| | | import com.forgerock.opendj.util.StringPrepProfile; |
| | | import static com.forgerock.opendj.util.StringPrepProfile.*; |
| | | |
| | | /** |
| | | * This class implements the caseIgnoreListSubstringsMatch matching rule defined |
| | |
| | | */ |
| | | final class CaseIgnoreListSubstringMatchingRuleImpl extends AbstractSubstringMatchingRuleImpl { |
| | | public ByteString normalizeAttributeValue(final Schema schema, final ByteSequence value) { |
| | | final StringBuilder buffer = new StringBuilder(); |
| | | prepareUnicode(buffer, value, StringPrepProfile.TRIM, CASE_FOLD); |
| | | |
| | | final int bufferLength = buffer.length(); |
| | | if (bufferLength == 0) { |
| | | if (value.length() > 0) { |
| | | // This should only happen if the value is composed entirely of |
| | | // spaces. In that case, the normalized value is a single space. |
| | | return SchemaConstants.SINGLE_SPACE_VALUE; |
| | | } else { |
| | | // The value is empty, so it is already normalized. |
| | | return ByteString.empty(); |
| | | } |
| | | } |
| | | |
| | | // Replace any consecutive spaces with a single space. Any spaces |
| | | // around a dollar sign will also be removed. |
| | | for (int pos = bufferLength - 1; pos > 0; pos--) { |
| | | if (buffer.charAt(pos) == ' ') { |
| | | final char c = buffer.charAt(pos - 1); |
| | | if (c == ' ') { |
| | | buffer.delete(pos, pos + 1); |
| | | } else if (c == '$') { |
| | | if (pos <= 1 || buffer.charAt(pos - 2) != '\\') { |
| | | buffer.delete(pos, pos + 1); |
| | | } |
| | | } else if (buffer.charAt(pos + 1) == '$') { |
| | | buffer.delete(pos, pos + 1); |
| | | } |
| | | } |
| | | } |
| | | |
| | | return ByteString.valueOf(buffer.toString()); |
| | | return SchemaUtils.normalizeStringListAttributeValue(value, TRIM, CASE_FOLD); |
| | | } |
| | | |
| | | @Override |
| | |
| | | // 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 opening or trailing space. |
| | | final StringBuilder buffer = new StringBuilder(); |
| | | prepareUnicode(buffer, value, false, CASE_FOLD); |
| | | |
| | | final int bufferLength = buffer.length(); |
| | | if (bufferLength == 0) { |
| | | if (value.length() > 0) { |
| | | // This should only happen if the value is composed entirely of |
| | | // spaces. In that case, the normalized value is a single space. |
| | | return SchemaConstants.SINGLE_SPACE_VALUE; |
| | | } else { |
| | | // The value is empty, so it is already normalized. |
| | | return value.toByteString(); |
| | | } |
| | | } |
| | | |
| | | trimConsecutiveSpaces(buffer); |
| | | |
| | | return ByteString.valueOf(buffer.toString()); |
| | | return SchemaUtils.normalizeStringAttributeValue(value, false, CASE_FOLD); |
| | | } |
| | | } |
| | |
| | | */ |
| | | package org.forgerock.opendj.ldap.schema; |
| | | |
| | | import static com.forgerock.opendj.util.StringPrepProfile.CASE_FOLD; |
| | | import static com.forgerock.opendj.util.StringPrepProfile.TRIM; |
| | | import static com.forgerock.opendj.util.StringPrepProfile.prepareUnicode; |
| | | |
| | | import org.forgerock.opendj.ldap.ByteSequence; |
| | | import org.forgerock.opendj.ldap.ByteString; |
| | | |
| | | import static com.forgerock.opendj.util.StringPrepProfile.*; |
| | | |
| | | /** |
| | | * This class defines the caseIgnoreOrderingMatch matching rule defined in X.520 |
| | | * and referenced in RFC 2252. |
| | | */ |
| | | final class CaseIgnoreOrderingMatchingRuleImpl extends AbstractOrderingMatchingRuleImpl { |
| | | @Override |
| | | public ByteString normalizeAttributeValue(final Schema schema, final ByteSequence value) { |
| | | final StringBuilder buffer = new StringBuilder(); |
| | | prepareUnicode(buffer, value, TRIM, CASE_FOLD); |
| | | |
| | | final int bufferLength = buffer.length(); |
| | | if (bufferLength == 0) { |
| | | if (value.length() > 0) { |
| | | // This should only happen if the value is composed entirely of |
| | | // spaces. In that case, the normalized value is a single space. |
| | | return SchemaConstants.SINGLE_SPACE_VALUE; |
| | | } else { |
| | | // The value is empty, so it is already normalized. |
| | | return ByteString.empty(); |
| | | } |
| | | } |
| | | |
| | | trimConsecutiveSpaces(buffer); |
| | | |
| | | return ByteString.valueOf(buffer.toString()); |
| | | return SchemaUtils.normalizeStringAttributeValue(value, TRIM, CASE_FOLD); |
| | | } |
| | | } |
| | |
| | | */ |
| | | package org.forgerock.opendj.ldap.schema; |
| | | |
| | | import static com.forgerock.opendj.util.StringPrepProfile.CASE_FOLD; |
| | | import static com.forgerock.opendj.util.StringPrepProfile.TRIM; |
| | | |
| | | import org.forgerock.opendj.ldap.ByteSequence; |
| | | import org.forgerock.opendj.ldap.ByteString; |
| | | import org.forgerock.opendj.ldap.DecodeException; |
| | | |
| | | import com.forgerock.opendj.util.StringPrepProfile; |
| | | import static com.forgerock.opendj.util.StringPrepProfile.*; |
| | | |
| | | /** |
| | | * This class defines the caseIgnoreSubstringsMatch matching rule defined in |
| | |
| | | } |
| | | |
| | | private ByteString normalize(final boolean trim, final ByteSequence value) { |
| | | |
| | | final StringBuilder buffer = new StringBuilder(); |
| | | StringPrepProfile.prepareUnicode(buffer, value, trim, CASE_FOLD); |
| | | |
| | | final int bufferLength = buffer.length(); |
| | | if (bufferLength == 0) { |
| | | if (value.length() > 0) { |
| | | // This should only happen if the value is composed entirely of |
| | | // spaces. In that case, the normalized value is a single space. |
| | | return SchemaConstants.SINGLE_SPACE_VALUE; |
| | | } else { |
| | | // The value is empty, so it is already normalized. |
| | | return value.toByteString(); |
| | | } |
| | | } |
| | | |
| | | trimConsecutiveSpaces(buffer); |
| | | |
| | | return ByteString.valueOf(buffer.toString()); |
| | | return SchemaUtils.normalizeStringAttributeValue(value, trim, CASE_FOLD); |
| | | } |
| | | } |
| | |
| | | |
| | | import static com.forgerock.opendj.util.StringPrepProfile.CASE_FOLD; |
| | | import static com.forgerock.opendj.util.StringPrepProfile.TRIM; |
| | | import static com.forgerock.opendj.util.StringPrepProfile.prepareUnicode; |
| | | import static com.forgerock.opendj.ldap.CoreMessages.ERR_ATTR_SYNTAX_EMPTY_VALUE; |
| | | import static com.forgerock.opendj.ldap.CoreMessages.ERR_ATTR_SYNTAX_EXPECTED_OPEN_PARENTHESIS; |
| | | |
| | | import org.forgerock.i18n.LocalizableMessage; |
| | | import org.forgerock.opendj.ldap.Assertion; |
| | | import org.forgerock.opendj.ldap.ByteSequence; |
| | | import org.forgerock.opendj.ldap.ByteString; |
| | |
| | | final class DirectoryStringFirstComponentEqualityMatchingRuleImpl extends AbstractEqualityMatchingRuleImpl { |
| | | @Override |
| | | public Assertion getAssertion(final Schema schema, final ByteSequence assertionValue) { |
| | | final StringBuilder buffer = new StringBuilder(); |
| | | prepareUnicode(buffer, assertionValue, TRIM, CASE_FOLD); |
| | | |
| | | final int bufferLength = buffer.length(); |
| | | if (bufferLength == 0) { |
| | | if (assertionValue.length() > 0) { |
| | | // This should only happen if the value is composed entirely of |
| | | // spaces. In that case, the normalized value is a single space. |
| | | return new DefaultEqualityAssertion(SchemaConstants.SINGLE_SPACE_VALUE); |
| | | } else { |
| | | // The value is empty, so it is already normalized. |
| | | return new DefaultEqualityAssertion(ByteString.empty()); |
| | | } |
| | | } |
| | | |
| | | trimConsecutiveSpaces(buffer); |
| | | |
| | | return new DefaultEqualityAssertion(ByteString.valueOf(buffer.toString())); |
| | | return new DefaultEqualityAssertion(SchemaUtils.normalizeStringAttributeValue(assertionValue, TRIM, CASE_FOLD)); |
| | | } |
| | | |
| | | public ByteString normalizeAttributeValue(final Schema schema, final ByteSequence value) |
| | |
| | | // This means that the value was empty or contained only |
| | | // whitespace. |
| | | // That is illegal. |
| | | final LocalizableMessage message = ERR_ATTR_SYNTAX_EMPTY_VALUE.get(); |
| | | throw DecodeException.error(message); |
| | | throw DecodeException.error(ERR_ATTR_SYNTAX_EMPTY_VALUE.get()); |
| | | } |
| | | |
| | | // The next character must be an open parenthesis. If it is not, |
| | | // then that is an error. |
| | | final char c = reader.read(); |
| | | if (c != '(') { |
| | | final LocalizableMessage message = |
| | | ERR_ATTR_SYNTAX_EXPECTED_OPEN_PARENTHESIS.get(definition, (reader.pos() - 1), |
| | | String.valueOf(c)); |
| | | throw DecodeException.error(message); |
| | | throw DecodeException.error( |
| | | ERR_ATTR_SYNTAX_EXPECTED_OPEN_PARENTHESIS.get(definition, reader.pos() - 1, c)); |
| | | } |
| | | |
| | | // Skip over any spaces immediately following the opening parenthesis. |
| | |
| | | |
| | | import static com.forgerock.opendj.util.StringPrepProfile.CASE_FOLD; |
| | | import static com.forgerock.opendj.util.StringPrepProfile.TRIM; |
| | | import static com.forgerock.opendj.util.StringPrepProfile.prepareUnicode; |
| | | import static com.forgerock.opendj.ldap.CoreMessages.WARN_ATTR_SYNTAX_LDAPSYNTAX_ENUM_INVALID_VALUE; |
| | | |
| | | import static org.forgerock.opendj.ldap.schema.AbstractMatchingRuleImpl.*; |
| | | import static org.forgerock.opendj.ldap.schema.SchemaConstants.AMR_DOUBLE_METAPHONE_OID; |
| | | import static org.forgerock.opendj.ldap.schema.SchemaConstants.EMR_CASE_IGNORE_OID; |
| | | import static org.forgerock.opendj.ldap.schema.SchemaConstants.OMR_OID_GENERIC_ENUM; |
| | |
| | | } |
| | | |
| | | private String normalize(final ByteSequence value) { |
| | | final StringBuilder buffer = new StringBuilder(); |
| | | prepareUnicode(buffer, value, TRIM, CASE_FOLD); |
| | | |
| | | final int bufferLength = buffer.length(); |
| | | if (bufferLength == 0) { |
| | | if (value.length() > 0) { |
| | | // This should only happen if the value is composed entirely of |
| | | // spaces. In that case, the normalized value is a single space. |
| | | return " "; |
| | | } else { |
| | | // The value is empty, so it is already normalized. |
| | | return ""; |
| | | } |
| | | } |
| | | |
| | | trimConsecutiveSpaces(buffer); |
| | | |
| | | return buffer.toString(); |
| | | return SchemaUtils.normalizeStringAttributeValue(value, TRIM, CASE_FOLD).toString(); |
| | | } |
| | | } |
| | |
| | | |
| | | import static com.forgerock.opendj.util.StringPrepProfile.CASE_FOLD; |
| | | import static com.forgerock.opendj.util.StringPrepProfile.TRIM; |
| | | import static com.forgerock.opendj.util.StringPrepProfile.prepareUnicode; |
| | | |
| | | import org.forgerock.opendj.ldap.Assertion; |
| | | import org.forgerock.opendj.ldap.ByteSequence; |
| | |
| | | } |
| | | |
| | | private String normalize(final ByteSequence value) { |
| | | final StringBuilder buffer = new StringBuilder(); |
| | | prepareUnicode(buffer, value, TRIM, CASE_FOLD); |
| | | |
| | | if (buffer.length() == 0) { |
| | | if (value.length() > 0) { |
| | | // This should only happen if the value is composed entirely of |
| | | // spaces. In that case, the normalized value is a single space. |
| | | return " "; |
| | | } else { |
| | | // The value is empty, so it is already normalized. |
| | | return ""; |
| | | } |
| | | } |
| | | |
| | | trimConsecutiveSpaces(buffer); |
| | | |
| | | return buffer.toString(); |
| | | return SchemaUtils.normalizeStringAttributeValue(value, TRIM, CASE_FOLD).toString(); |
| | | } |
| | | } |
| | |
| | | */ |
| | | package org.forgerock.opendj.ldap.schema; |
| | | |
| | | import static com.forgerock.opendj.util.StringPrepProfile.NO_CASE_FOLD; |
| | | import static com.forgerock.opendj.util.StringPrepProfile.TRIM; |
| | | import static com.forgerock.opendj.util.StringPrepProfile.prepareUnicode; |
| | | |
| | | import org.forgerock.opendj.ldap.ByteSequence; |
| | | import org.forgerock.opendj.ldap.ByteString; |
| | | |
| | |
| | | */ |
| | | final class NumericStringEqualityMatchingRuleImpl extends AbstractEqualityMatchingRuleImpl { |
| | | public ByteString normalizeAttributeValue(final Schema schema, final ByteSequence value) { |
| | | final StringBuilder buffer = new StringBuilder(); |
| | | prepareUnicode(buffer, value, TRIM, NO_CASE_FOLD); |
| | | |
| | | if (buffer.length() == 0) { |
| | | return ByteString.empty(); |
| | | } |
| | | return ByteString.valueOf(buffer.toString()); |
| | | return SchemaUtils.normalizeNumericStringAttributeValue(value); |
| | | } |
| | | } |
| | |
| | | * |
| | | * |
| | | * Copyright 2009 Sun Microsystems, Inc. |
| | | * Portions copyright 2014 ForgeRock AS |
| | | */ |
| | | package org.forgerock.opendj.ldap.schema; |
| | | |
| | | import static com.forgerock.opendj.util.StringPrepProfile.NO_CASE_FOLD; |
| | | import static com.forgerock.opendj.util.StringPrepProfile.TRIM; |
| | | import static com.forgerock.opendj.util.StringPrepProfile.prepareUnicode; |
| | | |
| | | import org.forgerock.opendj.ldap.ByteSequence; |
| | | import org.forgerock.opendj.ldap.ByteString; |
| | | |
| | |
| | | */ |
| | | final class NumericStringOrderingMatchingRuleImpl extends AbstractOrderingMatchingRuleImpl { |
| | | public ByteString normalizeAttributeValue(final Schema schema, final ByteSequence value) { |
| | | final StringBuilder buffer = new StringBuilder(); |
| | | prepareUnicode(buffer, value, TRIM, NO_CASE_FOLD); |
| | | |
| | | if (buffer.length() == 0) { |
| | | return ByteString.empty(); |
| | | } |
| | | return ByteString.valueOf(buffer.toString()); |
| | | return SchemaUtils.normalizeNumericStringAttributeValue(value); |
| | | } |
| | | } |
| | |
| | | * |
| | | * |
| | | * Copyright 2009 Sun Microsystems, Inc. |
| | | * Portions copyright 2014 ForgeRock AS |
| | | */ |
| | | package org.forgerock.opendj.ldap.schema; |
| | | |
| | | import static com.forgerock.opendj.util.StringPrepProfile.NO_CASE_FOLD; |
| | | import static com.forgerock.opendj.util.StringPrepProfile.TRIM; |
| | | import static com.forgerock.opendj.util.StringPrepProfile.prepareUnicode; |
| | | |
| | | import org.forgerock.opendj.ldap.ByteSequence; |
| | | import org.forgerock.opendj.ldap.ByteString; |
| | | |
| | |
| | | */ |
| | | final class NumericStringSubstringMatchingRuleImpl extends AbstractSubstringMatchingRuleImpl { |
| | | public ByteString normalizeAttributeValue(final Schema schema, final ByteSequence value) { |
| | | final StringBuilder buffer = new StringBuilder(); |
| | | prepareUnicode(buffer, value, TRIM, NO_CASE_FOLD); |
| | | |
| | | if (buffer.length() == 0) { |
| | | return ByteString.empty(); |
| | | } |
| | | return ByteString.valueOf(buffer.toString()); |
| | | return SchemaUtils.normalizeNumericStringAttributeValue(value); |
| | | } |
| | | } |
| | |
| | | */ |
| | | package org.forgerock.opendj.ldap.schema; |
| | | |
| | | import static com.forgerock.opendj.util.StringPrepProfile.CASE_FOLD; |
| | | import static com.forgerock.opendj.util.StringPrepProfile.TRIM; |
| | | import static com.forgerock.opendj.util.StringPrepProfile.prepareUnicode; |
| | | |
| | | import org.forgerock.opendj.ldap.ByteSequence; |
| | | import org.forgerock.opendj.ldap.ByteString; |
| | | |
| | | import static com.forgerock.opendj.util.StringPrepProfile.*; |
| | | |
| | | /** |
| | | * This class implements the presentationAddressMatch matching rule defined in |
| | | * X.520 and referenced in RFC 2252. However, since this matching rule and the |
| | |
| | | * like the caseIgnoreMatch rule. |
| | | */ |
| | | final class PresentationAddressEqualityMatchingRuleImpl extends AbstractEqualityMatchingRuleImpl { |
| | | @Override |
| | | public ByteString normalizeAttributeValue(final Schema schema, final ByteSequence value) { |
| | | final StringBuilder buffer = new StringBuilder(); |
| | | prepareUnicode(buffer, value, TRIM, CASE_FOLD); |
| | | |
| | | final int bufferLength = buffer.length(); |
| | | if (bufferLength == 0) { |
| | | if (value.length() > 0) { |
| | | // This should only happen if the value is composed entirely of |
| | | // spaces. In that case, the normalized value is a single space. |
| | | return SchemaConstants.SINGLE_SPACE_VALUE; |
| | | } else { |
| | | // The value is empty, so it is already normalized. |
| | | return ByteString.empty(); |
| | | } |
| | | } |
| | | |
| | | trimConsecutiveSpaces(buffer); |
| | | |
| | | return ByteString.valueOf(buffer.toString()); |
| | | return SchemaUtils.normalizeStringAttributeValue(value, TRIM, CASE_FOLD); |
| | | } |
| | | } |
| | |
| | | */ |
| | | package org.forgerock.opendj.ldap.schema; |
| | | |
| | | import static com.forgerock.opendj.util.StringPrepProfile.CASE_FOLD; |
| | | import static com.forgerock.opendj.util.StringPrepProfile.TRIM; |
| | | import static com.forgerock.opendj.util.StringPrepProfile.prepareUnicode; |
| | | |
| | | import org.forgerock.opendj.ldap.ByteSequence; |
| | | import org.forgerock.opendj.ldap.ByteString; |
| | | |
| | | import static com.forgerock.opendj.util.StringPrepProfile.*; |
| | | |
| | | /** |
| | | * This class implements the protocolInformationMatch matching rule defined in |
| | | * X.520 and referenced in RFC 2252. However, since this matching rule and the |
| | |
| | | * like the caseIgnoreMatch rule. |
| | | */ |
| | | final class ProtocolInformationEqualityMatchingRuleImpl extends AbstractEqualityMatchingRuleImpl { |
| | | @Override |
| | | public ByteString normalizeAttributeValue(final Schema schema, final ByteSequence value) { |
| | | final StringBuilder buffer = new StringBuilder(); |
| | | prepareUnicode(buffer, value, TRIM, CASE_FOLD); |
| | | |
| | | final int bufferLength = buffer.length(); |
| | | if (bufferLength == 0) { |
| | | if (value.length() > 0) { |
| | | // This should only happen if the value is composed entirely of |
| | | // spaces. In that case, the normalized value is a single space. |
| | | return SchemaConstants.SINGLE_SPACE_VALUE; |
| | | } else { |
| | | // The value is empty, so it is already normalized. |
| | | return ByteString.empty(); |
| | | } |
| | | } |
| | | |
| | | trimConsecutiveSpaces(buffer); |
| | | |
| | | return ByteString.valueOf(buffer.toString()); |
| | | return SchemaUtils.normalizeStringAttributeValue(value, TRIM, CASE_FOLD); |
| | | } |
| | | } |
| | |
| | | * |
| | | * |
| | | * Copyright 2009 Sun Microsystems, Inc. |
| | | * Portions copyright 2011 ForgeRock AS |
| | | * Portions copyright 2011-2014 ForgeRock AS |
| | | */ |
| | | package org.forgerock.opendj.ldap.schema; |
| | | |
| | | import static com.forgerock.opendj.util.StaticUtils.isAlpha; |
| | | import static com.forgerock.opendj.util.StaticUtils.isDigit; |
| | | import static com.forgerock.opendj.util.StaticUtils.isKeyChar; |
| | | import static com.forgerock.opendj.ldap.CoreMessages.*; |
| | | import static com.forgerock.opendj.util.StaticUtils.*; |
| | | import static com.forgerock.opendj.util.StringPrepProfile.*; |
| | | |
| | | import java.util.ArrayList; |
| | | import java.util.Collections; |
| | |
| | | import java.util.Set; |
| | | |
| | | import org.forgerock.i18n.LocalizableMessage; |
| | | import org.forgerock.opendj.ldap.ByteSequence; |
| | | import org.forgerock.opendj.ldap.ByteString; |
| | | import org.forgerock.opendj.ldap.DecodeException; |
| | | |
| | | import com.forgerock.opendj.util.SubstringReader; |
| | |
| | | |
| | | return values; |
| | | } catch (final StringIndexOutOfBoundsException e) { |
| | | final LocalizableMessage message = ERR_ATTR_SYNTAX_TRUNCATED_VALUE1.get(); |
| | | throw DecodeException.error(message); |
| | | throw DecodeException.error(ERR_ATTR_SYNTAX_TRUNCATED_VALUE1.get()); |
| | | } |
| | | } |
| | | |
| | |
| | | |
| | | return values; |
| | | } catch (final StringIndexOutOfBoundsException e) { |
| | | final LocalizableMessage message = ERR_ATTR_SYNTAX_TRUNCATED_VALUE1.get(); |
| | | throw DecodeException.error(message); |
| | | throw DecodeException.error(ERR_ATTR_SYNTAX_TRUNCATED_VALUE1.get()); |
| | | } |
| | | } |
| | | |
| | |
| | | } |
| | | |
| | | if (length == 0) { |
| | | final LocalizableMessage message = ERR_ATTR_SYNTAX_OID_NO_VALUE1.get(reader.pos() - 1); |
| | | throw DecodeException.error(message); |
| | | throw DecodeException.error(ERR_ATTR_SYNTAX_OID_NO_VALUE1.get(reader.pos() - 1)); |
| | | } |
| | | |
| | | reader.reset(); |
| | |
| | | } |
| | | } else if (!isDigit(c)) { |
| | | // Technically, this must be an illegal character. |
| | | // However, |
| | | // it is possible that someone just got sloppy and did |
| | | // not |
| | | // However, it is possible that someone just got sloppy |
| | | // and did not |
| | | // include a space between the name/OID and a closing |
| | | // parenthesis. In that case, we'll assume it's the end |
| | | // of |
| | | // the value. |
| | | // of the value. |
| | | if (c == ')') { |
| | | break; |
| | | } |
| | |
| | | |
| | | return oid; |
| | | } catch (final StringIndexOutOfBoundsException e) { |
| | | final LocalizableMessage message = ERR_ATTR_SYNTAX_TRUNCATED_VALUE1.get(); |
| | | throw DecodeException.error(message); |
| | | throw DecodeException.error(ERR_ATTR_SYNTAX_TRUNCATED_VALUE1.get()); |
| | | } |
| | | } |
| | | |
| | |
| | | |
| | | return values; |
| | | } catch (final StringIndexOutOfBoundsException e) { |
| | | final LocalizableMessage message = ERR_ATTR_SYNTAX_TRUNCATED_VALUE1.get(); |
| | | throw DecodeException.error(message); |
| | | throw DecodeException.error(ERR_ATTR_SYNTAX_TRUNCATED_VALUE1.get()); |
| | | } |
| | | } |
| | | |
| | |
| | | reader.read(); |
| | | return str; |
| | | } catch (final StringIndexOutOfBoundsException e) { |
| | | final LocalizableMessage message = ERR_ATTR_SYNTAX_TRUNCATED_VALUE1.get(); |
| | | throw DecodeException.error(message); |
| | | throw DecodeException.error(ERR_ATTR_SYNTAX_TRUNCATED_VALUE1.get()); |
| | | } |
| | | } |
| | | |
| | |
| | | try { |
| | | return Integer.valueOf(ruleID); |
| | | } catch (final NumberFormatException e) { |
| | | final LocalizableMessage message = ERR_ATTR_SYNTAX_RULE_ID_INVALID1.get(ruleID); |
| | | throw DecodeException.error(message); |
| | | throw DecodeException.error(ERR_ATTR_SYNTAX_RULE_ID_INVALID1.get(ruleID)); |
| | | } |
| | | } catch (final StringIndexOutOfBoundsException e) { |
| | | final LocalizableMessage message = ERR_ATTR_SYNTAX_TRUNCATED_VALUE1.get(); |
| | | throw DecodeException.error(message); |
| | | throw DecodeException.error(ERR_ATTR_SYNTAX_TRUNCATED_VALUE1.get()); |
| | | } |
| | | } |
| | | |
| | |
| | | |
| | | return values; |
| | | } catch (final StringIndexOutOfBoundsException e) { |
| | | final LocalizableMessage message = ERR_ATTR_SYNTAX_TRUNCATED_VALUE1.get(); |
| | | throw DecodeException.error(message); |
| | | throw DecodeException.error(ERR_ATTR_SYNTAX_TRUNCATED_VALUE1.get()); |
| | | } |
| | | } |
| | | |
| | |
| | | |
| | | return token; |
| | | } catch (final StringIndexOutOfBoundsException e) { |
| | | final LocalizableMessage message = ERR_ATTR_SYNTAX_TRUNCATED_VALUE1.get(); |
| | | throw DecodeException.error(message); |
| | | throw DecodeException.error(ERR_ATTR_SYNTAX_TRUNCATED_VALUE1.get()); |
| | | } |
| | | } |
| | | |
| | |
| | | reader.read(); |
| | | return descr; |
| | | } catch (final StringIndexOutOfBoundsException e) { |
| | | final LocalizableMessage message = ERR_ATTR_SYNTAX_TRUNCATED_VALUE1.get(); |
| | | throw DecodeException.error(message); |
| | | throw DecodeException.error(ERR_ATTR_SYNTAX_TRUNCATED_VALUE1.get()); |
| | | } |
| | | } |
| | | |
| | |
| | | // Nothing to do. |
| | | } |
| | | |
| | | private static ByteString singleSpaceOrEmpty(final ByteSequence value) { |
| | | if (value.length() > 0) { |
| | | // This should only happen if the value is composed entirely of |
| | | // spaces. In that case, the normalized value is a single space. |
| | | return SchemaConstants.SINGLE_SPACE_VALUE; |
| | | } |
| | | // The value is empty, so it is already normalized. |
| | | return ByteString.empty(); |
| | | } |
| | | |
| | | static ByteString normalizeStringListAttributeValue(final ByteSequence value, boolean trim, boolean foldCase) { |
| | | final StringBuilder buffer = new StringBuilder(); |
| | | prepareUnicode(buffer, value, trim, foldCase); |
| | | |
| | | if (buffer.length() == 0) { |
| | | return singleSpaceOrEmpty(value); |
| | | } |
| | | trimConsecutiveSpacesInStringList(buffer); |
| | | return ByteString.valueOf(buffer.toString()); |
| | | } |
| | | |
| | | private static void trimConsecutiveSpacesInStringList(StringBuilder buffer) { |
| | | // Replace any consecutive spaces with a single space. Any spaces |
| | | // around a dollar sign will also be removed. |
| | | for (int pos = buffer.length() - 1; pos > 0; pos--) { |
| | | if (buffer.charAt(pos) == ' ') { |
| | | final char c = buffer.charAt(pos - 1); |
| | | if (c == ' ') { |
| | | buffer.delete(pos, pos + 1); |
| | | } else if (c == '$') { |
| | | if (pos <= 1 || buffer.charAt(pos - 2) != '\\') { |
| | | buffer.delete(pos, pos + 1); |
| | | } |
| | | } else if (buffer.charAt(pos + 1) == '$') { |
| | | buffer.delete(pos, pos + 1); |
| | | } |
| | | } |
| | | } |
| | | } |
| | | |
| | | static ByteString normalizeStringAttributeValue(final ByteSequence value, final boolean trim, |
| | | final boolean foldCase) { |
| | | final StringBuilder buffer = new StringBuilder(); |
| | | prepareUnicode(buffer, value, trim, foldCase); |
| | | |
| | | if (buffer.length() == 0) { |
| | | return singleSpaceOrEmpty(value); |
| | | } |
| | | trimConsecutiveSpaces(buffer); |
| | | return ByteString.valueOf(buffer.toString()); |
| | | } |
| | | |
| | | private static void trimConsecutiveSpaces(StringBuilder buffer) { |
| | | for (int pos = buffer.length() - 1; pos > 0; pos--) { |
| | | if (buffer.charAt(pos) == ' ' |
| | | && buffer.charAt(pos - 1) == ' ') { |
| | | buffer.delete(pos, pos + 1); |
| | | } |
| | | } |
| | | } |
| | | |
| | | static ByteString normalizeIA5StringAttributeValue(final ByteSequence value, boolean trim, boolean foldCase) |
| | | throws DecodeException { |
| | | final StringBuilder buffer = new StringBuilder(); |
| | | prepareUnicode(buffer, value, trim, foldCase); |
| | | |
| | | if (buffer.length() == 0) { |
| | | return singleSpaceOrEmpty(value); |
| | | } |
| | | trimConsecutiveSpacesInIA5String(buffer, value); |
| | | return ByteString.valueOf(buffer.toString()); |
| | | } |
| | | |
| | | private static void trimConsecutiveSpacesInIA5String(StringBuilder buffer, ByteSequence value) |
| | | throws DecodeException { |
| | | // Replace any consecutive spaces with a single space and watch out |
| | | // for non-ASCII characters. |
| | | for (int pos = buffer.length() - 1; pos > 0; pos--) { |
| | | final char c = buffer.charAt(pos); |
| | | if (c == ' ') { |
| | | if (buffer.charAt(pos - 1) == ' ') { |
| | | buffer.delete(pos, pos + 1); |
| | | } |
| | | } else if ((c & 0x7F) != c) { |
| | | // This is not a valid character for an IA5 string. If strict |
| | | // syntax enforcement is enabled, then we'll throw an exception. |
| | | // Otherwise, we'll get rid of the character. |
| | | throw DecodeException.error( |
| | | WARN_ATTR_SYNTAX_IA5_ILLEGAL_CHARACTER.get(value, c)); |
| | | } |
| | | } |
| | | } |
| | | |
| | | static ByteString normalizeNumericStringAttributeValue(final ByteSequence value) { |
| | | final StringBuilder buffer = new StringBuilder(); |
| | | prepareUnicode(buffer, value, TRIM, NO_CASE_FOLD); |
| | | |
| | | if (buffer.length() == 0) { |
| | | return ByteString.empty(); |
| | | } |
| | | return ByteString.valueOf(buffer.toString()); |
| | | } |
| | | |
| | | } |