/**
  * Return the file where the configuration is stored. If the base path is a URL with a protocol
  * different than "file", or the configuration file is within a compressed archive, the
  * return value will not point to a valid file object.
  *
  * @return the file where the configuration is stored; this can be <b>null</b>
  */
 public File getFile() {
   if (getFileName() == null && sourceURL == null) {
     return null;
   } else if (sourceURL != null) {
     return ConfigurationUtils.fileFromURL(sourceURL);
   } else {
     return ConfigurationUtils.getFile(getBasePath(), getFileName());
   }
 }
Example #2
0
  /**
   * If sending im is supported check it for supporting html messages if a font is set. As it can be
   * slow make sure its not on our way
   */
  private void checkImCaps() {
    if (ConfigurationUtils.getChatDefaultFontFamily() != null
        && ConfigurationUtils.getChatDefaultFontSize() > 0) {
      OperationSetBasicInstantMessaging imOpSet =
          contact.getProtocolProvider().getOperationSet(OperationSetBasicInstantMessaging.class);

      if (imOpSet != null)
        imOpSet.isContentTypeSupported(OperationSetBasicInstantMessaging.HTML_MIME_TYPE, contact);
    }
  }
        @Override
        public void run() {
          String[] joinOptions;
          String subject = null;
          String nickName = null;

          nickName =
              ConfigurationUtils.getChatRoomProperty(
                  chatRoomWrapper.getParentProvider().getProtocolProvider(),
                  chatRoomWrapper.getChatRoomID(),
                  "userNickName");
          if (nickName == null) {
            joinOptions =
                ChatRoomJoinOptionsDialog.getJoinOptions(
                    chatRoomWrapper.getParentProvider().getProtocolProvider(),
                    chatRoomWrapper.getChatRoomID(),
                    MUCActivator.getMUCService()
                        .getDefaultNickname(
                            chatRoomWrapper.getParentProvider().getProtocolProvider()));
            nickName = joinOptions[0];
            subject = joinOptions[1];
          }

          if (nickName != null)
            MUCActivator.getMUCService().joinChatRoom(chatRoomWrapper, nickName, null, subject);
        }
  /**
   * Load the configuration from the specified URL. This does not change the source of the
   * configuration (i.e. the internally maintained file name). Use on of the setter methods for this
   * purpose.
   *
   * @param url the URL of the file to be loaded
   * @throws ConfigurationException if an error occurs
   */
  public void load(URL url) throws ConfigurationException {
    if (sourceURL == null) {
      if (StringUtils.isEmpty(getBasePath())) {
        // ensure that we have a valid base path
        setBasePath(url.toString());
      }
      sourceURL = url;
    }

    // throw an exception if the target URL is a directory
    File file = ConfigurationUtils.fileFromURL(url);
    if (file != null && file.isDirectory()) {
      throw new ConfigurationException("Cannot load a configuration from a directory");
    }

    InputStream in = null;

    try {
      in = url.openStream();
      load(in);
    } catch (ConfigurationException e) {
      throw e;
    } catch (Exception e) {
      throw new ConfigurationException("Unable to load the configuration from the URL " + url, e);
    } finally {
      // close the input stream
      try {
        if (in != null) {
          in.close();
        }
      } catch (IOException e) {
        getLogger().warn("Could not close input stream", e);
      }
    }
  }
