summaryrefslogtreecommitdiff
path: root/wizards/com/sun/star/wizards/web/FTPDialog.java
blob: 976e57790ab2e72ed1660f077fc2c3d8efa9a16f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
/*************************************************************************
 *
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
 *
 * Copyright 2000, 2010 Oracle and/or its affiliates.
 *
 * OpenOffice.org - a multi-platform office productivity suite
 *
 * This file is part of OpenOffice.org.
 *
 * OpenOffice.org is free software: you can redistribute it and/or modify
 * it under the terms of the GNU Lesser General Public License version 3
 * only, as published by the Free Software Foundation.
 *
 * OpenOffice.org is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU Lesser General Public License version 3 for more details
 * (a copy is included in the LICENSE file that accompanied this code).
 *
 * You should have received a copy of the GNU Lesser General Public License
 * version 3 along with OpenOffice.org.  If not, see
 * <http://www.openoffice.org/license.html>
 * for a copy of the LGPLv3 License.
 *
 ************************************************************************/
package com.sun.star.wizards.web;

import java.util.List;
import java.util.Vector;

import com.sun.star.awt.PushButtonType;
import com.sun.star.awt.XButton;
import com.sun.star.awt.XControl;
import com.sun.star.awt.XFixedText;
import com.sun.star.awt.XTextComponent;
import com.sun.star.lang.XMultiServiceFactory;
import com.sun.star.ucb.AuthenticationRequest;
import com.sun.star.ucb.InteractiveAugmentedIOException;
import com.sun.star.ucb.InteractiveNetworkConnectException;
import com.sun.star.ucb.InteractiveNetworkResolveNameException;
import com.sun.star.ucb.OpenCommandArgument2;
import com.sun.star.ucb.OpenMode;
import com.sun.star.wizards.common.Desktop;
import com.sun.star.wizards.common.FileAccess;
import com.sun.star.wizards.common.Helper;
import com.sun.star.wizards.common.SystemDialog;
import com.sun.star.wizards.common.UCB;
import com.sun.star.wizards.ui.UIConsts;
import com.sun.star.wizards.ui.UnoDialog;
import com.sun.star.wizards.ui.UnoDialog2;
import com.sun.star.wizards.ui.event.DataAware;
import com.sun.star.wizards.ui.event.UnoDataAware;
import com.sun.star.wizards.web.data.CGPublish;
import com.sun.star.wizards.web.data.CGSettings;

/**
 * This is the FTP Dialog. <br/>
 * The Dialog enables the user:
 * (*) entering FTP server and user information.
 * (*) testing the connection.
 * (*) choosing a directory on the server.
 * If a connection was established succesfully, the user may
 * press OK, which will change
 * the CGPublish object propertiers according the user's input.
 * If no connection was established. the OK and Choose-Dir button are disabled.
 * See the method "disconnect()" which disables them.
 *
 * I use here the DataAware concept to automatically update
 * the members ip, username, and password (via the methods setXXX(...))
 * for details see the ui.events.DataAware classes. <br/>
 */
public class FTPDialog extends UnoDialog2 implements UIConsts, WWHID
{

