/**
   * Initializes the service implementation, and puts it in a sate where it could interoperate with
   * other services. It is strongly recomended that properties in this Map be mapped to property
   * names as specified by <tt>AccountProperties</tt>.
   *
   * @param userID the user id of the ssh account we're currently initializing
   * @param accountID the identifier of the account that this protocol provider represents.
   * @see net.java.sip.communicator.service.protocol.AccountID
   */
  protected void initialize(String userID, AccountID accountID) {
    synchronized (initializationLock) {
      this.accountID = accountID;

      // initialize the presence operationset
      OperationSetPersistentPresenceSSHImpl persistentPresence =
          new OperationSetPersistentPresenceSSHImpl(this);

      supportedOperationSets.put(
          OperationSetPersistentPresence.class.getName(), persistentPresence);

      // register it once again for those that simply need presence and
      // won't be smart enough to check for a persistent presence
      // alternative
      supportedOperationSets.put(OperationSetPresence.class.getName(), persistentPresence);

      // initialize the IM operation set
      basicInstantMessaging = new OperationSetBasicInstantMessagingSSHImpl(this);

      supportedOperationSets.put(
          OperationSetBasicInstantMessaging.class.getName(), basicInstantMessaging);

      // initialze the file transfer operation set
      fileTranfer = new OperationSetFileTransferSSHImpl(this);

      supportedOperationSets.put(OperationSetFileTransfer.class.getName(), fileTranfer);

      isInitialized = true;
    }
  }
Ejemplo n.º 2
0
  /**
   * Implements CallListener.callEnded. Stops sounds that are playing at the moment if there're any.
   * Removes the call panel and disables the hangup button.
   */
  public void callEnded(CallEvent event) {
    Call sourceCall = event.getSourceCall();

    NotificationManager.stopSound(NotificationManager.BUSY_CALL);
    NotificationManager.stopSound(NotificationManager.INCOMING_CALL);
    NotificationManager.stopSound(NotificationManager.OUTGOING_CALL);

    if (activeCalls.get(sourceCall) != null) {
      CallPanel callPanel = (CallPanel) activeCalls.get(sourceCall);

      this.removeCallPanelWait(callPanel);
    }
  }
Ejemplo n.º 3
0
  static {
    iconsTable.put(
        ProtocolIcon.ICON_SIZE_16x16, getImageInBytes("service.protocol.yahoo.YAHOO_16x16"));

    iconsTable.put(
        ProtocolIcon.ICON_SIZE_32x32, getImageInBytes("service.protocol.yahoo.YAHOO_32x32"));

    iconsTable.put(
        ProtocolIcon.ICON_SIZE_48x48, getImageInBytes("service.protocol.yahoo.YAHOO_48x48"));

    iconsTable.put(
        ProtocolIcon.ICON_SIZE_64x64, getImageInBytes("service.protocol.yahoo.YAHOO_64x64"));
  }
  /**
   * Initializes and creates an account corresponding to the specified accountProperties and
   * registers the resulting ProtocolProvider in the <tt>context</tt> BundleContext parameter.
   *
   * @param accountProperties a set of protocol (or implementation) specific properties defining the
   *     new account.
   * @return the AccountID of the newly created account
   */
  protected AccountID loadAccount(Map accountProperties) {
    BundleContext context = SipActivator.getBundleContext();
    if (context == null) throw new NullPointerException("The specified BundleContext was null");

    String userIDStr = (String) accountProperties.get(USER_ID);
    if (userIDStr == null)
      throw new NullPointerException("The account properties contained no user id.");

    if (accountProperties == null)
      throw new NullPointerException("The specified property map was null");

    String serverAddress = (String) accountProperties.get(SERVER_ADDRESS);

    if (serverAddress == null)
      throw new NullPointerException(serverAddress + " is not a valid ServerAddress");

    if (!accountProperties.containsKey(PROTOCOL))
      accountProperties.put(PROTOCOL, ProtocolNames.SIP);

    SipAccountID accountID = new SipAccountID(userIDStr, accountProperties, serverAddress);

    // get a reference to the configuration service and register whatever
    // properties we have in it.

    Hashtable properties = new Hashtable();
    properties.put(PROTOCOL, ProtocolNames.SIP);
    properties.put(USER_ID, userIDStr);

    ProtocolProviderServiceSipImpl sipProtocolProvider = new ProtocolProviderServiceSipImpl();

    try {
      sipProtocolProvider.initialize(userIDStr, accountID);

      // We store again the account in order to store all properties added
      // during the protocol provider initialization.
      this.storeAccount(SipActivator.getBundleContext(), accountID);
    } catch (OperationFailedException ex) {
      logger.error("Failed to initialize account", ex);
      throw new IllegalArgumentException("Failed to initialize account" + ex.getMessage());
    }

    ServiceRegistration registration =
        context.registerService(
            ProtocolProviderService.class.getName(), sipProtocolProvider, properties);

    registeredAccounts.put(accountID, registration);
    return accountID;
  }
  /**
   * Removes the specified account from the list of accounts that this provider factory is handling.
   * If the specified accountID is unknown to the ProtocolProviderFactory, the call has no effect
   * and false is returned. This method is persistent in nature and once called the account
   * corresponding to the specified ID will not be loaded during future runs of the project.
   *
   * @param accountID the ID of the account to remove.
   * @return true if an account with the specified ID existed and was removed and false otherwise.
   */
  public boolean uninstallAccount(AccountID accountID) {
    // unregister the protocol provider
    ServiceReference serRef = getProviderForAccount(accountID);

    if (serRef == null) return false;

    ProtocolProviderService protocolProvider =
        (ProtocolProviderService) SipActivator.getBundleContext().getService(serRef);

    try {
      protocolProvider.unregister();
    } catch (OperationFailedException e) {
      logger.error(
          "Failed to unregister protocol provider for account : "
              + accountID
              + " caused by : "
              + e);
    }

    ServiceRegistration registration = (ServiceRegistration) registeredAccounts.remove(accountID);

    if (registration == null) return false;

    // kill the service
    registration.unregister();

    return removeStoredAccount(SipActivator.getBundleContext(), accountID);
  }
  /**
   * Returns the set of data that user has entered through this wizard.
   *
   * @return Iterator
   */
  public Iterator<Map.Entry<String, String>> getSummary() {
    Hashtable<String, String> summaryTable = new Hashtable<String, String>();

    /*
     * Hashtable arranges the entries alphabetically so the order
     * of appearance is
     * - Computer Name / IP
     * - Port
     * - User ID
     */
    summaryTable.put("Account ID", registration.getAccountID());
    summaryTable.put("Known Hosts", registration.getKnownHostsFile());
    summaryTable.put("Identity", registration.getIdentityFile());

    return summaryTable.entrySet().iterator();
  }
