use of org.jxmpp.stringprep.XmppStringprepException in project Spark by igniterealtime.
the class JoinRoomSwingWorker method construct.
@Override
public Object construct() {
try {
groupChat = MultiUserChatManager.getInstanceFor(SparkManager.getConnection()).getMultiUserChat(roomJID);
// Create a UI component, if one was not yet created. It is important that this happens before the MUC is
// joined server-side, as the UI component needs to be able to display data that is sent by the server upon
// joining the room.
ChatRoom room;
try {
final EntityBareJid roomName = groupChat.getRoom();
room = SparkManager.getChatManager().getChatContainer().getChatRoom(roomName);
} catch (ChatRoomNotFoundException e) {
room = UIComponentRegistry.createGroupChatRoom(groupChat);
((GroupChatRoom) room).setPassword(password);
((GroupChatRoom) room).setTabTitle(tabTitle);
}
// Use the default nickname, if none has been provided.
if (nickname == null) {
nickname = SettingsManager.getRelodLocalPreferences().getNickname();
}
// Join the MUC server-sided, if we're not already in.
if (!groupChat.isJoined()) {
if (password == null && ConferenceUtils.isPasswordRequired(roomJID)) {
JLabel label = new JLabel(Res.getString("message.enter.room.password"));
JPasswordField passwordField = new JPasswordField();
passwordField.addAncestorListener(new RequestFocusListener());
JOptionPane.showConfirmDialog(null, new Object[] { label, passwordField }, Res.getString("title.password.required"), JOptionPane.OK_CANCEL_OPTION);
password = new String(passwordField.getPassword());
if (!ModelUtil.hasLength(password)) {
return null;
}
}
if (!ConferenceUtils.confirmToRevealVisibility()) {
return null;
}
if (ModelUtil.hasLength(password)) {
groupChat.join(nickname, password);
} else {
groupChat.join(nickname);
}
}
return room;
} catch (XMPPException | SmackException | InterruptedException ex) {
Log.error("An exception occurred while trying to join room '" + roomJID + "'.", ex);
StanzaError error = null;
if (ex instanceof XMPPException.XMPPErrorException) {
error = ((XMPPException.XMPPErrorException) ex).getStanzaError();
if (StanzaError.Condition.conflict.equals(error.getCondition())) {
final Object userInput = JOptionPane.showInputDialog(SparkManager.getMainWindow(), Res.getString("message.nickname.in.use"), Res.getString("title.change.nickname"), JOptionPane.WARNING_MESSAGE, null, // null selection values implies text field.
null, nickname);
if (userInput != null) {
Log.debug("Retry joining room '" + roomJID + "', using nickname: " + userInput);
try {
this.nickname = Resourcepart.from((String) userInput);
} catch (XmppStringprepException e) {
throw new IllegalStateException(e);
}
return construct();
}
}
}
final String errorText = ConferenceUtils.getReason(error);
errors.add(errorText);
return null;
}
}
use of org.jxmpp.stringprep.XmppStringprepException in project Spark by igniterealtime.
the class RoomCreationDialog method createGroupChat.
public MultiUserChat createGroupChat(Component parent, final DomainBareJid serviceName) {
final JOptionPane pane;
final JDialog dlg;
TitlePanel titlePanel;
// Create the title panel for this dialog
titlePanel = new TitlePanel(Res.getString("title.create.or.join"), Res.getString("message.create.or.join.room"), SparkRes.getImageIcon(SparkRes.BLANK_24x24), true);
// Construct main panel w/ layout.
final JPanel mainPanel = new JPanel();
mainPanel.setLayout(new BorderLayout());
mainPanel.add(titlePanel, BorderLayout.NORTH);
// The user should only be able to close this dialog.
Object[] options = { Res.getString("create"), Res.getString("close") };
pane = new JOptionPane(this, JOptionPane.PLAIN_MESSAGE, JOptionPane.OK_CANCEL_OPTION, null, options, options[0]);
mainPanel.add(pane, BorderLayout.CENTER);
JOptionPane p = new JOptionPane();
dlg = p.createDialog(parent, Res.getString("title.conference.rooms"));
dlg.pack();
dlg.setSize(400, 350);
dlg.setContentPane(mainPanel);
dlg.setLocationRelativeTo(parent);
PropertyChangeListener changeListener = new PropertyChangeListener() {
@Override
public void propertyChange(PropertyChangeEvent e) {
Object o = pane.getValue();
if (o instanceof Integer) {
dlg.setVisible(false);
return;
}
String value = (String) pane.getValue();
if (Res.getString("close").equals(value)) {
dlg.setVisible(false);
} else if (Res.getString("create").equals(value)) {
boolean isValid = validatePanel();
if (isValid) {
String roomJidString = nameField.getText().replaceAll(" ", "_") + "@" + serviceName;
EntityBareJid room;
try {
room = JidCreate.entityBareFrom(roomJidString);
} catch (XmppStringprepException ex) {
throw new IllegalStateException(ex);
}
try {
MultiUserChatManager.getInstanceFor(SparkManager.getConnection()).getRoomInfo(room);
// JOptionPane.showMessageDialog(dlg, "Room already exists. Please specify a unique room name.", "Room Exists", JOptionPane.ERROR_MESSAGE);
// pane.setValue(JOptionPane.UNINITIALIZED_VALUE);
pane.removePropertyChangeListener(this);
dlg.setVisible(false);
ConferenceUtils.joinConferenceRoom(room.toString(), room);
return;
} catch (XMPPException | SmackException | InterruptedException e1) {
// Nothing to do
}
groupChat = createGroupChat(nameField.getText(), serviceName);
if (groupChat == null) {
showError("Could not join chat " + nameField.getText());
pane.setValue(JOptionPane.UNINITIALIZED_VALUE);
} else {
pane.removePropertyChangeListener(this);
dlg.setVisible(false);
}
} else {
pane.setValue(JOptionPane.UNINITIALIZED_VALUE);
}
}
}
};
pane.addPropertyChangeListener(changeListener);
nameField.requestFocusInWindow();
dlg.setVisible(true);
dlg.toFront();
dlg.requestFocus();
return groupChat;
}
use of org.jxmpp.stringprep.XmppStringprepException in project Spark by igniterealtime.
the class GroupChatParticipantList method unbanUser.
protected void unbanUser(String jidString) {
try {
Jid jid = JidCreate.from(jidString);
chat.grantMembership(jid);
} catch (XMPPException | SmackException | XmppStringprepException | InterruptedException e) {
groupChatRoom.getTranscriptWindow().insertNotificationMessage("No can do " + e.getMessage(), ChatManager.ERROR_COLOR);
}
}
use of org.jxmpp.stringprep.XmppStringprepException in project Spark by igniterealtime.
the class UriManager method handleUnsubscribe.
/**
* Handles the ?unsubscribe URI
*
* @param uri
* the decoded uri
*/
public void handleUnsubscribe(URI uri) throws SmackException.NotConnectedException {
Jid jid;
try {
jid = JidCreate.from(retrieveJID(uri));
} catch (XmppStringprepException e) {
throw new IllegalStateException(e);
}
Presence response = new Presence(Presence.Type.unsubscribe);
response.setTo(jid);
try {
SparkManager.getConnection().sendStanza(response);
} catch (InterruptedException e) {
throw new IllegalStateException(e);
}
}
use of org.jxmpp.stringprep.XmppStringprepException in project Spark by igniterealtime.
the class BookmarksUI method checkPopup.
private void checkPopup(MouseEvent mouseEvent) {
// Handle no path for x y coordinates
if (tree.getPathForLocation(mouseEvent.getX(), mouseEvent.getY()) == null) {
return;
}
final JiveTreeNode node = (JiveTreeNode) tree.getPathForLocation(mouseEvent.getX(), mouseEvent.getY()).getLastPathComponent();
if (mouseEvent.isPopupTrigger() && node != null) {
JPopupMenu popupMenu = new JPopupMenu();
// Define service actions
Action browseAction = new AbstractAction() {
private static final long serialVersionUID = -8866708581713789939L;
@Override
public void actionPerformed(ActionEvent actionEvent) {
browseRooms(node.toString());
}
};
browseAction.putValue(Action.NAME, Res.getString("menuitem.browse.service"));
browseAction.putValue(Action.SMALL_ICON, SparkRes.getImageIcon(SparkRes.SMALL_DATA_FIND_IMAGE));
Action removeServiceAction = new AbstractAction() {
private static final long serialVersionUID = -5276754429117462223L;
@Override
public void actionPerformed(ActionEvent actionEvent) {
DefaultTreeModel treeModel = (DefaultTreeModel) tree.getModel();
treeModel.removeNodeFromParent(node);
}
};
removeServiceAction.putValue(Action.NAME, Res.getString("menuitem.remove.service"));
removeServiceAction.putValue(Action.SMALL_ICON, SparkRes.getImageIcon(SparkRes.SMALL_DELETE));
JMenuItem browseServiceMenu = new JMenuItem(browseAction);
JMenuItem removeServiceMenu = new JMenuItem(removeServiceAction);
// Define room actions
Action joinRoomAction = new AbstractAction() {
private static final long serialVersionUID = -356016505214728244L;
@Override
public void actionPerformed(ActionEvent actionEvent) {
String roomName = node.getUserObject().toString();
String roomJIDString = node.getAssociatedObject().toString();
EntityBareJid roomJID = JidCreate.entityBareFromUnescapedOrThrowUnchecked(roomJIDString);
ConferenceUtils.joinConferenceOnSeperateThread(roomName, roomJID, null);
}
};
joinRoomAction.putValue(Action.NAME, Res.getString("menuitem.join.room"));
joinRoomAction.putValue(Action.SMALL_ICON, SparkRes.getImageIcon(SparkRes.SMALL_USER_ENTER));
Action removeRoomAction = new AbstractAction() {
private static final long serialVersionUID = -7560090091884746914L;
@Override
public void actionPerformed(ActionEvent actionEvent) {
DefaultTreeModel treeModel = (DefaultTreeModel) tree.getModel();
treeModel.removeNodeFromParent(node);
String roomJIDString = node.getAssociatedObject().toString();
EntityBareJid roomJID;
try {
roomJID = JidCreate.entityBareFrom(roomJIDString);
} catch (XmppStringprepException e) {
Log.error("Not a JID", e);
return;
}
autoJoinRooms.remove(roomJID);
removeBookmark(roomJID);
}
};
removeRoomAction.putValue(Action.NAME, Res.getString("menuitem.remove.bookmark"));
removeRoomAction.putValue(Action.SMALL_ICON, SparkRes.getImageIcon(SparkRes.DELETE_BOOKMARK_ICON));
JMenuItem joinRoomMenu = new JMenuItem(joinRoomAction);
JMenuItem removeRoomMenu = new JMenuItem(removeRoomAction);
if (node.getAllowsChildren()) {
popupMenu.add(browseServiceMenu);
popupMenu.add(removeServiceMenu);
} else {
popupMenu.add(joinRoomMenu);
popupMenu.add(removeRoomMenu);
popupMenu.addSeparator();
Action autoJoin = new AbstractAction() {
private static final long serialVersionUID = 7857469398581933449L;
@Override
public void actionPerformed(ActionEvent e) {
String roomJIDString = node.getAssociatedObject().toString();
EntityBareJid roomJID;
try {
roomJID = JidCreate.entityBareFrom(roomJIDString);
} catch (XmppStringprepException e1) {
Log.error("Not a JID", e1);
return;
}
if (autoJoinRooms.contains(roomJID)) {
autoJoinRooms.remove(roomJID);
} else {
autoJoinRooms.add(roomJID);
}
String name = node.getUserObject().toString();
addBookmark(name, roomJID, autoJoinRooms.contains(roomJID));
}
};
autoJoin.putValue(Action.NAME, Res.getString("menuitem.join.on.startup"));
JCheckBoxMenuItem item = new JCheckBoxMenuItem(autoJoin);
String roomJIDString = node.getAssociatedObject().toString();
EntityBareJid roomJID;
try {
roomJID = JidCreate.entityBareFrom(roomJIDString);
} catch (XmppStringprepException e1) {
Log.error("Not a JID", e1);
return;
}
item.setSelected(autoJoinRooms.contains(roomJID));
popupMenu.add(item);
// Define service actions
Action roomInfoAction = new AbstractAction() {
private static final long serialVersionUID = -8336773839944003744L;
@Override
public void actionPerformed(ActionEvent actionEvent) {
String roomJIDString = node.getAssociatedObject().toString();
EntityBareJid roomJID;
try {
roomJID = JidCreate.entityBareFrom(roomJIDString);
} catch (XmppStringprepException e) {
throw new IllegalStateException(e);
}
RoomBrowser roomBrowser = new RoomBrowser();
roomBrowser.displayRoomInformation(roomJID);
}
};
roomInfoAction.putValue(Action.NAME, Res.getString("menuitem.view.room.info"));
roomInfoAction.putValue(Action.SMALL_ICON, SparkRes.getImageIcon(SparkRes.SMALL_DATA_FIND_IMAGE));
popupMenu.add(roomInfoAction);
}
// Fire menu listeners
fireContextMenuListeners(popupMenu, node);
// Display popup menu.
popupMenu.show(tree, mouseEvent.getX(), mouseEvent.getY());
}
}
Aggregations