1 29 38 39 package org.planetamessenger.mos.engine; 40 41 import org.planetamessenger.mos.forms.*; 42 import org.planetamessenger.mos.ui.*; 43 import org.planetamessenger.plugin.*; 44 import org.planetamessenger.db.*; 45 import org.planetamessenger.util.*; 46 import java.sql.Connection ; 47 import java.sql.PreparedStatement ; 48 import java.sql.ResultSet ; 49 import java.sql.SQLException ; 50 import java.util.*; 51 52 53 54 public class JContactListManager implements JContactListListener { 55 56 JMOSWindow parent = null; 57 58 59 63 public JContactListManager() { 64 65 parent = JSharedObjects.getMainWindow(); 66 } 67 68 76 public synchronized boolean saveMessage( org.planetamessenger.plugin.JPlugin sender, java.lang.String strFromUserId, int nMessageStatus, java.lang.String strMsg ) { 77 78 strFromUserId = strFromUserId.toLowerCase(); 79 80 JContactList contactList = parent.getContactList(); 81 JMOSSendMessageDlg messageDlg = JSharedObjects.getPluginEngine().getMessageWindow( sender.getPluginProperties().getPluginId() ); 82 long nProfileId = JSharedObjects.getProfileManager().getProfileId(); 83 JContactListItem item; 84 85 86 synchronized( contactList ) { 87 item = contactList.getItem( sender.getPluginProperties().getPluginId(), strFromUserId ); 88 } 89 90 String strMsgHtml = JTextUtil.encodeHtml( strMsg ); 92 93 98 if( item == null ) { 99 100 int nRet; 101 102 addToContactList( sender, strFromUserId, strFromUserId, true ); 103 synchronized( contactList ) { 104 item = contactList.getItem( sender.getPluginProperties().getPluginId(), strFromUserId ); 105 } 106 nRet = javax.swing.JOptionPane.showConfirmDialog( null, JSharedObjects.getLanguageManager().getStringEx( "DO_YOU_WANT_ADD_USER" ) + " " + item.getUserId() + " " + JSharedObjects.getLanguageManager().getStringEx( "TO_CONTACT_LIST" ), JSharedObjects.getLanguageManager().getStringEx( "ADD_TO_CONTACT_LIST" ), javax.swing.JOptionPane.YES_NO_OPTION, javax.swing.JOptionPane.QUESTION_MESSAGE ); 107 108 if( nRet == javax.swing.JOptionPane.YES_OPTION ) { 109 JExtendedPopupWindow popupWindow = new JExtendedPopupWindow( sender.getPluginProperties().getName(), JSharedObjects.getLanguageManager().getStringEx( "THE_USER" ) + " " + item.getNickName() + " " + JSharedObjects.getLanguageManager().getStringEx( "WAS_ADDED_TO_YOUR_CONTACT_LIST" ), null ); 111 112 item.setContactFlag( JContactListItem.CONTACT_IN_LIST ); 113 updateContactInfo( item ); 114 115 ( ( JPlugin ) JSharedObjects.getPluginEngine().get( sender.getPluginProperties().getPluginId() ) ).fireOnAddUserToContactList( strFromUserId ); 116 popupWindow.showPopup(); 117 } 118 } 119 120 if( messageDlg.contains( item ) ) { 121 122 if( !messageDlg.isItemActive( item ) ) 123 messageDlg.newTab( item ); 124 125 strMsgHtml = "<b>" + item.getNickName() + ": </b>" + strMsgHtml; 126 messageDlg.setMessage( item, strMsgHtml ); 127 return false; 128 } 129 else { 130 String strPopupMessage = item.getNickName() + " " + JSharedObjects.getLanguageManager().getStringEx( "SAYS" ) + " : " + strMsg; 131 JExtendedPopupWindow popupWindow = new JExtendedPopupWindow( sender.getPluginProperties().getName(), strPopupMessage, null ); 132 Connection conn = null; 133 PreparedStatement st = null; 134 135 136 popupWindow.showPopup(); 137 setItemStatus( sender, strFromUserId, nMessageStatus ); 138 139 try{ 140 conn = JSharedObjects.getDatabase().getConnection(); 141 st = conn.prepareStatement( "INSERT INTO messages (profile_id, plugin_id, user_id, msg_type, msg_datetime, message) VALUES(?, ?, ?, ?, NOW(), ?)" ); 142 st.setLong( 1, nProfileId ); 143 st.setInt( 2, sender.getPluginProperties().getPluginId() ); 144 st.setString( 3, strFromUserId ); 145 st.setInt( 4, nMessageStatus ); 146 st.setString( 5, strMsg ); 147 148 st.executeUpdate(); 149 }catch( SQLException e ) { 150 System.err.println( "JContactListManager.saveMessage() - " + e ); 151 } finally{ 152 if( st != null ) 153 try { 154 st.close(); 155 } catch( SQLException e ) { 156 System.err.println( "JContactListManager.saveMessage() - " + e ); 157 } 158 } 159 } 160 161 return true; 162 } 163 164 171 public void setItemStatus( org.planetamessenger.plugin.JPlugin plugin, String strItemId, int nNewStatus ) { 172 173 JContactListItem item; 174 JContactList contactList = parent.getContactList(); 175 176 177 synchronized( contactList ) { 178 item = contactList.getItem( plugin.getPluginProperties().getPluginId(), strItemId.toLowerCase() ); 179 } 180 181 if( item == null ) { 182 System.err.println( "JContactListManager.setItemStatus() - Item not in list. Nothing to do." ); 183 return; 184 } 185 186 if( ( nNewStatus > JPlugin.STATUS_OFFLINE ) && ( nNewStatus != JPlugin.STATUS_MESSAGE ) && ( item.getStatus() == JPlugin.STATUS_OFFLINE ) ) { 188 JExtendedPopupWindow popupWindow = new JExtendedPopupWindow( plugin.getPluginProperties().getName(), " " + item.getNickName() + " " + JSharedObjects.getLanguageManager().getStringEx( "IS" ) + " " + JSharedObjects.getLanguageManager().getStringEx( "ONLINE" ), null ); 189 popupWindow.showPopup(); 190 } 191 192 synchronized( contactList ) { 193 contactList.setItemStatus( item, nNewStatus ); 194 } 195 } 196 197 204 public void setAllItemsStatus( org.planetamessenger.plugin.JPlugin plugin, int nNewStatus ) { 205 206 JContactList contactList = parent.getContactList(); 207 208 synchronized( contactList ) { 209 contactList.setAllItemsStatus( plugin.getPluginProperties().getPluginId(), nNewStatus ); 210 } 211 } 212 213 218 public void removeAllUIItems( org.planetamessenger.plugin.JPlugin plugin ) { 219 220 JContactList contactList = parent.getContactList(); 221 222 synchronized( contactList ) { 223 contactList.removePluginItems( plugin.getPluginProperties().getPluginId() ); 224 } 225 } 226 227 235 boolean addToContactList( org.planetamessenger.plugin.JPlugin plugin, String strNick, String strUserId, boolean bNotInListUser ) { 236 237 Connection conn = null; 238 PreparedStatement st = null; 239 JContactListItem item = null; 240 JContactList contactList = JSharedObjects.getMainWindow().getContactList(); 241 long nProfileId = JSharedObjects.getProfileManager().getProfileId(); 242 int nPluginId = plugin.getPluginProperties().getPluginId(); 243 int nContactFlag = ( bNotInListUser ? JContactListItem.CONTACT_NOT_IN_LIST : JContactListItem.CONTACT_IN_LIST ); 244 245 246 strUserId = strUserId.toLowerCase(); 247 248 synchronized( contactList ) { 249 item = contactList.getItem( nPluginId, strUserId ); 250 } 251 252 if( item == null ) { item = new JContactListItem( plugin.getPluginProperties().getPluginId(), strUserId, strNick ); 254 255 try { 256 conn = JSharedObjects.getDatabase().getConnection(); 257 st = conn.prepareStatement( "INSERT INTO contact_list (profile_id, plugin_id, user_id, nick_name, visible, blocked, contact_flag) VALUES(?,?,?,?,0,0,?)" ); 258 st.setLong( 1, nProfileId ); 259 st.setInt( 2, nPluginId ); 260 st.setString( 3, strUserId ); 261 st.setString( 4, strNick ); 262 st.setInt( 5, nContactFlag ); 263 st.executeUpdate(); 264 } catch( SQLException e ) { 265 System.err.println( "JContactListManager.addToContactList() - " + e ); 266 } finally{ 267 if( st != null ) 268 try { 269 st.close(); 270 } catch( SQLException e ) { 271 System.err.println( "JContactListManager.addToContactList() - " + e ); 272 } 273 } 274 } 275 276 if( !bNotInListUser ) { 277 item.setContactFlag( JContactListItem.CONTACT_IN_LIST ); 278 item.setStatus( JPlugin.STATUS_OFFLINE ); 279 } 280 else { 281 item.setStatus( JPlugin.STATUS_NOT_IN_LIST ); 282 item.setContactFlag( JContactListItem.CONTACT_NOT_IN_LIST ); 283 } 284 285 updateContactInfo( item ); 286 287 synchronized( contactList ) { 288 contactList.addItem( item ); 289 } 290 291 294 if( !bNotInListUser ) 295 ( ( JPlugin ) JSharedObjects.getPluginEngine().get( item.getPluginId() ) ).fireOnRequestAuthorization( strUserId, strNick ); 296 297 return true; 298 } 299 300 308 public synchronized boolean addToContactList( org.planetamessenger.plugin.JPlugin plugin, String strNick, String strUserId ) { 309 310 return addToContactList( plugin, strNick, strUserId, false ); 311 } 312 313 320 public synchronized boolean removeFromContactList( org.planetamessenger.plugin.JPlugin plugin, String strUserId ) { 321 322 JContactList contactList = JSharedObjects.getMainWindow().getContactList(); 323 JContactListItem item = new JContactListItem( plugin.getPluginProperties().getPluginId(), strUserId.toLowerCase(), "" ); 324 long nPluginId = plugin.getPluginProperties().getPluginId(); 325 long nProfileId = JSharedObjects.getProfileManager().getProfileId(); 326 327 328 synchronized( contactList ) { 330 contactList.removeItem( item ); 331 } 332 333 JSharedObjects.getDatabase().execUpdate( "DELETE FROM messages WHERE profile_id=" + nProfileId + " AND plugin_id=" + nPluginId + " AND LCASE(user_id)='" + item.getUserId() + "'" ); 335 JSharedObjects.getDatabase().execUpdate( "DELETE FROM contact_list WHERE profile_id=" + nProfileId + " AND plugin_id=" + nPluginId + " AND LCASE(user_id)='" + item.getUserId() + "'" ); 336 337 return true; 338 } 339 340 346 public synchronized boolean updateScreenName( org.planetamessenger.plugin.JPlugin plugin, java.lang.String strUserId, java.lang.String strNewNick ) { 347 348 JContactList contactList = parent.getContactList(); 349 JContactListItem item; 350 351 352 synchronized( contactList ) { 353 item = contactList.getItem( plugin.getPluginProperties().getPluginId(), strUserId.toLowerCase() ); 354 } 355 356 if( item != null ) { 358 int nPluginId = plugin.getPluginProperties().getPluginId(); 359 long nProfileId = JSharedObjects.getProfileManager().getProfileId(); 360 Connection conn = JSharedObjects.getDatabase().getConnection(); 361 PreparedStatement st = null; 362 363 try { 364 item.setNickName( strNewNick ); 365 366 st = conn.prepareStatement( "UPDATE contact_list SET nick_name= ? WHERE profile_id= ? AND plugin_id= ? AND user_id= ?" ); 367 st.setString( 1, strNewNick ); 368 st.setLong( 2, nProfileId ); 369 st.setInt( 3, nPluginId ); 370 st.setString( 4, item.getUserId() ); 371 st.executeUpdate(); 372 373 synchronized( contactList ) { 374 ( ( JContactListModel ) contactList.getModel() ).update(); 375 } 376 377 } catch( java.sql.SQLException e ) { 378 System.out.println( "JContactListManager.updateScreenName() - SQLException " + e ); 379 return false; 380 } finally { 381 if( st != null ) 382 try { 383 st.close(); 384 } catch( SQLException e ) { 385 System.err.println( "JContactListManager.updateScreenName() - " + e ); 386 } 387 } 388 } 389 390 return true; 391 } 392 393 399 public synchronized boolean updatePrivacy( JContactListItem contactItem ) { 400 401 JContactList contactList = parent.getContactList(); 402 long nProfileId = JSharedObjects.getProfileManager().getProfileId(); 403 Connection conn = JSharedObjects.getDatabase().getConnection(); 404 PreparedStatement st = null; 405 JContactListItem item; 406 407 408 try { 409 410 synchronized( contactList ) { 411 item = contactList.getItem( contactItem.getPluginId(), contactItem.getUserId().toLowerCase() ); 412 } 413 414 if( item != null ) 416 item.copy( contactItem ); 417 418 st = conn.prepareStatement( "UPDATE contact_list SET visible= ? , blocked= ? WHERE profile_id= ? AND plugin_id= ? AND LCASE(user_id)= ? " ); 419 st.setInt( 1, ( contactItem.getVisible() ? 1 : 0 ) ); 420 st.setInt( 2, ( contactItem.getBlocked() ? 1 : 0 ) ); 421 st.setLong( 3, nProfileId ); 422 st.setInt( 4, contactItem.getPluginId() ); 423 st.setString( 5, contactItem.getUserId().toLowerCase() ); 424 425 st.executeUpdate(); 426 427 } catch( java.sql.SQLException e ) { 428 System.out.println( "JContactListManager.updatePrivacy() - SQLException " + e ); 429 return false; 430 } finally { 431 if( st != null ) 432 try { 433 st.close(); 434 } catch( SQLException e ) { 435 System.err.println( "JContactListManager.addToContactList() - " + e ); 436 } 437 } 438 439 return true; 440 } 441 442 446 public synchronized boolean updateContactInfo( JContactListItem contactItem ) { 447 448 PreparedStatement st = null; 449 Connection conn = JSharedObjects.getDatabase().getConnection(); 450 long nProfileId = JSharedObjects.getProfileManager().getProfileId(); 451 JContactList contactList = parent.getContactList(); 452 JContactListItem item; 453 String strQuery; 454 455 456 synchronized( contactList ) { 457 item = contactList.getItem( contactItem.getPluginId(), contactItem.getUserId().toLowerCase() ); 458 } 459 460 if( item != null ) 462 item.copy( contactItem ); 463 464 try { 465 strQuery = "UPDATE contact_list SET first_name= ? , last_name= ? , email= ? , notes= ?, gender= ? , age= ? , contact_flag= ? WHERE profile_id= ? AND plugin_id= ? AND LCASE(user_id)= ?"; 466 467 st = conn.prepareStatement( strQuery ); 468 469 st.setString( 1, contactItem.getFirstName() ); 470 st.setString( 2, contactItem.getLastName() ); 471 st.setString( 3, contactItem.getEmail() ); 472 st.setString( 4, contactItem.getNotes() ); 473 st.setInt( 5, contactItem.getGender() ); 474 st.setInt( 6, contactItem.getAge() ); 475 st.setInt( 7, contactItem.getContactFlag() ); 476 st.setLong( 8, nProfileId ); 477 st.setInt( 9, contactItem.getPluginId() ); 478 st.setString( 10, contactItem.getUserId().toLowerCase() ); 479 480 st.executeUpdate(); 481 482 } catch( java.sql.SQLException e ) { 483 System.out.println( "JContactListManager.updateContactInfo() - SQLException " + e ); 484 return false; 485 } finally { 486 if( st != null ) 487 try { 488 st.close(); 489 } catch( SQLException e ) { 490 System.err.println( "JContactListManager.updateContactInfo() - " + e ); 491 } 492 } 493 494 return true; 495 } 496 497 502 public synchronized Hashtable getContactList( org.planetamessenger.plugin.JPlugin plugin ) { 503 504 if( plugin != null ) { 505 long nProfileId = JSharedObjects.getProfileManager().getProfileId(); 506 Connection conn = JSharedObjects.getDatabase().getConnection(); 507 PreparedStatement st = null; 508 ResultSet resultSet = null; 509 510 511 try { 512 st = conn.prepareStatement( "SELECT * FROM contact_list WHERE profile_id = ? AND plugin_id = ? " ); 513 st.setLong( 1, nProfileId ); 514 st.setInt( 2, plugin.getPluginProperties().getPluginId() ); 515 516 resultSet = st.executeQuery(); 517 518 if( resultSet == null ) 519 return null; 520 521 Hashtable contactList = new Hashtable(); 522 JContactList contactListUI = parent.getContactList(); 523 524 while( resultSet.next() ) { 525 526 JContactListItem contactItem = new JContactListItem(); 527 JContactListItem contactItemUI = null; 528 529 contactItem.setUserId( resultSet.getString( "user_id" ).toLowerCase() ); 530 contactItem.setNickName( resultSet.getString( "nick_name" ) ); 531 contactItem.setFirstName( resultSet.getString( "first_name" ) ); 532 contactItem.setLastName( resultSet.getString( "last_name" ) ); 533 contactItem.setLastName( resultSet.getString( "last_name" ) ); 534 contactItem.setGender( resultSet.getInt( "gender" ) ); 535 contactItem.setEmail( resultSet.getString( "email" ) ); 536 contactItem.setAge( resultSet.getInt( "age" ) ); 537 contactItem.setGroupId( resultSet.getInt( "group_id" ) ); 538 contactItem.setPluginId( plugin.getPluginProperties().getPluginId() ); 539 contactItem.setNotes( resultSet.getString( "notes" ) ); 540 contactItem.setContactFlag( resultSet.getInt( "contact_flag" ) ); 541 542 synchronized( contactListUI ) { 543 contactItemUI = contactListUI.getItem( plugin.getPluginProperties().getPluginId(), contactItem.getUserId() ); 544 } 545 546 if( contactItemUI != null ) 548 contactItem.setStatus( contactItemUI.getStatus() ); 549 550 if( resultSet.getInt( "visible" ) == 0 ) 551 contactItem.setVisible( false ); 552 else 553 contactItem.setVisible( true ); 554 555 if( resultSet.getInt( "blocked" ) == 0 ) 556 contactItem.setBlocked( false ); 557 else 558 contactItem.setBlocked( true ); 559 560 contactList.put( contactItem.getUserId(), contactItem ); 561 } 562 563 resultSet.close(); 564 565 return contactList; 566 567 } catch( java.sql.SQLException e ) { 568 System.out.println( "JContactListManager.getContactList() - SQLException " + e ); 569 return null; 570 } finally { 571 if( resultSet != null ) 572 try { 573 resultSet.close(); 574 } catch( SQLException e ) { 575 System.err.println( "JContactListManager.getContactList()" + e ); 576 } 577 578 if( st != null ) 579 try { 580 st.close(); 581 } catch( SQLException e ) { 582 System.err.println( "JContactListManager.getContactList()" + e ); 583 } 584 } 585 } 586 else 587 return null; 588 } 589 590 596 public synchronized JContactListItem getContact( org.planetamessenger.plugin.JPlugin plugin, String strUserId ) { 597 598 if( plugin != null ) { 599 long nProfileId = JSharedObjects.getProfileManager().getProfileId(); 600 Connection conn = JSharedObjects.getDatabase().getConnection(); 601 PreparedStatement st = null; 602 ResultSet resultSet = null; 603 JContactListItem contactItem = null; 604 JContactList contactList = parent.getContactList(); 605 606 607 try { 608 st = conn.prepareStatement( "SELECT * FROM contact_list WHERE profile_id = ? AND plugin_id = ? AND user_id = ?" ); 609 st.setLong( 1, nProfileId ); 610 st.setInt( 2, plugin.getPluginProperties().getPluginId() ); 611 st.setString( 3, strUserId.toLowerCase() ); 612 613 resultSet = st.executeQuery(); 614 615 if( resultSet == null ) 616 return null; 617 618 if( resultSet.next() ) { 619 620 contactItem = new JContactListItem(); 621 JContactListItem contactItemUI = null; 622 623 contactItem.setUserId( resultSet.getString( "user_id" ).toLowerCase() ); 624 contactItem.setNickName( resultSet.getString( "nick_name" ) ); 625 contactItem.setFirstName( resultSet.getString( "first_name" ) ); 626 contactItem.setLastName( resultSet.getString( "last_name" ) ); 627 contactItem.setLastName( resultSet.getString( "last_name" ) ); 628 contactItem.setGender( resultSet.getInt( "gender" ) ); 629 contactItem.setEmail( resultSet.getString( "email" ) ); 630 contactItem.setAge( resultSet.getInt( "age" ) ); 631 contactItem.setGroupId( resultSet.getInt( "group_id" ) ); 632 contactItem.setPluginId( plugin.getPluginProperties().getPluginId() ); 633 contactItem.setNotes( resultSet.getString( "notes" ) ); 634 contactItem.setContactFlag( resultSet.getInt( "contact_flag" ) ); 635 636 synchronized( contactList ) { 637 contactItemUI = contactList.getItem( plugin.getPluginProperties().getPluginId(), contactItem.getUserId() ); 638 } 639 640 if( contactItemUI != null ) 642 contactItem.setStatus( contactItemUI.getStatus() ); 643 644 if( resultSet.getInt( "visible" ) == 0 ) 645 contactItem.setVisible( false ); 646 else 647 contactItem.setVisible( true ); 648 649 if( resultSet.getInt( "blocked" ) == 0 ) 650 contactItem.setBlocked( false ); 651 else 652 contactItem.setBlocked( true ); 653 654 } 655 656 resultSet.close(); 657 658 } catch( java.sql.SQLException e ) { 659 System.out.println( "JContactListManager.getContact() - SQLException " + e ); 660 return null; 661 } finally { 662 if( resultSet != null ) 663 try { 664 resultSet.close(); 665 } catch( SQLException e ) { 666 System.err.println( "JContactListManager.getContact()" + e ); 667 } 668 669 if( st != null ) 670 try { 671 st.close(); 672 } catch( SQLException e ) { 673 System.err.println( "JContactListManager.getContact()" + e ); 674 } 675 } 676 677 return contactItem; 678 } 679 680 return null; 681 } 682 683 688 public synchronized boolean isContact( JPlugin plugin, String strUserId ) { 689 690 long nProfileId = JSharedObjects.getProfileManager().getProfileId(); 691 Connection conn = JSharedObjects.getDatabase().getConnection(); 692 PreparedStatement st = null; 693 ResultSet resultSet = null; 694 int nRet = 0; 695 696 697 try { 698 st = conn.prepareStatement( "SELECT COUNT(*) AS count_contacts FROM contact_list WHERE profile_id = ? AND plugin_id = ? AND LCASE(user_id) = ?" ); 699 st.setLong( 1, nProfileId ); 700 st.setInt( 2, plugin.getPluginProperties().getPluginId() ); 701 st.setString( 3, strUserId.toLowerCase() ); 702 703 resultSet = st.executeQuery(); 704 705 if( resultSet == null ) 706 return false; 707 708 if( resultSet.next() ) 709 nRet = resultSet.getInt( "count_contacts" ); 710 711 resultSet.close(); 712 713 return ( nRet > 0 ? true : false ); 714 715 } catch( SQLException e ) { 716 System.err.println( "JContactListManager.isContact()" + e ); 717 } 718 719 return true; 720 } 721 722 725 public void updateUI() { 726 727 JContactList contactList = parent.getContactList(); 728 729 synchronized( contactList ) { 730 contactList.repaint(); 731 } 732 } 733 734 740 public synchronized void loadMessagesToContactList() { 741 742 long nProfileId = JSharedObjects.getProfileManager().getProfileId(); 743 JContactListItem item = new JContactListItem(); 744 Connection conn = null; 745 PreparedStatement st = null; 746 ResultSet resultSet = null; 747 JContactList contactList = parent.getContactList(); 748 749 try{ 750 conn = JSharedObjects.getDatabase().getConnection(); 751 st = conn.prepareStatement( "SELECT * FROM messages WHERE profile_id = ?" ); 752 st.setLong( 1, nProfileId ); 753 754 resultSet = st.executeQuery(); 755 756 int nCount = 0; 757 758 if( resultSet == null ) 759 return; 760 761 while( resultSet.next() ) { 762 item.setPluginId( resultSet.getInt( "plugin_id" ) ); 763 item.setUserId( resultSet.getString( "user_id" ).toLowerCase() ); 764 765 synchronized( contactList ) { 766 contactList.setItemStatus( item, resultSet.getInt( "msg_type" ) ); 767 } 768 769 nCount++; 770 } 771 772 if( nCount > 0 ) { 774 JExtendedPopupWindow popupWindow = new JExtendedPopupWindow( JSharedObjects.getLanguageManager().getStringEx( "MESSAGE" ), JSharedObjects.getLanguageManager().getStringEx( "YOU_HAVE" ) + " " + nCount + " " + JSharedObjects.getLanguageManager().getStringEx( "UNREAD_MESSAGES" ), null ); 775 popupWindow.showPopup(); 776 } 777 778 } catch( java.sql.SQLException e ) { 779 System.out.println( "JContactListManager.loadMessagesToContactList() - SQLException " + e ); 780 }finally{ 781 if( resultSet != null ) 782 try { 783 resultSet.close(); 784 } catch ( SQLException e ) { 785 System.err.println( "JContactListManager.loadMessagesToContactList() - " + e ); 786 } 787 if( st != null ) 788 try { 789 st.close(); 790 } catch ( SQLException e ) { 791 System.err.println( "JContactListManager.loadMessagesToContactList() - " + e ); 792 } 793 } 794 } 795 796 800 public synchronized String getContactMessages( JContactListItem item ) { 801 802 long nProfileId = JSharedObjects.getProfileManager().getProfileId(); 803 int nCount = 0; 804 StringBuffer strMsg = new StringBuffer (); 805 Connection conn = null; 806 ResultSet resultSet = null; 807 PreparedStatement st = null; 808 809 810 try{ 811 conn = JSharedObjects.getDatabase().getConnection(); 812 st = conn.prepareStatement( "SELECT * FROM messages WHERE profile_id = ? AND plugin_id = ? AND LCASE(user_id) = ? ORDER BY msg_datetime ASC" ); 813 814 st.setLong( 1, nProfileId ); 815 st.setInt( 2, item.getPluginId() ); 816 st.setString( 3, item.getUserId().toLowerCase() ); 817 818 resultSet = st.executeQuery(); 819 820 if( resultSet == null ) 821 return null; 822 823 while( resultSet.next() ) { 824 825 if( strMsg.length() != 0 ) 826 strMsg.append( "<br>" ); 827 828 strMsg.append("<b>") 829 .append( item.getNickName() ) 830 .append( ": </b>" ) 831 .append( 832 JTextUtil.encodeHtml( 833 resultSet.getString( "message" ) 834 ) 835 ); 836 837 nCount++; 838 } 839 840 resultSet.close(); 841 resultSet = null; 842 st.close(); 843 st = null; 844 845 conn = JSharedObjects.getDatabase().getConnection(); 846 st = conn.prepareStatement( "DELETE FROM messages WHERE profile_id = ? AND plugin_id = ? AND LCASE(user_id) = ?" ); 847 848 st.setLong( 1, nProfileId ); 849 st.setInt( 2, item.getPluginId() ); 850 st.setString( 3, item.getUserId().toLowerCase() ); 851 852 st.executeUpdate(); 853 854 if( nCount > 0 ) 856 return strMsg.toString(); 857 else 858 return null; 859 860 } catch( java.sql.SQLException e ) { 861 System.out.println( "JContactListManager.getContactMessages() - SQLException " + e ); 862 return null; 863 }finally { 864 if( resultSet != null ) 865 try { 866 resultSet.close(); 867 } catch ( SQLException e ) { 868 System.err.println( "JContactListManager.getContactMessages() - " + e ); 869 } 870 if( st != null ) 871 try { 872 st.close(); 873 } catch ( SQLException e ) { 874 System.err.println( "JContactListManager.getContactMessages() - " + e ); 875 } 876 } 877 } 878 879 883 public synchronized int countContactMessages( JContactListItem item ) { 884 885 long nProfileId = JSharedObjects.getProfileManager().getProfileId(); 886 int nCount = 0; 887 PreparedStatement st = null; 888 ResultSet resultSet = null; 889 890 891 try{ 892 Connection conn = JSharedObjects.getDatabase().getConnection(); 893 st = conn.prepareStatement( "SELECT COUNT(*) AS _count FROM messages WHERE profile_id = ? AND plugin_id = ? AND LCASE(user_id) = ? " ); 894 895 st.setLong( 1, nProfileId ); 896 st.setInt( 2, item.getPluginId() ); 897 st.setString( 3, item.getUserId().toLowerCase() ); 898 899 resultSet = st.executeQuery(); 900 901 if( resultSet == null ) 902 return 0; 903 904 resultSet.next(); 905 nCount = resultSet.getInt( "_count" ); 906 } catch( java.sql.SQLException e ) { 907 System.out.println( "JContactListManager.countContactMessages() - SQLException " + e ); 908 return 0; 909 } finally { 910 if( resultSet != null ) 911 try { 912 resultSet.close(); 913 } catch ( SQLException e ) { 914 System.err.println( "JContactListManager.countContactMessages() - " + e ); 915 } 916 if( st != null ) 917 try { 918 st.close(); 919 } catch ( SQLException e ) { 920 System.err.println( "JContactListManager.countContactMessages() - " + e ); 921 } 922 } 923 924 return nCount; 925 } 926 927 934 public boolean onBuddyRequestAuthorization( java.lang.String strUserId, java.lang.String strNickName ) { 935 936 System.err.println( "JContactList.onBuddyRequestAuthorization( " + strUserId + " )" ); 937 938 if( javax.swing.JOptionPane.showConfirmDialog( null, JSharedObjects.getLanguageManager().getStringEx( "THE_USER" ) + " " + strNickName + " " + JSharedObjects.getLanguageManager().getStringEx( "IS_REQUESTING_AUTHORIZATION" ), JSharedObjects.getLanguageManager().getStringEx( "REQUEST_AUTHORIZATION" ), javax.swing.JOptionPane.YES_NO_OPTION, javax.swing.JOptionPane.QUESTION_MESSAGE ) == javax.swing.JOptionPane.YES_OPTION ) 939 return true; 940 else 941 return false; 942 } 943 } 944 945 | Popular Tags |