Ejemplo n.º 7
0
  /**
   * Implements CallListener.incomingCallReceived. When a call is received creates a call panel and
   * adds it to the main tabbed pane and plays the ring phone sound to the user.
   */
  public void incomingCallReceived(CallEvent event) {
    Call sourceCall = event.getSourceCall();

    CallPanel callPanel = new CallPanel(this, sourceCall, GuiCallParticipantRecord.INCOMING_CALL);

    mainFrame.addCallPanel(callPanel);

    if (mainFrame.getState() == JFrame.ICONIFIED) mainFrame.setState(JFrame.NORMAL);

    if (!mainFrame.isVisible()) mainFrame.setVisible(true);

    mainFrame.toFront();

    this.callButton.setEnabled(true);
    this.hangupButton.setEnabled(true);

    NotificationManager.fireNotification(
        NotificationManager.INCOMING_CALL,
        null,
        "Incoming call recived from: " + sourceCall.getCallParticipants().next());

    activeCalls.put(sourceCall, callPanel);

    this.setCallPanelVisible(true);
  }
Ejemplo n.º 8
0
  static {
    iconsTable.put(
        ProtocolIcon.ICON_SIZE_16x16,
        getImageInBytes("service.protocol.gibberish.GIBBERISH_16x16"));

    iconsTable.put(
        ProtocolIcon.ICON_SIZE_32x32,
        getImageInBytes("service.protocol.gibberish.GIBBERISH_32x32"));

    iconsTable.put(
        ProtocolIcon.ICON_SIZE_48x48,
        getImageInBytes("service.protocol.gibberish.GIBBERISH_48x48"));

    iconsTable.put(
        ProtocolIcon.ICON_SIZE_64x64,
        getImageInBytes("service.protocol.gibberish.GIBBERISH_64x64"));
  }
Ejemplo n.º 9
0
  static {
    iconPathsTable.put(
        ProtocolIcon.ICON_SIZE_16x16,
        getResources().getImagePath("service.protocol.gibberish.GIBBERISH_16x16"));

    iconPathsTable.put(
        ProtocolIcon.ICON_SIZE_32x32,
        getResources().getImagePath("service.protocol.gibberish.GIBBERISH_32x32"));

    iconPathsTable.put(
        ProtocolIcon.ICON_SIZE_48x48,
        getResources().getImagePath("service.protocol.gibberish.GIBBERISH_48x48"));

    iconPathsTable.put(
        ProtocolIcon.ICON_SIZE_64x64,
        getResources().getImagePath("service.protocol.gibberish.GIBBERISH_64x64"));
  }
Ejemplo n.º 10
0
  /**
   * Removes the given call panel tab.
   *
   * @param callPanel the CallPanel to remove
   */
  private void removeCallPanel(CallPanel callPanel) {
    if (callPanel.getCall() != null && activeCalls.contains(callPanel.getCall())) {
      this.activeCalls.remove(callPanel.getCall());
    }

    mainFrame.removeCallPanel(callPanel);
    updateButtonsStateAccordingToSelectedPanel();
  }
Ejemplo n.º 11
0
  static {
    iconPathsTable.put(
        ProtocolIcon.ICON_SIZE_16x16,
        getResources().getImagePath("service.protocol.yahoo.YAHOO_16x16"));

    iconPathsTable.put(
        ProtocolIcon.ICON_SIZE_32x32,
        getResources().getImagePath("service.protocol.yahoo.YAHOO_32x32"));

    iconPathsTable.put(
        ProtocolIcon.ICON_SIZE_48x48,
        getResources().getImagePath("service.protocol.yahoo.YAHOO_48x48"));

    iconPathsTable.put(
        ProtocolIcon.ICON_SIZE_64x64,
        getResources().getImagePath("service.protocol.yahoo.YAHOO_64x64"));
  }