Example #5
0
  /**
   * Leaves the given chat room.
   *
   * @param chatRoomWrapper the chat room to leave.
   * @return <tt>ChatRoomWrapper</tt> instance associated with the chat room.
   */
  public ChatRoomWrapper leaveChatRoom(ChatRoomWrapper chatRoomWrapper) {
    ChatRoom chatRoom = chatRoomWrapper.getChatRoom();

    if (chatRoom == null) {
      ResourceManagementService resources = MUCActivator.getResources();

      MUCActivator.getAlertUIService()
          .showAlertDialog(
              resources.getI18NString("service.gui.WARNING"),
              resources.getI18NString("service.gui.CHAT_ROOM_LEAVE_NOT_CONNECTED"));

      return null;
    }

    if (chatRoom.isJoined()) chatRoom.leave();

    ChatRoomWrapper existChatRoomWrapper = chatRoomList.findChatRoomWrapperFromChatRoom(chatRoom);

    if (existChatRoomWrapper == null) return null;

    // We save the choice of the user, before the chat room is really
    // joined, because even the join fails we want the next time when
    // we login to join this chat room automatically.
    ConfigurationUtils.updateChatRoomStatus(
        chatRoomWrapper.getParentProvider().getProtocolProvider(),
        chatRoomWrapper.getChatRoomID(),
        GlobalStatusEnum.OFFLINE_STATUS);

    return existChatRoomWrapper;
  }
 public static ProcessEntryPoint createForArguments(String[] args) {
   Props props = ConfigurationUtils.loadPropsFromCommandLineArgs(args);
   ProcessCommands commands =
       new DefaultProcessCommands(
           props.nonNullValueAsFile(PROPERTY_SHARED_PATH),
           Integer.parseInt(props.nonNullValue(PROPERTY_PROCESS_INDEX)));
   return new ProcessEntryPoint(props, new SystemExit(), commands);
 }
 public void testReadStringPropertyInvalidType() {
   try {
     ConfigurationUtils.readStringProperty(null, null, config, "arr");
   } catch (ElasticsearchParseException e) {
     assertThat(
         e.getMessage(),
         equalTo("[arr] property isn't a string, but of type [java.util.Arrays$ArrayList]"));
   }
 }
 /**
  * Load the configuration from the specified file. This does not change the source of the
  * configuration (i.e. the internally maintained file name). Use one of the setter methods for
  * this purpose.
  *
  * @param file the file to load
  * @throws ConfigurationException if an error occurs
  */
 public void load(File file) throws ConfigurationException {
   try {
     load(ConfigurationUtils.toURL(file));
   } catch (ConfigurationException e) {
     throw e;
   } catch (Exception e) {
     throw new ConfigurationException("Unable to load the configuration file " + file, e);
   }
 }
 @Test
 public void loadPropsFromCommandLineArgs_missing_argument() {
   try {
     ConfigurationUtils.loadPropsFromCommandLineArgs(new String[0]);
     fail();
   } catch (IllegalArgumentException e) {
     assertThat(e.getMessage()).startsWith("Only a single command-line argument is accepted");
   }
 }
Example #10
0
  /**
   * Handles the <tt>ActionEvent</tt>, when one of the tool bar buttons is clicked.
   *
   * @param e the <tt>ActionEvent</tt> that notified us
   */
  public void actionPerformed(ActionEvent e) {
    AbstractButton button = (AbstractButton) e.getSource();
    String buttonText = button.getName();

    ChatPanel chatPanel = chatContainer.getCurrentChat();

    if (buttonText.equals("previous")) {
      chatPanel.loadPreviousPageFromHistory();
    } else if (buttonText.equals("next")) {
      chatPanel.loadNextPageFromHistory();
    } else if (buttonText.equals("sendFile")) {
      SipCommFileChooser scfc =
          GenericFileDialog.create(
              null,
              "Send file...",
              SipCommFileChooser.LOAD_FILE_OPERATION,
              ConfigurationUtils.getSendFileLastDir());
      File selectedFile = scfc.getFileFromDialog();
      if (selectedFile != null) {
        ConfigurationUtils.setSendFileLastDir(selectedFile.getParent());
        chatContainer.getCurrentChat().sendFile(selectedFile);
      }
    } else if (buttonText.equals("invite")) {
      ChatInviteDialog inviteDialog = new ChatInviteDialog(chatPanel);

      inviteDialog.setVisible(true);
    } else if (buttonText.equals("leave")) {
      ChatRoomWrapper chatRoomWrapper =
          (ChatRoomWrapper) chatPanel.getChatSession().getDescriptor();
      ChatRoomWrapper leavedRoomWrapped =
          GuiActivator.getMUCService().leaveChatRoom(chatRoomWrapper);
    } else if (buttonText.equals("call")) {
      call(false, false);
    } else if (buttonText.equals("callVideo")) {
      call(true, false);
    } else if (buttonText.equals("desktop")) {
      call(true, true);
    } else if (buttonText.equals("options")) {
      GuiActivator.getUIService().getConfigurationContainer().setVisible(true);
    } else if (buttonText.equals("font")) chatPanel.showFontChooserDialog();
    else if (buttonText.equals("createConference")) {
      chatPanel.showChatConferenceDialog();
    }
  }
Example #11
0
  @Test
  public void loadPropsFromCommandLineArgs_load_properties_from_file() throws Exception {
    File propsFile = temp.newFile();
    FileUtils.write(propsFile, "foo=bar");

    Props result =
        ConfigurationUtils.loadPropsFromCommandLineArgs(new String[] {propsFile.getAbsolutePath()});
    assertThat(result.value("foo")).isEqualTo("bar");
    assertThat(result.rawProperties()).hasSize(1);
  }
