/**
   * Sends a file transfer request to the given <tt>toContact</tt> by specifying the local and
   * remote file path and the <tt>fromContact</tt>, sending the file.
   *
   * @param toContact the contact that should receive the file
   * @param file the file to send
   * @return the transfer object
   * @throws IllegalStateException if the protocol provider is not registered or connected
   * @throws IllegalArgumentException if some of the arguments doesn't fit the protocol requirements
   */
  public FileTransfer sendFile(Contact toContact, File file)
      throws IllegalStateException, IllegalArgumentException {
    assertConnected();

    if (file.length() > getMaximumFileLength())
      throw new IllegalArgumentException("File length exceeds the allowed one for this protocol");

    // Get the aim connection
    AimConnection aimConnection = icqProvider.getAimConnection();

    // Create an outgoing file transfer instance
    OutgoingFileTransfer outgoingFileTransfer =
        aimConnection
            .getIcbmService()
            .getRvConnectionManager()
            .createOutgoingFileTransfer(new Screenname(toContact.getAddress()));

    String id =
        String.valueOf(outgoingFileTransfer.getRvSessionInfo().getRvSession().getRvSessionId());

    FileTransferImpl outFileTransfer =
        new FileTransferImpl(outgoingFileTransfer, id, toContact, file, FileTransfer.OUT);

    // Adding the file to the outgoing file transfer
    try {
      outgoingFileTransfer.setSingleFile(new File(file.getPath()));
    } catch (IOException e) {
      if (logger.isDebugEnabled()) logger.debug("Error sending file", e);
      return null;
    }

    // Notify all interested listeners that a file transfer has been
    // created.
    FileTransferCreatedEvent event = new FileTransferCreatedEvent(outFileTransfer, new Date());

    fireFileTransferCreated(event);

    // Sending the file
    outgoingFileTransfer.sendRequest(new InvitationMessage(""));

    outFileTransfer.fireStatusChangeEvent(FileTransferStatusChangeEvent.PREPARING);

    return outFileTransfer;
  }
예제 #2
0
  @Override
  public boolean connect(AccountLoginListener loginListener) {
    Screenname name = new Screenname(this.getUserName());
    AimConnectionProperties props = new AimConnectionProperties(name, this.getPassword());
    try {
      File dir = Util.getInstance().activity.getDir("aimconfig", Context.MODE_PRIVATE);
      DAppSession sess = new DAppSession(new File(dir.getAbsolutePath(), ".dolca"));
      sess.setSavePrefsOnExit(true);
      aimSession = (DAimAppSession) sess.openAimSession(name);
      connection = aimSession.openConnection(props);

      connection.addStateListener(connStateListener);
      //			connection.addOpenedServiceListener(new OpenedServiceListener() {
      //
      //				public void openedServices(AimConnection conn,
      //						Collection<? extends Service> services) {
      //					// TODO Auto-generated method stub
      //
      //				}
      //
      //				public void closedServices(AimConnection conn,
      //						Collection<? extends Service> services) {
      //					// TODO Auto-generated method stub
      //
      //				}
      //			})

      connection.connect();
      this.loginListener = loginListener;

    } catch (Exception e) {
      String errorMessage = e.getLocalizedMessage();
      loginListener.loginDidFailedWithError(errorMessage != null ? errorMessage : e.toString());
      return false;
    }
    return true;
  }