Ejemplo n.º 12
0
  /**
   * Returns all properties necessary for the intialization of the account with
   * <tt>accountPrefix</tt>.
   *
   * @param accountPrefix the prefix contained by all property names for the the account we'd like
   *     to initialized
   * @return a Hashtable that can be used when creating the account in a protocol provider factory.
   */
  private Hashtable<String, String> getAccountProperties(String accountPrefix) {
    Hashtable<String, String> table = new Hashtable<String, String>();

    String userID = System.getProperty(accountPrefix + ProtocolProviderFactory.USER_ID, null);

    assertNotNull(
        "The system property named "
            + accountPrefix
            + ProtocolProviderFactory.USER_ID
            + " has to tontain a valid Jabber address that could be used during "
            + "SIP Communicator's tests.",
        userID);

    table.put(ProtocolProviderFactory.USER_ID, userID);

    String passwd = System.getProperty(accountPrefix + ProtocolProviderFactory.PASSWORD, null);

    assertNotNull(
        "The system property named "
            + accountPrefix
            + ProtocolProviderFactory.PASSWORD
            + " has to contain the password corresponding to the account "
            + "specified in "
            + accountPrefix
            + ProtocolProviderFactory.USER_ID,
        passwd);

    table.put(ProtocolProviderFactory.PASSWORD, passwd);

    String serverAddress =
        System.getProperty(accountPrefix + ProtocolProviderFactory.SERVER_ADDRESS, null);

    // optional
    if (serverAddress != null) table.put(ProtocolProviderFactory.SERVER_ADDRESS, serverAddress);

    String serverPort =
        System.getProperty(accountPrefix + ProtocolProviderFactory.SERVER_PORT, null);

    // optional
    if (serverPort != null) table.put(ProtocolProviderFactory.SERVER_PORT, serverPort);

    return table;
  }
  /**
   * Creates an account for the given user and password.
   *
   * @param providerFactory the ProtocolProviderFactory which will create the account
   * @param user the user identifier
   * @return the <tt>ProtocolProviderService</tt> for the new account.
   */
  public ProtocolProviderService installAccount(
      ProtocolProviderFactory providerFactory, String user) throws OperationFailedException {
    Hashtable<String, String> accountProperties = new Hashtable<String, String>();

    accountProperties.put(
        ProtocolProviderFactory.ACCOUNT_ICON_PATH,
        "resources/images/protocol/gibberish/gibberish32x32.png");

    if (registration.isRememberPassword()) {
      accountProperties.put(ProtocolProviderFactory.PASSWORD, registration.getPassword());
    }

    if (isModification()) {
      providerFactory.uninstallAccount(protocolProvider.getAccountID());
      this.protocolProvider = null;
      setModification(false);
    }

    try {
      AccountID accountID = providerFactory.installAccount(user, accountProperties);

      ServiceReference serRef = providerFactory.getProviderForAccount(accountID);

      protocolProvider =
          (ProtocolProviderService) GibberishAccRegWizzActivator.bundleContext.getService(serRef);
    } catch (IllegalStateException exc) {
      logger.warn(exc.getMessage());

      throw new OperationFailedException(
          "Account already exists.", OperationFailedException.IDENTIFICATION_CONFLICT);
    } catch (Exception exc) {
      logger.warn(exc.getMessage());

      throw new OperationFailedException(
          "Failed to add account", OperationFailedException.GENERAL_ERROR);
    }

    return protocolProvider;
  }
  /**
   * Creates an account for the given Account ID, Identity File and Known Hosts File
   *
   * @param providerFactory the ProtocolProviderFactory which will create the account
   * @param user the user identifier
   * @return the <tt>ProtocolProviderService</tt> for the new account.
   */
  public ProtocolProviderService installAccount(
      ProtocolProviderFactory providerFactory, String user) throws OperationFailedException {
    Hashtable<String, String> accountProperties = new Hashtable<String, String>();

    accountProperties.put(
        ProtocolProviderFactory.ACCOUNT_ICON_PATH, "resources/images/protocol/ssh/ssh32x32.png");

    accountProperties.put(
        ProtocolProviderFactory.NO_PASSWORD_REQUIRED, new Boolean(true).toString());

    accountProperties.put(
        ProtocolProviderFactorySSHImpl.IDENTITY_FILE, registration.getIdentityFile());

    accountProperties.put(
        ProtocolProviderFactorySSHImpl.KNOWN_HOSTS_FILE,
        String.valueOf(registration.getKnownHostsFile()));

    try {
      AccountID accountID = providerFactory.installAccount(user, accountProperties);

      ServiceReference serRef = providerFactory.getProviderForAccount(accountID);

      protocolProvider =
          (ProtocolProviderService) SSHAccRegWizzActivator.bundleContext.getService(serRef);
    } catch (IllegalStateException exc) {
      logger.warn(exc.getMessage());

      throw new OperationFailedException(
          "Account already exists.", OperationFailedException.IDENTIFICATION_CONFLICT);
    } catch (Exception exc) {
      logger.warn(exc.getMessage());

      throw new OperationFailedException(
          "Failed to add account", OperationFailedException.GENERAL_ERROR);
    }

    return protocolProvider;
  }