Example #12
0
  @Test
  public void loadPropsFromCommandLineArgs_file_does_not_exist() throws Exception {
    File propsFile = temp.newFile();
    FileUtils.deleteQuietly(propsFile);

    try {
      ConfigurationUtils.loadPropsFromCommandLineArgs(new String[] {propsFile.getAbsolutePath()});
      fail();
    } catch (IllegalStateException e) {
      assertThat(e)
          .hasMessage("Could not read properties from file: " + propsFile.getAbsolutePath());
    }
  }
 /**
  * Save the configuration to the specified file. This doesn't change the source of the
  * configuration, use setFileName() if you need it.
  *
  * @param fileName the file name
  * @throws ConfigurationException if an error occurs during the save operation
  */
 public void save(String fileName) throws ConfigurationException {
   try {
     File file = ConfigurationUtils.getFile(basePath, fileName);
     if (file == null) {
       throw new ConfigurationException("Invalid file name for save: " + fileName);
     }
     save(file);
   } catch (ConfigurationException e) {
     throw e;
   } catch (Exception e) {
     throw new ConfigurationException(
         "Unable to save the configuration to the file " + fileName, e);
   }
 }
  /**
   * Locate the specified file and load the configuration. This does not change the source of the
   * configuration (i.e. the internally maintained file name). Use one of the setter methods for
   * this purpose.
   *
   * @param fileName the name of the file to be loaded
   * @throws ConfigurationException if an error occurs
   */
  public void load(String fileName) throws ConfigurationException {
    try {
      URL url = ConfigurationUtils.locate(basePath, fileName);

      if (url == null) {
        throw new ConfigurationException("Cannot locate configuration source " + fileName);
      }
      load(url);
    } catch (ConfigurationException e) {
      throw e;
    } catch (Exception e) {
      throw new ConfigurationException("Unable to load the configuration file " + fileName, e);
    }
  }
  public void testReadProcessors() throws Exception {
    Processor processor = mock(Processor.class);
    ProcessorsRegistry.Builder builder = new ProcessorsRegistry.Builder();
    builder.registerProcessor("test_processor", (templateService, registry) -> config -> processor);
    ProcessorsRegistry registry = builder.build(TestTemplateService.instance());

    List<Map<String, Map<String, Object>>> config = new ArrayList<>();
    Map<String, Object> emptyConfig = Collections.emptyMap();
    config.add(Collections.singletonMap("test_processor", emptyConfig));
    config.add(Collections.singletonMap("test_processor", emptyConfig));

    List<Processor> result = ConfigurationUtils.readProcessorConfigs(config, registry);
    assertThat(result.size(), equalTo(2));
    assertThat(result.get(0), sameInstance(processor));
    assertThat(result.get(1), sameInstance(processor));

    config.add(Collections.singletonMap("unknown_processor", emptyConfig));
    try {
      ConfigurationUtils.readProcessorConfigs(config, registry);
      fail("exception expected");
    } catch (ElasticsearchParseException e) {
      assertThat(e.getMessage(), equalTo("No processor type exists with name [unknown_processor]"));
    }
  }
Example #16
0
  /**
   * When a sent message is delivered shows it in the chat conversation panel.
   *
   * @param evt the event containing details on the message delivery
   */
  public void messageDelivered(MessageDeliveredEvent evt) {
    Contact contact = evt.getDestinationContact();
    MetaContact metaContact =
        GuiActivator.getContactListService().findMetaContactByContact(contact);

    if (logger.isTraceEnabled())
      logger.trace("MESSAGE DELIVERED to contact: " + contact.getAddress());

    ChatPanel chatPanel = chatWindowManager.getContactChat(metaContact, false);

    if (chatPanel != null) {
      Message msg = evt.getSourceMessage();
      ProtocolProviderService protocolProvider = contact.getProtocolProvider();

      if (logger.isTraceEnabled())
        logger.trace(
            "MESSAGE DELIVERED: process message to chat for contact: "
                + contact.getAddress()
                + " MESSAGE: "
                + msg.getContent());

      chatPanel.addMessage(
          this.mainFrame.getAccountAddress(protocolProvider),
          this.mainFrame.getAccountDisplayName(protocolProvider),
          evt.getTimestamp(),
          Chat.OUTGOING_MESSAGE,
          msg.getContent(),
          msg.getContentType(),
          msg.getMessageUID(),
          evt.getCorrectedMessageUID());

      if (evt.isSmsMessage() && !ConfigurationUtils.isSmsNotifyTextDisabled()) {
        chatPanel.addMessage(
            contact.getDisplayName(),
            new Date(),
            Chat.ACTION_MESSAGE,
            GuiActivator.getResources().getI18NString("service.gui.SMS_SUCCESSFULLY_SENT"),
            "text");
      }
    }
  }
