@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())); } }
@Override public CharSequence toXML(String enclosingNamespace) { if (configForm == null) { return super.toXML(enclosingNamespace); } else { StringBuilder builder = new StringBuilder("<"); builder.append(getElementName()); if (getNode() != null) { builder.append(" node='"); builder.append(getNode()); builder.append("'>"); } else builder.append('>'); builder.append(configForm.getDataFormToSend().toXML(null)); builder.append("</"); builder.append(getElementName() + '>'); return builder.toString(); } }
/** * Get a {@link ConfigureForm} from a packet. * * @param packet * @param elem * @return The configuration form */ public static ConfigureForm getFormFromPacket(Stanza packet, PubSubElementType elem) { FormNode config = packet.getExtension(elem.getElementName(), elem.getNamespace().getXmlns()); Form formReply = config.getForm(); return new ConfigureForm(formReply); } }
/** * Update the configuration with the contents of the new {@link Form}. * * @param submitForm * @throws XMPPErrorException * @throws NoResponseException * @throws NotConnectedException * @throws InterruptedException */ public void sendConfigurationForm(Form submitForm) throws NoResponseException, XMPPErrorException, NotConnectedException, InterruptedException { PubSub packet = createPubsubPacket(Type.set, new FormNode(FormNodeType.CONFIGURE_OWNER, getId(), submitForm)); pubSubManager.getConnection().createStanzaCollectorAndSend(packet).nextResultOrThrow(); }
@Override public String toXML() { if (configForm == null) { return super.toXML(); } else { StringBuilder builder = new StringBuilder("<"); builder.append(getElementName()); if (getNode() != null) { builder.append(" node='"); builder.append(getNode()); builder.append("'>"); } else builder.append('>'); builder.append(configForm.getDataFormToSend().toXML()); builder.append("</"); builder.append(getElementName() + '>'); return builder.toString(); } }
/** * Get the options for configuring the specified subscription. * * @param jid JID the subscription is registered under * @param subscriptionId The subscription id * * @return The subscription option form * @throws XMPPErrorException * @throws NoResponseException * @throws NotConnectedException * @throws InterruptedException * */ public SubscribeForm getSubscriptionOptions(String jid, String subscriptionId) throws NoResponseException, XMPPErrorException, NotConnectedException, InterruptedException { PubSub packet = sendPubsubPacket(createPubsubPacket(Type.get, new OptionsExtension(jid, getId(), subscriptionId))); FormNode ext = packet.getExtension(PubSubElementType.OPTIONS); return new SubscribeForm(ext.getForm()); }
/** * Creates a node with specified configuration. * * Note: This is the only way to create a collection node. * * @param nodeId 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 * @throws InterruptedException */ public Node createNode(String nodeId, Form config) throws NoResponseException, XMPPErrorException, NotConnectedException, InterruptedException { PubSub request = PubSub.createPubsubPacket(pubSubService, Type.set, new NodeExtension(PubSubElementType.CREATE, nodeId)); 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).toString().equals(NodeType.leaf.toString()); } // Errors will cause exceptions in getReply, so it only returns // on success. sendPubsubPacket(request); Node newNode = isLeafNode ? new LeafNode(this, nodeId) : new CollectionNode(this, nodeId); nodeMap.put(newNode.getId(), newNode); return newNode; }
@Override public String toXML() { if (configForm == null) { return super.toXML(); } else { StringBuilder builder = new StringBuilder("<"); builder.append(getElementName()); if (getNode() != null) { builder.append(" node='"); builder.append(getNode()); builder.append("'>"); } else builder.append('>'); builder.append(configForm.getDataFormToSend().toXML()); builder.append("</"); builder.append(getElementName() + '>'); return builder.toString(); } }
/** * Get a {@link ConfigureForm} from a packet. * * @param packet * @param elem * @return The configuration form */ public static ConfigureForm getFormFromPacket(Packet packet, PubSubElementType elem) { FormNode config = (FormNode)packet.getExtension(elem.getElementName(), elem.getNamespace().getXmlns()); Form formReply = config.getForm(); return new ConfigureForm(formReply); } }
/** * The user subscribes to the node using the supplied jid and subscription * options. The bare jid portion of this one must match the jid for the * connection. * * Please note that the {@link Subscription.State} should be checked * on return since more actions may be required by the caller. * {@link Subscription.State#pending} - The owner must approve the subscription * request before messages will be received. * {@link Subscription.State#unconfigured} - If the {@link Subscription#isConfigRequired()} is true, * the caller must configure the subscription before messages will be received. If it is false * the caller can configure it but is not required to do so. * * @param jid The jid to subscribe as. * @param subForm * * @return The subscription * @throws XMPPErrorException * @throws NoResponseException * @throws NotConnectedException * @throws InterruptedException */ public Subscription subscribe(String jid, SubscribeForm subForm) throws NoResponseException, XMPPErrorException, NotConnectedException, InterruptedException { PubSub request = createPubsubPacket(Type.set, new SubscribeExtension(jid, getId())); request.addExtension(new FormNode(FormNodeType.OPTIONS, subForm)); PubSub reply = sendPubsubPacket(request); return reply.getExtension(PubSubElementType.SUBSCRIPTION); }
@Override public String toXML() { if (configForm == null) { return super.toXML(); } else { StringBuilder builder = new StringBuilder("<"); builder.append(getElementName()); if (getNode() != null) { builder.append(" node='"); builder.append(getNode()); builder.append("'>"); } else builder.append('>'); builder.append(configForm.getDataFormToSend().toXML()); builder.append("</"); builder.append(getElementName() + '>'); return builder.toString(); } }
/** * Get a {@link ConfigureForm} from a packet. * * @param packet * @param elem * @return The configuration form */ public static ConfigureForm getFormFromPacket(Packet packet, PubSubElementType elem) { FormNode config = (FormNode)packet.getExtension(elem.getElementName(), elem.getNamespace().getXmlns()); Form formReply = config.getForm(); return new ConfigureForm(formReply); } }
new FormNode(FormNodeType.CONFIGURE_OWNER, nodeName ,cfg)); try
/** * Get a {@link ConfigureForm} from a packet. * * @param packet * @param elem * @return The configuration form */ public static ConfigureForm getFormFromPacket(Packet packet, PubSubElementType elem) { FormNode config = (FormNode)packet.getExtension(elem.getElementName(), elem.getNamespace().getXmlns()); Form formReply = config.getForm(); return new ConfigureForm(formReply); } }
@Override protected PacketExtension createReturnExtension(String currentElement, String currentNamespace, Map<String, String> attributeMap, List<? extends PacketExtension> content) { return new FormNode(FormNodeType.valueOfFromElementName(currentElement, currentNamespace), attributeMap.get("node"), new Form((DataForm)content.iterator().next())); } }
/** * Get the options for configuring the specified subscription. * * @param jid JID the subscription is registered under * @param subscriptionId The subscription id * * @return The subscription option form * * @throws XMPPException */ public SubscribeForm getSubscriptionOptions(String jid, String subscriptionId) throws XMPPException { PubSub packet = (PubSub)sendPubsubPacket(Type.GET, new OptionsExtension(jid, getId(), subscriptionId)); FormNode ext = (FormNode)packet.getExtension(PubSubElementType.OPTIONS); return new SubscribeForm(ext.getForm()); }
@Override protected PacketExtension createReturnExtension(String currentElement, String currentNamespace, Map<String, String> attributeMap, List<? extends PacketExtension> content) { return new FormNode(FormNodeType.valueOfFromElementName(currentElement, currentNamespace), attributeMap.get("node"), new Form((DataForm)content.iterator().next())); } }
/** * Get the options for configuring the specified subscription. * * @param jid JID the subscription is registered under * @param subscriptionId The subscription id * * @return The subscription option form * * @throws XMPPException */ public SubscribeForm getSubscriptionOptions(String jid, String subscriptionId) throws XMPPException { PubSub packet = (PubSub)sendPubsubPacket(Type.GET, new OptionsExtension(jid, getId(), subscriptionId)); FormNode ext = (FormNode)packet.getExtension(PubSubElementType.OPTIONS); return new SubscribeForm(ext.getForm()); }
@Override protected PacketExtension createReturnExtension(String currentElement, String currentNamespace, Map<String, String> attributeMap, List<? extends PacketExtension> content) { return new FormNode(FormNodeType.valueOfFromElementName(currentElement, currentNamespace), attributeMap.get("node"), new Form((DataForm)content.iterator().next())); } }
/** * Get the options for configuring the specified subscription. * * @param jid JID the subscription is registered under * @param subscriptionId The subscription id * * @return The subscription option form * * @throws XMPPException */ public SubscribeForm getSubscriptionOptions(String jid, String subscriptionId) throws XMPPException { PubSub packet = (PubSub)sendPubsubPacket(Type.GET, new OptionsExtension(jid, getId(), subscriptionId)); FormNode ext = (FormNode)packet.getExtension(PubSubElementType.OPTIONS); return new SubscribeForm(ext.getForm()); }