1 18 package sync4j.syncclient.ipod; 19 20 import java.io.File ; 21 import java.util.Hashtable ; 22 import java.util.Properties ; 23 24 import java.awt.*; 25 import java.awt.event.*; 26 import javax.swing.*; 27 28 import sync4j.syncclient.spdm.DMException; 29 import sync4j.syncclient.spdm.ManagementNode; 30 import sync4j.syncclient.spdm.SimpleDeviceManager; 31 32 import sync4j.syncclient.spds.SyncManager; 33 import sync4j.syncclient.spds.UpdateException; 34 import sync4j.syncclient.spds.AuthenticationException; 35 import sync4j.syncclient.spds.event.SyncListener; 36 import sync4j.syncclient.spds.event.SyncItemListener; 37 import sync4j.syncclient.spds.event.SyncSourceListener; 38 import sync4j.syncclient.spds.event.SyncStatusListener; 39 import sync4j.syncclient.spds.event.SyncTransportListener; 40 import sync4j.syncclient.spds.event.SyncEvent; 41 import sync4j.syncclient.spds.event.SyncItemEvent; 42 import sync4j.syncclient.spds.event.SyncSourceEvent; 43 import sync4j.syncclient.spds.event.SyncStatusEvent; 44 import sync4j.syncclient.spds.event.SyncTransportEvent; 45 46 import sync4j.syncclient.ipod.utils.*; 47 48 import sync4j.syncclient.common.logging.Logger; 49 50 51 57 public class MainWindow extends JFrame 58 implements ActionListener, Constants, SyncItemListener, SyncListener, 59 SyncSourceListener, SyncStatusListener, SyncTransportListener { 60 61 public static final String DM_VALUE_PATH = "spds/syncml" ; 63 public static final String DM_VALUE_CONTACT_PATH = "spds/sources/contact" ; 64 public static final String DM_VALUE_CALENDAR_PATH = "spds/sources/calendar"; 65 public static final String DM_VALUE_NOTE_PATH = "spds/sources/note" ; 66 67 public static final String PROP_CHARSET = "spds.charset"; 68 public static final String PROP_WD = "wd" ; 69 70 public static final String VALUE_UTF8 = "UTF8" ; 71 72 public static final String ROOT_DIRECTORY = "config"; 73 74 76 80 private boolean syncError = false; 81 82 85 private ManagementNode rootNode = null; 86 87 90 private Hashtable syncmlValues = null; 91 92 95 private Hashtable xmlContactValues = null; 96 97 100 private Hashtable xmlCalendarValues = null; 101 102 105 private Hashtable xmlNoteValues = null; 106 107 110 private String rootDirectory = null; 111 112 115 private String sourceDirectory = ""; 116 117 120 private JLabel jlStatus; 121 private JButton btSync; 122 public static void main(String [] args) { 124 MainWindow mw = new MainWindow(); 125 mw.show(); 126 } 127 128 public MainWindow() { 129 super(); 130 Language.init(); 131 createAndShowMainGUI(); 132 133 Properties props = System.getProperties(); 134 rootDirectory = System.getProperty(PROP_WD); 135 136 if (System.getProperty(SimpleDeviceManager.PROP_DM_DIR_BASE) == null) { 137 props.put(SimpleDeviceManager.PROP_DM_DIR_BASE , 138 buildPath(rootDirectory, ROOT_DIRECTORY) 139 ); 140 System.setProperties(props); 141 } 142 props = System.getProperties(); 143 props.put(PROP_CHARSET, VALUE_UTF8); 144 System.setProperties(props); 145 146 sourceDirectory = buildPath(rootDirectory,sourceDirectory); 147 148 rootNode = SimpleDeviceManager.getDeviceManager().getManagementTree(); 152 153 try { 154 syncmlValues = rootNode.getNodeValues(DM_VALUE_PATH ); 155 xmlContactValues = rootNode.getNodeValues(DM_VALUE_CONTACT_PATH ); 156 xmlCalendarValues = rootNode.getNodeValues(DM_VALUE_CALENDAR_PATH); 157 xmlNoteValues = rootNode.getNodeValues(DM_VALUE_NOTE_PATH ); 158 159 String logLevel = (String )syncmlValues.get(PARAM_LOGLEVEL); 163 if(logLevel.equals(LOG_INFO)) { 164 Logger.setLevel(Logger.INFO); 165 } else if(logLevel.equals(LOG_DEBUG)) { 166 Logger.setLevel(Logger.DEBUG); 167 } 168 Logger.setDefaultLogFile(); 169 170 } catch (DMException e) { 171 if (Logger.isLoggable(Logger.ERROR)) { 172 Logger.error(Language.getMessage(Language.ERROR_NOT_FOUNT_DM_VALUES)); 173 Logger.error(e.getMessage()); 174 } 175 } 176 } 177 178 181 public void createAndShowMainGUI() { 182 try { 183 UIManager.setLookAndFeel(lookAndFeel); 184 } catch(Exception e) { 185 e.printStackTrace(); 186 } 187 188 getContentPane().setLayout(new BorderLayout(1,1)); 192 setTitle(Language.getMessage(Language.LABEL_TITLE_MAINWINDOW)); 193 setIconImage(Toolkit.getDefaultToolkit().getImage(FRAME_ICONNAME)); 194 setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); 195 setSize(280,362); 196 setLocationRelativeTo(null); 197 setResizable(false); 198 getContentPane().setBackground(new Color(236,233,216)); 199 200 JPanel mainPanel = new JPanel(null); 201 mainPanel.setBackground(Color.WHITE); 202 getContentPane().add(mainPanel, BorderLayout.CENTER); 203 204 JLabel lab = new JLabel(new ImageIcon(FRAME_LOGONAME)); 205 lab.setBounds(47,22,185,70); 206 mainPanel.add(lab); 207 208 JLabel lab1 = new JLabel(new ImageIcon(FRAME_ARROWSNAME)); 209 lab1.setBounds(96,110,88,77); 210 mainPanel.add(lab1); 211 212 btSync = new JButton(Language.getMessage(Language.BT_SYNC)); 213 btSync.setFont(new Font("Microsoft Sans Serif", 0, 13)); 214 btSync.setBounds(84,228,112,24); 215 btSync.setBackground(Color.WHITE); 216 btSync.addActionListener(this); 217 218 mainPanel.add(btSync); 219 220 mainPanel.setBorder(BorderFactory.createRaisedBevelBorder()); 221 222 jlStatus = new JLabel(); 226 jlStatus.setFont(font); 227 jlStatus.setPreferredSize(new Dimension(260, 25)); 228 getContentPane().add(jlStatus, BorderLayout.SOUTH); 229 230 setJMenuBar(new MenuBar(this)); 231 } 232 233 236 public void actionPerformed(ActionEvent e) { 237 if (checkSyncSettings()) { 238 runSynchronization(); 239 } else { 240 setStatusMessage(Language.getMessage(Language.STATUS_NOT_SYNC_REQUIRED)); 241 } 242 } 243 244 249 private boolean checkSyncSettings() { 250 String contactSM = (String )xmlContactValues.get(PARAM_SYNCMODE); 251 String calendarSM = (String )xmlCalendarValues.get(PARAM_SYNCMODE); 252 253 if (contactSM.equalsIgnoreCase(SYNC_NONE) && 254 calendarSM.equalsIgnoreCase(SYNC_NONE) ) { 255 return false; 256 } 257 return true; 258 } 259 260 public void runSynchronization() { 261 File f = null; 262 if ((f = getFileLog()) != null) { 263 f.delete(); 264 } 265 setCursor(new Cursor(Cursor.WAIT_CURSOR)); 266 setStatusMessage(Language.getMessage(Language.STATUS_SYNC_BEGIN)); 267 268 new Thread (new Runnable () { 269 public void run() { 270 synchronize(); 271 } 272 }).start(); 273 } 274 275 278 private void synchronize() { 279 try { 280 281 SyncManager syncManager = SyncManager.getSyncManager(""); 282 283 syncManager.addSyncItemListener (this); 284 syncManager.addSyncListener (this); 285 syncManager.addSyncSourceListener (this); 286 syncManager.addSyncStatusListener (this); 287 syncManager.addSyncTransportListener(this); 288 289 syncManager.sync(); 290 291 } catch (AuthenticationException e) { 292 setStatusMessage(Language.getMessage(Language.ERROR_AUTH)); 293 } catch (UpdateException e) { 294 setStatusMessage(Language.getMessage(Language.ERROR_SERVER_GENERIC)); 295 } catch (Exception e) { 296 setStatusMessage(Language.getMessage(Language.ERROR_CONNECT)); 297 } 298 299 if (syncError) { 300 setStatusMessage(Language.getMessage(Language.ERROR_SYNC)); 301 } 302 303 setCursor(new Cursor(Cursor.DEFAULT_CURSOR)); 304 } 305 306 311 private void setStatusMessage(String msg) { 312 jlStatus.setText(msg); 313 jlStatus.setAutoscrolls(true); 314 jlStatus.setHorizontalAlignment(SwingConstants.CENTER); 315 } 316 317 323 public void writeSyncSettings(Hashtable values) { 324 325 try { 326 xmlContactValues.put(PARAM_SYNCSOURCEDRIVE, values.get(PARAM_SYNCSOURCEDRIVE)); 327 xmlContactValues.put(PARAM_SYNCMODE, values.get(PARAM_SYNCCONTACT)); 328 329 xmlCalendarValues.put(PARAM_SYNCSOURCEDRIVE, values.get(PARAM_SYNCSOURCEDRIVE)); 330 xmlCalendarValues.put(PARAM_SYNCMODE, values.get(PARAM_SYNCCALENDAR)); 331 332 xmlNoteValues.put(PARAM_SYNCSOURCEDRIVE, values.get(PARAM_SYNCSOURCEDRIVE)); 333 xmlNoteValues.put(PARAM_SYNCMODE, values.get(PARAM_SYNCNOTE)); 334 335 syncmlValues.put (PARAM_LOGLEVEL,values.get(PARAM_LOGLEVEL)); 339 rootNode.setValue(DM_VALUE_PATH, PARAM_LOGLEVEL, values.get(PARAM_LOGLEVEL)); 340 341 rootNode.setValue(DM_VALUE_CONTACT_PATH, 345 PARAM_SYNCSOURCEDRIVE, 346 values.get(PARAM_SYNCSOURCEDRIVE) 347 ); 348 rootNode.setValue(DM_VALUE_CALENDAR_PATH, 349 PARAM_SYNCSOURCEDRIVE , 350 values.get(PARAM_SYNCSOURCEDRIVE) 351 ); 352 rootNode.setValue(DM_VALUE_NOTE_PATH , 353 PARAM_SYNCSOURCEDRIVE, 354 values.get(PARAM_SYNCSOURCEDRIVE) 355 ); 356 357 rootNode.setValue(DM_VALUE_CONTACT_PATH, 361 PARAM_SYNCMODE , 362 values.get(PARAM_SYNCCONTACT) 363 ); 364 rootNode.setValue(DM_VALUE_CALENDAR_PATH, 365 PARAM_SYNCMODE , 366 values.get(PARAM_SYNCCALENDAR) 367 ); 368 rootNode.setValue(DM_VALUE_NOTE_PATH, 369 PARAM_SYNCMODE , 370 values.get(PARAM_SYNCNOTE) 371 ); 372 373 } catch (DMException e) { 374 if (Logger.isLoggable(Logger.ERROR)) { 375 Logger.error(Language.getMessage(Language.ERROR_DEVICE_MANAGER)); 376 Logger.error(e.getMessage()); 377 } 378 } catch (Exception e) { 379 if (Logger.isLoggable(Logger.ERROR)) { 380 Logger.error(Language.getMessage(Language.ERROR_WRITE_SYNCSET)); 381 Logger.error(e.getMessage()); 382 } 383 } 384 } 385 386 392 public void writeRemoteSettings(Hashtable values) { 393 394 try { 395 xmlContactValues.put(PARAM_SYNCSOURCEURI, values.get(PARAM_SOURCEURICONTACT)); 396 xmlCalendarValues.put(PARAM_SYNCSOURCEURI,values.get(PARAM_SOURCEURICALENDAR)); 397 xmlNoteValues.put(PARAM_SYNCSOURCEURI,values.get(PARAM_SOURCEURINOTE)); 398 399 rootNode.setValue(DM_VALUE_CONTACT_PATH , 400 PARAM_SYNCSOURCEURI , 401 values.get(PARAM_SOURCEURICONTACT) 402 ); 403 rootNode.setValue(DM_VALUE_CALENDAR_PATH , 404 PARAM_SYNCSOURCEURI , 405 values.get(PARAM_SOURCEURICALENDAR) 406 ); 407 rootNode.setValue(DM_VALUE_NOTE_PATH , 408 PARAM_SYNCSOURCEURI , 409 values.get(PARAM_SOURCEURINOTE) 410 ); 411 } catch (DMException e) { 412 if (Logger.isLoggable(Logger.ERROR)) { 413 Logger.error(Language.getMessage(Language.ERROR_DEVICE_MANAGER)); 414 Logger.error(e.getMessage()); 415 } 416 } catch (Exception e) { 417 if (Logger.isLoggable(Logger.ERROR)) { 418 Logger.error(Language.getMessage(Language.ERROR_WRITE_REMOTESET)); 419 Logger.error(e.getMessage()); 420 } 421 } 422 } 423 424 430 public void writeCommunicationSettings(Hashtable values) { 431 try { 432 syncmlValues.put(PARAM_SYNCMLURL, values.get(PARAM_SYNCMLURL)); 433 syncmlValues.put(PARAM_USERNAME , values.get(PARAM_USERNAME) ); 434 syncmlValues.put(PARAM_PASSWORD , values.get(PARAM_PASSWORD) ); 435 syncmlValues.put(PARAM_DEVICEID , values.get(PARAM_DEVICEID) ); 436 437 rootNode.setValue(DM_VALUE_PATH , 438 PARAM_TARGETLOCALURI , 439 getBaseURL((String ) values.get(PARAM_SYNCMLURL)) 440 ); 441 rootNode.setValue(DM_VALUE_PATH , 442 PARAM_SYNCMLURL , 443 values.get(PARAM_SYNCMLURL) 444 ) ; 445 rootNode.setValue(DM_VALUE_PATH , 446 PARAM_USERNAME , 447 values.get(PARAM_USERNAME) 448 ); 449 rootNode.setValue(DM_VALUE_PATH , 450 PARAM_PASSWORD , 451 values.get(PARAM_PASSWORD) 452 ); 453 rootNode.setValue(DM_VALUE_PATH , 454 PARAM_DEVICEID , 455 values.get(PARAM_DEVICEID) 456 ); 457 458 } catch (DMException e) { 459 if (Logger.isLoggable(Logger.ERROR)) { 460 Logger.error(Language.getMessage(Language.ERROR_DEVICE_MANAGER)); 461 Logger.error(e.getMessage()); 462 } 463 } catch (Exception e) { 464 if (Logger.isLoggable(Logger.ERROR)) { 465 Logger.error(Language.getMessage(Language.ERROR_WRITE_COMMUNICATIONSET)); 466 Logger.error(e.getMessage()); 467 } 468 } 469 } 470 471 public Hashtable getXmlContactValues() { 472 return this.xmlContactValues; 473 } 474 475 public Hashtable getXmlCalendarValues() { 476 return this.xmlCalendarValues; 477 } 478 479 public Hashtable getXmlNoteValues() { 480 return this.xmlNoteValues; 481 } 482 483 public Hashtable getSyncmlValues() { 484 return this.syncmlValues; 485 } 486 487 public File getFileLog() { 488 File f = new File (rootDirectory + File.separator + "sync.log"); 489 if (f.exists()) { 490 return f; 491 } 492 return null; 493 } 494 495 498 public void exit() { 499 setVisible(false); 500 dispose(); 501 502 if (Logger.isLoggable(Logger.INFO)) { 503 Logger.info(Language.getMessage(Language.LOGGING_STOPPED)); 504 } 505 System.exit(0); 506 } 507 508 513 public void syncBegin(SyncEvent syncEvent) { 514 syncError = false; 515 if (Logger.isLoggable(Logger.INFO)) { 516 Logger.info(syncEvent.getDate() + ", " + 517 Language.getMessage(Language.LOG_SYNC_BEGIN) 518 ); 519 } 520 } 521 522 527 public void syncEnd(SyncEvent syncEvent) { 528 if (Logger.isLoggable(Logger.INFO)) { 529 Logger.info(syncEvent.getDate() + ", " + 530 Language.getMessage(Language.LOG_SYNC_END) 531 ); 532 } 533 setStatusMessage(Language.getMessage(Language.STATUS_SYNC_END)); 534 } 535 536 541 public void syncError(SyncEvent syncEvent) { 542 syncError = true; 543 if (Logger.isLoggable(Logger.DEBUG)) { 544 Logger.debug(syncEvent.getDate() + ", " 545 + Language.getMessage(Language.LOG_SYNC_ERROR) 546 + " - " + Language.getMessage(Language.LOG_SYNCERROR_MSG) 547 + " " + syncEvent.getMessage() 548 + " - " + Language.getMessage(Language.LOG_SYNCCAUSE_MSG) 549 + " " + syncEvent.getCause().getMessage() 550 ); 551 } 552 } 553 554 560 public void sendInitialization(SyncEvent syncEvent) { 561 if (Logger.isLoggable(Logger.DEBUG)) { 562 Logger.debug(syncEvent.getDate() + ", " + 563 Language.getMessage(Language.LOG_SYNC_SENDINIT) 564 ); 565 } 566 } 567 568 574 public void sendModification(SyncEvent syncEvent) { 575 if (Logger.isLoggable(Logger.DEBUG)) { 576 Logger.debug(syncEvent.getDate() + ", " + 577 Language.getMessage(Language.LOG_SYNC_SENDMOD) 578 ); 579 } 580 } 581 582 587 public void sendFinalization(SyncEvent syncEvent) { 588 if (Logger.isLoggable(Logger.DEBUG)) { 589 Logger.debug(syncEvent.getDate() + ", " + 590 Language.getMessage(Language.LOG_SYNC_SENDFINAL) 591 ); 592 } 593 } 594 595 600 public void sendDataBegin(SyncTransportEvent syncTransportEvent) { 601 if (Logger.isLoggable(Logger.DEBUG)) { 602 Logger.debug(Language.getMessage(Language.LOG_SYNCTRANSPORT_SENDDATABEGIN) 603 + " " + syncTransportEvent.getData() 604 ); 605 } 606 } 607 608 613 public void sendDataEnd(SyncTransportEvent syncTransportEvent) { 614 if (Logger.isLoggable(Logger.DEBUG)) { 615 Logger.debug(Language.getMessage(Language.LOG_SYNCTRANSPORT_SENDDATAEND) 616 + " " + syncTransportEvent.getData() 617 ); 618 } 619 } 620 621 626 public void receiveDataBegin(SyncTransportEvent syncTransportEvent) { 627 if (Logger.isLoggable(Logger.DEBUG)) { 628 Logger.debug(Language.getMessage(Language.LOG_SYNCTRANSPORT_RECEIVEDATABEGIN) 629 + " " + syncTransportEvent.getData() 630 ); 631 } 632 } 633 634 639 public void dataReceived(SyncTransportEvent syncTransportEvent) { 640 if (Logger.isLoggable(Logger.DEBUG)) { 641 Logger.debug(Language.getMessage(Language.LOG_SYNCTRANSPORT_RECEIVEDATA) 642 + " " + syncTransportEvent.getData() 643 ); 644 } 645 } 646 647 652 public void receiveDataEnd(SyncTransportEvent syncTransportEvent) { 653 if (Logger.isLoggable(Logger.DEBUG)) { 654 Logger.debug(Language.getMessage(Language.LOG_SYNCTRANSPORT_RECEIVEDATAEND) 655 + " " + syncTransportEvent.getData() 656 ); 657 } 658 } 659 660 665 public void syncBegin(SyncSourceEvent syncSourceEvent) { 666 if (Logger.isLoggable(Logger.DEBUG)) { 667 Logger.debug(syncSourceEvent.getDate() + ", " 668 + Language.getMessage(Language.LOG_SYNCSOURCE_BEGIN) 669 + " - " 670 + Language.getMessage(Language.LOG_SYNCSOURCE_SOURCEURI) 671 + " " + syncSourceEvent.getSourceUri() 672 + " - " 673 + Language.getMessage(Language.LOG_SYNCSOURCE_SYNCMODE) 674 + " " + syncSourceEvent.getSyncMode() 675 ); 676 } 677 } 678 679 684 public void syncEnd(SyncSourceEvent syncSourceEvent) { 685 if (Logger.isLoggable(Logger.DEBUG)) { 686 Logger.debug(syncSourceEvent.getDate() + ", " 687 + Language.getMessage(Language.LOG_SYNCSOURCE_END) 688 + " - " 689 + Language.getMessage(Language.LOG_SYNCSOURCE_SOURCEURI) 690 + " " + syncSourceEvent.getSourceUri() 691 + " - " 692 + Language.getMessage(Language.LOG_SYNCSOURCE_SYNCMODE) 693 + " " + syncSourceEvent.getSyncMode() 694 ); 695 } 696 } 697 698 703 public void itemAddedByServer(SyncItemEvent syncItemEvent) { 704 if (Logger.isLoggable(Logger.DEBUG)) { 705 Logger.debug(Language.getMessage(Language.LOG_SYNCITEM_ADDSERVER) 706 + " - " 707 + Language.getMessage(Language.LOG_SYNCSOURCE_SOURCEURI) 708 + " " + syncItemEvent.getSourceUri() 709 + " - " + Language.getMessage(Language.LOG_SYNCITEM_KEY) 710 + " " + syncItemEvent.getItemKey().getKeyAsString() 711 ); 712 } 713 } 714 715 720 public void itemDeletedByServer(SyncItemEvent syncItemEvent) { 721 if (Logger.isLoggable(Logger.DEBUG)) { 722 Logger.debug(Language.getMessage(Language.LOG_SYNCITEM_DELETESERVER) 723 + " - " 724 + Language.getMessage(Language.LOG_SYNCSOURCE_SOURCEURI) 725 + " " + syncItemEvent.getSourceUri() 726 + " - " 727 + Language.getMessage(Language.LOG_SYNCITEM_KEY) 728 + " " + syncItemEvent.getItemKey().getKeyAsString() 729 ); 730 } 731 } 732 733 738 public void itemUpdatedByServer(SyncItemEvent syncItemEvent) { 739 if (Logger.isLoggable(Logger.DEBUG)) { 740 Logger.debug(Language.getMessage(Language.LOG_SYNCITEM_UPDATESERVER) 741 + " - " 742 + Language.getMessage(Language.LOG_SYNCSOURCE_SOURCEURI) 743 + " " + syncItemEvent.getSourceUri() 744 + " - " + Language.getMessage(Language.LOG_SYNCITEM_KEY) 745 + " " + syncItemEvent.getItemKey().getKeyAsString() 746 ); 747 } 748 } 749 750 755 public void itemAddedByClient(SyncItemEvent syncItemEvent) { 756 if (Logger.isLoggable(Logger.DEBUG)) { 757 Logger.debug(Language.getMessage(Language.LOG_SYNCITEM_ADDCLIENT) 758 + " - " 759 + Language.getMessage(Language.LOG_SYNCSOURCE_SOURCEURI) 760 + " " + syncItemEvent.getSourceUri() 761 + " - " + Language.getMessage(Language.LOG_SYNCITEM_KEY) 762 + " " + syncItemEvent.getItemKey().getKeyAsString() 763 ); 764 } 765 } 766 767 772 public void itemDeletedByClient(SyncItemEvent syncItemEvent) { 773 if (Logger.isLoggable(Logger.DEBUG)) { 774 Logger.debug(Language.getMessage(Language.LOG_SYNCITEM_DELETECLIENT) 775 + " - " 776 + Language.getMessage(Language.LOG_SYNCSOURCE_SOURCEURI) 777 + " " + syncItemEvent.getSourceUri() 778 + " - " + Language.getMessage(Language.LOG_SYNCITEM_KEY) 779 + " " + syncItemEvent.getItemKey().getKeyAsString() 780 ); 781 } 782 } 783 784 789 public void itemUpdatedByClient(SyncItemEvent syncItemEvent) { 790 if (Logger.isLoggable(Logger.DEBUG)) { 791 Logger.debug(Language.getMessage(Language.LOG_SYNCITEM_UPDATECLIENT) 792 + " - " 793 + Language.getMessage(Language.LOG_SYNCSOURCE_SOURCEURI) 794 + " " + syncItemEvent.getSourceUri() 795 + " - " + Language.getMessage(Language.LOG_SYNCITEM_KEY) 796 + " " + syncItemEvent.getItemKey().getKeyAsString() 797 ); 798 } 799 } 800 801 806 public void statusToSend(SyncStatusEvent syncStatusEvent) { 807 if (Logger.isLoggable(Logger.DEBUG)) { 808 Logger.debug(Language.getMessage(Language.LOG_SYNCSTATUS_SEND) 809 + " - " + Language.getMessage(Language.LOG_SYNCSTATUS_CMD) 810 + " " + syncStatusEvent.getCommand() 811 + " - " + Language.getMessage(Language.LOG_SYNCSTATUS_STATUS) 812 + " " + syncStatusEvent.getStatusCode() 813 + " - " 814 + Language.getMessage(Language.LOG_SYNCSOURCE_SOURCEURI) 815 + " " + syncStatusEvent.getSourceUri() 816 + " - " + Language.getMessage(Language.LOG_SYNCITEM_KEY) 817 + " " + syncStatusEvent.getItemKey().getKeyAsString() 818 ); 819 } 820 } 821 822 827 public void statusReceived(SyncStatusEvent syncStatusEvent) { 828 if (Logger.isLoggable(Logger.DEBUG)) { 829 Logger.debug(Language.getMessage(Language.LOG_SYNCSTATUS_RECEIVED) 830 + " - " + Language.getMessage(Language.LOG_SYNCSTATUS_CMD) 831 + " " + syncStatusEvent.getCommand() 832 + " - " + Language.getMessage(Language.LOG_SYNCSTATUS_STATUS) 833 + " " + syncStatusEvent.getStatusCode() 834 + " - " 835 + Language.getMessage(Language.LOG_SYNCSOURCE_SOURCEURI) 836 + " " + syncStatusEvent.getSourceUri() 837 + " - " + Language.getMessage(Language.LOG_SYNCITEM_KEY) 838 + " " + syncStatusEvent.getItemKey().getKeyAsString() 839 ); 840 } 841 } 842 843 845 853 private String buildPath(String sourceDirectory, String dir) { 854 return sourceDirectory+"/"+dir; 855 } 856 857 private String getBaseURL (String url) { 858 859 int firstSlash = url.indexOf("/" ) ; 860 int secondSlash = url.indexOf("/", firstSlash + 1 ) ; 861 int thirdSlash = url.indexOf("/", secondSlash + 1 ) ; 862 int portColon = url.indexOf(":", secondSlash + 1 ) ; 863 864 if (thirdSlash < portColon || portColon == -1) { 865 866 return url.substring(0, thirdSlash); 870 } else { 871 return url.substring(0, portColon); 876 } 877 } 878 } 879 | Popular Tags |