Search in sources :

Example 36 with Attribute

use of org.apache.directory.api.ldap.model.entry.Attribute in project directory-ldap-api by apache.

the class SearchResultEntryDsml method toDsml.

/**
 * {@inheritDoc}
 */
@Override
public Element toDsml(Element root) {
    Element element;
    if (root != null) {
        element = root.addElement(SEARCH_RESULT_ENTRY_TAG);
    } else {
        element = new DefaultElement(SEARCH_RESULT_ENTRY_TAG);
    }
    SearchResultEntry searchResultEntry = getDecorated();
    element.addAttribute("dn", searchResultEntry.getObjectName().getName());
    Entry entry = searchResultEntry.getEntry();
    for (Attribute attribute : entry) {
        Element attributeElement = element.addElement("attr");
        attributeElement.addAttribute("name", attribute.getUpId());
        for (Value value : attribute) {
            if (ParserUtils.needsBase64Encoding(value.getValue())) {
                Namespace xsdNamespace = new Namespace(ParserUtils.XSD, ParserUtils.XML_SCHEMA_URI);
                Namespace xsiNamespace = new Namespace(ParserUtils.XSI, ParserUtils.XML_SCHEMA_INSTANCE_URI);
                Document doc = attributeElement.getDocument();
                if (doc != null) {
                    Element docRoot = doc.getRootElement();
                    docRoot.add(xsdNamespace);
                    docRoot.add(xsiNamespace);
                }
                Element valueElement = attributeElement.addElement("value").addText(ParserUtils.base64Encode(value.getValue()));
                valueElement.addAttribute(new QName("type", xsiNamespace), ParserUtils.XSD + ":" + ParserUtils.BASE64BINARY);
            } else {
                attributeElement.addElement("value").addText(value.getValue());
            }
        }
    }
    return element;
}
Also used : SearchResultEntry(org.apache.directory.api.ldap.model.message.SearchResultEntry) Entry(org.apache.directory.api.ldap.model.entry.Entry) DefaultElement(org.dom4j.tree.DefaultElement) DefaultAttribute(org.apache.directory.api.ldap.model.entry.DefaultAttribute) Attribute(org.apache.directory.api.ldap.model.entry.Attribute) QName(org.dom4j.QName) DefaultElement(org.dom4j.tree.DefaultElement) Element(org.dom4j.Element) Value(org.apache.directory.api.ldap.model.entry.Value) Document(org.dom4j.Document) Namespace(org.dom4j.Namespace) SearchResultEntry(org.apache.directory.api.ldap.model.message.SearchResultEntry)

Example 37 with Attribute

use of org.apache.directory.api.ldap.model.entry.Attribute in project directory-ldap-api by apache.

the class AddRequestTest method testRequestWith1AttrWithBase64Value.

/**
 * Test parsing of a request with an Attr elements with value
 */
@Test
public void testRequestWith1AttrWithBase64Value() {
    Dsmlv2Parser parser = null;
    try {
        parser = newParser();
        parser.setInput(AddRequestTest.class.getResource("request_with_1_attr_with_base64_value.xml").openStream(), "UTF-8");
        parser.parse();
    } catch (Exception e) {
        fail(e.getMessage());
    }
    AddRequest addRequest = (AddRequest) parser.getBatchRequest().getCurrentRequest();
    Entry entry = addRequest.getEntry();
    assertEquals(1, entry.size());
    // Getting the Attribute
    Iterator<Attribute> attributeIterator = entry.iterator();
    Attribute attribute = attributeIterator.next();
    assertEquals("objectclass", attribute.getUpId());
    // Getting the Value
    Iterator<Value> valueIterator = attribute.iterator();
    assertTrue(valueIterator.hasNext());
    Value value = valueIterator.next();
    assertFalse(value.isHumanReadable());
    assertEquals("DSMLv2.0 rocks!!", value.getValue());
}
Also used : AddRequest(org.apache.directory.api.ldap.model.message.AddRequest) Entry(org.apache.directory.api.ldap.model.entry.Entry) Attribute(org.apache.directory.api.ldap.model.entry.Attribute) Value(org.apache.directory.api.ldap.model.entry.Value) Dsmlv2Parser(org.apache.directory.api.dsmlv2.Dsmlv2Parser) Test(org.junit.Test) AbstractTest(org.apache.directory.api.dsmlv2.AbstractTest)

Example 38 with Attribute

use of org.apache.directory.api.ldap.model.entry.Attribute in project directory-ldap-api by apache.

the class AddRequestTest method testRequestWith1AttrWithValue.

/**
 * Test parsing of a request with an Attr elements with value
 */
@Test
public void testRequestWith1AttrWithValue() {
    Dsmlv2Parser parser = null;
    try {
        parser = newParser();
        parser.setInput(AddRequestTest.class.getResource("request_with_1_attr_with_value.xml").openStream(), "UTF-8");
        parser.parse();
    } catch (Exception e) {
        fail(e.getMessage());
    }
    AddRequest addRequest = (AddRequest) parser.getBatchRequest().getCurrentRequest();
    Entry entry = addRequest.getEntry();
    assertEquals(1, entry.size());
    // Getting the Attribute
    Iterator<Attribute> attributeIterator = entry.iterator();
    Attribute attribute = attributeIterator.next();
    assertEquals("objectclass", attribute.getUpId());
    // Getting the Value
    Iterator<Value> valueIterator = attribute.iterator();
    assertTrue(valueIterator.hasNext());
    Value value = valueIterator.next();
    assertEquals("top", value.getValue());
}
Also used : AddRequest(org.apache.directory.api.ldap.model.message.AddRequest) Entry(org.apache.directory.api.ldap.model.entry.Entry) Attribute(org.apache.directory.api.ldap.model.entry.Attribute) Value(org.apache.directory.api.ldap.model.entry.Value) Dsmlv2Parser(org.apache.directory.api.dsmlv2.Dsmlv2Parser) Test(org.junit.Test) AbstractTest(org.apache.directory.api.dsmlv2.AbstractTest)

