/** * Sets a new boolean value to a given form's field. The field whose variable matches the * requested variable will be completed with the specified value. If no field could be found * for the specified variable then an exception will be raised. * * @param variable the variable name that was completed. * @param value the boolean value that was answered. * @throws IllegalStateException if the form is not of type "submit". * @throws IllegalArgumentException if the form does not include the specified variable or * if the answer type does not correspond with the field type. */ public void setAnswer(String variable, boolean value) { FormField field = getField(variable); if (field == null) { throw new IllegalArgumentException("Field not found for the specified variable name."); } if (field.getType() != FormField.Type.bool) { throw new IllegalArgumentException("This field is not of type boolean."); } setAnswer(field, Boolean.toString(value)); }
List<CharSequence> ownerStrings = answerForm.getField(MUC_ROOMCONFIG_ROOMOWNERS).getValues(); owners = new ArrayList<>(ownerStrings.size()); JidUtil.jidsFrom(ownerStrings, owners, null);
/** * Sets a new int value to a given form's field. The field whose variable matches the * requested variable will be completed with the specified value. If no field could be found * for the specified variable then an exception will be raised. * * @param variable the variable name that was completed. * @param value the int value that was answered. * @throws IllegalStateException if the form is not of type "submit". * @throws IllegalArgumentException if the form does not include the specified variable or * if the answer type does not correspond with the field type. */ public void setAnswer(String variable, int value) { FormField field = getField(variable); if (field == null) { throw new IllegalArgumentException("Field not found for the specified variable name."); } validateThatFieldIsText(field); setAnswer(field, value); }
/** * Sets a new long value to a given form's field. The field whose variable matches the * requested variable will be completed with the specified value. If no field could be found * for the specified variable then an exception will be raised. * * @param variable the variable name that was completed. * @param value the long value that was answered. * @throws IllegalStateException if the form is not of type "submit". * @throws IllegalArgumentException if the form does not include the specified variable or * if the answer type does not correspond with the field type. */ public void setAnswer(String variable, long value) { FormField field = getField(variable); if (field == null) { throw new IllegalArgumentException("Field not found for the specified variable name."); } validateThatFieldIsText(field); setAnswer(field, value); }
/** * Sets a new float value to a given form's field. The field whose variable matches the * requested variable will be completed with the specified value. If no field could be found * for the specified variable then an exception will be raised. * * @param variable the variable name that was completed. * @param value the float value that was answered. * @throws IllegalStateException if the form is not of type "submit". * @throws IllegalArgumentException if the form does not include the specified variable or * if the answer type does not correspond with the field type. */ public void setAnswer(String variable, float value) { FormField field = getField(variable); if (field == null) { throw new IllegalArgumentException("Field not found for the specified variable name."); } validateThatFieldIsText(field); setAnswer(field, value); }
/** * Sets a new double value to a given form's field. The field whose variable matches the * requested variable will be completed with the specified value. If no field could be found * for the specified variable then an exception will be raised. * * @param variable the variable name that was completed. * @param value the double value that was answered. * @throws IllegalStateException if the form is not of type "submit". * @throws IllegalArgumentException if the form does not include the specified variable or * if the answer type does not correspond with the field type. */ public void setAnswer(String variable, double value) { FormField field = getField(variable); if (field == null) { throw new IllegalArgumentException("Field not found for the specified variable name."); } validateThatFieldIsText(field); setAnswer(field, value); }
FormField field = getField(variable); if (field == null) { throw new IllegalArgumentException("Field not found for the specified variable name.");
public void addUser(final EntityBareJid userJid, final String password) throws NoResponseException, XMPPErrorException, NotConnectedException, InterruptedException { RemoteCommand command = addUser(); command.execute(); Form answerForm = command.getForm().createAnswerForm(); FormField accountJidField = answerForm.getField("accountjid"); accountJidField.addValue(userJid.toString()); FormField passwordField = answerForm.getField("password"); passwordField.addValue(password); FormField passwordVerifyField = answerForm.getField("password-verify"); passwordVerifyField.addValue(password); command.execute(answerForm); assert (command.isCompleted()); }
/** * Sets the default value as the value of a given form's field. The field whose variable matches * the requested variable will be completed with its default value. If no field could be found * for the specified variable then an exception will be raised. * * @param variable the variable to complete with its default value. * @throws IllegalStateException if the form is not of type "submit". * @throws IllegalArgumentException if the form does not include the specified variable. */ public void setDefaultAnswer(String variable) { if (!isSubmitType()) { throw new IllegalStateException("Cannot set an answer if the form is not of type " + "\"submit\""); } FormField field = getField(variable); if (field != null) { // Clear the old values field.resetValues(); // Set the default value for (CharSequence value : field.getValues()) { field.addValue(value); } } else { throw new IllegalArgumentException("Couldn't find a field for the specified variable."); } }
"\"submit\""); FormField field = getField(variable); if (field != null) {
/** * Returns the number of offline messages for the user of the connection. * * @return the number of offline messages for the user of the connection. * @throws XMPPErrorException If the user is not allowed to make this request or the server does * not support offline message retrieval. * @throws NoResponseException if there was no response from the server. * @throws NotConnectedException * @throws InterruptedException */ public int getMessageCount() throws NoResponseException, XMPPErrorException, NotConnectedException, InterruptedException { DiscoverInfo info = ServiceDiscoveryManager.getInstanceFor(connection).discoverInfo(null, namespace); Form extendedInfo = Form.getFormFrom(info); if (extendedInfo != null) { String value = extendedInfo.getField("number_of_messages").getFirstValue(); return Integer.parseInt(value); } return 0; }
FormField descField = form.getField("muc#roominfo_description"); if (descField != null && !descField.getValues().isEmpty()) { FormField subjField = form.getField("muc#roominfo_subject"); if (subjField != null && !subjField.getValues().isEmpty()) { subject = subjField.getFirstValue(); FormField occCountField = form.getField("muc#roominfo_occupants"); if (occCountField != null && !occCountField.getValues().isEmpty()) { occupantsCount = Integer.parseInt(occCountField.getFirstValue()); FormField maxhistoryfetchField = form.getField("muc#maxhistoryfetch"); if (maxhistoryfetchField != null && !maxhistoryfetchField.getValues().isEmpty()) { maxhistoryfetch = Integer.parseInt(maxhistoryfetchField.getFirstValue()); FormField contactJidField = form.getField("muc#roominfo_contactjid"); if (contactJidField != null && !contactJidField.getValues().isEmpty()) { List<CharSequence> contactJidValues = contactJidField.getValues(); FormField langField = form.getField("muc#roominfo_lang"); if (langField != null && !langField.getValues().isEmpty()) { lang = langField.getFirstValue(); FormField ldapgroupField = form.getField("muc#roominfo_ldapgroup"); if (ldapgroupField != null && !ldapgroupField.getValues().isEmpty()) { ldapgroup = ldapgroupField.getFirstValue(); FormField subjectmodField = form.getField("muc#roominfo_subjectmod"); if (subjectmodField != null && !subjectmodField.getValues().isEmpty()) {
/** * Creates a node with specified configuration. * * Note: This is the only way to create a collection node. * * @param nodeId The name of the node, which must be unique within the * pubsub service * @param config The configuration for the node * @return The node that was created * @throws XMPPErrorException * @throws NoResponseException * @throws NotConnectedException * @throws InterruptedException */ public Node createNode(String nodeId, Form config) throws NoResponseException, XMPPErrorException, NotConnectedException, InterruptedException { PubSub request = PubSub.createPubsubPacket(pubSubService, Type.set, new NodeExtension(PubSubElementType.CREATE, nodeId)); boolean isLeafNode = true; if (config != null) { request.addExtension(new FormNode(FormNodeType.CONFIGURE, config)); FormField nodeTypeField = config.getField(ConfigureNodeFields.node_type.getFieldName()); if (nodeTypeField != null) isLeafNode = nodeTypeField.getValues().get(0).toString().equals(NodeType.leaf.toString()); } // Errors will cause exceptions in getReply, so it only returns // on success. sendPubsubPacket(request); Node newNode = isLeafNode ? new LeafNode(this, nodeId) : new CollectionNode(this, nodeId); nodeMap.put(newNode.getId(), newNode); return newNode; }
public void deleteUser(Set<EntityBareJid> jidsToDelete) throws NoResponseException, XMPPErrorException, NotConnectedException, InterruptedException { RemoteCommand command = deleteUser(); command.execute(); Form answerForm = command.getForm().createAnswerForm(); FormField accountJids = answerForm.getField("accountjids"); accountJids.addValues(JidUtil.toStringList(jidsToDelete)); command.execute(answerForm); assert (command.isCompleted()); } }
assertNotNull(formToRespond.getField("name")); assertNotNull(formToRespond.getField("description")); assertNotNull(completedForm.getField("hidden_var")); assertNotNull(completedForm.getField("name")); assertNotNull(completedForm.getField("description")); assertEquals( completedForm.getField("name").getValues().get(0).toString(), "Credit card number invalid"); assertNotNull(completedForm.getField("time")); assertNotNull(completedForm.getField("age")); assertEquals("The age is bad", "20", completedForm.getField("age").getValues().get(0).toString());
FormField whois = answer.getField(whoisFieldName); if (whois == null)