use of org.xmpp.forms.DataForm in project Openfire by igniterealtime.
the class UserProperties method execute.
@Override
public void execute(SessionData data, Element command) {
DataForm form = new DataForm(DataForm.Type.result);
FormField field = form.addField();
field.setType(FormField.Type.hidden);
field.setVariable("FORM_TYPE");
field.addValue("http://jabber.org/protocol/admin");
List<String> accounts = data.getData().get("accountjids");
if (accounts != null && accounts.size() > 0) {
populateResponseFields(form, accounts);
}
command.add(form.getElement());
}
use of org.xmpp.forms.DataForm in project Openfire by igniterealtime.
the class GroupDeleting method addStageInformation.
@Override
protected void addStageInformation(SessionData data, Element command) {
DataForm form = new DataForm(DataForm.Type.form);
form.setTitle("Dispatching a deleting group event.");
form.addInstruction("Fill out this form to dispatch a deleting group event.");
FormField field = form.addField();
field.setType(FormField.Type.hidden);
field.setVariable("FORM_TYPE");
field.addValue("http://jabber.org/protocol/admin");
field = form.addField();
field.setType(FormField.Type.text_single);
field.setLabel("The group name of the group that is being deleted");
field.setVariable("groupName");
field.setRequired(true);
// Add the form to the command
command.add(form.getElement());
}
use of org.xmpp.forms.DataForm in project Openfire by igniterealtime.
the class GroupMemberAdded method addStageInformation.
@Override
protected void addStageInformation(SessionData data, Element command) {
DataForm form = new DataForm(DataForm.Type.form);
form.setTitle("Dispatching a group member added event.");
form.addInstruction("Fill out this form to dispatch a group member added event.");
FormField field = form.addField();
field.setType(FormField.Type.hidden);
field.setVariable("FORM_TYPE");
field.addValue("http://jabber.org/protocol/admin");
field = form.addField();
field.setType(FormField.Type.text_single);
field.setLabel("The group name of the group");
field.setVariable("groupName");
field.setRequired(true);
field = form.addField();
field.setType(FormField.Type.text_single);
field.setLabel("Member");
field.setVariable("member");
field.setRequired(true);
// Add the form to the command
command.add(form.getElement());
}
use of org.xmpp.forms.DataForm in project Openfire by igniterealtime.
the class IQMUCRegisterHandler method handleIQ.
public IQ handleIQ(IQ packet) {
IQ reply = null;
// Get the target room
MUCRoom room = null;
String name = packet.getTo().getNode();
if (name != null) {
room = mucService.getChatRoom(name);
}
if (room == null) {
// The room doesn't exist so answer a NOT_FOUND error
reply = IQ.createResultIQ(packet);
reply.setChildElement(packet.getChildElement().createCopy());
reply.setError(PacketError.Condition.item_not_found);
return reply;
} else if (!room.isRegistrationEnabled() || (packet.getFrom() != null && MUCRole.Affiliation.outcast == room.getAffiliation(packet.getFrom().asBareJID()))) {
// The room does not accept users to register or
// the user is an outcast and is not allowed to register
reply = IQ.createResultIQ(packet);
reply.setChildElement(packet.getChildElement().createCopy());
reply.setError(PacketError.Condition.not_allowed);
return reply;
}
if (IQ.Type.get == packet.getType()) {
reply = IQ.createResultIQ(packet);
String nickname = room.getReservedNickname(packet.getFrom());
Element currentRegistration = probeResult.createCopy();
if (nickname != null) {
// The user is already registered with the room so answer a completed form
ElementUtil.setProperty(currentRegistration, "query.registered", null);
currentRegistration.addElement("username").addText(nickname);
Element form = currentRegistration.element(QName.get("x", "jabber:x:data"));
currentRegistration.remove(form);
// @SuppressWarnings("unchecked")
// Iterator<Element> fields = form.elementIterator("field");
//
// Element field;
// while (fields.hasNext()) {
// field = fields.next();
// if ("muc#register_roomnick".equals(field.attributeValue("var"))) {
// field.addElement("value").addText(nickname);
// }
// }
reply.setChildElement(currentRegistration);
} else {
// The user is not registered with the room so answer an empty form
reply.setChildElement(currentRegistration);
}
} else if (IQ.Type.set == packet.getType()) {
try {
// Keep a registry of the updated presences
List<Presence> presences = new ArrayList<>();
reply = IQ.createResultIQ(packet);
Element iq = packet.getChildElement();
if (ElementUtil.includesProperty(iq, "query.remove")) {
// The user is deleting his registration
presences.addAll(room.addNone(packet.getFrom(), room.getRole()));
} else {
// The user is trying to register with a room
Element formElement = iq.element("x");
// Check if a form was used to provide the registration info
if (formElement != null) {
// Get the sent form
final DataForm registrationForm = new DataForm(formElement);
// Get the desired nickname sent in the form
List<String> values = registrationForm.getField("muc#register_roomnick").getValues();
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
// MUCRoom.addMember in order to receive a RegistrationInfo (new class)
// Add the new member to the members list
presences.addAll(room.addMember(packet.getFrom(), nickname, room.getRole()));
} else {
reply.setChildElement(packet.getChildElement().createCopy());
reply.setError(PacketError.Condition.bad_request);
}
}
// Send the updated presences to the room occupants
for (Presence presence : presences) {
room.send(presence);
}
} catch (ForbiddenException e) {
reply = IQ.createResultIQ(packet);
reply.setChildElement(packet.getChildElement().createCopy());
reply.setError(PacketError.Condition.forbidden);
} catch (ConflictException e) {
reply = IQ.createResultIQ(packet);
reply.setChildElement(packet.getChildElement().createCopy());
reply.setError(PacketError.Condition.conflict);
} catch (Exception e) {
Log.error(e.getMessage(), e);
}
}
return reply;
}
use of org.xmpp.forms.DataForm in project Openfire by igniterealtime.
the class IQMUCSearchHandler method getDataElement.
/**
* Utility method that returns a 'jabber:iq:search' child element filled
* with a blank dataform.
*
* @return Element, named 'query', escaped by the 'jabber:iq:search'
* namespace, filled with a blank dataform.
*/
private static Element getDataElement() {
final DataForm searchForm = new DataForm(DataForm.Type.form);
searchForm.setTitle("Chat Rooms Search");
searchForm.addInstruction("Instructions");
final FormField typeFF = searchForm.addField();
typeFF.setVariable("FORM_TYPE");
typeFF.setType(FormField.Type.hidden);
typeFF.addValue("jabber:iq:search");
final FormField nameFF = searchForm.addField();
nameFF.setVariable("name");
nameFF.setType(FormField.Type.text_single);
nameFF.setLabel("Name");
nameFF.setRequired(false);
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);
final FormField subjectFF = searchForm.addField();
subjectFF.setVariable("subject");
subjectFF.setType(FormField.Type.text_single);
subjectFF.setLabel("Subject");
subjectFF.setRequired(false);
final FormField userAmountFF = searchForm.addField();
userAmountFF.setVariable("num_users");
userAmountFF.setType(FormField.Type.text_single);
userAmountFF.setLabel("Number of users");
userAmountFF.setRequired(false);
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);
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);
final Element probeResult = DocumentHelper.createElement(QName.get("query", "jabber:iq:search"));
probeResult.add(searchForm.getElement());
return probeResult;
}
Aggregations