1 /**************************************************************
2  *
3  * Licensed to the Apache Software Foundation (ASF) under one
4  * or more contributor license agreements.  See the NOTICE file
5  * distributed with this work for additional information
6  * regarding copyright ownership.  The ASF licenses this file
7  * to you under the Apache License, Version 2.0 (the
8  * "License"); you may not use this file except in compliance
9  * with the License.  You may obtain a copy of the License at
10  *
11  *   http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing,
14  * software distributed under the License is distributed on an
15  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16  * KIND, either express or implied.  See the License for the
17  * specific language governing permissions and limitations
18  * under the License.
19  *
20  *************************************************************/
21 
22 
23 package com.sun.star.wizards.web;
24 
25 import java.util.List;
26 import java.util.Vector;
27 
28 import com.sun.star.awt.PushButtonType;
29 import com.sun.star.awt.XButton;
30 import com.sun.star.awt.XControl;
31 import com.sun.star.awt.XFixedText;
32 import com.sun.star.awt.XTextComponent;
33 import com.sun.star.lang.XMultiServiceFactory;
34 import com.sun.star.ucb.AuthenticationRequest;
35 import com.sun.star.ucb.InteractiveAugmentedIOException;
36 import com.sun.star.ucb.InteractiveNetworkConnectException;
37 import com.sun.star.ucb.InteractiveNetworkResolveNameException;
38 import com.sun.star.ucb.OpenCommandArgument2;
39 import com.sun.star.ucb.OpenMode;
40 import com.sun.star.wizards.common.Desktop;
41 import com.sun.star.wizards.common.FileAccess;
42 import com.sun.star.wizards.common.Helper;
43 import com.sun.star.wizards.common.SystemDialog;
44 import com.sun.star.wizards.common.PropertyNames;
45 import com.sun.star.wizards.common.UCB;
46 import com.sun.star.wizards.ui.UIConsts;
47 import com.sun.star.wizards.ui.UnoDialog;
48 import com.sun.star.wizards.ui.UnoDialog2;
49 import com.sun.star.wizards.ui.event.DataAware;
50 import com.sun.star.wizards.ui.event.UnoDataAware;
51 import com.sun.star.wizards.web.data.CGPublish;
52 import com.sun.star.wizards.web.data.CGSettings;
53 import com.sun.star.wizards.common.HelpIds;
54 
55 /**
56  * This is the FTP Dialog. <br/>
57  * The Dialog enables the user:
58  * (*) entering FTP server and user information.
59  * (*) testing the connection.
60  * (*) choosing a directory on the server.
61  * If a connection was established succesfully, the user may
62  * press OK, which will change
63  * the CGPublish object propertiers according the user's input.
64  * If no connection was established. the OK and Choose-Dir button are disabled.
65  * See the method "disconnect()" which disables them.
66  *
67  * I use here the DataAware concept to automatically update
68  * the members ip, username, and password (via the methods setXXX(...))
69  * for details see the ui.events.DataAware classes. <br/>
70  */
71 public class FTPDialog extends UnoDialog2 implements UIConsts, WWHID
72 {
73 
74     /**
75      * A Constant used for the setLabel(int) method to change the
76      * status-display. "unknown" is the status when the user first
77      * opens the dialog, or changes the servername/username/password.
78      */
79     private final static int STATUS_UNKONWN = 0;
80     /**
81      * A Constant used for the setLabel(int) method to change the
82      * status-display. (connection established)
83      */
84     private final static int STATUS_OK = 1;
85     /**
86      * A Constant used for the setLabel(int) method to change the
87      * status-display.
88      */
89     private final static int STATUS_USER_PWD_WRONG = 2;
90     /**
91      * A Constant used for the setLabel(int) method to change the
92      * status-display.
93      */
94     private final static int STATUS_SERVER_NOT_FOUND = 3;
95     /**
96      * A Constant used for the setLabel(int) method to change the
97      * status-display.
98      */
99     private final static int STATUS_NO_RIGHTS = 4;
100     /**
101      * A Constant used for the setLabel(int) method to change the
102      * status-display.
103      */
104     private final static int STATUS_HOST_UNREACHABLE = 5;
105     /**
106      * A Constant used for the setLabel(int) method to change the
107      * status-display.
108      */
109     private final static int STATUS_CONNECTING = 6;
110     /**
111      * The icon url for error
112      */
113     private final static String ICON_ERROR = "ftperror.gif";
114     /**
115      * The icon url for ok (connection ok)
116      */
117     private final static String ICON_OK = "ftpconnected.gif";
118     /**
119      * The icon url for unknown - this is the status when
120      * the user first opens the dialog
121      */
122     private final static String ICON_UNKNOWN = "ftpunknown.gif";
123     /**
124      * The icon url for an icon representing the "connecting" state.
125      */
126     private final static String ICON_CONNECTING = "ftpconnecting.gif";    //GUI Components as Class members.
127     //Fixed Line
128     private XControl ln1;
129     private XFixedText lblFTPAddress;
130     private XTextComponent txtHost;
131     private XFixedText lblUsername;
132     private XTextComponent txtUsername;
133     private XFixedText lblPassword;
134     private XTextComponent txtPassword;
135     //Fixed Line
136     private XControl ln2;
137     private XButton btnTestConnection;
138     private XControl imgStatus;
139     private XFixedText lblStatus;
140     //Fixed Line
141     private XControl ln3;
142     private XTextComponent txtDir;
143     private XButton btnDir;
144     private XButton btnOK;
145     private XButton btnCancel;
146     private XButton btnHelp;
147     //Font Descriptors as Class members.
148 
149     //Resources Object
150     private FTPDialogResources resources;
151     private List dataAware = new Vector();
152     public String username = PropertyNames.EMPTY_STRING;
153     public String password = PropertyNames.EMPTY_STRING;
154     /**
155      * The ftp host name
156      */
157     public String host = PropertyNames.EMPTY_STRING;
158     /**
159      * The ftp directory.
160      */
161     private String dir = PropertyNames.EMPTY_STRING;
162     /**
163      * the ftp publish object which contains the
164      * data for this dialog.
165      */
166     private CGPublish publish;
167     private UCB ucb;
168     /**
169      * used for the status images url.
170      */
171     private String imagesDirectory;
172 
173     /**
174      * constructor.
175      * constructs the UI.
176      * @param xmsf
177      * @param p the publishert object that contains the data
178      * for this dialog
179      * @throws Exception
180      */
FTPDialog(XMultiServiceFactory xmsf, CGPublish p)181     public FTPDialog(XMultiServiceFactory xmsf, CGPublish p) throws Exception
182     {
183         super(xmsf);
184         publish = p;
185 
186 
187         imagesDirectory = FileAccess.connectURLs(((CGSettings) (publish.root)).soTemplateDir, "../wizard/bitmap/");
188 
189         //Load Resources
190         resources = new FTPDialogResources(xmsf);
191         ucb = new UCB(xmsf);
192 
193         //set dialog properties...
194         Helper.setUnoPropertyValues(xDialogModel,
195                 new String[]
196                 {
197                     PropertyNames.PROPERTY_CLOSEABLE, PropertyNames.PROPERTY_HEIGHT, PropertyNames.PROPERTY_HELPURL, PropertyNames.PROPERTY_MOVEABLE, PropertyNames.PROPERTY_NAME, PropertyNames.PROPERTY_POSITION_X, PropertyNames.PROPERTY_POSITION_Y, PropertyNames.PROPERTY_TITLE, PropertyNames.PROPERTY_WIDTH
198                 },
199                 new Object[]
200                 {
201                     Boolean.TRUE, 160, HelpIds.getHelpIdString(HID_FTP), Boolean.TRUE, "FTPDialog", 167, 82, resources.resFTPDialog_title, 222
202                 });
203 
204         //add controls to dialog
205         build();
206         //make the hostname, username and password textfield data-aware.
207         configure();
208         //make sure we display a disconnected status.
209         disconnect();
210     }
211 
212     /**
213      * Add controls to dialog.
214      */
build()215     public void build()
216     {
217         final String[] PROPNAMES_LABEL = new String[]
218         {
219             PropertyNames.PROPERTY_HEIGHT, PropertyNames.PROPERTY_LABEL, PropertyNames.PROPERTY_NAME, PropertyNames.PROPERTY_POSITION_X, PropertyNames.PROPERTY_POSITION_Y, PropertyNames.PROPERTY_TABINDEX, PropertyNames.PROPERTY_WIDTH
220         };
221         final String[] PROPNAMES_BUTTON = new String[]
222         {
223             PropertyNames.PROPERTY_HEIGHT, PropertyNames.PROPERTY_HELPURL, PropertyNames.PROPERTY_LABEL, PropertyNames.PROPERTY_NAME, PropertyNames.PROPERTY_POSITION_X, PropertyNames.PROPERTY_POSITION_Y, PropertyNames.PROPERTY_TABINDEX, PropertyNames.PROPERTY_WIDTH
224         };
225         final String[] PROPNAMES_BUTTON2 = new String[]
226         {
227             PropertyNames.PROPERTY_HEIGHT, PropertyNames.PROPERTY_HELPURL, PropertyNames.PROPERTY_LABEL, PropertyNames.PROPERTY_NAME, PropertyNames.PROPERTY_POSITION_X, PropertyNames.PROPERTY_POSITION_Y, "PushButtonType", PropertyNames.PROPERTY_TABINDEX, PropertyNames.PROPERTY_WIDTH
228         };
229 
230         ln1 = insertFixedLine("ln1",
231                 PROPNAMES_LABEL,
232                 new Object[]
233                 {
234                     INTEGERS[8], resources.resln1_value, "ln1", INTEGERS[6], INTEGERS[6], new Short((short) 0), 210
235                 });
236         lblFTPAddress = insertLabel("lblFTPAddress",
237                 PROPNAMES_LABEL,
238                 new Object[]
239                 {
240                     INTEGERS[8], resources.reslblFTPAddress_value, "lblFTPAddress", INTEGER_12, 20, new Short((short) 1), 95
241                 });
242         txtHost = insertTextField("txtHost", "disconnect",
243                 new String[]
244                 {
245                     PropertyNames.PROPERTY_HEIGHT, PropertyNames.PROPERTY_HELPURL, PropertyNames.PROPERTY_NAME, PropertyNames.PROPERTY_POSITION_X, PropertyNames.PROPERTY_POSITION_Y, PropertyNames.PROPERTY_TABINDEX, PropertyNames.PROPERTY_WIDTH
246                 },
247                 new Object[]
248                 {
249                     INTEGER_12, HelpIds.getHelpIdString(HID_FTP_SERVER), "txtIP", 110, 18, new Short((short) 2), 106
250                 });
251         lblUsername = insertLabel("lblUsername",
252                 PROPNAMES_LABEL,
253                 new Object[]
254                 {
255                     INTEGERS[8], resources.reslblUsername_value, "lblUsername", INTEGER_12, 36, new Short((short) 3), 85
256                 });
257         txtUsername = insertTextField("txtUsername", "disconnect",
258                 new String[]
259                 {
260                     PropertyNames.PROPERTY_HEIGHT, PropertyNames.PROPERTY_HELPURL, PropertyNames.PROPERTY_NAME, PropertyNames.PROPERTY_POSITION_X, PropertyNames.PROPERTY_POSITION_Y, PropertyNames.PROPERTY_TABINDEX, PropertyNames.PROPERTY_WIDTH
261                 },
262                 new Object[]
263                 {
264                     INTEGER_12, HelpIds.getHelpIdString(HID_FTP_USERNAME), "txtUsername", 110, 34, new Short((short) 4), 106
265                 });
266         lblPassword = insertLabel("lblPassword",
267                 PROPNAMES_LABEL,
268                 new Object[]
269                 {
270                     INTEGERS[8], resources.reslblPassword_value, "lblPassword", INTEGER_12, 52, new Short((short) 5), 85
271                 });
272         txtPassword = insertTextField("txtPassword", "disconnect",
273                 new String[]
274                 {
275                     "EchoChar", PropertyNames.PROPERTY_HEIGHT, PropertyNames.PROPERTY_HELPURL, PropertyNames.PROPERTY_NAME, PropertyNames.PROPERTY_POSITION_X, PropertyNames.PROPERTY_POSITION_Y, PropertyNames.PROPERTY_TABINDEX, PropertyNames.PROPERTY_WIDTH
276                 },
277                 new Object[]
278                 {
279                     new Short((short) 42), INTEGER_12, HelpIds.getHelpIdString(HID_FTP_PASS), "txtPassword", 110, 50, new Short((short) 6), 106
280                 });
281         ln2 = insertFixedLine("ln2",
282                 PROPNAMES_LABEL,
283                 new Object[]
284                 {
285                     INTEGERS[8], resources.resln2_value, "ln2", INTEGERS[6], 68, new Short((short) 7), 210
286                 });
287         btnTestConnection = insertButton("btnConnect", "connect",
288                 PROPNAMES_BUTTON,
289                 new Object[]
290                 {
291                     INTEGER_14, HelpIds.getHelpIdString(HID_FTP_TEST), resources.resbtnConnect_value, "btnConnect", INTEGER_12, 80, new Short((short) 8), INTEGER_50
292                 });
293 
294         imgStatus = insertImage("imgStatus",
295                 new String[]
296                 {
297                     PropertyNames.PROPERTY_BORDER, PropertyNames.PROPERTY_HEIGHT, PropertyNames.PROPERTY_POSITION_X, PropertyNames.PROPERTY_POSITION_Y, "ScaleImage", "Tabstop", PropertyNames.PROPERTY_WIDTH
298                 },
299                 new Object[]
300                 {
301                     new Short((short) 0), INTEGER_14, 68, 80, Boolean.FALSE, Boolean.FALSE, INTEGER_14
302                 });
303 
304         lblStatus = insertLabel("lblStatus",
305                 PROPNAMES_LABEL,
306                 new Object[]
307                 {
308                     INTEGERS[8], resources.resFTPDisconnected, "lblStatus", 86, 82, new Short((short) 9), 99
309                 });
310 
311         ln3 = insertFixedLine("ln3",
312                 PROPNAMES_LABEL,
313                 new Object[]
314                 {
315                     INTEGERS[8], resources.resln3_value, "ln3", INTEGERS[6], 100, new Short((short) 10), 210
316                 });
317 
318         txtDir = insertTextField("txtDir",
319                 null, new String[]
320                 {
321                     PropertyNames.PROPERTY_ENABLED, PropertyNames.PROPERTY_HEIGHT, PropertyNames.PROPERTY_HELPURL, PropertyNames.PROPERTY_NAME, PropertyNames.PROPERTY_POSITION_X, PropertyNames.PROPERTY_POSITION_Y, PropertyNames.PROPERTY_TABINDEX, "Text", PropertyNames.PROPERTY_WIDTH
322                 },
323                 new Object[]
324                 {
325                         Boolean.FALSE, INTEGER_12, HelpIds.getHelpIdString(HID_FTP_TXT_PATH), "txtDir", INTEGER_12, 113, new Short((short) 11), resources.restxtDir_value, 184
326                 });
327         btnDir = insertButton("btnDir", "chooseDirectory",
328                 PROPNAMES_BUTTON,
329                 new Object[]
330                 {
331                     INTEGER_14, HelpIds.getHelpIdString(HID_FTP_BTN_PATH), resources.resbtnDir_value, "btnDir", 199, 112, new Short((short) 12), INTEGER_16
332                 });
333 
334         btnOK = insertButton("btnOK", null,
335                 PROPNAMES_BUTTON2,
336                 new Object[]
337                 {
338                     INTEGER_14, HelpIds.getHelpIdString(HID_FTP_OK), resources.resbtnOK_value, "btnOK", 165, 142, new Short((short) PushButtonType.OK_value), new Short((short) 13), INTEGER_50
339                 });
340 
341         btnCancel = insertButton("btnCancel",
342                 null, PROPNAMES_BUTTON2,
343                 new Object[]
344                 {
345                     INTEGER_14, HelpIds.getHelpIdString(HID_FTP_CANCEL), resources.resbtnCancel_value, "btnCancel", 113, 142, new Short((short) PushButtonType.CANCEL_value), new Short((short) 14), INTEGER_50
346                 });
347 
348         btnHelp = insertButton("btnHelp", null,
349                 PROPNAMES_BUTTON2,
350                 new Object[]
351                 {
352                     INTEGER_14, PropertyNames.EMPTY_STRING, resources.resbtnHelp_value, "btnHelp", 57, 142, new Short((short) PushButtonType.HELP_value), new Short((short) 15), INTEGER_50
353                 });
354 
355     }
356 
357     /**
358      * Make hostname, username and password text fields data aware.
359      */
configure()360     private void configure()
361     {
362         dataAware.add(UnoDataAware.attachEditControl(this, "host", txtHost, null, true));
363         dataAware.add(UnoDataAware.attachEditControl(this, "username", txtUsername, null, true));
364         dataAware.add(UnoDataAware.attachEditControl(this, "password", txtPassword, null, true));
365     }
366 
367     /**
368      * Shows the dialog.
369      * If the user clicks ok, changes the given CGPublish properties to the
370      * user input.
371      * @param parent a dialog to center this dialog to.
372      * @return 0 for cancel, 1 for ok.
373      * @throws Exception - well, if something goes wrong...
374      */
execute(UnoDialog parent)375     public short execute(UnoDialog parent) throws Exception
376     {
377         host = extractHost(publish.cp_URL);
378         username = publish.cp_Username == null ? PropertyNames.EMPTY_STRING : publish.cp_Username;
379         password = publish.password == null ? PropertyNames.EMPTY_STRING : publish.password;
380         dir = extractDir(publish.cp_URL);
381         setLabel(STATUS_UNKONWN);
382 
383         enableTestButton();
384         updateUI();
385         short result = executeDialog(parent);
386         //change the CGPublish properties
387         if (result == 1)
388         {
389             publish.cp_URL = "ftp://" + host() + getDir();
390             publish.cp_Username = username;
391             publish.password = password;
392         }
393 
394         return result;
395     }
396 
397     /**
398      * updates the hostname, username, password and
399      * directory text fields.
400      * is called uppon initialization.
401      */
updateUI()402     private void updateUI()
403     {
404         DataAware.updateUI(dataAware);
405         setDir(dir);
406     }
407 
408     /**
409      * extract the hostname out of the url used by the
410      * publisher. This url does not include the username:password string.
411      * @param ftpUrl
412      * @return
413      */
extractHost(String ftpUrl)414     private String extractHost(String ftpUrl)
415     {
416         if (ftpUrl == null || ftpUrl.length() < 6)
417         {
418             return PropertyNames.EMPTY_STRING;
419         }
420         String url = ftpUrl.substring(6);
421         int i = url.indexOf("/");
422         if (i == -1)
423         {
424             return url;
425         }
426         else
427         {
428             return url.substring(0, i);
429         }
430     }
431 
432     /**
433      * used to get data from the CGPublish object.
434      * @param ftpUrl
435      * @return the directory portion of the ftp-url
436      */
extractDir(String ftpUrl)437     private String extractDir(String ftpUrl)
438     {
439         if (ftpUrl == null || ftpUrl.length() < 6)
440         {
441             return "/";
442         }
443         String url = ftpUrl.substring(6);
444         int i = url.indexOf("/");
445         if (i == -1)
446         {
447             return "/";
448         }
449         else
450         {
451             return url.substring(i);
452         }
453     }
454 
455     /**
456      * enables/disables the "test" button
457      * according to the status of the hostname, username, password text fields.
458      * If one of these fields is empty, the button is disabled.
459      */
enableTestButton()460     private void enableTestButton()
461     {
462         setEnabled(btnTestConnection, !(isEmpty(host) || isEmpty(username) || isEmpty(password)));
463 
464     }
465 
466     /**
467      * @param s
468      * @return true if the string is null or PropertyNames.EMPTY_STRING.
469      */
isEmpty(String s)470     private final boolean isEmpty(String s)
471     {
472         return (s == null) || (s.equals(PropertyNames.EMPTY_STRING));
473     }
474 
475     /**
476      * @return the ftp url with username and password,
477      * but without the directory portion.
478      */
getAcountUrl()479     public String getAcountUrl()
480     {
481         return "ftp://" + username + ":" + password + "@" + host();
482     }
483 
484     /**
485      * return the host name without the "ftp://"
486      * @return
487      */
host()488     private String host()
489     {
490         return host(host);
491     }
492 
host(String s)493     private static String host(String s)
494     {
495         return (s.startsWith("ftp://") ? s.substring(6) : s);
496     }
497 
498     /**
499      * @return the full ftp url including username, password and directory portion.
500      */
getFullUrl()501     private String getFullUrl()
502     {
503         return getAcountUrl() + dir;
504     }
505 
506     /**
507      * First I try to connect to the full url, including directory.
508      * If an InteractiveAugmentedIOException accures, I try again,
509      * this time without the dir spec. If this works, I change the dir
510      * to "/", if not I say to the user its his problem...
511      *
512      */
connect()513     public void connect()
514     {
515         setEnabled(btnTestConnection, false);
516         setLabel(STATUS_CONNECTING);
517         boolean success = false;
518         try
519         {
520             connect(getFullUrl());
521             success = true;
522         }
523         catch (InteractiveAugmentedIOException iaioex)
524         {
525             try
526             {
527                 connect(getAcountUrl());
528                 setDir("/");
529                 success = true;
530             }
531             catch (Exception ex)
532             {
533                 setLabel(STATUS_NO_RIGHTS);
534             }
535         }
536         catch (InteractiveNetworkResolveNameException inrne)
537         {
538             setLabel(STATUS_SERVER_NOT_FOUND);
539         }
540         catch (AuthenticationRequest ar)
541         {
542             setLabel(STATUS_USER_PWD_WRONG);
543         }
544         catch (InteractiveNetworkConnectException incx)
545         {
546             setLabel(STATUS_HOST_UNREACHABLE);
547         }
548         catch (Exception ex)
549         {
550             setLabel(-1);
551             ex.printStackTrace();
552         }
553 
554 
555         if (success)
556         {
557             setLabel(STATUS_OK);
558             setEnabled(btnDir, true);
559             setEnabled(btnOK, true);
560         }
561 
562         setEnabled(btnTestConnection, true);
563 
564     }
565 
566     /**
567      * To try the conenction I do some actions that
568      * seem logical to me: <br/>
569      * I get a ucb content.
570      * I list the files in this content.
571      * I call the ucb "open" command.
572      * I get the PropertyNames.PROPERTY_TITLE property of this content.
573      * @param acountUrl
574      * @throws Exception
575      */
connect(String acountUrl)576     private void connect(String acountUrl) throws Exception
577     {
578         Object content = ucb.getContent(acountUrl);
579 
580         //list files in the content.
581         List l = ucb.listFiles(acountUrl, null);
582 
583         //open the content
584         OpenCommandArgument2 aArg = new OpenCommandArgument2();
585         aArg.Mode = OpenMode.FOLDERS; // FOLDER, DOCUMENTS -> simple filter
586         aArg.Priority = 32768; // Ignored by most implementations
587 
588         ucb.executeCommand(content, "open", aArg);
589 
590         //get the title property of the content.
591         Object obj = ucb.getContentProperty(content, PropertyNames.PROPERTY_TITLE, String.class);
592 
593     }
594 
595     /**
596      * changes the ftp subdirectory, in both
597      * the UI and the data.
598      * @param s the directory.
599      */
setDir(String s)600     public void setDir(String s)
601     {
602         dir = s;
603         Helper.setUnoPropertyValue(getModel(txtDir), "Text", dir);
604     }
605 
606     /**
607      * @return the ftp subdirecrtory.
608      */
getDir()609     public String getDir()
610     {
611         return dir;
612     }
613 
614     /**
615      * changes the status label to disconnected status, and
616      * disables the ok and choose-dir buttons.
617      * This method is called also when the hostname, username
618      * and passwordtext fields change.
619      */
disconnect()620     public void disconnect()
621     {
622         enableTestButton();
623         setEnabled(btnOK, false);
624         setEnabled(btnDir, false);
625         setLabel(STATUS_UNKONWN);
626     }
627 
628     /**
629      * used for debuging.
630      * @param args
631      */
main(String args[])632     public static void main(String args[])
633     {
634         String ConnectStr = "uno:socket,host=localhost,port=8100;urp,negotiate=0,forcesynchronous=1;StarOffice.ServiceManager";
635         try
636         {
637             XMultiServiceFactory xLocMSF = Desktop.connect(ConnectStr);
638             CGPublish p = new CGPublish();
639             p.cp_URL = "ftp://tv-1/Folder";
640             p.cp_Username = "ronftp";
641             p.password = "ronftp";
642 
643             FTPDialog dialog = new FTPDialog(xLocMSF, p);
644             dialog.execute(null);
645         }
646         catch (Exception exception)
647         {
648             exception.printStackTrace();
649         }
650     }
651 
652     /**
653      * changes the status label and icon, according to the
654      * given status
655      * @param status one opf the private status-constants.
656      * if this param is not one of them, an "unknown error" status is displayed.
657      */
setLabel(int status)658     private void setLabel(int status)
659     {
660         switch (status)
661         {
662             //not connected yet
663             case STATUS_UNKONWN:
664                 setLabel(resources.resFTPDisconnected, ICON_UNKNOWN);
665                 break;
666             //connected!
667             case STATUS_OK:
668                 setLabel(resources.resFTPConnected, ICON_OK);
669                 break;
670             case STATUS_USER_PWD_WRONG:
671                 setLabel(resources.resFTPUserPwdWrong, ICON_ERROR);
672                 break;
673             //problem resolving server name
674             case STATUS_SERVER_NOT_FOUND:
675                 setLabel(resources.resFTPServerNotFound, ICON_ERROR);
676                 break;
677             //rights problem
678             case STATUS_NO_RIGHTS:
679                 setLabel(resources.resFTPRights, ICON_ERROR);
680                 break;
681             //host unreachable (firewall?)
682             case STATUS_HOST_UNREACHABLE:
683                 setLabel(resources.resFTPHostUnreachable, ICON_ERROR);
684                 break;
685             case STATUS_CONNECTING:
686                 setLabel(resources.resConnecting, ICON_CONNECTING);
687                 break;
688             default:
689                 setLabel(resources.resFTPUnknownError, ICON_ERROR);
690         }
691     }
692 
693     /**
694      * changes the text of the status label and
695      * (TODO) the status image.
696      * @param label
697      * @param color
698      */
setLabel(String label, String image)699     private void setLabel(String label, String image)
700     {
701         Helper.setUnoPropertyValue(getModel(lblStatus), PropertyNames.PROPERTY_LABEL, label);
702         Helper.setUnoPropertyValue(getModel(imgStatus), PropertyNames.PROPERTY_IMAGEURL, imageUrl(image));
703     }
704 
imageUrl(String s)705     private String imageUrl(String s)
706     {
707         return imagesDirectory + s;
708     }
709 
710     /**
711      * called when the user clicks
712      * the choose-dir button. ("...")
713      * Opens the pickFolder dialog.
714      * checks if the returned folder is an ftp folder.
715      * sets the textbox and the data to the new selected dir.
716      */
chooseDirectory()717     public void chooseDirectory()
718     {
719         SystemDialog sd = SystemDialog.createOfficeFolderDialog(xMSF);
720         String newUrl = sd.callFolderDialog(resources.resFTPDirectory, PropertyNames.EMPTY_STRING, getFullUrl());
721         if (newUrl != null)
722         {
723             /*  if the user chose a local directory,
724              *  sI do not accept it.
725              */
726             if (newUrl.startsWith("ftp://"))
727             {
728                 setDir(extractDir(newUrl));
729             }
730             else
731             {
732                 AbstractErrorHandler.showMessage(xMSF, xControl.getPeer(), resources.resIllegalFolder, ErrorHandler.ERROR_PROCESS_FATAL);
733             }
734         }
735     }
736 
737     /**
738      * practical to have such a method...
739      * @param p the publisher obejct that contains the ftp connection info.
740      * @return the full ftp url with username password and everything one needs.
741      */
getFullURL(CGPublish p)742     public static final String getFullURL(CGPublish p)
743     {
744         return "ftp://" + p.cp_Username + ":" + p.password + "@" + host(p.cp_URL);
745     }
746 }
747