use of org.jxmpp.stringprep.XmppStringprepException in project Spark by igniterealtime.
the class RosterDialog method addEntry.
private void addEntry() {
Transport transport = null;
AccountItem item;
if (publicBox.isSelected()) {
item = (AccountItem) accounts.getSelectedItem();
transport = item.getTransport();
}
if (transport == null) {
String jid = getJID();
if (!jid.contains("@")) {
jid = jid + "@" + SparkManager.getConnection().getXMPPServiceDomain();
}
String nickname = nicknameField.getText();
String group = (String) groupBox.getSelectedItem();
jid = UserManager.escapeJID(jid);
BareJid bareJid;
try {
bareJid = JidCreate.bareFrom(jid);
} catch (XmppStringprepException e) {
throw new IllegalStateException(e);
}
// Add as a new entry
addRosterEntry(bareJid, nickname, group);
} else {
String jid = getJID();
try {
jid = Gateway.getJID(transport.getXMPPServiceDomain(), jid);
} catch (SmackException | InterruptedException e) {
Log.error(e);
}
String nickname = nicknameField.getText();
String group = (String) groupBox.getSelectedItem();
BareJid bareJid;
try {
bareJid = JidCreate.bareFrom(jid);
} catch (XmppStringprepException e) {
throw new IllegalStateException(e);
}
addRosterEntry(bareJid, nickname, group);
}
}
use of org.jxmpp.stringprep.XmppStringprepException in project Spark by igniterealtime.
the class BookmarksUI method browseRooms.
public void browseRooms(String serviceNameString) {
DomainBareJid serviceName;
try {
serviceName = JidCreate.domainBareFrom(serviceNameString);
} catch (XmppStringprepException e) {
throw new IllegalStateException(e);
}
browseRooms(serviceName);
}
use of org.jxmpp.stringprep.XmppStringprepException in project Spark by igniterealtime.
the class BookmarksUI method getServicePanel.
private JPanel getServicePanel() {
final JPanel servicePanel = new JPanel();
servicePanel.setOpaque(false);
servicePanel.setLayout(new GridBagLayout());
final JLabel serviceLabel = new JLabel();
final RolloverButton addButton = new RolloverButton(SparkRes.getImageIcon(SparkRes.SMALL_ADD_IMAGE));
addButton.setToolTipText(Res.getString("message.add.conference.service"));
final JTextField serviceField = new JTextField();
servicePanel.add(serviceLabel, new GridBagConstraints(0, 0, 2, 1, 0.0, 0.0, GridBagConstraints.WEST, GridBagConstraints.HORIZONTAL, new Insets(0, 5, 2, 5), 0, 0));
servicePanel.add(serviceField, new GridBagConstraints(0, 1, 1, 1, 1.0, 0.0, GridBagConstraints.WEST, GridBagConstraints.HORIZONTAL, new Insets(0, 5, 2, 5), 0, 0));
servicePanel.add(addButton, new GridBagConstraints(1, 1, 1, 1, 0.0, 0.0, GridBagConstraints.WEST, GridBagConstraints.NONE, new Insets(0, 5, 2, 5), 0, 0));
// Add resource utils
ResourceUtils.resLabel(serviceLabel, serviceField, Res.getString("label.add.conference.service"));
final Action conferenceAction = new AbstractAction() {
private static final long serialVersionUID = 7973928300442518496L;
@Override
public void actionPerformed(ActionEvent e) {
final String conferenceService = serviceField.getText();
if (hasService(conferenceService)) {
UIManager.put("OptionPane.okButtonText", Res.getString("ok"));
JOptionPane.showMessageDialog(null, Res.getString("message.service.already.exists"), Res.getString("title.error"), JOptionPane.ERROR_MESSAGE);
serviceField.setText("");
} else {
final List<DomainBareJid> serviceList = new ArrayList<>();
serviceField.setText(Res.getString("message.searching.please.wait"));
serviceField.setEnabled(false);
addButton.setEnabled(false);
SwingWorker worker = new SwingWorker() {
DiscoverInfo discoInfo;
@Override
public Object construct() {
XMPPConnection connection = SparkManager.getConnection();
ServiceDiscoveryManager discoManager = ServiceDiscoveryManager.getInstanceFor(connection);
try {
DomainBareJid conferenceServiceJid = JidCreate.domainBareFrom(conferenceService);
discoInfo = discoManager.discoverInfo(conferenceServiceJid);
for (DiscoverInfo.Identity identity : discoInfo.getIdentities()) {
if ("conference".equals(identity.getCategory())) {
serviceList.add(conferenceServiceJid);
break;
} else if ("server".equals(identity.getCategory())) {
try {
Collection<DomainBareJid> services = getConferenceServices(conferenceServiceJid);
serviceList.addAll(services);
} catch (Exception e1) {
Log.error("Unable to load conference services in server.", e1);
}
}
}
} catch (XMPPException | SmackException | XmppStringprepException | InterruptedException e1) {
Log.error("Error in disco discovery.", e1);
}
return true;
}
@Override
public void finished() {
if (discoInfo != null) {
for (DomainBareJid aServiceList : serviceList) {
if (!hasService(aServiceList)) {
addServiceToList(aServiceList);
}
}
} else {
UIManager.put("OptionPane.okButtonText", Res.getString("ok"));
JOptionPane.showMessageDialog(SparkManager.getMainWindow(), Res.getString("message.conference.service.error"), Res.getString("title.error"), JOptionPane.ERROR_MESSAGE);
}
serviceField.setText("");
serviceField.setEnabled(true);
addButton.setEnabled(true);
}
};
worker.start();
}
}
};
addButton.addActionListener(conferenceAction);
serviceField.addKeyListener(new KeyAdapter() {
@Override
public void keyPressed(KeyEvent e) {
if (e.getKeyChar() == KeyEvent.VK_ENTER) {
conferenceAction.actionPerformed(null);
}
}
});
return servicePanel;
}
use of org.jxmpp.stringprep.XmppStringprepException in project Spark by igniterealtime.
the class UriManager method handleRemove.
/**
* Handles the ?remove URI
*
* @param uri
* the decoded uri
* @throws Exception
*/
public void handleRemove(URI uri) throws Exception {
// xmpp:romeo@montague.net?remove
BareJid jid;
try {
jid = JidCreate.bareFrom(retrieveJID(uri));
} catch (XmppStringprepException e) {
throw new IllegalStateException(e);
}
Roster roster = Roster.getInstanceFor(SparkManager.getConnection());
RosterEntry entry = roster.getEntry(jid);
roster.removeEntry(entry);
}
use of org.jxmpp.stringprep.XmppStringprepException in project Spark by igniterealtime.
the class UriManager method handleRoster.
/**
* Handles the ?roster URI<br>
* with name= and group=
*
* @param uri
* the decoded uri
* @throws Exception
*/
public void handleRoster(URI uri) throws Exception {
// xmpp:romeo@montague.net?roster
// xmpp:romeo@montague.net?roster;name=Romeo%20Montague
// xmpp:romeo@montague.net?roster;group=Friends
// xmpp:romeo@montague.net?roster;name=Romeo%20Montague;group=Friends
BareJid jid;
try {
jid = JidCreate.bareFrom(retrieveJID(uri));
} catch (XmppStringprepException e) {
throw new IllegalStateException(e);
}
String name = "";
String query = uri.getQuery();
if (query.contains("name=")) {
StringBuilder buf = new StringBuilder();
int x = query.indexOf("name=") + 5;
while (x < query.length() && query.charAt(x) != ';') {
buf.append(query.charAt(x));
x++;
}
}
String group = "";
if (query.contains("group=")) {
StringBuilder buf = new StringBuilder();
int x = query.indexOf("group=") + 6;
while (x < query.length() && query.charAt(x) != ';') {
buf.append(query.charAt(x));
x++;
}
}
Roster roster = Roster.getInstanceFor(SparkManager.getConnection());
RosterEntry userEntry = roster.getEntry(jid);
roster.createEntry(jid, name, new String[] { group });
RosterGroup rosterGroup = roster.getGroup(group);
if (rosterGroup == null) {
rosterGroup = roster.createGroup(group);
}
if (userEntry == null) {
roster.createEntry(jid, name, new String[] { group });
} else {
userEntry.setName(name);
rosterGroup.addEntry(userEntry);
}
}
Aggregations