Search in sources :

Example 11 with DitStructureRule

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

the class DitStructureRuleDescriptionSchemaParserTest method testForm.

/**
 * Tests FORM
 *
 * @throws ParseException
 */
@Test
public void testForm() throws ParseException {
    String value = null;
    DitStructureRule ditStructureRule = null;
    // numeric oid
    value = "( 1 FORM 1.2.3.4.5.6.7.8.9.0 )";
    ditStructureRule = parser.parseDITStructureRuleDescription(value);
    assertEquals("1.2.3.4.5.6.7.8.9.0", ditStructureRule.getForm());
    // numeric oid
    value = "(   1    FORM    123.4567.890    )";
    ditStructureRule = parser.parseDITStructureRuleDescription(value);
    assertEquals("123.4567.890", ditStructureRule.getForm());
    // descr
    value = "( 1 FORM abcdefghijklmnopqrstuvwxyz-ABCDEFGHIJKLMNOPQRSTUVWXYZ-0123456789 )";
    ditStructureRule = parser.parseDITStructureRuleDescription(value);
    assertEquals("abcdefghijklmnopqrstuvwxyz-ABCDEFGHIJKLMNOPQRSTUVWXYZ-0123456789", ditStructureRule.getForm());
    // descr, no space
    value = "(1 FORMabc)";
    ditStructureRule = parser.parseDITStructureRuleDescription(value);
    assertEquals("abc", ditStructureRule.getForm());
    // descr, tab
    value = "\t(\t1\tFORM\tabc\t)\t";
    ditStructureRule = parser.parseDITStructureRuleDescription(value);
    assertEquals("abc", ditStructureRule.getForm());
    // quoted value
    value = "( 1 FORM '1.2.3.4.5.6.7.8.9.0' )";
    ditStructureRule = parser.parseDITStructureRuleDescription(value);
    assertEquals("1.2.3.4.5.6.7.8.9.0", ditStructureRule.getForm());
    // no quote allowed
    value = "( 1 FORM ('test') )";
    ditStructureRule = parser.parseDITStructureRuleDescription(value);
    assertEquals("test", ditStructureRule.getForm());
    // invalid character
    value = "( 1 FORM 1.2.3.4.A )";
    try {
        ditStructureRule = parser.parseDITStructureRuleDescription(value);
        fail("Exception expected, invalid FORM 1.2.3.4.A (invalid character)");
    } catch (ParseException pe) {
    // expected
    }
    // no multiple values
    value = "( 1 FORM ( test1 test2 ) )";
    try {
        ditStructureRule = parser.parseDITStructureRuleDescription(value);
        fail("Exception expected, FORM must be single valued");
    } catch (ParseException pe) {
    // expected
    }
    if (!parser.isQuirksMode()) {
        // invalid start
        value = "( 1 FORM -test ) )";
        try {
            ditStructureRule = parser.parseDITStructureRuleDescription(value);
            fail("Exception expected, invalid FORM '-test' (starts with hypen)");
        } catch (ParseException pe) {
        // expected
        }
    }
}
Also used : DitStructureRule(org.apache.directory.api.ldap.model.schema.DitStructureRule) ParseException(java.text.ParseException) Test(org.junit.Test)

Example 12 with DitStructureRule

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

the class DefaultSchemaLoader method loadDitStructureRules.

/**
 * {@inheritDoc}
 */
@Override
public List<Entry> loadDitStructureRules(Schema... schemas) throws LdapException, IOException {
    List<Entry> ditStructureRuleEntries = new ArrayList<>();
    if (schemas == null) {
        return ditStructureRuleEntries;
    }
    AttributesFactory factory = new AttributesFactory();
    for (Schema schema : schemas) {
        Set<SchemaObjectWrapper> schemaObjectWrappers = schema.getContent();
        for (SchemaObjectWrapper schemaObjectWrapper : schemaObjectWrappers) {
            SchemaObject schemaObject = schemaObjectWrapper.get();
            if (schemaObject instanceof DitStructureRule) {
                DitStructureRule ditStructureRule = (DitStructureRule) schemaObject;
                Entry ditStructureRuleEntry = factory.convert(ditStructureRule, schema, null);
                ditStructureRuleEntries.add(ditStructureRuleEntry);
            }
        }
    }
    return ditStructureRuleEntries;
}
Also used : SchemaObject(org.apache.directory.api.ldap.model.schema.SchemaObject) DefaultEntry(org.apache.directory.api.ldap.model.entry.DefaultEntry) Entry(org.apache.directory.api.ldap.model.entry.Entry) AttributesFactory(org.apache.directory.api.ldap.model.schema.AttributesFactory) DitStructureRule(org.apache.directory.api.ldap.model.schema.DitStructureRule) DefaultSchema(org.apache.directory.api.ldap.model.schema.registries.DefaultSchema) Schema(org.apache.directory.api.ldap.model.schema.registries.Schema) ArrayList(java.util.ArrayList) SchemaObjectWrapper(org.apache.directory.api.ldap.model.schema.SchemaObjectWrapper)

Aggregations

DitStructureRule (org.apache.directory.api.ldap.model.schema.DitStructureRule)12 ParseException (java.text.ParseException)5 Test (org.junit.Test)5 LdapException (org.apache.directory.api.ldap.model.exception.LdapException)4 SchemaObject (org.apache.directory.api.ldap.model.schema.SchemaObject)4 AttributeType (org.apache.directory.api.ldap.model.schema.AttributeType)2 DitContentRule (org.apache.directory.api.ldap.model.schema.DitContentRule)2 LdapSyntax (org.apache.directory.api.ldap.model.schema.LdapSyntax)2 LoadableSchemaObject (org.apache.directory.api.ldap.model.schema.LoadableSchemaObject)2 MatchingRule (org.apache.directory.api.ldap.model.schema.MatchingRule)2 MatchingRuleUse (org.apache.directory.api.ldap.model.schema.MatchingRuleUse)2 MutableAttributeType (org.apache.directory.api.ldap.model.schema.MutableAttributeType)2 MutableMatchingRule (org.apache.directory.api.ldap.model.schema.MutableMatchingRule)2 NameForm (org.apache.directory.api.ldap.model.schema.NameForm)2 ObjectClass (org.apache.directory.api.ldap.model.schema.ObjectClass)2 SchemaObjectWrapper (org.apache.directory.api.ldap.model.schema.SchemaObjectWrapper)2 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 HashSet (java.util.HashSet)1 Map (java.util.Map)1