Thread: [Zerofile-svn] SF.net SVN: zerofile: [57] trunk/src (Page 2)
Status: Pre-Alpha
Brought to you by:
karl-bengtsson
|
From: <kar...@us...> - 2007-11-27 15:38:31
|
Revision: 57
http://zerofile.svn.sourceforge.net/zerofile/?rev=57&view=rev
Author: karl-bengtsson
Date: 2007-11-27 07:38:23 -0800 (Tue, 27 Nov 2007)
Log Message:
-----------
Implemented DOM XMPP parsing and basic message handling thingys. And various improvements. Huzzah!
Modified Paths:
--------------
trunk/src/XMPPLinkLocalChatSession.java
trunk/src/ZeroFileChatWindow.java
trunk/src/ZeroconfBrowsing.java
Added Paths:
-----------
trunk/src/XMPPDOMParser.java
Added: trunk/src/XMPPDOMParser.java
===================================================================
--- trunk/src/XMPPDOMParser.java (rev 0)
+++ trunk/src/XMPPDOMParser.java 2007-11-27 15:38:23 UTC (rev 57)
@@ -0,0 +1,38 @@
+import java.io.*;
+import javax.xml.parsers.*;
+import org.w3c.dom.*;
+import org.xml.sax.*;
+
+public class XMPPDOMParser {
+ public static String getRootTagName(String XMLexcerpt)
+ {
+ try
+ {
+ DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
+ Document d = factory.newDocumentBuilder().parse(new InputSource(new StringReader(XMLexcerpt)));
+ Node n = d.getFirstChild();
+ return n.getNodeName();
+ }
+ catch (Exception e)
+ {
+ System.out.println(e);
+ }
+ return null;
+ }
+
+ public static String getMessageBodyFromMessageStanza(String stanza)
+ {
+ try
+ {
+ DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
+ Document d = factory.newDocumentBuilder().parse(new InputSource(new StringReader(stanza)));
+ Node n = d.getElementsByTagName("body").item(0);
+ return n.getTextContent();
+ }
+ catch (Exception e)
+ {
+ System.out.println(e);
+ }
+ return null;
+ }
+}
Modified: trunk/src/XMPPLinkLocalChatSession.java
===================================================================
--- trunk/src/XMPPLinkLocalChatSession.java 2007-11-27 13:04:34 UTC (rev 56)
+++ trunk/src/XMPPLinkLocalChatSession.java 2007-11-27 15:38:23 UTC (rev 57)
@@ -7,11 +7,11 @@
public class XMPPLinkLocalChatSession {
private boolean _sentHandshake = false;
- private boolean _recievedHandshake =false;
+ private boolean _recievedHandshake = false;
+ private boolean _sentHangup = false;
private Socket _s;
private Reader _fromRemoteHost;
private PrintWriter _toRemoteHost;
- //private PrintWriter _toUser = new PrintWriter(System.out,true);
private ZeroFileChatWindow _chatWindow;
private Thread _remoteHostReadingThread = new Thread() {
@@ -22,13 +22,13 @@
while ((chars_read = _fromRemoteHost.read(buffer)) != -1)
{
RecievedStanza(String.valueOf(buffer).substring(0,chars_read));
- //_toUser.write(buffer,0,chars_read);
- //_toUser.flush();
- //_chatWindow.printText(String.valueOf(buffer));
}
}
- catch (IOException e) {System.out.println(e);}
- System.out.println("Connection closed!");
+ catch (IOException e)
+ {
+ this.interrupt();
+ }
+
}
};
@@ -66,7 +66,41 @@
private void RecievedStanza(String stanza)
{
- RecievedMessage(stanza);
+ if (stanza.contains("<?xml"))
+ // Stanza is a handshake
+ {
+ _recievedHandshake = true;
+ if (!_sentHandshake)
+ sendHandshake();
+ }
+ else if (stanza.contains("</stream:stream>"))
+ // Stanza is a hangup message
+ {
+ _chatWindow.printText("Opposite party has left the chat");
+ disconnect();
+ }
+ else
+ // Stanza is neither handshake nor hangup, rather a message with a payload of some sort
+ {
+ if (_sentHandshake && _recievedHandshake)
+ {
+ String stanzaType = null;
+ try
+ {
+ stanzaType = XMPPDOMParser.getRootTagName(stanza);
+ }
+ catch (Exception e)
+ {
+ e.printStackTrace();
+ }
+ if (stanzaType.equals("message"))
+ {
+ RecievedMessage(XMPPDOMParser.getMessageBodyFromMessageStanza(stanza));
+ }
+ else
+ System.out.println(stanzaType + " - not yet handled stanza type.");
+ }
+ }
}
private void RecievedMessage(String mess)
@@ -84,7 +118,6 @@
_fromRemoteHost = new InputStreamReader(_s.getInputStream());
_remoteHostReadingThread.start();
_toRemoteHost = new PrintWriter(_s.getOutputStream());
- sendHandshake();
}
catch (Exception e)
{
@@ -102,9 +135,15 @@
{
try
{
- _toRemoteHost.print("</stream:stream>");
- _toRemoteHost.flush();
- _s.close();
+ if (!_sentHangup)
+ {
+ _toRemoteHost.print("</stream:stream>");
+ _toRemoteHost.flush();
+ _s.close();
+ _sentHandshake = false;
+ _recievedHandshake = false;
+ _sentHangup = true;
+ }
}
catch (Exception e)
{
Modified: trunk/src/ZeroFileChatWindow.java
===================================================================
--- trunk/src/ZeroFileChatWindow.java 2007-11-27 13:04:34 UTC (rev 56)
+++ trunk/src/ZeroFileChatWindow.java 2007-11-27 15:38:23 UTC (rev 57)
@@ -71,7 +71,7 @@
_chatWindowFrame.addWindowListener(new WindowListener(){
public void windowClosing(WindowEvent e)
{
-
+ _session.disconnect();
}
public void windowDeiconified(WindowEvent e)
{
@@ -87,7 +87,7 @@
}
public void windowClosed(WindowEvent e)
{
- _session.disconnect();
+
}
public void windowIconified(WindowEvent e)
{
Modified: trunk/src/ZeroconfBrowsing.java
===================================================================
--- trunk/src/ZeroconfBrowsing.java 2007-11-27 13:04:34 UTC (rev 56)
+++ trunk/src/ZeroconfBrowsing.java 2007-11-27 15:38:23 UTC (rev 57)
@@ -19,7 +19,6 @@
if (!ZeroFileMainWindow.containsHost(newHost) && !ZeroconfRegistration.getMyServiceName().equals(name))
{
ZeroFileMainWindow.addHost(newHost);
- System.out.println("hittat servicename: " + name);
}
}
public void serviceLost(DNSSDService browser, int flags, int ifIndex,
@@ -28,10 +27,8 @@
ZeroFileMainWindow.removeHost(new XMPPLinkLocalHost(name));
}
});
- System.out.println("Starting browsing...");
}
static void stopBrowsing(){
_s.stop();
- System.out.println("Stopped browsing");
}
}
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <kar...@us...> - 2007-11-27 21:08:58
|
Revision: 58
http://zerofile.svn.sourceforge.net/zerofile/?rev=58&view=rev
Author: karl-bengtsson
Date: 2007-11-27 13:09:02 -0800 (Tue, 27 Nov 2007)
Log Message:
-----------
*) Added (more or less empty) About-window where we can brag about how great we are.
*) Modified the LayoutManager for the main window to use BorderLayout, and put the contact list inside a ScrollPane, providing scroll bars and a more balanced look.
*) Did likewise for the chat window.
So now our application looks a little bit more professional, at least on a Mac. Please try it out on other platforms.
Modified Paths:
--------------
trunk/src/ZeroFileChatWindow.java
trunk/src/ZeroFileMainWindow.java
trunk/src/ZeroFileSettingsWindow.java
Added Paths:
-----------
trunk/src/ZeroFileAboutWindow.java
Added: trunk/src/ZeroFileAboutWindow.java
===================================================================
--- trunk/src/ZeroFileAboutWindow.java (rev 0)
+++ trunk/src/ZeroFileAboutWindow.java 2007-11-27 21:09:02 UTC (rev 58)
@@ -0,0 +1,27 @@
+import java.awt.*;
+import javax.swing.*;
+
+/**
+ *
+ */
+
+/**
+ * @author Karl Bengtsson
+ *
+ */
+public class ZeroFileAboutWindow {
+ private static JFrame _aboutWindowFrame;
+ private static JLabel _aboutText;
+
+ public static void showAboutWindow()
+ {
+ _aboutWindowFrame = new JFrame();
+ _aboutWindowFrame.setTitle("About ZeroFile");
+ _aboutWindowFrame.setSize(new Dimension(300,200));
+ _aboutWindowFrame.setLayout(new BorderLayout(10,10));
+ _aboutText = new JLabel();
+ _aboutText.setText("Hell jeas!");
+ _aboutWindowFrame.add(_aboutText,BorderLayout.CENTER);
+ _aboutWindowFrame.setVisible(true);
+ }
+}
Modified: trunk/src/ZeroFileChatWindow.java
===================================================================
--- trunk/src/ZeroFileChatWindow.java 2007-11-27 15:38:23 UTC (rev 57)
+++ trunk/src/ZeroFileChatWindow.java 2007-11-27 21:09:02 UTC (rev 58)
@@ -8,23 +8,12 @@
*/
public class ZeroFileChatWindow {
private JFrame _chatWindowFrame;
- private JTextArea _chatTextArea;
+ private JTextArea _chatTextArea = new JTextArea();;
+ private JScrollPane _chatTextAreaPane = new JScrollPane(_chatTextArea);
private JPanel _bottomPanel;
private JTextField _entryTextField;
private JButton _sendButton;
private XMPPLinkLocalChatSession _session;
- /*public ZeroFileChatWindow(Socket sock)
- {
- this.ZeroFileChatWindowInit();
- _session = new XMPPLinkLocalChatSession(this,sock);
- }
- public ZeroFileChatWindow(XMPPLinkLocalHost hostToChatWith)
- {
- this.ZeroFileChatWindowInit();
- hostToChatWith.updateData();
- this.setWindowTitle(hostToChatWith.toString());
- _session = new XMPPLinkLocalChatSession(this,hostToChatWith);
- }*/
public ZeroFileChatWindow(XMPPLinkLocalChatSession sess)
{
@@ -42,29 +31,50 @@
_chatTextArea.append("\n"+s);
}
+ public void sendMessage(String str)
+ {
+ printText(str);
+ _session.sendMessage(str);
+ _entryTextField.setText("");
+ }
+
private void ZeroFileChatWindowInit()
{
_chatWindowFrame = new JFrame();
- _chatWindowFrame.setLayout(new GridLayout(0,1,1,1));
+ _chatWindowFrame.setLayout(new BorderLayout(1,1));
_chatWindowFrame.setLocation(0,400);
_chatWindowFrame.setSize(new Dimension(300,200));
- _chatTextArea = new JTextArea();
- _chatWindowFrame.add(_chatTextArea);
+ _chatTextAreaPane.setHorizontalScrollBarPolicy(JScrollPane.HORIZONTAL_SCROLLBAR_NEVER);
+ _chatWindowFrame.add(_chatTextAreaPane,BorderLayout.CENTER);
_bottomPanel = new JPanel();
- _chatWindowFrame.add(_bottomPanel);
+ _chatWindowFrame.add(_bottomPanel,BorderLayout.SOUTH);
_bottomPanel.setLayout(new GridLayout(1,0,1,1));
_entryTextField = new JTextField();
_sendButton = new JButton("Send");
_bottomPanel.add(_entryTextField);
+ _entryTextField.addKeyListener(
+ new KeyListener()
+ {
+ public void keyPressed(KeyEvent e)
+ {
+ }
+ public void keyReleased(KeyEvent e)
+ {
+ }
+ public void keyTyped(KeyEvent e)
+ {
+ if (e.getKeyChar() == '\n')
+ {
+ sendMessage(_entryTextField.getText());
+ }
+ }
+ });
_bottomPanel.add(_sendButton);
_chatWindowFrame.setVisible(true);
_sendButton.addActionListener(
new ActionListener(){
public void actionPerformed(ActionEvent sendButtonPress){
- String message = _entryTextField.getText();
- printText(message);
- _session.sendMessage(message);
- _entryTextField.setText("");
+ sendMessage(_entryTextField.getText());
}
}
);
Modified: trunk/src/ZeroFileMainWindow.java
===================================================================
--- trunk/src/ZeroFileMainWindow.java 2007-11-27 15:38:23 UTC (rev 57)
+++ trunk/src/ZeroFileMainWindow.java 2007-11-27 21:09:02 UTC (rev 58)
@@ -1,6 +1,5 @@
import java.awt.*;
import java.awt.event.*;
-
import javax.swing.*;
public class ZeroFileMainWindow
@@ -16,8 +15,9 @@
private static JMenu _helpMenu;
private static JMenuItem _aboutMenuItem;
private static JComboBox _statusLista;
- private static DefaultListModel _contactListModel = new DefaultListModel();;
- private static JList _contactList = new JList(_contactListModel);;
+ private static DefaultListModel _contactListModel = new DefaultListModel();
+ private static JList _contactList = new JList(_contactListModel);
+ private static JScrollPane _contactListPane = new JScrollPane(_contactList);
static boolean containsHost(XMPPLinkLocalHost h)
{
@@ -29,7 +29,6 @@
static void addHost(XMPPLinkLocalHost h)
{
- //System.out.println("forsoker adda: " + h.toString());
h.updateData();
_contactListModel.addElement(h);
}
@@ -71,10 +70,15 @@
_helpMenu = new JMenu("Help");
_mainMenuBar.add(_helpMenu);
_aboutMenuItem = new JMenuItem("About..");
+ _aboutMenuItem.addActionListener(new ActionListener(){
+ public void actionPerformed(ActionEvent e) {
+ ZeroFileAboutWindow.showAboutWindow();
+ }
+ });
_helpMenu.add(_aboutMenuItem);
// Layout, sizes, and the connection of the JMenuBar
- _mainWindowFrame.setLayout(new GridLayout(0,1,1,1));
+ _mainWindowFrame.setLayout(new BorderLayout(1,1));
_mainWindowFrame.setMinimumSize(new Dimension(120,300));
_mainWindowFrame.setSize(new Dimension(150,400));
_mainWindowFrame.setJMenuBar(_mainMenuBar);
@@ -83,7 +87,7 @@
String[] statusModes = {"Available","Away","Do not disturb"};
_statusLista = new JComboBox(statusModes);
_statusLista.setMaximumSize(new Dimension(20,100));
- _mainWindowFrame.add(_statusLista);
+ _mainWindowFrame.add(_statusLista,BorderLayout.NORTH);
_statusLista.addItemListener(new ItemListener(){
public void itemStateChanged(ItemEvent e)
{
@@ -97,8 +101,6 @@
});
// Contact list
- //_contactListModel = new DefaultListModel();
- //_contactList = new JList(_contactListModel);
_contactList.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
_contactList.setLayoutOrientation(JList.VERTICAL);
_contactList.setSize(500,700);
@@ -122,11 +124,11 @@
public void mouseClicked(MouseEvent e)
{
if (e.getClickCount() == 2)
- //new ZeroFileChatWindow((XMPPLinkLocalHost)_contactList.getSelectedValue());
new XMPPLinkLocalChatSession((XMPPLinkLocalHost)_contactList.getSelectedValue());
}
});
- _mainWindowFrame.add(_contactList);
+ _contactListPane.setHorizontalScrollBarPolicy(JScrollPane.HORIZONTAL_SCROLLBAR_NEVER);
+ _mainWindowFrame.add(_contactListPane,BorderLayout.CENTER);
// Show the window
_mainWindowFrame.setVisible(true);
Modified: trunk/src/ZeroFileSettingsWindow.java
===================================================================
--- trunk/src/ZeroFileSettingsWindow.java 2007-11-27 15:38:23 UTC (rev 57)
+++ trunk/src/ZeroFileSettingsWindow.java 2007-11-27 21:09:02 UTC (rev 58)
@@ -7,7 +7,7 @@
* @author Richard
*/
-public class ZeroFileSettingsWindow
+public class ZeroFileSettingsWindow
{
static void startSettingsWindow()
{
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <kar...@us...> - 2007-11-29 15:53:41
|
Revision: 59
http://zerofile.svn.sourceforge.net/zerofile/?rev=59&view=rev
Author: karl-bengtsson
Date: 2007-11-29 07:37:32 -0800 (Thu, 29 Nov 2007)
Log Message:
-----------
Helt kukad release, som f?\195?\182rmodligen inte alls fungerar. Men det ?\195?\164r ny kod iaf.
Modified Paths:
--------------
trunk/src/XMPPDOMParser.java
trunk/src/XMPPLinkLocalChatSession.java
trunk/src/XMPPLinkLocalHost.java
trunk/src/XMPPSessionListener.java
trunk/src/ZeroFile.java
trunk/src/ZeroFileChatWindow.java
trunk/src/ZeroFileMainWindow.java
trunk/src/ZeroconfRegistration.java
Modified: trunk/src/XMPPDOMParser.java
===================================================================
--- trunk/src/XMPPDOMParser.java 2007-11-27 21:09:02 UTC (rev 58)
+++ trunk/src/XMPPDOMParser.java 2007-11-29 15:37:32 UTC (rev 59)
@@ -16,8 +16,8 @@
catch (Exception e)
{
System.out.println(e);
+ return null;
}
- return null;
}
public static String getMessageBodyFromMessageStanza(String stanza)
@@ -32,7 +32,37 @@
catch (Exception e)
{
System.out.println(e);
+ return null;
}
- return null;
}
+
+ public static String getToAttributeFromMessageStanza(String stanza)
+ {
+ try
+ {
+ DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
+ Document d = factory.newDocumentBuilder().parse(new InputSource(new StringReader(stanza)));
+ return d.getAttributes().getNamedItem("to").toString();
+ }
+ catch (Exception e)
+ {
+ System.out.println(e);
+ return null;
+ }
+ }
+
+ public static String getFromAttributeFromMessageStanza(String stanza)
+ {
+ try
+ {
+ DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
+ Document d = factory.newDocumentBuilder().parse(new InputSource(new StringReader(stanza)));
+ return d.getAttributes().getNamedItem("from").toString();
+ }
+ catch (Exception e)
+ {
+ System.out.println(e);
+ return null;
+ }
+ }
}
Modified: trunk/src/XMPPLinkLocalChatSession.java
===================================================================
--- trunk/src/XMPPLinkLocalChatSession.java 2007-11-27 21:09:02 UTC (rev 58)
+++ trunk/src/XMPPLinkLocalChatSession.java 2007-11-29 15:37:32 UTC (rev 59)
@@ -13,6 +13,7 @@
private Reader _fromRemoteHost;
private PrintWriter _toRemoteHost;
private ZeroFileChatWindow _chatWindow;
+ private XMPPLinkLocalHost _chatPartner;
private Thread _remoteHostReadingThread = new Thread() {
public void run() {
@@ -49,6 +50,7 @@
public XMPPLinkLocalChatSession(XMPPLinkLocalHost hostToChatWith)
{
+ _chatPartner = hostToChatWith;
_chatWindow = new ZeroFileChatWindow(this);
try
{
@@ -64,19 +66,26 @@
}
}
+ public XMPPLinkLocalHost getChatPartner()
+ {
+ return _chatPartner;
+ }
+
private void RecievedStanza(String stanza)
{
if (stanza.contains("<?xml"))
// Stanza is a handshake
{
_recievedHandshake = true;
+ System.out.println(stanza);
if (!_sentHandshake)
sendHandshake();
}
else if (stanza.contains("</stream:stream>"))
// Stanza is a hangup message
{
- _chatWindow.printText("Opposite party has left the chat");
+ if (_chatWindow != null)
+ _chatWindow.printText("Opposite party has left the chat");
disconnect();
}
else
@@ -95,18 +104,36 @@
}
if (stanzaType.equals("message"))
{
- RecievedMessage(XMPPDOMParser.getMessageBodyFromMessageStanza(stanza));
- }
+ String msg = XMPPDOMParser.getMessageBodyFromMessageStanza(stanza);
+ String to = XMPPDOMParser.getToAttributeFromMessageStanza(stanza);
+ String from = XMPPDOMParser.getFromAttributeFromMessageStanza(stanza);
+ RecievedMessage(msg,to,from);
+ System.out.println(stanza);
+ }
else
- System.out.println(stanzaType + " - not yet handled stanza type.");
+ System.out.println(stanza);
+ //System.out.println(stanzaType + " - not yet handled stanza type.");
}
}
}
- private void RecievedMessage(String mess)
+ private void RecievedMessage(String mess,String to,String from)
{
+ if (_chatPartner == null)
+ {
+ _chatPartner = new XMPPLinkLocalHost(from);
+ _chatPartner.updateData();
+ }
if (_chatWindow == null)
+ {
+ /* TODO - set _chatPartner to a new host and update this hosts data
+ * based on a browse of the network using the stanzas to-attribute
+ * as search parameter - this also means that we need the entire stanza at this
+ * point, not just the payload.
+ */
+ System.out.println("nu skapas f\x9Anstret");
_chatWindow = new ZeroFileChatWindow(this);
+ }
_chatWindow.printText(mess);
}
@@ -127,6 +154,9 @@
public void sendMessage(String m)
{
+ String test = "<iq type='get' from='"+ZeroconfRegistration.getMyServiceName()+"' to='" + _chatPartner.getServiceName() + "' id='items1'> <query xmlns='http://jabber.org/protocol/disco#items'/></iq>";
+ _toRemoteHost.print(test);
+ _toRemoteHost.flush();
_toRemoteHost.print("<message><body>"+m+"</body></message>");
_toRemoteHost.flush();
}
Modified: trunk/src/XMPPLinkLocalHost.java
===================================================================
--- trunk/src/XMPPLinkLocalHost.java 2007-11-27 21:09:02 UTC (rev 58)
+++ trunk/src/XMPPLinkLocalHost.java 2007-11-29 15:37:32 UTC (rev 59)
@@ -44,16 +44,19 @@
}
public String toString()
- {
- if (_nickName != null)
+ {
+ return _firstName;
+ /*if (_nickName != null)
return _nickName;
else
if (_firstName != null && _lastName != null)
return _firstName + " " + _lastName;
else
return _serviceName;
+ */
}
+ // TODO - Fungerar inte alltid
public void updateData()
{
try
@@ -79,13 +82,18 @@
if (txtRecord.contains("nick"))
_nickName = txtRecord.getValueAsString("nick").toString();
}
+ System.out.println("nu har vi resolvat");
+ System.out.println("1st - " + _firstName);
+ System.out.println("2nd - " +_lastName);
+ System.out.println("nick - "+ _nickName);
+ System.out.println("vid: " + _host + ":" + _port);
_r.stop();
}
});
}
catch (Exception e)
{
- System.out.println("Error: " + e.getStackTrace().toString());
+ System.out.println("Error: " + e);
}
}
Modified: trunk/src/XMPPSessionListener.java
===================================================================
--- trunk/src/XMPPSessionListener.java 2007-11-27 21:09:02 UTC (rev 58)
+++ trunk/src/XMPPSessionListener.java 2007-11-29 15:37:32 UTC (rev 59)
@@ -12,7 +12,6 @@
while(true)
{
Socket connection = _listeningSock.accept();
- //new ZeroFileChatWindow(connection);
new XMPPLinkLocalChatSession(connection);
}
}
Modified: trunk/src/ZeroFile.java
===================================================================
--- trunk/src/ZeroFile.java 2007-11-27 21:09:02 UTC (rev 58)
+++ trunk/src/ZeroFile.java 2007-11-29 15:37:32 UTC (rev 59)
@@ -25,18 +25,20 @@
}
}
- public static String getServiceName()
+ public static String getSuggestedServiceName()
{
- String serviceName = "serviceName";
+ String userName = System.getProperty("user.name");
+ String hostName;
try
{
InetAddress localMachine = InetAddress.getLocalHost();
- serviceName = localMachine.getHostName();
+ hostName = localMachine.getHostName().split("\\.")[0];
+ return userName + "@" + hostName;
}
catch (Exception e)
{
System.out.println(e);
+ return null;
}
- return serviceName;
}
}
Modified: trunk/src/ZeroFileChatWindow.java
===================================================================
--- trunk/src/ZeroFileChatWindow.java 2007-11-27 21:09:02 UTC (rev 58)
+++ trunk/src/ZeroFileChatWindow.java 2007-11-29 15:37:32 UTC (rev 59)
@@ -19,6 +19,7 @@
{
this.ZeroFileChatWindowInit();
_session = sess;
+ _chatWindowFrame.setTitle(_session.getChatPartner().toString());
}
public void setWindowTitle(String t)
Modified: trunk/src/ZeroFileMainWindow.java
===================================================================
--- trunk/src/ZeroFileMainWindow.java 2007-11-27 21:09:02 UTC (rev 58)
+++ trunk/src/ZeroFileMainWindow.java 2007-11-29 15:37:32 UTC (rev 59)
@@ -29,7 +29,7 @@
static void addHost(XMPPLinkLocalHost h)
{
- h.updateData();
+ //h.updateData();
_contactListModel.addElement(h);
}
Modified: trunk/src/ZeroconfRegistration.java
===================================================================
--- trunk/src/ZeroconfRegistration.java 2007-11-27 21:09:02 UTC (rev 58)
+++ trunk/src/ZeroconfRegistration.java 2007-11-29 15:37:32 UTC (rev 59)
@@ -14,7 +14,8 @@
static void registerService(String status,int port)
throws DNSSDException, InterruptedException
{
- _r = DNSSD.register(null, "_presence._tcp", port, new RegisterListener()
+
+ _r = DNSSD.register(ZeroFile.getSuggestedServiceName(), "_presence._tcp", port, new RegisterListener()
{
public void serviceRegistered(DNSSDRegistration registration, int flags,
String serviceName, String regType, String domain)
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <kar...@us...> - 2007-11-29 23:20:30
|
Revision: 60
http://zerofile.svn.sourceforge.net/zerofile/?rev=60&view=rev
Author: karl-bengtsson
Date: 2007-11-29 15:20:21 -0800 (Thu, 29 Nov 2007)
Log Message:
-----------
*) UpdateData() on XMPPLinkLocalHost is now blocking, meaning that most of the problems with the main contact list not being properly updated due to synchronization issues should now be resolved.
*) Code has been added to look through the contact list for possible hosts that we are communicating with when a session is opened on a socket. This implementation and the corresponding required changes in the registration code means that only one instance of the program will operate properly on a machine at any given time.
*) This also means that we now have a proper status bar title set on sessions originated by someone else as well.
*) The chat window messages have been improved, with indication of who sent what message, you or your chat partner.
Modified Paths:
--------------
trunk/src/XMPPDOMParser.java
trunk/src/XMPPLinkLocalChatSession.java
trunk/src/XMPPLinkLocalHost.java
trunk/src/ZeroFile.java
trunk/src/ZeroFileChatWindow.java
trunk/src/ZeroFileMainWindow.java
trunk/src/ZeroconfRegistration.java
Modified: trunk/src/XMPPDOMParser.java
===================================================================
--- trunk/src/XMPPDOMParser.java 2007-11-29 15:37:32 UTC (rev 59)
+++ trunk/src/XMPPDOMParser.java 2007-11-29 23:20:21 UTC (rev 60)
@@ -15,7 +15,6 @@
}
catch (Exception e)
{
- System.out.println(e);
return null;
}
}
@@ -31,7 +30,6 @@
}
catch (Exception e)
{
- System.out.println(e);
return null;
}
}
@@ -46,7 +44,6 @@
}
catch (Exception e)
{
- System.out.println(e);
return null;
}
}
@@ -61,7 +58,6 @@
}
catch (Exception e)
{
- System.out.println(e);
return null;
}
}
Modified: trunk/src/XMPPLinkLocalChatSession.java
===================================================================
--- trunk/src/XMPPLinkLocalChatSession.java 2007-11-29 15:37:32 UTC (rev 59)
+++ trunk/src/XMPPLinkLocalChatSession.java 2007-11-29 23:20:21 UTC (rev 60)
@@ -77,7 +77,6 @@
// Stanza is a handshake
{
_recievedHandshake = true;
- System.out.println(stanza);
if (!_sentHandshake)
sendHandshake();
}
@@ -93,7 +92,19 @@
{
if (_sentHandshake && _recievedHandshake)
{
- String stanzaType = null;
+ String stanzaType = null;
+ if (_chatPartner == null)
+ {
+ if (XMPPDOMParser.getFromAttributeFromMessageStanza(stanza) != null && !XMPPDOMParser.getFromAttributeFromMessageStanza(stanza).equals(""))
+ {
+ _chatPartner = new XMPPLinkLocalHost(XMPPDOMParser.getFromAttributeFromMessageStanza(stanza));
+ }
+ else
+ {
+ _chatPartner = ZeroFileMainWindow.getHostFromContactList(_s.getInetAddress());
+ }
+ _chatPartner.updateData();
+ }
try
{
stanzaType = XMPPDOMParser.getRootTagName(stanza);
@@ -104,36 +115,21 @@
}
if (stanzaType.equals("message"))
{
- String msg = XMPPDOMParser.getMessageBodyFromMessageStanza(stanza);
- String to = XMPPDOMParser.getToAttributeFromMessageStanza(stanza);
- String from = XMPPDOMParser.getFromAttributeFromMessageStanza(stanza);
- RecievedMessage(msg,to,from);
- System.out.println(stanza);
+ RecievedMessage(XMPPDOMParser.getMessageBodyFromMessageStanza(stanza));
}
else
System.out.println(stanza);
- //System.out.println(stanzaType + " - not yet handled stanza type.");
}
}
}
- private void RecievedMessage(String mess,String to,String from)
+ private void RecievedMessage(String mess)
{
- if (_chatPartner == null)
- {
- _chatPartner = new XMPPLinkLocalHost(from);
- _chatPartner.updateData();
- }
if (_chatWindow == null)
{
- /* TODO - set _chatPartner to a new host and update this hosts data
- * based on a browse of the network using the stanzas to-attribute
- * as search parameter - this also means that we need the entire stanza at this
- * point, not just the payload.
- */
- System.out.println("nu skapas f\x9Anstret");
_chatWindow = new ZeroFileChatWindow(this);
}
+ _chatWindow.printText(_chatPartner.toString()+":");
_chatWindow.printText(mess);
}
@@ -154,11 +150,9 @@
public void sendMessage(String m)
{
- String test = "<iq type='get' from='"+ZeroconfRegistration.getMyServiceName()+"' to='" + _chatPartner.getServiceName() + "' id='items1'> <query xmlns='http://jabber.org/protocol/disco#items'/></iq>";
- _toRemoteHost.print(test);
+ String messageStanza = "<message to=\""+_chatPartner.getServiceName()+"\" from=\""+ZeroconfRegistration.getMyServiceName()+"\"><body>"+m+"</body></message>";
+ _toRemoteHost.print(messageStanza);
_toRemoteHost.flush();
- _toRemoteHost.print("<message><body>"+m+"</body></message>");
- _toRemoteHost.flush();
}
public void disconnect()
Modified: trunk/src/XMPPLinkLocalHost.java
===================================================================
--- trunk/src/XMPPLinkLocalHost.java 2007-11-29 15:37:32 UTC (rev 59)
+++ trunk/src/XMPPLinkLocalHost.java 2007-11-29 23:20:21 UTC (rev 60)
@@ -10,6 +10,7 @@
private String _firstName;
private String _lastName;
private String _host;
+ private Boolean _hasBeenResolved;
private int _port;
private static DNSSDService _r;
@@ -45,22 +46,23 @@
public String toString()
{
- return _firstName;
- /*if (_nickName != null)
+ if (_nickName != null && !_nickName.equals(""))
return _nickName;
else
- if (_firstName != null && _lastName != null)
- return _firstName + " " + _lastName;
+ if (_firstName != null && !_firstName.equals(""))
+ if (_lastName != null && !_lastName.equals(""))
+ return _firstName + " " + _lastName;
+ else
+ return _firstName;
else
return _serviceName;
- */
}
- // TODO - Fungerar inte alltid
public void updateData()
{
try
{
+ _hasBeenResolved = false;
_r = DNSSD.resolve(0, DNSSD.ALL_INTERFACES, _serviceName, "_presence._tcp", "local", new ResolveListener()
{
public void operationFailed(DNSSDService service,int errorCode)
@@ -71,6 +73,7 @@
public void serviceResolved(DNSSDService resolver, int flags, int ifIndex,
String fullName, String hostName, int port, TXTRecord txtRecord)
{
+ _hasBeenResolved = true;
_host = hostName;
_port = port;
if (txtRecord != null)
@@ -82,18 +85,25 @@
if (txtRecord.contains("nick"))
_nickName = txtRecord.getValueAsString("nick").toString();
}
- System.out.println("nu har vi resolvat");
- System.out.println("1st - " + _firstName);
- System.out.println("2nd - " +_lastName);
- System.out.println("nick - "+ _nickName);
- System.out.println("vid: " + _host + ":" + _port);
_r.stop();
}
});
+ while (!_hasBeenResolved)
+ {
+ try
+ {
+ Thread.sleep(50);
+ }
+ catch (InterruptedException e)
+ {
+ e.printStackTrace();
+ }
+ }
}
catch (Exception e)
{
System.out.println("Error: " + e);
+ System.out.println(_serviceName);
}
}
Modified: trunk/src/ZeroFile.java
===================================================================
--- trunk/src/ZeroFile.java 2007-11-29 15:37:32 UTC (rev 59)
+++ trunk/src/ZeroFile.java 2007-11-29 23:20:21 UTC (rev 60)
@@ -7,6 +7,10 @@
* @throws IOException
*/
public static void main(String[] args) throws IOException {
+ System.out.println(
+ new java.io.OutputStreamWriter(
+ new java.io.ByteArrayOutputStream()).getEncoding()
+ );
ZeroFileMainWindow.startMainWindow();
ZeroFileSettings.loadSettings();
try
Modified: trunk/src/ZeroFileChatWindow.java
===================================================================
--- trunk/src/ZeroFileChatWindow.java 2007-11-29 15:37:32 UTC (rev 59)
+++ trunk/src/ZeroFileChatWindow.java 2007-11-29 23:20:21 UTC (rev 60)
@@ -29,12 +29,13 @@
public void printText(String s)
{
- _chatTextArea.append("\n"+s);
+ _chatTextArea.append(s+"\n");
}
public void sendMessage(String str)
{
- printText(str);
+ printText("You:");
+ printText(str+"\n");
_session.sendMessage(str);
_entryTextField.setText("");
}
Modified: trunk/src/ZeroFileMainWindow.java
===================================================================
--- trunk/src/ZeroFileMainWindow.java 2007-11-29 15:37:32 UTC (rev 59)
+++ trunk/src/ZeroFileMainWindow.java 2007-11-29 23:20:21 UTC (rev 60)
@@ -1,5 +1,6 @@
import java.awt.*;
import java.awt.event.*;
+import java.net.*;
import javax.swing.*;
public class ZeroFileMainWindow
@@ -22,14 +23,37 @@
static boolean containsHost(XMPPLinkLocalHost h)
{
for (int i = 0; i<_contactListModel.size(); i++)
+ {
if (((XMPPLinkLocalHost)_contactListModel.getElementAt(i)).getServiceName().equals(h.getServiceName()))
return true;
+ }
return false;
}
+ static XMPPLinkLocalHost getHostFromContactList(InetAddress searchedAddress)
+ {
+ for (int i = 0; i<_contactListModel.size(); i++)
+ {
+ InetAddress iteratedAddress = null;
+ XMPPLinkLocalHost iteratedHost = (XMPPLinkLocalHost)_contactListModel.getElementAt(i);
+ try
+ {
+ iteratedAddress = InetAddress.getByName(iteratedHost.getHost());
+ }
+ catch (Exception e)
+ {
+ System.out.println(e);
+ }
+ if (searchedAddress.equals(iteratedAddress))
+ {
+ return (XMPPLinkLocalHost)_contactListModel.getElementAt(i);
+ }
+ }
+ return new XMPPLinkLocalHost(null);
+ }
+
static void addHost(XMPPLinkLocalHost h)
{
- //h.updateData();
_contactListModel.addElement(h);
}
Modified: trunk/src/ZeroconfRegistration.java
===================================================================
--- trunk/src/ZeroconfRegistration.java 2007-11-29 15:37:32 UTC (rev 59)
+++ trunk/src/ZeroconfRegistration.java 2007-11-29 23:20:21 UTC (rev 60)
@@ -10,12 +10,14 @@
private static TXTRecord _txtRecord = new TXTRecord();
private static DNSSDRegistration _r;
private static String _myServiceName;
+ private static Boolean _registrationStarted = false;
static void registerService(String status,int port)
throws DNSSDException, InterruptedException
{
-
- _r = DNSSD.register(ZeroFile.getSuggestedServiceName(), "_presence._tcp", port, new RegisterListener()
+ _registrationStarted = true;
+ _r = DNSSD.register(0,0,ZeroFile.getSuggestedServiceName(), "_presence._tcp","local",null,port,_txtRecord, new RegisterListener()
+ //_r = DNSSD.register(ZeroFile.getSuggestedServiceName(), "_presence._tcp",port, new RegisterListener()
{
public void serviceRegistered(DNSSDRegistration registration, int flags,
String serviceName, String regType, String domain)
@@ -36,13 +38,25 @@
public static String getMyServiceName()
{
- while (_myServiceName == null)
- try {
- Thread.sleep(50);
- } catch (InterruptedException e) {
- e.printStackTrace();
+ if (!_registrationStarted)
+ {
+ return null;
+ }
+ else
+ {
+ while (_myServiceName == null)
+ {
+ try
+ {
+ Thread.sleep(50);
+ }
+ catch (InterruptedException e)
+ {
+ e.printStackTrace();
+ }
}
return _myServiceName;
+ }
}
static void registerService(int port)
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <kar...@us...> - 2007-12-04 13:08:47
|
Revision: 61
http://zerofile.svn.sourceforge.net/zerofile/?rev=61&view=rev
Author: karl-bengtsson
Date: 2007-12-04 05:08:49 -0800 (Tue, 04 Dec 2007)
Log Message:
-----------
Added method to interpret URL message
Modified Paths:
--------------
trunk/src/XMPPDOMParser.java
trunk/src/XMPPLinkLocalChatSession.java
Modified: trunk/src/XMPPDOMParser.java
===================================================================
--- trunk/src/XMPPDOMParser.java 2007-11-29 23:20:21 UTC (rev 60)
+++ trunk/src/XMPPDOMParser.java 2007-12-04 13:08:49 UTC (rev 61)
@@ -61,4 +61,19 @@
return null;
}
}
+
+ public static String getUrlFromFileTransferStanza(String stanza)
+ {
+ try
+ {
+ DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
+ Document d = factory.newDocumentBuilder().parse(new InputSource(new StringReader(stanza)));
+ return d.getElementsByTagName("url").toString();
+ //return d.getAttributes().getNamedItem("from").toString();
+ }
+ catch (Exception e)
+ {
+ return null;
+ }
+ }
}
Modified: trunk/src/XMPPLinkLocalChatSession.java
===================================================================
--- trunk/src/XMPPLinkLocalChatSession.java 2007-11-29 23:20:21 UTC (rev 60)
+++ trunk/src/XMPPLinkLocalChatSession.java 2007-12-04 13:08:49 UTC (rev 61)
@@ -115,7 +115,19 @@
}
if (stanzaType.equals("message"))
{
- RecievedMessage(XMPPDOMParser.getMessageBodyFromMessageStanza(stanza));
+ if (XMPPDOMParser.getMessageBodyFromMessageStanza(stanza).equals(""))
+ {
+ if (stanza.contains("<x xmlns=\"jabber:x:oob\">"))
+ {
+ System.out.println(XMPPDOMParser.getUrlFromFileTransferStanza(stanza));
+ // This is a file
+
+ }
+ }
+ else
+ {
+ RecievedMessage(XMPPDOMParser.getMessageBodyFromMessageStanza(stanza));
+ }
}
else
System.out.println(stanza);
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <kar...@us...> - 2007-12-04 14:00:32
|
Revision: 65
http://zerofile.svn.sourceforge.net/zerofile/?rev=65&view=rev
Author: karl-bengtsson
Date: 2007-12-04 06:00:29 -0800 (Tue, 04 Dec 2007)
Log Message:
-----------
further refinement of download methods
Modified Paths:
--------------
trunk/src/XMPPLinkLocalChatSession.java
trunk/src/ZeroFile.java
Modified: trunk/src/XMPPLinkLocalChatSession.java
===================================================================
--- trunk/src/XMPPLinkLocalChatSession.java 2007-12-04 13:49:00 UTC (rev 64)
+++ trunk/src/XMPPLinkLocalChatSession.java 2007-12-04 14:00:29 UTC (rev 65)
@@ -120,9 +120,16 @@
if (stanza.contains("<x xmlns=\"jabber:x:oob\">"))
{
System.out.println(XMPPDOMParser.getUrlFromFileTransferStanza(stanza));
- ZeroFile.downloadFileFromHTTP(XMPPDOMParser.getUrlFromFileTransferStanza(stanza));
- // This is a file
-
+ if (ZeroFileSettings.getCheckBox().equals("true"))
+ {
+ ZeroFile.downloadFileFromHTTP(XMPPDOMParser.getUrlFromFileTransferStanza(stanza));
+ _chatWindow.printText("Downloading file from chat partner");
+ }
+ else
+ {
+ ZeroFile.downloadFileFromHTTP(XMPPDOMParser.getUrlFromFileTransferStanza(stanza));
+ _chatWindow.printText("Downloading file from chat partner");
+ }
}
}
else
Modified: trunk/src/ZeroFile.java
===================================================================
--- trunk/src/ZeroFile.java 2007-12-04 13:49:00 UTC (rev 64)
+++ trunk/src/ZeroFile.java 2007-12-04 14:00:29 UTC (rev 65)
@@ -62,9 +62,9 @@
{
String localFileName;
if (!ZeroFileSettings.getDownloadFolder().equals(""))
- localFileName = ZeroFileSettings.getDownloadFolder() + address.substring(lastSlashIndex + 1);
+ localFileName = ZeroFileSettings.getDownloadFolder() +"/"+ address.substring(lastSlashIndex + 1);
else
- localFileName = System.getProperty("user.home") + address.substring(lastSlashIndex + 1);
+ localFileName = System.getProperty("user.home") +"/"+ address.substring(lastSlashIndex + 1);
URL url = new URL(address);
out = new BufferedOutputStream(
new FileOutputStream(localFileName));
@@ -73,11 +73,11 @@
byte[] buffer = new byte[1024];
int numRead;
long numWritten = 0;
- /*while ((numRead = in.read(buffer)) != -1)
+ while ((numRead = in.read(buffer)) != -1)
{
out.write(buffer, 0, numRead);
numWritten += numRead;
- }*/
+ }
System.out.println(localFileName + "\t" + numWritten);
}
catch (Exception exception)
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <kar...@us...> - 2007-12-04 14:31:15
|
Revision: 68
http://zerofile.svn.sourceforge.net/zerofile/?rev=68&view=rev
Author: karl-bengtsson
Date: 2007-12-04 06:31:19 -0800 (Tue, 04 Dec 2007)
Log Message:
-----------
buggfix
Modified Paths:
--------------
trunk/src/XMPPLinkLocalChatSession.java
trunk/src/ZeroFile.java
Modified: trunk/src/XMPPLinkLocalChatSession.java
===================================================================
--- trunk/src/XMPPLinkLocalChatSession.java 2007-12-04 14:25:40 UTC (rev 67)
+++ trunk/src/XMPPLinkLocalChatSession.java 2007-12-04 14:31:19 UTC (rev 68)
@@ -127,7 +127,7 @@
}
else
{
- if (JOptionPane.showConfirmDialog(null, "Ta emot?", "Ta emot fil?", JOptionPane.YES_NO_OPTION) == 1)
+ if (JOptionPane.showConfirmDialog(null, "Ta emot?", "Ta emot fil?", JOptionPane.YES_NO_OPTION) == 0)
{
ZeroFile.downloadFileFromHTTP(XMPPDOMParser.getUrlFromFileTransferStanza(stanza));
_chatWindow.printText("Downloaded file from chat partner");
Modified: trunk/src/ZeroFile.java
===================================================================
--- trunk/src/ZeroFile.java 2007-12-04 14:25:40 UTC (rev 67)
+++ trunk/src/ZeroFile.java 2007-12-04 14:31:19 UTC (rev 68)
@@ -78,7 +78,6 @@
out.write(buffer, 0, numRead);
numWritten += numRead;
}
- System.out.println(localFileName + "\t" + numWritten);
}
catch (Exception exception)
{
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <kar...@us...> - 2007-12-04 14:50:01
|
Revision: 69
http://zerofile.svn.sourceforge.net/zerofile/?rev=69&view=rev
Author: karl-bengtsson
Date: 2007-12-04 06:50:04 -0800 (Tue, 04 Dec 2007)
Log Message:
-----------
Test av file sending stanza grejjer
Modified Paths:
--------------
trunk/src/XMPPLinkLocalChatSession.java
trunk/src/ZeroFileChatWindow.java
Modified: trunk/src/XMPPLinkLocalChatSession.java
===================================================================
--- trunk/src/XMPPLinkLocalChatSession.java 2007-12-04 14:31:19 UTC (rev 68)
+++ trunk/src/XMPPLinkLocalChatSession.java 2007-12-04 14:50:04 UTC (rev 69)
@@ -49,6 +49,25 @@
}
}
+ public void offerFileTransfer(String localFileNameAndPath)
+ {
+ int lastSlashIndex = localFileNameAndPath.lastIndexOf('/');
+ if (!(lastSlashIndex >= 0 && lastSlashIndex < localFileNameAndPath.length() - 1))
+ {
+ System.out.println("blaaargh, felaktigt filnamn");
+ }
+ else
+ {
+ File filen = new File(localFileNameAndPath);
+ long sizeOfFile = filen.length();
+ String filnamn = localFileNameAndPath.substring(lastSlashIndex + 1);
+ String fileTransferStanza = "<message to=\""+_chatPartner.getServiceName()+"\" from=\""+ZeroconfRegistration.getMyServiceName()+"\"><body></body></message>";
+ fileTransferStanza += "<x xmlns=\"jabber:x:oob\">";
+ fileTransferStanza += "<url type=\"file\" size=\""+String.valueOf(sizeOfFile)+"\">";
+ fileTransferStanza += "http://10.100.46.243:5297/25E8656B83FBA3A2/"+localFileNameAndPath+"</url></x></message>";
+ }
+ }
+
public XMPPLinkLocalChatSession(XMPPLinkLocalHost hostToChatWith)
{
_chatPartner = hostToChatWith;
Modified: trunk/src/ZeroFileChatWindow.java
===================================================================
--- trunk/src/ZeroFileChatWindow.java 2007-12-04 14:31:19 UTC (rev 68)
+++ trunk/src/ZeroFileChatWindow.java 2007-12-04 14:50:04 UTC (rev 69)
@@ -13,6 +13,7 @@
private JPanel _bottomPanel;
private JTextField _entryTextField;
private JButton _sendButton;
+ private JButton _sendFileButton;
private XMPPLinkLocalChatSession _session;
public ZeroFileChatWindow(XMPPLinkLocalChatSession sess)
@@ -53,6 +54,7 @@
_bottomPanel.setLayout(new GridLayout(1,0,1,1));
_entryTextField = new JTextField();
_sendButton = new JButton("Send");
+ _sendFileButton = new JButton("Send file...");
_bottomPanel.add(_entryTextField);
_entryTextField.addKeyListener(
new KeyListener()
@@ -72,6 +74,17 @@
}
});
_bottomPanel.add(_sendButton);
+ _bottomPanel.add(_sendFileButton);
+ _sendFileButton.addActionListener(
+ new ActionListener(){
+ public void actionPerformed(ActionEvent sendButtonPress){
+ JFileChooser _fileChooser= new JFileChooser();
+ _fileChooser.setFileSelectionMode(JFileChooser.FILES_ONLY);
+ _fileChooser.showOpenDialog(null);
+ _session.offerFileTransfer(_fileChooser.getSelectedFile().toString());
+ }
+ }
+ );
_chatWindowFrame.setVisible(true);
_sendButton.addActionListener(
new ActionListener(){
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <kar...@us...> - 2007-12-04 15:46:48
|
Revision: 74
http://zerofile.svn.sourceforge.net/zerofile/?rev=74&view=rev
Author: karl-bengtsson
Date: 2007-12-04 07:46:53 -0800 (Tue, 04 Dec 2007)
Log Message:
-----------
added skeleton http server without any functionality
Modified Paths:
--------------
trunk/src/XMPPLinkLocalChatSession.java
Added Paths:
-----------
trunk/src/HttpServer.java
Added: trunk/src/HttpServer.java
===================================================================
--- trunk/src/HttpServer.java (rev 0)
+++ trunk/src/HttpServer.java 2007-12-04 15:46:53 UTC (rev 74)
@@ -0,0 +1,41 @@
+import java.net.*;
+import java.io.*;
+import java.util.*;
+import java.lang.*;
+
+public class HttpServer {
+ private int _portNr;
+ private File[] _files;
+ private XMPPLinkLocalChatSession _session;
+ private Boolean _running;
+ public void start()
+ {
+ _running = true;
+ }
+ public void stop()
+ {
+ _running = false;
+ }
+ HttpServer(XMPPLinkLocalChatSession session)
+ {
+ _session = session;
+ if (!_running)
+ start();
+ }
+ public void addFile(File filen)
+ {
+
+ }
+ public void removeFile(File filen)
+ {
+
+ }
+ public int getPort()
+ {
+ return _portNr;
+ }
+ public Boolean isRunnin()
+ {
+ return _running;
+ }
+}
Modified: trunk/src/XMPPLinkLocalChatSession.java
===================================================================
--- trunk/src/XMPPLinkLocalChatSession.java 2007-12-04 15:32:18 UTC (rev 73)
+++ trunk/src/XMPPLinkLocalChatSession.java 2007-12-04 15:46:53 UTC (rev 74)
@@ -15,6 +15,7 @@
private PrintWriter _toRemoteHost;
private ZeroFileChatWindow _chatWindow;
private XMPPLinkLocalHost _chatPartner;
+ private HttpServer _httpServer = new HttpServer(this);
private Thread _remoteHostReadingThread = new Thread() {
public void run() {
@@ -52,6 +53,7 @@
public void offerFileTransfer(String localFileNameAndPath)
{
File filen = new File(localFileNameAndPath);
+ _httpServer.addFile(filen);
long sizeOfFile = filen.length();
String filnamn = filen.getName();
String fileTransferStanza = "<message to=\""+_chatPartner.getServiceName()+"\" from=\""+ZeroconfRegistration.getMyServiceName()+"\"><body></body>";
@@ -176,6 +178,7 @@
public XMPPLinkLocalChatSession(Socket s)
{
_s = s;
+
try
{
_fromRemoteHost = new InputStreamReader(_s.getInputStream());
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <kar...@us...> - 2007-12-13 11:30:40
|
Revision: 77
http://zerofile.svn.sourceforge.net/zerofile/?rev=77&view=rev
Author: karl-bengtsson
Date: 2007-12-13 03:30:42 -0800 (Thu, 13 Dec 2007)
Log Message:
-----------
File transfer ftw, w00t
Modified Paths:
--------------
trunk/src/HttpServer.java
trunk/src/XMPPLinkLocalChatSession.java
trunk/src/ZeroFile.java
Modified: trunk/src/HttpServer.java
===================================================================
--- trunk/src/HttpServer.java 2007-12-05 07:25:07 UTC (rev 76)
+++ trunk/src/HttpServer.java 2007-12-13 11:30:42 UTC (rev 77)
@@ -1,14 +1,14 @@
import java.net.*;
import java.io.*;
import java.util.*;
-import java.lang.*;
public class HttpServer {
private int _portNr;
- private List<File> _files;
+ private ArrayList<File> _files = new ArrayList<File>();
private XMPPLinkLocalChatSession _session;
private Boolean _running = false;
private ServerSocket _serverSocket;
+ private HttpServer _httpServer = this;
private Thread _httpListenerThread = new Thread()
{
public void run()
@@ -21,7 +21,7 @@
System.out.println("New connection accepted " + connection.getInetAddress() + ":" + connection.getPort());
try
{
- httpRequestHandler request = new httpRequestHandler(connection);
+ httpRequestHandler request = new httpRequestHandler(_httpServer,connection);
// Create a new thread to process the request.
Thread thread = new Thread(request);
@@ -49,6 +49,7 @@
_portNr = _serverSocket.getLocalPort();
System.out.println("httpServer starting running on port " + _portNr);
_httpListenerThread.start();
+ _running = true;
}
catch (Exception e)
{
@@ -67,7 +68,7 @@
}
public void addFile(File filen)
{
- //_files.add(filen); TODO N\x8Ctt buggar h\x8Ar
+ _files.add(filen);
if (!_running)
start();
}
@@ -83,6 +84,33 @@
{
return _running;
}
+ public ArrayList<File> getFiles()
+ {
+ return _files;
+ }
+ public Boolean servesFile(String fileName)
+ {
+ for (int i = 0; i<_files.size(); i++)
+ {
+ if (_files.get(i).getName().equals(fileName))
+ return true;
+ }
+ return false;
+ }
+
+ public File getFile(String fileName)
+ {
+ for (int i = 0; i<_files.size(); i++)
+ {
+ if (_files.get(i).getName().equals(fileName))
+ return _files.get(i);
+ }
+ return null;
+ }
+ public void printDoneMsg()
+ {
+ _session.printTextToChatWindow("File transferred successfully!");
+ }
}
class httpRequestHandler implements Runnable
@@ -92,14 +120,16 @@
InputStream input;
OutputStream output;
BufferedReader br;
+ HttpServer _httpServer;
// Constructor
- public httpRequestHandler(Socket socket) throws Exception
+ public httpRequestHandler(HttpServer httpServer,Socket socket) throws Exception
{
this.socket = socket;
this.input = socket.getInputStream();
this.output = socket.getOutputStream();
this.br = new BufferedReader(new InputStreamReader(socket.getInputStream()));
+ this._httpServer = httpServer;
}
public void run()
@@ -128,19 +158,17 @@
if(temp.equals("GET"))
{
String fileName = s.nextToken();
- fileName = "." + fileName ;
+ fileName = fileName.replaceFirst("/","");
- // Open the requested file.
FileInputStream fis = null ;
- boolean fileExists = true ;
- try
+ boolean fileExists = false;
+ File requestedFile = null;
+ if (_httpServer.servesFile(fileName))
{
- fis = new FileInputStream( fileName ) ;
+ requestedFile = _httpServer.getFile(fileName);
+ fis = new FileInputStream(requestedFile.getPath()) ;
+ fileExists = true;
}
- catch ( FileNotFoundException e )
- {
- fileExists = false ;
- }
// Construct the response message.
String serverLine = "Server: ZeroFile embedded http server/1.0" + CRLF;
@@ -150,7 +178,6 @@
String contentLengthLine = "error";
if ( fileExists )
{
- System.out.println("hittade fil");
statusLine = "HTTP/1.0 200 OK" + CRLF ;
contentTypeLine = "Content-type: " + contentType( fileName ) + CRLF ;
contentLengthLine = "Content-Length: "
@@ -159,7 +186,6 @@
}
else
{
- System.out.println("hittade inte fil");
statusLine = "HTTP/1.0 404 Not Found" + CRLF ;
contentTypeLine = "Content-Type: text/html" + CRLF ;
entityBody = "<HTML>"
@@ -188,6 +214,8 @@
{
sendBytes(fis, output) ;
fis.close();
+ _httpServer.removeFile(requestedFile);
+ _httpServer.printDoneMsg();
}
else
{
Modified: trunk/src/XMPPLinkLocalChatSession.java
===================================================================
--- trunk/src/XMPPLinkLocalChatSession.java 2007-12-05 07:25:07 UTC (rev 76)
+++ trunk/src/XMPPLinkLocalChatSession.java 2007-12-13 11:30:42 UTC (rev 77)
@@ -52,16 +52,24 @@
public void offerFileTransfer(String localFileNameAndPath)
{
- File filen = new File(localFileNameAndPath);
- _httpServer.addFile(filen);
- long sizeOfFile = filen.length();
- String filnamn = filen.getName();
- String fileTransferStanza = "<message to=\""+_chatPartner.getServiceName()+"\" from=\""+ZeroconfRegistration.getMyServiceName()+"\"><body></body>";
- fileTransferStanza += "<x xmlns=\"jabber:x:oob\">";
- fileTransferStanza += "<url type=\"file\" size=\""+String.valueOf(sizeOfFile)+"\">";
- fileTransferStanza += "http://10.100.46.243:5297/25E8656B83FBA3A2/"+filnamn+"</url></x></message>";
- _toRemoteHost.print(fileTransferStanza);
- _toRemoteHost.flush();
+ try
+ {
+ File filen = new File(localFileNameAndPath);
+ _httpServer.addFile(filen);
+ long sizeOfFile = filen.length();
+ String filnamn = filen.getName();
+ String fileTransferStanza = "<message to=\""+_chatPartner.getServiceName()+"\" from=\""+ZeroconfRegistration.getMyServiceName()+"\"><body></body>";
+ fileTransferStanza += "<x xmlns=\"jabber:x:oob\">";
+ fileTransferStanza += "<url type=\"file\" size=\""+String.valueOf(sizeOfFile)+"\">";
+ fileTransferStanza += "http://"+InetAddress.getLocalHost().getHostAddress()+":"+_httpServer.getPort()+"/"+filnamn+"</url></x></message>";
+ System.out.println(fileTransferStanza);
+ _toRemoteHost.print(fileTransferStanza);
+ _toRemoteHost.flush();
+ }
+ catch (Exception e)
+ {
+ System.out.println(e);
+ }
}
public XMPPLinkLocalChatSession(XMPPLinkLocalHost hostToChatWith)
@@ -147,10 +155,6 @@
ZeroFile.downloadFileFromHTTP(XMPPDOMParser.getUrlFromFileTransferStanza(stanza));
_chatWindow.printText("Downloaded file from chat partner");
}
- else
- {
- // Skicka "jag vill inte ha din j\x8Avla fil-meddelande"
- }
}
}
}
@@ -191,6 +195,11 @@
}
}
+ public void printTextToChatWindow(String txt)
+ {
+ _chatWindow.printText(txt);
+ }
+
public void sendMessage(String m)
{
String messageStanza = "<message to=\""+_chatPartner.getServiceName()+"\" from=\""+ZeroconfRegistration.getMyServiceName()+"\"><body>"+m+"</body></message>";
Modified: trunk/src/ZeroFile.java
===================================================================
--- trunk/src/ZeroFile.java 2007-12-05 07:25:07 UTC (rev 76)
+++ trunk/src/ZeroFile.java 2007-12-13 11:30:42 UTC (rev 77)
@@ -7,6 +7,7 @@
* @throws IOException
*/
public static void main(String[] args) throws IOException {
+ System.out.println(InetAddress.getLocalHost().getHostAddress());
System.out.println(
new java.io.OutputStreamWriter(
new java.io.ByteArrayOutputStream()).getEncoding()
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <kar...@us...> - 2007-12-13 13:42:16
|
Revision: 78
http://zerofile.svn.sourceforge.net/zerofile/?rev=78&view=rev
Author: karl-bengtsson
Date: 2007-12-13 05:42:14 -0800 (Thu, 13 Dec 2007)
Log Message:
-----------
maybe support for swedish characters
Modified Paths:
--------------
trunk/src/XMPPLinkLocalChatSession.java
trunk/src/ZeroFile.java
Modified: trunk/src/XMPPLinkLocalChatSession.java
===================================================================
--- trunk/src/XMPPLinkLocalChatSession.java 2007-12-13 11:30:42 UTC (rev 77)
+++ trunk/src/XMPPLinkLocalChatSession.java 2007-12-13 13:42:14 UTC (rev 78)
@@ -1,5 +1,8 @@
import java.io.*;
import java.net.*;
+import java.nio.*;
+import java.nio.charset.*;
+
import javax.swing.*;
/*
@@ -15,6 +18,8 @@
private PrintWriter _toRemoteHost;
private ZeroFileChatWindow _chatWindow;
private XMPPLinkLocalHost _chatPartner;
+ private Charset charset = Charset.forName("UTF-8");
+ private CharsetEncoder encoder = charset.newEncoder();
private HttpServer _httpServer = new HttpServer(this);
private Thread _remoteHostReadingThread = new Thread() {
@@ -62,8 +67,8 @@
fileTransferStanza += "<x xmlns=\"jabber:x:oob\">";
fileTransferStanza += "<url type=\"file\" size=\""+String.valueOf(sizeOfFile)+"\">";
fileTransferStanza += "http://"+InetAddress.getLocalHost().getHostAddress()+":"+_httpServer.getPort()+"/"+filnamn+"</url></x></message>";
- System.out.println(fileTransferStanza);
- _toRemoteHost.print(fileTransferStanza);
+ ByteBuffer bbuf = encoder.encode(CharBuffer.wrap(fileTransferStanza));
+ _toRemoteHost.print(bbuf);
_toRemoteHost.flush();
}
catch (Exception e)
@@ -80,7 +85,7 @@
{
_s = new Socket(hostToChatWith.getHost(),hostToChatWith.getPort());
_toRemoteHost = new PrintWriter(_s.getOutputStream());
- _fromRemoteHost = new InputStreamReader(_s.getInputStream());
+ _fromRemoteHost = new InputStreamReader(_s.getInputStream(),"UTF-8");
_remoteHostReadingThread.start();
sendHandshake();
}
@@ -202,9 +207,17 @@
public void sendMessage(String m)
{
- String messageStanza = "<message to=\""+_chatPartner.getServiceName()+"\" from=\""+ZeroconfRegistration.getMyServiceName()+"\"><body>"+m+"</body></message>";
- _toRemoteHost.print(messageStanza);
- _toRemoteHost.flush();
+ try
+ {
+ String messageStanza = "<message to=\""+_chatPartner.getServiceName()+"\" from=\""+ZeroconfRegistration.getMyServiceName()+"\"><body>"+m+"</body></message>";
+ ByteBuffer bbuf = encoder.encode(CharBuffer.wrap(messageStanza));
+ _toRemoteHost.print(bbuf);
+ _toRemoteHost.flush();
+ }
+ catch (Exception e)
+ {
+ System.out.println(e);
+ }
}
public void disconnect()
Modified: trunk/src/ZeroFile.java
===================================================================
--- trunk/src/ZeroFile.java 2007-12-13 11:30:42 UTC (rev 77)
+++ trunk/src/ZeroFile.java 2007-12-13 13:42:14 UTC (rev 78)
@@ -7,7 +7,6 @@
* @throws IOException
*/
public static void main(String[] args) throws IOException {
- System.out.println(InetAddress.getLocalHost().getHostAddress());
System.out.println(
new java.io.OutputStreamWriter(
new java.io.ByteArrayOutputStream()).getEncoding()
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <kar...@us...> - 2007-12-13 14:10:18
|
Revision: 82
http://zerofile.svn.sourceforge.net/zerofile/?rev=82&view=rev
Author: karl-bengtsson
Date: 2007-12-13 06:10:21 -0800 (Thu, 13 Dec 2007)
Log Message:
-----------
uppsnyggad fildelning
Modified Paths:
--------------
trunk/src/HttpServer.java
trunk/src/XMPPDOMParser.java
trunk/src/XMPPLinkLocalChatSession.java
trunk/src/ZeroFileChatWindow.java
Modified: trunk/src/HttpServer.java
===================================================================
--- trunk/src/HttpServer.java 2007-12-13 13:57:51 UTC (rev 81)
+++ trunk/src/HttpServer.java 2007-12-13 14:10:21 UTC (rev 82)
@@ -75,6 +75,8 @@
public void removeFile(File filen)
{
_files.remove(filen);
+ if (_files.size() == 0)
+ stop();
}
public int getPort()
{
@@ -107,9 +109,9 @@
}
return null;
}
- public void printDoneMsg()
+ public void printDoneMsg(String fileName)
{
- _session.printTextToChatWindow("File transferred successfully!");
+ _session.printTextToChatWindow("File \"" + fileName + "\" transferred successfully!");
}
}
@@ -215,7 +217,7 @@
sendBytes(fis, output) ;
fis.close();
_httpServer.removeFile(requestedFile);
- _httpServer.printDoneMsg();
+ _httpServer.printDoneMsg(requestedFile.getName());
}
else
{
Modified: trunk/src/XMPPDOMParser.java
===================================================================
--- trunk/src/XMPPDOMParser.java 2007-12-13 13:57:51 UTC (rev 81)
+++ trunk/src/XMPPDOMParser.java 2007-12-13 14:10:21 UTC (rev 82)
@@ -69,7 +69,6 @@
DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
Document d = factory.newDocumentBuilder().parse(new InputSource(new StringReader(stanza)));
return d.getElementsByTagName("url").item(0).getTextContent();
- //return d.getAttributes().getNamedItem("from").toString();
}
catch (Exception e)
{
Modified: trunk/src/XMPPLinkLocalChatSession.java
===================================================================
--- trunk/src/XMPPLinkLocalChatSession.java 2007-12-13 13:57:51 UTC (rev 81)
+++ trunk/src/XMPPLinkLocalChatSession.java 2007-12-13 14:10:21 UTC (rev 82)
@@ -1,7 +1,5 @@
import java.io.*;
import java.net.*;
-import java.nio.*;
-import java.nio.charset.*;
import javax.swing.*;
@@ -18,8 +16,6 @@
private PrintWriter _toRemoteHost;
private ZeroFileChatWindow _chatWindow;
private XMPPLinkLocalHost _chatPartner;
- private Charset charset = Charset.forName("UTF-8");
- private CharsetEncoder encoder = charset.newEncoder();
private HttpServer _httpServer = new HttpServer(this);
private Thread _remoteHostReadingThread = new Thread() {
@@ -101,7 +97,6 @@
private void RecievedStanza(String stanza)
{
- System.out.println(stanza);
if (stanza.contains("<?xml"))
// Stanza is a handshake
{
@@ -148,17 +143,19 @@
{
if (stanza.contains("<x xmlns=\"jabber:x:oob\">"))
{
+ String urlToFile = XMPPDOMParser.getUrlFromFileTransferStanza(stanza);
+ String fileName = urlToFile.substring(urlToFile.lastIndexOf("/")+1);
if (ZeroFileSettings.getCheckBox().equals("true"))
{
ZeroFile.downloadFileFromHTTP(XMPPDOMParser.getUrlFromFileTransferStanza(stanza));
- _chatWindow.printText("Downloaded file from chat partner");
+ _chatWindow.printText("Downloaded file \""+ fileName + "\" from chat partner");
}
else
{
- if (JOptionPane.showConfirmDialog(null, "Ta emot?", "Ta emot fil?", JOptionPane.YES_NO_OPTION) == 0)
+ if (JOptionPane.showConfirmDialog(null, "Ta emot?", _chatPartner.toString() + "is sending you the file \""+fileName+"\". Do you wish to accept this file transfer?", JOptionPane.YES_NO_OPTION) == 0)
{
ZeroFile.downloadFileFromHTTP(XMPPDOMParser.getUrlFromFileTransferStanza(stanza));
- _chatWindow.printText("Downloaded file from chat partner");
+ _chatWindow.printText("Downloaded file \""+ fileName + "\" from chat partner");
}
}
}
Modified: trunk/src/ZeroFileChatWindow.java
===================================================================
--- trunk/src/ZeroFileChatWindow.java 2007-12-13 13:57:51 UTC (rev 81)
+++ trunk/src/ZeroFileChatWindow.java 2007-12-13 14:10:21 UTC (rev 82)
@@ -1,5 +1,6 @@
import java.awt.*;
import java.awt.event.*;
+import java.io.File;
import javax.swing.*;
@@ -81,7 +82,9 @@
JFileChooser _fileChooser= new JFileChooser();
_fileChooser.setFileSelectionMode(JFileChooser.FILES_ONLY);
_fileChooser.showOpenDialog(null);
- _session.offerFileTransfer(_fileChooser.getSelectedFile().toString());
+ File offeredFile = _fileChooser.getSelectedFile();
+ _session.offerFileTransfer(offeredFile.toString());
+ printText("Offered file \"" + offeredFile.getName() + "\" to chat partner");
}
}
);
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <kar...@us...> - 2007-12-13 14:17:57
|
Revision: 83
http://zerofile.svn.sourceforge.net/zerofile/?rev=83&view=rev
Author: karl-bengtsson
Date: 2007-12-13 06:17:44 -0800 (Thu, 13 Dec 2007)
Log Message:
-----------
fancy chatwindow autoscroll
Modified Paths:
--------------
trunk/src/XMPPLinkLocalChatSession.java
trunk/src/ZeroFileChatWindow.java
Modified: trunk/src/XMPPLinkLocalChatSession.java
===================================================================
--- trunk/src/XMPPLinkLocalChatSession.java 2007-12-13 14:10:21 UTC (rev 82)
+++ trunk/src/XMPPLinkLocalChatSession.java 2007-12-13 14:17:44 UTC (rev 83)
@@ -152,7 +152,7 @@
}
else
{
- if (JOptionPane.showConfirmDialog(null, "Ta emot?", _chatPartner.toString() + "is sending you the file \""+fileName+"\". Do you wish to accept this file transfer?", JOptionPane.YES_NO_OPTION) == 0)
+ if (JOptionPane.showConfirmDialog(null, _chatPartner.toString() + "is sending you the file \""+fileName+"\". Do you wish to accept this file transfer?","Ta emot?", JOptionPane.YES_NO_OPTION) == 0)
{
ZeroFile.downloadFileFromHTTP(XMPPDOMParser.getUrlFromFileTransferStanza(stanza));
_chatWindow.printText("Downloaded file \""+ fileName + "\" from chat partner");
Modified: trunk/src/ZeroFileChatWindow.java
===================================================================
--- trunk/src/ZeroFileChatWindow.java 2007-12-13 14:10:21 UTC (rev 82)
+++ trunk/src/ZeroFileChatWindow.java 2007-12-13 14:17:44 UTC (rev 83)
@@ -32,6 +32,7 @@
public void printText(String s)
{
_chatTextArea.append(s+"\n");
+ _chatTextArea.setCaretPosition(_chatTextArea.getDocument().getLength());
}
public void sendMessage(String str)
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <kar...@us...> - 2007-12-13 14:47:21
|
Revision: 84
http://zerofile.svn.sourceforge.net/zerofile/?rev=84&view=rev
Author: karl-bengtsson
Date: 2007-12-13 06:47:19 -0800 (Thu, 13 Dec 2007)
Log Message:
-----------
bugfix for problems with sending files containing whitespace in file names
Modified Paths:
--------------
trunk/src/HttpServer.java
trunk/src/XMPPLinkLocalChatSession.java
trunk/src/ZeroFile.java
Modified: trunk/src/HttpServer.java
===================================================================
--- trunk/src/HttpServer.java 2007-12-13 14:17:44 UTC (rev 83)
+++ trunk/src/HttpServer.java 2007-12-13 14:47:19 UTC (rev 84)
@@ -160,7 +160,7 @@
if(temp.equals("GET"))
{
String fileName = s.nextToken();
- fileName = fileName.replaceFirst("/","");
+ fileName = fileName.replaceFirst("/","").replace("%20"," ");
FileInputStream fis = null ;
boolean fileExists = false;
Modified: trunk/src/XMPPLinkLocalChatSession.java
===================================================================
--- trunk/src/XMPPLinkLocalChatSession.java 2007-12-13 14:17:44 UTC (rev 83)
+++ trunk/src/XMPPLinkLocalChatSession.java 2007-12-13 14:47:19 UTC (rev 84)
@@ -62,7 +62,7 @@
String fileTransferStanza = "<message to=\""+_chatPartner.getServiceName()+"\" from=\""+ZeroconfRegistration.getMyServiceName()+"\"><body></body>";
fileTransferStanza += "<x xmlns=\"jabber:x:oob\">";
fileTransferStanza += "<url type=\"file\" size=\""+String.valueOf(sizeOfFile)+"\">";
- fileTransferStanza += "http://"+InetAddress.getLocalHost().getHostAddress()+":"+_httpServer.getPort()+"/"+filnamn+"</url></x></message>";
+ fileTransferStanza += "http://"+InetAddress.getLocalHost().getHostAddress()+":"+_httpServer.getPort()+"/"+filnamn.replace(" ", "%20")+"</url></x></message>";
_toRemoteHost.print(fileTransferStanza);
_toRemoteHost.flush();
}
@@ -144,7 +144,7 @@
if (stanza.contains("<x xmlns=\"jabber:x:oob\">"))
{
String urlToFile = XMPPDOMParser.getUrlFromFileTransferStanza(stanza);
- String fileName = urlToFile.substring(urlToFile.lastIndexOf("/")+1);
+ String fileName = urlToFile.substring(urlToFile.lastIndexOf("/")+1).replace("%20"," ");
if (ZeroFileSettings.getCheckBox().equals("true"))
{
ZeroFile.downloadFileFromHTTP(XMPPDOMParser.getUrlFromFileTransferStanza(stanza));
Modified: trunk/src/ZeroFile.java
===================================================================
--- trunk/src/ZeroFile.java 2007-12-13 14:17:44 UTC (rev 83)
+++ trunk/src/ZeroFile.java 2007-12-13 14:47:19 UTC (rev 84)
@@ -62,9 +62,9 @@
{
String localFileName;
if (!ZeroFileSettings.getDownloadFolder().equals(""))
- localFileName = ZeroFileSettings.getDownloadFolder() +"/"+ address.substring(lastSlashIndex + 1);
+ localFileName = ZeroFileSettings.getDownloadFolder() +"/"+ address.substring(lastSlashIndex + 1).replace("%20"," ");
else
- localFileName = System.getProperty("user.home") +"/"+ address.substring(lastSlashIndex + 1);
+ localFileName = System.getProperty("user.home") +"/"+ address.substring(lastSlashIndex + 1).replace("%20"," ");
URL url = new URL(address);
out = new BufferedOutputStream(
new FileOutputStream(localFileName));
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|