    /**
     * A Constant used for the setLabel(int) method to change the
     * status-display. "unknown" is the status when the user first
     * opens the dialog, or changes the servername/username/password.
     */
    private final static int STATUS_UNKONWN = 0;
    /**
     * A Constant used for the setLabel(int) method to change the
     * status-display. (connection established)
     */
    private final static int STATUS_OK = 1;
    /**
     * A Constant used for the setLabel(int) method to change the
     * status-display.
     */
    private final static int STATUS_USER_PWD_WRONG = 2;
    /**
     * A Constant used for the setLabel(int) method to change the
     * status-display.
     */
    private final static int STATUS_SERVER_NOT_FOUND = 3;
    /**
     * A Constant used for the setLabel(int) method to change the
     * status-display.
     */
    private final static int STATUS_NO_RIGHTS = 4;
    /**
     * A Constant used for the setLabel(int) method to change the
     * status-display.
     */
    private final static int STATUS_HOST_UNREACHABLE = 5;
    /**
     * A Constant used for the setLabel(int) method to change the
     * status-display.
     */
    private final static int STATUS_CONNECTING = 6;
    /**
     * The icon url for error
     */
    private final static String ICON_ERROR = "ftperror.gif";
    /**
     * The icon url for ok (connection ok)
     */
    private final static String ICON_OK = "ftpconnected.gif";
    /**
     * The icon url for unknown - this is the status when
     * the user first opens the dialog
     */
    private final static String ICON_UNKNOWN = "ftpunknown.gif";
    /**
     * The icon url for an icon representing the "connecting" state.
     */
    private final static String ICON_CONNECTING = "ftpconnecting.gif";    //GUI Components as Class members.
    //Fixed Line
    private XControl ln1;
    private XFixedText lblFTPAddress;
    private XTextComponent txtHost;
    private XFixedText lblUsername;
    private XTextComponent txtUsername;
    private XFixedText lblPassword;
    private XTextComponent txtPassword;
    //Fixed Line
    private XControl ln2;
    private XButton btnTestConnection;
    private XControl imgStatus;
    private XFixedText lblStatus;
    //Fixed Line
    private XControl ln3;
    private XTextComponent txtDir;
    private XButton btnDir;
    private XButton btnOK;
    private XButton btnCancel;
    private XButton btnHelp;
    //Font Descriptors as Class members.

    //Resources Object
    private FTPDialogResources resources;
    private List dataAware = new Vector();
    public String username = "";
    public String password = "";
    /**
     * The ftp host name
     */
    public String host = "";
    /**
     * The ftp directory.
     */
    private String dir = "";
    /**
     * the ftp publish object which contains the
     * data for this dialog.
     */
    private CGPublish publish;
    private UCB ucb;
    /**
     * used for the status images url.
     */
    private String imagesDirectory;

    /**
     * constructor.
     * constructs the UI.
     * @param xmsf
     * @param p the publishert object that contains the data
     * for this dialog
     * @throws Exception
     */
    public FTPDialog(XMultiServiceFactory xmsf, CGPublish p) throws Exception
    {
        super(xmsf);
        publish = p;


        imagesDirectory = FileAccess.connectURLs(((CGSettings) (publish.root)).soTemplateDir, "../wizard/bitmap/");

        //Load Resources
        resources = new FTPDialogResources(xmsf);
        ucb = new UCB(xmsf);

        //set dialog properties...
        Helper.setUnoPropertyValues(xDialogModel,
                new String[]
                {
                    "Closeable", "Height", "HelpURL", "Moveable", "Name", "PositionX", "PositionY", "Title", "Width"
                },
                new Object[]
                {
                    Boolean.TRUE, new Integer(160), "HID:" + HID_FTP, Boolean.TRUE, "FTPDialog", new Integer(167), new Integer(82), resources.resFTPDialog_title, new Integer(222)
                });

        //add controls to dialog
        build();
        //make the hostname, username and password textfield data-aware.
        configure();
        //make sure we display a disconnected status.
        disconnect();
    }