Example #17
0
  /**
   * Creates the <tt>UnknownContactPanel</tt> by specifying the parent window.
   *
   * @param window the parent window
   */
  public UnknownContactPanel(MainFrame window) {
    super(new BorderLayout());

    this.parentWindow = window;

    TransparentPanel mainPanel = new TransparentPanel(new BorderLayout());

    this.add(mainPanel, BorderLayout.NORTH);

    if (!ConfigurationUtils.isAddContactDisabled()) {
      initAddContactButton();
    }

    initCallButton();

    initSMSButton();

    initTextArea();
    mainPanel.add(textArea, BorderLayout.CENTER);

    if (callButton.getParent() != null) {
      textArea.setText(
          GuiActivator.getResources()
              .getI18NString(
                  "service.gui.NO_CONTACTS_FOUND",
                  new String[] {'"' + parentWindow.getCurrentSearchText() + '"'}));
    } else {
      textArea.setText(
          GuiActivator.getResources().getI18NString("service.gui.NO_CONTACTS_FOUND_SHORT"));
    }

    if (buttonPanel.getComponentCount() > 0) {
      TransparentPanel southPanel = new TransparentPanel(new FlowLayout(FlowLayout.CENTER));
      southPanel.add(buttonPanel);

      mainPanel.add(southPanel, BorderLayout.SOUTH);
    }

    loadSkin();
  }
Example #18
0
  /**
   * Opens a chat window for the chat room.
   *
   * @param room the chat room.
   */
  public void openChatRoom(ChatRoomWrapper room) {
    if (room.getChatRoom() == null) {
      room =
          createChatRoom(
              room.getChatRoomName(),
              room.getParentProvider().getProtocolProvider(),
              new ArrayList<String>(),
              "",
              false,
              false,
              true);

      // leave the chatroom because getChatRoom().isJoined() returns true
      // otherwise
      if (room.getChatRoom().isJoined()) room.getChatRoom().leave();
    }

    if (!room.getChatRoom().isJoined()) {
      String savedNick =
          ConfigurationUtils.getChatRoomProperty(
              room.getParentProvider().getProtocolProvider(), room.getChatRoomID(), "userNickName");
      String subject = null;

      if (savedNick == null) {
        String[] joinOptions =
            ChatRoomJoinOptionsDialog.getJoinOptions(
                room.getParentProvider().getProtocolProvider(),
                room.getChatRoomID(),
                getDefaultNickname(room.getParentProvider().getProtocolProvider()));
        savedNick = joinOptions[0];
        subject = joinOptions[1];
      }

      if (savedNick != null) {
        joinChatRoom(room, savedNick, null, subject);
      } else return;
    }

    MUCActivator.getUIService().openChatRoomWindow(room);
  }
Example #19
0
  @Test
  public void shouldInterpolateVariables() {
    Properties input = new Properties();
    input.setProperty("hello", "world");
    input.setProperty("url", "${env:SONAR_JDBC_URL}");
    input.setProperty("do_not_change", "${SONAR_JDBC_URL}");
    Map<String, String> variables = Maps.newHashMap();
    variables.put("SONAR_JDBC_URL", "jdbc:h2:mem");

    Properties output = ConfigurationUtils.interpolateVariables(input, variables);

    assertThat(output).hasSize(3);
    assertThat(output.getProperty("hello")).isEqualTo("world");
    assertThat(output.getProperty("url")).isEqualTo("jdbc:h2:mem");
    assertThat(output.getProperty("do_not_change")).isEqualTo("${SONAR_JDBC_URL}");

    // input is not changed
    assertThat(input).hasSize(3);
    assertThat(input.getProperty("hello")).isEqualTo("world");
    assertThat(input.getProperty("url")).isEqualTo("${env:SONAR_JDBC_URL}");
    assertThat(input.getProperty("do_not_change")).isEqualTo("${SONAR_JDBC_URL}");
  }
  /**
   * Save the configuration to the specified URL. This doesn't change the source of the
   * configuration, use setURL() if you need it.
   *
   * @param url the URL
   * @throws ConfigurationException if an error occurs during the save operation
   */
  public void save(URL url) throws ConfigurationException {
    // file URLs have to be converted to Files since FileURLConnection is
    // read only (http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=4191800)
    File file = ConfigurationUtils.fileFromURL(url);
    if (file != null) {
      save(file);
    } else {
      // for non file URLs save through an URLConnection
      OutputStream out = null;
      try {
        URLConnection connection = url.openConnection();
        connection.setDoOutput(true);

        // use the PUT method for http URLs
        if (connection instanceof HttpURLConnection) {
          HttpURLConnection conn = (HttpURLConnection) connection;
          conn.setRequestMethod("PUT");
        }

        out = connection.getOutputStream();
        save(out);

        // check the response code for http URLs and throw an exception if an error occured
        if (connection instanceof HttpURLConnection) {
          HttpURLConnection conn = (HttpURLConnection) connection;
          if (conn.getResponseCode() >= HttpURLConnection.HTTP_BAD_REQUEST) {
            throw new IOException(
                "HTTP Error " + conn.getResponseCode() + " " + conn.getResponseMessage());
          }
        }
      } catch (IOException e) {
        throw new ConfigurationException("Could not save to URL " + url, e);
      } finally {
        closeSilent(out);
      }
    }
  }
  /**
   * Returns the full path to the file this configuration is based on. The return value is a valid
   * File path only if this configuration is based on a file on the local disk. If the configuration
   * was loaded from a packed archive the returned value is the string form of the URL from which
   * the configuration was loaded.
   *
   * @return the full path to the configuration file
   */
  public String getPath() {
    String path = null;
    File file = getFile();
    // if resource was loaded from jar file may be null
    if (file != null) {
      path = file.getAbsolutePath();
    }

    // try to see if file was loaded from a jar
    if (path == null) {
      if (sourceURL != null) {
        path = sourceURL.getPath();
      } else {
        try {
          path = ConfigurationUtils.getURL(getBasePath(), getFileName()).getPath();
        } catch (MalformedURLException e) {
          // simply ignore it and return null
          ;
        }
      }
    }

    return path;
  }