Ejemplo n.º 15
0
  /**
   * Implements ChangeListener.stateChanged. Enables the hangup button if ones selects a tab in the
   * main tabbed pane that contains a call panel.
   */
  public void stateChanged(ChangeEvent e) {
    this.updateButtonsStateAccordingToSelectedPanel();

    Component selectedPanel = mainFrame.getSelectedTab();
    if (selectedPanel == null || !(selectedPanel instanceof CallPanel)) {
      Iterator callPanels = activeCalls.values().iterator();

      while (callPanels.hasNext()) {
        CallPanel callPanel = (CallPanel) callPanels.next();

        callPanel.removeDialogs();
      }
    }
  }
  /** Prepares the factory for bundle shutdown. */
  public void stop() {
    logger.trace("Preparing to stop all SIP protocol providers.");
    Enumeration registrations = this.registeredAccounts.elements();

    while (registrations.hasMoreElements()) {
      ServiceRegistration reg = ((ServiceRegistration) registrations.nextElement());

      ProtocolProviderServiceSipImpl provider =
          (ProtocolProviderServiceSipImpl)
              SipActivator.getBundleContext().getService(reg.getReference());

      // do an attempt to kill the provider
      provider.shutdown();

      reg.unregister();
    }

    registeredAccounts.clear();
  }
  /**
   * Initializes and creates an account corresponding to the specified accountProperties and
   * registers the resulting ProtocolProvider in the <tt>context</tt> BundleContext parameter.
   *
   * @param userIDStr the user identifier uniquely representing the newly created account within the
   *     protocol namespace.
   * @param accountProperties a set of protocol (or implementation) specific properties defining the
   *     new account.
   * @return the AccountID of the newly created account.
   * @throws IllegalArgumentException if userID does not correspond to an identifier in the context
   *     of the underlying protocol or if accountProperties does not contain a complete set of
   *     account installation properties.
   * @throws IllegalStateException if the account has already been installed.
   * @throws NullPointerException if any of the arguments is null.
   */
  public AccountID installAccount(String userIDStr, Map accountProperties) {
    BundleContext context = SipActivator.getBundleContext();
    if (context == null) throw new NullPointerException("The specified BundleContext was null");

    if (userIDStr == null) throw new NullPointerException("The specified AccountID was null");

    accountProperties.put(USER_ID, userIDStr);

    if (accountProperties == null)
      throw new NullPointerException("The specified property map was null");

    String serverAddress = (String) accountProperties.get(SERVER_ADDRESS);

    if (serverAddress == null) throw new NullPointerException("null is not a valid ServerAddress");

    if (!accountProperties.containsKey(PROTOCOL))
      accountProperties.put(PROTOCOL, ProtocolNames.SIP);

    AccountID accountID = new SipAccountID(userIDStr, accountProperties, serverAddress);

    // make sure we haven't seen this account id before.
    if (registeredAccounts.containsKey(accountID))
      throw new IllegalStateException("An account for id " + userIDStr + " was already installed!");

    // first store the account and only then load it as the load generates
    // an osgi event, the osgi event triggers (trhgough the UI) a call to
    // the register() method and it needs to acces the configuration service
    // and check for a password.
    this.storeAccount(SipActivator.getBundleContext(), accountID);

    try {
      accountID = loadAccount(accountProperties);
    } catch (RuntimeException exc) {
      // it might happen that load-ing the account fails because of a bad
      // initialization. if this is the case, make sure we remove it.
      this.removeStoredAccount(SipActivator.getBundleContext(), accountID);

      throw exc;
    }

    return accountID;
  }
