Commit ec8cad81 authored by guus's avatar guus

Deprecated org.jivesoftware.openfire.forms in favor of org.xmpp.forms (TINDER-1)

git-svn-id: http://svn.igniterealtime.org/svn/repos/openfire/trunk@11053 b35dd754-fafc-0310-a699-88a17e54d16e
parent 06c4956c
<?xml version="1.0" encoding="UTF-8"?>
<projectDescription>
<name>Openfire</name>
<comment></comment>
<projects>
</projects>
<buildSpec>
<buildCommand>
<name>org.eclipse.jdt.core.javabuilder</name>
<arguments>
</arguments>
</buildCommand>
</buildSpec>
<natures>
<nature>org.eclipse.jdt.core.javanature</nature>
</natures>
</projectDescription>
...@@ -28,7 +28,6 @@ import org.jivesoftware.openfire.commands.clearspace.SystemAdminAdded; ...@@ -28,7 +28,6 @@ import org.jivesoftware.openfire.commands.clearspace.SystemAdminAdded;
import org.jivesoftware.openfire.commands.clearspace.SystemAdminRemoved; import org.jivesoftware.openfire.commands.clearspace.SystemAdminRemoved;
import org.jivesoftware.openfire.commands.event.*; import org.jivesoftware.openfire.commands.event.*;
import org.jivesoftware.openfire.disco.*; import org.jivesoftware.openfire.disco.*;
import org.jivesoftware.openfire.forms.spi.XDataFormImpl;
import org.jivesoftware.openfire.handler.IQHandler; import org.jivesoftware.openfire.handler.IQHandler;
import org.xmpp.forms.DataForm; import org.xmpp.forms.DataForm;
import org.xmpp.packet.IQ; import org.xmpp.packet.IQ;
......
/**
* $RCSfile$
* $Revision: 128 $
* $Date: 2004-10-25 20:42:00 -0300 (Mon, 25 Oct 2004) $
*
* Copyright (C) 2004-2008 Jive Software. All rights reserved.
*
* This software is published under the terms of the GNU Public License (GPL),
* a copy of which is included in this distribution, or a commercial license
* agreement with Jive.
*/
package org.jivesoftware.openfire.forms;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
/**
* Represents a form that could be use for gathering data as well as for reporting data
* returned from a search.
* <p/>
* The form could be of the following types:
* <ul>
* <li>form -> Indicates a form to fill out.</li>
* <li>submit -> The form is filled out, and this is the data that is being returned from
* the form.</li>
* <li>cancel -> The form was cancelled. Tell the asker that piece of information.</li>
* <li>result -> Data results being returned from a search, or some other query.</li>
* </ul>
* <p/>
* In case the form represents a search, the report will be structured in columns and rows. Use
* {@link #addReportedField(FormField)} to set the columns of the report whilst the report's rows
* can be configured using {@link #addItemFields(ArrayList)}.
*
* @author gdombiak
* @deprecated replaced by {@link org.xmpp.forms.DataForm}
*/
@Deprecated
public interface DataForm {
public static final String TYPE_FORM = "form";
public static final String TYPE_SUBMIT = "submit";
public static final String TYPE_CANCEL = "cancel";
public static final String TYPE_RESULT = "result";
/**
* Sets the description of the data. It is similar to the title on a web page or an X window.
* You can put a <title/> on either a form to fill out, or a set of data results.
*
* @param title description of the data.
*/
public abstract void setTitle(String title);
/**
* Sets the list of instructions that explain how to fill out the form and what the form is
* about. The dataform could include multiple instructions since each instruction could not
* contain newlines characters.
*
* @param instructions list of instructions that explain how to fill out the form.
*/
public abstract void setInstructions(List instructions);
/**
* Returns the meaning of the data within the context. The data could be part of a form
* to fill out, a form submission or data results.<p>
* <p/>
* Possible form types are:
* <ul>
* <li>form -> This packet contains a form to fill out. Display it to the user (if your
* program can).</li>
* <li>submit -> The form is filled out, and this is the data that is being returned from
* the form.</li>
* <li>cancel -> The form was cancelled. Tell the asker that piece of information.</li>
* <li>result -> Data results being returned from a search, or some other query.</li>
* </ul>
*
* @return the form's type.
*/
public abstract String getType();
/**
* Returns the description of the data. It is similar to the title on a web page or an X
* window. You can put a <title/> on either a form to fill out, or a set of data results.
*
* @return description of the data.
*/
public abstract String getTitle();
/**
* Returns an Iterator for the list of instructions that explain how to fill out the form and
* what the form is about. The dataform could include multiple instructions since each
* instruction could not contain newlines characters. Join the instructions together in order
* to show them to the user.
*
* @return an Iterator for the list of instructions that explain how to fill out the form.
*/
public abstract Iterator getInstructions();
/**
* Returns the field of the form whose variable matches the specified variable.
* The fields of type FIXED will never be returned since they do not specify a
* variable.
*
* @param variable the variable to look for in the form fields.
* @return the field of the form whose variable matches the specified variable.
*/
public FormField getField(String variable);
/**
* Returns an Iterator for the fields that are part of the form.
*
* @return an Iterator for the fields that are part of the form.
*/
public abstract Iterator getFields();
/**
* Returns the number of fields included in the form.
*
* @return the number of fields included in the form.
*/
public abstract int getFieldsSize();
/**
* Adds a new instruction to the list of instructions that explain how to fill out the form
* and what the form is about. The dataform could include multiple instructions since each
* instruction could not contain newlines characters.
*
* @param instruction the new instruction that explain how to fill out the form.
*/
public abstract void addInstruction(String instruction);
/**
* Adds a new field as part of the form.
*
* @param field the field to add to the form.
*/
public abstract void addField(FormField field);
/**
* Adds a field to the list of fields that will be returned from a search. Each field represents
* a column in the report. The order of the columns in the report will honor the sequence in
* which they were added.
*
* @param field the field to add to the list of fields that will be returned from a search.
*/
public abstract void addReportedField(FormField field);
/**
* Adds a new row of items of reported data. The list of items to add will be formed by
* FormFields. Each FormField variable <b>must</b> be valid (i.e. the variable must be defined
* by the FormFields added as ReportedField.
*
* @param itemFields list of FormFields to add as a row in the report.
*/
public abstract void addItemFields(ArrayList itemFields);
}
/**
* $RCSfile$
* $Revision: 223 $
* $Date: 2004-11-07 22:52:36 -0300 (Sun, 07 Nov 2004) $
*
* Copyright (C) 2004-2008 Jive Software. All rights reserved.
*
* This software is published under the terms of the GNU Public License (GPL),
* a copy of which is included in this distribution, or a commercial license
* agreement with Jive.
*/
package org.jivesoftware.openfire.forms;
import java.util.Iterator;
/**
* Represents a field of a form. The field could be used to represent a question to complete,
* a completed question or a data returned from a search. The exact interpretation of the field
* depends on the context where the field is used.
*
* @author Gaston Dombiak
* @deprecated replaced by {@link org.xmpp.forms.FormField}
*/
@Deprecated
public interface FormField {
public static final String TYPE_BOOLEAN = "boolean";
public static final String TYPE_FIXED = "fixed";
public static final String TYPE_HIDDEN = "hidden";
public static final String TYPE_JID_MULTI = "jid-multi";
public static final String TYPE_JID_SINGLE = "jid-single";
public static final String TYPE_LIST_MULTI = "list-multi";
public static final String TYPE_LIST_SINGLE = "list-single";
public static final String TYPE_TEXT_MULTI = "text-multi";
public static final String TYPE_TEXT_PRIVATE = "text-private";
public static final String TYPE_TEXT_SINGLE = "text-single";
/**
* Adds a default value to the question if the question is part of a form to fill out.
* Otherwise, adds an answered value to the question.
*
* @param value a default value or an answered value of the question.
*/
public void addValue(String value);
/**
* Removes all the values of the field.
*/
public void clearValues();
/**
* Adds an available option to the question that the user has in order to answer
* the question.
*
* @param label a label that represents the option.
* @param value the value of the option.
*/
public void addOption(String label, String value);
/**
* Sets an indicative of the format for the data to answer. Valid formats are:
* <p/>
* <ul>
* <li>text-single -> single line or word of text
* <li>text-private -> instead of showing the user what they typed, you show ***** to
* protect it
* <li>text-multi -> multiple lines of text entry
* <li>list-single -> given a list of choices, pick one
* <li>list-multi -> given a list of choices, pick one or more
* <li>boolean -> 0 or 1, true or false, yes or no. Default value is 0
* <li>fixed -> fixed for putting in text to show sections, or just advertise your web
* site in the middle of the form
* <li>hidden -> is not given to the user at all, but returned with the questionnaire
* <li>jid-single -> Jabber ID - choosing a JID from your roster, and entering one based
* on the rules for a JID.
* <li>jid-multi -> multiple entries for JIDs
* </ul>
*
* @param type an indicative of the format for the data to answer.
*/
public abstract void setType(String type);
/**
* Sets if the question must be answered in order to complete the questionnaire.
*
* @param required if the question must be answered in order to complete the questionnaire.
*/
public abstract void setRequired(boolean required);
/**
* Sets the label of the question which should give enough information to the user to
* fill out the form.
*
* @param label the label of the question.
*/
public abstract void setLabel(String label);
/**
* Sets a description that provides extra clarification about the question. This information
* could be presented to the user either in tool-tip, help button, or as a section of text
* before the question.<p>
* <p/>
* If the question is of type FIXED then the description should remain empty.
*
* @param description provides extra clarification about the question.
*/
public abstract void setDescription(String description);
/**
* Returns true if the question must be answered in order to complete the questionnaire.
*
* @return true if the question must be answered in order to complete the questionnaire.
*/
public abstract boolean isRequired();
/**
* Returns the variable name that the question is filling out.
*
* @return the variable name of the question.
*/
public abstract String getVariable();
/**
* Returns an Iterator for the default values of the question if the question is part
* of a form to fill out. Otherwise, returns an Iterator for the answered values of
* the question.
*
* @return an Iterator for the default values or answered values of the question.
*/
public abstract Iterator<String> getValues();
/**
* Returns an indicative of the format for the data to answer. Valid formats are:
* <p/>
* <ul>
* <li>text-single -> single line or word of text
* <li>text-private -> instead of showing the user what they typed, you show ***** to
* protect it
* <li>text-multi -> multiple lines of text entry
* <li>list-single -> given a list of choices, pick one
* <li>list-multi -> given a list of choices, pick one or more
* <li>boolean -> 0 or 1, true or false, yes or no. Default value is 0
* <li>fixed -> fixed for putting in text to show sections, or just advertise your web
* site in the middle of the form
* <li>hidden -> is not given to the user at all, but returned with the questionnaire
* <li>jid-single -> Jabber ID - choosing a JID from your roster, and entering one based
* on the rules for a JID.
* <li>jid-multi -> multiple entries for JIDs
* </ul>
*
* @return format for the data to answer.
*/
public abstract String getType();
/**
* Returns the label of the question which should give enough information to the user to
* fill out the form.
*
* @return label of the question.
*/
public abstract String getLabel();
/**
* Returns a description that provides extra clarification about the question. This information
* could be presented to the user either in tool-tip, help button, or as a section of text
* before the question.<p>
* <p/>
* If the question is of type FIXED then the description should remain empty.
*
* @return description that provides extra clarification about the question.
*/
public abstract String getDescription();
}
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
</head>
<body>
<p>Data forms implementation (JEP-0004).</p>
</body>
</html>
/**
* $RCSfile$
* $Revision: 904 $
* $Date: 2005-01-25 15:41:48 -0300 (Tue, 25 Jan 2005) $
*
* Copyright (C) 2004-2008 Jive Software. All rights reserved.
*
* This software is published under the terms of the GNU Public License (GPL),
* a copy of which is included in this distribution, or a commercial license
* agreement with Jive.
*/
package org.jivesoftware.openfire.forms.spi;
import org.jivesoftware.openfire.forms.FormField;
import java.util.*;
import org.dom4j.DocumentHelper;
import org.dom4j.Element;
import org.dom4j.QName;
/**
* A concrete DataForm capable of sending itself to a writer and recover its state from an XMPP
* stanza. XDataForms are packets of the form:
* <code><pre>
* &lt;x xmlns='jabber:x:data' type='{form-type}'&gt;
* &lt;title/&gt;
* &lt;instructions/&gt;
* &lt;field var='field-name'
* type='{field-type}'
* label='description'&gt;
* &lt;desc/&gt;
* &lt;required/&gt;
* &lt;value&gt;field-value&lt;/value&gt;
* &lt;option label='option-label'&gt;&lt;value&gt;option-value&lt;/value&gt;&lt;/option&gt;
* &lt;option label='option-label'&gt;&lt;value&gt;option-value&lt;/value&gt;&lt;/option&gt;
* &lt;/field&gt;
* &lt;/x&gt;
* </pre></code>
* <p/>
* An XDataFormImpl can contain zero or more XFormFieldImpl 'field' fragments.<p>
* <p/>
* To learn more follow this link: <a href="http://www.jabber.org/jeps/jep-0004.html">JEP-04</a>.
*
* @author gdombiak
* @deprecated replaced by {@link org.xmpp.forms.DataForm}
*/
@Deprecated
public class XDataFormImpl {
private String type;
private String title;
private List instructions = new ArrayList();
private List fields = new ArrayList();
private List reportedFields = new ArrayList();
private List reportedItems = new ArrayList();
public XDataFormImpl() {
super();
}
public XDataFormImpl(String type) {
this.type = type;
}
public void setTitle(String title) {
this.title = title;
}
public void setInstructions(List instructions) {
this.instructions = instructions;
}
public String getType() {
return type;
}
public String getTitle() {
return title;
}
public Iterator getInstructions() {
synchronized (instructions) {
return Collections.unmodifiableList(new ArrayList(instructions)).iterator();
}
}
public FormField getField(String variable) {
if (variable == null || variable.equals("")) {
throw new IllegalArgumentException("Variable must not be null or blank.");
}
// Look for the field whose variable matches the requested variable
FormField field;
for (Iterator it = getFields(); it.hasNext();) {
field = (FormField)it.next();
if (variable.equals(field.getVariable())) {
return field;
}
}
return null;
}
public Iterator getFields() {
synchronized (fields) {
return Collections.unmodifiableList(new ArrayList(fields)).iterator();
}
}
public int getFieldsSize() {
return fields.size();
}
public void addInstruction(String instruction) {
synchronized (instructions) {
instructions.add(instruction);
}
}
public void addField(FormField field) {
synchronized (fields) {
fields.add(field);
}
}
public void addReportedField(FormField field) {
synchronized (reportedFields) {
reportedFields.add(field);
}
}
public void addItemFields(ArrayList itemFields) {
synchronized (reportedItems) {
// We are nesting a List (of fields) inside of the List of items
reportedItems.add(itemFields);
}
}
public String getNamespace() {
// Is someone sending this message?
return "jabber:x:data";
}
public void setNamespace(String namespace) {
// Is someone sending this message?
// Do nothing
}
public String getName() {
// Is someone sending this message?
return "x";
}
public void setName(String name) {
// Is someone sending this message?
// Do nothing
}
public Element asXMLElement() {
Element x = DocumentHelper.createElement(QName.get("x", "jabber:x:data"));
if (getType() != null) {
x.addAttribute("type", getType());
}
if (getTitle() != null) {
x.addElement("title").addText(getTitle());
}
if (instructions.size() > 0) {
Iterator instrItr = getInstructions();
while (instrItr.hasNext()) {
x.addElement("instructions").addText((String)instrItr.next());
}
}
// Append the list of fields returned from a search
if (reportedFields.size() > 0) {
Element reportedElement = x.addElement("reported");
Iterator fieldsItr = reportedFields.iterator();
while (fieldsItr.hasNext()) {
XFormFieldImpl field = (XFormFieldImpl)fieldsItr.next();
reportedElement.add(field.asXMLElement());
}
}
// Append the list of items returned from a search
// Note: each item contains a List of XFormFieldImpls
if (reportedItems.size() > 0) {
Iterator itemsItr = reportedItems.iterator();
while (itemsItr.hasNext()) {
// Add a new item element for this list of fields
Element itemElement = x.addElement("item");
List fields = (List)itemsItr.next();
Iterator fieldsItr = fields.iterator();
// Iterate on the fields and add them to the new item
while (fieldsItr.hasNext()) {
XFormFieldImpl field = (XFormFieldImpl)fieldsItr.next();
itemElement.add(field.asXMLElement());
}
}
}
if (fields.size() > 0) {
Iterator fieldsItr = getFields();
while (fieldsItr.hasNext()) {
XFormFieldImpl field = (XFormFieldImpl)fieldsItr.next();
x.add(field.asXMLElement());
}
}
return x;
}
public void parse(Element formElement) {
type = formElement.attributeValue("type");
Element titleElement = formElement.element("title");
if (titleElement != null) {
setTitle(titleElement.getTextTrim());
}
Iterator instructionElements = formElement.elementIterator("instructions");
while (instructionElements.hasNext()) {
addInstruction(((Element)instructionElements.next()).getTextTrim());
}
Iterator fieldElements = formElement.elementIterator("field");
while (fieldElements.hasNext()) {
XFormFieldImpl field = new XFormFieldImpl();
field.parse((Element)fieldElements.next());
addField(field);
}
Element reportedElement = formElement.element("reported");
if (reportedElement != null) {
Iterator reportedFieldElements = reportedElement.elementIterator("field");
while (reportedFieldElements.hasNext()) {
XFormFieldImpl field = new XFormFieldImpl();
field.parse((Element)reportedFieldElements.next());
addReportedField(field);
}
}
Iterator itemElements = formElement.elementIterator("item");
while (itemElements.hasNext()) {
Element itemElement = (Element)itemElements.next();
Iterator itemFieldElements = itemElement.elementIterator("field");
ArrayList itemFields = new ArrayList();
while (itemFieldElements.hasNext()) {
XFormFieldImpl field = new XFormFieldImpl();
field.parse((Element)itemFieldElements.next());
itemFields.add(field);
}
addItemFields(itemFields);
}
}
}
\ No newline at end of file
/**
* $RCSfile$
* $Revision: 942 $
* $Date: 2005-02-02 21:55:43 -0300 (Wed, 02 Feb 2005) $
*
* Copyright (C) 2004-2008 Jive Software. All rights reserved.
*
* This software is published under the terms of the GNU Public License (GPL),
* a copy of which is included in this distribution, or a commercial license
* agreement with Jive.
*/
package org.jivesoftware.openfire.forms.spi;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Iterator;
import java.util.List;
import org.dom4j.DocumentHelper;
import org.dom4j.Element;
import org.dom4j.QName;
import org.jivesoftware.openfire.forms.FormField;
/**
* A concrete FormField capable of sending itself to a writer and recover its state from an XMPP
* stanza.
*
* @author gdombiak
* @deprecated replaced by {@link org.xmpp.forms.FormField}
*/
@Deprecated
public class XFormFieldImpl implements FormField {
private String description;
private boolean required = false;
private String label;
private String variable;
private String type;
private List<Option> options = new ArrayList<Option>();
private List<String> values = new ArrayList<String>();
public XFormFieldImpl() {
super();
}
public XFormFieldImpl(String variable) {
this.variable = variable;
}
public String getNamespace() {
// Is someone sending this message?
return "jabber:x:data";
}
public void setNamespace(String namespace) {
// Is someone sending this message?
// Do nothing
}
public String getName() {
// Is someone sending this message?
return "x";
}
public void setName(String name) {
// Is someone sending this message?
// Do nothing
}
public Element asXMLElement() {
Element field = DocumentHelper.createElement(QName.get("field", "jabber:x:data"));
if (getLabel() != null) {
field.addAttribute("label", getLabel());
}
if (getVariable() != null) {
field.addAttribute("var", getVariable());
}
if (getType() != null) {
field.addAttribute("type", getType());
}
if (getDescription() != null) {
field.addElement("desc").addText(getDescription());
}
if (isRequired()) {
field.addElement("required");
}
// Loop through all the values and append them to the stream writer
if (values.size() > 0) {
Iterator<String> valuesItr = getValues();
while (valuesItr.hasNext()) {
field.addElement("value").addText(valuesItr.next());
}
}
// Loop through all the options and append them to the stream writer
if (options.size() > 0) {
Iterator<Option> optionsItr = getOptions();
while (optionsItr.hasNext()) {
field.add((optionsItr.next()).asXMLElement());
}
}
// Loop through all the values and append them to the stream writer
/*Iterator frags = fragments.iterator();
while (frags.hasNext()){
XMPPFragment frag = (XMPPFragment) frags.next();
frag.send(xmlSerializer,version);
}*/
return field;
}
public void addValue(String value) {
if (value == null) {
value = "";
}
synchronized (values) {
values.add(value);
}
}
public void clearValues() {
synchronized (values) {
values.clear();
}
}
public void addOption(String label, String value) {
synchronized (options) {
options.add(new Option(label, value));
}
}
public void setType(String type) {
this.type = type;
}
public void setRequired(boolean required) {
this.required = required;
}
public void setLabel(String label) {
this.label = label;
}
public void setDescription(String description) {
this.description = description;
}
public boolean isRequired() {
return required;
}
public String getVariable() {
return variable;
}
public Iterator<String> getValues() {
synchronized (values) {
return Collections.unmodifiableList(new ArrayList<String>(values)).iterator();
}
}
public String getType() {
return type;
}
/**
* Returns an Iterator for the available options that the user has in order to answer
* the question.
*
* @return Iterator for the available options.
*/
private Iterator<Option> getOptions() {
synchronized (options) {
return Collections.unmodifiableList(new ArrayList<Option>(options)).iterator();
}
}
public String getLabel() {
return label;
}
public String getDescription() {
return description;
}
public void parse(Element formElement) {
variable = formElement.attributeValue("var");
setLabel(formElement.attributeValue("label"));
setType(formElement.attributeValue("type"));
Element descElement = formElement.element("desc");
if (descElement != null) {
setDescription(descElement.getTextTrim());
}
if (formElement.element("required") != null) {
setRequired(true);
}
Iterator valueElements = formElement.elementIterator("value");
while (valueElements.hasNext()) {
addValue(((Element)valueElements.next()).getTextTrim());
}
Iterator optionElements = formElement.elementIterator("option");
Element optionElement;
while (optionElements.hasNext()) {
optionElement = (Element)optionElements.next();
addOption(optionElement.attributeValue("label"), optionElement.elementTextTrim("value"));
}
}
public String toString() {
return "XFormFieldImpl " + Integer.toHexString(hashCode()) + " " + getVariable() + ">" + values
+ " o: " + (options.isEmpty() ? "no options" : options.toString());
}
/**
* Represents the available option of a given FormField.
*
* @author Gaston Dombiak
*/
private static class Option {
private String label;
private String value;
public Option(String label, String value) {
this.label = label;
this.value = value;
}
/**
* Returns the label that represents the option.
*
* @return the label that represents the option.
*/
public String getLabel() {
return label;
}
/**
* Returns the value of the option.
*
* @return the value of the option.
*/
public String getValue() {
return value;
}
public Element asXMLElement() {
Element option = DocumentHelper.createElement(QName.get("option", "jabber:x:data"));
if (getLabel() != null) {
option.addAttribute("label", getLabel());
}
if (getValue() != null) {
option.addElement("value").addText(getValue());
}
return option;
}
}
}
\ No newline at end of file
...@@ -12,6 +12,10 @@ ...@@ -12,6 +12,10 @@
package org.jivesoftware.openfire.handler; package org.jivesoftware.openfire.handler;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import org.dom4j.DocumentHelper; import org.dom4j.DocumentHelper;
import org.dom4j.Element; import org.dom4j.Element;
import org.dom4j.QName; import org.dom4j.QName;
...@@ -20,10 +24,6 @@ import org.jivesoftware.openfire.PacketException; ...@@ -20,10 +24,6 @@ import org.jivesoftware.openfire.PacketException;
import org.jivesoftware.openfire.XMPPServer; import org.jivesoftware.openfire.XMPPServer;
import org.jivesoftware.openfire.auth.UnauthorizedException; import org.jivesoftware.openfire.auth.UnauthorizedException;
import org.jivesoftware.openfire.disco.ServerFeaturesProvider; import org.jivesoftware.openfire.disco.ServerFeaturesProvider;
import org.jivesoftware.openfire.forms.DataForm;
import org.jivesoftware.openfire.forms.FormField;
import org.jivesoftware.openfire.forms.spi.XDataFormImpl;
import org.jivesoftware.openfire.forms.spi.XFormFieldImpl;
import org.jivesoftware.openfire.group.GroupManager; import org.jivesoftware.openfire.group.GroupManager;
import org.jivesoftware.openfire.roster.RosterManager; import org.jivesoftware.openfire.roster.RosterManager;
import org.jivesoftware.openfire.session.ClientSession; import org.jivesoftware.openfire.session.ClientSession;
...@@ -32,18 +32,17 @@ import org.jivesoftware.openfire.user.User; ...@@ -32,18 +32,17 @@ import org.jivesoftware.openfire.user.User;
import org.jivesoftware.openfire.user.UserAlreadyExistsException; import org.jivesoftware.openfire.user.UserAlreadyExistsException;
import org.jivesoftware.openfire.user.UserManager; import org.jivesoftware.openfire.user.UserManager;
import org.jivesoftware.openfire.user.UserNotFoundException; import org.jivesoftware.openfire.user.UserNotFoundException;
import org.jivesoftware.util.JiveGlobals;
import org.jivesoftware.util.Log;
import org.jivesoftware.stringprep.Stringprep; import org.jivesoftware.stringprep.Stringprep;
import org.jivesoftware.stringprep.StringprepException; import org.jivesoftware.stringprep.StringprepException;
import org.jivesoftware.util.JiveGlobals;
import org.jivesoftware.util.Log;
import org.xmpp.forms.DataForm;
import org.xmpp.forms.FormField;
import org.xmpp.packet.IQ; import org.xmpp.packet.IQ;
import org.xmpp.packet.JID; import org.xmpp.packet.JID;
import org.xmpp.packet.PacketError; import org.xmpp.packet.PacketError;
import org.xmpp.packet.StreamError; import org.xmpp.packet.StreamError;
import java.util.ArrayList;
import java.util.Iterator;
/** /**
* Implements the TYPE_IQ jabber:iq:register protocol (plain only). Clients * Implements the TYPE_IQ jabber:iq:register protocol (plain only). Clients
* use this protocol to register a user account with the server. * use this protocol to register a user account with the server.
...@@ -105,45 +104,45 @@ public class IQRegisterHandler extends IQHandler implements ServerFeaturesProvid ...@@ -105,45 +104,45 @@ public class IQRegisterHandler extends IQHandler implements ServerFeaturesProvid
// Create the registration form to include in the probeResult. The form will include // Create the registration form to include in the probeResult. The form will include
// the basic information plus name and visibility of name and email. // the basic information plus name and visibility of name and email.
// TODO Future versions could allow plugin modules to add new fields to the form // TODO Future versions could allow plugin modules to add new fields to the form
XDataFormImpl registrationForm = new XDataFormImpl(DataForm.TYPE_FORM); final DataForm registrationForm = new DataForm(DataForm.Type.form);
registrationForm.setTitle("XMPP Client Registration"); registrationForm.setTitle("XMPP Client Registration");
registrationForm.addInstruction("Please provide the following information"); registrationForm.addInstruction("Please provide the following information");
XFormFieldImpl field = new XFormFieldImpl("FORM_TYPE"); final FormField fieldForm = registrationForm.addField();
field.setType(FormField.TYPE_HIDDEN); fieldForm.setVariable("FORM_TYPE");
field.addValue("jabber:iq:register"); fieldForm.setType(FormField.Type.hidden);
registrationForm.addField(field); fieldForm.addValue("jabber:iq:register");
field = new XFormFieldImpl("username"); final FormField fieldUser = registrationForm.addField();
field.setType(FormField.TYPE_TEXT_SINGLE); fieldUser.setVariable("username");
field.setLabel("Username"); fieldUser.setType(FormField.Type.text_single);
field.setRequired(true); fieldUser.setLabel("Username");
registrationForm.addField(field); fieldUser.setRequired(true);
field = new XFormFieldImpl("name"); final FormField fieldName = registrationForm.addField();
field.setType(FormField.TYPE_TEXT_SINGLE); fieldName.setVariable("name");
field.setLabel("Full name"); fieldName.setType(FormField.Type.text_single);
fieldName.setLabel("Full name");
if (UserManager.getUserProvider().isNameRequired()) { if (UserManager.getUserProvider().isNameRequired()) {
field.setRequired(true); fieldName.setRequired(true);
} }
registrationForm.addField(field);
field = new XFormFieldImpl("email"); final FormField fieldMail = registrationForm.addField();
field.setType(FormField.TYPE_TEXT_SINGLE); fieldMail.setVariable("email");
field.setLabel("Email"); fieldMail.setType(FormField.Type.text_single);
fieldMail.setLabel("Email");
if (UserManager.getUserProvider().isEmailRequired()) { if (UserManager.getUserProvider().isEmailRequired()) {
field.setRequired(true); fieldMail.setRequired(true);
} }
registrationForm.addField(field);
field = new XFormFieldImpl("password"); final FormField fieldPwd = registrationForm.addField();
field.setType(FormField.TYPE_TEXT_PRIVATE); fieldPwd.setVariable("password");
field.setLabel("Password"); fieldPwd.setType(FormField.Type.text_private);
field.setRequired(true); fieldPwd.setLabel("Password");
registrationForm.addField(field); fieldPwd.setRequired(true);
// Add the registration form to the probe result. // Add the registration form to the probe result.
probeResult.add(registrationForm.asXMLElement()); probeResult.add(registrationForm.getElement());
} }
// See if in-band registration should be enabled (default is true). // See if in-band registration should be enabled (default is true).
registrationEnabled = JiveGlobals.getBooleanProperty("register.inband", true); registrationEnabled = JiveGlobals.getBooleanProperty("register.inband", true);
...@@ -263,35 +262,34 @@ public class IQRegisterHandler extends IQHandler implements ServerFeaturesProvid ...@@ -263,35 +262,34 @@ public class IQRegisterHandler extends IQHandler implements ServerFeaturesProvid
String email = null; String email = null;
String name = null; String name = null;
User newUser; User newUser;
XDataFormImpl registrationForm; DataForm registrationForm;
FormField field; FormField field;
Element formElement = iqElement.element("x"); Element formElement = iqElement.element("x");
// Check if a form was used to provide the registration info // Check if a form was used to provide the registration info
if (formElement != null) { if (formElement != null) {
// Get the sent form // Get the sent form
registrationForm = new XDataFormImpl(); registrationForm = new DataForm(formElement);
registrationForm.parse(formElement);
// Get the username sent in the form // Get the username sent in the form
Iterator<String> values = registrationForm.getField("username").getValues(); List<String> values = registrationForm.getField("username").getValues();
username = (values.hasNext() ? values.next() : " "); username = (!values.isEmpty() ? values.get(0) : " ");
// Get the password sent in the form // Get the password sent in the form
field = registrationForm.getField("password"); field = registrationForm.getField("password");
if (field != null) { if (field != null) {
values = field.getValues(); values = field.getValues();
password = (values.hasNext() ? values.next() : " "); password = (!values.isEmpty() ? values.get(0) : " ");
} }
// Get the email sent in the form // Get the email sent in the form
field = registrationForm.getField("email"); field = registrationForm.getField("email");
if (field != null) { if (field != null) {
values = field.getValues(); values = field.getValues();
email = (values.hasNext() ? values.next() : " "); email = (!values.isEmpty() ? values.get(0) : " ");
} }
// Get the name sent in the form // Get the name sent in the form
field = registrationForm.getField("name"); field = registrationForm.getField("name");
if (field != null) { if (field != null) {
values = field.getValues(); values = field.getValues();
name = (values.hasNext() ? values.next() : " "); name = (!values.isEmpty() ? values.get(0) : " ");
} }
} }
else { else {
......
...@@ -15,10 +15,6 @@ package org.jivesoftware.openfire.muc.spi; ...@@ -15,10 +15,6 @@ package org.jivesoftware.openfire.muc.spi;
import org.dom4j.DocumentHelper; import org.dom4j.DocumentHelper;
import org.dom4j.Element; import org.dom4j.Element;
import org.dom4j.QName; import org.dom4j.QName;
import org.jivesoftware.openfire.forms.DataForm;
import org.jivesoftware.openfire.forms.FormField;
import org.jivesoftware.openfire.forms.spi.XDataFormImpl;
import org.jivesoftware.openfire.forms.spi.XFormFieldImpl;
import org.jivesoftware.openfire.muc.ConflictException; import org.jivesoftware.openfire.muc.ConflictException;
import org.jivesoftware.openfire.muc.ForbiddenException; import org.jivesoftware.openfire.muc.ForbiddenException;
import org.jivesoftware.openfire.muc.MUCRoom; import org.jivesoftware.openfire.muc.MUCRoom;
...@@ -26,6 +22,8 @@ import org.jivesoftware.openfire.muc.MultiUserChatService; ...@@ -26,6 +22,8 @@ import org.jivesoftware.openfire.muc.MultiUserChatService;
import org.jivesoftware.util.ElementUtil; import org.jivesoftware.util.ElementUtil;
import org.jivesoftware.util.LocaleUtils; import org.jivesoftware.util.LocaleUtils;
import org.jivesoftware.util.Log; import org.jivesoftware.util.Log;
import org.xmpp.forms.DataForm;
import org.xmpp.forms.FormField;
import org.xmpp.packet.IQ; import org.xmpp.packet.IQ;
import org.xmpp.packet.PacketError; import org.xmpp.packet.PacketError;
import org.xmpp.packet.Presence; import org.xmpp.packet.Presence;
...@@ -55,52 +53,52 @@ class IQMUCRegisterHandler { ...@@ -55,52 +53,52 @@ class IQMUCRegisterHandler {
if (probeResult == null) { if (probeResult == null) {
// Create the registration form of the room which contains information // Create the registration form of the room which contains information
// such as: first name, last name and nickname. // such as: first name, last name and nickname.
XDataFormImpl registrationForm = new XDataFormImpl(DataForm.TYPE_FORM); final DataForm registrationForm = new DataForm(DataForm.Type.form);
registrationForm.setTitle(LocaleUtils.getLocalizedString("muc.form.reg.title")); registrationForm.setTitle(LocaleUtils.getLocalizedString("muc.form.reg.title"));
registrationForm.addInstruction(LocaleUtils registrationForm.addInstruction(LocaleUtils
.getLocalizedString("muc.form.reg.instruction")); .getLocalizedString("muc.form.reg.instruction"));
XFormFieldImpl field = new XFormFieldImpl("FORM_TYPE"); final FormField fieldForm = registrationForm.addField();
field.setType(FormField.TYPE_HIDDEN); fieldForm.setVariable("FORM_TYPE");
field.addValue("http://jabber.org/protocol/muc#register"); fieldForm.setType(FormField.Type.hidden);
registrationForm.addField(field); fieldForm.addValue("http://jabber.org/protocol/muc#register");
field = new XFormFieldImpl("muc#register_first"); final FormField fieldReg = registrationForm.addField();
field.setType(FormField.TYPE_TEXT_SINGLE); fieldReg.setVariable("muc#register_first");
field.setLabel(LocaleUtils.getLocalizedString("muc.form.reg.first-name")); fieldReg.setType(FormField.Type.text_single);
field.setRequired(true); fieldReg.setLabel(LocaleUtils.getLocalizedString("muc.form.reg.first-name"));
registrationForm.addField(field); fieldReg.setRequired(true);
field = new XFormFieldImpl("muc#register_last"); final FormField fieldLast = registrationForm.addField();
field.setType(FormField.TYPE_TEXT_SINGLE); fieldLast.setVariable("muc#register_last");
field.setLabel(LocaleUtils.getLocalizedString("muc.form.reg.last-name")); fieldLast.setType(FormField.Type.text_single);
field.setRequired(true); fieldLast.setLabel(LocaleUtils.getLocalizedString("muc.form.reg.last-name"));
registrationForm.addField(field); fieldLast.setRequired(true);
field = new XFormFieldImpl("muc#register_roomnick"); final FormField fieldNick = registrationForm.addField();
field.setType(FormField.TYPE_TEXT_SINGLE); fieldNick.setVariable("muc#register_roomnick");
field.setLabel(LocaleUtils.getLocalizedString("muc.form.reg.nickname")); fieldNick.setType(FormField.Type.text_single);
field.setRequired(true); fieldNick.setLabel(LocaleUtils.getLocalizedString("muc.form.reg.nickname"));
registrationForm.addField(field); fieldNick.setRequired(true);
field = new XFormFieldImpl("muc#register_url"); final FormField fieldUrl = registrationForm.addField();
field.setType(FormField.TYPE_TEXT_SINGLE); fieldUrl.setVariable("muc#register_url");
field.setLabel(LocaleUtils.getLocalizedString("muc.form.reg.url")); fieldUrl.setType(FormField.Type.text_single);
registrationForm.addField(field); fieldUrl.setLabel(LocaleUtils.getLocalizedString("muc.form.reg.url"));
field = new XFormFieldImpl("muc#register_email"); final FormField fieldMail = registrationForm.addField();
field.setType(FormField.TYPE_TEXT_SINGLE); fieldMail.setVariable("muc#register_email");
field.setLabel(LocaleUtils.getLocalizedString("muc.form.reg.email")); fieldMail.setType(FormField.Type.text_single);
registrationForm.addField(field); fieldMail.setLabel(LocaleUtils.getLocalizedString("muc.form.reg.email"));
field = new XFormFieldImpl("muc#register_faqentry"); final FormField fieldFaq = registrationForm.addField();
field.setType(FormField.TYPE_TEXT_MULTI); fieldFaq.setVariable("muc#register_faqentry");
field.setLabel(LocaleUtils.getLocalizedString("muc.form.reg.faqentry")); fieldFaq.setType(FormField.Type.text_single);
registrationForm.addField(field); fieldFaq.setLabel(LocaleUtils.getLocalizedString("muc.form.reg.faqentry"));
// Create the probeResult and add the registration form // Create the probeResult and add the registration form
probeResult = DocumentHelper.createElement(QName.get("query", "jabber:iq:register")); probeResult = DocumentHelper.createElement(QName.get("query", "jabber:iq:register"));
probeResult.add(registrationForm.asXMLElement()); probeResult.add(registrationForm.getElement());
} }
} }
...@@ -168,12 +166,11 @@ class IQMUCRegisterHandler { ...@@ -168,12 +166,11 @@ class IQMUCRegisterHandler {
// Check if a form was used to provide the registration info // Check if a form was used to provide the registration info
if (formElement != null) { if (formElement != null) {
// Get the sent form // Get the sent form
XDataFormImpl registrationForm = new XDataFormImpl(); final DataForm registrationForm = new DataForm(formElement);
registrationForm.parse(formElement);
// Get the desired nickname sent in the form // Get the desired nickname sent in the form
Iterator<String> values = registrationForm.getField("muc#register_roomnick") List<String> values = registrationForm.getField("muc#register_roomnick")
.getValues(); .getValues();
String nickname = (values.hasNext() ? values.next() : null); String nickname = (!values.isEmpty() ? values.get(0) : null);
// TODO The rest of the fields of the form are ignored. If we have a // TODO The rest of the fields of the form are ignored. If we have a
// requirement in the future where we need those fields we'll have to change // requirement in the future where we need those fields we'll have to change
......
...@@ -8,6 +8,21 @@ ...@@ -8,6 +8,21 @@
package org.jivesoftware.openfire.plugin; package org.jivesoftware.openfire.plugin;
import java.io.File;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import java.util.Comparator;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Hashtable;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.TreeMap;
import java.util.Map.Entry;
import org.dom4j.DocumentHelper; import org.dom4j.DocumentHelper;
import org.dom4j.Element; import org.dom4j.Element;
import org.dom4j.QName; import org.dom4j.QName;
...@@ -16,31 +31,29 @@ import org.jivesoftware.openfire.container.Plugin; ...@@ -16,31 +31,29 @@ import org.jivesoftware.openfire.container.Plugin;
import org.jivesoftware.openfire.container.PluginManager; import org.jivesoftware.openfire.container.PluginManager;
import org.jivesoftware.openfire.disco.IQDiscoInfoHandler; import org.jivesoftware.openfire.disco.IQDiscoInfoHandler;
import org.jivesoftware.openfire.disco.IQDiscoItemsHandler; import org.jivesoftware.openfire.disco.IQDiscoItemsHandler;
import org.jivesoftware.openfire.forms.DataForm;
import org.jivesoftware.openfire.forms.FormField;
import org.jivesoftware.openfire.forms.spi.XDataFormImpl;
import org.jivesoftware.openfire.forms.spi.XFormFieldImpl;
import org.jivesoftware.openfire.user.User; import org.jivesoftware.openfire.user.User;
import org.jivesoftware.openfire.user.UserManager; import org.jivesoftware.openfire.user.UserManager;
import org.jivesoftware.openfire.user.UserNotFoundException; import org.jivesoftware.util.JiveGlobals;
import org.jivesoftware.util.*; import org.jivesoftware.util.LocaleUtils;
import org.jivesoftware.util.Log;
import org.jivesoftware.util.PropertyEventDispatcher;
import org.jivesoftware.util.PropertyEventListener;
import org.jivesoftware.util.StringUtils;
import org.xmpp.component.Component; import org.xmpp.component.Component;
import org.xmpp.component.ComponentException; import org.xmpp.component.ComponentException;
import org.xmpp.component.ComponentManager; import org.xmpp.component.ComponentManager;
import org.xmpp.component.ComponentManagerFactory; import org.xmpp.component.ComponentManagerFactory;
import org.xmpp.forms.DataForm;
import org.xmpp.forms.FormField;
import org.xmpp.packet.IQ; import org.xmpp.packet.IQ;
import org.xmpp.packet.IQ.Type;
import org.xmpp.packet.JID; import org.xmpp.packet.JID;
import org.xmpp.packet.Packet; import org.xmpp.packet.Packet;
import org.xmpp.packet.PacketError; import org.xmpp.packet.PacketError;
import org.xmpp.packet.IQ.Type;
import org.xmpp.packet.PacketError.Condition; import org.xmpp.packet.PacketError.Condition;
import org.xmpp.resultsetmanagement.ResultSet; import org.xmpp.resultsetmanagement.ResultSet;
import org.xmpp.resultsetmanagement.ResultSetImpl; import org.xmpp.resultsetmanagement.ResultSetImpl;
import java.io.File;
import java.util.*;
import java.util.Map.Entry;
/** /**
* Provides support for Jabber Search * Provides support for Jabber Search
* (<a href="http://www.xmpp.org/extensions/xep-0055.html">XEP-0055</a>).<p> * (<a href="http://www.xmpp.org/extensions/xep-0055.html">XEP-0055</a>).<p>
...@@ -350,12 +363,12 @@ public class SearchPlugin implements Component, Plugin, PropertyEventListener { ...@@ -350,12 +363,12 @@ public class SearchPlugin implements Component, Plugin, PropertyEventListener {
IQ replyPacket = IQ.createResultIQ(packet); IQ replyPacket = IQ.createResultIQ(packet);
Element reply = replyPacket.setChildElement("query", Element reply = replyPacket.setChildElement("query",
NAMESPACE_JABBER_IQ_SEARCH); NAMESPACE_JABBER_IQ_SEARCH);
XDataFormImpl unavailableForm = new XDataFormImpl(DataForm.TYPE_CANCEL); final DataForm unavailableForm = new DataForm(DataForm.Type.cancel);
unavailableForm.setTitle(LocaleUtils.getLocalizedString( unavailableForm.setTitle(LocaleUtils.getLocalizedString(
"advance.user.search.title", "search")); "advance.user.search.title", "search"));
unavailableForm.addInstruction(LocaleUtils.getLocalizedString( unavailableForm.addInstruction(LocaleUtils.getLocalizedString(
"search.service_unavailable", "search")); "search.service_unavailable", "search"));
reply.add(unavailableForm.asXMLElement()); reply.add(unavailableForm.getElement());
return replyPacket; return replyPacket;
} }
...@@ -388,34 +401,31 @@ public class SearchPlugin implements Component, Plugin, PropertyEventListener { ...@@ -388,34 +401,31 @@ public class SearchPlugin implements Component, Plugin, PropertyEventListener {
queryResult.addElement("nick"); queryResult.addElement("nick");
queryResult.addElement("email"); queryResult.addElement("email");
XDataFormImpl searchForm = new XDataFormImpl(DataForm.TYPE_FORM); DataForm searchForm = new DataForm(DataForm.Type.form);
searchForm.setTitle(LocaleUtils.getLocalizedString( searchForm.setTitle(LocaleUtils.getLocalizedString(
"advance.user.search.title", "search")); "advance.user.search.title", "search"));
searchForm.addInstruction(instructions); searchForm.addInstruction(instructions);
XFormFieldImpl field = new XFormFieldImpl("FORM_TYPE"); searchForm.addField("FORM_TYPE", null, FormField.Type.hidden)
field.setType(FormField.TYPE_HIDDEN); .addValue(NAMESPACE_JABBER_IQ_SEARCH);
field.addValue(NAMESPACE_JABBER_IQ_SEARCH);
searchForm.addField(field); searchForm.addField("search",
LocaleUtils.getLocalizedString("advance.user.search.search", "search"),
FormField.Type.text_single)
.setRequired(true);
field = new XFormFieldImpl("search");
field.setType(FormField.TYPE_TEXT_SINGLE);
field.setLabel(LocaleUtils.getLocalizedString(
"advance.user.search.search", "search"));
field.setRequired(true);
searchForm.addField(field);
for (String searchField : getFilteredSearchFields()) { for (String searchField : getFilteredSearchFields()) {
field = new XFormFieldImpl(searchField); final FormField field = searchForm.addField();
field.setType(FormField.TYPE_BOOLEAN); field.setVariable(searchField);
field.setType(FormField.Type.boolean_type);
field.addValue("1"); field.addValue("1");
field.setLabel(LocaleUtils.getLocalizedString( field.setLabel(LocaleUtils.getLocalizedString(
"advance.user.search." + searchField.toLowerCase(), "search")); "advance.user.search." + searchField.toLowerCase(), "search"));
field.setRequired(false); field.setRequired(false);
searchForm.addField(field);
} }
queryResult.add(searchForm.asXMLElement()); queryResult.add(searchForm.getElement());
replyPacket.setChildElement(queryResult); replyPacket.setChildElement(queryResult);
return replyPacket; return replyPacket;
...@@ -515,6 +525,7 @@ public class SearchPlugin implements Component, Plugin, PropertyEventListener { ...@@ -515,6 +525,7 @@ public class SearchPlugin implements Component, Plugin, PropertyEventListener {
* @return ''true'' if the supplied IQ stanza is a spec compliant search * @return ''true'' if the supplied IQ stanza is a spec compliant search
* request, ''false'' otherwise. * request, ''false'' otherwise.
*/ */
@SuppressWarnings("unchecked")
public static boolean isValidSearchRequest(IQ iq) { public static boolean isValidSearchRequest(IQ iq) {
if (iq == null) { if (iq == null) {
...@@ -620,6 +631,7 @@ public class SearchPlugin implements Component, Plugin, PropertyEventListener { ...@@ -620,6 +631,7 @@ public class SearchPlugin implements Component, Plugin, PropertyEventListener {
* The form from which to extract the query * The form from which to extract the query
* @return The search query for a particular user search request. * @return The search query for a particular user search request.
*/ */
@SuppressWarnings("unchecked")
private Hashtable<String, String> extractSearchQuery(Element incomingForm) { private Hashtable<String, String> extractSearchQuery(Element incomingForm) {
if (incomingForm.element(QName.get("x", "jabber:x:data")) != null) { if (incomingForm.element(QName.get("x", "jabber:x:data")) != null) {
// forward the request. // forward the request.
...@@ -657,6 +669,7 @@ public class SearchPlugin implements Component, Plugin, PropertyEventListener { ...@@ -657,6 +669,7 @@ public class SearchPlugin implements Component, Plugin, PropertyEventListener {
* @return The search query for a particular user search request. * @return The search query for a particular user search request.
* @see #extractSearchQuery(Element) * @see #extractSearchQuery(Element)
*/ */
@SuppressWarnings("unchecked")
private Hashtable<String, String> extractExtendedSearchQuery( private Hashtable<String, String> extractExtendedSearchQuery(
Element incomingForm) { Element incomingForm) {
final Element dataform = incomingForm.element(QName.get("x", final Element dataform = incomingForm.element(QName.get("x",
...@@ -697,51 +710,41 @@ public class SearchPlugin implements Component, Plugin, PropertyEventListener { ...@@ -697,51 +710,41 @@ public class SearchPlugin implements Component, Plugin, PropertyEventListener {
* @return the iq packet that contains the search results * @return the iq packet that contains the search results
*/ */
private IQ replyDataFormResult(Collection<User> users, IQ packet) { private IQ replyDataFormResult(Collection<User> users, IQ packet) {
XDataFormImpl searchResults = new XDataFormImpl(DataForm.TYPE_RESULT); final DataForm searchResults = new DataForm(DataForm.Type.result);
XFormFieldImpl field = new XFormFieldImpl("FORM_TYPE"); searchResults.addField("FORM_TYPE", null, FormField.Type.hidden);
field.setType(FormField.TYPE_HIDDEN);
searchResults.addField(field);
field = new XFormFieldImpl("jid"); searchResults.addReportedField("jid", "JID", null);
field.setLabel("JID");
searchResults.addReportedField(field);
for (String fieldName : getFilteredSearchFields()) { for (final String fieldName : getFilteredSearchFields()) {
field = new XFormFieldImpl(fieldName); searchResults.addReportedField(fieldName,
field.setLabel(LocaleUtils.getLocalizedString( LocaleUtils.getLocalizedString("advance.user.search." + fieldName.toLowerCase(), "search"),
"advance.user.search." + fieldName.toLowerCase(), "search")); null);
searchResults.addReportedField(field);
} }
for (User user : users) { for (final User user : users) {
String username = JID.unescapeNode(user.getUsername()); final String username = JID.unescapeNode(user.getUsername());
ArrayList<XFormFieldImpl> items = new ArrayList<XFormFieldImpl>();
XFormFieldImpl fieldJID = new XFormFieldImpl("jid"); final Map<String, Object> item = new HashMap<String, Object>();
fieldJID.addValue(username + "@" + serverName); item.put("jid",
items.add(fieldJID); username + "@" + serverName);
XFormFieldImpl fieldUsername = new XFormFieldImpl(LocaleUtils.getLocalizedString("advance.user.search.username", "search")); item.put(LocaleUtils.getLocalizedString("advance.user.search.username", "search"),
fieldUsername.addValue(username); username);
items.add(fieldUsername);
XFormFieldImpl fieldName = new XFormFieldImpl(LocaleUtils.getLocalizedString("advance.user.search.name", "search")); item.put(LocaleUtils.getLocalizedString("advance.user.search.name", "search"),
fieldName.addValue((user.isNameVisible() ? removeNull(user.getName()) : "")); (user.isNameVisible() ? removeNull(user.getName()) : ""));
items.add(fieldName);
XFormFieldImpl fieldEmail = new XFormFieldImpl(LocaleUtils.getLocalizedString("advance.user.search.email", "search")); item.put(LocaleUtils.getLocalizedString("advance.user.search.email", "search"),
fieldEmail.addValue((user.isEmailVisible() ? removeNull(user.getEmail()) : "")); (user.isEmailVisible() ? removeNull(user.getEmail()) : ""));
items.add(fieldEmail);
searchResults.addItemFields(items); searchResults.addItemFields(item);
} }
IQ replyPacket = IQ.createResultIQ(packet); IQ replyPacket = IQ.createResultIQ(packet);
Element reply = replyPacket.setChildElement("query", Element reply = replyPacket.setChildElement("query",
NAMESPACE_JABBER_IQ_SEARCH); NAMESPACE_JABBER_IQ_SEARCH);
reply.add(searchResults.asXMLElement()); reply.add(searchResults.getElement());
return replyPacket; return replyPacket;
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment