Search in sources :

Example 1 with ByteArrayComparator

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

the class BinaryValueTest method initAT.

/**
 * Initialize an AttributeType and the associated MatchingRule
 * and Syntax
 */
@Before
public void initAT() {
    s = EntryUtils.syntaxFactory("1.1.1.1", false);
    s.setSyntaxChecker(OctetStringSyntaxChecker.INSTANCE);
    mr = EntryUtils.matchingRuleFactory("1.1.2.1");
    mr.setSyntax(s);
    mr.setLdapComparator(new ByteArrayComparator("1.1.1"));
    mr.setNormalizer(new Normalizer("1.1.1") {

        public static final long serialVersionUID = 1L;

        public String normalize(String value) throws LdapException {
            return normalize(value, PrepareString.AssertionType.ATTRIBUTE_VALUE);
        }

        public String normalize(String value, PrepareString.AssertionType assertionType) throws LdapException {
            byte[] val = Strings.getBytesUtf8(value);
            // each byte will be changed to be > 0, and spaces will be trimmed
            byte[] newVal = new byte[val.length];
            int i = 0;
            for (byte b : val) {
                newVal[i++] = (byte) (b & 0x007F);
            }
            return Strings.utf8ToString(Strings.trim(newVal));
        }
    });
    at = new MutableAttributeType("1.1.3.1");
    at.setEquality(mr);
    at.setOrdering(mr);
    at.setSubstring(mr);
    at.setSyntax(s);
}
Also used : PrepareString(org.apache.directory.api.ldap.model.schema.PrepareString) Normalizer(org.apache.directory.api.ldap.model.schema.Normalizer) PrepareString(org.apache.directory.api.ldap.model.schema.PrepareString) MutableAttributeType(org.apache.directory.api.ldap.model.schema.MutableAttributeType) ByteArrayComparator(org.apache.directory.api.ldap.model.schema.comparators.ByteArrayComparator) LdapException(org.apache.directory.api.ldap.model.exception.LdapException) Before(org.junit.Before)

Example 2 with ByteArrayComparator

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

the class TestEntryUtils method getBytesAttributeType.

/* No protection */
static AttributeType getBytesAttributeType() {
    MutableAttributeType attributeType = new MutableAttributeType("1.2");
    LdapSyntax syntax = new LdapSyntax("1.2.1", "", true);
    syntax.setSyntaxChecker(new SyntaxChecker("1.2.1") {

        /**
         * The mandatory serialVersionUID field
         */
        public static final long serialVersionUID = 1L;

        public boolean isValidSyntax(Object value) {
            return (value == null) || (((byte[]) value).length < 5);
        }
    });
    MutableMatchingRule matchingRule = new MutableMatchingRule("1.2.2");
    matchingRule.setSyntax(syntax);
    matchingRule.setLdapComparator(new ByteArrayComparator("1.2.2"));
    matchingRule.setNormalizer(new Normalizer("1.1.1") {

        /**
         * The mandatory serialVersionUID field
         */
        public static final long serialVersionUID = 1L;

        public String normalize(String value) throws LdapException {
            return normalize(value, AssertionType.ATTRIBUTE_VALUE);
        }

        public String normalize(String value, PrepareString.AssertionType assertionType) throws LdapException {
            byte[] val = Strings.getBytesUtf8(value);
            // each byte will be changed to be > 0, and spaces will be trimmed
            byte[] newVal = new byte[val.length];
            int i = 0;
            for (byte b : val) {
                newVal[i++] = (byte) (b & 0x007F);
            }
            return Strings.utf8ToString(Strings.trim(newVal));
        }
    });
    attributeType.setEquality(matchingRule);
    attributeType.setSyntax(syntax);
    return attributeType;
}
Also used : MutableMatchingRule(org.apache.directory.api.ldap.model.schema.MutableMatchingRule) SyntaxChecker(org.apache.directory.api.ldap.model.schema.SyntaxChecker) PrepareString(org.apache.directory.api.ldap.model.schema.PrepareString) DeepTrimToLowerNormalizer(org.apache.directory.api.ldap.model.schema.normalizers.DeepTrimToLowerNormalizer) Normalizer(org.apache.directory.api.ldap.model.schema.Normalizer) AssertionType(org.apache.directory.api.ldap.model.schema.PrepareString.AssertionType) LdapSyntax(org.apache.directory.api.ldap.model.schema.LdapSyntax) PrepareString(org.apache.directory.api.ldap.model.schema.PrepareString) MutableAttributeType(org.apache.directory.api.ldap.model.schema.MutableAttributeType) ByteArrayComparator(org.apache.directory.api.ldap.model.schema.comparators.ByteArrayComparator) LdapException(org.apache.directory.api.ldap.model.exception.LdapException)

