Search in sources :

Example 21 with XmppStringprepException

use of org.jxmpp.stringprep.XmppStringprepException in project Spark by igniterealtime.

the class UserSearchForm method addSearchServices.

private void addSearchServices() {
    // Populate with Search Services
    servicesBox = new JComboBox<>();
    for (CharSequence searchService : searchServices) {
        String service = searchService.toString();
        servicesBox.addItem(service);
    }
    // Load the property file and add the search services that are read
    final Properties props = new Properties();
    String nextprop;
    boolean numbprop_bool;
    int numbprop;
    if (pluginsettings.exists()) {
        // Log.warning("Search-service Properties-file does exist= " + pluginsettings.getPath());
        try {
            numbprop = 0;
            props.load(new FileInputStream(pluginsettings));
            String testsearch;
            numbprop_bool = true;
            while (numbprop_bool) {
                nextprop = "search" + numbprop;
                testsearch = props.getProperty(nextprop);
                if (null != testsearch) {
                    Log.warning("Search-Info: SearchService-" + numbprop + " from properties-file is " + nextprop + " : " + testsearch);
                    servicesBox.addItem(testsearch);
                    numbprop++;
                } else
                    numbprop_bool = false;
            }
        } catch (IOException ioe) {
            Log.error(ioe);
        }
    }
    if (servicesBox.getItemCount() > 0) {
        servicesBox.setSelectedIndex(0);
    }
    titlePanel = new TitlePanel("", "", SparkRes.getImageIcon(SparkRes.BLANK_IMAGE), true);
    add(titlePanel, new GridBagConstraints(0, 0, 3, 1, 1.0, 0.0, GridBagConstraints.CENTER, GridBagConstraints.HORIZONTAL, new Insets(0, 0, 0, 0), 0, 0));
    // Add Search Service ComboBox
    final JLabel serviceLabel = new JLabel("");
    ResourceUtils.resLabel(serviceLabel, servicesBox, Res.getString("label.search.service") + ":");
    add(serviceLabel, new GridBagConstraints(0, 1, 1, 1, 0.0, 0.0, GridBagConstraints.WEST, GridBagConstraints.NONE, new Insets(5, 5, 5, 5), 0, 0));
    add(servicesBox, new GridBagConstraints(1, 1, 1, 1, 0.0, 0.0, GridBagConstraints.WEST, GridBagConstraints.NONE, new Insets(5, 5, 5, 5), 150, 0));
    final JButton addService = new JButton();
    ResourceUtils.resButton(addService, Res.getString("button.add.service"));
    add(addService, new GridBagConstraints(2, 1, 1, 1, 0.0, 0.0, GridBagConstraints.WEST, GridBagConstraints.NONE, new Insets(5, 5, 5, 5), 0, 0));
    addService.addActionListener(actionEvent -> {
        final String serviceName = JOptionPane.showInputDialog(getRootPane(), Res.getString("message.name.of.search.service.question"), Res.getString("title.add.search.service"), JOptionPane.QUESTION_MESSAGE);
        if (ModelUtil.hasLength(serviceName)) {
            SwingWorker findServiceThread = new SwingWorker() {

                DataForm newForm;

                @Override
                public Object construct() {
                    try {
                        DomainBareJid serviceJid = JidCreate.domainBareFrom(serviceName);
                        newForm = searchManager.getSearchForm(serviceJid);
                    } catch (XMPPException | SmackException | XmppStringprepException | InterruptedException e) {
                    // Nothing to do
                    }
                    return newForm;
                }

                @Override
                public void finished() {
                    if (newForm == null) {
                        UIManager.put("OptionPane.okButtonText", Res.getString("ok"));
                        JOptionPane.showMessageDialog(getGUI(), Res.getString("message.search.service.not.available"), Res.getString("title.notification"), JOptionPane.ERROR_MESSAGE);
                    } else {
                        servicesBox.addItem(serviceName);
                        servicesBox.setSelectedItem(serviceName);
                        int numbprop1 = 0;
                        boolean numbprop_bool1 = true;
                        String nextprop1, testsearch;
                        while (numbprop_bool1) {
                            nextprop1 = "search" + numbprop1;
                            testsearch = props.getProperty(nextprop1);
                            if (testsearch != null)
                                numbprop1++;
                            else {
                                Log.warning("Search-Service: " + nextprop1 + " : " + serviceName + " added");
                                props.setProperty(nextprop1, serviceName);
                                numbprop_bool1 = false;
                            }
                        }
                        try {
                            props.store(new FileOutputStream(pluginsettings), null);
                        } catch (IOException e) {
                            Log.error(e);
                        }
                    }
                }
            };
            findServiceThread.start();
        }
    });
    servicesBox.addActionListener(actionEvent -> {
        SwingWorker worker = new SwingWorker() {

            @Override
            public Object construct() {
                try {
                    Thread.sleep(50);
                } catch (Exception e) {
                    Log.error("Problem sleeping thread.", e);
                }
                return "ok";
            }

            @Override
            public void finished() {
                showService(getSearchService());
            }
        };
        worker.start();
    });
    add(cardPanel, new GridBagConstraints(0, 3, 3, 1, 1.0, 1.0, GridBagConstraints.WEST, GridBagConstraints.BOTH, new Insets(5, 5, 5, 5), 0, 0));
}
Also used : GridBagConstraints(java.awt.GridBagConstraints) Insets(java.awt.Insets) SmackException(org.jivesoftware.smack.SmackException) JButton(javax.swing.JButton) JLabel(javax.swing.JLabel) IOException(java.io.IOException) XmppStringprepException(org.jxmpp.stringprep.XmppStringprepException) Properties(java.util.Properties) FileInputStream(java.io.FileInputStream) TitlePanel(org.jivesoftware.spark.component.TitlePanel) SmackException(org.jivesoftware.smack.SmackException) IOException(java.io.IOException) XmppStringprepException(org.jxmpp.stringprep.XmppStringprepException) XMPPException(org.jivesoftware.smack.XMPPException) FileOutputStream(java.io.FileOutputStream) DataForm(org.jivesoftware.smackx.xdata.packet.DataForm) SwingWorker(org.jivesoftware.spark.util.SwingWorker) XMPPException(org.jivesoftware.smack.XMPPException) DomainBareJid(org.jxmpp.jid.DomainBareJid)

