use of org.jivesoftware.smackx.disco.ServiceDiscoveryManager 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<String> 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() {
ServiceDiscoveryManager discoManager = ServiceDiscoveryManager.getInstanceFor(SparkManager.getConnection());
try {
discoInfo = discoManager.discoverInfo(conferenceService);
for (DiscoverInfo.Identity identity : discoInfo.getIdentities()) {
if ("conference".equals(identity.getCategory())) {
serviceList.add(conferenceService);
break;
} else if ("server".equals(identity.getCategory())) {
try {
Collection<String> services = getConferenceServices(conferenceService);
for (String service : services) {
serviceList.add(service);
}
} catch (Exception e1) {
Log.error("Unable to load conference services in server.", e1);
}
}
}
} catch (XMPPException | SmackException e1) {
Log.error("Error in disco discovery.", e1);
}
return true;
}
@Override
public void finished() {
if (discoInfo != null) {
for (String aServiceList : serviceList) {
if (!hasService(aServiceList)) {
addServiceToList(aServiceList);
}
}
serviceField.setText("");
serviceField.setEnabled(true);
addButton.setEnabled(true);
} 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.jivesoftware.smackx.disco.ServiceDiscoveryManager in project Spark by igniterealtime.
the class ConferenceUtils method getCreationDate.
/**
* Retrieve the date (in yyyyMMdd) format of the time the room was created.
*
* @param roomJID the jid of the room.
* @return the formatted date.
* @throws Exception throws an exception if we are unable to retrieve the date.
*/
public static String getCreationDate(String roomJID) throws Exception {
ServiceDiscoveryManager discoManager = ServiceDiscoveryManager.getInstanceFor(SparkManager.getConnection());
final DateFormat dateFormatter = new SimpleDateFormat("yyyyMMdd'T'HH:mm:ss");
DiscoverInfo infoResult = discoManager.discoverInfo(roomJID);
DataForm dataForm = infoResult.getExtension("x", "jabber:x:data");
if (dataForm == null) {
return "Not available";
}
String creationDate = "";
for (final FormField field : dataForm.getFields()) {
String label = field.getLabel();
if (label != null && "Creation date".equalsIgnoreCase(label)) {
for (String value : field.getValues()) {
creationDate = value;
Date date = dateFormatter.parse(creationDate);
creationDate = DateFormat.getDateTimeInstance(DateFormat.FULL, DateFormat.MEDIUM).format(date);
}
}
}
return creationDate;
}
use of org.jivesoftware.smackx.disco.ServiceDiscoveryManager in project Spark by igniterealtime.
the class UserSearchService method getServices.
/**
* Returns a collection of search services found on the server.
*
* @return a Collection of search services found on the server.
* @throws XMPPException thrown if a server error has occurred.
*/
private Collection<String> getServices() throws Exception {
final Set<String> searchServices = new HashSet<>();
ServiceDiscoveryManager discoManager = ServiceDiscoveryManager.getInstanceFor(SparkManager.getConnection());
DiscoverItems items = SparkManager.getSessionManager().getDiscoveredItems();
for (DiscoverItems.Item item : items.getItems()) {
try {
DiscoverInfo info;
try {
info = discoManager.discoverInfo(item.getEntityID());
} catch (XMPPException | SmackException e) {
// Ignore Case
continue;
}
if (info.containsFeature("jabber:iq:search")) {
// Check that the search service belongs to user searches (and not room searches or other searches)
for (DiscoverInfo.Identity identity : info.getIdentities()) {
if ("directory".equals(identity.getCategory()) && "user".equals(identity.getType())) {
searchServices.add(item.getEntityID());
}
}
}
} catch (Exception e) {
// No info found.
break;
}
}
return searchServices;
}
use of org.jivesoftware.smackx.disco.ServiceDiscoveryManager in project Spark by igniterealtime.
the class Enterprise method populateFeatureSet.
private void populateFeatureSet() {
final ServiceDiscoveryManager disco = ServiceDiscoveryManager.getInstanceFor(SparkManager.getConnection());
final DiscoverItems items = SparkManager.getSessionManager().getDiscoveredItems();
for (DiscoverItems.Item item : items.getItems()) {
String entity = item.getEntityID();
if (entity != null) {
if (entity.startsWith("manager.")) {
sparkManagerInstalled = true;
// Populate with feature sets.
try {
featureInfo = disco.discoverInfo(item.getEntityID());
} catch (XMPPException | SmackException e) {
Log.error("Error while retrieving feature list for SparkManager.", e);
}
}
}
}
}
use of org.jivesoftware.smackx.disco.ServiceDiscoveryManager in project Spark by igniterealtime.
the class PrivacyManager method checkIfPrivacyIsSupported.
private boolean checkIfPrivacyIsSupported(XMPPConnection conn) {
ServiceDiscoveryManager servDisc = ServiceDiscoveryManager.getInstanceFor(conn);
DiscoverInfo info = null;
try {
info = servDisc.discoverInfo(conn.getServiceName());
} catch (XMPPException | SmackException e) {
// We could not query the server
}
if (info != null) {
for (final Feature feature : info.getFeatures()) {
if (feature.getVar().contains("jabber:iq:privacy")) {
return true;
}
}
}
return false;
}
Aggregations