本文整理汇总了Java中org.jivesoftware.smackx.pubsub.PayloadItem类的典型用法代码示例。如果您正苦于以下问题:Java PayloadItem类的具体用法?Java PayloadItem怎么用?Java PayloadItem使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
PayloadItem类属于org.jivesoftware.smackx.pubsub包,在下文中一共展示了PayloadItem类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: eventReceived
import org.jivesoftware.smackx.pubsub.PayloadItem; //导入依赖的package包/类
@Override
public void eventReceived(String from, String node, List<Item> items) {
if (!"urn:xmpp:avatar:metadata".equals(node))
return;
Item i = items.get(0);
if (i instanceof PayloadItem) {
PayloadItem<PacketExtension> pi = (PayloadItem<PacketExtension>) i;
PacketExtension ex = pi.getPayload();
if (ex instanceof AvatarMetadataExtension) {
AvatarMetadataExtension ext = (AvatarMetadataExtension) ex;
String id = i.getId();
List<Info> infos = ext.getInfos();
if (infos.size() > 0 && mAutoDownload) {
Info info = selectAvatar(infos);
if (!mCache.contains(id))
downloadAvatar(from, id, info);
}
fireListeners(from, id, infos);
}
}
}
示例2: XMPPPublisher
import org.jivesoftware.smackx.pubsub.PayloadItem; //导入依赖的package包/类
private void XMPPPublisher(String xmlString, String SCHEMA, String mtype, Node pubNode){
SimplePayload payload = new SimplePayload(mtype,SCHEMA, xmlString);
@SuppressWarnings({ "unchecked", "rawtypes" })
PayloadItem payloadItem = new PayloadItem(null, payload);
Log.i(appTAG, classTAG+": Message Published to:"+pubNode.getId());
try {
((LeafNode)pubNode).publish(payloadItem);
} catch (NotConnectedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
示例3: parse
import org.jivesoftware.smackx.pubsub.PayloadItem; //导入依赖的package包/类
@Override
public Item parse(XmlPullParser parser, int initialDepth)
throws XmlPullParserException, IOException, SmackException {
String id = parser.getAttributeValue(null, "id");
String node = parser.getAttributeValue(null, "node");
int tag = parser.next();
if (tag == XmlPullParser.END_TAG)
{
return new Item(id, node);
}
else
{
String payloadElemName = parser.getName();
String payloadNS = parser.getNamespace();
final ExtensionElementProvider<ExtensionElement> extensionProvider = ProviderManager.getExtensionProvider(payloadElemName, payloadNS);
if (extensionProvider == null)
{
CharSequence payloadText = PacketParserUtils.parseElement(parser, true);
return new PayloadItem<SimplePayload>(id, node, new SimplePayload(payloadElemName, payloadNS, payloadText));
}
else
{
return new PayloadItem<ExtensionElement>(id, node, extensionProvider.parse(parser));
}
}
}
示例4: parseExtension
import org.jivesoftware.smackx.pubsub.PayloadItem; //导入依赖的package包/类
public PacketExtension parseExtension(XmlPullParser parser) throws Exception
{
String id = parser.getAttributeValue(null, "id");
String elem = parser.getName();
int tag = parser.next();
if (tag == XmlPullParser.END_TAG)
{
return new Item(id);
}
else
{
String payloadElemName = parser.getName();
String payloadNS = parser.getNamespace();
if (ProviderManager.getInstance().getExtensionProvider(payloadElemName, payloadNS) == null)
{
boolean done = false;
StringBuilder payloadText = new StringBuilder();
while (!done)
{
if (tag == XmlPullParser.END_TAG && parser.getName().equals(elem))
done = true;
else if (!((tag == XmlPullParser.START_TAG) && parser.isEmptyElementTag()))
payloadText.append(parser.getText());
if (!done)
tag = parser.next();
}
return new PayloadItem<SimplePayload>(id, new SimplePayload(payloadElemName, payloadNS, payloadText.toString()));
}
else
{
return new PayloadItem<PacketExtension>(id, PacketParserUtils.parsePacketExtension(payloadElemName, payloadNS, parser));
}
}
}
示例5: DataHandler
import org.jivesoftware.smackx.pubsub.PayloadItem; //导入依赖的package包/类
/**
* Creates a new data handler.
* @param connectionHandler The connection handler to be used for requests.
* @param spaceHandler An instance of a space handler to be used for requesting space properties.
*/
public DataHandler(ConnectionHandler connectionHandler, SpaceHandler spaceHandler){
if (connectionHandler == null || spaceHandler == null){
throw new IllegalArgumentException("None of the Arguments may be null");
}
this.connectionHandler = connectionHandler;
this.isConnectionResetted = true;
this.spaceHandler = spaceHandler;
this.timeout = connectionHandler.getConfiguration().requestTimeout();
this.userWantedMode = Mode.OFFLINE;
this.connection = this.connectionHandler.getXMPPConnection();
this.listeners = new ArrayList<DataObjectListener>();
this.handledSpaces = new ArrayList<Space>();
this.datawrapper = DataWrapper.getInstance();
this.pendingPayloadRequests = new HashMap<String, RequestFuture<List<PayloadItem<SimplePayload>>>>();
this.pendingPublishingRequests = new HashMap<String, RequestFuture<IQ>>();
this.pendingPersistenceServiceQueries = new HashMap<String, RequestFuture<IQ>>();
this.userInfo = this.connectionHandler.getCurrentUser();
this.dataObjectFilter = null;
this.publishIdMap = new HashMap<String, String>();
this.pubsubServiceListeners = new HashMap<String, PacketListener>();
this.persistenceServiceListeners = new HashMap<String, PacketListener>();
this.pubsubManagers = new HashMap<String, PubSubManager>();
setPubSubPacketInterceptor();
setConnectionStatusListener();
}
示例6: handlePublishedItems
import org.jivesoftware.smackx.pubsub.PayloadItem; //导入依赖的package包/类
/**
* Item handler of this data handler implementation. Checks if received items are already cached,
* if not, it caches them. Ultimately it sends the items to the subscribed listeners.
*/
@Override
public void handlePublishedItems(ItemPublishEvent<PayloadItem<SimplePayload>> items){
String spaceId = getSpaceId(items.getNodeId());
if (spaceId == null) return;
List<String> toRequest = new ArrayList<String>();
for (PayloadItem<SimplePayload> item:items.getItems()){
if (item.getPayload() == null && !pendingPayloadRequests.containsKey(item.getId())){
toRequest.add(item.getId());
continue;
}
DataObject obj = parseItemToDataObject(item);
if (dataObjectFilter == null || dataObjectFilter.isDataObjectValid(obj)) {
if (!datawrapper.isDataObjectAlreadyCached(item.getId())){
datawrapper.saveDataObject(items.getNodeId(), obj, item.getId());
}
for (DataObjectListener listener:listeners){
listener.handleDataObject(obj, spaceId);
}
}
}
if (!toRequest.isEmpty()){
for (String id:toRequest){
try {
retrievePayload(items.getNodeId(), id);
} catch (Exception e) {
//Ignore
continue;
}
}
}
}
示例7: processMetadataEvent
import org.jivesoftware.smackx.pubsub.PayloadItem; //导入依赖的package包/类
void processMetadataEvent(JID jid, ItemsExtension itemsExt) {
List<? extends ExtensionElement> items = itemsExt.getItems();
if (items.isEmpty()) {
LOGGER.warning("no items in items event");
return;
}
// there should be only one item
ExtensionElement e = items.get(0);
if (!(e instanceof PayloadItem)) {
LOGGER.warning("element not a payloaditem");
return;
}
PayloadItem item = (PayloadItem) e;
ExtensionElement metadataExt = item.getPayload();
if (!(metadataExt instanceof AvatarMetadataExtension)) {
LOGGER.warning("payload not avatar metadata");
return;
}
AvatarMetadataExtension metadata = (AvatarMetadataExtension) metadataExt;
List<AvatarMetadataExtension.Info> infos = metadata.getInfos();
if (infos.isEmpty()) {
// this means the contact disabled avatar publishing
mHandler.onNotify(jid, "");
return;
}
// assuming infos are always in the same order
for (AvatarMetadataExtension.Info info : infos) {
if (AvatarHandler.SUPPORTED_TYPES.contains(info.getType())) {
mHandler.onNotify(jid, info.getId());
break;
} else {
LOGGER.info("image type not supported: "+info.getType());
}
}
}
示例8: parseExtension
import org.jivesoftware.smackx.pubsub.PayloadItem; //导入依赖的package包/类
public PacketExtension parseExtension(XmlPullParser parser) throws Exception
{
String id = parser.getAttributeValue(null, "id");
String node = parser.getAttributeValue(null, "node");
String elem = parser.getName();
int tag = parser.next();
if (tag == XmlPullParser.END_TAG)
{
return new Item(id, node);
}
else
{
String payloadElemName = parser.getName();
String payloadNS = parser.getNamespace();
if (ProviderManager.getInstance().getExtensionProvider(payloadElemName, payloadNS) == null)
{
boolean done = false;
StringBuilder payloadText = new StringBuilder();
while (!done)
{
if (tag == XmlPullParser.END_TAG && parser.getName().equals(elem))
done = true;
else if (!((tag == XmlPullParser.START_TAG) && parser.isEmptyElementTag()))
payloadText.append(parser.getText());
if (!done)
tag = parser.next();
}
return new PayloadItem<SimplePayload>(id, node, new SimplePayload(payloadElemName, payloadNS, payloadText.toString()));
}
else
{
return new PayloadItem<PacketExtension>(id, node, PacketParserUtils.parsePacketExtension(payloadElemName, payloadNS, parser));
}
}
}
示例9: publishAvatarData
import org.jivesoftware.smackx.pubsub.PayloadItem; //导入依赖的package包/类
/**
* Publish an avatar data.
*
* @param id the id of the avatar data
* @param data the data of the avatar
*/
private void publishAvatarData(String id, byte[] data) {
AvatarExtension avatar = new AvatarExtension(data);
PayloadItem<AvatarExtension> item = new PayloadItem<AvatarExtension>(id, avatar);
LeafNode node = mPep.getPEPNode(AVATARDATA_NODE);
node.publish(item);
}
示例10: getAvatar
import org.jivesoftware.smackx.pubsub.PayloadItem; //导入依赖的package包/类
@Override
public byte[] getAvatar() {
try {
LeafNode node = mPubsub.getPEPNode(AVATARDATANODE);
List<Item> items = node.getItems(Arrays.asList(mId));
PayloadItem<AvatarExtension> item = (PayloadItem<AvatarExtension>) items.get(0);
AvatarExtension avatar = item.getPayload();
return avatar.getData();
} catch (XMPPException e) {
return null;
}
}
示例11: receiveBlogPosts
import org.jivesoftware.smackx.pubsub.PayloadItem; //导入依赖的package包/类
private void receiveBlogPosts() {
PEPManager pepManager = PEPManager.getInstanceFor(mXMPPConnection);
pepManager.addPEPListener(new PEPListener() {
@Override
public void eventReceived(EntityBareJid entityBareJid, EventElement eventElement, Message message) {
if (EventElementType.items == eventElement.getEventType()) {
ItemsExtension itemsExtension = (ItemsExtension) eventElement.getExtensions().get(0);
PayloadItem payloadItem = (PayloadItem) itemsExtension.getItems().get(0);
PostEntryExtension postEntryExtension = (PostEntryExtension) payloadItem.getPayload();
String id = postEntryExtension.getId();
String jid = entityBareJid.toString();
String title = postEntryExtension.getTitle();
Date published = postEntryExtension.getPublished();
Date updated = postEntryExtension.getUpdated();
BlogPost blogPost = new BlogPost(id, jid, null, title, published, updated);
RealmManager.getInstance().saveBlogPost(blogPost);
String commentsNode = PublishCommentExtension.NODE + "/" + id;
ServiceDiscoveryManager.getInstanceFor(mXMPPConnection).addFeature(commentsNode + "+notify");
notifyNewBlogPost();
}
}
private void notifyNewBlogPost() {
MangostaApplication mangostaApplication = MangostaApplication.getInstance();
if (mangostaApplication.isClosed()) {
BlogPostNotifications.newBlogPostNotification();
} else {
mangostaApplication.getCurrentActivity().runOnUiThread(new Runnable() {
@Override
public void run() {
new Event(Event.Type.BLOG_POST_CREATED).post();
}
});
}
}
});
}
示例12: parseExtension
import org.jivesoftware.smackx.pubsub.PayloadItem; //导入依赖的package包/类
public PacketExtension parseExtension(XmlPullParser parser) throws Exception
{
String id = parser.getAttributeValue(null, "id");
String node = parser.getAttributeValue(null, "node");
String elem = parser.getName();
int tag = parser.next();
if (tag == XmlPullParser.END_TAG)
{
return new Item(id, node);
}
else
{
String payloadElemName = parser.getName();
String payloadNS = parser.getNamespace();
if (ProviderManager.getInstance().getExtensionProvider(payloadElemName, payloadNS) == null)
{
boolean done = false;
boolean isEmptyElement = false;
StringBuilder payloadText = new StringBuilder();
while (!done)
{
if (tag == XmlPullParser.END_TAG && parser.getName().equals(elem))
{
done = true;
continue;
}
else if (parser.getEventType() == XmlPullParser.START_TAG)
{
payloadText.append("<").append(parser.getName());
if (parser.getName().equals(payloadElemName) && (payloadNS.length() > 0))
payloadText.append(" xmlns=\"").append(payloadNS).append("\"");
int n = parser.getAttributeCount();
for (int i = 0; i < n; i++)
payloadText.append(" ").append(parser.getAttributeName(i)).append("=\"")
.append(parser.getAttributeValue(i)).append("\"");
if (parser.isEmptyElementTag())
{
payloadText.append("/>");
isEmptyElement = true;
}
else
{
payloadText.append(">");
}
}
else if (parser.getEventType() == XmlPullParser.END_TAG)
{
if (isEmptyElement)
{
isEmptyElement = false;
}
else
{
payloadText.append("</").append(parser.getName()).append(">");
}
}
else if (parser.getEventType() == XmlPullParser.TEXT)
{
payloadText.append(parser.getText());
}
tag = parser.next();
}
return new PayloadItem<SimplePayload>(id, node, new SimplePayload(payloadElemName, payloadNS, payloadText.toString()));
}
else
{
return new PayloadItem<PacketExtension>(id, node, PacketParserUtils.parsePacketExtension(payloadElemName, payloadNS, parser));
}
}
}
示例13: parseExtension
import org.jivesoftware.smackx.pubsub.PayloadItem; //导入依赖的package包/类
public PacketExtension parseExtension(XmlPullParser parser)
throws Exception {
String id = parser.getAttributeValue(null, "id");
String node = parser.getAttributeValue(null, "node");
String elem = parser.getName();
int tag = parser.next();
if (tag == XmlPullParser.END_TAG) {
return new Item(id, node);
} else {
while (tag != XmlPullParser.START_TAG)
tag = parser.next();
String payloadElemName = parser.getName();
String payloadNS = parser.getNamespace();
if (ProviderManager.getInstance().getExtensionProvider(
payloadElemName, payloadNS) == null) {
boolean done = false;
StringBuilder payloadText = new StringBuilder();
while (!done) {
if (tag == XmlPullParser.END_TAG
&& parser.getName().equals(elem))
done = true;
else if (!((tag == XmlPullParser.START_TAG) && parser
.isEmptyElementTag()))
payloadText.append(parser.getText());
if (!done)
tag = parser.next();
}
return new PayloadItem<SimplePayload>(id, node,
new SimplePayload(payloadElemName, payloadNS,
payloadText.toString()));
} else {
return new PayloadItem<PacketExtension>(id, node,
PacketParserUtils.parsePacketExtension(payloadElemName,
payloadNS, parser));
}
}
}
示例14: parseExtension
import org.jivesoftware.smackx.pubsub.PayloadItem; //导入依赖的package包/类
public PacketExtension parseExtension(XmlPullParser parser) throws Exception
{
String id = parser.getAttributeValue(null, "id");
String node = parser.getAttributeValue(null, "node");
String elem = parser.getName();
int tag = parser.next();
if (tag == XmlPullParser.END_TAG)
{
return new Item(id, node);
}
else
{
String payloadElemName = parser.getName();
String payloadNS = parser.getNamespace();
if (ProviderManager.getInstance().getExtensionProvider(payloadElemName, payloadNS) == null)
{
boolean done = false;
boolean isEmptyElement = false;
StringBuilder payloadText = new StringBuilder();
while (!done)
{
if (tag == XmlPullParser.END_TAG && parser.getName().equals(elem))
{
done = true;
}
else if (parser.getEventType() == XmlPullParser.START_TAG)
{
payloadText.append("<").append(parser.getName());
if (parser.getName().equals(payloadElemName) && (payloadNS.length() > 0))
payloadText.append(" xmlns=\"").append(payloadNS).append("\"");
int n = parser.getAttributeCount();
for (int i = 0; i < n; i++)
payloadText.append(" ").append(parser.getAttributeName(i)).append("=\"")
.append(parser.getAttributeValue(i)).append("\"");
if (parser.isEmptyElementTag())
{
payloadText.append("/>");
isEmptyElement = true;
}
else
{
payloadText.append(">");
}
}
else if (parser.getEventType() == XmlPullParser.END_TAG)
{
if (isEmptyElement)
isEmptyElement = false;
else
payloadText.append("</").append(parser.getName()).append(">");
}
else if (parser.getEventType() == XmlPullParser.TEXT)
{
payloadText.append(parser.getText());
}
tag = parser.next();
}
return new PayloadItem<SimplePayload>(id, node, new SimplePayload(payloadElemName, payloadNS, payloadText.toString()));
}
else {
return new PayloadItem<PacketExtension>(id, node, PacketParserUtils.parsePacketExtension(
payloadElemName, payloadNS, parser));
}
}
}
示例15: publishAvatarMetaData
import org.jivesoftware.smackx.pubsub.PayloadItem; //导入依赖的package包/类
/**
* Send the metadata of the avatar you want to publish.
* By sending this metadata, you publish an avatar.
*
* @param id the id of the metadata item
* @param metadata the metadata to publish
*/
public void publishAvatarMetaData(String id, AvatarMetadataExtension metadata) {
PayloadItem<AvatarMetadataExtension> item = new PayloadItem<AvatarMetadataExtension>(id, metadata);
LeafNode node = mPep.getPEPNode(AVATARMETADATA_NODE);
node.publish(item);
}