Example 39 with Attribute

use of org.apache.directory.api.ldap.model.entry.Attribute in project directory-ldap-api by apache.

the class AddRequestTest method testRequestWith2AttrWithValue.

/**
 * Test parsing of a request with 2 Attr elements with value
 */
@Test
public void testRequestWith2AttrWithValue() {
    Dsmlv2Parser parser = null;
    try {
        parser = newParser();
        parser.setInput(AddRequestTest.class.getResource("request_with_2_attr_with_value.xml").openStream(), "UTF-8");
        parser.parse();
    } catch (Exception e) {
        fail(e.getMessage());
    }
    AddRequest addRequest = (AddRequest) parser.getBatchRequest().getCurrentRequest();
    Entry entry = addRequest.getEntry();
    assertEquals(1, entry.size());
    // Getting the Attribute
    Iterator<Attribute> attributeIterator = entry.iterator();
    Attribute attribute = attributeIterator.next();
    assertEquals("objectclass", attribute.getUpId());
    // Getting the Value
    Iterator<Value> valueIterator = attribute.iterator();
    assertTrue(valueIterator.hasNext());
    Value value = valueIterator.next();
    assertEquals("top", value.getValue());
    assertTrue(valueIterator.hasNext());
    value = valueIterator.next();
    assertEquals("person", value.getValue());
    assertFalse(valueIterator.hasNext());
}
Also used : AddRequest(org.apache.directory.api.ldap.model.message.AddRequest) Entry(org.apache.directory.api.ldap.model.entry.Entry) Attribute(org.apache.directory.api.ldap.model.entry.Attribute) Value(org.apache.directory.api.ldap.model.entry.Value) Dsmlv2Parser(org.apache.directory.api.dsmlv2.Dsmlv2Parser) Test(org.junit.Test) AbstractTest(org.apache.directory.api.dsmlv2.AbstractTest)

Example 40 with Attribute

use of org.apache.directory.api.ldap.model.entry.Attribute in project directory-ldap-api by apache.

the class LdapNetworkConnection method modify.

/**
 * {@inheritDoc}
 */
@Override
public void modify(Entry entry, ModificationOperation modOp) throws LdapException {
    if (entry == null) {
        if (LOG.isDebugEnabled()) {
            LOG.debug(I18n.msg(I18n.MSG_03241_NULL_ENTRY_MODIFY));
        }
        throw new IllegalArgumentException("Entry to be modified cannot be null");
    }
    ModifyRequest modReq = new ModifyRequestImpl();
    modReq.setName(entry.getDn());
    Iterator<Attribute> itr = entry.iterator();
    while (itr.hasNext()) {
        modReq.addModification(itr.next(), modOp);
    }
    ModifyResponse modifyResponse = modify(modReq);
    processResponse(modifyResponse);
}
Also used : ModifyRequestImpl(org.apache.directory.api.ldap.model.message.ModifyRequestImpl) Attribute(org.apache.directory.api.ldap.model.entry.Attribute) ModifyRequest(org.apache.directory.api.ldap.model.message.ModifyRequest) ModifyResponse(org.apache.directory.api.ldap.model.message.ModifyResponse)

Aggregations

Attribute (org.apache.directory.api.ldap.model.entry.Attribute)269 Test (org.junit.Test)180 DefaultAttribute (org.apache.directory.api.ldap.model.entry.DefaultAttribute)168 Entry (org.apache.directory.api.ldap.model.entry.Entry)94 Modification (org.apache.directory.api.ldap.model.entry.Modification)56 Value (org.apache.directory.api.ldap.model.entry.Value)52 DefaultEntry (org.apache.directory.api.ldap.model.entry.DefaultEntry)46 DefaultModification (org.apache.directory.api.ldap.model.entry.DefaultModification)35 LdapException (org.apache.directory.api.ldap.model.exception.LdapException)23 EncoderException (org.apache.directory.api.asn1.EncoderException)20 ByteBuffer (java.nio.ByteBuffer)18 DecoderException (org.apache.directory.api.asn1.DecoderException)18 Asn1Decoder (org.apache.directory.api.asn1.ber.Asn1Decoder)18 LdapMessageContainer (org.apache.directory.api.ldap.codec.api.LdapMessageContainer)18 AbstractCodecServiceTest (org.apache.directory.api.ldap.codec.osgi.AbstractCodecServiceTest)18 SearchResultEntry (org.apache.directory.api.ldap.model.message.SearchResultEntry)18 LdapInvalidAttributeValueException (org.apache.directory.api.ldap.model.exception.LdapInvalidAttributeValueException)16 LdifEntry (org.apache.directory.api.ldap.model.ldif.LdifEntry)16 ModifyRequest (org.apache.directory.api.ldap.model.message.ModifyRequest)14 ByteArrayInputStream (java.io.ByteArrayInputStream)13