-
Notifications
You must be signed in to change notification settings - Fork 40
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
18 changed files
with
1,899 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
68 changes: 68 additions & 0 deletions
68
src/main/java/org/buddycloud/channelserver/packetprocessor/iq/namespace/search/Search.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
package org.buddycloud.channelserver.packetprocessor.iq.namespace.search; | ||
|
||
import java.util.Collection; | ||
import java.util.concurrent.BlockingQueue; | ||
|
||
import org.apache.log4j.Logger; | ||
import org.buddycloud.channelserver.Configuration; | ||
import org.buddycloud.channelserver.channel.ChannelManager; | ||
import org.buddycloud.channelserver.channel.Conf; | ||
import org.buddycloud.channelserver.db.exception.NodeStoreException; | ||
import org.buddycloud.channelserver.packetprocessor.PacketProcessor; | ||
import org.buddycloud.channelserver.packetprocessor.iq.namespace.pubsub.JabberPubsub; | ||
import org.buddycloud.channelserver.pubsub.accessmodel.AccessModels; | ||
import org.buddycloud.channelserver.pubsub.model.impl.NodeSubscriptionImpl; | ||
import org.buddycloud.channelserver.pubsub.subscription.Subscriptions; | ||
import org.dom4j.Element; | ||
import org.dom4j.QName; | ||
import org.xmpp.packet.IQ; | ||
import org.xmpp.packet.IQ.Type; | ||
import org.xmpp.packet.JID; | ||
import org.xmpp.packet.Packet; | ||
import org.xmpp.packet.PacketError; | ||
|
||
public class Search implements PacketProcessor<IQ> { | ||
|
||
public static final String ELEMENT_NAME = "query"; | ||
private static final Logger logger = Logger.getLogger(Search.class); | ||
|
||
public static final String NAMESPACE_URI = "jabber:iq:search"; | ||
|
||
private final BlockingQueue<Packet> outQueue; | ||
private final ChannelManager channelManager; | ||
private IQ request; | ||
|
||
private SearchGet searchGet; | ||
private SearchSet searchSet; | ||
|
||
public Search(BlockingQueue<Packet> outQueue, | ||
ChannelManager channelManager) { | ||
this.outQueue = outQueue; | ||
this.channelManager = channelManager; | ||
|
||
this.searchGet = new SearchGet(outQueue, channelManager); | ||
this.searchSet = new SearchSet(outQueue, channelManager); | ||
} | ||
|
||
@Override | ||
public void process(IQ reqIQ) throws Exception { | ||
request = reqIQ; | ||
if (request.getType().equals(Type.get)) { | ||
logger.trace("Using search processor: SearchGet"); | ||
this.searchGet.process(request); | ||
return; | ||
} else if (request.getType().equals(Type.set)) { | ||
logger.trace("Using search processor: SearchSet"); | ||
this.searchSet.process(request); | ||
return; | ||
} | ||
IQ response = IQ.createResultIQ(request); | ||
response.setType(IQ.Type.error); | ||
PacketError error = new PacketError( | ||
PacketError.Condition.bad_request, | ||
PacketError.Type.modify | ||
); | ||
response.setError(error); | ||
outQueue.put(response); | ||
} | ||
} |
94 changes: 94 additions & 0 deletions
94
...main/java/org/buddycloud/channelserver/packetprocessor/iq/namespace/search/SearchGet.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,94 @@ | ||
package org.buddycloud.channelserver.packetprocessor.iq.namespace.search; | ||
|
||
import java.util.concurrent.BlockingQueue; | ||
|
||
import org.buddycloud.channelserver.channel.ChannelManager; | ||
import org.buddycloud.channelserver.packetprocessor.PacketProcessor; | ||
import org.dom4j.Element; | ||
import org.xmpp.forms.DataForm; | ||
import org.xmpp.packet.IQ; | ||
import org.xmpp.packet.Packet; | ||
import org.xmpp.packet.PacketError; | ||
import org.xmpp.packet.PacketError.Type; | ||
|
||
public class SearchGet implements PacketProcessor<IQ> { | ||
|
||
public static final String INSTRUCTIONS = "Search for content/hashtags/mentions"; | ||
|
||
public static final String TITLE = "Please populate one or more of the following fields"; | ||
public static final String CONTENT_FIELD_LABEL = "Content search"; | ||
public static final String AUTHOR_FIELD_LABEL = "Author"; | ||
public static final String RPP_FIELD_LABEL = "Results per page"; | ||
public static final String PAGE_FIELD_LABEL = "Page"; | ||
|
||
private ChannelManager channelManager; | ||
private BlockingQueue<Packet> outQueue; | ||
private IQ response; | ||
|
||
private Element x; | ||
|
||
public SearchGet(BlockingQueue<Packet> outQueue, | ||
ChannelManager channelManager) { | ||
this.channelManager = channelManager; | ||
this.outQueue = outQueue; | ||
} | ||
|
||
@Override | ||
public void process(IQ request) throws Exception { | ||
response = IQ.createResultIQ(request); | ||
|
||
if (false == channelManager.isLocalJID(request.getFrom())) { | ||
sendErrorResponse(PacketError.Type.cancel, | ||
PacketError.Condition.not_allowed); | ||
return; | ||
} | ||
|
||
Element query = response.getElement().addElement("query"); | ||
query.addAttribute("xmlns", Search.NAMESPACE_URI); | ||
query.addElement("instructions").addText(INSTRUCTIONS); | ||
x = query.addElement("x"); | ||
addFields(); | ||
outQueue.put(response); | ||
} | ||
|
||
private void addFields() { | ||
x.addAttribute("xmlns", DataForm.NAMESPACE); | ||
x.addElement("title").addText(TITLE); | ||
x.addElement("instructions").addText(INSTRUCTIONS); | ||
|
||
Element formType = x.addElement("field"); | ||
formType.addAttribute("type", "hidden"); | ||
formType.addAttribute("var", "FORM_TYPE"); | ||
formType.addElement("value").addText(Search.NAMESPACE_URI); | ||
|
||
Element content = x.addElement("field"); | ||
content.addAttribute("type", "text-multi"); | ||
content.addAttribute("var", "content"); | ||
content.addAttribute("label", CONTENT_FIELD_LABEL); | ||
|
||
Element author = x.addElement("field"); | ||
author.addAttribute("type", "jid-single"); | ||
author.addAttribute("var", "author"); | ||
author.addAttribute("label", AUTHOR_FIELD_LABEL); | ||
|
||
Element rpp = x.addElement("field"); | ||
rpp.addAttribute("type", "fixed"); | ||
rpp.addAttribute("var", "rpp"); | ||
rpp.addAttribute("label", RPP_FIELD_LABEL); | ||
|
||
Element page = x.addElement("field"); | ||
page.addAttribute("type", "fixed"); | ||
page.addAttribute("var", "page"); | ||
page.addAttribute("label", PAGE_FIELD_LABEL); | ||
} | ||
|
||
private void sendErrorResponse(PacketError.Type type, | ||
PacketError.Condition condition) throws InterruptedException { | ||
response.setType(IQ.Type.error); | ||
PacketError error = new PacketError(PacketError.Condition.not_allowed, | ||
PacketError.Type.cancel); | ||
response.setError(error); | ||
outQueue.put(response); | ||
} | ||
|
||
} |
Oops, something went wrong.