@Override protected ConfigurationEvent createReturnExtension(String currentElement, String currentNamespace, Map<String, String> attMap, List<? extends ExtensionElement> content) { if (content.size() == 0) return new ConfigurationEvent(attMap.get("node")); else return new ConfigurationEvent(attMap.get("node"), new ConfigureForm((DataForm) content.iterator().next())); } }
/** * Sets the value of access model. * * @param accessModel */ public void setAccessModel(AccessModel accessModel) { addField(ConfigureNodeFields.access_model, FormField.Type.list_single); setAnswer(ConfigureNodeFields.access_model.getFieldName(), getListSingle(accessModel.toString())); }
@Override public List<ExtensionElement> getExtensions() { if (getConfiguration() == null) return Collections.emptyList(); else return Arrays.asList(((ExtensionElement) getConfiguration().getDataFormToSend())); } }
/** * Does the node deliver payloads with event notifications. * * @return true if it does, false otherwise */ public boolean isDeliverPayloads() { return parseBoolean(getFieldValue(ConfigureNodeFields.deliver_payloads)); }
/** * Set the JID's in the whitelist of users that can associate child nodes with the collection * node. This is only relevant if {@link #getChildrenAssociationPolicy()} is set to * {@link ChildrenAssociationPolicy#whitelist}. * * @param whitelist The list of JID's */ public void setChildrenAssociationWhitelist(List<String> whitelist) { addField(ConfigureNodeFields.children_association_whitelist, FormField.Type.jid_multi); setAnswer(ConfigureNodeFields.children_association_whitelist.getFieldName(), whitelist); }
@SmackIntegrationTest public void simplePubSubNodeTest() throws NoResponseException, XMPPErrorException, NotConnectedException, InterruptedException { final String nodename = "sinttest-simple-nodename-" + testRunId; final String itemId = "sintest-simple-itemid-" + testRunId; ConfigureForm defaultConfiguration = pubSubManagerOne.getDefaultConfiguration(); ConfigureForm config = new ConfigureForm(defaultConfiguration.createAnswerForm()); // Configure the node as "Notification-Only Node", which in turn means that // items do not need payload, to prevent payload-required error responses when // publishing the item. config.setDeliverPayloads(false); config.setPersistentItems(true); Node node = pubSubManagerOne.createNode(nodename, config); try { LeafNode leafNode = (LeafNode) node; leafNode.publish(new Item(itemId)); List<Item> items = leafNode.getItems(); assertEquals(1, items.size()); Item item = items.get(0); assertEquals(itemId, item.getId()); } finally { pubSubManagerOne.deleteNode(nodename); } } }
ConfigureForm form = new ConfigureForm(FormType.submit); form.setPersistentItems(false); form.setDeliverPayloads(true); form.setAccessModel(AccessModel.open); return (LeafNode)manager.createNode(nodePath, form); } catch (XMPPException e) {
/** * Query the access model of {@code node}. If it is different from {@code accessModel}, change the access model * of the node to {@code accessModel}. * * @see <a href="https://xmpp.org/extensions/xep-0060.html#accessmodels">XEP-0060 ยง4.5 - Node Access Models</a> * * @param node {@link LeafNode} whose PubSub access model we want to change * @param accessModel new access model. * * @throws XMPPException.XMPPErrorException in case of an XMPP protocol error. * @throws SmackException.NotConnectedException if we are not connected. * @throws InterruptedException if the thread is interrupted. * @throws SmackException.NoResponseException if the server doesn't respond. */ public static void changeAccessModelIfNecessary(LeafNode node, AccessModel accessModel) throws XMPPException.XMPPErrorException, SmackException.NotConnectedException, InterruptedException, SmackException.NoResponseException { ConfigureForm current = node.getNodeConfiguration(); if (current.getAccessModel() != accessModel) { ConfigureForm updateConfig = new ConfigureForm(DataForm.Type.submit); updateConfig.setAccessModel(accessModel); node.sendConfigurationForm(updateConfig); } }
ConfigureForm cfg = new ConfigureForm(DataForm.Type.submit); PubSub pubsub = new PubSub(); cfg.setAccessModel(AccessModel.open); cfg.setPersistentItems(false); cfg.setPublishModel(PublishModel.open); pubsub.setTo(serviceName); pubsub.setType(IQ.Type.set);
/** * List of the multi user chat rooms that are specified as reply rooms. * * @return The reply room JID's */ public List<String> getReplyRoom() { return getFieldValues(ConfigureNodeFields.replyroom); }
@Test public void checkChildrenAssocPolicy() { ConfigureForm form = new ConfigureForm(DataForm.Type.submit); form.setChildrenAssociationPolicy(ChildrenAssociationPolicy.owners); assertEquals(ChildrenAssociationPolicy.owners, form.getChildrenAssociationPolicy()); }
@Test public void checkNotificationType() { ConfigureForm form = new ConfigureForm(DataForm.Type.submit); form.setNotificationType(NotificationType.normal); assertEquals(NotificationType.normal, form.getNotificationType()); form.setNotificationType(NotificationType.headline); assertEquals(NotificationType.headline, form.getNotificationType()); }
/** * Gets the URL of an XSL transformation which can be applied to the payload * format in order to generate a valid Data Forms result that the client could * display using a generic Data Forms rendering engine. * * @return The URL of an XSL transformation */ public String getDataformXSLT() { return getFieldValue(ConfigureNodeFields.dataform_xslt); }
private String getFieldValue(ConfigureNodeFields field) { FormField formField = getField(field.getFieldName()); return formField.getFirstValue(); }
form.setPersistentItems(false); form.setDeliverPayloads(true); form.setAccessModel(AccessModel.open);
@Override public String toString() { StringBuilder result = new StringBuilder(getClass().getName() + " Content ["); for (FormField formField : getFields()) { result.append('('); result.append(formField.getVariable()); result.append(':'); StringBuilder valuesBuilder = new StringBuilder(); for (CharSequence value : formField.getValues()) { if (valuesBuilder.length() > 0) result.append(','); valuesBuilder.append(value); } if (valuesBuilder.length() == 0) valuesBuilder.append("NOT SET"); result.append(valuesBuilder); result.append(')'); } result.append(']'); return result.toString(); }
/** * Determines if subscriptions are allowed. * * @return true if subscriptions are allowed, false otherwise */ public boolean isSubscribe() { return parseBoolean(getFieldValue(ConfigureNodeFields.subscribe)); }
/** * Set the maximum number of child nodes that can be associated with a collection node. * * @param max The maximum number of child nodes. */ public void setChildrenMax(int max) { addField(ConfigureNodeFields.children_max, FormField.Type.text_single); setAnswer(ConfigureNodeFields.children_max.getFieldName(), max); }