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