use of org.jivesoftware.smackx.xdata.FormField in project Smack by igniterealtime.
the class HttpFileUploadManager method uploadServiceFrom.
private static UploadService uploadServiceFrom(DiscoverInfo discoverInfo) {
assert (containsHttpFileUploadNamespace(discoverInfo));
UploadService.Version version;
if (discoverInfo.containsFeature(NAMESPACE)) {
version = Version.v0_3;
} else if (discoverInfo.containsFeature(NAMESPACE_0_2)) {
version = Version.v0_2;
} else {
throw new AssertionError();
}
DomainBareJid address = discoverInfo.getFrom().asDomainBareJid();
DataForm dataForm = DataForm.from(discoverInfo);
if (dataForm == null) {
return new UploadService(address, version);
}
FormField field = dataForm.getField("max-file-size");
if (field == null) {
return new UploadService(address, version);
}
List<String> values = field.getValues();
if (values.isEmpty()) {
return new UploadService(address, version);
}
Long maxFileSize = Long.valueOf(values.get(0));
return new UploadService(address, version, maxFileSize);
}
use of org.jivesoftware.smackx.xdata.FormField in project Smack by igniterealtime.
the class Workgroup method joinQueue.
/**
* <p>Joins the workgroup queue to wait to be routed to an agent. After joining
* the queue, queue status events will be sent to indicate the user's position and
* estimated time left in the queue. Once joining the queue, there are three ways
* the user can leave the queue: <ul>
* <p/>
* <li>The user is routed to an agent, which triggers a GroupChat invitation.
* <li>The user asks to leave the queue by calling the {@link #departQueue} method.
* <li>A server error occurs, or an administrator explicitly removes the user
* from the queue.
* </ul>
* <p/>
* A user cannot request to join the queue again if already in the queue. Therefore,
* this method will throw an IllegalStateException if the user is already in the queue.<p>
* <p/>
* Some servers may be configured to require certain meta-data in order to
* join the queue.<p>
* <p/>
* The server tracks the conversations that a user has with agents over time. By
* default, that tracking is done using the user's JID. However, this is not always
* possible. For example, when the user is logged in anonymously using a web client.
* In that case the user ID might be a randomly generated value put into a persistent
* cookie or a username obtained via the session. When specified, that userID will
* be used instead of the user's JID to track conversations. The server will ignore a
* manually specified userID if the user's connection to the server is not anonymous.
*
* @param metadata metadata to create a dataform from.
* @param userID String that represents the ID of the user when using anonymous sessions
* or <tt>null</tt> if a userID should not be used.
* @throws XMPPException if an error occured joining the queue. An error may indicate
* that a connection failure occured or that the server explicitly rejected the
* request to join the queue.
* @throws SmackException
* @throws InterruptedException
*/
public void joinQueue(Map<String, Object> metadata, Jid userID) throws XMPPException, SmackException, InterruptedException {
// If already in the queue ignore the join request.
if (inQueue) {
throw new IllegalStateException("Already in queue " + workgroupJID);
}
// Build dataform from metadata
Form form = new Form(DataForm.Type.submit);
Iterator<String> iter = metadata.keySet().iterator();
while (iter.hasNext()) {
String name = iter.next();
String value = metadata.get(name).toString();
FormField field = new FormField(name);
field.setType(FormField.Type.text_single);
form.addField(field);
form.setAnswer(name, value);
}
joinQueue(form, userID);
}
use of org.jivesoftware.smackx.xdata.FormField in project Smack by igniterealtime.
the class ServiceAdministrationManager method addUser.
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.next(answerForm);
assert (command.isCompleted());
}
use of org.jivesoftware.smackx.xdata.FormField in project Smack by igniterealtime.
the class RetrieveFormFieldsTest method checkAddAdditionalFieldsStanza.
@Test
public void checkAddAdditionalFieldsStanza() throws Exception {
Method methodAddAdditionalFields = MamManager.class.getDeclaredMethod("addAdditionalFields", List.class, DataForm.class);
methodAddAdditionalFields.setAccessible(true);
DataForm dataForm = getNewMamForm();
List<FormField> additionalFields = new ArrayList<>();
FormField field1 = new FormField("urn:example:xmpp:free-text-search");
field1.setType(FormField.Type.text_single);
field1.addValue("Hi");
FormField field2 = new FormField("urn:example:xmpp:stanza-content");
field2.setType(FormField.Type.jid_single);
field2.addValue("Hi2");
additionalFields.add(field1);
additionalFields.add(field2);
methodAddAdditionalFields.invoke(mamManager, additionalFields, dataForm);
String dataFormResult = dataForm.toXML().toString();
Assert.assertEquals(dataFormResult, additionalFieldsStanza);
}
use of org.jivesoftware.smackx.xdata.FormField in project Smack by igniterealtime.
the class DataForm method toXML.
@Override
public XmlStringBuilder toXML() {
XmlStringBuilder buf = new XmlStringBuilder(this);
buf.attribute("type", getType());
buf.rightAngleBracket();
buf.optElement("title", getTitle());
for (String instruction : getInstructions()) {
buf.element("instructions", instruction);
}
// Append the list of fields returned from a search
if (getReportedData() != null) {
buf.append(getReportedData().toXML());
}
// Loop through all the items returned from a search and append them to the string buffer
for (Item item : getItems()) {
buf.append(item.toXML());
}
// Loop through all the form fields and append them to the string buffer
for (FormField field : getFields()) {
buf.append(field.toXML());
}
for (Element element : extensionElements) {
buf.append(element.toXML());
}
buf.closeElement(this);
return buf;
}
Aggregations