Example 22 with XmppStringprepException

use of org.jxmpp.stringprep.XmppStringprepException in project Zom-Android by zom.

the class ChatSession method initJid.

private void initJid() {
    try {
        mJid = JidCreate.from(mParticipant.getAddress().getAddress());
        mXa = new XmppAddress(mJid.toString());
        if (mJid.hasNoResource()) {
            if (!TextUtils.isEmpty(mParticipant.getAddress().getResource())) {
                mJid = JidCreate.from(mParticipant.getAddress().getAddress());
            } else if (mParticipant instanceof Contact) {
                String resource = ((Contact) mParticipant).getPresence().getResource();
                if (!TextUtils.isEmpty(resource)) {
                    mJid = JidCreate.from(mParticipant.getAddress().getBareAddress() + '/' + resource);
                }
            }
            mXa = new XmppAddress(mJid.toString());
        }
        // not for groups yet
        if (mParticipant instanceof Contact) {
            // if we can't omemo, check it again to be sure
            if (!mCanOmemo) {
                mCanOmemo = mManager.resourceSupportsOmemo(mJid);
            }
        }
    } catch (XmppStringprepException xe) {
        throw new RuntimeException("Error with address that shouldn't happen: " + xe);
    }
}
Also used : XmppAddress(org.awesomeapp.messenger.plugin.xmpp.XmppAddress) XmppStringprepException(org.jxmpp.stringprep.XmppStringprepException)

Example 23 with XmppStringprepException

use of org.jxmpp.stringprep.XmppStringprepException in project xabber-android by redsolution.

the class AvatarManager method onLoad.

@Override
public void onLoad() {
    final Map<Jid, String> hashes = new HashMap<>();
    final Map<String, Bitmap> bitmaps = new HashMap<>();
    Cursor cursor = AvatarTable.getInstance().list();
    try {
        if (cursor.moveToFirst()) {
            do {
                String hash = AvatarTable.getHash(cursor);
                try {
                    Jid jid = JidCreate.from(AvatarTable.getUser(cursor));
                    hashes.put(jid, hash == null ? EMPTY_HASH : hash);
                } catch (XmppStringprepException e) {
                    LogManager.exception(this, e);
                }
            } while (cursor.moveToNext());
        }
    } finally {
        cursor.close();
    }
    for (String hash : new HashSet<>(hashes.values())) if (!hash.equals(EMPTY_HASH)) {
        Bitmap bitmap = makeBitmap(AvatarStorage.getInstance().read(hash));
        bitmaps.put(hash, bitmap == null ? EMPTY_BITMAP : bitmap);
    }
    Application.getInstance().runOnUiThread(new Runnable() {

        @Override
        public void run() {
            onLoaded(hashes, bitmaps);
        }
    });
}
Also used : Bitmap(android.graphics.Bitmap) UserJid(com.xabber.android.data.entity.UserJid) AccountJid(com.xabber.android.data.entity.AccountJid) Jid(org.jxmpp.jid.Jid) HashMap(java.util.HashMap) XmppStringprepException(org.jxmpp.stringprep.XmppStringprepException) Cursor(android.database.Cursor) HashSet(java.util.HashSet)

Example 24 with XmppStringprepException

use of org.jxmpp.stringprep.XmppStringprepException in project xabber-android by redsolution.

the class AccountEditorFragment method setValues.