Ejemplo n.º 18
0
  /**
   * Handles the <tt>ActionEvent</tt> generated when user presses one of the buttons in this panel.
   */
  public void actionPerformed(ActionEvent evt) {
    JButton button = (JButton) evt.getSource();
    String buttonName = button.getName();

    if (buttonName.equals("call")) {
      Component selectedPanel = mainFrame.getSelectedTab();

      // call button is pressed over an already open call panel
      if (selectedPanel != null
          && selectedPanel instanceof CallPanel
          && ((CallPanel) selectedPanel).getCall().getCallState()
              == CallState.CALL_INITIALIZATION) {

        NotificationManager.stopSound(NotificationManager.BUSY_CALL);
        NotificationManager.stopSound(NotificationManager.INCOMING_CALL);

        CallPanel callPanel = (CallPanel) selectedPanel;

        Iterator participantPanels = callPanel.getParticipantsPanels();

        while (participantPanels.hasNext()) {
          CallParticipantPanel panel = (CallParticipantPanel) participantPanels.next();

          panel.setState("Connecting");
        }

        Call call = callPanel.getCall();

        answerCall(call);
      }
      // call button is pressed over the call list
      else if (selectedPanel != null
          && selectedPanel instanceof CallListPanel
          && ((CallListPanel) selectedPanel).getCallList().getSelectedIndex() != -1) {

        CallListPanel callListPanel = (CallListPanel) selectedPanel;

        GuiCallParticipantRecord callRecord =
            (GuiCallParticipantRecord) callListPanel.getCallList().getSelectedValue();

        String stringContact = callRecord.getParticipantName();

        createCall(stringContact);
      }
      // call button is pressed over the contact list
      else if (selectedPanel != null && selectedPanel instanceof ContactListPanel) {
        // call button is pressed when a meta contact is selected
        if (isCallMetaContact) {
          Object[] selectedContacts =
              mainFrame.getContactListPanel().getContactList().getSelectedValues();

          Vector telephonyContacts = new Vector();

          for (int i = 0; i < selectedContacts.length; i++) {

            Object o = selectedContacts[i];

            if (o instanceof MetaContact) {

              Contact contact =
                  ((MetaContact) o).getDefaultContact(OperationSetBasicTelephony.class);

              if (contact != null) telephonyContacts.add(contact);
              else {
                new ErrorDialog(
                        this.mainFrame,
                        Messages.getI18NString("warning").getText(),
                        Messages.getI18NString(
                                "contactNotSupportingTelephony",
                                new String[] {((MetaContact) o).getDisplayName()})
                            .getText())
                    .showDialog();
              }
            }
          }

          if (telephonyContacts.size() > 0) createCall(telephonyContacts);

        } else if (!phoneNumberCombo.isComboFieldEmpty()) {

          // if no contact is selected checks if the user has chosen
          // or has
          // writen something in the phone combo box

          String stringContact = phoneNumberCombo.getEditor().getItem().toString();

          createCall(stringContact);
        }
      } else if (selectedPanel != null && selectedPanel instanceof DialPanel) {
        String stringContact = phoneNumberCombo.getEditor().getItem().toString();
        createCall(stringContact);
      }
    } else if (buttonName.equalsIgnoreCase("hangup")) {
      Component selectedPanel = this.mainFrame.getSelectedTab();

      if (selectedPanel != null && selectedPanel instanceof CallPanel) {

        NotificationManager.stopSound(NotificationManager.BUSY_CALL);
        NotificationManager.stopSound(NotificationManager.INCOMING_CALL);
        NotificationManager.stopSound(NotificationManager.OUTGOING_CALL);

        CallPanel callPanel = (CallPanel) selectedPanel;

        Call call = callPanel.getCall();

        if (removeCallTimers.containsKey(callPanel)) {
          ((Timer) removeCallTimers.get(callPanel)).stop();
          removeCallTimers.remove(callPanel);
        }

        removeCallPanel(callPanel);

        if (call != null) {
          ProtocolProviderService pps = call.getProtocolProvider();

          OperationSetBasicTelephony telephony = mainFrame.getTelephonyOpSet(pps);

          Iterator participants = call.getCallParticipants();

          while (participants.hasNext()) {
            try {
              // now we hang up the first call participant in the
              // call
              telephony.hangupCallParticipant((CallParticipant) participants.next());
            } catch (OperationFailedException e) {
              logger.error("Hang up was not successful: " + e);
            }
          }
        }
      }
    } else if (buttonName.equalsIgnoreCase("minimize")) {
      JCheckBoxMenuItem hideCallPanelItem =
          mainFrame.getMainMenu().getViewMenu().getHideCallPanelItem();

      if (!hideCallPanelItem.isSelected()) hideCallPanelItem.setSelected(true);

      this.setCallPanelVisible(false);
    } else if (buttonName.equalsIgnoreCase("restore")) {

      JCheckBoxMenuItem hideCallPanelItem =
          mainFrame.getMainMenu().getViewMenu().getHideCallPanelItem();

      if (hideCallPanelItem.isSelected()) hideCallPanelItem.setSelected(false);

      this.setCallPanelVisible(true);
    }
  }