    /**
     * Add controls to dialog.
     */
    public void build()
    {
        final String[] PROPNAMES_LABEL = new String[]
        {
            "Height", "Label", "Name", "PositionX", "PositionY", "TabIndex", "Width"
        };
        final String[] PROPNAMES_BUTTON = new String[]
        {
            "Height", "HelpURL", "Label", "Name", "PositionX", "PositionY", "TabIndex", "Width"
        };
        final String[] PROPNAMES_BUTTON2 = new String[]
        {
            "Height", "HelpURL", "Label", "Name", "PositionX", "PositionY", "PushButtonType", "TabIndex", "Width"
        };

        ln1 = insertFixedLine("ln1",
                PROPNAMES_LABEL,
                new Object[]
                {
                    INTEGERS[8], resources.resln1_value, "ln1", INTEGERS[6], INTEGERS[6], new Short((short) 0), new Integer(210)
                });
        lblFTPAddress = insertLabel("lblFTPAddress",
                PROPNAMES_LABEL,
                new Object[]
                {
                    INTEGERS[8], resources.reslblFTPAddress_value, "lblFTPAddress", INTEGER_12, new Integer(20), new Short((short) 1), new Integer(95)
                });
        txtHost = insertTextField("txtHost", "disconnect",
                new String[]
                {
                    "Height", "HelpURL", "Name", "PositionX", "PositionY", "TabIndex", "Width"
                },
                new Object[]
                {
                    INTEGER_12, "HID:" + HID_FTP_SERVER, "txtIP", new Integer(110), new Integer(18), new Short((short) 2), new Integer(106)
                });
        lblUsername = insertLabel("lblUsername",
                PROPNAMES_LABEL,
                new Object[]
                {
                    INTEGERS[8], resources.reslblUsername_value, "lblUsername", INTEGER_12, new Integer(36), new Short((short) 3), new Integer(85)
                });
        txtUsername = insertTextField("txtUsername", "disconnect",
                new String[]
                {
                    "Height", "HelpURL", "Name", "PositionX", "PositionY", "TabIndex", "Width"
                },
                new Object[]
                {
                    INTEGER_12, "HID:" + HID_FTP_USERNAME, "txtUsername", new Integer(110), new Integer(34), new Short((short) 4), new Integer(106)
                });
        lblPassword = insertLabel("lblPassword",
                PROPNAMES_LABEL,
                new Object[]
                {
                    INTEGERS[8], resources.reslblPassword_value, "lblPassword", INTEGER_12, new Integer(52), new Short((short) 5), new Integer(85)
                });
        txtPassword = insertTextField("txtPassword", "disconnect",
                new String[]
                {
                    "EchoChar", "Height", "HelpURL", "Name", "PositionX", "PositionY", "TabIndex", "Width"
                },
                new Object[]
                {
                    new Short((short) 42), INTEGER_12, "HID:" + HID_FTP_PASS, "txtPassword", new Integer(110), new Integer(50), new Short((short) 6), new Integer(106)
                });
        ln2 = insertFixedLine("ln2",
                PROPNAMES_LABEL,
                new Object[]
                {
                    INTEGERS[8], resources.resln2_value, "ln2", INTEGERS[6], new Integer(68), new Short((short) 7), new Integer(210)
                });
        btnTestConnection = insertButton("btnConnect", "connect",
                PROPNAMES_BUTTON,
                new Object[]
                {
                    INTEGER_14, "HID:" + HID_FTP_TEST, resources.resbtnConnect_value, "btnConnect", INTEGER_12, new Integer(80), new Short((short) 8), INTEGER_50
                });

        imgStatus = insertImage("imgStatus",
                new String[]
                {
                    "Border", "Height", "PositionX", "PositionY", "ScaleImage", "Tabstop", "Width"
                },
                new Object[]
                {
                    new Short((short) 0), INTEGER_14, new Integer(68), new Integer(80), Boolean.FALSE, Boolean.FALSE, INTEGER_14
                });

        lblStatus = insertLabel("lblStatus",
                PROPNAMES_LABEL,
                new Object[]
                {
                    INTEGERS[8], resources.resFTPDisconnected, "lblStatus", new Integer(86), new Integer(82), new Short((short) 9), new Integer(99)
                });

        ln3 = insertFixedLine("ln3",
                PROPNAMES_LABEL,
                new Object[]
                {
                    INTEGERS[8], resources.resln3_value, "ln3", INTEGERS[6], new Integer(100), new Short((short) 10), new Integer(210)
                });

        txtDir = insertTextField("txtDir",
                null, new String[]
                {
                    "Enabled", "Height", "HelpURL", "Name", "PositionX", "PositionY", "TabIndex", "Text", "Width"
                },
                new Object[]
                {
                    new Boolean(false), INTEGER_12, "HID:" + HID_FTP_TXT_PATH, "txtDir", INTEGER_12, new Integer(113), new Short((short) 11), resources.restxtDir_value, new Integer(184)
                });
        btnDir = insertButton("btnDir", "chooseDirectory",
                PROPNAMES_BUTTON,
                new Object[]
                {
                    INTEGER_14, "HID:" + HID_FTP_BTN_PATH, resources.resbtnDir_value, "btnDir", new Integer(199), new Integer(112), new Short((short) 12), INTEGER_16
                });

        btnOK = insertButton("btnOK", null,
                PROPNAMES_BUTTON2,
                new Object[]
                {
                    INTEGER_14, "HID:" + HID_FTP_OK, resources.resbtnOK_value, "btnOK", new Integer(165), new Integer(142), new Short((short) PushButtonType.OK_value), new Short((short) 13), INTEGER_50
                });

        btnCancel = insertButton("btnCancel",
                null, PROPNAMES_BUTTON2,
                new Object[]
                {
                    INTEGER_14, "HID:" + HID_FTP_CANCEL, resources.resbtnCancel_value, "btnCancel", new Integer(113), new Integer(142), new Short((short) PushButtonType.CANCEL_value), new Short((short) 14), INTEGER_50
                });

        btnHelp = insertButton("btnHelp", null,
                PROPNAMES_BUTTON2,
                new Object[]
                {
                    INTEGER_14, "", resources.resbtnHelp_value, "btnHelp", new Integer(57), new Integer(142), new Short((short) PushButtonType.HELP_value), new Short((short) 15), INTEGER_50
                });

    }

