else if (DataForm.Type.submit.equals(completedForm.getType())) {
List<String> values;
String booleanValue;
// Get the new list of owners
FormField ownerField = completedForm.getField("pubsub#owner");
boolean ownersSent = ownerField != null;
List<JID> owners = new ArrayList<JID>();
if (ownersSent) {
for (String value : ownerField.getValues()) {
try {
owners.add(new JID(value));
}
catch (Exception e) {
// Do nothing
}
}
}
// Answer a not-acceptable error if all the current owners will be removed
if (ownersSent && owners.isEmpty()) {
throw new NotAcceptableException();
}
for (FormField field : completedForm.getFields()) {
if ("FORM_TYPE".equals(field.getVariable())) {
// Do nothing
}
else if ("pubsub#deliver_payloads".equals(field.getVariable())) {
values = field.getValues();
booleanValue = (values.size() > 0 ? values.get(0) : "1");
deliverPayloads = "1".equals(booleanValue);
}
else if ("pubsub#notify_config".equals(field.getVariable())) {
values = field.getValues();
booleanValue = (values.size() > 0 ? values.get(0) : "1");
notifyConfigChanges = "1".equals(booleanValue);
}
else if ("pubsub#notify_delete".equals(field.getVariable())) {
values = field.getValues();
booleanValue = (values.size() > 0 ? values.get(0) : "1");
notifyDelete = "1".equals(booleanValue);
}
else if ("pubsub#notify_retract".equals(field.getVariable())) {
values = field.getValues();
booleanValue = (values.size() > 0 ? values.get(0) : "1");
notifyRetract = "1".equals(booleanValue);
}
else if ("pubsub#presence_based_delivery".equals(field.getVariable())) {
values = field.getValues();
booleanValue = (values.size() > 0 ? values.get(0) : "1");
presenceBasedDelivery = "1".equals(booleanValue);
}
else if ("pubsub#subscribe".equals(field.getVariable())) {
values = field.getValues();
booleanValue = (values.size() > 0 ? values.get(0) : "1");
subscriptionEnabled = "1".equals(booleanValue);
}
else if ("pubsub#subscription_required".equals(field.getVariable())) {
// TODO Replace this variable for the one defined in the JEP (once one is defined)
values = field.getValues();
booleanValue = (values.size() > 0 ? values.get(0) : "1");
subscriptionConfigurationRequired = "1".equals(booleanValue);
}
else if ("pubsub#type".equals(field.getVariable())) {
values = field.getValues();
payloadType = values.size() > 0 ? values.get(0) : " ";
}
else if ("pubsub#body_xslt".equals(field.getVariable())) {
values = field.getValues();
bodyXSLT = values.size() > 0 ? values.get(0) : " ";
}
else if ("pubsub#dataform_xslt".equals(field.getVariable())) {
values = field.getValues();
dataformXSLT = values.size() > 0 ? values.get(0) : " ";
}
else if ("pubsub#access_model".equals(field.getVariable())) {
values = field.getValues();
if (values.size() > 0) {
accessModel = AccessModel.valueOf(values.get(0));
}
}
else if ("pubsub#publish_model".equals(field.getVariable())) {
values = field.getValues();
if (values.size() > 0) {
publisherModel = PublisherModel.valueOf(values.get(0));
}
}
else if ("pubsub#roster_groups_allowed".equals(field.getVariable())) {
// Get the new list of roster group(s) allowed to subscribe and retrieve items
rosterGroupsAllowed = new ArrayList<String>();
for (String value : field.getValues()) {
addAllowedRosterGroup(value);
}
}
else if ("pubsub#contact".equals(field.getVariable())) {
// Get the new list of users that may be contacted with questions
contacts = new ArrayList<JID>();
for (String value : field.getValues()) {
try {
addContact(new JID(value));
}
catch (Exception e) {
// Do nothing
}
}
}
else if ("pubsub#description".equals(field.getVariable())) {
values = field.getValues();
description = values.size() > 0 ? values.get(0) : " ";
}
else if ("pubsub#language".equals(field.getVariable())) {
values = field.getValues();
language = values.size() > 0 ? values.get(0) : " ";
}
else if ("pubsub#title".equals(field.getVariable())) {
values = field.getValues();
name = values.size() > 0 ? values.get(0) : " ";
}
else if ("pubsub#itemreply".equals(field.getVariable())) {
values = field.getValues();
if (values.size() > 0) {
replyPolicy = ItemReplyPolicy.valueOf(values.get(0));
}
}
else if ("pubsub#replyroom".equals(field.getVariable())) {
// Get the new list of multi-user chat rooms to specify for replyroom
replyRooms = new ArrayList<JID>();
for (String value : field.getValues()) {
try {
addReplyRoom(new JID(value));
}
catch (Exception e) {
// Do nothing
}
}
}
else if ("pubsub#replyto".equals(field.getVariable())) {
// Get the new list of JID(s) to specify for replyto
replyTo = new ArrayList<JID>();
for (String value : field.getValues()) {
try {
addReplyTo(new JID(value));
}
catch (Exception e) {
// Do nothing
}
}
}
else {
// Let subclasses be configured by specified fields
configure(field);
}
}
// Set new list of owners of the node
if (ownersSent) {
// Calculate owners to remove and remove them from the DB
Collection<JID> oldOwners = getOwners();
oldOwners.removeAll(owners);
for (JID jid : oldOwners) {
removeOwner(jid);
}
// Calculate new owners and add them to the DB
owners.removeAll(getOwners());
for (JID jid : owners) {
addOwner(jid);
}
}
// TODO Before removing owner or admin check if user was changed from admin to owner or vice versa. This way his susbcriptions are not going to be deleted.
// Set the new list of publishers
FormField publisherField = completedForm.getField("pubsub#publisher");
if (publisherField != null) {
// New list of publishers was sent to update publishers of the node
List<JID> publishers = new ArrayList<JID>();
for (String value : publisherField.getValues()) {
try {
publishers.add(new JID(value));
}
catch (Exception e) {
// Do nothing