nl.tue.id.tim
Class FileTransfer

java.lang.Object
  extended bynl.tue.id.tim.FileTransfer
All Implemented Interfaces:
com.valhalla.pluginmanager.Plugin, com.valhalla.pluginmanager.PluginEventListener

public class FileTransfer
extends java.lang.Object
implements com.valhalla.pluginmanager.Plugin, com.valhalla.pluginmanager.PluginEventListener

TIM File Transfer plugin for JBother.

Description: This plugin uses a simple http server for transfering files. it monitors incoming and outgoing messages and reacts on those that started with "/file". A "/file" message is expected to come with a url that links to a file. The sender first upload selected file to the root of the http server (a cache under the users profile directory), then form a url to this file, send a "/file [url]" to the buddy in conversation. The receiver get the url from the message, download the file and send a confirmation message back to the sender.
This plugin also addes a file transfer button to chat panels.

Copyright: Copyright (c) 2005 Jun Hu

Company: ID, TU/e

Version:
1.0
Author:
Jun Hu

Field Summary
private  java.util.ResourceBundle resources
          i18n translation resources.
(package private)  java.lang.String root
          root directory of the simple http server.
(package private)  HttpServer server
          a simple http server for tranfering files.
 
Constructor Summary
FileTransfer()
           
 
Method Summary
private  void conversationHandler(com.valhalla.jbother.plugins.events.ConversationEvent pluginEvent)
          conversationHandler processes the conversation events from ChatPanels.
private  void copy(java.io.File src, java.io.File dst)
          copy one file to another. no worning if the destination file exists. use it with care.
 void downloadFile(java.lang.String f, com.valhalla.jbother.ChatPanel chat)
          download the file, when finish send a confirmation message to the butty in chat.
 void handleEvent(com.valhalla.pluginmanager.PluginEvent pluginEvent)
          This is the event handling interface defined in JBother Plugin.
 boolean init()
          Initiate the plugin.
 void unload()
          Unloads the plugin. remove this plugin from the PluginChain, stop the web server, remove file transfer buttons from ChatPanels.
 java.lang.String uploadFile()
          uploadFile the file will be uploaded to a cahce directory that serves as http root. the cache directory is named "cache" under the current user's profile All the uploaded files will be removed when the virtual machine terminates.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

resources

private java.util.ResourceBundle resources
i18n translation resources.


server

HttpServer server
a simple http server for tranfering files.


root

java.lang.String root
root directory of the simple http server.

Constructor Detail

FileTransfer

public FileTransfer()
Method Detail

init

public boolean init()
Initiate the plugin.
add this plugin to the PluginChain, start the httpServer, add a FileTransferButton to the ChatPanel.

Specified by:
init in interface com.valhalla.pluginmanager.Plugin
Returns:
boolean. if the plugin is sucessfully loaded, retun true.

unload

public void unload()
Unloads the plugin. remove this plugin from the PluginChain, stop the web server, remove file transfer buttons from ChatPanels.

Specified by:
unload in interface com.valhalla.pluginmanager.Plugin

handleEvent

public void handleEvent(com.valhalla.pluginmanager.PluginEvent pluginEvent)
This is the event handling interface defined in JBother Plugin. File Transfer monitors the conversation events distributed from ChatPanel.

Specified by:
handleEvent in interface com.valhalla.pluginmanager.PluginEventListener
Parameters:
pluginEvent - PluginEvent

conversationHandler

private void conversationHandler(com.valhalla.jbother.plugins.events.ConversationEvent pluginEvent)
conversationHandler processes the conversation events from ChatPanels. If RECEIVEING_MESSAGE, check if the message is a file trasfer notification that starts with "/file".
If SENDING_MESSAGE and the message is "/file", then start a dialogue to ask the user for the file to send, upload the selected file to the httpServer root (/cache), form an http url link to this file, modify the message to "/file [url]>".
if the coversation is just initialized, add a file transfer button to the ChatPanel.

Parameters:
pluginEvent - ConversationEvent

uploadFile

public java.lang.String uploadFile()
uploadFile the file will be uploaded to a cahce directory that serves as http root. the cache directory is named "cache" under the current user's profile All the uploaded files will be removed when the virtual machine terminates.

Returns:
String, formatted url link to the file uploaded.

downloadFile

public void downloadFile(java.lang.String f,
                         com.valhalla.jbother.ChatPanel chat)
                  throws java.io.IOException
download the file, when finish send a confirmation message to the butty in chat.

Parameters:
f - String, the url link to the file to download. If the url is malformed, nothing will happen.
chat - ChatPanel, to which the confirmation message will be sent.
Throws:
java.io.IOException - IOException, if anything wrong during downloading, an IOException will be thrown.

copy

private void copy(java.io.File src,
                  java.io.File dst)
           throws java.io.IOException
copy one file to another. no worning if the destination file exists. use it with care.

Parameters:
src - File
dst - File
Throws:
java.io.IOException