Java 类org.jivesoftware.smackx.pubsub.PayloadItem 实例源码

项目:Beem    文件:AvatarManager.java   
@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);
    }
    }
}
项目:beem-fork-xmpp    文件:AvatarManager.java   
@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);
    }
    }
}
项目:Android_Resource_Controller    文件:MessagePublisher.java   
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();
    }

}
项目:Smack    文件:ItemProvider.java   
@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));
        }
    }
}
项目:EIM    文件:ItemProvider.java   
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));
        }
    }
}
项目:msf-spaces-sdk-android    文件:DataHandler.java   
/**
 * 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();
}
项目:msf-spaces-sdk-android    文件:DataHandler.java   
/**
 * 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;
            }
        }
    }
}
项目:desktopclient-java    文件:AvatarSendReceiver.java   
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());
        }
    }
}
项目:telegraph    文件:ItemProvider.java   
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));
        }
    }
}
项目:NewCommunication-Android    文件:ItemProvider.java   
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));
        }
    }
}
项目:Beem    文件:AvatarManager.java   
/**
    * 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);
   }
项目:Beem    文件:XmppAvatarRetriever.java   
@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;
}
   }
项目:beem-fork-xmpp    文件:AvatarManager.java   
/**
    * 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);
   }
项目:beem-fork-xmpp    文件:XmppAvatarRetriever.java   
@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;
}
   }
项目:mangosta-android    文件:XMPPSession.java   
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();
                    }
                });
            }
        }
    });
}
项目:androidPN-client.    文件:ItemProvider.java   
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));
        }
    }
}
项目:xmppsupport_v2    文件:ItemProvider.java   
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));
        }
    }
}
项目:java-bells    文件:ItemProvider.java   
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));
        }
    }
}
项目:Beem    文件:AvatarManager.java   
/**
    * 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);
   }
项目:beem-fork-xmpp    文件:AvatarManager.java   
/**
    * 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);
   }