/** * Sets a new Object value to a given form's field. In fact, the object representation * (i.e. #toString) will be the actual value of the field.<p> * * If the value to set to the field is not a basic type (e.g. String, boolean, int, etc.) you * will need to use {@link #setAnswer(String, String))} where the String value is the * String representation of the object.<p> * * Before setting the new value to the field we will check if the form is of type submit. If * the form isn't of type submit means that it's not possible to complete the form and an * exception will be thrown. * * @param field the form field that was completed. * @param value the Object value that was answered. The object representation will be the * actual value. * @throws IllegalStateException if the form is not of type "submit". */ private void setAnswer(FormField field, Object value) { if (!isSubmitType()) { throw new IllegalStateException("Cannot set an answer if the form is not of type " + "\"submit\""); } field.resetValues(); field.addValue(value.toString()); }
/** * Sets a new Object value to a given form's field. In fact, the object representation * (i.e. #toString) will be the actual value of the field.<p> * * If the value to set to the field is not a basic type (e.g. String, boolean, int, etc.) you * will need to use {@link #setAnswer(String, String))} where the String value is the * String representation of the object.<p> * * Before setting the new value to the field we will check if the form is of type submit. If * the form isn't of type submit means that it's not possible to complete the form and an * exception will be thrown. * * @param field the form field that was completed. * @param value the Object value that was answered. The object representation will be the * actual value. * @throws IllegalStateException if the form is not of type "submit". */ private void setAnswer(FormField field, Object value) { if (!isSubmitType()) { throw new IllegalStateException("Cannot set an answer if the form is not of type " + "\"submit\""); } field.resetValues(); field.addValue(value.toString()); }
/** * Sets a new Object value to a given form's field. In fact, the object representation * (i.e. #toString) will be the actual value of the field.<p> * * If the value to set to the field is not a basic type (e.g. String, boolean, int, etc.) you * will need to use {@link #setAnswer(String, String))} where the String value is the * String representation of the object.<p> * * Before setting the new value to the field we will check if the form is of type submit. If * the form isn't of type submit means that it's not possible to complete the form and an * exception will be thrown. * * @param field the form field that was completed. * @param value the Object value that was answered. The object representation will be the * actual value. * @throws IllegalStateException if the form is not of type "submit". */ private void setAnswer(FormField field, Object value) { if (!isSubmitType()) { throw new IllegalStateException("Cannot set an answer if the form is not of type " + "\"submit\""); } field.resetValues(); field.addValue(value.toString()); }
/** * Sets a new Object value to a given form's field. In fact, the object representation * (i.e. #toString) will be the actual value of the field.<p> * * If the value to set to the field is not a basic type (e.g. String, boolean, int, etc.) you * will need to use {@link #setAnswer(String, String))} where the String value is the * String representation of the object.<p> * * Before setting the new value to the field we will check if the form is of type submit. If * the form isn't of type submit means that it's not possible to complete the form and an * exception will be thrown. * * @param field the form field that was completed. * @param value the Object value that was answered. The object representation will be the * actual value. * @throws IllegalStateException if the form is not of type "submit". */ private void setAnswer(FormField field, Object value) { if (!isSubmitType()) { throw new IllegalStateException("Cannot set an answer if the form is not of type " + "\"submit\""); } field.resetValues(); field.addValue(value.toString()); }
/** * 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 (Iterator it = field.getValues(); it.hasNext();) { field.addValue((String) it.next()); } } else { throw new IllegalArgumentException("Couldn't find a field for the specified variable."); } }
/** * 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 (Iterator<String> it = field.getValues(); it.hasNext();) { field.addValue(it.next()); } } else { throw new IllegalArgumentException("Couldn't find a field for the specified variable."); } }
/** * 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 (Iterator<String> it = field.getValues(); it.hasNext();) { field.addValue(it.next()); } } else { throw new IllegalArgumentException("Couldn't find a field for the specified variable."); } }
private FormField parseField(XmlPullParser parser) throws Exception { boolean done = false; FormField formField = new FormField(parser.getAttributeValue("", "var")); formField.setLabel(parser.getAttributeValue("", "label")); formField.setType(parser.getAttributeValue("", "type")); while (!done) { int eventType = parser.next(); if (eventType == XmlPullParser.START_TAG) { if (parser.getName().equals("desc")) { formField.setDescription(parser.nextText()); } else if (parser.getName().equals("value")) { formField.addValue(parser.nextText()); } else if (parser.getName().equals("required")) { formField.setRequired(true); } else if (parser.getName().equals("option")) { formField.addOption(parseOption(parser)); } } else if (eventType == XmlPullParser.END_TAG) { if (parser.getName().equals("field")) { done = true; } } } return formField; }
/** * 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 (Iterator<String> it = field.getValues(); it.hasNext();) { field.addValue(it.next()); } } else { throw new IllegalArgumentException("Couldn't find a field for the specified variable."); } }
private FormField parseField(XmlPullParser parser) throws Exception { boolean done = false; FormField formField = new FormField(parser.getAttributeValue("", "var")); formField.setLabel(parser.getAttributeValue("", "label")); formField.setType(parser.getAttributeValue("", "type")); while (!done) { int eventType = parser.next(); if (eventType == XmlPullParser.START_TAG) { if (parser.getName().equals("desc")) { formField.setDescription(parser.nextText()); } else if (parser.getName().equals("value")) { formField.addValue(parser.nextText()); } else if (parser.getName().equals("required")) { formField.setRequired(true); } else if (parser.getName().equals("option")) { formField.addOption(parseOption(parser)); } } else if (eventType == XmlPullParser.END_TAG) { if (parser.getName().equals("field")) { done = true; } } } return formField; }
private FormField parseField(XmlPullParser parser) throws Exception { boolean done = false; FormField formField = new FormField(parser.getAttributeValue("", "var")); formField.setLabel(parser.getAttributeValue("", "label")); formField.setType(parser.getAttributeValue("", "type")); while (!done) { int eventType = parser.next(); if (eventType == XmlPullParser.START_TAG) { if (parser.getName().equals("desc")) { formField.setDescription(parser.nextText()); } else if (parser.getName().equals("value")) { formField.addValue(parser.nextText()); } else if (parser.getName().equals("required")) { formField.setRequired(true); } else if (parser.getName().equals("option")) { formField.addOption(parseOption(parser)); } } else if (eventType == XmlPullParser.END_TAG) { if (parser.getName().equals("field")) { done = true; } } } return formField; }
private FormField parseField(XmlPullParser parser) throws Exception { boolean done = false; FormField formField = new FormField(parser.getAttributeValue("", "var")); formField.setLabel(parser.getAttributeValue("", "label")); formField.setType(parser.getAttributeValue("", "type")); while (!done) { int eventType = parser.next(); if (eventType == XmlPullParser.START_TAG) { if (parser.getName().equals("desc")) { formField.setDescription(parser.nextText()); } else if (parser.getName().equals("value")) { formField.addValue(parser.nextText()); } else if (parser.getName().equals("required")) { formField.setRequired(true); } else if (parser.getName().equals("option")) { formField.addOption(parseOption(parser)); } } else if (eventType == XmlPullParser.END_TAG) { if (parser.getName().equals("field")) { done = true; } } } return formField; }
/** * Creates the initiation acceptance packet to forward to the stream * initiator. * * @param streamInitiationOffer The offer from the stream initiator to connect for a stream. * @param namespaces The namespace that relates to the accepted means of transfer. * @return The response to be forwarded to the initiator. */ public StreamInitiation createInitiationAccept( StreamInitiation streamInitiationOffer, String[] namespaces) { StreamInitiation response = new StreamInitiation(); response.setTo(streamInitiationOffer.getFrom()); response.setFrom(streamInitiationOffer.getTo()); response.setType(IQ.Type.RESULT); response.setPacketID(streamInitiationOffer.getPacketID()); DataForm form = new DataForm(Form.TYPE_SUBMIT); FormField field = new FormField( FileTransferNegotiator.STREAM_DATA_FIELD_NAME); for (String namespace : namespaces) { field.addValue(namespace); } form.addField(field); response.setFeatureNegotiationForm(form); return response; }
/** * Creates the initiation acceptance packet to forward to the stream * initiator. * * @param streamInitiationOffer The offer from the stream initiator to connect for a stream. * @param namespaces The namespace that relates to the accepted means of transfer. * @return The response to be forwarded to the initiator. */ public StreamInitiation createInitiationAccept( StreamInitiation streamInitiationOffer, String[] namespaces) { StreamInitiation response = new StreamInitiation(); response.setTo(streamInitiationOffer.getFrom()); response.setFrom(streamInitiationOffer.getTo()); response.setType(IQ.Type.RESULT); response.setPacketID(streamInitiationOffer.getPacketID()); DataForm form = new DataForm(Form.TYPE_SUBMIT); FormField field = new FormField( FileTransferNegotiator.STREAM_DATA_FIELD_NAME); for (String namespace : namespaces) { field.addValue(namespace); } form.addField(field); response.setFeatureNegotiationForm(form); return response; }
/** * Creates the initiation acceptance packet to forward to the stream * initiator. * * @param streamInitiationOffer The offer from the stream initatior to connect for a stream. * @param namespaces The namespace that relates to the accepted means of transfer. * @return The response to be forwarded to the initator. */ public StreamInitiation createInitiationAccept( StreamInitiation streamInitiationOffer, String [] namespaces) { StreamInitiation response = new StreamInitiation(); response.setTo(streamInitiationOffer.getFrom()); response.setFrom(streamInitiationOffer.getTo()); response.setType(IQ.Type.RESULT); response.setPacketID(streamInitiationOffer.getPacketID()); DataForm form = new DataForm(Form.TYPE_SUBMIT); FormField field = new FormField( FileTransferNegotiator.STREAM_DATA_FIELD_NAME); for (int i = 0; i < namespaces.length; i++) { field.addValue(namespaces[i]); } form.addField(field); response.setFeatureNegotiationForm(form); return response; }
/** * Creates the initiation acceptance packet to forward to the stream * initiator. * * @param streamInitiationOffer The offer from the stream initiator to connect for a stream. * @param namespaces The namespace that relates to the accepted means of transfer. * @return The response to be forwarded to the initiator. */ public StreamInitiation createInitiationAccept( StreamInitiation streamInitiationOffer, String[] namespaces) { StreamInitiation response = new StreamInitiation(); response.setTo(streamInitiationOffer.getFrom()); response.setFrom(streamInitiationOffer.getTo()); response.setType(IQ.Type.RESULT); response.setPacketID(streamInitiationOffer.getPacketID()); DataForm form = new DataForm(Form.TYPE_SUBMIT); FormField field = new FormField( FileTransferNegotiator.STREAM_DATA_FIELD_NAME); for (String namespace : namespaces) { field.addValue(namespace); } form.addField(field); response.setFeatureNegotiationForm(form); return response; }