Example #22
0
  /**
   * Handles the <tt>ActionEvent</tt>, when one of the tool bar buttons is clicked.
   *
   * @param e the <tt>ActionEvent</tt> that notified us
   */
  public void actionPerformed(ActionEvent e) {
    AbstractButton button = (AbstractButton) e.getSource();
    String buttonText = button.getName();

    ChatPanel chatPanel = chatContainer.getCurrentChat();

    if (buttonText.equals("previous")) {
      chatPanel.loadPreviousPageFromHistory();
    } else if (buttonText.equals("next")) {
      chatPanel.loadNextPageFromHistory();
    } else if (buttonText.equals("sendFile")) {
      SipCommFileChooser scfc =
          GenericFileDialog.create(
              null,
              "Send file...",
              SipCommFileChooser.LOAD_FILE_OPERATION,
              ConfigurationUtils.getSendFileLastDir());
      File selectedFile = scfc.getFileFromDialog();
      if (selectedFile != null) {
        ConfigurationUtils.setSendFileLastDir(selectedFile.getParent());
        chatContainer.getCurrentChat().sendFile(selectedFile);
      }
    } else if (buttonText.equals("history")) {
      HistoryWindow history;

      HistoryWindowManager historyWindowManager =
          GuiActivator.getUIService().getHistoryWindowManager();

      ChatSession chatSession = chatPanel.getChatSession();

      if (historyWindowManager.containsHistoryWindowForContact(chatSession.getDescriptor())) {
        history = historyWindowManager.getHistoryWindowForContact(chatSession.getDescriptor());

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

        history.toFront();
      } else {
        history = new HistoryWindow(chatPanel.getChatSession().getDescriptor());

        history.setVisible(true);

        historyWindowManager.addHistoryWindowForContact(chatSession.getDescriptor(), history);
      }
    } else if (buttonText.equals("invite")) {
      ChatInviteDialog inviteDialog = new ChatInviteDialog(chatPanel);

      inviteDialog.setVisible(true);
    } else if (buttonText.equals("leave")) {
      ConferenceChatManager conferenceManager =
          GuiActivator.getUIService().getConferenceChatManager();
      conferenceManager.leaveChatRoom((ChatRoomWrapper) chatPanel.getChatSession().getDescriptor());
    } else if (buttonText.equals("call")) {
      call(false, false);
    } else if (buttonText.equals("callVideo")) {
      call(true, false);
    } else if (buttonText.equals("desktop")) {
      call(true, true);
    } else if (buttonText.equals("options")) {
      GuiActivator.getUIService().getConfigurationContainer().setVisible(true);
    } else if (buttonText.equals("font")) chatPanel.showFontChooserDialog();
  }
