use of org.jivesoftware.smackx.Form in project ecf by eclipse.
the class NodeUtils method getFormFromPacket.
/**
* Get a {@link ConfigureForm} from a packet.
*
* @param packet
* @param elem
* @return The configuration form
*/
public static ConfigureForm getFormFromPacket(Packet packet, PubSubElementType elem) {
FormNode config = (FormNode) packet.getExtension(elem.getElementName(), elem.getNamespace().getXmlns());
Form formReply = config.getForm();
return new ConfigureForm(formReply);
}
use of org.jivesoftware.smackx.Form in project ecf by eclipse.
the class XMPPChatRoomManager method createChatRoom.
/*
* (non-Javadoc)
*
* @see org.eclipse.ecf.presence.chatroom.IChatRoomManager#createChatRoom(java.lang.String,
* java.util.Map)
*/
public IChatRoomInfo createChatRoom(String roomname, Map properties) throws ChatRoomCreateException {
if (roomname == null)
throw new ChatRoomCreateException(roomname, Messages.XMPPChatRoomManager_EXCEPTION_ROOM_CANNOT_BE_NULL);
try {
final String nickname = ecfConnection.getXMPPConnection().getUser();
final String server = ecfConnection.getXMPPConnection().getHost();
final String domain = (properties == null) ? XMPPRoomID.DOMAIN_DEFAULT : (String) properties.get(PROP_XMPP_CONFERENCE);
final String conference = XMPPRoomID.fixConferenceDomain(domain, server);
final String roomID = roomname + XMPPRoomID.AT_SIGN + conference;
// create proxy to the room
final MultiUserChat muc = new MultiUserChat(ecfConnection.getXMPPConnection(), roomID);
if (!checkRoom(conference, roomID)) {
// otherwise create a new one
muc.create(nickname);
muc.sendConfigurationForm(new Form(Form.TYPE_SUBMIT));
final String subject = (properties == null) ? null : (String) properties.get(PROP_XMPP_SUBJECT);
if (subject != null)
muc.changeSubject(subject);
}
String longname = muc.getRoom();
if (longname == null || longname.length() <= 0) {
longname = roomID;
}
final RoomInfo info = MultiUserChat.getRoomInfo(ecfConnection.getXMPPConnection(), roomID);
if (info != null) {
final XMPPRoomID xid = new XMPPRoomID(connectedID.getNamespace(), ecfConnection.getXMPPConnection(), roomID, longname);
return new ECFRoomInfo(xid, info, connectedID);
} else
throw new XMPPException(NLS.bind(Messages.XMPPChatRoomManager_EXCEPTION_NO_ROOM_INFO, roomID));
} catch (final XMPPException e) {
throw new ChatRoomCreateException(roomname, e.getMessage(), e);
} catch (final URISyntaxException e) {
throw new ChatRoomCreateException(roomname, e.getMessage(), e);
}
}
use of org.jivesoftware.smackx.Form in project ecf by eclipse.
the class XMPPUserSearchManager method search.
/**
* Specific implementation for XMPP
*
* @see IUserSearchManager#search(ICriteria).
*/
public ISearch search(ICriteria criteria) throws UserSearchException {
ResultList resultList = new ResultList();
try {
// initialize the form by chance it is null
if (form == null)
form = manager.getSearchForm(ecfConnection.getXMPPConnection(), SERVICE_SEARCH + ecfConnection.getXMPPConnection().getServiceName());
/*
* For XMPP criterion is considered. The XMPP server will deal with
* the search.
*/
List criterions = criteria.getCriterions();
// add the fields for the search dynamically
// consider just the fields used on the search
// fields checked by user
String[] fields = getUserPropertiesFields();
for (int i = 0; i < fields.length; i++) {
Iterator criterionsIterator = criterions.iterator();
// the partial result is added to the result list
while (criterionsIterator.hasNext()) {
ICriterion criterion = (ICriterion) criterionsIterator.next();
if (criterion.equals(fields[i])) {
Form answerForm = form.createAnswerForm();
answerForm.setAnswer(fields[i], true);
answerForm.setAnswer(SEARCH_ACTION, criterion.toExpression());
ReportedData data = manager.sendSearchForm(ecfConnection.getXMPPConnection(), answerForm, SERVICE_SEARCH + ecfConnection.getXMPPConnection().getServiceName());
// create a result list from ReportedData
IResultList partialResultList = createResultList(data);
resultList.addAll(partialResultList.getResults());
}
}
}
return new XMPPSearch(resultList);
} catch (final XMPPException e) {
String message = null;
if (e.getXMPPError() != null && e.getXMPPError().getCode() == 404) {
message = Messages.XMPPContainer_UNRECOGONIZED_SEARCH_SERVICE;
} else {
message = e.getLocalizedMessage();
}
throw new UserSearchException(message, e, criteria);
} catch (ECFException e) {
throw new UserSearchException(e, criteria);
}
}
use of org.jivesoftware.smackx.Form in project Smack by igniterealtime.
the class MultiUserChatCreationTest method testCreateReservedRoom.
/**
* Tests creating a new "Reserved Room".
*/
public void testCreateReservedRoom() {
MultiUserChat muc = new MultiUserChat(getConnection(0), room);
try {
// Create the room
muc.create("testbot1");
// Get the the room's configuration form
Form form = muc.getConfigurationForm();
assertNotNull("No room configuration form", form);
// Create a new form to submit based on the original form
Form submitForm = form.createAnswerForm();
// Add default answers to the form to submit
for (Iterator<FormField> fields = form.getFields(); fields.hasNext(); ) {
FormField field = fields.next();
if (!FormField.TYPE_HIDDEN.equals(field.getType()) && field.getVariable() != null) {
// Sets the default value as the answer
submitForm.setDefaultAnswer(field.getVariable());
}
}
List<String> owners = new ArrayList<String>();
owners.add(getBareJID(0));
submitForm.setAnswer("muc#roomconfig_roomowners", owners);
// Update the new room's configuration
muc.sendConfigurationForm(submitForm);
// Destroy the new room
muc.destroy("The room has almost no activity...", null);
} catch (XMPPException e) {
e.printStackTrace();
fail(e.getMessage());
}
}
use of org.jivesoftware.smackx.Form in project Smack by igniterealtime.
the class MultiUserChatTest method makeRoomModerated.
private void makeRoomModerated() throws XMPPException {
// User1 (which is the room owner) converts the instant room into a moderated room
Form form = muc.getConfigurationForm();
Form answerForm = form.createAnswerForm();
answerForm.setAnswer("muc#roomconfig_moderatedroom", true);
answerForm.setAnswer("muc#roomconfig_whois", Arrays.asList("moderators"));
// Keep the room owner
try {
List<String> owners = new ArrayList<String>();
owners.add(getBareJID(0));
answerForm.setAnswer("muc#roomconfig_roomowners", owners);
} catch (IllegalArgumentException e) {
// Do nothing
}
muc.sendConfigurationForm(answerForm);
}
Aggregations