@Override protected void writeResponse(final SearchResult result, final HttpServletResponse response) throws IOException { response.setContentType("text/xml"); final Dsmlv1Writer writer = new Dsmlv1Writer( new BufferedWriter(new OutputStreamWriter(response.getOutputStream()))); writer.write(result); } }
/** * Returns a list of <dsml:attr/> elements for the supplied attributes. * * @param doc to source elements from * @param attrs to iterate over * * @return list of elements contains attributes */ protected List<Element> createDsmlAttributes(final Document doc, final Collection<LdapAttribute> attrs) { final List<Element> attrElements = new ArrayList<>(); for (LdapAttribute attr : attrs) { final String attrName = attr.getName(); Element attrElement; if ("objectclass".equalsIgnoreCase(attrName)) { attrElement = createObjectclassElement(doc, attr); if (attrElement.hasChildNodes()) { attrElements.add(0, attrElement); } } else { attrElement = createAttrElement(doc, attr); if (attrElement.hasChildNodes()) { attrElements.add(attrElement); } } } return attrElements; }
/** * Writes the supplied search result to the writer. * * @param result search result to write * * @throws IOException if an error occurs using the writer */ @Override public void write(final SearchResult result) throws IOException { try { final Transformer transformer = TRANSFORMER_FACTORY.newTransformer(); for (Map.Entry<String, String> prop : outputProperties.entrySet()) { transformer.setOutputProperty(prop.getKey(), prop.getValue()); } final StreamResult sr = new StreamResult(dsmlWriter); final DOMSource source = new DOMSource(createDsml(result)); transformer.transform(source, sr); dsmlWriter.flush(); } catch (ParserConfigurationException | TransformerException e) { throw new IOException(e); } }
/** * Executes the ldap search operation. * * @param cf connection factory * @param request search request * * @return status code * * @throws Exception on any LDAP search error */ protected int search(final ConnectionFactory cf, final SearchRequest request) throws Exception { final Connection conn = cf.getConnection(); conn.open(); final SearchOperation op = new SearchOperation(conn); final Response<SearchResult> response = op.execute(request); final SearchResult result = response.getResult(); final SearchResultWriter writer; if (outputDsmlv1) { writer = new Dsmlv1Writer(new BufferedWriter(new OutputStreamWriter(System.out))); } else { writer = new LdifWriter(new BufferedWriter(new OutputStreamWriter(System.out))); } writer.write(result); conn.close(); return response.getResultCode().value(); }
/** * Returns a <dsml:objectclass/> element for the supplied ldap attribute. * * @param doc to source elements from * @param attr ldap attribute to add * * @return element containing the attribute values */ protected Element createObjectclassElement(final Document doc, final LdapAttribute attr) { final Element ocElement = doc.createElement("dsml:objectclass"); for (String s : attr.getStringValues()) { final Element ocValueElement = doc.createElement("dsml:oc-value"); ocElement.appendChild(ocValueElement); setAttrValue(doc, ocValueElement, s, attr.isBinary()); } return ocElement; }
entryElement.setAttribute("dn", le.getDn()); createDsmlAttributes(doc, le.getAttributes()).forEach(entryElement::appendChild); entriesElement.appendChild(entryElement);
/** * Executes the ldap search operation. * * @param cf connection factory * @param request search request * * @return status code * * @throws Exception on any LDAP search error */ protected int search(final ConnectionFactory cf, final SearchRequest request) throws Exception { final Connection conn = cf.getConnection(); conn.open(); final SearchOperation op = new SearchOperation(conn); final Response<SearchResult> response = op.execute(request); final SearchResult result = response.getResult(); final SearchResultWriter writer; if (outputDsmlv1) { writer = new Dsmlv1Writer(new BufferedWriter(new OutputStreamWriter(System.out))); } else { writer = new LdifWriter(new BufferedWriter(new OutputStreamWriter(System.out))); } writer.write(result); conn.close(); return response.getResultCode().value(); }
/** * Returns a <dsml:objectclass/> element for the supplied ldap attribute. * * @param doc to source elements from * @param attr ldap attribute to add * * @return element containing the attribute values */ protected Element createObjectclassElement(final Document doc, final LdapAttribute attr) { final Element ocElement = doc.createElement("dsml:objectclass"); for (String s : attr.getStringValues()) { final Element ocValueElement = doc.createElement("dsml:oc-value"); ocElement.appendChild(ocValueElement); setAttrValue(doc, ocValueElement, s, attr.isBinary()); } return ocElement; }
entryElement.setAttribute("dn", le.getDn()); for (Element e : createDsmlAttributes(doc, le.getAttributes())) { entryElement.appendChild(e);
@Override protected void writeResponse(final SearchResult result, final HttpServletResponse response) throws IOException { response.setContentType("text/xml"); final Dsmlv1Writer writer = new Dsmlv1Writer( new BufferedWriter(new OutputStreamWriter(response.getOutputStream()))); writer.write(result); } }
final SearchResultWriter writer; if (outputDsmlv1) { writer = new Dsmlv1Writer(new BufferedWriter(new OutputStreamWriter(System.out))); } else { writer = new LdifWriter(new BufferedWriter(new OutputStreamWriter(System.out)));
/** * Returns a list of <dsml:attr/> elements for the supplied attributes. * * @param doc to source elements from * @param attrs to iterate over * * @return list of elements contains attributes */ protected List<Element> createDsmlAttributes(final Document doc, final Collection<LdapAttribute> attrs) { final List<Element> attrElements = new ArrayList<>(); for (LdapAttribute attr : attrs) { final String attrName = attr.getName(); final Element attrElement; if ("objectclass".equalsIgnoreCase(attrName)) { attrElement = createObjectclassElement(doc, attr); if (attrElement.hasChildNodes()) { attrElements.add(0, attrElement); } } else { attrElement = createAttrElement(doc, attr); if (attrElement.hasChildNodes()) { attrElements.add(attrElement); } } } return attrElements; }
/** * Returns a <dsml:objectclass/> element for the supplied ldap attribute. * * @param doc to source elements from * @param attr ldap attribute to add * * @return element containing the attribute values */ protected Element createObjectclassElement(final Document doc, final LdapAttribute attr) { final Element ocElement = doc.createElement("dsml:objectclass"); for (String s : attr.getStringValues()) { final Element ocValueElement = doc.createElement("dsml:oc-value"); ocElement.appendChild(ocValueElement); setAttrValue(doc, ocValueElement, s, attr.isBinary()); } return ocElement; }
/** * Writes the supplied search result to the writer. * * @param result search result to write * * @throws IOException if an error occurs using the writer */ @Override public void write(final SearchResult result) throws IOException { try { final Transformer transformer = TRANSFORMER_FACTORY.newTransformer(); for (Map.Entry<String, String> prop : outputProperties.entrySet()) { transformer.setOutputProperty(prop.getKey(), prop.getValue()); } final StreamResult sr = new StreamResult(dsmlWriter); final DOMSource source = new DOMSource(createDsml(result)); transformer.transform(source, sr); dsmlWriter.flush(); } catch (ParserConfigurationException | TransformerException e) { throw new IOException(e); } }
entryElement.setAttribute("dn", le.getDn()); createDsmlAttributes(doc, le.getAttributes()).forEach(entryElement::appendChild); entriesElement.appendChild(entryElement);
@Override protected void writeResponse(final SearchResult result, final HttpServletResponse response) throws IOException { response.setContentType("text/xml"); final Dsmlv1Writer writer = new Dsmlv1Writer( new BufferedWriter(new OutputStreamWriter(response.getOutputStream()))); writer.write(result); } }
/** * Executes the ldap search operation. * * @param cf connection factory * @param request search request * * @return status code * * @throws Exception on any LDAP search error */ protected int search(final ConnectionFactory cf, final SearchRequest request) throws Exception { final Connection conn = cf.getConnection(); conn.open(); final SearchOperation op = new SearchOperation(conn); final Response<SearchResult> response = op.execute(request); final SearchResult result = response.getResult(); SearchResultWriter writer; if (outputDsmlv1) { writer = new Dsmlv1Writer(new BufferedWriter(new OutputStreamWriter(System.out))); } else { writer = new LdifWriter(new BufferedWriter(new OutputStreamWriter(System.out))); } writer.write(result); conn.close(); return response.getResultCode().value(); }
/** * Returns a list of <dsml:attr/> elements for the supplied attributes. * * @param doc to source elements from * @param attrs to iterate over * * @return list of elements contains attributes */ protected List<Element> createDsmlAttributes(final Document doc, final Collection<LdapAttribute> attrs) { final List<Element> attrElements = new ArrayList<>(); for (LdapAttribute attr : attrs) { final String attrName = attr.getName(); final Element attrElement; if ("objectclass".equalsIgnoreCase(attrName)) { attrElement = createObjectclassElement(doc, attr); if (attrElement.hasChildNodes()) { attrElements.add(0, attrElement); } } else { attrElement = createAttrElement(doc, attr); if (attrElement.hasChildNodes()) { attrElements.add(attrElement); } } } return attrElements; }
/** * Returns a <dsml:attr/> element for the supplied ldap attribute. * * @param doc to source elements from * @param attr ldap attribute to add * * @return element containing the attribute */ protected Element createAttrElement(final Document doc, final LdapAttribute attr) { final Element attrElement = doc.createElement("dsml:attr"); attrElement.setAttribute("name", attr.getName()); for (String s : attr.getStringValues()) { final Element valueElement = doc.createElement("dsml:value"); attrElement.appendChild(valueElement); setAttrValue(doc, valueElement, s, attr.isBinary()); } return attrElement; }
/** * Writes the supplied search result to the writer. * * @param result search result to write * * @throws IOException if an error occurs using the writer */ @Override public void write(final SearchResult result) throws IOException { try { final Transformer transformer = TRANSFORMER_FACTORY.newTransformer(); for (Map.Entry<String, String> prop : outputProperties.entrySet()) { transformer.setOutputProperty(prop.getKey(), prop.getValue()); } final StreamResult sr = new StreamResult(dsmlWriter); final DOMSource source = new DOMSource(createDsml(result)); transformer.transform(source, sr); dsmlWriter.flush(); } catch (ParserConfigurationException | TransformerException e) { throw new IOException(e); } }