    /**
     * Make hostname, username and password text fields data aware.
     */
    private void configure()
    {
        dataAware.add(UnoDataAware.attachEditControl(this, "host", txtHost, null, true));
        dataAware.add(UnoDataAware.attachEditControl(this, "username", txtUsername, null, true));
        dataAware.add(UnoDataAware.attachEditControl(this, "password", txtPassword, null, true));
    }

    /**
     * Shows the dialog.
     * If the user clicks ok, changes the given CGPublish properties to the
     * user input.
     * @param parent a dialog to center this dialog to.
     * @return 0 for cancel, 1 for ok.
     * @throws Exception - well, if something goes wrong...
     */
    public short execute(UnoDialog parent) throws Exception
    {
        host = extractHost(publish.cp_URL);
        username = publish.cp_Username == null ? "" : publish.cp_Username;
        password = publish.password == null ? "" : publish.password;
        dir = extractDir(publish.cp_URL);
        setLabel(STATUS_UNKONWN);

        enableTestButton();
        updateUI();
        short result = executeDialog(parent);
        //change the CGPublish properties
        if (result == 1)
        {
            publish.cp_URL = "ftp://" + host() + getDir();
            publish.cp_Username = username;
            publish.password = password;
        }

        return result;
    }

    /**
     * updates the hostname, username, password and
     * directory text fields.
     * is called uppon initialization.
     */
    private void updateUI()
    {
        DataAware.updateUI(dataAware);
        setDir(dir);
    }

    /**
     * extract the hostname out of the url used by the
     * publisher. This url does not include the username:password string.
     * @param ftpUrl
     * @return
     */
    private String extractHost(String ftpUrl)
    {
        if (ftpUrl == null || ftpUrl.length() < 6)
        {
            return "";
        }
        String url = ftpUrl.substring(6);
        int i = url.indexOf("/");
        if (i == -1)
        {
            return url;
        }
        else
        {
            return url.substring(0, i);
        }
    }

    /**
     * used to get data from the CGPublish object.
     * @param ftpUrl
     * @return the directory portion of the ftp-url
     */
    private String extractDir(String ftpUrl)
    {
        if (ftpUrl == null || ftpUrl.length() < 6)
        {
            return "/";
        }
        String url = ftpUrl.substring(6);
        int i = url.indexOf("/");
        if (i == -1)
        {
            return "/";
        }
        else
        {
            return url.substring(i);
        }
    }

