Author: jflesch
Date: 2007-07-25 15:48:12 +0000 (Wed, 25 Jul 2007)
New Revision: 14334

Added:
   trunk/apps/Thaw/images/mail-attachment.png
   trunk/apps/Thaw/images/min-mail-attachment.png
   trunk/apps/Thaw/src/thaw/plugins/miniFrost/frostKSK/KSKAttachment.java
   trunk/apps/Thaw/src/thaw/plugins/miniFrost/frostKSK/KSKAttachmentFactory.java
   trunk/apps/Thaw/src/thaw/plugins/miniFrost/frostKSK/KSKBoardAttachment.java
   trunk/apps/Thaw/src/thaw/plugins/miniFrost/frostKSK/KSKFileAttachment.java
   trunk/apps/Thaw/src/thaw/plugins/miniFrost/interfaces/Attachment.java
Modified:
   trunk/apps/Thaw/src/thaw/fcp/FCPClientGet.java
   trunk/apps/Thaw/src/thaw/gui/IconBox.java
   trunk/apps/Thaw/src/thaw/i18n/source.thaw_fr.properties
   trunk/apps/Thaw/src/thaw/i18n/thaw.properties
   trunk/apps/Thaw/src/thaw/plugins/miniFrost/MessagePanel.java
   trunk/apps/Thaw/src/thaw/plugins/miniFrost/MiniFrostPanel.java
   trunk/apps/Thaw/src/thaw/plugins/miniFrost/frostKSK/KSKBoard.java
   trunk/apps/Thaw/src/thaw/plugins/miniFrost/frostKSK/KSKBoardFactory.java
   trunk/apps/Thaw/src/thaw/plugins/miniFrost/frostKSK/KSKMessage.java
   trunk/apps/Thaw/src/thaw/plugins/miniFrost/frostKSK/KSKMessageParser.java
   trunk/apps/Thaw/src/thaw/plugins/miniFrost/interfaces/Message.java
Log:
Add support for the attachments in the messages

Added: trunk/apps/Thaw/images/mail-attachment.png
===================================================================
(Binary files differ)


Property changes on: trunk/apps/Thaw/images/mail-attachment.png
___________________________________________________________________
Name: svn:mime-type
   + application/octet-stream

Added: trunk/apps/Thaw/images/min-mail-attachment.png
===================================================================
(Binary files differ)


Property changes on: trunk/apps/Thaw/images/min-mail-attachment.png
___________________________________________________________________
Name: svn:mime-type
   + application/octet-stream

Modified: trunk/apps/Thaw/src/thaw/fcp/FCPClientGet.java
===================================================================
--- trunk/apps/Thaw/src/thaw/fcp/FCPClientGet.java      2007-07-25 15:14:22 UTC 
(rev 14333)
+++ trunk/apps/Thaw/src/thaw/fcp/FCPClientGet.java      2007-07-25 15:48:12 UTC 
(rev 14334)
@@ -13,7 +13,7 @@
        implements Observer, FCPTransferQuery {

        public final static int DEFAULT_PRIORITY = 4;
-
+       public final static int DEFAULT_MAX_RETRIES = -1;
        public final static int PERSISTENCE_FOREVER           = 0;
        public final static int PERSISTENCE_UNTIL_NODE_REBOOT = 1;
        public final static int PERSISTENCE_UNTIL_DISCONNECT  = 2;
@@ -480,7 +480,7 @@
                                return;
                        }

