this.answerForm = configForm.createAnswerForm(); for (FormField field : configForm.getFields()) { if (field.getType() == FormField.Type.hidden || StringUtils.isNullOrEmpty(field.getVariable())) { continue; answerForm.setDefaultAnswer(field.getVariable()); if (answerForm.hasField(MUC_ROOMCONFIG_ROOMOWNERS)) { List<CharSequence> ownerStrings = answerForm.getField(MUC_ROOMCONFIG_ROOMOWNERS).getValues(); owners = new ArrayList<>(ownerStrings.size()); JidUtil.jidsFrom(ownerStrings, owners, null);
if (!isFormType()) { throw new IllegalStateException("Only forms of type \"form\" could be answered"); Form form = new Form(DataForm.Type.submit); for (FormField field : getFields()) { FormField newField = new FormField(field.getVariable()); newField.setType(field.getType()); form.addField(newField); form.setAnswer(field.getVariable(), values);
/** * Create a decorator from an existing {@link Form} for node configuration. * Typically, this can be used to create a decorator for an answer form * by using the result of {@link #createAnswerForm()} as the input parameter. * * @param nodeConfigForm */ public ConfigureForm(Form nodeConfigForm) { super(nodeConfigForm.getDataFormToSend()); }
/** * 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); }
/** * Set the room secret, aka the room password. If set and enabled, the password is required to * join the room. Note that this does only set it by does not enable password protection. Use * {@link #setAndEnablePassword(String)} to set a password and make the room protected. * * @param secret the secret/password. * @return a reference to this object. * @throws MucConfigurationNotSupportedException */ public MucConfigFormManager setRoomSecret(String secret) throws MucConfigurationNotSupportedException { if (!answerForm.hasField(MUC_ROOMCONFIG_ROOMSECRET)) { throw new MucConfigurationNotSupportedException(MUC_ROOMCONFIG_ROOMSECRET); } answerForm.setAnswer(MUC_ROOMCONFIG_ROOMSECRET, secret); return this; }
/** * 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)); }
erSearchManager search = new UserSearchManager(connection); Form searchForm = search.getSearchForm("search."+connection.getServiceName()); Form answerForm = searchForm.createAnswerForm(); answerForm.setAnswer("Username", true); answerForm.setAnswer("search", name);//Here username must be added name replace by "amith"
@SmackIntegrationTest public void testFilloutForm() throws NotConnectedException, InterruptedException { Form formToSend = new Form(DataForm.Type.form); formToSend.setInstructions( "Fill out this form to report your case.\nThe case will be created automatically."); formToSend.setTitle("Case configurations"); formToSend.addField(field); formToSend.addField(field); formToSend.addField(field); formToSend.addField(field); formToSend.addField(field); formToSend.addField(field); msg.addExtension(formToSend.getDataFormToSend()); Form formToRespond = Form.getFormFrom(msg2); assertNotNull(formToRespond); assertNotNull(formToRespond.getField("name")); assertNotNull(formToRespond.getField("description")); Form completedForm = formToRespond.createAnswerForm(); assertNotNull(completedForm.getField("hidden_var"));
/** * Set if the room is members only. Rooms are not members only per default. * * @param isMembersOnly if the room should be members only. * @return a reference to this object. * @throws MucConfigurationNotSupportedException */ public MucConfigFormManager setMembersOnly(boolean isMembersOnly) throws MucConfigurationNotSupportedException { if (!supportsMembersOnly()) { throw new MucConfigurationNotSupportedException(MUC_ROOMCONFIG_MEMBERSONLY); } answerForm.setAnswer(MUC_ROOMCONFIG_MEMBERSONLY, isMembersOnly); return this; }
Form submitForm = form.createAnswerForm(); List<FormField> fields = form.getFields(); for (int i = 0; fields != null && i < fields.size(); i++) { if (FormField.Type.hidden != fields.get(i).getType() && fields.get(i).getVariable() != null) { submitForm.setDefaultAnswer(fields.get(i).getVariable()); submitForm.setAnswer("muc#roomconfig_roomowners", owners); submitForm.setAnswer("muc#roomconfig_persistentroom", true); submitForm.setAnswer("muc#roomconfig_membersonly", false); submitForm.setAnswer("muc#roomconfig_allowinvites", true); if (password != null && password.length() != 0) { submitForm.setAnswer("muc#roomconfig_passwordprotectedroom", true); submitForm.setAnswer("muc#roomconfig_roomsecret", password); submitForm.setAnswer("muc#roomconfig_enablelogging", true); submitForm.setAnswer("x-muc#roomconfig_reservednick", true); submitForm.setAnswer("x-muc#roomconfig_canchangenick", false); submitForm.setAnswer("x-muc#roomconfig_registration", false);
Form answer = config.createAnswerForm(); FormField whois = answer.getField(whoisFieldName); if (whois == null) answer.addField(whois);
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()); }
@Override protected FormNode createReturnExtension(String currentElement, String currentNamespace, Map<String, String> attributeMap, List<? extends ExtensionElement> content) { return new FormNode(FormNodeType.valueOfFromElementName(currentElement, currentNamespace), attributeMap.get("node"), new Form((DataForm) content.iterator().next())); } }
for ( final FormField formfield : form.getFields() ) { JLabel label = new JLabel(formfield.getLabel()); FormField.Type type = formfield.getType(); updatebutton.addActionListener( e -> { dialog.dispose(); sendAnswerForm(form.createAnswerForm(), chat); } );
for ( final FormField field : form.getFields() ) { String variable = field.getVariable(); String label = field.getLabel(); submitForm.setAnswer( variable, isSelected ); addField(label, box, variable); type.equals(FormField.Type.jid_single)) { String value = valueList.get(0).toString(); submitForm.setAnswer( variable, value ); addField(label, new JTextField(value), variable); submitForm.setAnswer( variable, valueList ); addField(label, new JTextArea(buf.toString()), variable); submitForm.setAnswer( variable, value ); String defaultValue = valueList.get(0).toString(); box.setSelectedItem(defaultValue); submitForm.setAnswer( variable, valueList ); checkBoxList.addCheckBox(new JCheckBox(optionLabel, values.contains(optionValue)), optionValue); submitForm.setAnswer( variable, valueList ); addField(label, checkBoxList, variable);
/** * 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; }
private String getItemsToSearch() { StringBuilder buf = new StringBuilder(); if (form == null) { form = Form.getFormFrom(this); } if (form == null) { return ""; } for (FormField field : form.getFields()) { String name = field.getVariable(); String value = getSingleValue(field); if (value.trim().length() > 0) { buf.append('<').append(name).append('>').append(value).append("</").append(name).append('>'); } } return buf.toString(); }
/** * Returns the form for all search fields supported by the search service. * * @param con the current XMPPConnection. * @param searchService the search service to use. (ex. search.jivesoftware.com) * @return the search form received by the server. * @throws XMPPErrorException * @throws NoResponseException * @throws NotConnectedException * @throws InterruptedException */ public Form getSearchForm(XMPPConnection con, DomainBareJid searchService) throws NoResponseException, XMPPErrorException, NotConnectedException, InterruptedException { UserSearch search = new UserSearch(); search.setType(IQ.Type.get); search.setTo(searchService); IQ response = con.createStanzaCollectorAndSend(search).nextResultOrThrow(); return Form.getFormFrom(response); }
/** * Returns a DataForm that serves to send this Form to the server. If the form is of type * submit, it may contain fields with no value. These fields will be removed since they only * exist to assist the user while editing/completing the form in a UI. * * @return the wrapped DataForm. */ public DataForm getDataFormToSend() { if (isSubmitType()) { // Create a new DataForm that contains only the answered fields DataForm dataFormToSend = new DataForm(getType()); for (FormField field : getFields()) { if (!field.getValues().isEmpty()) { dataFormToSend.addField(field); } } return dataFormToSend; } return dataForm; }