Example #23
0
  /** Initializes this component. */
  protected void init() {
    this.setLayout(new FlowLayout(FlowLayout.LEFT, 3, 0));
    this.setOpaque(false);

    this.add(inviteButton);

    // if we leave a chat room when we close the window
    // there is no need for this button
    if (!ConfigurationUtils.isLeaveChatRoomOnWindowCloseEnabled()) this.add(leaveChatRoomButton);

    this.add(callButton);
    this.add(callVideoButton);
    this.add(desktopSharingButton);
    this.add(sendFileButton);

    ChatPanel chatPanel = chatContainer.getCurrentChat();
    if (chatPanel == null || !(chatPanel.getChatSession() instanceof MetaContactChatSession))
      sendFileButton.setEnabled(false);

    this.addSeparator();

    this.add(historyButton);
    this.add(previousButton);
    this.add(nextButton);

    // We only add the options button if the property SHOW_OPTIONS_WINDOW
    // specifies so or if it's not set.
    Boolean showOptionsProp =
        GuiActivator.getConfigurationService()
            .getBoolean(ConfigurationFrame.SHOW_OPTIONS_WINDOW_PROPERTY, false);

    if (showOptionsProp.booleanValue()) {
      this.add(optionsButton);
    }

    this.addSeparator();

    if (ConfigurationUtils.isFontSupportEnabled()) {
      this.add(fontButton);
      fontButton.setName("font");
      fontButton.setToolTipText(
          GuiActivator.getResources().getI18NString("service.gui.CHANGE_FONT"));
      fontButton.addActionListener(this);
    }

    initSmiliesSelectorBox();

    this.addSeparator();

    this.inviteButton.setName("invite");
    this.inviteButton.setToolTipText(
        GuiActivator.getResources().getI18NString("service.gui.INVITE"));

    this.leaveChatRoomButton.setName("leave");
    this.leaveChatRoomButton.setToolTipText(
        GuiActivator.getResources().getI18NString("service.gui.LEAVE"));

    this.callButton.setName("call");
    this.callButton.setToolTipText(
        GuiActivator.getResources().getI18NString("service.gui.CALL_CONTACT"));

    this.callVideoButton.setName("callVideo");
    this.callVideoButton.setToolTipText(
        GuiActivator.getResources().getI18NString("service.gui.CALL_CONTACT"));

    this.desktopSharingButton.setName("desktop");
    this.desktopSharingButton.setToolTipText(
        GuiActivator.getResources().getI18NString("service.gui.SHARE_DESKTOP_WITH_CONTACT"));

    this.historyButton.setName("history");
    this.historyButton.setToolTipText(
        GuiActivator.getResources().getI18NString("service.gui.HISTORY") + " Ctrl-H");

    optionsButton.setName("options");
    optionsButton.setToolTipText(GuiActivator.getResources().getI18NString("service.gui.OPTIONS"));

    this.sendFileButton.setName("sendFile");
    this.sendFileButton.setToolTipText(
        GuiActivator.getResources().getI18NString("service.gui.SEND_FILE"));

    this.previousButton.setName("previous");
    this.previousButton.setToolTipText(
        GuiActivator.getResources().getI18NString("service.gui.PREVIOUS"));

    this.nextButton.setName("next");
    this.nextButton.setToolTipText(GuiActivator.getResources().getI18NString("service.gui.NEXT"));

    inviteButton.addActionListener(this);
    leaveChatRoomButton.addActionListener(this);
    callButton.addActionListener(this);
    callVideoButton.addActionListener(this);
    desktopSharingButton.addActionListener(this);
    historyButton.addActionListener(this);
    optionsButton.addActionListener(this);
    sendFileButton.addActionListener(this);
    previousButton.addActionListener(this);
    nextButton.addActionListener(this);
  }
 /**
  * Return the URL where the configuration is stored.
  *
  * @return the configuration's location as URL
  */
 public URL getURL() {
   return (sourceURL != null)
       ? sourceURL
       : ConfigurationUtils.locate(getBasePath(), getFileName());
 }
Example #25
0
    /**
     * Performs UI changes after the chat room join task has finished.
     *
     * @param returnCode the result code from the chat room join task.
     */
    private void done(String returnCode) {
      ConfigurationUtils.updateChatRoomStatus(
          chatRoomWrapper.getParentProvider().getProtocolProvider(),
          chatRoomWrapper.getChatRoomID(),
          GlobalStatusEnum.ONLINE_STATUS);

      String errorMessage = null;
      if (JOIN_AUTHENTICATION_FAILED_PROP.equals(returnCode)) {
        chatRoomWrapper.removePassword();

        AuthenticationWindowService authWindowsService =
            ServiceUtils.getService(MUCActivator.bundleContext, AuthenticationWindowService.class);

        AuthenticationWindowService.AuthenticationWindow authWindow =
            authWindowsService.create(
                null,
                null,
                null,
                false,
                chatRoomWrapper.isPersistent(),
                AuthenticationWindow.getAuthenticationWindowIcon(
                    chatRoomWrapper.getParentProvider().getProtocolProvider()),
                resources.getI18NString(
                    "service.gui.AUTHENTICATION_WINDOW_TITLE",
                    new String[] {chatRoomWrapper.getParentProvider().getName()}),
                resources.getI18NString(
                    "service.gui.CHAT_ROOM_REQUIRES_PASSWORD",
                    new String[] {chatRoomWrapper.getChatRoomName()}),
                "",
                null,
                isFirstAttempt
                    ? null
                    : resources.getI18NString(
                        "service.gui.AUTHENTICATION_FAILED",
                        new String[] {chatRoomWrapper.getChatRoomName()}),
                null);

        authWindow.setVisible(true);

        if (!authWindow.isCanceled()) {
          joinChatRoom(
              chatRoomWrapper,
              nickName,
              new String(authWindow.getPassword()).getBytes(),
              authWindow.isRememberPassword(),
              false,
              subject);
        }
      } else if (JOIN_REGISTRATION_REQUIRED_PROP.equals(returnCode)) {
        errorMessage =
            resources.getI18NString(
                "service.gui.CHAT_ROOM_REGISTRATION_REQUIRED",
                new String[] {chatRoomWrapper.getChatRoomName()});
      } else if (JOIN_PROVIDER_NOT_REGISTERED_PROP.equals(returnCode)) {
        errorMessage =
            resources.getI18NString(
                "service.gui.CHAT_ROOM_NOT_CONNECTED",
                new String[] {chatRoomWrapper.getChatRoomName()});
      } else if (JOIN_SUBSCRIPTION_ALREADY_EXISTS_PROP.equals(returnCode)) {
        errorMessage =
            resources.getI18NString(
                "service.gui.CHAT_ROOM_ALREADY_JOINED",
                new String[] {chatRoomWrapper.getChatRoomName()});
      } else {
        errorMessage =
            resources.getI18NString(
                "service.gui.FAILED_TO_JOIN_CHAT_ROOM",
                new String[] {chatRoomWrapper.getChatRoomName()});
      }

      if (!JOIN_SUCCESS_PROP.equals(returnCode)
          && !JOIN_AUTHENTICATION_FAILED_PROP.equals(returnCode)) {
        MUCActivator.getAlertUIService()
            .showAlertPopup(resources.getI18NString("service.gui.ERROR"), errorMessage);
      }

      if (JOIN_SUCCESS_PROP.equals(returnCode)) {
        if (rememberPassword) {
          chatRoomWrapper.savePassword(new String(password));
        }

        if (subject != null) {
          try {
            chatRoomWrapper.getChatRoom().setSubject(subject);
          } catch (OperationFailedException ex) {
            logger.warn("Failed to set subject.");
          }
        }
      }

      chatRoomWrapper.firePropertyChange(returnCode);
    }