-                       Logger.warning(this, "==== GET FAILED 
===\n"+message.toString());
+                       Logger.notice(this, "==== GET FAILED 
===\n"+message.toString());


                        if(!isRunning()) { /* Must be a "GetFailed: cancelled 
by caller", so we simply ignore */

Modified: trunk/apps/Thaw/src/thaw/gui/IconBox.java
===================================================================
--- trunk/apps/Thaw/src/thaw/gui/IconBox.java   2007-07-25 15:14:22 UTC (rev 
14333)
+++ trunk/apps/Thaw/src/thaw/gui/IconBox.java   2007-07-25 15:48:12 UTC (rev 
14334)
@@ -159,6 +159,8 @@
        public static ImageIcon minLeft;
        public static ImageIcon minRight;

+       public static ImageIcon attachment;
+       public static ImageIcon minAttachment;

        /**
         * Not really used
@@ -293,6 +295,8 @@
                IconBox.minDown             = 
IconBox.loadIcon("min-go-down.png");
                IconBox.minLeft             = 
IconBox.loadIcon("min-go-previous.png");
                IconBox.minRight            = 
IconBox.loadIcon("min-go-next.png");
+               IconBox.attachment          = 
IconBox.loadIcon("mail-attachment.png");
+               IconBox.minAttachment       = 
IconBox.loadIcon("min-mail-attachment.png");
        }

 }

Modified: trunk/apps/Thaw/src/thaw/i18n/source.thaw_fr.properties
===================================================================
--- trunk/apps/Thaw/src/thaw/i18n/source.thaw_fr.properties     2007-07-25 
15:14:22 UTC (rev 14333)
+++ trunk/apps/Thaw/src/thaw/i18n/source.thaw_fr.properties     2007-07-25 
15:48:12 UTC (rev 14334)
@@ -64,6 +64,7 @@
 thaw.common.removeFromTheList=Annuler et retirer les transferts s?lectionn?s
 thaw.common.cancel=Annuler
 thaw.common.delay=Retarder
+thaw.common.copyKeyToClipboard=Copier la clef dans le presse-papier
 thaw.common.copyKeysToClipboard=Copier les clefs dans le presse-papier
 thaw.common.forceRestart=Forcer le red?marrage du/des transfert(s)
 thaw.common.downloadLocally=T?l?chargement en local
@@ -520,6 +521,7 @@

 thaw.plugin.miniFrost=Forums
 thaw.plugin.miniFrost.boards=Boards
+thaw.plugin.miniFrost.board=Board
 thaw.plugin.miniFrost.FrostKSK=boards Frost non-sign?e
 thaw.plugin.miniFrost.selectType=Veuillez selectionner le type de board voulu
 thaw.plugin.miniFrost.boardName=Nom de la board ?
@@ -555,3 +557,9 @@
 thaw.plugin.miniFrost.seeArchived=Voir les messages archiv?s

 thaw.plugin.miniFrost.maxBoardsRefreshed=Nombre maximum de boards rafraichies 
simultan?ment
+
+thaw.plugin.miniFrost.copyAllKeys=Copier toutes les clefs des fichiers joints 
dans le presse-papier
+
+thaw.plugin.miniFrost.attachments=Pieces jointes
+thaw.plugin.miniFrost.downloadAll=T?l?charger tout les fichiers joints
+

Modified: trunk/apps/Thaw/src/thaw/i18n/thaw.properties
===================================================================
--- trunk/apps/Thaw/src/thaw/i18n/thaw.properties       2007-07-25 15:14:22 UTC 
(rev 14333)
+++ trunk/apps/Thaw/src/thaw/i18n/thaw.properties       2007-07-25 15:48:12 UTC 
(rev 14334)
@@ -65,6 +65,7 @@
 thaw.common.removeFromTheList=Cancel and remove selected transfers
 thaw.common.cancel=Cancel
 thaw.common.delay=Delay
+thaw.common.copyKeyToClipboard=Copy the key to clipboard
 thaw.common.copyKeysToClipboard=Copy keys to clipboard
 thaw.common.forceRestart=Force (re)start
 thaw.common.downloadLocally=Download locally
@@ -535,6 +536,7 @@

 thaw.plugin.miniFrost=Boards
 thaw.plugin.miniFrost.boards=Boards
+thaw.plugin.miniFrost.board=Board
 thaw.plugin.miniFrost.FrostKSK=unsigned Frost boards
 thaw.plugin.miniFrost.selectType=Please select the board type wanted
 thaw.plugin.miniFrost.boardName=Board name ?
@@ -571,3 +573,7 @@
 thaw.plugin.miniFrost.seeArchived=See archived messages
 thaw.plugin.miniFrost.maxBoardsRefreshed=Maximum number of boards being 
refreshed at the same time

+thaw.plugin.miniFrost.copyAllKeys=Copy all the keys of the joined files to 
clipboard
+
+thaw.plugin.miniFrost.attachments=Attachment(s)
+thaw.plugin.miniFrost.downloadAll=Download all the files attached

Modified: trunk/apps/Thaw/src/thaw/plugins/miniFrost/MessagePanel.java
===================================================================
--- trunk/apps/Thaw/src/thaw/plugins/miniFrost/MessagePanel.java        
2007-07-25 15:14:22 UTC (rev 14333)
+++ trunk/apps/Thaw/src/thaw/plugins/miniFrost/MessagePanel.java        
2007-07-25 15:48:12 UTC (rev 14334)
@@ -19,12 +19,17 @@

 import java.awt.event.KeyEvent;

+import javax.swing.JMenu;
+import javax.swing.JMenuItem;
+import javax.swing.JPopupMenu;

+
 import thaw.gui.IconBox;
 import thaw.core.I18n;
 import thaw.core.Logger;
 import thaw.plugins.miniFrost.interfaces.Message;
 import thaw.plugins.miniFrost.interfaces.SubMessage;
+import thaw.plugins.miniFrost.interfaces.Attachment;


 public class MessagePanel
@@ -52,7 +57,9 @@

        private Message msg;
        private Vector subMsgs;
+       private Vector attachments;

+
        private JScrollPane scrollPane;


@@ -119,6 +126,7 @@
        public void setMessage(Message msg) {
                this.msg = msg;
                subMsgs = msg.getSubMessages();
+               attachments = msg.getAttachments();

                refresh();
        }
@@ -217,6 +225,75 @@
        }


+       protected class AttachmentAction extends JMenuItem
+               implements ActionListener {
+
+               private Attachment a;
+               private String action;
+
+               public AttachmentAction(Attachment a, String action) {
+                       super(action);
+
+                       this.a = a;
+                       this.action = action;
+
+                       super.addActionListener(this);
+               }
+
+               public void actionPerformed(ActionEvent e) {
+                       a.apply(mainPanel.getDb(),
+                               
mainPanel.getPluginCore().getCore().getQueueManager(),
+                               action);
+               }
+       }
+
+
+       protected class AttachmentPanel extends JPanel
+               implements ActionListener {
+
+               private JButton button;
+               private Vector attachments;
+
+               public AttachmentPanel(Vector attachments) {
+                       super();
+                       this.attachments = attachments;
+                       button = new JButton(IconBox.attachment);
+                       
button.setToolTipText(I18n.getMessage("thaw.plugin.miniFrost.attachments"));
+                       button.addActionListener(this);
+                       super.add(button);
+               }
+
+               public void actionPerformed(ActionEvent e) {
+                       if (e.getSource() == button) {
+                               JPopupMenu menu = new JPopupMenu();
+
+                               /* make the menu */
+
+                               for(Iterator it = attachments.iterator();
+                                   it.hasNext();) {
+                                       Attachment a = (Attachment)it.next();
+                                       JMenu subMenu = new 
JMenu(a.getPrintableType() + " : "+a.toString());
+
+                                       String[] actions = a.getActions();
+
+                                       for (int i = 0 ; i < actions.length ; 
i++) {
+                                               subMenu.add(new 
AttachmentAction(a, actions[i]));
+                                       }
+
+                                       menu.add(subMenu);
+                               }
+
+
+                               /* and next display it */
+                               menu.show(this,
+                                         this.getWidth()/2,
+                                         this.getHeight()/2);
+                       }
+               }
+       }
+
+
+
        public void refresh() {
                subPanels = new Vector();

@@ -229,6 +306,7 @@

                int i = 0;

+               /* sub messages */
                for (Iterator it = subMsgs.iterator();
                     it.hasNext();) {
                        SubMessage subMsg = (SubMessage)it.next();
@@ -249,6 +327,22 @@
                        i++;
                }

+
+               /* attachments */
+               if (attachments != null) {
+                       AttachmentPanel panel = new 
AttachmentPanel(attachments);
+
+                       if (iPanel == null) {
+                               iPanel = panel;
+                       } else {
+                               JPanel newPanel = new JPanel(new 
BorderLayout(0, 20));
+                               newPanel.add(iPanel, BorderLayout.NORTH);
+                               newPanel.add(panel, BorderLayout.CENTER);
+                               iPanel = newPanel;
+                       }
+               }
+
+
                if (insidePanel != null) {
                        msgsPanel.remove(insidePanel);
                        msgsPanel.revalidate();

Modified: trunk/apps/Thaw/src/thaw/plugins/miniFrost/MiniFrostPanel.java
===================================================================
--- trunk/apps/Thaw/src/thaw/plugins/miniFrost/MiniFrostPanel.java      
2007-07-25 15:14:22 UTC (rev 14333)
+++ trunk/apps/Thaw/src/thaw/plugins/miniFrost/MiniFrostPanel.java      
2007-07-25 15:48:12 UTC (rev 14334)
@@ -80,7 +80,17 @@
                loadState();
        }

+       /**
+        * notify major changes : board added / removed
+        */
+       public void notifyChange() {
+               boardTree.refresh();
+       }

+       /**
+        * notify a change on this board. usually
+        * that a new non-read message has been added
+        */
        public void notifyChange(Board board) {
                boardTree.refresh(board);


Added: trunk/apps/Thaw/src/thaw/plugins/miniFrost/frostKSK/KSKAttachment.java
===================================================================
--- trunk/apps/Thaw/src/thaw/plugins/miniFrost/frostKSK/KSKAttachment.java      
                        (rev 0)
+++ trunk/apps/Thaw/src/thaw/plugins/miniFrost/frostKSK/KSKAttachment.java      
2007-07-25 15:48:12 UTC (rev 14334)
@@ -0,0 +1,12 @@
+package thaw.plugins.miniFrost.frostKSK;
+
+import java.util.Vector;
+
+import thaw.plugins.Hsqldb;
+
+
+public interface KSKAttachment
+       extends thaw.plugins.miniFrost.interfaces.Attachment {
+
+       public void   insert(Hsqldb db, int messageId);
+}

Added: 
trunk/apps/Thaw/src/thaw/plugins/miniFrost/frostKSK/KSKAttachmentFactory.java
===================================================================
--- 
trunk/apps/Thaw/src/thaw/plugins/miniFrost/frostKSK/KSKAttachmentFactory.java   
                            (rev 0)
+++ 
trunk/apps/Thaw/src/thaw/plugins/miniFrost/frostKSK/KSKAttachmentFactory.java   
    2007-07-25 15:48:12 UTC (rev 14334)
@@ -0,0 +1,94 @@
+package thaw.plugins.miniFrost.frostKSK;
+
+import java.sql.*;
+
+import org.w3c.dom.Element;
+import org.xml.sax.SAXException;
+
+import java.util.Vector;
+
+import frost.util.XMLTools;
+
+import thaw.plugins.Hsqldb;
+import thaw.plugins.miniFrost.interfaces.Attachment;
+import thaw.core.Logger;
+
+
+public class KSKAttachmentFactory {
+
+       /**
+        * one per message (not really used atm, but we never know)
+        */
+       public KSKAttachmentFactory() {
+
+       }
+
+
+       public static Vector getAttachments(KSKMessage msg,
+                                           KSKBoardFactory boardFactory,
+                                           Hsqldb db) {
+               Vector v = new Vector();
+
+               Vector sub;
+
+               if ((sub = KSKFileAttachment.select( msg, boardFactory,  db)) 
!= null)
+                       v.addAll(sub);
+               if ((sub = KSKBoardAttachment.select(msg, boardFactory,  db)) 
!= null)
+                       v.addAll(sub);
+
+               return (v.size() > 0 ? v : null);
+       }
+
+
+       public KSKAttachment getAttachment(Element attachmentEl) {
+               if (attachmentEl.getAttribute("type").length() <= 0) {
+                       Logger.warning(this, "No type specified in the 
attachment ("+
+                                      attachmentEl.toString()+")");
+                       return null;
+               }
+
+               KSKAttachment a = null;
+
+               if (attachmentEl.getAttribute("type").equals("file"))
+                       a = new KSKFileAttachment();
+               else if (attachmentEl.getAttribute("type").equals("board"))
+                       a = new KSKBoardAttachment();
+
+               if (a == null) {
+                       Logger.warning(this, "Unknown attachment type : "
+                                      +attachmentEl.getAttribute("type"));
+               }
+               else
+                       loadValues(a, attachmentEl);
+
+               return a;
+       }
+
+
+
+       public void loadValues(KSKAttachment a, Element rootEl) {
+               if (a.getContainer() != null)
+                       rootEl = 
(Element)XMLTools.getChildElementsByTagName(rootEl, 
a.getContainer()).iterator().next();
+
+               if (rootEl == null) {
+                       Logger.warning(this, "no container ?!");
+                       return;
+               }
+
+               String[] properties = a.getProperties();
+
+               for (int i = 0 ; i < properties.length ; i++) {
+                       String val;
+
+                       try {
+                               val = 
XMLTools.getChildElementsCDATAValue(rootEl, properties[i]);
+                       } catch(java.lang.ClassCastException e) {
+                               /* FROST XML SUCKS. IT SUCKS IT SUCKS IT SUCKS 
IT SUCKS. */
+                               val = 
XMLTools.getChildElementsTextValue(rootEl, properties[i]);
+                       }
+
+                       if (val != null)
+                               a.setValue(properties[i], val);
+               }
+       }
+}

Modified: trunk/apps/Thaw/src/thaw/plugins/miniFrost/frostKSK/KSKBoard.java
===================================================================
--- trunk/apps/Thaw/src/thaw/plugins/miniFrost/frostKSK/KSKBoard.java   
2007-07-25 15:14:22 UTC (rev 14333)
+++ trunk/apps/Thaw/src/thaw/plugins/miniFrost/frostKSK/KSKBoard.java   
2007-07-25 15:48:12 UTC (rev 14334)
@@ -357,7 +357,8 @@
                                && msg.isSuccessful();

                        if (successful) {
-                               newMsgs++;
+                               if (msg.isParsable())
+                                       newMsgs++;

                                notifyChange();
                                lastSuccessfulRev = msg.getRev();

Added: 
trunk/apps/Thaw/src/thaw/plugins/miniFrost/frostKSK/KSKBoardAttachment.java
===================================================================
--- trunk/apps/Thaw/src/thaw/plugins/miniFrost/frostKSK/KSKBoardAttachment.java 
                        (rev 0)
+++ trunk/apps/Thaw/src/thaw/plugins/miniFrost/frostKSK/KSKBoardAttachment.java 
2007-07-25 15:48:12 UTC (rev 14334)
@@ -0,0 +1,234 @@
+package thaw.plugins.miniFrost.frostKSK;
+
+import java.sql.*;
+
+import java.util.Vector;
+
+import thaw.core.I18n;
+import thaw.plugins.Hsqldb;
+import thaw.core.Logger;
+import thaw.fcp.FCPQueueManager;
+
+
+public class KSKBoardAttachment
+       implements KSKAttachment {
+
+       private String boardName;
+       private String publicKey;
+       private String privateKey;
+       private String description;
+
+       private KSKMessage msg;
+       private KSKBoardFactory boardFactory;
+
+
+       public KSKBoardAttachment() {
+
+       }
+
+       public KSKBoardAttachment(String boardName,
+                                 String publicKey,
+                                 String privateKey,
+                                 String description) {
+               this.boardName = boardName;
+               this.publicKey = publicKey;
+               this.privateKey = privateKey;
+               this.description = description;
+
+               if (this.description == null)
+                       this.description = "";
+       }
+
+
+       public KSKBoardAttachment(String boardName,
+                                 String publicKey,
+                                 String privateKey,
+                                 String description,
+                                 KSKMessage msg,
+                                 KSKBoardFactory boardFactory) {
+               this(boardName, publicKey, privateKey, description);
+               this.msg = msg;
+               this.boardFactory = boardFactory;
+       }
+
+
+       public String getType() {
+               return "board";
+       }
+
+       public String getPrintableType() {
+               return I18n.getMessage("thaw.plugin.miniFrost.board");
+       }
+
+       public String[] getProperties() {
+               /* DIRTY :p */
+               if (publicKey == null) {
+                       return new String[] {
+                               "Name",
+                               "description",
+                       };
+               } else if (privateKey == null) {
+                       return new String[] {
+                               "Name",
+                               "pubKey",
+                               "description"
+                       };
+               } else {
+                       return new String[] {
+                               "Name",
+                               "pubKey",
+                               "privKey",
+                               "description"
+                       };
+               }
+       }
+
+
+       public String[] getValues() {
+               /* DIRTY :p */
+               if (publicKey == null) {
+                       return new String[] {
+                               boardName,
+                               description,
+                       };
+               } else if (privateKey == null) {
+                       return new String[] {
+                               boardName,
+                               publicKey,
+                               description
+                       };
+               } else {
+                       return new String[] {
+                               boardName,
+                               publicKey,
+                               privateKey,
+                               description
+                       };
+               }
+       }
+
+       public String getValue(String property) {
+               if ("Name".equals(property)) {
+                       return boardName;
+               } else if ("pubKey".equals(property)) {
+                       return publicKey;
+               } else if ("privKey".equals(property)) {
+                       return privateKey;
+               } else if ("description".equals(property)) {
+                       return description;
+               }
+
+               return null;
+       }
+
+       public void setValue(String property, String value) {
+               if ("Name".equals(property)) {
+                       boardName = value;
+               } else if ("pubKey".equals(property)) {
+                       publicKey = value;
+               } else if ("privKey".equals(property)) {
+                       privateKey = value;
+               } else if ("description".equals(property)) {
+                       description = value;
+               } else {
+                       Logger.error(this, "Unknown field : "+property);
+               }
+       }
+
+       public String getContainer() {
+               return null;
+       }
+
+       public String toString() {
+               if (publicKey == null)
+                       return boardName;
+               else if (privateKey == null)
+                       return boardName + " (R)";
+               else
+                       return boardName + " (R/W)";
+       }
+
+       public String[] getActions() {
+               return new String[] {
+                       I18n.getMessage("thaw.common.add")
+               };
+       }
+
+
+       public void apply(Hsqldb db, FCPQueueManager queueManager, String 
action) {
+               if (action.equals(I18n.getMessage("thaw.common.add"))) {
+                       if (publicKey != null) {
+                               /* TODO */
+                               Logger.error(this, "Signed board not supported 
atm");
+                               return;
+                       }
+                       boardFactory.createBoard(boardName);
+                       boardFactory.getPlugin().getPanel().notifyChange();
+               }
+       }
+
+
+       public void insert(Hsqldb db, int messageId) {
+               if (boardName == null) {
+                       Logger.warning(this, "Missing field");
+                       return;
+               }
+
+               if (description == null) {
+                       Logger.notice(this, "no description");
+               }
+
+               try {
+                       synchronized(db.dbLock) {
+                               PreparedStatement st;
+
+                               st = 
db.getConnection().prepareStatement("INSERT INTO frostKSKAttachmentBoards "
+                                                                        
+"(name, publicKey, privateKey, description, messageId) "
+                                                                        
+"VALUES (?, ?, ?, ?, ?)");
+                               st.setString(1, boardName);
+                               st.setString(2, publicKey);
+                               st.setString(3, privateKey);
+                               st.setString(4, description);
+                               st.setInt(5, messageId);
+
+                               st.execute();
+                       }
+               } catch(SQLException e) {
+                       Logger.error(this, "Can't insert the file attachment 
because : "+e.toString());
+               }
+       }
+
+
+       public static Vector select(KSKMessage msg, KSKBoardFactory 
boardFactory,
+                                   Hsqldb db) {
+
+               Vector v = new Vector();
+
+               try {
+                       synchronized(db.dbLock) {
+                               PreparedStatement st;
+
+                               st = 
db.getConnection().prepareStatement("SELECT name, publicKey, "+
+                                                                        
"privateKey, description "+
+                                                                        "FROM 
frostKSKAttachmentBoards "+
+                                                                        "WHERE 
messageId = ?");
+                               st.setInt(1, msg.getId());
+
+                               ResultSet set = st.executeQuery();
+
+                               while(set.next()) {
+                                       v.add(new 
KSKBoardAttachment(set.getString("name"),
+                                                                    
set.getString("publicKey"),
+                                                                    
set.getString("privateKey"),
+                                                                    
set.getString("description"),
+                                                                    msg,
+                                                                    
boardFactory));
+                               }
+                       }
+               } catch(SQLException e) {
+                       Logger.error(e, "Can't select file attachments because: 
"+e.toString());
+               }
+
+               return (v.size() > 0 ? v : null);
+       }
+}

Modified: 
trunk/apps/Thaw/src/thaw/plugins/miniFrost/frostKSK/KSKBoardFactory.java
===================================================================
--- trunk/apps/Thaw/src/thaw/plugins/miniFrost/frostKSK/KSKBoardFactory.java    
2007-07-25 15:14:22 UTC (rev 14333)
+++ trunk/apps/Thaw/src/thaw/plugins/miniFrost/frostKSK/KSKBoardFactory.java    
2007-07-25 15:48:12 UTC (rev 14334)
@@ -20,6 +20,9 @@
 public class KSKBoardFactory
        implements thaw.plugins.miniFrost.interfaces.BoardFactory {

+       /* must correspond at the position in the array of boardfactory in 
miniFrost */
+       public final static int BOARD_FACTORY_ID = 0;
+
        public final static String[] DEFAULT_BOARDS = new String[] {
                "freenet",
                "thaw",
@@ -121,6 +124,23 @@
                          + "FOREIGN KEY (boardId) REFERENCES frostKSKBoards 
(id), "
                          + "FOREIGN KEY (inReplyTo) REFERENCES 
frostKSKMessages (id), "
                          + "FOREIGN KEY (sigId) REFERENCES signatures (id))");
+
+               sendQuery("CREATE CACHED TABLE frostKSKAttachmentFiles ("
+                         + "id INTEGER IDENTITY NOT NULL, "
+                         + "filename VARCHAR(256) NOT NULL, "
+                         + "size BIGINT NOT NULL, "
+                         + "key VARCHAR(512) NOT NULL, "
+                         + "messageId INTEGER NOT NULL, "
+                         + "FOREIGN KEY (messageId) REFERENCES 
frostKSKMessages (id))");
+
+               sendQuery("CREATE CACHED TABLE frostKSKAttachmentBoards ("
+                         + "id INTEGER IDENTITY NOT NULL, "
+                         + "name VARCHAR(128) NOT NULL, "
+                         + "publicKey VARCHAR(256) NULL, "
+                         + "privateKey VARCHAR(256) NULL, "
+                         + "description VARCHAR(512) NULL, "
+                         + "messageId INTEGER NOT NULL, "
+                         + "FOREIGN KEY (messageId) REFERENCES 
frostKSKMessages (id))");
        }



Added: 
trunk/apps/Thaw/src/thaw/plugins/miniFrost/frostKSK/KSKFileAttachment.java
===================================================================
--- trunk/apps/Thaw/src/thaw/plugins/miniFrost/frostKSK/KSKFileAttachment.java  
                        (rev 0)
+++ trunk/apps/Thaw/src/thaw/plugins/miniFrost/frostKSK/KSKFileAttachment.java  
2007-07-25 15:48:12 UTC (rev 14334)
@@ -0,0 +1,259 @@
+package thaw.plugins.miniFrost.frostKSK;
+
+import java.sql.*;
+
+import java.util.Vector;
+import java.util.Iterator;
+
+import thaw.core.I18n;
+import thaw.core.Config;
+import thaw.plugins.Hsqldb;
+import thaw.core.Logger;
+import thaw.gui.FileChooser;
+import thaw.fcp.*;
+
+
+public class KSKFileAttachment
+       implements KSKAttachment, Runnable {
+
+       private String filename;
+       private long size;
+       private String key;
+
+       private FCPQueueManager queueManager;
+       private KSKMessage msg;
+
+       public KSKFileAttachment() {
+
+       }
+
+       public KSKFileAttachment(String filename,
+                                long size,
+                                String key) {
+               this.filename = filename;
+               this.size = size;
+               this.key = key;
+       }
+
+       public KSKFileAttachment(String filename,
+                                long size,
+                                String key,
+                                KSKMessage msg,
+                                FCPQueueManager queueManager) {
+               this(filename, size, key);
+               this.msg = msg;
+               this.queueManager = queueManager;
+       }
+
+
+       public String getType() {
+               return "file";
+       }
+
+       public String getPrintableType() {
+               return I18n.getMessage("thaw.common.file");
+       }
+
+
+       public String[] getProperties() {
+               return new String[] {
+                       "name",
+                       "size",
+                       "key"
+               };
+       }
+
+       public String[] getValues() {
+               return new String[] {
+                       filename,
+                       Long.toString(size),
+                       key
+               };
+       }
+
+       public String getValue(String property) {
+               if ("name".equals(property)) {
+                       return filename;
+               } else if ("size".equals(property)) {
+                       return Long.toString(size);
+               } else if ("key".equals(property)) {
+                       return key;
+               }
+
+               return null;
+       }
+
+       public void setValue(String property, String value) {
+               if ("name".equals(property)) {
+                       if (filename == null)
+                               filename = value;
+               } else if ("size".equals(property)) {
+                       try {
+                               size = Long.parseLong(value);
+                       } catch(NumberFormatException e) {
+                               Logger.warning(this, "Can't parse size");
+                               return;
+                       }
+               } else if ("key".equals(property)) {
+                       key = value;
+
+                       String possibleFilename = 
thaw.fcp.FreenetURIHelper.getFilenameFromKey(key).trim();
+
+                       if (possibleFilename != null
+                           && !("".equals(possibleFilename)))
+                               filename = possibleFilename;
+               } else {
+                       Logger.error(this, "Unknown field : "+property);
+               }
+       }
+
+       public String toString() {
+               return filename;
+       }
+
+       public String getContainer() {
+               return "File";
+       }
+
+
+       public String[] getActions() {
+               return new String[] {
+                       I18n.getMessage("thaw.common.copyKeyToClipboard"),
+                       I18n.getMessage("thaw.plugin.miniFrost.copyAllKeys"),
+                       I18n.getMessage("thaw.common.action.download"),
+                       I18n.getMessage("thaw.plugin.miniFrost.downloadAll")
+               };
+       }
+
+       private Vector keysToDownload;
+
+
+       public void apply(Hsqldb db, FCPQueueManager queueManager, String 
action) {
+               if 
(action.equals(I18n.getMessage("thaw.common.copyKeyToClipboard"))) {
+                       thaw.gui.GUIHelper.copyToClipboard(key);
+               } else if 
(action.equals(I18n.getMessage("thaw.plugin.miniFrost.copyAllKeys"))) {
+                       String keys = "";
+
+                       Vector a = msg.getAttachments();
+
+                       for (Iterator it = a.iterator() ;
+                            it.hasNext();) {
+                               Object o = it.next();
+
+                               if (o instanceof KSKFileAttachment)
+                                       keys += 
((KSKFileAttachment)o).getValue("key");
+                       }
+
+                       thaw.gui.GUIHelper.copyToClipboard(keys);
+
+               } else if 
(action.equals(I18n.getMessage("thaw.common.action.download"))) {
+                       keysToDownload = new Vector();
+                       keysToDownload.add(key);
+
+                       Thread th = new Thread(this);
+                       th.start();
+               } else if 
(action.equals(I18n.getMessage("thaw.plugin.miniFrost.downloadAll"))) {
+                       keysToDownload = new Vector();
+
+                       Vector a = msg.getAttachments();
+
+                       for (Iterator it = a.iterator() ;
+                            it.hasNext();) {
+                               Object o = it.next();
+
+                               if (o instanceof KSKFileAttachment)
+                                       
keysToDownload.add(((KSKFileAttachment)o).getValue("key"));
+                       }
+
+                       Thread th = new Thread(this);
+                       th.start();
+               }
+       }
+
+
+       public void run() {
+               /* yeah, I didn't realize that I may need the config here :/ */
+               Config config = 
((KSKBoard)msg.getBoard()).getFactory().getCore().getConfig();
+
+               FileChooser ch = new 
FileChooser(config.getValue("lastDestinationDirectory"));
+               
ch.setTitle(I18n.getMessage("thaw.plugin.fetch.chooseDestination"));
+               ch.setDirectoryOnly(true);
+               ch.setDialogType(javax.swing.JFileChooser.SAVE_DIALOG);
+
+               java.io.File dir = ch.askOneFile();
+
+               if (dir == null)
+                       return;
+
+               for (Iterator it = keysToDownload.iterator();
+                    it.hasNext();) {
+                       String key = (String)it.next();
+
+                       FCPClientGet get = new FCPClientGet(key, 
FCPClientGet.DEFAULT_PRIORITY,
+                                                           
FCPClientGet.PERSISTENCE_FOREVER,
+                                                           true, /* globale 
queue */
+                                                           
FCPClientGet.DEFAULT_MAX_RETRIES,
+                                                           dir.getPath());
+                       queueManager.addQueryToThePendingQueue(get);
+               }
+       }
+
+
+       public void insert(Hsqldb db, int messageId) {
+               if (filename == null
+                   || size == 0
+                   || key == null) {
+                       Logger.warning(this, "Missing field");
+                       return;
+               }
+
+               try {
+                       synchronized(db.dbLock) {
+                               PreparedStatement st;
+
+                               st = 
db.getConnection().prepareStatement("INSERT INTO frostKSKAttachmentFiles "+
+                                                                        
"(filename, size, key, messageId) "+
+                                                                        
"VALUEs (?, ?, ?, ?)");
+                               st.setString(1, filename);
+                               st.setLong(2, size);
+                               st.setString(3, key);
+                               st.setInt(4, messageId);
+
+                               st.execute();
+                       }
+               } catch(SQLException e) {
+                       Logger.error(this, "Can't insert the file attachment 
because : "+e.toString());
+               }
+       }
+
+
+       public static Vector select(KSKMessage msg, KSKBoardFactory 
boardFactory,
+                                   Hsqldb db) {
+               Vector v = new Vector();
+
+               try {
+                       synchronized(db.dbLock) {
+                               PreparedStatement st;
+
+                               st = 
db.getConnection().prepareStatement("SELECT filename, size, key "+
+                                                                        "FROM 
frostKSKAttachmentFiles "+
+                                                                        "WHERE 
messageId = ?");
+                               st.setInt(1, msg.getId());
+
+                               ResultSet set = st.executeQuery();
+
+                               while(set.next()) {
+                                       v.add(new 
KSKFileAttachment(set.getString("filename"),
+                                                                   
set.getLong("size"),
+                                                                   
set.getString("key"),
+                                                                   msg,
+                                                                   
boardFactory.getCore().getQueueManager()));
+                               }
+                       }
+               } catch(SQLException e) {
+                       Logger.error(e, "Can't select file attachments because: 
"+e.toString());
+               }
+
+               return (v.size() > 0 ? v : null);
+       }
+}

Modified: trunk/apps/Thaw/src/thaw/plugins/miniFrost/frostKSK/KSKMessage.java
===================================================================
--- trunk/apps/Thaw/src/thaw/plugins/miniFrost/frostKSK/KSKMessage.java 
2007-07-25 15:14:22 UTC (rev 14333)
+++ trunk/apps/Thaw/src/thaw/plugins/miniFrost/frostKSK/KSKMessage.java 
2007-07-25 15:48:12 UTC (rev 14334)
@@ -398,6 +398,15 @@
                return id;
        }

+
+       public Vector getAttachments() {
+               return KSKAttachmentFactory.getAttachments(this,
+                                                          board.getFactory(),
+                                                          
board.getFactory().getDb());
+
+       }
+
+
        public boolean equals(Object o) {
                if (!(o instanceof KSKMessage))
                        return false;

Modified: 
trunk/apps/Thaw/src/thaw/plugins/miniFrost/frostKSK/KSKMessageParser.java
===================================================================
--- trunk/apps/Thaw/src/thaw/plugins/miniFrost/frostKSK/KSKMessageParser.java   
2007-07-25 15:14:22 UTC (rev 14333)
+++ trunk/apps/Thaw/src/thaw/plugins/miniFrost/frostKSK/KSKMessageParser.java   
2007-07-25 15:48:12 UTC (rev 14334)
@@ -8,12 +8,16 @@
 import java.text.SimpleDateFormat;
 import java.io.File;

+import java.util.Vector;
+import java.util.Iterator;
+import java.util.List;
+
+
 import frost.util.XMLTools;

 import thaw.plugins.Hsqldb;
 import thaw.core.Logger;

-
 /**
  * Dirty parser reusing some Frost functions
  * (Note: dirty mainly because of the Frost format :p)
@@ -35,7 +39,9 @@
        private String board;
        private String body;

+       private Vector attachments;

+
        private boolean alreadyInTheDb(Hsqldb db, String msgId) {
                try {
                        synchronized(db.dbLock) {
@@ -99,6 +105,7 @@
                        synchronized(db.dbLock) {
                                PreparedStatement st;

+                               /* we search the message to this one answer */
                                if (inReplyTo != null) {
                                        String[] split = inReplyTo.split(",");
                                        inReplyTo = split[split.length-1];
@@ -114,6 +121,7 @@

                                }

+                               /* we insert the message */

                                st = 
db.getConnection().prepareStatement("INSERT INTO frostKSKMessages ("+
                                                                         
"subject, nick, sigId, content, "+
@@ -143,6 +151,28 @@

                                st.execute();

+
+                               /* we need the id of the message */
+
+                               st = 
db.getConnection().prepareStatement("SELECT id FROM frostKSKmessages "+
+                                                                        "WHERE 
msgId = ? LIMIT 1");
+                               st.setString(1, messageId);
+
+                               ResultSet set = st.executeQuery();
+
+                               set.next();
+
+                               int id = set.getInt("id");
+
+                               /* we insert the attachments */
+
+                               if (attachments != null) {
+                                       for(Iterator it = 
attachments.iterator();
+                                           it.hasNext();) {
+                                               KSKAttachment a = 
(KSKAttachment)it.next();
+                                               a.insert(db, id);
+                                       }
+                               }
                        }
                } catch(SQLException e) {
                        Logger.error(this, "Can't insert the message into the 
db because : "+e.toString());
@@ -165,6 +195,22 @@
                board         = XMLTools.getChildElementsCDATAValue(root, 
"Board");
                body          = XMLTools.getChildElementsCDATAValue(root, 
"Body");

+               List l = XMLTools.getChildElementsByTagName(root, 
"AttachmentList");
+               if (l.size() == 1) {
+                       attachments = new Vector();
+
+                       KSKAttachmentFactory factory = new 
KSKAttachmentFactory();
+
+                       Element attachmentsEl = (Element) l.get(0);
+                       Iterator i = 
XMLTools.getChildElementsByTagName(attachmentsEl,"Attachment").iterator();
+                       while (i.hasNext()){
+                               Element el = (Element)i.next();
+                               KSKAttachment attachment = 
factory.getAttachment(el);
+                               if (attachment != null)
+                                       attachments.add(attachment);
+                       }
+               }
+
                return true;
        }

@@ -195,7 +241,9 @@
                        return loadXMLElements(rootNode);

                } catch(Exception e) {
+                       /* XMLTools throws runtime exception sometimes ... */
                        Logger.warning(this, "Unable to parse XML message 
because : "+e.toString());
+                       e.printStackTrace();
                        return false;
                }
        }

Added: trunk/apps/Thaw/src/thaw/plugins/miniFrost/interfaces/Attachment.java
===================================================================
--- trunk/apps/Thaw/src/thaw/plugins/miniFrost/interfaces/Attachment.java       
                        (rev 0)
+++ trunk/apps/Thaw/src/thaw/plugins/miniFrost/interfaces/Attachment.java       
2007-07-25 15:48:12 UTC (rev 14334)
@@ -0,0 +1,36 @@
+package thaw.plugins.miniFrost.interfaces;
+
+import thaw.plugins.Hsqldb;
+import thaw.fcp.FCPQueueManager;
+
+
+public interface Attachment {
+
+       public String getType();
+       public String getPrintableType();
+
+       public String[] getProperties();
+
+       /**
+        * @return an array with the same size than the one of getProperties()
+        */
+       public String[] getValues();
+
+       public String getValue(String property);
+       public void   setValue(String property, String value);
+
+       /**
+        * Provides the XML tag name containing the properties
+        * @return null if none
+        */
+       public String getContainer();
+
+       /**
+        * Name to display
+        * (the exact display will be: "[getPrintableType()]: [toString()]")
+        */
+       public String toString();
+
+       public String[] getActions();
+       public void apply(Hsqldb db, FCPQueueManager queueManager, String 
action);
+}

Modified: trunk/apps/Thaw/src/thaw/plugins/miniFrost/interfaces/Message.java
===================================================================
--- trunk/apps/Thaw/src/thaw/plugins/miniFrost/interfaces/Message.java  
2007-07-25 15:14:22 UTC (rev 14333)
+++ trunk/apps/Thaw/src/thaw/plugins/miniFrost/interfaces/Message.java  
2007-07-25 15:48:12 UTC (rev 14334)
@@ -29,6 +29,10 @@
         */
        public Vector getSubMessages();

+       /**
+        * @return null if none
+        */
+       public Vector getAttachments();

        public boolean equals(Object o);
 }


Reply via email to