Example 3 with ByteArrayComparator

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

the class BinaryValueAttributeTypeTest method initAT.

/**
 * Initialize an AttributeType and the associated MatchingRule
 * and Syntax
 */
@Before
public void initAT() {
    s = EntryUtils.syntaxFactory("1.1.1.1", false);
    s.setSyntaxChecker(OctetStringSyntaxChecker.INSTANCE);
    mr = EntryUtils.matchingRuleFactory("1.1.2.1");
    mr.setSyntax(s);
    mr.setLdapComparator(new ByteArrayComparator("1.1.1"));
    mr.setNormalizer(new Normalizer("1.1.1") {

        public static final long serialVersionUID = 1L;

        public String normalize(String value) throws LdapException {
            return normalize(value, PrepareString.AssertionType.ATTRIBUTE_VALUE);
        }

        public String normalize(String value, PrepareString.AssertionType assertionType) throws LdapException {
            byte[] val = Strings.getBytesUtf8(value);
            // each byte will be changed to be > 0, and spaces will be trimmed
            byte[] newVal = new byte[val.length];
            int i = 0;
            for (byte b : val) {
                newVal[i++] = (byte) (b & 0x007F);
            }
            return Strings.utf8ToString(Strings.trim(newVal));
        }
    });
    at = new MutableAttributeType("1.1.3.1");
    at.setEquality(mr);
    at.setOrdering(mr);
    at.setSubstring(mr);
    at.setSyntax(s);
}
Also used : PrepareString(org.apache.directory.api.ldap.model.schema.PrepareString) Normalizer(org.apache.directory.api.ldap.model.schema.Normalizer) PrepareString(org.apache.directory.api.ldap.model.schema.PrepareString) MutableAttributeType(org.apache.directory.api.ldap.model.schema.MutableAttributeType) ByteArrayComparator(org.apache.directory.api.ldap.model.schema.comparators.ByteArrayComparator) LdapException(org.apache.directory.api.ldap.model.exception.LdapException) Before(org.junit.Before)

Example 4 with ByteArrayComparator

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

the class EntryUtils method getBytesAttributeType.

/* No protection */
static AttributeType getBytesAttributeType() {
    MutableAttributeType attributeType = new MutableAttributeType("1.2");
    LdapSyntax syntax = new LdapSyntax("1.2.1", "", false);
    syntax.setSyntaxChecker(new SyntaxChecker("1.2.1") {

        public static final long serialVersionUID = 1L;

        public boolean isValidSyntax(Object value) {
            return (value == null) || (((byte[]) value).length < 5);
        }
    });
    MutableMatchingRule matchingRule = new MutableMatchingRule("1.2.2");
    matchingRule.setSyntax(syntax);
    matchingRule.setLdapComparator(new ByteArrayComparator("1.2.2"));
    matchingRule.setNormalizer(new NoOpNormalizer("1.1.1"));
    attributeType.setEquality(matchingRule);
    attributeType.setSyntax(syntax);
    return attributeType;
}
Also used : MutableMatchingRule(org.apache.directory.api.ldap.model.schema.MutableMatchingRule) NoOpNormalizer(org.apache.directory.api.ldap.model.schema.normalizers.NoOpNormalizer) SyntaxChecker(org.apache.directory.api.ldap.model.schema.SyntaxChecker) LdapSyntax(org.apache.directory.api.ldap.model.schema.LdapSyntax) MutableAttributeType(org.apache.directory.api.ldap.model.schema.MutableAttributeType) ByteArrayComparator(org.apache.directory.api.ldap.model.schema.comparators.ByteArrayComparator)

