/** * Creates a new UserSearchManager. * * @param con the XMPPConnection to use. */ public UserSearchManager(XMPPConnection con) { this.con = con; userSearch = new UserSearch(); }
/** * Returns the form to fill out to perform a search. * * @param searchService the search service to query. * @return the form to fill out to perform a search. * @throws XMPPErrorException * @throws NoResponseException * @throws NotConnectedException * @throws InterruptedException */ public Form getSearchForm(DomainBareJid searchService) throws NoResponseException, XMPPErrorException, NotConnectedException, InterruptedException { return userSearch.getSearchForm(con, searchService); }
/** * Submits a search form to the server and returns the resulting information * in the form of <code>ReportedData</code>. * * @param searchForm the <code>Form</code> to submit for searching. * @param searchService the name of the search service to use. * @return the ReportedData returned by the server. * @throws XMPPErrorException * @throws NoResponseException * @throws NotConnectedException * @throws InterruptedException */ public ReportedData getSearchResults(Form searchForm, DomainBareJid searchService) throws NoResponseException, XMPPErrorException, NotConnectedException, InterruptedException { return userSearch.sendSearchForm(con, searchForm, searchService); }
/** * Sends the filled out answer form to be sent and queried by the search service. * * @param con the current XMPPConnection. * @param searchForm the <code>Form</code> to send for querying. * @param searchService the search service to use. (ex. search.jivesoftware.com) * @return ReportedData the data found from the query. * @throws XMPPErrorException * @throws NoResponseException * @throws NotConnectedException * @throws InterruptedException */ public ReportedData sendSimpleSearchForm(XMPPConnection con, Form searchForm, DomainBareJid searchService) throws NoResponseException, XMPPErrorException, NotConnectedException, InterruptedException { SimpleUserSearch search = new SimpleUserSearch(); search.setForm(searchForm); search.setType(IQ.Type.set); search.setTo(searchService); SimpleUserSearch response = con.createStanzaCollectorAndSend(search).nextResultOrThrow(); return response.getReportedData(); }
/** * Sends the filled out answer form to be sent and queried by the search service. * * @param con the current XMPPConnection. * @param searchForm the <code>Form</code> to send for querying. * @param searchService the search service to use. (ex. search.jivesoftware.com) * @return ReportedData the data found from the query. * @throws XMPPErrorException * @throws NoResponseException * @throws NotConnectedException * @throws InterruptedException */ public ReportedData sendSearchForm(XMPPConnection con, Form searchForm, DomainBareJid searchService) throws NoResponseException, XMPPErrorException, NotConnectedException, InterruptedException { UserSearch search = new UserSearch(); search.setType(IQ.Type.set); search.setTo(searchService); search.addExtension(searchForm.getDataFormToSend()); IQ response = con.createStanzaCollectorAndSend(search).nextResultOrThrow(); return ReportedData.getReportedDataFrom(response); }
@Override public IQ parse(XmlPullParser parser, int initialDepth) throws Exception { UserSearch search = null; SimpleUserSearch simpleUserSearch = new SimpleUserSearch(); simpleUserSearch.parseItems(parser); return simpleUserSearch; search = new UserSearch(); PacketParserUtils.addExtensionElement(search, parser);
/** * Returns the form for all search fields supported by the search service. * * @param con the current XMPPConnection. * @param searchService the search service to use. (ex. search.jivesoftware.com) * @return the search form received by the server. * @throws XMPPErrorException * @throws NoResponseException * @throws NotConnectedException * @throws InterruptedException */ public Form getSearchForm(XMPPConnection con, DomainBareJid searchService) throws NoResponseException, XMPPErrorException, NotConnectedException, InterruptedException { UserSearch search = new UserSearch(); search.setType(IQ.Type.get); search.setTo(searchService); IQ response = con.createStanzaCollectorAndSend(search).nextResultOrThrow(); return Form.getFormFrom(response); }
protected void parseItems(XmlPullParser parser) throws XmlPullParserException, IOException { ReportedData data = new ReportedData(); data.addColumn(new ReportedData.Column("JID", "jid", FormField.Type.text_single)); List<String> valueList = new ArrayList<>(); valueList.add(jid); ReportedData.Field field = new ReportedData.Field("jid", valueList); fields.add(field); ReportedData.Row row = new ReportedData.Row(fields); data.addRow(row); ReportedData.Field field = new ReportedData.Field(name, valueList); fields.add(field); for (ReportedData.Column column : data.getColumns()) { if (column.getVariable().equals(name)) { exists = true; break; ReportedData.Column column = new ReportedData.Column(name, name, FormField.Type.text_single); data.addColumn(column);
if (search.getExtension("x", "jabber:x:data") == null) { search.addExtension(dataForm);
@Override protected IQChildElementXmlStringBuilder getIQChildElementBuilder(IQChildElementXmlStringBuilder buf) { buf.rightAngleBracket(); buf.append(getItemsToSearch()); return buf; }
private String getItemsToSearch() { StringBuilder buf = new StringBuilder(); if (form == null) { form = Form.getFormFrom(this); } if (form == null) { return ""; } for (FormField field : form.getFields()) { String name = field.getVariable(); String value = getSingleValue(field); if (value.trim().length() > 0) { buf.append('<').append(name).append('>').append(value).append("</").append(name).append('>'); } } return buf.toString(); }
/** * Returns the values of the field whose variable matches the requested variable. * * @param variable the variable to match. * @return the values of the field whose variable matches the requested variable. */ public List<CharSequence> getValues(String variable) { for (Field field : getFields()) { if (variable.equalsIgnoreCase(field.getVariable())) { return field.getValues(); } } return null; }
/** * Creates a new ReportedData based on the returned dataForm from a search *(namespace "jabber:iq:search"). * * @param dataForm the dataForm returned from a search (namespace "jabber:iq:search"). */ private ReportedData(DataForm dataForm) { // Add the columns to the report based on the reported data fields for (FormField field : dataForm.getReportedData().getFields()) { columns.add(new Column(field.getLabel(), field.getVariable(), field.getType())); } // Add the rows to the report based on the form's items for (Item item : dataForm.getItems()) { List<Field> fieldList = new ArrayList<>(columns.size()); for (FormField field : item.getFields()) { // The field is created with all the values of the data form's field List<CharSequence> values = new ArrayList<>(); values.addAll(field.getValues()); fieldList.add(new Field(field.getVariable(), values)); } rows.add(new Row(fieldList)); } // Set the report's title this.title = dataForm.getTitle(); }
/** * Submits the completed form and returns the result of the transcript search. The result * will include all the data returned from the server so be careful with the amount of * data that the search may return. * * @param serviceJID the address of the workgroup service. * @param completedForm the filled out search form. * @return the result of the transcript search. * @throws XMPPErrorException * @throws NoResponseException * @throws NotConnectedException * @throws InterruptedException */ public ReportedData submitSearch(DomainBareJid serviceJID, Form completedForm) throws NoResponseException, XMPPErrorException, NotConnectedException, InterruptedException { TranscriptSearch search = new TranscriptSearch(); search.setType(IQ.Type.get); search.setTo(serviceJID); search.addExtension(completedForm.getDataFormToSend()); TranscriptSearch response = connection.createStanzaCollectorAndSend( search).nextResultOrThrow(); return ReportedData.getReportedDataFrom(response); } }
/** * Returns a new ReportedData if the stanza is used for reporting data and includes an * extension that matches the elementName and namespace "x","jabber:x:data". * * @param packet the stanza used for reporting data. * @return ReportedData from the packet if present, otherwise null. */ public static ReportedData getReportedDataFrom(Stanza packet) { // Check if the packet includes the DataForm extension DataForm dataForm = DataForm.from(packet); if (dataForm != null) { if (dataForm.getReportedData() != null) return new ReportedData(dataForm); } // Otherwise return null return null; }
/** * Submits a search form to the server and returns the resulting information * in the form of <code>ReportedData</code> * * @param searchForm the <code>Form</code> to submit for searching. * @param searchService the name of the search service to use. * @return the ReportedData returned by the server. * @throws XMPPException thrown if a server error has occurred. */ public ReportedData getSearchResults(Form searchForm, String searchService) throws XMPPException { return userSearch.sendSearchForm(con, searchForm, searchService); }
/** * Returns the form to fill out to perform a search. * * @param searchService the search service to query. * @return the form to fill out to perform a search. * @throws XMPPException thrown if a server error has occurred. */ public Form getSearchForm(String searchService) throws XMPPException { return userSearch.getSearchForm(con, searchService); }
/** * Creates a new UserSearchManager. * * @param con the Connection to use. */ public UserSearchManager(Connection con) { this.con = con; userSearch = new UserSearch(); }
/** * Submits a search form to the server and returns the resulting information * in the form of <code>ReportedData</code> * * @param searchForm the <code>Form</code> to submit for searching. * @param searchService the name of the search service to use. * @return the ReportedData returned by the server. * @throws XMPPException thrown if a server error has occurred. */ public ReportedData getSearchResults(Form searchForm, String searchService) throws XMPPException { return userSearch.sendSearchForm(con, searchForm, searchService); }
/** * Returns the form to fill out to perform a search. * * @param searchService the search service to query. * @return the form to fill out to perform a search. * @throws XMPPException thrown if a server error has occurred. */ public Form getSearchForm(String searchService) throws XMPPException { return userSearch.getSearchForm(con, searchService); }