Ejemplo n.º 19
0
 /**
  * Returns a path to the icon with the given size.
  *
  * @param iconSize the size of the icon we're looking for
  * @return the path to the icon with the given size
  */
 public String getIconPath(String iconSize) {
   return iconPathsTable.get(iconSize);
 }
  /**
   * Creates an account for the given user and password.
   *
   * @param providerFactory the ProtocolProviderFactory which will create the account
   * @param userName the user identifier
   * @param passwd the password
   * @return the <tt>ProtocolProviderService</tt> for the new account.
   * @throws OperationFailedException if the operation didn't succeed
   */
  protected ProtocolProviderService installAccount(
      ProtocolProviderFactory providerFactory, String userName, String passwd)
      throws OperationFailedException {
    if (logger.isTraceEnabled()) {
      logger.trace("Preparing to install account for user " + userName);
    }
    Hashtable<String, String> accountProperties = new Hashtable<String, String>();

    String protocolIconPath = getProtocolIconPath();

    String accountIconPath = getAccountIconPath();

    registration.storeProperties(
        userName, passwd, protocolIconPath, accountIconPath, accountProperties);

    accountProperties.put(
        ProtocolProviderFactory.IS_PREFERRED_PROTOCOL, Boolean.toString(isPreferredProtocol()));
    accountProperties.put(ProtocolProviderFactory.PROTOCOL, getProtocol());

    if (isModification()) {
      providerFactory.modifyAccount(protocolProvider, accountProperties);

      setModification(false);

      return protocolProvider;
    }

    try {
      if (logger.isTraceEnabled()) {
        logger.trace(
            "Will install account for user "
                + userName
                + " with the following properties."
                + accountProperties);
      }

      AccountID accountID = providerFactory.installAccount(userName, accountProperties);

      ServiceReference serRef = providerFactory.getProviderForAccount(accountID);

      protocolProvider =
          (ProtocolProviderService) JabberAccRegWizzActivator.bundleContext.getService(serRef);
    } catch (IllegalArgumentException exc) {
      logger.warn(exc.getMessage());

      throw new OperationFailedException(
          "Username, password or server is null.", OperationFailedException.ILLEGAL_ARGUMENT);
    } catch (IllegalStateException exc) {
      logger.warn(exc.getMessage());

      throw new OperationFailedException(
          "Account already exists.", OperationFailedException.IDENTIFICATION_CONFLICT);
    } catch (Throwable exc) {
      logger.warn(exc.getMessage());

      throw new OperationFailedException(
          "Failed to add account.", OperationFailedException.GENERAL_ERROR);
    }

    return protocolProvider;
  }
 /**
  * Returns an array containing all operation sets supported by the current implementation.
  *
  * @return a java.util.Map containing instance of all supported operation sets mapped against
  *     their class names (e.g. OperationSetPresence.class.getName()) .
  */
 public Map getSupportedOperationSets() {
   // Copy the map so that the caller is not able to modify it.
   return (Map) supportedOperationSets.clone();
 }
  /** Loads the configuration form obtained from the chat room. */
  protected void loadConfigurationForm() {
    Iterator<ChatRoomConfigurationFormField> configurationSet = configForm.getConfigurationSet();

    while (configurationSet.hasNext()) {
      ChatRoomConfigurationFormField formField = configurationSet.next();

      Iterator<?> values = formField.getValues();
      Iterator<String> options = formField.getOptions();

      JComponent field;
      JLabel label = new JLabel("", JLabel.RIGHT);

      if (formField.getLabel() != null) label.setText(formField.getLabel() + ": ");

      String fieldType = formField.getType();

      if (fieldType.equals(ChatRoomConfigurationFormField.TYPE_BOOLEAN)) {
        // Create a check box when the field is of type boolean.
        field = new SIPCommCheckBox(formField.getLabel());
        label.setText("");

        if (values.hasNext()) {
          ((JCheckBox) field).setSelected((Boolean) values.next());
        }
      } else if (fieldType.equals(ChatRoomConfigurationFormField.TYPE_TEXT_FIXED)) {
        field = new JLabel();

        if (values.hasNext()) {
          String value = values.next().toString();

          ((JLabel) field).setText(value);
          field.setFont(new Font(null, Font.ITALIC, 10));
          field.setForeground(Color.GRAY);
        }
      } else if (fieldType.equals(ChatRoomConfigurationFormField.TYPE_LIST_MULTI)) {
        field = new TransparentPanel(new GridLayout(0, 1));

        field.setBorder(BorderFactory.createLineBorder(Color.GRAY));

        Hashtable<Object, JCheckBox> optionCheckBoxes = new Hashtable<Object, JCheckBox>();

        while (options.hasNext()) {
          Object option = options.next();
          JCheckBox checkBox = new SIPCommCheckBox(option.toString());

          field.add(checkBox);
          optionCheckBoxes.put(option, checkBox);
        }

        while (values.hasNext()) {
          Object value = values.next();

          (optionCheckBoxes.get(value)).setSelected(true);
        }
      } else if (fieldType.equals(ChatRoomConfigurationFormField.TYPE_LIST_SINGLE)) {
        field = new JComboBox();

        while (options.hasNext()) {
          ((JComboBox) field).addItem(options.next());
        }

        if (values.hasNext()) {
          ((JComboBox) field).setSelectedItem(values.next());
        }
      } else if (fieldType.equals(ChatRoomConfigurationFormField.TYPE_TEXT_MULTI)) {
        field = new JEditorPane();

        if (values.hasNext()) {
          String value = values.next().toString();

          ((JEditorPane) field).setText(value);
        }
      } else if (fieldType.equals(ChatRoomConfigurationFormField.TYPE_TEXT_SINGLE)
          || fieldType.equals(ChatRoomConfigurationFormField.TYPE_ID_SINGLE)) {
        field = new JTextField();

        if (values.hasNext()) {
          String value = values.next().toString();

          ((JTextField) field).setText(value);
        }
      } else if (fieldType.equals(ChatRoomConfigurationFormField.TYPE_TEXT_PRIVATE)) {
        field = new JPasswordField();

        if (values.hasNext()) {
          String value = values.next().toString();

          ((JPasswordField) field).setText(value);
        }
      } else if (fieldType.equals(ChatRoomConfigurationFormField.TYPE_ID_MULTI)) {
        StringBuffer buff = new StringBuffer();

        while (values.hasNext()) {
          String value = values.next().toString();
          buff.append(value);

          if (values.hasNext()) buff.append(System.getProperty("line.separator"));
        }
        field = new JTextArea(buff.toString());
      } else {
        if (label.getText() == null) continue;

        field = new JTextField();

        if (values.hasNext()) {
          String value = values.next().toString();

          ((JTextField) field).setText(value);
        }
      }

      // If the field is not fixed (i.e. could be changed) we would like
      // to save it in a list in order to use it later when user saves
      // the configuration data.
      if (!fieldType.equals(ChatRoomConfigurationFormField.TYPE_TEXT_FIXED)) {
        uiFieldsTable.put(formField.getName(), field);
      }

      JPanel fieldPanel = new TransparentPanel(new GridLayout(1, 2));
      fieldPanel.setOpaque(false);

      if (!(field instanceof JLabel))
        fieldPanel.setBorder(BorderFactory.createEmptyBorder(0, 0, 8, 0));
      else fieldPanel.setBorder(BorderFactory.createEmptyBorder(0, 0, 1, 0));

      fieldPanel.add(label);
      fieldPanel.add(field);

      this.mainPanel.add(fieldPanel);
    }
  }
  /**
   * Returns the set of data that user has entered through this wizard.
   *
   * @return Iterator
   */
  @Override
  public Iterator<Map.Entry<String, String>> getSummary() {
    Hashtable<String, String> summaryTable = new Hashtable<String, String>();

    summaryTable.put(
        Resources.getString("plugin.jabberaccregwizz.USERNAME"), registration.getUserID());

    summaryTable.put(
        Resources.getString("service.gui.REMEMBER_PASSWORD"),
        Boolean.toString(registration.isRememberPassword()));

    summaryTable.put(
        Resources.getString("plugin.jabberaccregwizz.SERVER"), registration.getServerAddress());

    summaryTable.put(
        Resources.getString("service.gui.PORT"), String.valueOf(registration.getServerPort()));

    summaryTable.put(
        Resources.getString("plugin.jabberaccregwizz.ENABLE_KEEP_ALIVE"),
        String.valueOf(registration.isSendKeepAlive()));

    summaryTable.put(
        Resources.getString("plugin.jabberaccregwizz.ENABLE_GMAIL_NOTIFICATIONS"),
        String.valueOf(registration.isGmailNotificationEnabled()));

    summaryTable.put(
        Resources.getString("plugin.jabberaccregwizz.RESOURCE"), registration.getResource());

    summaryTable.put(
        Resources.getString("plugin.jabberaccregwizz.PRIORITY"),
        String.valueOf(registration.getPriority()));

    summaryTable.put(
        Resources.getString("plugin.sipaccregwizz.DTMF_METHOD"), registration.getDTMFMethod());

    summaryTable.put(
        Resources.getString("plugin.sipaccregwizz.DTMF_MINIMAL_TONE_DURATION"),
        registration.getDtmfMinimalToneDuration());

    return summaryTable.entrySet().iterator();
  }
  /**
   * Saves all configuration settings when the "Save" button is pressed.
   *
   * @param e the <tt>ActionEvent</tt> that notified us of the button action
   */
  public void actionPerformed(ActionEvent e) {
    JButton button = (JButton) e.getSource();

    if (button.equals(saveButton)) {
      Iterator<ChatRoomConfigurationFormField> configurationSet = configForm.getConfigurationSet();

      while (configurationSet.hasNext()) {
        ChatRoomConfigurationFormField formField = configurationSet.next();

        // If the field is of type fixed the user could not change it,
        // so we skip it.
        if (formField.getType().equals(ChatRoomConfigurationFormField.TYPE_TEXT_FIXED)) continue;

        JComponent c = uiFieldsTable.get(formField.getName());

        if (c instanceof JTextComponent) {
          String newValue = ((JTextComponent) c).getText();

          if (formField.getType().equals(ChatRoomConfigurationFormField.TYPE_ID_MULTI)) {
            // extract values
            StringTokenizer idTokens =
                new StringTokenizer(newValue, System.getProperty("line.separator"));
            while (idTokens.hasMoreTokens()) {
              formField.addValue(idTokens.nextToken());
            }
          } else formField.addValue(newValue);
        } else if (c instanceof AbstractButton) {
          boolean isSelected = ((AbstractButton) c).isSelected();

          formField.addValue(isSelected);
        } else if (c instanceof JComboBox) {
          Object selectedObject = ((JComboBox) c).getSelectedItem();

          formField.addValue(selectedObject);
        } else if (c instanceof JPanel) {
          Component[] components = c.getComponents();

          for (Component comp : components) {
            if (!(comp instanceof JCheckBox)) continue;

            JCheckBox checkBox = (JCheckBox) comp;

            formField.addValue(checkBox.getText());
          }
        }
      }

      new Thread() {
        @Override
        public void run() {
          try {
            configForm.submit();
          } catch (Exception e) {
            new ErrorDialog(
                    ChatRoomConfigurationWindow.this,
                    GuiActivator.getResources().getI18NString("service.gui.ERROR"),
                    GuiActivator.getResources()
                        .getI18NString("service.gui.CHAT_ROOM_CONFIGURATION_SUBMIT_FAILED"),
                    e)
                .showDialog();
          }
        }
      }.start();
    }

    this.dispose();
  }
