本文整理汇总了Java中org.jivesoftware.smackx.xdata.Form类的典型用法代码示例。如果您正苦于以下问题:Java Form类的具体用法?Java Form怎么用?Java Form使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
Form类属于org.jivesoftware.smackx.xdata包,在下文中一共展示了Form类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: executeAction
import org.jivesoftware.smackx.xdata.Form; //导入依赖的package包/类
/**
* Executes the <code>action</code> with the <code>form</code>.
* The action could be any of the available actions. The form must
* be the answer of the previous stage. It can be <tt>null</tt> if it is the first stage.
*
* @param action the action to execute.
* @param form the form with the information.
* @throws XMPPErrorException if there is a problem executing the command.
* @throws NoResponseException if there was no response from the server.
* @throws NotConnectedException
*/
private void executeAction(Action action, Form form) throws NoResponseException, XMPPErrorException, NotConnectedException {
// TODO: Check that all the required fields of the form were filled, if
// TODO: not throw the corresponding exeption. This will make a faster response,
// TODO: since the request is stoped before it's sent.
AdHocCommandData data = new AdHocCommandData();
data.setType(IQ.Type.set);
data.setTo(getOwnerJID());
data.setNode(getNode());
data.setSessionID(sessionID);
data.setAction(action);
if (form != null) {
data.setForm(form.getDataFormToSend());
}
AdHocCommandData responseData = (AdHocCommandData) connection.createPacketCollectorAndSend(
data).nextResultOrThrow();
this.sessionID = responseData.getSessionID();
super.setData(responseData);
}
示例2: createNode
import org.jivesoftware.smackx.xdata.Form; //导入依赖的package包/类
/**
* Creates a node with specified configuration.
*
* Note: This is the only way to create a collection node.
*
* @param name 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
*/
public Node createNode(String name, Form config) throws NoResponseException, XMPPErrorException, NotConnectedException
{
PubSub request = PubSub.createPubsubPacket(to, Type.set, new NodeExtension(PubSubElementType.CREATE, name), null);
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).equals(NodeType.leaf.toString());
}
// Errors will cause exceptions in getReply, so it only returns
// on success.
sendPubsubPacket(con, request);
Node newNode = isLeafNode ? new LeafNode(con, name) : new CollectionNode(con, name);
newNode.setTo(to);
nodeMap.put(newNode.getId(), newNode);
return newNode;
}
示例3: getItemsToSearch
import org.jivesoftware.smackx.xdata.Form; //导入依赖的package包/类
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();
}
示例4: prepareKeyPacket
import org.jivesoftware.smackx.xdata.Form; //导入依赖的package包/类
private Stanza prepareKeyPacket() {
String privatekey = Base64.encodeToString(mPrivateKeyData, Base64.NO_WRAP);
Registration iq = new Registration();
iq.setType(IQ.Type.set);
iq.setTo(getConnection().getServiceName());
Form form = new Form(DataForm.Type.submit);
// form type: register#privatekey
FormField type = new FormField("FORM_TYPE");
type.setType(FormField.Type.hidden);
type.addValue("http://kontalk.org/protocol/register#privatekey");
form.addField(type);
// private key
FormField fieldKey = new FormField("privatekey");
fieldKey.setLabel("Private key");
fieldKey.setType(FormField.Type.text_single);
fieldKey.addValue(privatekey);
form.addField(fieldKey);
iq.addExtension(form.getDataFormToSend());
return iq;
}
示例5: createValidationForm
import org.jivesoftware.smackx.xdata.Form; //导入依赖的package包/类
private Stanza createValidationForm() throws IOException {
Registration iq = new Registration();
iq.setType(IQ.Type.set);
iq.setTo(mConnector.getConnection().getServiceName());
Form form = new Form(DataForm.Type.submit);
FormField type = new FormField("FORM_TYPE");
type.setType(FormField.Type.hidden);
type.addValue("http://kontalk.org/protocol/register#code");
form.addField(type);
if (mValidationCode != null) {
FormField code = new FormField("code");
code.setLabel("Validation code");
code.setType(FormField.Type.text_single);
code.addValue(mValidationCode.toString());
form.addField(code);
}
iq.addExtension(form.getDataFormToSend());
return iq;
}
示例6: createRegistrationForm
import org.jivesoftware.smackx.xdata.Form; //导入依赖的package包/类
private Packet createRegistrationForm() {
Registration iq = new Registration();
iq.setType(IQ.Type.SET);
iq.setTo(mConnector.getConnection().getServiceName());
Form form = new Form(Form.TYPE_SUBMIT);
FormField type = new FormField("FORM_TYPE");
type.setType(FormField.TYPE_HIDDEN);
type.addValue("jabber:iq:register");
form.addField(type);
FormField phone = new FormField("phone");
phone.setLabel("Phone number");
phone.setType(FormField.TYPE_TEXT_SINGLE);
phone.addValue(mPhone);
form.addField(phone);
iq.addExtension(form.getDataFormToSend());
return iq;
}
示例7: JoinQueuePacket
import org.jivesoftware.smackx.xdata.Form; //导入依赖的package包/类
public JoinQueuePacket(String workgroup, Form answerForm, String userID) {
super("join-queue", "http://jabber.org/protocol/workgroup");
this.userID = userID;
setTo(workgroup);
setType(IQ.Type.set);
form = answerForm.getDataFormToSend();
addExtension(form);
}
示例8: FormNode
import org.jivesoftware.smackx.xdata.Form; //导入依赖的package包/类
/**
* Create a {@link FormNode} which contains the specified form.
*
* @param formType The type of form being sent
* @param submitForm The form
*/
public FormNode(FormNodeType formType, Form submitForm)
{
super(formType.getNodeElement());
if (submitForm == null)
throw new IllegalArgumentException("Submit form cannot be null");
configForm = submitForm;
}
示例9: getMessageCount
import org.jivesoftware.smackx.xdata.Form; //导入依赖的package包/类
/**
* 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
*/
public int getMessageCount() throws NoResponseException, XMPPErrorException, NotConnectedException {
DiscoverInfo info = ServiceDiscoveryManager.getInstanceFor(connection).discoverInfo(null,
namespace);
Form extendedInfo = Form.getFormFrom(info);
if (extendedInfo != null) {
String value = extendedInfo.getField("number_of_messages").getValues().get(0);
return Integer.parseInt(value);
}
return 0;
}
示例10: joinQueue
import org.jivesoftware.smackx.xdata.Form; //导入依赖的package包/类
/**
* <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
*/
public void joinQueue(Map<String,Object> metadata, String userID) throws XMPPException, SmackException {
// 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);
}
示例11: complete
import org.jivesoftware.smackx.xdata.Form; //导入依赖的package包/类
@Override
public void complete(Form form) throws NoResponseException, XMPPErrorException, NotConnectedException {
executeAction(Action.complete, form);
}
示例12: next
import org.jivesoftware.smackx.xdata.Form; //导入依赖的package包/类
@Override
public void next(Form form) throws NoResponseException, XMPPErrorException, NotConnectedException {
executeAction(Action.next, form);
}
示例13: SubscribeForm
import org.jivesoftware.smackx.xdata.Form; //导入依赖的package包/类
public SubscribeForm(Form subscribeOptionsForm)
{
super(subscribeOptionsForm.getDataFormToSend());
}
示例14: createReturnExtension
import org.jivesoftware.smackx.xdata.Form; //导入依赖的package包/类
@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()));
}
示例15: setForm
import org.jivesoftware.smackx.xdata.Form; //导入依赖的package包/类
public void setForm(Form form) {
this.form = form;
}