diff options
Diffstat (limited to 'src/main/java/de/thedevstack/conversationsplus/generator/IqGenerator.java')
-rw-r--r-- | src/main/java/de/thedevstack/conversationsplus/generator/IqGenerator.java | 141 |
1 files changed, 0 insertions, 141 deletions
diff --git a/src/main/java/de/thedevstack/conversationsplus/generator/IqGenerator.java b/src/main/java/de/thedevstack/conversationsplus/generator/IqGenerator.java deleted file mode 100644 index 8f6b128f..00000000 --- a/src/main/java/de/thedevstack/conversationsplus/generator/IqGenerator.java +++ /dev/null @@ -1,141 +0,0 @@ -package de.thedevstack.conversationsplus.generator; - -import java.util.ArrayList; -import java.util.List; - -import de.thedevstack.conversationsplus.ConversationsPlusApplication; -import de.thedevstack.conversationsplus.entities.Account; -import de.thedevstack.conversationsplus.entities.Conversation; -import de.thedevstack.conversationsplus.entities.DownloadableFile; -import de.thedevstack.conversationsplus.services.MessageArchiveService; -import de.thedevstack.conversationsplus.utils.Xmlns; -import de.thedevstack.conversationsplus.xml.Element; -import de.thedevstack.conversationsplus.xmpp.forms.Data; -import de.thedevstack.conversationsplus.xmpp.jid.Jid; -import de.thedevstack.conversationsplus.xmpp.pep.Avatar; -import de.thedevstack.conversationsplus.xmpp.stanzas.IqPacket; - -public class IqGenerator extends AbstractGenerator { - - public IqPacket discoResponse(final IqPacket request) { - final IqPacket packet = new IqPacket(IqPacket.TYPE.RESULT); - packet.setId(request.getId()); - packet.setTo(request.getFrom()); - final Element query = packet.addChild("query", - "http://jabber.org/protocol/disco#info"); - query.setAttribute("node", request.query().getAttribute("node")); - final Element identity = query.addChild("identity"); - identity.setAttribute("category", "client"); - identity.setAttribute("type", IDENTITY_TYPE); - identity.setAttribute("name", ConversationsPlusApplication.getNameAndVersion()); - for (final String feature : getFeatures()) { - query.addChild("feature").setAttribute("var", feature); - } - return packet; - } - - public IqPacket versionResponse(final IqPacket request) { - final IqPacket packet = request.generateResponse(IqPacket.TYPE.RESULT); - Element query = packet.query("jabber:iq:version"); - query.addChild("name").setContent(ConversationsPlusApplication.getName()); - query.addChild("version").setContent(ConversationsPlusApplication.getVersion()); - return packet; - } - - public static IqPacket retrieveVcardAvatar(final Avatar avatar) { - final IqPacket packet = new IqPacket(IqPacket.TYPE.GET); - packet.setTo(avatar.owner); - packet.addChild("vCard", "vcard-temp"); - return packet; - } - - public IqPacket queryMessageArchiveManagement(final MessageArchiveService.Query mam) { - final IqPacket packet = new IqPacket(IqPacket.TYPE.SET); - final Element query = packet.query("urn:xmpp:mam:0"); - query.setAttribute("queryid",mam.getQueryId()); - final Data data = new Data(); - data.setFormType("urn:xmpp:mam:0"); - if (mam.muc()) { - packet.setTo(mam.getWith()); - } else if (mam.getWith()!=null) { - data.put("with", mam.getWith().toString()); - } - data.put("start",getTimestamp(mam.getStart())); - data.put("end",getTimestamp(mam.getEnd())); - query.addChild(data); - if (mam.getPagingOrder() == MessageArchiveService.PagingOrder.REVERSE) { - query.addChild("set", "http://jabber.org/protocol/rsm").addChild("before").setContent(mam.getReference()); - } else if (mam.getReference() != null) { - query.addChild("set", "http://jabber.org/protocol/rsm").addChild("after").setContent(mam.getReference()); - } - return packet; - } - public IqPacket generateGetBlockList() { - final IqPacket iq = new IqPacket(IqPacket.TYPE.GET); - iq.addChild("blocklist", Xmlns.BLOCKING); - - return iq; - } - - public IqPacket generateSetBlockRequest(final Jid jid) { - final IqPacket iq = new IqPacket(IqPacket.TYPE.SET); - final Element block = iq.addChild("block", Xmlns.BLOCKING); - block.addChild("item").setAttribute("jid", jid.toBareJid().toString()); - return iq; - } - - public IqPacket generateSetUnblockRequest(final Jid jid) { - final IqPacket iq = new IqPacket(IqPacket.TYPE.SET); - final Element block = iq.addChild("unblock", Xmlns.BLOCKING); - block.addChild("item").setAttribute("jid", jid.toBareJid().toString()); - return iq; - } - - public IqPacket generateSetPassword(final Account account, final String newPassword) { - final IqPacket packet = new IqPacket(IqPacket.TYPE.SET); - packet.setTo(account.getServer()); - final Element query = packet.addChild("query", Xmlns.REGISTER); - final Jid jid = account.getJid(); - query.addChild("username").setContent(jid.getLocalpart()); - query.addChild("password").setContent(newPassword); - return packet; - } - - public IqPacket changeAffiliation(Conversation conference, Jid jid, String affiliation) { - List<Jid> jids = new ArrayList<>(); - jids.add(jid); - return changeAffiliation(conference,jids,affiliation); - } - - public IqPacket changeAffiliation(Conversation conference, List<Jid> jids, String affiliation) { - IqPacket packet = new IqPacket(IqPacket.TYPE.SET); - packet.setTo(conference.getJid().toBareJid()); - packet.setFrom(conference.getAccount().getJid()); - Element query = packet.query("http://jabber.org/protocol/muc#admin"); - for(Jid jid : jids) { - Element item = query.addChild("item"); - item.setAttribute("jid", jid.toString()); - item.setAttribute("affiliation", affiliation); - } - return packet; - } - - public IqPacket changeRole(Conversation conference, String nick, String role) { - IqPacket packet = new IqPacket(IqPacket.TYPE.SET); - packet.setTo(conference.getJid().toBareJid()); - packet.setFrom(conference.getAccount().getJid()); - Element item = packet.query("http://jabber.org/protocol/muc#admin").addChild("item"); - item.setAttribute("nick", nick); - item.setAttribute("role", role); - return packet; - } - - public IqPacket requestHttpUploadSlot(Jid host, DownloadableFile file) { - IqPacket packet = new IqPacket(IqPacket.TYPE.GET); - packet.setTo(host); - Element request = packet.addChild("request",Xmlns.HTTP_UPLOAD); - request.addChild("filename").setContent(file.getName()); - request.addChild("size").setContent(String.valueOf(file.getExpectedSize())); - return packet; - } -} |