Example #26
0
  /**
   * Loads the tooltip with the data for current metacontact.
   *
   * @param tip the tooltip to fill.
   */
  private void loadTooltip(final ExtendedTooltip tip) {
    Iterator<Contact> i = metaContact.getContacts();

    ContactPhoneUtil contactPhoneUtil = ContactPhoneUtil.getPhoneUtil(metaContact);

    String statusMessage = null;
    Contact protocolContact;
    boolean isLoading = false;
    while (i.hasNext()) {
      protocolContact = i.next();

      // Set the first found status message.
      if (statusMessage == null
          && protocolContact.getStatusMessage() != null
          && protocolContact.getStatusMessage().length() > 0)
        statusMessage = protocolContact.getStatusMessage();

      if (ConfigurationUtils.isHideAccountStatusSelectorsEnabled()) break;

      ImageIcon protocolStatusIcon =
          ImageLoader.getIndexedProtocolIcon(
              ImageUtils.getBytesInImage(protocolContact.getPresenceStatus().getStatusIcon()),
              protocolContact.getProtocolProvider());

      String contactAddress = protocolContact.getAddress();
      // String statusMessage = protocolContact.getStatusMessage();

      tip.addLine(protocolStatusIcon, contactAddress);

      addContactResourceTooltipLines(tip, protocolContact);

      if (!protocolContact.getProtocolProvider().isRegistered()) continue;

      contactPhoneUtil.addDetailsResponseListener(
          protocolContact,
          new OperationSetServerStoredContactInfo.DetailsResponseListener() {
            public void detailsRetrieved(final Iterator<GenericDetail> details) {
              if (!SwingUtilities.isEventDispatchThread()) {
                SwingUtilities.invokeLater(
                    new Runnable() {
                      public void run() {
                        detailsRetrieved(details);
                      }
                    });
                return;
              }

              // remove previously shown information
              // as it contains "Loading..." text
              tip.removeAllLines();

              // load it again
              loadTooltip(tip);
            }
          });

      List<String> phones = contactPhoneUtil.getPhones(protocolContact);

      if (phones != null) {
        addPhoneTooltipLines(tip, phones.iterator());
      } else isLoading = true;
    }

    if (isLoading)
      tip.addLine(null, GuiActivator.getResources().getI18NString("service.gui.LOADING"));

    if (statusMessage != null) tip.setBottomText(statusMessage);
  }
 /**
  * Set the location of this configuration as a URL. For loading this can be an arbitrary URL with
  * a supported protocol. If the configuration is to be saved, too, a URL with the &quot;file&quot;
  * protocol should be provided.
  *
  * @param url the location of this configuration as URL
  */
 public void setURL(URL url) {
   setBasePath(ConfigurationUtils.getBasePath(url));
   setFileName(ConfigurationUtils.getFileName(url));
   sourceURL = url;
 }
  /**
   * Initializes buttons panel.
   *
   * @param uiContact the <tt>UIContact</tt> for which we initialize the button panel
   */
  private void initButtonsPanel(UIContact uiContact) {
    this.remove(chatButton);
    this.remove(callButton);
    this.remove(callVideoButton);
    this.remove(desktopSharingButton);
    this.remove(addContactButton);

    clearCustomActionButtons();

    if (!isSelected) return;

    UIContactDetail imContact = null;
    // For now we support instance messaging only for contacts in our
    // contact list until it's implemented for external source contacts.
    if (uiContact.getDescriptor() instanceof MetaContact)
      imContact = uiContact.getDefaultContactDetail(OperationSetBasicInstantMessaging.class);

    int x = (statusIcon == null ? 0 : statusIcon.getIconWidth()) + LEFT_BORDER + H_GAP;

    // Re-initialize the x grid.
    constraints.gridx = 0;
    int gridX = 0;

    if (imContact != null) {
      x += addButton(chatButton, ++gridX, x, false);
    }

    UIContactDetail telephonyContact =
        uiContact.getDefaultContactDetail(OperationSetBasicTelephony.class);

    // Check if contact has additional phone numbers, if yes show the
    // call button
    ContactPhoneUtil contactPhoneUtil = null;

    // check for phone stored in contact info only
    // if telephony contact is missing
    if (uiContact.getDescriptor() != null
        && uiContact.getDescriptor() instanceof MetaContact
        && telephonyContact == null) {
      contactPhoneUtil = ContactPhoneUtil.getPhoneUtil((MetaContact) uiContact.getDescriptor());

      MetaContact metaContact = (MetaContact) uiContact.getDescriptor();
      Iterator<Contact> contacts = metaContact.getContacts();

      while (contacts.hasNext()) // && !hasPhone)
      {
        Contact contact = contacts.next();

        if (!contact.getProtocolProvider().isRegistered()) continue;

        contactPhoneUtil.addDetailsResponseListener(
            contact, new DetailsListener(treeNode, callButton, uiContact));
      }
    }

    // for SourceContact in history that do not support telephony, we
    // show the button but disabled
    List<ProtocolProviderService> providers =
        AccountUtils.getOpSetRegisteredProviders(OperationSetBasicTelephony.class, null, null);

    if ((telephonyContact != null && telephonyContact.getAddress() != null)
        || (contactPhoneUtil != null && contactPhoneUtil.isCallEnabled() && providers.size() > 0)) {
      x += addButton(callButton, ++gridX, x, false);
    }

    UIContactDetail videoContact =
        uiContact.getDefaultContactDetail(OperationSetVideoTelephony.class);

    if (videoContact != null
        || (contactPhoneUtil != null && contactPhoneUtil.isVideoCallEnabled())) {
      x += addButton(callVideoButton, ++gridX, x, false);
    }

    UIContactDetail desktopContact =
        uiContact.getDefaultContactDetail(OperationSetDesktopSharingServer.class);

    if (desktopContact != null
        || (contactPhoneUtil != null && contactPhoneUtil.isDesktopSharingEnabled())) {
      x += addButton(desktopSharingButton, ++gridX, x, false);
    }

    // enable add contact button if contact source has indicated
    // that this is possible
    if (uiContact.getDescriptor() instanceof SourceContact
        && uiContact.getDefaultContactDetail(OperationSetPersistentPresence.class) != null
        && AccountUtils.getOpSetRegisteredProviders(
                    OperationSetPersistentPresence.class, null, null)
                .size()
            > 0
        && !ConfigurationUtils.isAddContactDisabled()) {
      x += addButton(addContactButton, ++gridX, x, false);
    }

    // The list of the contact actions
    // we will create a button for every action
    Collection<SIPCommButton> contactActions = uiContact.getContactCustomActionButtons();

    int lastGridX = gridX;
    if (contactActions != null && contactActions.size() > 0) {
      lastGridX = initContactActionButtons(contactActions, gridX, x);
    } else {
      addLabels(gridX);
    }

    if (lastAddedButton != null) setButtonBg(lastAddedButton, lastGridX, true);

    this.setBounds(0, 0, treeContactList.getWidth(), getPreferredSize().height);
  }
Example #29
0
 /**
  * Returns the value of the chat room open automatically property
  *
  * @param pps the provider
  * @param chatRoomId the chat room id
  * @return the value of the chat room open automatically property
  */
 public static String getChatRoomAutoOpenOption(ProtocolProviderService pps, String chatRoomId) {
   return ConfigurationUtils.getChatRoomProperty(pps, chatRoomId, "openAutomatically");
 }
Example #30
0
 /**
  * Sets chat room open automatically property
  *
  * @param pps the provider
  * @param chatRoomId the chat room id
  * @param value the new value for the property
  */
 public static void setChatRoomAutoOpenOption(
     ProtocolProviderService pps, String chatRoomId, String value) {
   ConfigurationUtils.updateChatRoomProperty(pps, chatRoomId, "openAutomatically", value);
 }