@Override
protected boolean setValues(Map<String, Object> source, Map<String, Object> result) {
    if (listener == null) {
        return false;
    }
    ProxyType proxyType = ProxyType.values()[getInt(result, R.string.account_proxy_type_key)];
    if (proxyType == ProxyType.orbot && !OrbotHelper.isOrbotInstalled()) {
        listener.showOrbotDialog();
        return false;
    }
    DomainBareJid serverName;
    Localpart userName;
    Resourcepart resource;
    try {
        serverName = JidCreate.domainBareFrom(getString(result, R.string.account_server_key).trim());
        userName = Localpart.from(getString(result, R.string.account_username_key).trim());
        resource = Resourcepart.from(getString(result, R.string.account_resource_key).trim());
    } catch (XmppStringprepException e) {
        LogManager.exception(this, e);
        return false;
    }
    AccountManager.getInstance().updateAccount(listener.getAccount(), getBoolean(result, R.string.account_custom_key), getString(result, R.string.account_host_key), getInt(result, R.string.account_port_key), serverName, userName, getBoolean(result, R.string.account_store_password_key), getString(result, R.string.account_password_key), "", resource, getInt(result, R.string.account_priority_key), getBoolean(result, R.string.account_enabled_key), getBoolean(result, R.string.account_sasl_key), TLSMode.values()[getInt(result, R.string.account_tls_mode_key)], getBoolean(result, R.string.account_compression_key), proxyType, getString(result, R.string.account_proxy_host_key), getInt(result, R.string.account_proxy_port_key), getString(result, R.string.account_proxy_user_key), getString(result, R.string.account_proxy_password_key), getBoolean(result, R.string.account_syncable_key), ArchiveMode.values()[getInt(result, R.string.account_archive_mode_key)], getInt(result, R.string.account_color_key));
    return true;
}
Also used : Localpart(org.jxmpp.jid.parts.Localpart) ProxyType(com.xabber.android.data.connection.ProxyType) XmppStringprepException(org.jxmpp.stringprep.XmppStringprepException) DomainBareJid(org.jxmpp.jid.DomainBareJid) Resourcepart(org.jxmpp.jid.parts.Resourcepart)

Example 25 with XmppStringprepException

use of org.jxmpp.stringprep.XmppStringprepException in project xabber-android by redsolution.

the class SSNManager method setSessionOtrMode.

/**
 * Sets OTR mode for the session and starts negotiation / renegotiation.
 */
public void setSessionOtrMode(String account, String user, String session, OtrMode otrMode) {
    if (sessionOtrs.get(account, session) == otrMode) {
        return;
    }
    sessionOtrs.put(account, session, otrMode);
    SessionState state = sessionStates.get(account, session);
    DataForm dataForm = Feature.createDataForm(DataForm.Type.form);
    Feature.addLoggingField(dataForm, otrMode.getLoggingValues(), otrMode.getLoggingValues()[0]);
    Feature.addDisclosureField(dataForm, DisclosureValue.values(), otrMode.getDisclosureValue());
    Feature.addSecurityField(dataForm, SecurityValue.values(), otrMode.getSecurityValue());
    if (state == null || state == SessionState.requesting) {
        sessionStates.put(account, session, SessionState.requesting);
        Feature.addAcceptField(dataForm, true);
    } else {
        sessionStates.put(account, session, SessionState.renegotiation);
        Feature.addRenegotiateField(dataForm, true);
    }
    try {
        sendFeature(AccountJid.from(account), JidCreate.from(user), session, new Feature(dataForm));
    } catch (XmppStringprepException e) {
        LogManager.exception(this, e);
    }
}
Also used : DataForm(org.jivesoftware.smackx.xdata.packet.DataForm) XmppStringprepException(org.jxmpp.stringprep.XmppStringprepException) Feature(com.xabber.xmpp.ssn.Feature)

Aggregations

XmppStringprepException (org.jxmpp.stringprep.XmppStringprepException)76 DomainBareJid (org.jxmpp.jid.DomainBareJid)20 SmackException (org.jivesoftware.smack.SmackException)18 Jid (org.jxmpp.jid.Jid)18 EntityBareJid (org.jxmpp.jid.EntityBareJid)16 AccountJid (com.xabber.android.data.entity.AccountJid)12 XMPPException (org.jivesoftware.smack.XMPPException)12 UserJid (com.xabber.android.data.entity.UserJid)11 BareJid (org.jxmpp.jid.BareJid)9 Resourcepart (org.jxmpp.jid.parts.Resourcepart)9 ArrayList (java.util.ArrayList)8 Localpart (org.jxmpp.jid.parts.Localpart)8 Cursor (android.database.Cursor)5 NoSuchAlgorithmException (java.security.NoSuchAlgorithmException)5 HashMap (java.util.HashMap)5 SwingWorker (org.jivesoftware.spark.util.SwingWorker)5 IOException (java.io.IOException)4 KeyManagementException (java.security.KeyManagementException)4 NetworkException (com.xabber.android.data.NetworkException)3 InetAddress (java.net.InetAddress)3