use of org.xmpp.forms.DataForm in project Openfire by igniterealtime.
the class PubSubEngine method configureSubscription.
private void configureSubscription(PubSubService service, IQ iq, Element optionsElement) {
String nodeID = optionsElement.attributeValue("node");
String subID = optionsElement.attributeValue("subid");
Node node;
if (nodeID == null) {
if (service.isCollectionNodesSupported()) {
// Entity submits new subscription options of root collection node
node = service.getRootCollectionNode();
} else {
// Service does not have a root collection node so return a nodeid-required error
Element pubsubError = DocumentHelper.createElement(QName.get("nodeid-required", "http://jabber.org/protocol/pubsub#errors"));
sendErrorPacket(iq, PacketError.Condition.bad_request, pubsubError);
return;
}
} else {
// Look for the specified node
node = service.getNode(nodeID);
if (node == null) {
// Node does not exist. Return item-not-found error
sendErrorPacket(iq, PacketError.Condition.item_not_found, null);
return;
}
}
NodeSubscription subscription;
if (node.isMultipleSubscriptionsEnabled()) {
if (subID == null) {
// No subid was specified and the node supports multiple subscriptions
Element pubsubError = DocumentHelper.createElement(QName.get("subid-required", "http://jabber.org/protocol/pubsub#errors"));
sendErrorPacket(iq, PacketError.Condition.bad_request, pubsubError);
return;
} else {
// Check if the specified subID belongs to an existing node subscription
subscription = node.getSubscription(subID);
if (subscription == null) {
Element pubsubError = DocumentHelper.createElement(QName.get("invalid-subid", "http://jabber.org/protocol/pubsub#errors"));
sendErrorPacket(iq, PacketError.Condition.not_acceptable, pubsubError);
return;
}
}
} else {
// Check if the specified JID has a subscription with the node
String jidAttribute = optionsElement.attributeValue("jid");
if (jidAttribute == null) {
// No JID was specified so return an error indicating that jid is required
Element pubsubError = DocumentHelper.createElement(QName.get("jid-required", "http://jabber.org/protocol/pubsub#errors"));
sendErrorPacket(iq, PacketError.Condition.bad_request, pubsubError);
return;
}
JID subscriberJID = new JID(jidAttribute);
subscription = node.getSubscription(subscriberJID);
if (subscription == null) {
Element pubsubError = DocumentHelper.createElement(QName.get("not-subscribed", "http://jabber.org/protocol/pubsub#errors"));
sendErrorPacket(iq, PacketError.Condition.unexpected_request, pubsubError);
return;
}
}
// new subscription options
if (!subscription.canModify(iq.getFrom())) {
// Requestor is prohibited from setting new subscription options
sendErrorPacket(iq, PacketError.Condition.forbidden, null);
return;
}
Element formElement = optionsElement.element(QName.get("x", "jabber:x:data"));
if (formElement != null) {
// Change the subscription configuration based on the completed form
subscription.configure(iq, new DataForm(formElement));
} else {
// No data form was included so return bad request error
sendErrorPacket(iq, PacketError.Condition.bad_request, null);
}
}
use of org.xmpp.forms.DataForm in project Openfire by igniterealtime.
the class WorkgroupFormProvider method executeGet.
public void executeGet(IQ packet, Workgroup workgroup) {
IQ reply = IQ.createResultIQ(packet);
FormManager formManager = FormManager.getInstance();
DataForm dataForm = formManager.getDataForm(workgroup);
if (dataForm == null) {
reply.setChildElement(packet.getChildElement().createCopy());
reply.setError(new PacketError(PacketError.Condition.item_not_found));
workgroup.send(reply);
return;
}
Element iq = packet.getChildElement();
if (iq.elements().isEmpty()) {
reply.setChildElement(iq.createCopy());
// Send the data form to the requestor
reply.addExtension(dataForm.createCopy());
workgroup.send(reply);
}
}
use of org.xmpp.forms.DataForm in project Openfire by igniterealtime.
the class FormManager method saveDataForm.
private void saveDataForm(Workgroup workgroup) {
DataForm dataForm = new DataForm(DataForm.Type.form);
WorkgroupForm form = getWebForm(workgroup);
if (form.getTitle() != null) {
dataForm.setTitle(form.getTitle());
}
if (form.getDescription() != null) {
dataForm.addInstruction(form.getDescription());
}
List<FormElement> elems = new ArrayList<FormElement>();
// Add normal elems
int size = form.getFormElements().size();
for (int j = 0; j < size; j++) {
elems.add(form.getFormElementAt(j));
}
size = form.getHiddenVars().size();
for (int k = 0; k < size; k++) {
elems.add(form.getHiddenVars().get(k));
}
size = elems.size();
for (int i = 0; i < size; i++) {
FormElement elem = elems.get(i);
FormField field = dataForm.addField();
field.setLabel(elem.getLabel());
field.setVariable(elem.getVariable());
field.setRequired(elem.isRequired());
if (elem.getDescription() != null) {
field.setDescription(elem.getDescription());
}
if (elem.getAnswerType() == WorkgroupForm.FormEnum.textarea) {
field.setType(FormField.Type.text_multi);
} else if (elem.getAnswerType() == WorkgroupForm.FormEnum.textfield) {
field.setType(FormField.Type.text_single);
} else if (elem.getAnswerType() == WorkgroupForm.FormEnum.checkbox) {
field.setType(FormField.Type.boolean_type);
} else if (elem.getAnswerType() == WorkgroupForm.FormEnum.radio_button) {
field.setType(FormField.Type.list_multi);
} else if (elem.getAnswerType() == WorkgroupForm.FormEnum.dropdown_box) {
field.setType(FormField.Type.list_single);
} else if (elem.getAnswerType() == WorkgroupForm.FormEnum.hidden) {
field.setType(FormField.Type.hidden);
} else if (elem.getAnswerType() == WorkgroupForm.FormEnum.password) {
field.setType(FormField.Type.text_private);
}
if (elem.getAnswers().size() > 0 && elem.getAnswerType() != WorkgroupForm.FormEnum.hidden) {
for (String item : elem.getAnswers()) {
field.addOption(item, item);
}
} else if (elem.getAnswers().size() > 0) {
// Add hidden element values.
for (String item : elem.getAnswers()) {
field.addValue(item);
}
}
}
XStream xstream = new XStream();
String xmlToSave = xstream.toXML(dataForm);
DbProperties props = workgroup.getProperties();
String context = "jive.dataform.wg";
try {
props.deleteProperty(context);
props.setProperty(context, xmlToSave);
} catch (UnauthorizedException e) {
Log.error(e.getMessage(), e);
}
}
use of org.xmpp.forms.DataForm in project Openfire by igniterealtime.
the class IQOwnerHandler method init.
private void init() {
Element element = DocumentHelper.createElement(QName.get("query", "http://jabber.org/protocol/muc#owner"));
configurationForm = new DataForm(DataForm.Type.form);
configurationForm.setTitle(LocaleUtils.getLocalizedString("muc.form.conf.title"));
List<String> params = new ArrayList<>();
params.add(room.getName());
configurationForm.addInstruction(LocaleUtils.getLocalizedString("muc.form.conf.instruction", params));
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");
final FormField allowpm = configurationForm.addField("muc#roomconfig_allowpm", LocaleUtils.getLocalizedString("muc.form.conf.owner_allowpm"), Type.list_single);
allowpm.addOption(LocaleUtils.getLocalizedString("muc.form.conf.anyone"), "anyone");
allowpm.addOption(LocaleUtils.getLocalizedString("muc.form.conf.moderator"), "moderators");
allowpm.addOption(LocaleUtils.getLocalizedString("muc.form.conf.participant"), "participants");
allowpm.addOption(LocaleUtils.getLocalizedString("muc.form.conf.none"), "none");
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(null, null, Type.fixed).addValue(LocaleUtils.getLocalizedString("muc.form.conf.owner_registration"));
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.roomadminsfixed"));
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.getElement());
}
use of org.xmpp.forms.DataForm in project Openfire by igniterealtime.
the class ForwardTest method testForwarded.
@Test
public void testForwarded() {
Message message = new Message();
message.setType(Message.Type.chat);
message.setBody("Tests");
message.addExtension(new DataForm(DataForm.Type.submit));
Forwarded forwarded = new Forwarded(message);
Forwarded forwarded2 = new Forwarded(message);
String xml1 = forwarded.getElement().asXML();
String xml2 = forwarded2.getElement().asXML();
assertEquals("<forwarded xmlns=\"urn:xmpp:forward:0\"><message xmlns=\"jabber:client\" type=\"chat\"><body>Tests</body><x xmlns=\"jabber:x:data\" type=\"submit\"/></message></forwarded>", xml1);
assertEquals("<forwarded xmlns=\"urn:xmpp:forward:0\"><message xmlns=\"jabber:client\" type=\"chat\"><body>Tests</body><x xmlns=\"jabber:x:data\" type=\"submit\"/></message></forwarded>", xml2);
}
Aggregations