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;
}
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());
}
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());
}
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());
}
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);
}
Aggregations