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;
import org.jivesoftware.openfire.commands.clearspace.SystemAdminRemoved;
import org.jivesoftware.openfire.commands.event.*;
import org.jivesoftware.openfire.disco.*;
import org.jivesoftware.openfire.forms.spi.XDataFormImpl;
import org.jivesoftware.openfire.handler.IQHandler;
import org.xmpp.forms.DataForm;
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 @@
package org.jivesoftware.openfire.handler;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import org.dom4j.DocumentHelper;
import org.dom4j.Element;
import org.dom4j.QName;
......@@ -20,10 +24,6 @@ import org.jivesoftware.openfire.PacketException;
import org.jivesoftware.openfire.XMPPServer;
import org.jivesoftware.openfire.auth.UnauthorizedException;
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.roster.RosterManager;
import org.jivesoftware.openfire.session.ClientSession;
......@@ -32,18 +32,17 @@ import org.jivesoftware.openfire.user.User;
import org.jivesoftware.openfire.user.UserAlreadyExistsException;
import org.jivesoftware.openfire.user.UserManager;
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.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.JID;
import org.xmpp.packet.PacketError;
import org.xmpp.packet.StreamError;
import java.util.ArrayList;
import java.util.Iterator;
/**
* Implements the TYPE_IQ jabber:iq:register protocol (plain only). Clients
* use this protocol to register a user account with the server.
......@@ -105,45 +104,45 @@ public class IQRegisterHandler extends IQHandler implements ServerFeaturesProvid
// Create the registration form to include in the probeResult. The form will include
// 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
XDataFormImpl registrationForm = new XDataFormImpl(DataForm.TYPE_FORM);
final DataForm registrationForm = new DataForm(DataForm.Type.form);
registrationForm.setTitle("XMPP Client Registration");
registrationForm.addInstruction("Please provide the following information");
XFormFieldImpl field = new XFormFieldImpl("FORM_TYPE");
field.setType(FormField.TYPE_HIDDEN);
field.addValue("jabber:iq:register");
registrationForm.addField(field);
final FormField fieldForm = registrationForm.addField();
fieldForm.setVariable("FORM_TYPE");
fieldForm.setType(FormField.Type.hidden);
fieldForm.addValue("jabber:iq:register");
field = new XFormFieldImpl("username");
field.setType(FormField.TYPE_TEXT_SINGLE);
field.setLabel("Username");
field.setRequired(true);
registrationForm.addField(field);
final FormField fieldUser = registrationForm.addField();
fieldUser.setVariable("username");
fieldUser.setType(FormField.Type.text_single);
fieldUser.setLabel("Username");
fieldUser.setRequired(true);
field = new XFormFieldImpl("name");
field.setType(FormField.TYPE_TEXT_SINGLE);
field.setLabel("Full name");
final FormField fieldName = registrationForm.addField();
fieldName.setVariable("name");
fieldName.setType(FormField.Type.text_single);
fieldName.setLabel("Full name");
if (UserManager.getUserProvider().isNameRequired()) {
field.setRequired(true);
fieldName.setRequired(true);
}
registrationForm.addField(field);
field = new XFormFieldImpl("email");
field.setType(FormField.TYPE_TEXT_SINGLE);
field.setLabel("Email");
final FormField fieldMail = registrationForm.addField();
fieldMail.setVariable("email");
fieldMail.setType(FormField.Type.text_single);
fieldMail.setLabel("Email");
if (UserManager.getUserProvider().isEmailRequired()) {
field.setRequired(true);
fieldMail.setRequired(true);
}
registrationForm.addField(field);
field = new XFormFieldImpl("password");
field.setType(FormField.TYPE_TEXT_PRIVATE);
field.setLabel("Password");
field.setRequired(true);
registrationForm.addField(field);
final FormField fieldPwd = registrationForm.addField();
fieldPwd.setVariable("password");
fieldPwd.setType(FormField.Type.text_private);
fieldPwd.setLabel("Password");
fieldPwd.setRequired(true);
// 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).
registrationEnabled = JiveGlobals.getBooleanProperty("register.inband", true);
......@@ -263,35 +262,34 @@ public class IQRegisterHandler extends IQHandler implements ServerFeaturesProvid
String email = null;
String name = null;
User newUser;
XDataFormImpl registrationForm;
DataForm registrationForm;
FormField field;
Element formElement = iqElement.element("x");
// Check if a form was used to provide the registration info
if (formElement != null) {
// Get the sent form
registrationForm = new XDataFormImpl();
registrationForm.parse(formElement);
registrationForm = new DataForm(formElement);
// Get the username sent in the form
Iterator<String> values = registrationForm.getField("username").getValues();
username = (values.hasNext() ? values.next() : " ");
List<String> values = registrationForm.getField("username").getValues();
username = (!values.isEmpty() ? values.get(0) : " ");
// Get the password sent in the form
field = registrationForm.getField("password");
if (field != null) {
values = field.getValues();
password = (values.hasNext() ? values.next() : " ");
password = (!values.isEmpty() ? values.get(0) : " ");
}
// Get the email sent in the form
field = registrationForm.getField("email");
if (field != null) {
values = field.getValues();
email = (values.hasNext() ? values.next() : " ");
email = (!values.isEmpty() ? values.get(0) : " ");
}
// Get the name sent in the form
field = registrationForm.getField("name");
if (field != null) {
values = field.getValues();
name = (values.hasNext() ? values.next() : " ");
name = (!values.isEmpty() ? values.get(0) : " ");
}
}
else {
......
......@@ -15,10 +15,6 @@ package org.jivesoftware.openfire.muc.spi;
import org.dom4j.DocumentHelper;
import org.dom4j.Element;
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.ForbiddenException;
import org.jivesoftware.openfire.muc.MUCRoom;
......@@ -26,6 +22,8 @@ import org.jivesoftware.openfire.muc.MultiUserChatService;
import org.jivesoftware.util.ElementUtil;
import org.jivesoftware.util.LocaleUtils;
import org.jivesoftware.util.Log;
import org.xmpp.forms.DataForm;
import org.xmpp.forms.FormField;
import org.xmpp.packet.IQ;
import org.xmpp.packet.PacketError;
import org.xmpp.packet.Presence;
......@@ -55,52 +53,52 @@ class IQMUCRegisterHandler {
if (probeResult == null) {
// Create the registration form of the room which contains information
// 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.addInstruction(LocaleUtils
.getLocalizedString("muc.form.reg.instruction"));
XFormFieldImpl field = new XFormFieldImpl("FORM_TYPE");
field.setType(FormField.TYPE_HIDDEN);
field.addValue("http://jabber.org/protocol/muc#register");
registrationForm.addField(field);
field = new XFormFieldImpl("muc#register_first");
field.setType(FormField.TYPE_TEXT_SINGLE);
field.setLabel(LocaleUtils.getLocalizedString("muc.form.reg.first-name"));
field.setRequired(true);
registrationForm.addField(field);
field = new XFormFieldImpl("muc#register_last");
field.setType(FormField.TYPE_TEXT_SINGLE);
field.setLabel(LocaleUtils.getLocalizedString("muc.form.reg.last-name"));
field.setRequired(true);
registrationForm.addField(field);
field = new XFormFieldImpl("muc#register_roomnick");
field.setType(FormField.TYPE_TEXT_SINGLE);
field.setLabel(LocaleUtils.getLocalizedString("muc.form.reg.nickname"));
field.setRequired(true);
registrationForm.addField(field);
field = new XFormFieldImpl("muc#register_url");
field.setType(FormField.TYPE_TEXT_SINGLE);
field.setLabel(LocaleUtils.getLocalizedString("muc.form.reg.url"));
registrationForm.addField(field);
field = new XFormFieldImpl("muc#register_email");
field.setType(FormField.TYPE_TEXT_SINGLE);
field.setLabel(LocaleUtils.getLocalizedString("muc.form.reg.email"));
registrationForm.addField(field);
field = new XFormFieldImpl("muc#register_faqentry");
field.setType(FormField.TYPE_TEXT_MULTI);
field.setLabel(LocaleUtils.getLocalizedString("muc.form.reg.faqentry"));
registrationForm.addField(field);
final FormField fieldForm = registrationForm.addField();
fieldForm.setVariable("FORM_TYPE");
fieldForm.setType(FormField.Type.hidden);
fieldForm.addValue("http://jabber.org/protocol/muc#register");
final FormField fieldReg = registrationForm.addField();
fieldReg.setVariable("muc#register_first");
fieldReg.setType(FormField.Type.text_single);
fieldReg.setLabel(LocaleUtils.getLocalizedString("muc.form.reg.first-name"));
fieldReg.setRequired(true);
final FormField fieldLast = registrationForm.addField();
fieldLast.setVariable("muc#register_last");
fieldLast.setType(FormField.Type.text_single);
fieldLast.setLabel(LocaleUtils.getLocalizedString("muc.form.reg.last-name"));
fieldLast.setRequired(true);
final FormField fieldNick = registrationForm.addField();
fieldNick.setVariable("muc#register_roomnick");
fieldNick.setType(FormField.Type.text_single);
fieldNick.setLabel(LocaleUtils.getLocalizedString("muc.form.reg.nickname"));
fieldNick.setRequired(true);
final FormField fieldUrl = registrationForm.addField();
fieldUrl.setVariable("muc#register_url");
fieldUrl.setType(FormField.Type.text_single);
fieldUrl.setLabel(LocaleUtils.getLocalizedString("muc.form.reg.url"));
final FormField fieldMail = registrationForm.addField();
fieldMail.setVariable("muc#register_email");
fieldMail.setType(FormField.Type.text_single);
fieldMail.setLabel(LocaleUtils.getLocalizedString("muc.form.reg.email"));
final FormField fieldFaq = registrationForm.addField();
fieldFaq.setVariable("muc#register_faqentry");
fieldFaq.setType(FormField.Type.text_single);
fieldFaq.setLabel(LocaleUtils.getLocalizedString("muc.form.reg.faqentry"));
// Create the probeResult and add the registration form
probeResult = DocumentHelper.createElement(QName.get("query", "jabber:iq:register"));
probeResult.add(registrationForm.asXMLElement());
probeResult.add(registrationForm.getElement());
}
}
......@@ -168,12 +166,11 @@ class IQMUCRegisterHandler {
// Check if a form was used to provide the registration info
if (formElement != null) {
// Get the sent form
XDataFormImpl registrationForm = new XDataFormImpl();
registrationForm.parse(formElement);
final DataForm registrationForm = new DataForm(formElement);
// 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();
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
// requirement in the future where we need those fields we'll have to change
......
......@@ -13,12 +13,10 @@ package org.jivesoftware.openfire.muc.spi;
import org.dom4j.DocumentHelper;
import org.dom4j.Element;
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.MUCRoom;
import org.jivesoftware.openfire.muc.MultiUserChatService;
import org.xmpp.forms.DataForm;
import org.xmpp.forms.FormField;
import org.xmpp.packet.IQ;
import org.xmpp.packet.PacketError;
import org.xmpp.packet.PacketError.Condition;
......@@ -61,55 +59,54 @@ public class IQMUCSearchHandler
*/
private static Element getDataElement()
{
final XDataFormImpl searchForm = new XDataFormImpl(DataForm.TYPE_FORM);
final DataForm searchForm = new DataForm(DataForm.Type.form);
searchForm.setTitle("Chat Rooms Search");
searchForm.addInstruction("Instructions");
final FormField typeFF = new XFormFieldImpl("FORM_TYPE");
typeFF.setType(FormField.TYPE_HIDDEN);
final FormField typeFF = searchForm.addField();
typeFF.setVariable("FORM_TYPE");
typeFF.setType(FormField.Type.hidden);
typeFF.addValue("jabber:iq:search");
searchForm.addField(typeFF);
final FormField nameFF = new XFormFieldImpl("name");
nameFF.setType(FormField.TYPE_TEXT_SINGLE);
final FormField nameFF = searchForm.addField();
nameFF.setVariable("name");
nameFF.setType(FormField.Type.text_single);
nameFF.setLabel("Name");
nameFF.setRequired(false);
searchForm.addField(nameFF);
final FormField matchFF = new XFormFieldImpl("name_is_exact_match");
matchFF.setType(FormField.TYPE_BOOLEAN);
final FormField matchFF = searchForm.addField();
matchFF.setVariable("name_is_exact_match");
matchFF.setType(FormField.Type.boolean_type);
matchFF.setLabel("Name must match exactly");
matchFF.setRequired(false);
searchForm.addField(matchFF);
final FormField subjectFF = new XFormFieldImpl("subject");
subjectFF.setType(FormField.TYPE_TEXT_SINGLE);
final FormField subjectFF = searchForm.addField();
subjectFF.setVariable("subject");
subjectFF.setType(FormField.Type.text_single);
subjectFF.setLabel("Subject");
subjectFF.setRequired(false);
searchForm.addField(subjectFF);
final FormField userAmountFF = new XFormFieldImpl("num_users");
userAmountFF.setType(FormField.TYPE_TEXT_SINGLE);
final FormField userAmountFF = searchForm.addField();
userAmountFF.setVariable("num_users");
userAmountFF.setType(FormField.Type.text_single);
userAmountFF.setLabel("Number of users");
userAmountFF.setRequired(false);
searchForm.addField(userAmountFF);
final FormField maxUsersFF = new XFormFieldImpl("num_max_users");
maxUsersFF.setType(FormField.TYPE_TEXT_SINGLE);
final FormField maxUsersFF = searchForm.addField();
maxUsersFF.setVariable("num_max_users");
maxUsersFF.setType(FormField.Type.text_single);
maxUsersFF.setLabel("Max number allowed of users");
maxUsersFF.setRequired(false);
searchForm.addField(maxUsersFF);
final FormField includePasswordProtectedFF = new XFormFieldImpl(
"include_password_protected");
includePasswordProtectedFF.setType(FormField.TYPE_BOOLEAN);
final FormField includePasswordProtectedFF = searchForm.addField();
includePasswordProtectedFF.setVariable("include_password_protected");
includePasswordProtectedFF.setType(FormField.Type.boolean_type);
includePasswordProtectedFF.setLabel("Include password protected rooms");
includePasswordProtectedFF.setRequired(false);
searchForm.addField(includePasswordProtectedFF);
final Element probeResult = DocumentHelper.createElement(QName.get(
"query", "jabber:iq:search"));
probeResult.add(searchForm.asXMLElement());
probeResult.add(searchForm.getElement());
return probeResult;
}
......@@ -133,8 +130,7 @@ public class IQMUCSearchHandler
}
// parse params from request.
final XDataFormImpl df = new XDataFormImpl();
df.parse(formElement);
final DataForm df = new DataForm(formElement);
boolean name_is_exact_match = false;
String subject = null;
int numusers = -1;
......@@ -142,22 +138,18 @@ public class IQMUCSearchHandler
boolean includePasswordProtectedRooms = true;
final Set<String> names = new HashSet<String>();
@SuppressWarnings("unchecked")
final Iterator<FormField> formFields = df.getFields();
while (formFields.hasNext())
for (final FormField field : df.getFields())
{
final FormField field = formFields.next();
if (field.getVariable().equals("name"))
{
names.add(getFirstValue(field));
names.add(field.getFirstValue());
}
}
final FormField matchFF = df.getField("name_is_exact_match");
if (matchFF != null)
{
final String b = getFirstValue(matchFF);
final String b = matchFF.getFirstValue();
if (b != null)
{
name_is_exact_match = b.equals("1")
......@@ -169,7 +161,7 @@ public class IQMUCSearchHandler
final FormField subjectFF = df.getField("subject");
if (subjectFF != null)
{
subject = getFirstValue(subjectFF);
subject = subjectFF.getFirstValue();
}
try
......@@ -177,7 +169,7 @@ public class IQMUCSearchHandler
final FormField userAmountFF = df.getField("num_users");
if (userAmountFF != null)
{
String value = getFirstValue(userAmountFF);
String value = userAmountFF.getFirstValue();
if (value != null && !"".equals(value)) {
numusers = Integer.parseInt(value);
}
......@@ -186,7 +178,7 @@ public class IQMUCSearchHandler
final FormField maxUsersFF = df.getField("num_max_users");
if (maxUsersFF != null)
{
String value = getFirstValue(maxUsersFF);
String value = maxUsersFF.getFirstValue();
if (value != null && !"".equals(value)) {
numaxusers = Integer.parseInt(value);
}
......@@ -201,7 +193,7 @@ public class IQMUCSearchHandler
final FormField includePasswordProtectedRoomsFF = df.getField("include_password_protected");
if (includePasswordProtectedRoomsFF != null)
{
final String b = getFirstValue(includePasswordProtectedRoomsFF);
final String b = includePasswordProtectedRoomsFF.getFirstValue();
if (b != null)
{
if (b.equals("0") || b.equalsIgnoreCase("false")
......@@ -311,74 +303,30 @@ public class IQMUCSearchHandler
final Element res = DocumentHelper.createElement(QName.get("query",
"jabber:iq:search"));
final XDataFormImpl resultform = new XDataFormImpl(DataForm.TYPE_RESULT);
final DataForm resultform = new DataForm(DataForm.Type.result);
boolean atLeastoneResult = false;
for (MUCRoom room : mucrsm)
{
ArrayList<XFormFieldImpl> fields = new ArrayList<XFormFieldImpl>();
XFormFieldImpl innerfield = new XFormFieldImpl("name");
innerfield.setType(FormField.TYPE_TEXT_SINGLE);
innerfield.addValue(room.getNaturalLanguageName());
fields.add(innerfield);
innerfield = new XFormFieldImpl("subject");
innerfield.setType(FormField.TYPE_TEXT_SINGLE);
innerfield.addValue(room.getSubject());
fields.add(innerfield);
innerfield = new XFormFieldImpl("num_users");
innerfield.setType(FormField.TYPE_TEXT_SINGLE);
innerfield.addValue(String.valueOf(room.getOccupantsCount()));
fields.add(innerfield);
innerfield = new XFormFieldImpl("num_max_users");
innerfield.setType(FormField.TYPE_TEXT_SINGLE);
innerfield.addValue(String.valueOf(room.getMaxUsers()));
fields.add(innerfield);
innerfield = new XFormFieldImpl("is_password_protected");
innerfield.setType(FormField.TYPE_BOOLEAN);
innerfield.addValue(Boolean.toString(room.isPasswordProtected()));
fields.add(innerfield);
innerfield = new XFormFieldImpl("is_member_only");
innerfield.setType(FormField.TYPE_BOOLEAN);
innerfield.addValue(Boolean.toString(room.isMembersOnly()));
fields.add(innerfield);
innerfield = new XFormFieldImpl("jid");
innerfield.setType(FormField.TYPE_TEXT_SINGLE);
innerfield.addValue(room.getRole().getRoleAddress().toString());
fields.add(innerfield);
final Map<String, Object> fields = new HashMap<String, Object>();
fields.put("name", room.getNaturalLanguageName());
fields.put("subject", room.getSubject());
fields.put("num_users", room.getOccupantsCount());
fields.put("num_max_users", room.getMaxUsers());
fields.put("is_password_protected", room.isPasswordProtected());
fields.put("is_member_only", room.isMembersOnly());
fields.put("jid", room.getRole().getRoleAddress().toString());
resultform.addItemFields(fields);
atLeastoneResult = true;
}
if (atLeastoneResult)
{
final FormField rffName = new XFormFieldImpl("name");
rffName.setLabel("Name");
resultform.addReportedField(rffName);
final FormField rffSubject = new XFormFieldImpl("subject");
rffSubject.setLabel("Subject");
resultform.addReportedField(rffSubject);
final FormField rffNumUsers = new XFormFieldImpl("num_users");
rffNumUsers.setLabel("Number of users");
resultform.addReportedField(rffNumUsers);
final FormField rffNumMaxUsers = new XFormFieldImpl("num_max_users");
rffNumMaxUsers.setLabel("Max number allowed of users");
resultform.addReportedField(rffNumMaxUsers);
final FormField rffPasswordProtected = new XFormFieldImpl(
"is_password_protected");
rffPasswordProtected.setLabel("Is a password protected room.");
resultform.addReportedField(rffPasswordProtected);
final FormField rffJID = new XFormFieldImpl("jid");
rffJID.setLabel("JID");
resultform.addReportedField(rffJID);
FormField innerfield = new XFormFieldImpl("is_member_only");
innerfield.setType(FormField.TYPE_TEXT_SINGLE);
innerfield.setLabel("Is a member only room.");
resultform.addReportedField(innerfield);
res.add(resultform.asXMLElement());
resultform.addReportedField("name", "Name", FormField.Type.text_single);
resultform.addReportedField("subject", "Subject", FormField.Type.text_single);
resultform.addReportedField("num_users", "Number of users", FormField.Type.text_single);
resultform.addReportedField("num_max_users", "Max number allowed of users", FormField.Type.text_single);
resultform.addReportedField("is_password_protected", "Is a password protected room.", FormField.Type.boolean_type);
resultform.addReportedField("is_member_only", "Is a member only room.", FormField.Type.boolean_type);
resultform.addReportedField("jid", "JID", FormField.Type.text_single);
}
if (applyRSM)
......@@ -441,7 +389,9 @@ public class IQMUCSearchHandler
* @param formField
* The field from which to return the first value.
* @return String based value, or 'null' if the FormField has no values.
* @deprecated replaced by {@link FormField#getFirstValue()}
*/
@Deprecated
public static String getFirstValue(FormField formField)
{
if (formField == null)
......@@ -450,13 +400,13 @@ public class IQMUCSearchHandler
"The argument 'formField' cannot be null.");
}
Iterator<String> it = formField.getValues();
List<String> it = formField.getValues();
if (!it.hasNext())
if (it.isEmpty())
{
return null;
}
return it.next();
return it.get(0);
}
}
......@@ -12,14 +12,16 @@
package org.jivesoftware.openfire.muc.spi;
import java.util.ArrayList;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import org.dom4j.DocumentHelper;
import org.dom4j.Element;
import org.dom4j.QName;
import org.jivesoftware.openfire.PacketRouter;
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.CannotBeInvitedException;
import org.jivesoftware.openfire.muc.ConflictException;
import org.jivesoftware.openfire.muc.ForbiddenException;
......@@ -27,14 +29,16 @@ import org.jivesoftware.openfire.muc.MUCRole;
import org.jivesoftware.openfire.muc.cluster.RoomUpdatedEvent;
import org.jivesoftware.openfire.user.UserNotFoundException;
import org.jivesoftware.util.LocaleUtils;
import org.jivesoftware.util.Log;
import org.jivesoftware.util.cache.CacheFactory;
import org.xmpp.forms.DataForm;
import org.xmpp.forms.FormField;
import org.xmpp.forms.FormField.Type;
import org.xmpp.packet.IQ;
import org.xmpp.packet.JID;
import org.xmpp.packet.PacketError;
import org.xmpp.packet.Presence;
import java.util.*;
/**
* A handler for the IQ packet with namespace http://jabber.org/protocol/muc#owner. This kind of
* packets are usually sent by room owners. So this handler provides the necessary functionality
......@@ -47,7 +51,7 @@ public class IQOwnerHandler {
private PacketRouter router;
private XDataFormImpl configurationForm;
private DataForm configurationForm;
private Element probeResult;
......@@ -76,6 +80,7 @@ public class IQOwnerHandler {
* @throws ForbiddenException if the user does not have enough permissions (ie. is not an owner).
* @throws ConflictException If the room was going to lose all of its owners.
*/
@SuppressWarnings("unchecked")
public void handleIQ(IQ packet, MUCRole role) throws ForbiddenException, ConflictException, CannotBeInvitedException {
// Only owners can send packets with the namespace "http://jabber.org/protocol/muc#owner"
if (MUCRole.Affiliation.owner != role.getAffiliation()) {
......@@ -104,7 +109,7 @@ public class IQOwnerHandler {
.elementTextTrim("reason"));
}
else {
List itemsList = element.elements("item");
List<Element> itemsList = element.elements("item");
if (!itemsList.isEmpty()) {
handleItemsElement(itemsList, role, reply);
}
......@@ -145,16 +150,14 @@ public class IQOwnerHandler {
* @throws ConflictException If the room was going to lose all of its owners.
* @throws CannotBeInvitedException If the user being invited as a result of being added to a members-only room still does not have permission
*/
private void handleItemsElement(List itemsList, MUCRole senderRole, IQ reply)
private void handleItemsElement(List<Element> itemsList, MUCRole senderRole, IQ reply)
throws ForbiddenException, ConflictException, CannotBeInvitedException {
Element item;
boolean hasJID = ((Element)itemsList.get(0)).attributeValue("jid") != null;
boolean hasNick = ((Element)itemsList.get(0)).attributeValue("nick") != null;
boolean hasJID = itemsList.get(0).attributeValue("jid") != null;
boolean hasNick = itemsList.get(0).attributeValue("nick") != null;
// Check if the client is requesting or changing the list of owners/admin
if (!hasJID && !hasNick) {
// The client is requesting the list of owners or admins
for (Object anItem : itemsList) {
item = (Element) anItem;
for (final Element item : itemsList) {
String affiliation = item.attributeValue("affiliation");
// Create the result that will hold an item for each owner or admin
Element result = reply.setChildElement("query", "http://jabber.org/protocol/muc#owner");
......@@ -207,9 +210,8 @@ public class IQOwnerHandler {
Map<String,String> jids = new HashMap<String,String>();
String nick;
// Collect the new affiliations for the specified jids
for (Object anItem : itemsList) {
for (final Element item : itemsList) {
try {
item = (Element) anItem;
String affiliation = item.attributeValue("affiliation");
String bareJID;
if (hasJID) {
......@@ -290,19 +292,20 @@ public class IQOwnerHandler {
*/
private void handleDataFormElement(MUCRole senderRole, Element formElement)
throws ForbiddenException, ConflictException {
XDataFormImpl completedForm = new XDataFormImpl();
completedForm.parse(formElement);
DataForm completedForm = new DataForm(formElement);
if (DataForm.TYPE_CANCEL.equals(completedForm.getType())) {
switch(completedForm.getType()) {
case cancel:
// If the room was just created (i.e. is locked) and the owner cancels the configuration
// form then destroy the room
if (room.isLocked()) {
room.destroyRoom(null, null);
}
}
else if (DataForm.TYPE_SUBMIT.equals(completedForm.getType())) {
break;
case submit:
// The owner is requesting an instant room
if (completedForm.getFieldsSize() == 0) {
if (completedForm.getFields().isEmpty()) {
// Do nothing
}
// The owner is requesting a reserved room or is changing the current configuration
......@@ -318,6 +321,11 @@ public class IQOwnerHandler {
// Let other cluster nodes that the room has been updated
CacheFactory.doClusterTask(new RoomUpdatedEvent(room));
}
break;
default:
Log.warn("cannot handle data form element: " + formElement.asXML());
break;
}
}
......@@ -330,11 +338,10 @@ public class IQOwnerHandler {
* @throws ForbiddenException if the user does not have enough privileges.
* @throws ConflictException If the room was going to lose all of its owners.
*/
private void processConfigurationForm(XDataFormImpl completedForm, MUCRole senderRole)
private void processConfigurationForm(DataForm completedForm, MUCRole senderRole)
throws ForbiddenException, ConflictException {
Iterator<String> values;
List<String> values;
String booleanValue;
List<String> list;
FormField field;
// Get the new list of admins
......@@ -342,10 +349,7 @@ public class IQOwnerHandler {
boolean adminsSent = field != null;
List<String> admins = new ArrayList<String>();
if (field != null) {
values = field.getValues();
while (values.hasNext()) {
admins.add(values.next());
}
admins.addAll(field.getValues());
}
// Get the new list of owners
......@@ -353,10 +357,7 @@ public class IQOwnerHandler {
boolean ownersSent = field != null;
List<String> owners = new ArrayList<String>();
if (field != null) {
values = field.getValues();
while (values.hasNext()) {
owners.add(values.next());
}
owners.addAll(field.getValues());
}
// Answer a conflic error if all the current owners will be removed
......@@ -369,50 +370,46 @@ public class IQOwnerHandler {
field = completedForm.getField("muc#roomconfig_roomname");
if (field != null) {
values = field.getValues();
room.setNaturalLanguageName((values.hasNext() ? values.next() : " "));
final String value = field.getFirstValue();
room.setNaturalLanguageName((value != null ? value : " "));
}
field = completedForm.getField("muc#roomconfig_roomdesc");
if (field != null) {
values = field.getValues();
room.setDescription((values.hasNext() ? values.next() : " "));
final String value = field.getFirstValue();
room.setDescription((value != null ? value : " "));
}
field = completedForm.getField("muc#roomconfig_changesubject");
if (field != null) {
values = field.getValues();
booleanValue = (values.hasNext() ? values.next() : "1");
final String value = field.getFirstValue();
booleanValue = ((value != null ? value : "1"));
room.setCanOccupantsChangeSubject(("1".equals(booleanValue)));
}
field = completedForm.getField("muc#roomconfig_maxusers");
if (field != null) {
values = field.getValues();
room.setMaxUsers((values.hasNext() ? Integer.parseInt(values.next()) : 30));
final String value = field.getFirstValue();
room.setMaxUsers((value != null ? Integer.parseInt(value) : 30));
}
field = completedForm.getField("muc#roomconfig_presencebroadcast");
if (field != null) {
values = field.getValues();
list = new ArrayList<String>();
while (values.hasNext()) {
list.add(values.next());
}
room.setRolesToBroadcastPresence(list);
values = new ArrayList<String>(field.getValues());
room.setRolesToBroadcastPresence(values);
}
field = completedForm.getField("muc#roomconfig_publicroom");
if (field != null) {
values = field.getValues();
booleanValue = (values.hasNext() ? values.next() : "1");
final String value = field.getFirstValue();
booleanValue = ((value != null ? value : "1"));
room.setPublicRoom(("1".equals(booleanValue)));
}
field = completedForm.getField("muc#roomconfig_persistentroom");
if (field != null) {
values = field.getValues();
booleanValue = (values.hasNext() ? values.next() : "1");
final String value = field.getFirstValue();
booleanValue = ((value != null ? value : "1"));
boolean isPersistent = ("1".equals(booleanValue));
// Delete the room from the DB if it's no longer persistent
if (room.isPersistent() && !isPersistent) {
......@@ -423,36 +420,36 @@ public class IQOwnerHandler {
field = completedForm.getField("muc#roomconfig_moderatedroom");
if (field != null) {
values = field.getValues();
booleanValue = (values.hasNext() ? values.next() : "1");
final String value = field.getFirstValue();
booleanValue = ((value != null ? value : "1"));
room.setModerated(("1".equals(booleanValue)));
}
field = completedForm.getField("muc#roomconfig_membersonly");
if (field != null) {
values = field.getValues();
booleanValue = (values.hasNext() ? values.next() : "1");
final String value = field.getFirstValue();
booleanValue = ((value != null ? value : "1"));
presences.addAll(room.setMembersOnly(("1".equals(booleanValue))));
}
field = completedForm.getField("muc#roomconfig_allowinvites");
if (field != null) {
values = field.getValues();
booleanValue = (values.hasNext() ? values.next() : "1");
final String value = field.getFirstValue();
booleanValue = ((value != null ? value : "1"));
room.setCanOccupantsInvite(("1".equals(booleanValue)));
}
field = completedForm.getField("muc#roomconfig_passwordprotectedroom");
if (field != null) {
values = field.getValues();
booleanValue = (values.hasNext() ? values.next() : "1");
final String value = field.getFirstValue();
booleanValue = ((value != null ? value : "1"));
boolean isPasswordProtected = "1".equals(booleanValue);
if (isPasswordProtected) {
// The room is password protected so set the new password
field = completedForm.getField("muc#roomconfig_roomsecret");
if (field != null) {
values = completedForm.getField("muc#roomconfig_roomsecret").getValues();
room.setPassword((values.hasNext() ? values.next() : null));
final String secret = completedForm.getField("muc#roomconfig_roomsecret").getFirstValue();
room.setPassword(secret);
}
}
else {
......@@ -463,36 +460,36 @@ public class IQOwnerHandler {
field = completedForm.getField("muc#roomconfig_whois");
if (field != null) {
values = field.getValues();
booleanValue = (values.hasNext() ? values.next() : "1");
final String value = field.getFirstValue();
booleanValue = ((value != null ? value : "1"));
room.setCanAnyoneDiscoverJID(("anyone".equals(booleanValue)));
}
field = completedForm.getField("muc#roomconfig_enablelogging");
if (field != null) {
values = field.getValues();
booleanValue = (values.hasNext() ? values.next() : "1");
final String value = field.getFirstValue();
booleanValue = ((value != null ? value : "1"));
room.setLogEnabled(("1".equals(booleanValue)));
}
field = completedForm.getField("x-muc#roomconfig_reservednick");
if (field != null) {
values = field.getValues();
booleanValue = (values.hasNext() ? values.next() : "1");
final String value = field.getFirstValue();
booleanValue = ((value != null ? value : "1"));
room.setLoginRestrictedToNickname(("1".equals(booleanValue)));
}
field = completedForm.getField("x-muc#roomconfig_canchangenick");
if (field != null) {
values = field.getValues();
booleanValue = (values.hasNext() ? values.next() : "1");
final String value = field.getFirstValue();
booleanValue = ((value != null ? value : "1"));
room.setChangeNickname(("1".equals(booleanValue)));
}
field = completedForm.getField("x-muc#roomconfig_registration");
if (field != null) {
values = field.getValues();
booleanValue = (values.hasNext() ? values.next() : "1");
final String value = field.getFirstValue();
booleanValue = ((value != null ? value : "1"));
room.setRegistrationEnabled(("1".equals(booleanValue)));
}
......@@ -630,7 +627,7 @@ public class IQOwnerHandler {
// Remove the old element
probeResult.remove(probeResult.element(QName.get("x", "jabber:x:data")));
// Add the new representation of configurationForm as an element
probeResult.add(configurationForm.asXMLElement());
probeResult.add(configurationForm.getElement());
}
finally {
......@@ -642,145 +639,119 @@ public class IQOwnerHandler {
Element element = DocumentHelper.createElement(QName.get("query",
"http://jabber.org/protocol/muc#owner"));
configurationForm = new XDataFormImpl(DataForm.TYPE_FORM);
configurationForm = new DataForm(DataForm.Type.form);
configurationForm.setTitle(LocaleUtils.getLocalizedString("muc.form.conf.title"));
List<String> params = new ArrayList<String>();
params.add(room.getName());
configurationForm.addInstruction(LocaleUtils.getLocalizedString("muc.form.conf.instruction", params));
XFormFieldImpl field = new XFormFieldImpl("FORM_TYPE");
field.setType(FormField.TYPE_HIDDEN);
field.addValue("http://jabber.org/protocol/muc#roomconfig");
configurationForm.addField(field);
field = new XFormFieldImpl("muc#roomconfig_roomname");
field.setType(FormField.TYPE_TEXT_SINGLE);
field.setLabel(LocaleUtils.getLocalizedString("muc.form.conf.owner_roomname"));
configurationForm.addField(field);
field = new XFormFieldImpl("muc#roomconfig_roomdesc");
field.setType(FormField.TYPE_TEXT_SINGLE);
field.setLabel(LocaleUtils.getLocalizedString("muc.form.conf.owner_roomdesc"));
configurationForm.addField(field);
field = new XFormFieldImpl("muc#roomconfig_changesubject");
field.setType(FormField.TYPE_BOOLEAN);
field.setLabel(LocaleUtils.getLocalizedString("muc.form.conf.owner_changesubject"));
configurationForm.addField(field);
field = new XFormFieldImpl("muc#roomconfig_maxusers");
field.setType(FormField.TYPE_LIST_SINGLE);
field.setLabel(LocaleUtils.getLocalizedString("muc.form.conf.owner_maxusers"));
field.addOption("10", "10");
field.addOption("20", "20");
field.addOption("30", "30");
field.addOption("40", "40");
field.addOption("50", "50");
field.addOption(LocaleUtils.getLocalizedString("muc.form.conf.none"), "0");
configurationForm.addField(field);
field = new XFormFieldImpl("muc#roomconfig_presencebroadcast");
field.setType(FormField.TYPE_LIST_MULTI);
field.setLabel(LocaleUtils.getLocalizedString("muc.form.conf.owner_presencebroadcast"));
field.addOption(LocaleUtils.getLocalizedString("muc.form.conf.moderator"), "moderator");
field.addOption(LocaleUtils.getLocalizedString("muc.form.conf.participant"), "participant");
field.addOption(LocaleUtils.getLocalizedString("muc.form.conf.visitor"), "visitor");
configurationForm.addField(field);
field = new XFormFieldImpl("muc#roomconfig_publicroom");
field.setType(FormField.TYPE_BOOLEAN);
field.setLabel(LocaleUtils.getLocalizedString("muc.form.conf.owner_publicroom"));
configurationForm.addField(field);
field = new XFormFieldImpl("muc#roomconfig_persistentroom");
field.setType(FormField.TYPE_BOOLEAN);
field.setLabel(LocaleUtils.getLocalizedString("muc.form.conf.owner_persistentroom"));
configurationForm.addField(field);
field = new XFormFieldImpl("muc#roomconfig_moderatedroom");
field.setType(FormField.TYPE_BOOLEAN);
field.setLabel(LocaleUtils.getLocalizedString("muc.form.conf.owner_moderatedroom"));
configurationForm.addField(field);
field = new XFormFieldImpl("muc#roomconfig_membersonly");
field.setType(FormField.TYPE_BOOLEAN);
field.setLabel(LocaleUtils.getLocalizedString("muc.form.conf.owner_membersonly"));
configurationForm.addField(field);
field = new XFormFieldImpl();
field.setType(FormField.TYPE_FIXED);
field.addValue(LocaleUtils.getLocalizedString("muc.form.conf.allowinvitesfixed"));
configurationForm.addField(field);
field = new XFormFieldImpl("muc#roomconfig_allowinvites");
field.setType(FormField.TYPE_BOOLEAN);
field.setLabel(LocaleUtils.getLocalizedString("muc.form.conf.owner_allowinvites"));
configurationForm.addField(field);
field = new XFormFieldImpl("muc#roomconfig_passwordprotectedroom");
field.setType(FormField.TYPE_BOOLEAN);
field.setLabel(LocaleUtils.getLocalizedString("muc.form.conf.owner_passwordprotectedroom"));
configurationForm.addField(field);
field = new XFormFieldImpl();
field.setType(FormField.TYPE_FIXED);
field.addValue(LocaleUtils.getLocalizedString("muc.form.conf.roomsecretfixed"));
configurationForm.addField(field);
field = new XFormFieldImpl("muc#roomconfig_roomsecret");
field.setType(FormField.TYPE_TEXT_PRIVATE);
field.setLabel(LocaleUtils.getLocalizedString("muc.form.conf.owner_roomsecret"));
configurationForm.addField(field);
field = new XFormFieldImpl("muc#roomconfig_whois");
field.setType(FormField.TYPE_LIST_SINGLE);
field.setLabel(LocaleUtils.getLocalizedString("muc.form.conf.owner_whois"));
field.addOption(LocaleUtils.getLocalizedString("muc.form.conf.moderator"), "moderators");
field.addOption(LocaleUtils.getLocalizedString("muc.form.conf.anyone"), "anyone");
configurationForm.addField(field);
field = new XFormFieldImpl("muc#roomconfig_enablelogging");
field.setType(FormField.TYPE_BOOLEAN);
field.setLabel(LocaleUtils.getLocalizedString("muc.form.conf.owner_enablelogging"));
configurationForm.addField(field);
field = new XFormFieldImpl("x-muc#roomconfig_reservednick");
field.setType(FormField.TYPE_BOOLEAN);
field.setLabel(LocaleUtils.getLocalizedString("muc.form.conf.owner_reservednick"));
configurationForm.addField(field);
field = new XFormFieldImpl("x-muc#roomconfig_canchangenick");
field.setType(FormField.TYPE_BOOLEAN);
field.setLabel(LocaleUtils.getLocalizedString("muc.form.conf.owner_canchangenick"));
configurationForm.addField(field);
field = new XFormFieldImpl("x-muc#roomconfig_registration");
field.setType(FormField.TYPE_BOOLEAN);
field.setLabel(LocaleUtils.getLocalizedString("muc.form.conf.owner_registration"));
configurationForm.addField(field);
field = new XFormFieldImpl();
field.setType(FormField.TYPE_FIXED);
field.addValue(LocaleUtils.getLocalizedString("muc.form.conf.roomadminsfixed"));
configurationForm.addField(field);
field = new XFormFieldImpl("muc#roomconfig_roomadmins");
field.setType(FormField.TYPE_JID_MULTI);
field.setLabel(LocaleUtils.getLocalizedString("muc.form.conf.owner_roomadmins"));
configurationForm.addField(field);
field = new XFormFieldImpl();
field.setType(FormField.TYPE_FIXED);
field.addValue(LocaleUtils.getLocalizedString("muc.form.conf.roomownersfixed"));
configurationForm.addField(field);
field = new XFormFieldImpl("muc#roomconfig_roomowners");
field.setType(FormField.TYPE_JID_MULTI);
field.setLabel(LocaleUtils.getLocalizedString("muc.form.conf.owner_roomowners"));
configurationForm.addField(field);
configurationForm.addField("FORM_TYPE", null, Type.hidden)
.addValue("http://jabber.org/protocol/muc#roomconfig");
configurationForm.addField("muc#roomconfig_roomname",
LocaleUtils.getLocalizedString("muc.form.conf.owner_roomname"),
Type.text_single);
configurationForm.addField("muc#roomconfig_roomdesc",
LocaleUtils.getLocalizedString("muc.form.conf.owner_roomdesc"),
Type.text_single);
configurationForm.addField("muc#roomconfig_changesubject",
LocaleUtils.getLocalizedString("muc.form.conf.owner_changesubject"),
Type.boolean_type);
final FormField maxUsers = configurationForm.addField(
"muc#roomconfig_maxusers",
LocaleUtils.getLocalizedString("muc.form.conf.owner_maxusers"),
Type.list_single);
maxUsers.addOption("10", "10");
maxUsers.addOption("20", "20");
maxUsers.addOption("30", "30");
maxUsers.addOption("40", "40");
maxUsers.addOption("50", "50");
maxUsers.addOption(LocaleUtils.getLocalizedString("muc.form.conf.none"), "0");
final FormField broadcast = configurationForm.addField(
"muc#roomconfig_presencebroadcast",
LocaleUtils.getLocalizedString("muc.form.conf.owner_presencebroadcast"),
Type.list_multi);
broadcast.addOption(LocaleUtils.getLocalizedString("muc.form.conf.moderator"), "moderator");
broadcast.addOption(LocaleUtils.getLocalizedString("muc.form.conf.participant"), "participant");
broadcast.addOption(LocaleUtils.getLocalizedString("muc.form.conf.visitor"), "visitor");
configurationForm.addField("muc#roomconfig_publicroom",
LocaleUtils.getLocalizedString("muc.form.conf.owner_publicroom"),
Type.boolean_type);
configurationForm.addField("muc#roomconfig_persistentroom",
LocaleUtils.getLocalizedString("muc.form.conf.owner_persistentroom"),
Type.boolean_type);
configurationForm.addField("muc#roomconfig_moderatedroom",
LocaleUtils.getLocalizedString("muc.form.conf.owner_moderatedroom"),
Type.boolean_type);
configurationForm.addField("muc#roomconfig_membersonly",
LocaleUtils.getLocalizedString("muc.form.conf.owner_membersonly"),
Type.boolean_type);
configurationForm.addField(null, null, Type.fixed)
.addValue(LocaleUtils.getLocalizedString("muc.form.conf.allowinvitesfixed"));
configurationForm.addField("muc#roomconfig_allowinvites",
LocaleUtils.getLocalizedString("muc.form.conf.owner_allowinvites"),
Type.boolean_type);
configurationForm.addField("muc#roomconfig_passwordprotectedroom",
LocaleUtils.getLocalizedString("muc.form.conf.owner_passwordprotectedroom"),
Type.boolean_type);
configurationForm.addField(null, null, Type.fixed)
.addValue(LocaleUtils.getLocalizedString("muc.form.conf.roomsecretfixed"));
configurationForm.addField("muc#roomconfig_roomsecret",
LocaleUtils.getLocalizedString("muc.form.conf.owner_roomsecret"),
Type.text_private);
final FormField whois = configurationForm.addField(
"muc#roomconfig_whois",
LocaleUtils.getLocalizedString("muc.form.conf.owner_whois"),
Type.list_single);
whois.addOption(LocaleUtils.getLocalizedString("muc.form.conf.moderator"), "moderators");
whois.addOption(LocaleUtils.getLocalizedString("muc.form.conf.anyone"), "anyone");
configurationForm.addField("muc#roomconfig_enablelogging",
LocaleUtils.getLocalizedString("muc.form.conf.owner_enablelogging"),
Type.boolean_type);
configurationForm.addField("x-muc#roomconfig_reservednick",
LocaleUtils.getLocalizedString("muc.form.conf.owner_reservednick"),
Type.boolean_type);
configurationForm.addField("x-muc#roomconfig_canchangenick",
LocaleUtils.getLocalizedString("muc.form.conf.owner_canchangenick"),
Type.boolean_type);
configurationForm.addField("x-muc#roomconfig_registration",
LocaleUtils.getLocalizedString("muc.form.conf.owner_registration"),
Type.boolean_type);
configurationForm.addField(null, null, Type.fixed)
.addValue(LocaleUtils.getLocalizedString("muc.form.conf.owner_registration"));
configurationForm.addField("muc#roomconfig_roomadmins",
LocaleUtils.getLocalizedString("muc.form.conf.owner_roomadmins"),
Type.jid_multi);
configurationForm.addField(null, null, Type.fixed)
.addValue(LocaleUtils.getLocalizedString("muc.form.conf.roomownersfixed"));
configurationForm.addField("muc#roomconfig_roomowners",
LocaleUtils.getLocalizedString("muc.form.conf.owner_roomowners"),
Type.jid_multi);
// Create the probeResult and add the basic info together with the configuration form
probeResult = element;
probeResult.add(configurationForm.asXMLElement());
probeResult.add(configurationForm.getElement());
}
}
\ No newline at end of file
......@@ -8,6 +8,21 @@
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.Element;
import org.dom4j.QName;
......@@ -16,31 +31,29 @@ import org.jivesoftware.openfire.container.Plugin;
import org.jivesoftware.openfire.container.PluginManager;
import org.jivesoftware.openfire.disco.IQDiscoInfoHandler;
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.UserManager;
import org.jivesoftware.openfire.user.UserNotFoundException;
import org.jivesoftware.util.*;
import org.jivesoftware.util.JiveGlobals;
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.ComponentException;
import org.xmpp.component.ComponentManager;
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.Type;
import org.xmpp.packet.JID;
import org.xmpp.packet.Packet;
import org.xmpp.packet.PacketError;
import org.xmpp.packet.IQ.Type;
import org.xmpp.packet.PacketError.Condition;
import org.xmpp.resultsetmanagement.ResultSet;
import org.xmpp.resultsetmanagement.ResultSetImpl;
import java.io.File;
import java.util.*;
import java.util.Map.Entry;
/**
* Provides support for Jabber Search
* (<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 {
IQ replyPacket = IQ.createResultIQ(packet);
Element reply = replyPacket.setChildElement("query",
NAMESPACE_JABBER_IQ_SEARCH);
XDataFormImpl unavailableForm = new XDataFormImpl(DataForm.TYPE_CANCEL);
final DataForm unavailableForm = new DataForm(DataForm.Type.cancel);
unavailableForm.setTitle(LocaleUtils.getLocalizedString(
"advance.user.search.title", "search"));
unavailableForm.addInstruction(LocaleUtils.getLocalizedString(
"search.service_unavailable", "search"));
reply.add(unavailableForm.asXMLElement());
reply.add(unavailableForm.getElement());
return replyPacket;
}
......@@ -388,34 +401,31 @@ public class SearchPlugin implements Component, Plugin, PropertyEventListener {
queryResult.addElement("nick");
queryResult.addElement("email");
XDataFormImpl searchForm = new XDataFormImpl(DataForm.TYPE_FORM);
DataForm searchForm = new DataForm(DataForm.Type.form);
searchForm.setTitle(LocaleUtils.getLocalizedString(
"advance.user.search.title", "search"));
searchForm.addInstruction(instructions);
XFormFieldImpl field = new XFormFieldImpl("FORM_TYPE");
field.setType(FormField.TYPE_HIDDEN);
field.addValue(NAMESPACE_JABBER_IQ_SEARCH);
searchForm.addField(field);
searchForm.addField("FORM_TYPE", null, FormField.Type.hidden)
.addValue(NAMESPACE_JABBER_IQ_SEARCH);
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()) {
field = new XFormFieldImpl(searchField);
field.setType(FormField.TYPE_BOOLEAN);
final FormField field = searchForm.addField();
field.setVariable(searchField);
field.setType(FormField.Type.boolean_type);
field.addValue("1");
field.setLabel(LocaleUtils.getLocalizedString(
"advance.user.search." + searchField.toLowerCase(), "search"));
field.setRequired(false);
searchForm.addField(field);
}
queryResult.add(searchForm.asXMLElement());
queryResult.add(searchForm.getElement());
replyPacket.setChildElement(queryResult);
return replyPacket;
......@@ -515,6 +525,7 @@ public class SearchPlugin implements Component, Plugin, PropertyEventListener {
* @return ''true'' if the supplied IQ stanza is a spec compliant search
* request, ''false'' otherwise.
*/
@SuppressWarnings("unchecked")
public static boolean isValidSearchRequest(IQ iq) {
if (iq == null) {
......@@ -620,6 +631,7 @@ public class SearchPlugin implements Component, Plugin, PropertyEventListener {
* The form from which to extract the query
* @return The search query for a particular user search request.
*/
@SuppressWarnings("unchecked")
private Hashtable<String, String> extractSearchQuery(Element incomingForm) {
if (incomingForm.element(QName.get("x", "jabber:x:data")) != null) {
// forward the request.
......@@ -657,6 +669,7 @@ public class SearchPlugin implements Component, Plugin, PropertyEventListener {
* @return The search query for a particular user search request.
* @see #extractSearchQuery(Element)
*/
@SuppressWarnings("unchecked")
private Hashtable<String, String> extractExtendedSearchQuery(
Element incomingForm) {
final Element dataform = incomingForm.element(QName.get("x",
......@@ -697,51 +710,41 @@ public class SearchPlugin implements Component, Plugin, PropertyEventListener {
* @return the iq packet that contains the search results
*/
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");
field.setType(FormField.TYPE_HIDDEN);
searchResults.addField(field);
searchResults.addField("FORM_TYPE", null, FormField.Type.hidden);
field = new XFormFieldImpl("jid");
field.setLabel("JID");
searchResults.addReportedField(field);
searchResults.addReportedField("jid", "JID", null);
for (String fieldName : getFilteredSearchFields()) {
field = new XFormFieldImpl(fieldName);
field.setLabel(LocaleUtils.getLocalizedString(
"advance.user.search." + fieldName.toLowerCase(), "search"));
searchResults.addReportedField(field);
for (final String fieldName : getFilteredSearchFields()) {
searchResults.addReportedField(fieldName,
LocaleUtils.getLocalizedString("advance.user.search." + fieldName.toLowerCase(), "search"),
null);
}
for (User user : users) {
String username = JID.unescapeNode(user.getUsername());
ArrayList<XFormFieldImpl> items = new ArrayList<XFormFieldImpl>();
for (final User user : users) {
final String username = JID.unescapeNode(user.getUsername());
XFormFieldImpl fieldJID = new XFormFieldImpl("jid");
fieldJID.addValue(username + "@" + serverName);
items.add(fieldJID);
final Map<String, Object> item = new HashMap<String, Object>();
item.put("jid",
username + "@" + serverName);
XFormFieldImpl fieldUsername = new XFormFieldImpl(LocaleUtils.getLocalizedString("advance.user.search.username", "search"));
fieldUsername.addValue(username);
items.add(fieldUsername);
item.put(LocaleUtils.getLocalizedString("advance.user.search.username", "search"),
username);
XFormFieldImpl fieldName = new XFormFieldImpl(LocaleUtils.getLocalizedString("advance.user.search.name", "search"));
fieldName.addValue((user.isNameVisible() ? removeNull(user.getName()) : ""));
items.add(fieldName);
item.put(LocaleUtils.getLocalizedString("advance.user.search.name", "search"),
(user.isNameVisible() ? removeNull(user.getName()) : ""));
XFormFieldImpl fieldEmail = new XFormFieldImpl(LocaleUtils.getLocalizedString("advance.user.search.email", "search"));
fieldEmail.addValue((user.isEmailVisible() ? removeNull(user.getEmail()) : ""));
items.add(fieldEmail);
item.put(LocaleUtils.getLocalizedString("advance.user.search.email", "search"),
(user.isEmailVisible() ? removeNull(user.getEmail()) : ""));
searchResults.addItemFields(items);
searchResults.addItemFields(item);
}
IQ replyPacket = IQ.createResultIQ(packet);
Element reply = replyPacket.setChildElement("query",
NAMESPACE_JABBER_IQ_SEARCH);
reply.add(searchResults.asXMLElement());
reply.add(searchResults.getElement());
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