本文整理汇总了Java中org.jivesoftware.smackx.pubsub.packet.PubSub类的典型用法代码示例。如果您正苦于以下问题:Java PubSub类的具体用法?Java PubSub怎么用?Java PubSub使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
PubSub类属于org.jivesoftware.smackx.pubsub.packet包,在下文中一共展示了PubSub类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: sendBlogPostComment
import org.jivesoftware.smackx.pubsub.packet.PubSub; //导入依赖的package包/类
public BlogPostComment sendBlogPostComment(String content, BlogPost blogPost)
throws SmackException.NotConnectedException, InterruptedException,
XMPPException.XMPPErrorException, SmackException.NoResponseException {
Jid jid = XMPPSession.getInstance().getUser().asEntityBareJid();
String userName = XMPPUtils.fromJIDToUserName(jid.toString());
Jid pubSubServiceJid = XMPPSession.getInstance().getPubSubService();
// create stanza
PublishCommentExtension publishCommentExtension = new PublishCommentExtension(blogPost.getId(), userName, jid, content, new Date());
PubSub publishCommentPubSub = PubSub.createPubsubPacket(pubSubServiceJid, IQ.Type.set, publishCommentExtension, null);
// send stanza
XMPPSession.getInstance().sendStanza(publishCommentPubSub);
return new BlogPostComment(publishCommentExtension.getId(),
blogPost.getId(),
content,
userName,
jid.toString(),
publishCommentExtension.getPublished());
}
示例2: createNode
import org.jivesoftware.smackx.pubsub.packet.PubSub; //导入依赖的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: getSubscriptions
import org.jivesoftware.smackx.pubsub.packet.PubSub; //导入依赖的package包/类
private List<Subscription> getSubscriptions(List<ExtensionElement> additionalExtensions,
Collection<ExtensionElement> returnedExtensions, PubSubNamespace pubSubNamespace)
throws NoResponseException, XMPPErrorException, NotConnectedException {
PubSub pubSub = createPubsubPacket(Type.get, new NodeExtension(PubSubElementType.SUBSCRIPTIONS, getId()), pubSubNamespace);
if (additionalExtensions != null) {
for (ExtensionElement pe : additionalExtensions) {
pubSub.addExtension(pe);
}
}
PubSub reply = sendPubsubPacket(pubSub);
if (returnedExtensions != null) {
returnedExtensions.addAll(reply.getExtensions());
}
SubscriptionsExtension subElem = (SubscriptionsExtension) reply.getExtension(PubSubElementType.SUBSCRIPTIONS);
return subElem.getSubscriptions();
}
示例4: getAffiliations
import org.jivesoftware.smackx.pubsub.packet.PubSub; //导入依赖的package包/类
/**
* Get the affiliations of this node.
* <p>
* {@code additionalExtensions} can be used e.g. to add a "Result Set Management" extension.
* {@code returnedExtensions} will be filled with the stanza(/packet) extensions found in the answer.
* </p>
*
* @param additionalExtensions additional {@code PacketExtensions} add to the request
* @param returnedExtensions a collection that will be filled with the returned packet
* extensions
* @return List of {@link Affiliation}
* @throws NoResponseException
* @throws XMPPErrorException
* @throws NotConnectedException
*/
public List<Affiliation> getAffiliations(List<ExtensionElement> additionalExtensions, Collection<ExtensionElement> returnedExtensions)
throws NoResponseException, XMPPErrorException, NotConnectedException {
PubSub pubSub = createPubsubPacket(Type.get, new NodeExtension(PubSubElementType.AFFILIATIONS, getId()));
if (additionalExtensions != null) {
for (ExtensionElement pe : additionalExtensions) {
pubSub.addExtension(pe);
}
}
PubSub reply = sendPubsubPacket(pubSub);
if (returnedExtensions != null) {
returnedExtensions.addAll(reply.getExtensions());
}
AffiliationsExtension affilElem = (AffiliationsExtension) reply.getExtension(PubSubElementType.AFFILIATIONS);
return affilElem.getAffiliations();
}
示例5: parse
import org.jivesoftware.smackx.pubsub.packet.PubSub; //导入依赖的package包/类
@Override
public PubSub parse(XmlPullParser parser, int initialDepth)
throws XmlPullParserException, IOException, SmackException {
String namespace = parser.getNamespace();
PubSubNamespace pubSubNamespace = PubSubNamespace.valueOfFromXmlns(namespace);
PubSub pubsub = new PubSub(pubSubNamespace);
outerloop: while (true)
{
int eventType = parser.next();
switch (eventType) {
case XmlPullParser.START_TAG:
PacketParserUtils.addExtensionElement(pubsub, parser);
break;
case XmlPullParser.END_TAG:
if (parser.getDepth() == initialDepth) {
break outerloop;
}
break;
}
}
return pubsub;
}
示例6: getConfigFormWithInsufficientPriviliges
import org.jivesoftware.smackx.pubsub.packet.PubSub; //导入依赖的package包/类
@Test
public void getConfigFormWithInsufficientPriviliges() throws XMPPException, SmackException, IOException
{
ThreadedDummyConnection con = ThreadedDummyConnection.newInstance();
PubSubManager mgr = new PubSubManager(con);
DiscoverInfo info = new DiscoverInfo();
Identity ident = new Identity("pubsub", null, "leaf");
info.addIdentity(ident);
con.addIQReply(info);
Node node = mgr.getNode("princely_musings");
PubSub errorIq = new PubSub();
XMPPError error = new XMPPError(Condition.forbidden);
errorIq.setError(error);
con.addIQReply(errorIq);
try
{
node.getNodeConfiguration();
}
catch (XMPPErrorException e)
{
Assert.assertEquals(XMPPError.Type.AUTH, e.getXMPPError().getType());
}
}
示例7: extractHeadersFromXmpp
import org.jivesoftware.smackx.pubsub.packet.PubSub; //导入依赖的package包/类
public Map<String, Object> extractHeadersFromXmpp(Packet xmppPacket, Exchange exchange) {
Map<String, Object> answer = new HashMap<String, Object>();
PacketExtension jpe = xmppPacket.getExtension(JivePropertiesExtension.NAMESPACE);
if (jpe != null && jpe instanceof JivePropertiesExtension) {
extractHeadersFrom((JivePropertiesExtension)jpe, exchange, answer);
}
if (jpe != null && jpe instanceof DefaultPacketExtension) {
extractHeadersFrom((DefaultPacketExtension)jpe, exchange, answer);
}
if (xmppPacket instanceof Message) {
Message xmppMessage = (Message) xmppPacket;
answer.put(XmppConstants.MESSAGE_TYPE, xmppMessage.getType());
answer.put(XmppConstants.SUBJECT, xmppMessage.getSubject());
answer.put(XmppConstants.THREAD_ID, xmppMessage.getThread());
} else if (xmppPacket instanceof PubSub) {
PubSub pubsubPacket = (PubSub) xmppPacket;
answer.put(XmppConstants.MESSAGE_TYPE, pubsubPacket.getType());
}
answer.put(XmppConstants.FROM, xmppPacket.getFrom());
answer.put(XmppConstants.PACKET_ID, xmppPacket.getPacketID());
answer.put(XmppConstants.TO, xmppPacket.getTo());
return answer;
}
示例8: createNode
import org.jivesoftware.smackx.pubsub.packet.PubSub; //导入依赖的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
* @exception XMPPException
*/
public Node createNode(String name, Form config)
throws XMPPException
{
PubSub request = createPubsubPacket(to, Type.SET, new NodeExtension(PubSubElementType.CREATE, name));
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().next().equals(NodeType.leaf.toString());
}
// Errors will cause exceptions in getReply, so it only returns
// on success.
sendPubsubPacket(con, to, Type.SET, request);
Node newNode = isLeafNode ? new LeafNode(con, name) : new CollectionNode(con, name);
newNode.setTo(to);
nodeMap.put(newNode.getId(), newNode);
return newNode;
}
示例9: getItems
import org.jivesoftware.smackx.pubsub.packet.PubSub; //导入依赖的package包/类
/**
* Get the items specified from the node. This would typically be
* used when the server does not return the payload due to size
* constraints. The user would be required to retrieve the payload
* after the items have been retrieved via {@link #getItems()} or an
* event, that did not include the payload.
*
* @param ids Item ids of the items to retrieve
*
* @return The list of {@link Item} with payload
*
* @throws XMPPException
*/
public <T extends Item> List<T> getItems(Collection<String> ids)
throws XMPPException
{
List<Item> itemList = new ArrayList<Item>(ids.size());
for (String id : ids)
{
itemList.add(new Item(id));
}
PubSub request = createPubsubPacket(Type.GET, new ItemsExtension(ItemsExtension.ItemsElementType.items, getId(), itemList));
PubSub result = (PubSub)SyncPacketSend.getReply(con, request);
ItemsExtension itemsElem = (ItemsExtension)result.getExtension(PubSubElementType.ITEMS);
return (List<T>)itemsElem.getItems();
}
示例10: createNode
import org.jivesoftware.smackx.pubsub.packet.PubSub; //导入依赖的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
* @exception XMPPException
*/
public Node createNode(String name, Form config) throws XMPPException {
PubSub request = createPubsubPacket(to, Type.SET, new NodeExtension(
PubSubElementType.CREATE, name));
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().next()
.equals(NodeType.leaf.toString());
}
// Errors will cause exceptions in getReply, so it only returns
// on success.
sendPubsubPacket(con, to, Type.SET, request);
Node newNode = isLeafNode ? new LeafNode(con, name)
: new CollectionNode(con, name);
newNode.setTo(to);
nodeMap.put(newNode.getId(), newNode);
return newNode;
}
示例11: getItems
import org.jivesoftware.smackx.pubsub.packet.PubSub; //导入依赖的package包/类
/**
* Get the items specified from the node. This would typically be used when
* the server does not return the payload due to size constraints. The user
* would be required to retrieve the payload after the items have been
* retrieved via {@link #getItems()} or an event, that did not include the
* payload.
*
* @param ids
* Item ids of the items to retrieve
*
* @return The list of {@link Item} with payload
*
* @throws XMPPException
*/
public <T extends Item> List<T> getItems(Collection<String> ids)
throws XMPPException {
List<Item> itemList = new ArrayList<Item>(ids.size());
for (String id : ids) {
itemList.add(new Item(id));
}
PubSub request = createPubsubPacket(Type.GET, new ItemsExtension(
ItemsExtension.ItemsElementType.items, getId(), itemList));
PubSub result = (PubSub) SyncPacketSend.getReply(con, request);
ItemsExtension itemsElem = (ItemsExtension) result
.getExtension(PubSubElementType.ITEMS);
return (List<T>) itemsElem.getItems();
}
示例12: parseIQ
import org.jivesoftware.smackx.pubsub.packet.PubSub; //导入依赖的package包/类
public IQ parseIQ(XmlPullParser parser) throws Exception {
PubSub pubsub = new PubSub();
String namespace = parser.getNamespace();
pubsub.setPubSubNamespace(PubSubNamespace.valueOfFromXmlns(namespace));
boolean done = false;
while (!done) {
int eventType = parser.next();
if (eventType == XmlPullParser.START_TAG) {
PacketExtension ext = PacketParserUtils.parsePacketExtension(
parser.getName(), namespace, parser);
if (ext != null) {
pubsub.addExtension(ext);
}
} else if (eventType == XmlPullParser.END_TAG) {
if (parser.getName().equals("pubsub")) {
done = true;
}
}
}
return pubsub;
}
示例13: getNode
import org.jivesoftware.smackx.pubsub.packet.PubSub; //导入依赖的package包/类
/**
* Retrieves the requested node, if it exists. It will throw an
* exception if it does not.
*
* @param id - The unique id of the node
* @return the node
* @throws XMPPErrorException The node does not exist
* @throws NoResponseException if there was no response from the server.
* @throws NotConnectedException
*/
@SuppressWarnings("unchecked")
public <T extends Node> T getNode(String id) throws NoResponseException, XMPPErrorException, NotConnectedException
{
Node node = nodeMap.get(id);
if (node == null)
{
DiscoverInfo info = new DiscoverInfo();
info.setTo(to);
info.setNode(id);
DiscoverInfo infoReply = (DiscoverInfo) con.createPacketCollectorAndSend(info).nextResultOrThrow();
if (infoReply.hasIdentity(PubSub.ELEMENT, "leaf")) {
node = new LeafNode(con, id);
}
else if (infoReply.hasIdentity(PubSub.ELEMENT, "collection")) {
node = new CollectionNode(con, id);
}
else {
// XEP-60 5.3 states that
// "The 'disco#info' result MUST include an identity with a category of 'pubsub' and a type of either 'leaf' or 'collection'."
// If this is not the case, then we are dealing with an PubSub implementation that doesn't follow the specification.
throw new AssertionError(
"PubSub service '"
+ to
+ "' returned disco info result for node '"
+ id
+ "', but it did not contain an Identity of type 'leaf' or 'collection' (and category 'pubsub'), which is not allowed according to XEP-60 5.3.");
}
node.setTo(to);
nodeMap.put(id, node);
}
return (T) node;
}
示例14: sendPubsubPacket
import org.jivesoftware.smackx.pubsub.packet.PubSub; //导入依赖的package包/类
static PubSub sendPubsubPacket(XMPPConnection con, String to, Type type, List<ExtensionElement> extList, PubSubNamespace ns) throws NoResponseException, XMPPErrorException, NotConnectedException
{
PubSub pubSub = new PubSub(to, type, ns);
for (ExtensionElement pe : extList) {
pubSub.addExtension(pe);
}
return sendPubsubPacket(con ,pubSub);
}
示例15: getItems
import org.jivesoftware.smackx.pubsub.packet.PubSub; //导入依赖的package包/类
@SuppressWarnings("unchecked")
private <T extends Item> List<T> getItems(PubSub request,
List<ExtensionElement> returnedExtensions) throws NoResponseException,
XMPPErrorException, NotConnectedException {
PubSub result = con.createPacketCollectorAndSend(request).nextResultOrThrow();
ItemsExtension itemsElem = result.getExtension(PubSubElementType.ITEMS);
if (returnedExtensions != null) {
returnedExtensions.addAll(result.getExtensions());
}
return (List<T>) itemsElem.getItems();
}