/** * This will take a DSML <code>Document</code> and convert it to an Iterator of LDAP search * results. * * @param doc <code>Document</code> of DSML * @return <code>Iterator</code> - of LDAP search results */ public Iterator<SearchResult> createSearchResults(final Document doc) { final List<SearchResult> results = new ArrayList<SearchResult>(); if (doc != null && doc.hasContent()) { final Iterator<?> entryIterator = doc.selectNodes("/dsml:dsml/dsml:directory-entries/dsml:entry").iterator(); while (entryIterator.hasNext()) { final LdapEntry result = this.createSearchResult((Element) entryIterator.next()); if (result != null) { results.add(result.toSearchResult()); } } } return results.iterator(); }
/** * This will take a DSML <code>Element</code> containing an entry of type <dsml:entry * name="name"/> and convert it to an LDAP entry. * * @param entryElement <code>Element</code> of DSML content * @return <code>LdapEntry</code> */ protected LdapEntry createSearchResult(final Element entryElement) { final LdapEntry ldapEntry = new LdapEntry(); ldapEntry.setDn(""); if (entryElement != null) { final String name = entryElement.attributeValue("dn"); if (name != null) { ldapEntry.setDn(name); } if (entryElement.hasContent()) { final Iterator<?> ocIterator = entryElement.elementIterator("objectclass"); while (ocIterator.hasNext()) { final Element ocElement = (Element) ocIterator.next(); if (ocElement != null && ocElement.hasContent()) { final String ocName = "objectClass"; final LdapAttribute ldapAttribute = new LdapAttribute(ocName); final Iterator<?> valueIterator = ocElement.elementIterator("oc-value"); while (valueIterator.hasNext()) { final Element valueElement = (Element) valueIterator.next(); if (valueElement != null) { final String value = valueElement.getText(); if (value != null) { final String encoding = valueElement.attributeValue("encoding"); if (encoding != null && encoding.equals("base64")) { ldapAttribute.getValues().add(LdapUtil.base64Decode(value)); } else { ldapAttribute.getValues().add(value); } } } } ldapEntry.getLdapAttributes().addAttribute(ldapAttribute); } } ldapEntry .getLdapAttributes() .addAttributes( super.createSearchResult(entryElement).getLdapAttributes().getAttributes()); } } return ldapEntry; }
/** * @param ldifFile to create. * @param webXml web.xml for queries * @throws Exception On test failure. */ @Parameters({"createEntry10", "webXml"}) @BeforeClass(groups = {"servlettest"}) public void createLdapEntry(final String ldifFile, final String webXml) throws Exception { final String ldif = TestUtil.readFileIntoString(ldifFile); testLdapEntry = TestUtil.convertLdifToEntry(ldif); Ldap ldap = TestUtil.createSetupLdap(); ldap.create(testLdapEntry.getDn(), testLdapEntry.getLdapAttributes().toAttributes()); ldap.close(); ldap = TestUtil.createLdap(); while (!ldap.compare( testLdapEntry.getDn(), new SearchFilter(testLdapEntry.getDn().split(",")[0]))) { Thread.sleep(100); } ldap.close(); this.ldifServletRunner = new ServletRunner(new File(webXml)); this.dsmlServletRunner = new ServletRunner(new File(webXml)); }
/** @throws Exception On test failure. */ @AfterClass(groups = {"servlettest"}) public void deleteLdapEntry() throws Exception { final Ldap ldap = TestUtil.createSetupLdap(); ldap.delete(testLdapEntry.getDn()); ldap.close(); }