Search in sources :

Example 16 with Normalizer

use of org.apache.directory.api.ldap.model.schema.Normalizer in project directory-ldap-api by apache.

the class ConcreteNameComponentNormalizer method normalizeByName.

/**
 * {@inheritDoc}
 */
@Override
public Object normalizeByName(AttributeType attributeType, String value) throws LdapException {
    MatchingRule mrule = attributeType.getEquality();
    Normalizer normalizer;
    if (mrule == null) {
        return new NoOpNormalizer(attributeType.getOid());
    } else {
        normalizer = attributeType.getEquality().getNormalizer();
    }
    if (attributeType.getSyntax().isHumanReadable()) {
        return normalizer.normalize(value);
    } else {
        String unescaped = unescape(value);
        return normalizer.normalize(unescaped);
    }
}
Also used : Normalizer(org.apache.directory.api.ldap.model.schema.Normalizer) MatchingRule(org.apache.directory.api.ldap.model.schema.MatchingRule)

Example 17 with Normalizer

use of org.apache.directory.api.ldap.model.schema.Normalizer in project directory-ldap-api by apache.

the class DeepTrimToLowerNormalizerTest method testSpeed.

@Test
@Ignore
public void testSpeed() throws Exception {
    Normalizer normalizer = new DeepTrimToLowerNormalizer();
    String t = "xs crvtbynU  Jikl7897A90";
    normalizer.normalize(t);
    long t0 = System.currentTimeMillis();
    for (int i = 0; i < 100000000; i++) {
        normalizer.normalize(t);
    }
    long t1 = System.currentTimeMillis();
    System.out.println(t1 - t0);
    Strings.deepTrimToLower(t);
    t0 = System.currentTimeMillis();
    for (int i = 0; i < 100000000; i++) {
        Strings.deepTrimToLower(t);
    }
    t1 = System.currentTimeMillis();
    System.out.println(t1 - t0);
}
Also used : DeepTrimToLowerNormalizer(org.apache.directory.api.ldap.model.schema.normalizers.DeepTrimToLowerNormalizer) DeepTrimToLowerNormalizer(org.apache.directory.api.ldap.model.schema.normalizers.DeepTrimToLowerNormalizer) Normalizer(org.apache.directory.api.ldap.model.schema.Normalizer) Ignore(org.junit.Ignore) Test(org.junit.Test)

Example 18 with Normalizer

use of org.apache.directory.api.ldap.model.schema.Normalizer in project directory-ldap-api by apache.

the class DeepTrimToLowerNormalizerTest method testInsignifiantSpacesStringNCombining.

@Test
public void testInsignifiantSpacesStringNCombining() throws LdapException {
    Normalizer normalizer = new DeepTrimToLowerNormalizer("1.1.1");
    char[] chars = new char[] { 'e', 0x0301, ' ', 'a', 0x0300, 'i', 0x0302 };
    char[] expected = new char[] { ' ', '\u00E9', ' ', ' ', '\u00E0', '\u00EE', ' ' };
    assertEquals(new String(expected), normalizer.normalize(new String(chars)));
}
Also used : DeepTrimToLowerNormalizer(org.apache.directory.api.ldap.model.schema.normalizers.DeepTrimToLowerNormalizer) DeepTrimToLowerNormalizer(org.apache.directory.api.ldap.model.schema.normalizers.DeepTrimToLowerNormalizer) Normalizer(org.apache.directory.api.ldap.model.schema.Normalizer) Test(org.junit.Test)

Example 19 with Normalizer

use of org.apache.directory.api.ldap.model.schema.Normalizer in project directory-ldap-api by apache.

the class DeepTrimToLowerNormalizerTest method testNormalizeCharsCombiningSpaces.

@Test
public void testNormalizeCharsCombiningSpaces() throws LdapException {
    Normalizer normalizer = new DeepTrimToLowerNormalizer("1.1.1");
    char[] chars = new char[] { 'a', 'm', ' ', 'e', 0x0301, 'l', 'i', 'e' };
    char[] expected = new char[] { ' ', 'a', 'm', ' ', ' ', '\u00e9', 'l', 'i', 'e', ' ' };
    String expectedStr = new String(expected);
    String charsStr = new String(chars);
    assertEquals(expectedStr, normalizer.normalize(charsStr));
}
Also used : DeepTrimToLowerNormalizer(org.apache.directory.api.ldap.model.schema.normalizers.DeepTrimToLowerNormalizer) DeepTrimToLowerNormalizer(org.apache.directory.api.ldap.model.schema.normalizers.DeepTrimToLowerNormalizer) Normalizer(org.apache.directory.api.ldap.model.schema.Normalizer) Test(org.junit.Test)

Example 20 with Normalizer

use of org.apache.directory.api.ldap.model.schema.Normalizer in project directory-ldap-api by apache.

the class DeepTrimToLowerNormalizerTest method testDeepTrimToLowerNormalizerOneSpace.

@Test
public void testDeepTrimToLowerNormalizerOneSpace() throws LdapException {
    Normalizer normalizer = new DeepTrimToLowerNormalizer("1.1.1");
    assertEquals("  ", normalizer.normalize(" "));
}
Also used : DeepTrimToLowerNormalizer(org.apache.directory.api.ldap.model.schema.normalizers.DeepTrimToLowerNormalizer) DeepTrimToLowerNormalizer(org.apache.directory.api.ldap.model.schema.normalizers.DeepTrimToLowerNormalizer) Normalizer(org.apache.directory.api.ldap.model.schema.Normalizer) Test(org.junit.Test)

Aggregations

Normalizer (org.apache.directory.api.ldap.model.schema.Normalizer)78 Test (org.junit.Test)59 DeepTrimToLowerNormalizer (org.apache.directory.api.ldap.model.schema.normalizers.DeepTrimToLowerNormalizer)20 DeepTrimNormalizer (org.apache.directory.api.ldap.model.schema.normalizers.DeepTrimNormalizer)15 TelephoneNumberNormalizer (org.apache.directory.api.ldap.model.schema.normalizers.TelephoneNumberNormalizer)12 LdapException (org.apache.directory.api.ldap.model.exception.LdapException)10 NumericNormalizer (org.apache.directory.api.ldap.model.schema.normalizers.NumericNormalizer)9 SchemaManager (org.apache.directory.api.ldap.model.schema.SchemaManager)7 NoOpNormalizer (org.apache.directory.api.ldap.model.schema.normalizers.NoOpNormalizer)7 DefaultSchemaManager (org.apache.directory.api.ldap.schema.manager.impl.DefaultSchemaManager)7 MutableAttributeType (org.apache.directory.api.ldap.model.schema.MutableAttributeType)6 PrepareString (org.apache.directory.api.ldap.model.schema.PrepareString)6 LdapSchemaException (org.apache.directory.api.ldap.model.exception.LdapSchemaException)5 LdapSyntax (org.apache.directory.api.ldap.model.schema.LdapSyntax)5 MatchingRule (org.apache.directory.api.ldap.model.schema.MatchingRule)5 MutableMatchingRule (org.apache.directory.api.ldap.model.schema.MutableMatchingRule)4 SyntaxChecker (org.apache.directory.api.ldap.model.schema.SyntaxChecker)4 ByteArrayComparator (org.apache.directory.api.ldap.model.schema.comparators.ByteArrayComparator)4 BooleanNormalizer (org.apache.directory.api.ldap.model.schema.normalizers.BooleanNormalizer)4 LdapProtocolErrorException (org.apache.directory.api.ldap.model.exception.LdapProtocolErrorException)3