    /**
     * enables/disables the "test" button
     * according to the status of the hostname, username, password text fields.
     * If one of these fields is empty, the button is disabled.
     */
    private void enableTestButton()
    {
        setEnabled(btnTestConnection, !(isEmpty(host) || isEmpty(username) || isEmpty(password)));

    }

    /**
     * @param s
     * @return true if the string is null or "".
     */
    private final boolean isEmpty(String s)
    {
        return (s == null) || (s.equals(""));
    }

    /**
     * @return the ftp url with username and password,
     * but without the directory portion.
     */
    public String getAcountUrl()
    {
        return "ftp://" + username + ":" + password + "@" + host();
    }

    /**
     * return the host name without the "ftp://"
     * @return
     */
    private String host()
    {
        return host(host);
    }

    private static String host(String s)
    {
        return (s.startsWith("ftp://") ? s.substring(6) : s);
    }

    /**
     * @return the full ftp url including username, password and directory portion.
     */
    private String getFullUrl()
    {
        return getAcountUrl() + dir;
    }

    /**
     * First I try to connect to the full url, including directory.
     * If an InteractiveAugmentedIOException accures, I try again,
     * this time without the dir spec. If this works, I change the dir
     * to "/", if not I say to the user its his problem...
     *
     */
    public void connect()
    {
        setEnabled(btnTestConnection, false);
        setLabel(STATUS_CONNECTING);
        boolean success = false;
        try
        {
            connect(getFullUrl());
            success = true;
        }
        catch (InteractiveAugmentedIOException iaioex)
        {
            try
            {
                connect(getAcountUrl());
                setDir("/");
                success = true;
            }
            catch (Exception ex)
            {
                setLabel(STATUS_NO_RIGHTS);
            }
        }
        catch (InteractiveNetworkResolveNameException inrne)
        {
            setLabel(STATUS_SERVER_NOT_FOUND);
        }
        catch (AuthenticationRequest ar)
        {
            setLabel(STATUS_USER_PWD_WRONG);
        }
        catch (InteractiveNetworkConnectException incx)
        {
            setLabel(STATUS_HOST_UNREACHABLE);
        }
        catch (Exception ex)
        {
            setLabel(-1);
            ex.printStackTrace();
        }


        if (success)
        {
            setLabel(STATUS_OK);
            setEnabled(btnDir, true);
            setEnabled(btnOK, true);
        }

        setEnabled(btnTestConnection, true);

    }

    /**
     * To try the conenction I do some actions that
     * seem logical to me: <br/>
     * I get a ucb content.
     * I list the files in this content.
     * I call the ucb "open" command.
     * I get the "Title" property of this content.
     * @param acountUrl
     * @throws Exception
     */
    private void connect(String acountUrl) throws Exception
    {
        Object content = ucb.getContent(acountUrl);

        //list files in the content.
        List l = ucb.listFiles(acountUrl, null);

        //open the content
        OpenCommandArgument2 aArg = new OpenCommandArgument2();
        aArg.Mode = OpenMode.FOLDERS; // FOLDER, DOCUMENTS -> simple filter
        aArg.Priority = 32768; // Ignored by most implementations

        ucb.executeCommand(content, "open", aArg);

        //get the title property of the content.
        Object obj = ucb.getContentProperty(content, "Title", String.class);

    }

    /**
     * changes the ftp subdirectory, in both
     * the UI and the data.
     * @param s the directory.
     */
    public void setDir(String s)
    {
        dir = s;
        Helper.setUnoPropertyValue(getModel(txtDir), "Text", dir);
    }

    /**
     * @return the ftp subdirecrtory.
     */
    public String getDir()
    {
        return dir;
    }