Ejemplo n.º 25
0
  /** Installs an account and verifies whether the installation has gone well. */
  public void testInstallAccount() {
    // first obtain a reference to the provider factory
    ServiceReference[] serRefs = null;
    String osgiFilter = "(" + ProtocolProviderFactory.PROTOCOL + "=" + ProtocolNames.JABBER + ")";
    try {
      serRefs =
          JabberSlickFixture.bc.getServiceReferences(
              ProtocolProviderFactory.class.getName(), osgiFilter);
    } catch (InvalidSyntaxException ex) {
      // this really shouldhn't occur as the filter expression is static.
      fail(osgiFilter + " is not a valid osgi filter");
    }

    assertTrue(
        "Failed to find a provider factory service for protocol Jabber",
        serRefs != null && serRefs.length > 0);

    // Enable always trust mode for testing tls jabber connections
    ServiceReference confReference =
        JabberSlickFixture.bc.getServiceReference(ConfigurationService.class.getName());
    ConfigurationService configurationService =
        (ConfigurationService) JabberSlickFixture.bc.getService(confReference);

    configurationService.setProperty(CertificateService.PNAME_ALWAYS_TRUST, Boolean.TRUE);

    // Keep the reference for later usage.
    ProtocolProviderFactory jabberProviderFactory =
        (ProtocolProviderFactory) JabberSlickFixture.bc.getService(serRefs[0]);

    // make sure the account is empty
    assertTrue(
        "There was an account registered with the account mananger " + "before we've installed any",
        jabberProviderFactory.getRegisteredAccounts().size() == 0);

    // Prepare the properties of the first jabber account.

    Hashtable<String, String> jabberAccount1Properties =
        getAccountProperties(JabberProtocolProviderServiceLick.ACCOUNT_1_PREFIX);
    Hashtable<String, String> jabberAccount2Properties =
        getAccountProperties(JabberProtocolProviderServiceLick.ACCOUNT_2_PREFIX);
    Hashtable<String, String> jabberAccount3Properties =
        getAccountProperties(JabberProtocolProviderServiceLick.ACCOUNT_3_PREFIX);

    // try to install an account with a null account id
    try {
      jabberProviderFactory.installAccount(null, jabberAccount1Properties);
      fail(
          "installing an account with a null account id must result "
              + "in a NullPointerException");
    } catch (NullPointerException exc) {
      // that's what had to happen
    }

    // now really install the accounts
    jabberProviderFactory.installAccount(
        jabberAccount1Properties.get(ProtocolProviderFactory.USER_ID), jabberAccount1Properties);
    jabberProviderFactory.installAccount(
        jabberAccount2Properties.get(ProtocolProviderFactory.USER_ID), jabberAccount2Properties);
    jabberProviderFactory.installAccount(
        jabberAccount3Properties.get(ProtocolProviderFactory.USER_ID), jabberAccount3Properties);

    // try to install one of the accounts one more time and verify that an
    // excepion is thrown.
    try {
      jabberProviderFactory.installAccount(
          jabberAccount1Properties.get(ProtocolProviderFactory.USER_ID), jabberAccount1Properties);

      fail(
          "An IllegalStateException must be thrown when trying to "
              + "install a duplicate account");

    } catch (IllegalStateException exc) {
      // that's what supposed to happen.
    }

    // Verify that the provider factory is aware of our installation
    assertTrue(
        "The newly installed account was not in the acc man's " + "registered accounts!",
        jabberProviderFactory.getRegisteredAccounts().size() == 3);

    // Verify protocol providers corresponding to the new account have
    // been properly registered with the osgi framework.

    osgiFilter =
        "(&("
            + ProtocolProviderFactory.PROTOCOL
            + "="
            + ProtocolNames.JABBER
            + ")"
            + "("
            + ProtocolProviderFactory.USER_ID
            + "="
            + jabberAccount1Properties.get(ProtocolProviderFactory.USER_ID)
            + "))";

    try {
      serRefs =
          JabberSlickFixture.bc.getServiceReferences(
              ProtocolProviderService.class.getName(), osgiFilter);
    } catch (InvalidSyntaxException ex) {
      // this really shouldhn't occur as the filter expression is static.
      fail(osgiFilter + "is not a valid osgi filter");
    }

    assertTrue(
        "An protocol provider was apparently not installed as " + "requested.",
        serRefs != null && serRefs.length > 0);

    Object jabberProtocolProvider = JabberSlickFixture.bc.getService(serRefs[0]);

    assertTrue(
        "The installed protocol provider does not implement " + "the protocol provider service.",
        jabberProtocolProvider instanceof ProtocolProviderService);
  }
