use of org.xmpp.forms.FormField in project Openfire by igniterealtime.
the class Node method getMetadataForm.
/**
* Returns a data form containing the node configuration that is going to be used for
* service discovery.
*
* @return a data form with the node configuration.
*/
public DataForm getMetadataForm() {
DataForm form = new DataForm(DataForm.Type.result);
FormField formField = form.addField();
formField.setVariable("FORM_TYPE");
formField.setType(FormField.Type.hidden);
formField.addValue("http://jabber.org/protocol/pubsub#meta-data");
// Add the form fields
addFormFields(form, true);
return form;
}
use of org.xmpp.forms.FormField in project Openfire by igniterealtime.
the class NodeSubscription method getConfigurationForm.
/**
* Returns a data form with the subscription configuration. The data form can be used to
* edit the subscription configuration.
*
* @return data form used by the subscriber to edit the subscription configuration.
*/
public DataForm getConfigurationForm() {
DataForm form = new DataForm(DataForm.Type.form);
form.setTitle(LocaleUtils.getLocalizedString("pubsub.form.subscription.title"));
List<String> params = new ArrayList<>();
params.add(node.getNodeID());
form.addInstruction(LocaleUtils.getLocalizedString("pubsub.form.subscription.instruction", params));
// Add the form fields and configure them for edition
FormField formField = form.addField();
formField.setVariable("FORM_TYPE");
formField.setType(FormField.Type.hidden);
formField.addValue("http://jabber.org/protocol/pubsub#subscribe_options");
formField = form.addField();
formField.setVariable("pubsub#deliver");
formField.setType(FormField.Type.boolean_type);
formField.setLabel(LocaleUtils.getLocalizedString("pubsub.form.subscription.deliver"));
formField.addValue(deliverNotifications);
formField = form.addField();
formField.setVariable("pubsub#digest");
formField.setType(FormField.Type.boolean_type);
formField.setLabel(LocaleUtils.getLocalizedString("pubsub.form.subscription.digest"));
formField.addValue(usingDigest);
formField = form.addField();
formField.setVariable("pubsub#digest_frequency");
formField.setType(FormField.Type.text_single);
formField.setLabel(LocaleUtils.getLocalizedString("pubsub.form.subscription.digest_frequency"));
formField.addValue(digestFrequency);
formField = form.addField();
formField.setVariable("pubsub#expire");
formField.setType(FormField.Type.text_single);
formField.setLabel(LocaleUtils.getLocalizedString("pubsub.form.subscription.expire"));
if (expire != null) {
formField.addValue(XMPPDateTimeFormat.format(expire));
}
formField = form.addField();
formField.setVariable("pubsub#include_body");
formField.setType(FormField.Type.boolean_type);
formField.setLabel(LocaleUtils.getLocalizedString("pubsub.form.subscription.include_body"));
formField.addValue(includingBody);
formField = form.addField();
formField.setVariable("pubsub#show-values");
formField.setType(FormField.Type.list_multi);
formField.setLabel(LocaleUtils.getLocalizedString("pubsub.form.subscription.show-values"));
formField.addOption(null, Presence.Show.away.name());
formField.addOption(null, Presence.Show.chat.name());
formField.addOption(null, Presence.Show.dnd.name());
formField.addOption(null, "online");
formField.addOption(null, Presence.Show.xa.name());
for (String value : presenceStates) {
formField.addValue(value);
}
if (node.isCollectionNode()) {
formField = form.addField();
formField.setVariable("pubsub#subscription_type");
formField.setType(FormField.Type.list_single);
formField.setLabel(LocaleUtils.getLocalizedString("pubsub.form.subscription.subscription_type"));
formField.addOption(null, Type.items.name());
formField.addOption(null, Type.nodes.name());
formField.addValue(type);
formField = form.addField();
formField.setVariable("pubsub#subscription_depth");
formField.setType(FormField.Type.list_single);
formField.setLabel(LocaleUtils.getLocalizedString("pubsub.form.subscription.subscription_depth"));
formField.addOption(null, "1");
formField.addOption(null, "all");
formField.addValue(depth == 1 ? "1" : "all");
}
if (!node.isCollectionNode() || type == Type.items) {
formField = form.addField();
formField.setVariable("x-pubsub#keywords");
formField.setType(FormField.Type.text_single);
formField.setLabel(LocaleUtils.getLocalizedString("pubsub.form.subscription.keywords"));
if (keyword != null) {
formField.addValue(keyword);
}
}
return form;
}
use of org.xmpp.forms.FormField in project Openfire by igniterealtime.
the class NodeSubscription method configure.
void configure(DataForm options) {
List<String> values;
String booleanValue;
boolean wasUsingPresence = !presenceStates.isEmpty();
// Remove this field from the form
options.removeField("FORM_TYPE");
// Process and remove specific collection node fields
FormField collectionField = options.getField("pubsub#subscription_type");
if (collectionField != null) {
values = collectionField.getValues();
if (values.size() > 0) {
type = Type.valueOf(values.get(0));
}
options.removeField("pubsub#subscription_type");
}
collectionField = options.getField("pubsub#subscription_depth");
if (collectionField != null) {
values = collectionField.getValues();
depth = "all".equals(values.get(0)) ? 0 : 1;
options.removeField("pubsub#subscription_depth");
}
// the subscription has been configured
for (FormField field : options.getFields()) {
boolean fieldExists = true;
if ("pubsub#deliver".equals(field.getVariable())) {
values = field.getValues();
booleanValue = (values.size() > 0 ? values.get(0) : "1");
deliverNotifications = "1".equals(booleanValue);
} else if ("pubsub#digest".equals(field.getVariable())) {
values = field.getValues();
booleanValue = (values.size() > 0 ? values.get(0) : "1");
usingDigest = "1".equals(booleanValue);
} else if ("pubsub#digest_frequency".equals(field.getVariable())) {
values = field.getValues();
digestFrequency = values.size() > 0 ? Integer.parseInt(values.get(0)) : 86400000;
} else if ("pubsub#expire".equals(field.getVariable())) {
values = field.getValues();
try {
expire = xmppDateTime.parseString(values.get(0));
} catch (ParseException e) {
Log.error("Error parsing date", e);
}
} else if ("pubsub#include_body".equals(field.getVariable())) {
values = field.getValues();
booleanValue = (values.size() > 0 ? values.get(0) : "1");
includingBody = "1".equals(booleanValue);
} else if ("pubsub#show-values".equals(field.getVariable())) {
// Get the new list of presence states for which an entity wants to
// receive notifications
presenceStates = new ArrayList<>();
for (String value : field.getValues()) {
try {
presenceStates.add(value);
} catch (Exception e) {
// Do nothing
}
}
} else if ("x-pubsub#keywords".equals(field.getVariable())) {
values = field.getValues();
keyword = values.isEmpty() ? null : values.get(0);
} else {
fieldExists = false;
}
if (fieldExists) {
// Subscription has been configured so set the next state
if (node.getAccessModel().isAuthorizationRequired() && !node.isAdmin(owner)) {
state = State.pending;
} else {
state = State.subscribed;
}
}
}
if (savedToDB) {
// Update the subscription in the backend store
PubSubPersistenceManager.saveSubscription(node, this, false);
}
// Check if the service needs to subscribe or unsubscribe from the owner presence
if (!node.isPresenceBasedDelivery() && wasUsingPresence != !presenceStates.isEmpty()) {
if (presenceStates.isEmpty()) {
node.getService().presenceSubscriptionNotRequired(node, owner);
} else {
node.getService().presenceSubscriptionRequired(node, owner);
}
}
}
use of org.xmpp.forms.FormField in project Openfire by igniterealtime.
the class PendingSubscriptionsCommand method addStageInformation.
@Override
protected void addStageInformation(SessionData data, Element command) {
DataForm form = new DataForm(DataForm.Type.form);
form.setTitle(LocaleUtils.getLocalizedString("pubsub.command.pending-subscriptions.title"));
form.addInstruction(LocaleUtils.getLocalizedString("pubsub.command.pending-subscriptions.instruction"));
FormField formField = form.addField();
formField.setVariable("pubsub#node");
formField.setType(FormField.Type.list_single);
formField.setLabel(LocaleUtils.getLocalizedString("pubsub.command.pending-subscriptions.node"));
for (Node node : service.getNodes()) {
if (!node.isCollectionNode() && node.isAdmin(data.getOwner())) {
formField.addOption(null, node.getNodeID());
}
}
// Add the form to the command
command.add(form.getElement());
}
use of org.xmpp.forms.FormField in project Openfire by igniterealtime.
the class DefaultNodeConfiguration method getConfigurationForm.
public DataForm getConfigurationForm() {
DataForm form = new DataForm(DataForm.Type.form);
form.setTitle(LocaleUtils.getLocalizedString("pubsub.form.default.title"));
form.addInstruction(LocaleUtils.getLocalizedString("pubsub.form.default.instruction"));
// Add the form fields and configure them for edition
FormField formField = form.addField();
formField.setVariable("FORM_TYPE");
formField.setType(FormField.Type.hidden);
formField.addValue("http://jabber.org/protocol/pubsub#node_config");
formField = form.addField();
formField.setVariable("pubsub#subscribe");
formField.setType(FormField.Type.boolean_type);
formField.setLabel(LocaleUtils.getLocalizedString("pubsub.form.conf.subscribe"));
formField.addValue(subscriptionEnabled);
formField = form.addField();
formField.setVariable("pubsub#deliver_payloads");
formField.setType(FormField.Type.boolean_type);
formField.setLabel(LocaleUtils.getLocalizedString("pubsub.form.conf.deliver_payloads"));
formField.addValue(deliverPayloads);
formField = form.addField();
formField.setVariable("pubsub#notify_config");
formField.setType(FormField.Type.boolean_type);
formField.setLabel(LocaleUtils.getLocalizedString("pubsub.form.conf.notify_config"));
formField.addValue(notifyConfigChanges);
formField = form.addField();
formField.setVariable("pubsub#notify_delete");
formField.setType(FormField.Type.boolean_type);
formField.setLabel(LocaleUtils.getLocalizedString("pubsub.form.conf.notify_delete"));
formField.addValue(notifyDelete);
formField = form.addField();
formField.setVariable("pubsub#notify_retract");
formField.setType(FormField.Type.boolean_type);
formField.setLabel(LocaleUtils.getLocalizedString("pubsub.form.conf.notify_retract"));
formField.addValue(notifyRetract);
formField = form.addField();
formField.setVariable("pubsub#presence_based_delivery");
formField.setType(FormField.Type.boolean_type);
formField.setLabel(LocaleUtils.getLocalizedString("pubsub.form.conf.presence_based"));
formField.addValue(presenceBasedDelivery);
if (leaf) {
formField = form.addField();
formField.setVariable("pubsub#send_item_subscribe");
formField.setType(FormField.Type.boolean_type);
formField.setLabel(LocaleUtils.getLocalizedString("pubsub.form.conf.send_item_subscribe"));
formField.addValue(sendItemSubscribe);
formField = form.addField();
formField.setVariable("pubsub#persist_items");
formField.setType(FormField.Type.boolean_type);
formField.setLabel(LocaleUtils.getLocalizedString("pubsub.form.conf.persist_items"));
formField.addValue(persistPublishedItems);
formField = form.addField();
formField.setVariable("pubsub#max_items");
formField.setType(FormField.Type.text_single);
formField.setLabel(LocaleUtils.getLocalizedString("pubsub.form.conf.max_items"));
formField.addValue(maxPublishedItems);
formField = form.addField();
formField.setVariable("pubsub#max_payload_size");
formField.setType(FormField.Type.text_single);
formField.setLabel(LocaleUtils.getLocalizedString("pubsub.form.conf.max_payload_size"));
formField.addValue(maxPayloadSize);
}
formField = form.addField();
formField.setVariable("pubsub#access_model");
formField.setType(FormField.Type.list_single);
formField.setLabel(LocaleUtils.getLocalizedString("pubsub.form.conf.access_model"));
formField.addOption(null, AccessModel.authorize.getName());
formField.addOption(null, AccessModel.open.getName());
formField.addOption(null, AccessModel.presence.getName());
formField.addOption(null, AccessModel.roster.getName());
formField.addOption(null, AccessModel.whitelist.getName());
formField.addValue(accessModel.getName());
formField = form.addField();
formField.setVariable("pubsub#publish_model");
formField.setType(FormField.Type.list_single);
formField.setLabel(LocaleUtils.getLocalizedString("pubsub.form.conf.publish_model"));
formField.addOption(null, PublisherModel.publishers.getName());
formField.addOption(null, PublisherModel.subscribers.getName());
formField.addOption(null, PublisherModel.open.getName());
formField.addValue(publisherModel.getName());
formField = form.addField();
formField.setVariable("pubsub#language");
formField.setType(FormField.Type.text_single);
formField.setLabel(LocaleUtils.getLocalizedString("pubsub.form.conf.language"));
formField.addValue(language);
formField = form.addField();
formField.setVariable("pubsub#itemreply");
formField.setType(FormField.Type.list_single);
formField.setLabel(LocaleUtils.getLocalizedString("pubsub.form.conf.itemreply"));
if (replyPolicy != null) {
formField.addValue(replyPolicy.name());
}
if (!leaf) {
formField = form.addField();
formField.setVariable("pubsub#leaf_node_association_policy");
formField.setType(FormField.Type.list_single);
formField.setLabel(LocaleUtils.getLocalizedString("pubsub.form.conf.leaf_node_association"));
formField.addOption(null, CollectionNode.LeafNodeAssociationPolicy.all.name());
formField.addOption(null, CollectionNode.LeafNodeAssociationPolicy.owners.name());
formField.addOption(null, CollectionNode.LeafNodeAssociationPolicy.whitelist.name());
formField.addValue(associationPolicy.name());
formField = form.addField();
formField.setVariable("pubsub#leaf_nodes_max");
formField.setType(FormField.Type.text_single);
formField.setLabel(LocaleUtils.getLocalizedString("pubsub.form.conf.leaf_nodes_max"));
formField.addValue(maxLeafNodes);
}
return form;
}
Aggregations