Example 5 with ByteArrayComparator

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

the class ValueSerializationTest method initAT.

/**
 * Initialize an AttributeType and the associated MatchingRule
 * and Syntax
 */
@Before
public void initAT() {
    sb = new EntryUtils.S("1.1.1.1", false);
    sb.setSyntaxChecker(OctetStringSyntaxChecker.INSTANCE);
    mrb = new EntryUtils.MR("1.1.2.1");
    mrb.setSyntax(sb);
    mrb.setLdapComparator(new ByteArrayComparator("1.1.1"));
    mrb.setNormalizer(new Normalizer("1.1.1") {

        public static final long serialVersionUID = 1L;

        public String normalize(String value) throws LdapException {
            return normalize(value, PrepareString.AssertionType.ATTRIBUTE_VALUE);
        }

        public String normalize(String value, PrepareString.AssertionType assertionType) throws LdapException {
            byte[] val = Strings.getBytesUtf8(value);
            // each byte will be changed to be > 0, and spaces will be trimmed
            byte[] newVal = new byte[val.length];
            int i = 0;
            for (byte b : val) {
                newVal[i++] = (byte) (b & 0x007F);
            }
            return Strings.utf8ToString(Strings.trim(newVal));
        }
    });
    atb = new EntryUtils.AT("1.1.3.1");
    atb.setEquality(mrb);
    atb.setOrdering(mrb);
    atb.setSubstring(mrb);
    atb.setSyntax(sb);
    ss = new EntryUtils.S("1.1.1.1", true);
    ss.setSyntaxChecker(OctetStringSyntaxChecker.INSTANCE);
    mrs = new EntryUtils.MR("1.1.2.1");
    mrs.setSyntax(ss);
    mrs.setLdapComparator(new StringComparator("1.1.2.1"));
    mrs.setNormalizer(new DeepTrimToLowerNormalizer("1.1.2.1"));
    ats = new EntryUtils.AT("1.1.3.1");
    ats.setEquality(mrs);
    ats.setOrdering(mrs);
    ats.setSubstring(mrs);
    ats.setSyntax(ss);
}
Also used : DeepTrimToLowerNormalizer(org.apache.directory.api.ldap.model.schema.normalizers.DeepTrimToLowerNormalizer) Normalizer(org.apache.directory.api.ldap.model.schema.Normalizer) PrepareString(org.apache.directory.api.ldap.model.schema.PrepareString) StringComparator(org.apache.directory.api.ldap.model.schema.comparators.StringComparator) DeepTrimToLowerNormalizer(org.apache.directory.api.ldap.model.schema.normalizers.DeepTrimToLowerNormalizer) PrepareString(org.apache.directory.api.ldap.model.schema.PrepareString) ByteArrayComparator(org.apache.directory.api.ldap.model.schema.comparators.ByteArrayComparator) LdapException(org.apache.directory.api.ldap.model.exception.LdapException) Before(org.junit.Before)

Aggregations

ByteArrayComparator (org.apache.directory.api.ldap.model.schema.comparators.ByteArrayComparator)5 LdapException (org.apache.directory.api.ldap.model.exception.LdapException)4 MutableAttributeType (org.apache.directory.api.ldap.model.schema.MutableAttributeType)4 Normalizer (org.apache.directory.api.ldap.model.schema.Normalizer)4 PrepareString (org.apache.directory.api.ldap.model.schema.PrepareString)4 Before (org.junit.Before)3 LdapSyntax (org.apache.directory.api.ldap.model.schema.LdapSyntax)2 MutableMatchingRule (org.apache.directory.api.ldap.model.schema.MutableMatchingRule)2 SyntaxChecker (org.apache.directory.api.ldap.model.schema.SyntaxChecker)2 DeepTrimToLowerNormalizer (org.apache.directory.api.ldap.model.schema.normalizers.DeepTrimToLowerNormalizer)2 AssertionType (org.apache.directory.api.ldap.model.schema.PrepareString.AssertionType)1 StringComparator (org.apache.directory.api.ldap.model.schema.comparators.StringComparator)1 NoOpNormalizer (org.apache.directory.api.ldap.model.schema.normalizers.NoOpNormalizer)1