Ejemplo n.º 26
0
 /** Returne TRUE if a icon with the given size is supported, FALSE-otherwise. */
 public boolean isSizeSupported(String iconSize) {
   return iconsTable.containsKey(iconSize);
 }
Ejemplo n.º 27
0
 /**
  * Implements the <tt>ProtocolIcon.getSupportedSizes()</tt> method. Returns an iterator to a set
  * containing the supported icon sizes.
  *
  * @return an iterator to a set containing the supported icon sizes
  */
 public Iterator<String> getSupportedSizes() {
   return iconsTable.keySet().iterator();
 }
  /**
   * Returns the ServiceReference for the protocol provider corresponding to the specified accountID
   * or null if the accountID is unknown.
   *
   * @param accountID the accountID of the protocol provider we'd like to get
   * @return a ServiceReference object to the protocol provider with the specified account id and
   *     null if the account id is unknwon to the provider factory.
   */
  public ServiceReference getProviderForAccount(AccountID accountID) {
    ServiceRegistration registration = (ServiceRegistration) registeredAccounts.get(accountID);

    return (registration == null) ? null : registration.getReference();
  }
Ejemplo n.º 29
0
 /**
  * Returns the icon image in the given size.
  *
  * @param iconSize the icon size; one of ICON_SIZE_XXX constants
  */
 public byte[] getIcon(String iconSize) {
   return iconsTable.get(iconSize);
 }
 /**
  * Returns a copy of the list containing all accounts currently registered in this protocol
  * provider.
  *
  * @return a copy of the llist containing all accounts currently installed in the protocol
  *     provider.
  */
 public ArrayList getRegisteredAccounts() {
   return new ArrayList(registeredAccounts.keySet());
 }