    /**
     * changes the status label to disconnected status, and
     * disables the ok and choose-dir buttons.
     * This method is called also when the hostname, username
     * and passwordtext fields change.
     */
    public void disconnect()
    {
        enableTestButton();
        setEnabled(btnOK, false);
        setEnabled(btnDir, false);
        setLabel(STATUS_UNKONWN);
    }

    /**
     * used for debuging.
     * @param args
     */
    public static void main(String args[])
    {
        String ConnectStr = "uno:socket,host=localhost,port=8100;urp,negotiate=0,forcesynchronous=1;StarOffice.ServiceManager";
        try
        {
            XMultiServiceFactory xLocMSF = Desktop.connect(ConnectStr);
            CGPublish p = new CGPublish();
            p.cp_URL = "ftp://tv-1/Folder";
            p.cp_Username = "ronftp";
            p.password = "ronftp";

            FTPDialog dialog = new FTPDialog(xLocMSF, p);
            dialog.execute(null);
        }
        catch (Exception exception)
        {
            exception.printStackTrace();
        }
    }

    /**
     * changes the status label and icon, according to the
     * given status
     * @param status one opf the private status-constants.
     * if this param is not one of them, an "unknown error" status is displayed.
     */
    private void setLabel(int status)
    {
        switch (status)
        {
            //not connected yet
            case STATUS_UNKONWN:
                setLabel(resources.resFTPDisconnected, ICON_UNKNOWN);
                break;
            //connected!
            case STATUS_OK:
                setLabel(resources.resFTPConnected, ICON_OK);
                break;
            case STATUS_USER_PWD_WRONG:
                setLabel(resources.resFTPUserPwdWrong, ICON_ERROR);
                break;
            //problem resolving server name
            case STATUS_SERVER_NOT_FOUND:
                setLabel(resources.resFTPServerNotFound, ICON_ERROR);
                break;
            //rights problem
            case STATUS_NO_RIGHTS:
                setLabel(resources.resFTPRights, ICON_ERROR);
                break;
            //host unreachable (firewall?)
            case STATUS_HOST_UNREACHABLE:
                setLabel(resources.resFTPHostUnreachable, ICON_ERROR);
                break;
            case STATUS_CONNECTING:
                setLabel(resources.resConnecting, ICON_CONNECTING);
                break;
            default:
                setLabel(resources.resFTPUnknownError, ICON_ERROR);
        }
    }

    /**
     * changes the text of the status label and
     * (TODO) the status image.
     * @param label
     * @param color
     */
    private void setLabel(String label, String image)
    {
        Helper.setUnoPropertyValue(getModel(lblStatus), "Label", label);
        Helper.setUnoPropertyValue(getModel(imgStatus), "ImageURL", imageUrl(image));
    }

    private String imageUrl(String s)
    {
        String t = imagesDirectory + s;
        //System.out.println(t);
        return t;

    }

    /**
     * called when the user clicks
     * the choose-dir button. ("...")
     * Opens the pickFolder dialog.
     * checks if the returned folder is an ftp folder.
     * sets the textbox and the data to the new selected dir.
     */
    public void chooseDirectory()
    {
        SystemDialog sd = SystemDialog.createOfficeFolderDialog(xMSF);
        String newUrl = sd.callFolderDialog(resources.resFTPDirectory, "", getFullUrl());
        if (newUrl != null)
        {
            /*  if the user chose a local directory,
             *  sI do not accept it.
             */
            if (newUrl.startsWith("ftp://"))
            {
                setDir(extractDir(newUrl));
            }
            else
            {
                AbstractErrorHandler.showMessage(xMSF, xControl.getPeer(), resources.resIllegalFolder, ErrorHandler.ERROR_PROCESS_FATAL);
            }
        }
    }

    /**
     * practical to have such a method...
     * @param p the publisher obejct that contains the ftp connection info.
     * @return the full ftp url with username password and everything one needs.
     */
    public static final String getFullURL(CGPublish p)
    {
        return "ftp://" + p.cp_Username + ":" + p.password + "@" + host(p.cp_URL);
    }
}