1 package edu.rice.rubis.beans; 2 3 import java.rmi.RemoteException ; 4 import javax.ejb.MessageDrivenBean ; 5 import javax.ejb.MessageDrivenContext ; 6 import javax.ejb.EJBException ; 7 import javax.jms.*; 8 import javax.naming.Context ; 9 import javax.naming.InitialContext ; 10 import javax.rmi.PortableRemoteObject ; 11 import javax.sql.DataSource ; 12 import java.sql.Connection ; 13 import java.sql.PreparedStatement ; 14 import java.sql.ResultSet ; 15 import java.sql.SQLException ; 16 import java.io.Serializable ; 17 import javax.transaction.UserTransaction ; 18 import java.net.URLEncoder ; 19 20 26 27 public class MDB_AboutMe implements MessageDrivenBean , MessageListener 28 { 29 private DataSource dataSource; 30 private MessageDrivenContext messageDrivenContext; 31 private TopicConnectionFactory connectionFactory; 32 private TopicConnection connection; 33 private Topic topic; 34 private TopicSession session; 35 private TopicPublisher replier; 36 private Context initialContext = null; 37 38 39 public MDB_AboutMe() 40 { 41 42 } 43 44 public void onMessage(Message message) 45 { 46 try 47 { 48 MapMessage request = (MapMessage)message; 49 String correlationID = request.getJMSCorrelationID(); 50 String username = request.getString("username"); 51 String password = request.getString("password"); 52 connectionFactory = (TopicConnectionFactory) initialContext.lookup(BeanConfig.TopicConnectionFactoryName); 54 String html = getAboutMe(username, password); 56 TemporaryTopic temporaryTopic = (TemporaryTopic) request.getJMSReplyTo(); 58 if (temporaryTopic != null) 59 { 60 connection = connectionFactory.createTopicConnection(); 62 session = connection.createTopicSession(false, Session.AUTO_ACKNOWLEDGE); 64 TextMessage reply = session.createTextMessage(); 65 reply.setJMSCorrelationID(correlationID); 66 reply.setText(html); 67 68 replier = session.createPublisher(null); connection.start(); 70 replier.publish(temporaryTopic, reply); 71 replier.close(); 72 session.close(); 73 connection.stop(); 74 connection.close(); 75 } 76 } 77 catch (Exception e) 78 { 79 throw new EJBException ("Message traitment failed for MDB_AboutMe: " +e); 80 } 81 } 82 83 89 public String getAboutMe(String username, String password) throws RemoteException 90 { 91 PreparedStatement stmt = null; 93 ResultSet rs = null; 94 Connection conn = null; 95 int userId = -1; 96 StringBuffer html = new StringBuffer (); 97 98 if ((username != null && !username.equals("")) || (password != null && !password.equals(""))) 100 { 101 TopicConnection authConnection; 102 TopicSession authSession; 103 Topic authTopic; 104 try 105 { 106 authConnection = connectionFactory.createTopicConnection(); 108 authTopic = (Topic) initialContext.lookup(BeanConfig.PrefixTopicName+"topicAuth"); 110 authSession = authConnection.createTopicSession(false, Session.AUTO_ACKNOWLEDGE); } 113 catch (Exception e) 114 { 115 throw new EJBException ("Cannot connect to message bean MDB_Auth : " +e+"<br>"); 116 } 117 try 118 { 119 TopicRequestor requestor = new TopicRequestor(authSession, authTopic); 121 MapMessage m = authSession.createMapMessage(); 123 m.setStringProperty("nickname", username); 125 m.setStringProperty("password", password); 126 m.setJMSCorrelationID("auth"); 127 authConnection.start(); MapMessage authReply = (MapMessage)requestor.request(m); 130 authConnection.stop(); 131 userId = authReply.getInt("userId"); 133 requestor.close(); authConnection.close(); 136 } 137 catch (Exception e) 138 { 139 throw new EJBException ("user authentication failed: " +e+"<br>"); 140 } 141 if (userId == -1) 142 { 143 html.append("You don't have an account on RUBiS!<br>You have to register first.<br>"); 144 return html.toString(); 145 } 146 } 147 String firstname = null, lastname = null, nickname = null, email = null, date = null; 149 int rating = 0; 150 try 151 { 152 conn = dataSource.getConnection(); 153 stmt = conn.prepareStatement("SELECT * FROM users WHERE id=?"); 154 stmt.setInt(1, userId); 155 rs = stmt.executeQuery(); 156 } 157 catch (Exception e) 158 { 159 try { stmt.close(); } catch (Exception ignore) {} 160 try { conn.close(); } catch (Exception ignore) {} 161 throw new RemoteException ("Failed to execute Query for user: " +e); 162 } 163 try 164 { 165 if (rs.first()) 166 { 167 firstname = rs.getString("firstname"); 168 lastname = rs.getString("lastname"); 169 nickname = rs.getString("nickname"); 170 email = rs.getString("email"); 171 date = rs.getString("creation_date"); 172 rating = rs.getInt("rating"); 173 } 174 stmt.close(); 175 conn.close(); 176 html.append("<h2>Information about "+nickname+"<br></h2>"); 177 html.append("Real life name : "+firstname+" "+lastname+"<br>"); 178 html.append("Email address : "+email+"<br>"); 179 html.append("User since : "+date+"<br>"); 180 html.append("Current rating : <b>"+rating+"</b><br>"); 181 } 182 catch (Exception e) 183 { 184 try { stmt.close(); } catch (Exception ignore) {} 185 try { conn.close(); } catch (Exception ignore) {} 186 throw new RemoteException ("This user does not exist (got exception: " +e+")<br>"); 187 } 188 189 try 190 { 191 conn = dataSource.getConnection(); 194 html.append(listItem(userId, conn)); 195 html.append(listBoughtItems(userId, conn)); 196 html.append(listWonItems(userId, conn)); 197 html.append(listBids(userId, username, password, conn)); 198 html.append(listComments(userId, conn)); 199 conn.close(); 200 } 202 catch (Exception e) 203 { 204 try { conn.close(); } catch (Exception ignore) {} 205 throw new RemoteException ("Cannot get information about items and bids: " +e+"<br>"); 207 } 208 return html.toString(); 209 } 210 211 212 public String listItem(int userId, Connection conn) throws RemoteException 213 { 214 StringBuffer sell = new StringBuffer (); 215 ResultSet currentSellings = null; 216 ResultSet pastSellings = null; 217 PreparedStatement pastStmt = null; 218 PreparedStatement currentStmt = null; 219 220 String itemName, endDate, startDate; 221 float currentPrice=0, initialPrice=0, buyNow=0, reservePrice=0; 222 int quantity=0, itemId=-1; 223 224 try 226 { 227 currentStmt = conn.prepareStatement("SELECT * FROM items WHERE items.seller=? AND items.end_date>=NOW()"); 228 currentStmt.setInt(1, userId); 229 currentSellings = currentStmt.executeQuery(); 230 } 231 catch (Exception e) 232 { 233 try { currentStmt.close(); } catch (Exception ignore) {} 234 try { conn.close(); } catch (Exception ignore) {} 235 throw new RemoteException ("Exception getting current sellings list: " +e+"<br>"); 236 } 237 try 238 { 239 pastStmt = conn.prepareStatement("SELECT * FROM old_items WHERE old_items.seller=? AND TO_DAYS(NOW()) - TO_DAYS(old_items.end_date) < 30"); 240 pastStmt.setInt(1, userId); 241 pastSellings = pastStmt.executeQuery(); 242 } 243 catch (Exception e) 244 { 245 try { pastStmt.close(); } catch (Exception ignore) {} 246 try { conn.close(); } catch (Exception ignore) {} 247 throw new RemoteException ("Exception getting past sellings list: " +e+"<br>"); 248 } 249 try 250 { 251 if (currentSellings.first()) 252 { 253 sell.append(printSellHeader("Items you are currently selling.")); 255 do 256 { 257 try 259 { 260 itemId = currentSellings.getInt("id"); 261 itemName = currentSellings.getString("name"); 262 endDate = currentSellings.getString("end_date"); 263 startDate = currentSellings.getString("start_date"); 264 initialPrice = currentSellings.getFloat("initial_price"); 265 reservePrice = currentSellings.getFloat("reserve_price"); 266 buyNow = currentSellings.getFloat("buy_now"); 267 quantity = currentSellings.getInt("quantity"); 268 269 currentPrice = currentSellings.getFloat("max_bid"); 270 if (currentPrice <initialPrice) 271 currentPrice = initialPrice; 272 273 } 274 catch (Exception e) 275 { 276 try { currentStmt.close(); } catch (Exception ignore) {} 277 try { conn.close(); } catch (Exception ignore) {} 278 throw new RemoteException ("Exception getting item: " + e +"<br>"); 279 } 280 sell.append(printSell(itemId, itemName, initialPrice, currentPrice, quantity, reservePrice, buyNow, startDate, endDate)); 282 } 283 while (currentSellings.next()); 284 currentStmt.close(); 285 sell.append(printItemFooter()); 286 } 287 else 288 { 289 currentStmt.close(); 290 sell.append("<br>"); 291 sell.append(printHTMLHighlighted("<h3>You are currently selling no item.</h3>")); 292 } 293 } 294 catch (Exception e) 295 { 296 try { currentStmt.close(); } catch (Exception ignore) {} 297 try { conn.close(); } catch (Exception ignore) {} 298 throw new RemoteException ("Exception getting current items in sell: " + e +"<br>"); 299 } 300 try 301 { 302 if (pastSellings.first()) 303 { 304 sell.append("<br>"); 306 sell.append(printSellHeader("Items you sold in the last 30 days.")); 307 do 308 { 309 try 311 { 312 itemId = pastSellings.getInt("id"); 313 itemName = pastSellings.getString("name"); 314 endDate = pastSellings.getString("end_date"); 315 startDate = pastSellings.getString("start_date"); 316 initialPrice = pastSellings.getFloat("initial_price"); 317 reservePrice = pastSellings.getFloat("reserve_price"); 318 buyNow = pastSellings.getFloat("buy_now"); 319 quantity = pastSellings.getInt("quantity"); 320 321 currentPrice = pastSellings.getFloat("max_bid"); 322 if (currentPrice <initialPrice) 323 currentPrice = initialPrice; 324 } 325 catch (Exception e) 326 { 327 try { pastStmt.close(); } catch (Exception ignore) {} 328 try { conn.close(); } catch (Exception ignore) {} 329 throw new RemoteException ("Exception getting sold item: " + e +"<br>"); 330 } 331 sell.append(printSell(itemId, itemName, initialPrice, currentPrice, quantity, reservePrice, buyNow, startDate, endDate)); 333 } 334 while (pastSellings.next()); 335 pastStmt.close(); 336 sell.append(printItemFooter()); 337 } 338 else 339 { 340 sell.append(printHTMLHighlighted("<br><h3>You didn't sell any item in the past 30 days.</h3>")); 341 pastStmt.close(); 342 return sell.toString(); 343 } 344 } 345 catch (Exception e) 346 { 347 try { pastStmt.close(); } catch (Exception ignore) {} 348 try { conn.close(); } catch (Exception ignore) {} 349 throw new RemoteException ("Exception getting sold items: " + e +"<br>"); 350 } 351 return sell.toString(); 352 } 353 354 355 public String listBoughtItems(int userId, Connection conn) throws RemoteException 356 { 357 ResultSet buy = null; 358 PreparedStatement stmt = null; 359 String itemName = null, sellerName = null; 360 int quantity=0, sellerId=-1, itemId=-1; 361 float buyNow=0; 362 StringBuffer html = new StringBuffer (); 363 364 try 366 { 367 stmt = conn.prepareStatement("SELECT * FROM buy_now WHERE buy_now.buyer_id=? AND TO_DAYS(NOW()) - TO_DAYS(buy_now.date)<=30"); 368 stmt.setInt(1, userId); 369 buy = stmt.executeQuery(); 370 if (!buy.first()) 371 { 372 stmt.close(); 373 return printHTMLHighlighted("<br><h3>You didn't buy any item in the last 30 days.</h3><br>"); 374 } 375 } 376 catch (Exception e) 377 { 378 try { stmt.close(); } catch (Exception ignore) {} 379 try { conn.close(); } catch (Exception ignore) {} 380 throw new RemoteException ("Exception getting bought items list: " +e+"<br>"); 381 } 382 html.append(printUserBoughtItemHeader()); 383 PreparedStatement itemStmt = null; 384 PreparedStatement sellerStmt = null; 385 try 386 { 387 itemStmt = conn.prepareStatement("SELECT * FROM items WHERE id=?"); 388 sellerStmt = conn.prepareStatement("SELECT nickname FROM users WHERE id=?"); 389 ResultSet itemRS = null; 390 ResultSet sellerResult = null; 391 do 392 { 393 itemId = buy.getInt("item_id"); 394 quantity = buy.getInt("qty"); 395 397 itemStmt.setInt(1, itemId); 398 itemRS = itemStmt.executeQuery(); 399 if (itemRS.first()) 400 { 401 itemName = itemRS.getString("name"); 402 sellerId = itemRS.getInt("seller"); 403 buyNow = itemRS.getFloat("buy_now"); 404 } 405 406 sellerStmt.setInt(1, sellerId); 407 sellerResult = sellerStmt.executeQuery(); 408 if (sellerResult.first()) 410 sellerName = sellerResult.getString("nickname"); 411 412 html.append(printUserBoughtItem(itemId, itemName, quantity, buyNow, sellerId, sellerName)); 414 } 415 while (buy.next()); 416 stmt.close(); 417 itemStmt.close(); 418 sellerStmt.close(); 419 } 420 catch (Exception e) 421 { 422 try { stmt.close(); } catch (Exception ignore) {} 423 try { itemStmt.close(); } catch (Exception ignore) {} 424 try { sellerStmt.close(); } catch (Exception ignore) {} 425 throw new RemoteException ("Exception getting bought items: " +e+"<br>"); 426 } 427 html.append(printItemFooter()); 428 return html.toString(); 429 430 } 431 432 433 public String listWonItems(int userId, Connection conn) throws RemoteException 434 { 435 int sellerId=-1, itemId=-1; 436 float currentPrice=0, initialPrice=0; 437 String itemName = null, sellerName = null; 438 ResultSet won = null; 439 PreparedStatement stmt = null; 440 StringBuffer html; 441 442 try 444 { 445 stmt = conn.prepareStatement("SELECT item_id FROM bids, old_items WHERE bids.user_id=? AND bids.item_id=old_items.id AND TO_DAYS(NOW()) - TO_DAYS(old_items.end_date) < 30 GROUP BY item_id"); 446 stmt.setInt(1, userId); 447 won = stmt.executeQuery(); 448 if (!won.first()) 449 { 450 stmt.close(); 451 return printHTMLHighlighted("<br><h3>You didn't win any item in the last 30 days.</h3><br>"); 452 } 453 } 454 catch (Exception e) 455 { 456 try { stmt.close(); } catch (Exception ignore) {} 457 try { conn.close(); } catch (Exception ignore) {} 458 throw new RemoteException ("Exception getting won items list: " +e+"<br>"); 459 } 460 html = new StringBuffer (printUserWonItemHeader()); 461 462 PreparedStatement itemStmt = null; 463 PreparedStatement sellerStmt = null; 464 try 465 { 466 itemStmt = conn.prepareStatement("SELECT * FROM old_items WHERE id=?"); 467 sellerStmt = conn.prepareStatement("SELECT nickname FROM users WHERE id=?"); 468 ResultSet itemRS = null; 469 ResultSet sellerResult = null; 470 do 471 { 472 itemId = won.getInt("item_id"); 473 itemStmt.setInt(1, itemId); 475 itemRS = itemStmt.executeQuery(); 476 if (itemRS.first()) 477 { 478 itemName = itemRS.getString("name"); 479 sellerId = itemRS.getInt("seller"); 480 initialPrice = itemRS.getFloat("initial_price"); 481 482 currentPrice = itemRS.getFloat("max_bid"); 483 if (currentPrice <initialPrice) 484 currentPrice = initialPrice; 485 } 486 487 sellerStmt.setInt(1, sellerId); 488 sellerResult = sellerStmt.executeQuery(); 489 if (sellerResult.first()) 491 sellerName = sellerResult.getString("nickname"); 492 493 html.append(printUserWonItem(itemId, itemName, currentPrice, sellerId, sellerName)); 495 } 496 while (won.next()); 497 stmt.close(); 498 itemStmt.close(); 499 sellerStmt.close(); 500 } 501 catch (Exception e) 502 { 503 try { stmt.close(); } catch (Exception ignore) {} 504 try { itemStmt.close(); } catch (Exception ignore) {} 505 try { sellerStmt.close(); } catch (Exception ignore) {} 506 try { conn.close(); } catch (Exception ignore) {} 507 throw new RemoteException ("Exception getting won items: " +e+"<br>"); 508 } 509 html.append(printItemFooter()); 510 return html.toString(); 511 } 512 513 514 515 public String listComments(int userId, Connection conn) throws RemoteException 516 { 517 ResultSet rs = null; 518 PreparedStatement stmt = null; 519 String date = null, comment = null; 520 int authorId = -1; 521 StringBuffer html = null; 522 523 try 525 { 526 stmt = conn.prepareStatement("SELECT * FROM comments WHERE to_user_id=?"); 527 stmt.setInt(1, userId); 528 rs = stmt.executeQuery(); 529 if (!rs.first()) 530 { 531 stmt.close(); 532 return printHTMLHighlighted(("<br><h3>There is no comment yet for this user.</h3><br>")); 533 } 534 else 535 html = new StringBuffer (printHTMLHighlighted("<h3>Comments for this user</h3><br>")); 536 } 537 catch (Exception e) 538 { 539 try { stmt.close(); } catch (Exception ignore) {} 540 try { conn.close(); } catch (Exception ignore) {} 541 throw new RemoteException ("Failed to execute Query for list of comments: " +e); 542 } 543 html.append(printCommentHeader()); 544 PreparedStatement authorStmt = null; 545 try 546 { 547 authorStmt = conn.prepareStatement("SELECT nickname FROM users WHERE id=?"); 549 ResultSet authorRS = null; 550 do 551 { 552 comment = rs.getString("comment"); 553 date = rs.getString("date"); 554 authorId = rs.getInt("from_user_id"); 555 556 String authorName = "none"; 557 try 558 { 559 authorStmt.setInt(1, authorId); 560 authorRS = authorStmt.executeQuery(); 561 if (authorRS.first()) 562 authorName = authorRS.getString("nickname"); 563 } 564 catch (Exception e) 565 { 566 throw new RemoteException ("Failed to execute Query for the comment author: " +e); 567 } 568 html.append(printComment(authorName, date, comment, authorId)); 569 } 570 while (rs.next()); 571 authorStmt.close(); 572 stmt.close(); 573 } 574 catch (Exception e) 575 { 576 try { authorStmt.close(); } catch (Exception ignore) {} 577 try { stmt.close(); } catch (Exception ignore) {} 578 try { conn.close(); } catch (Exception ignore) {} 579 throw new RemoteException ("Failed to get comments list: " +e); 580 } 581 html.append(printCommentFooter()); 582 return html.toString(); 583 } 584 585 586 public String listBids(int userId, String username, String password, Connection conn) throws RemoteException 587 { 588 float currentPrice = 0, initialPrice = 0, maxBid = 0; 589 String itemName = null, sellerName = null, startDate = null, endDate = null; 590 int sellerId = -1, quantity = 0, itemId = -1; 591 ResultSet bid = null; 592 PreparedStatement stmt = null; 593 StringBuffer html = null; 594 595 try 597 { 598 stmt = conn.prepareStatement("SELECT item_id, bids.max_bid FROM bids, items WHERE bids.user_id=? AND bids.item_id=items.id AND items.end_date>=NOW() GROUP BY item_id"); 599 stmt.setInt(1, userId); 600 bid = stmt.executeQuery(); 601 if (!bid.first()) 602 { 603 stmt.close(); 604 return printHTMLHighlighted("<h3>You didn't put any bid.</h3>"); 605 } 606 } 607 catch (Exception e) 608 { 609 try { stmt.close(); } catch (Exception ignore) {} 610 try { conn.close(); } catch (Exception ignore) {} 611 throw new RemoteException ("Exception getting bids list: " +e+"<br>"); 612 } 613 html = new StringBuffer (printUserBidsHeader()); 614 615 PreparedStatement itemStmt = null; 616 PreparedStatement sellerStmt = null; 617 try 618 { 619 itemStmt = conn.prepareStatement("SELECT * FROM items WHERE id=?"); 620 sellerStmt = conn.prepareStatement("SELECT nickname FROM users WHERE id=?"); 621 ResultSet rs = null; 622 ResultSet sellerResult = null; 623 do 624 { 625 itemId = bid.getInt("item_id"); 626 maxBid = bid.getFloat("max_bid"); 628 itemStmt.setInt(1, itemId); 629 rs = itemStmt.executeQuery(); 630 631 if (rs.first()) 633 { 634 itemName = rs.getString("name"); 635 initialPrice = rs.getFloat("initial_price"); 636 quantity = rs.getInt("quantity"); 637 startDate = rs.getString("start_date"); 638 endDate = rs.getString("end_date"); 639 sellerId = rs.getInt("seller"); 640 641 currentPrice = rs.getFloat("max_bid"); if (currentPrice <initialPrice) 643 currentPrice = initialPrice; 644 } 645 646 sellerStmt.setInt(1, sellerId); 647 sellerResult = sellerStmt.executeQuery(); 648 if (sellerResult.first()) 650 sellerName = sellerResult.getString("nickname"); 651 652 html.append(printItemUserHasBidOn(itemId, itemName, initialPrice, maxBid, currentPrice, quantity, startDate, endDate, sellerId, sellerName, username, password)); 654 } 655 while(bid.next()); 656 stmt.close(); 657 itemStmt.close(); 658 sellerStmt.close(); 659 } 660 catch (Exception e) 661 { 662 try { stmt.close(); } catch (Exception ignore) {} 663 try { itemStmt.close(); } catch (Exception ignore) {} 664 try { sellerStmt.close(); } catch (Exception ignore) {} 665 try { conn.close(); } catch (Exception ignore) {} 666 throw new RemoteException ("Exception getting items the user has bid on: " + e +"<br>"); 667 } 668 html.append(printItemFooter()); 669 return html.toString(); 670 } 671 672 678 public String printUserBoughtItemHeader() 679 { 680 return "<br>"+ 681 printHTMLHighlighted("<p><h3>Items you bouhgt in the past 30 days.</h3>\n")+ 682 "<TABLE border=\"1\" summary=\"List of items\">\n"+ 683 "<THEAD>\n"+ 684 "<TR><TH>Designation<TH>Quantity<TH>Price you bought it<TH>Seller"+ 685 "<TBODY>\n"; 686 } 687 688 694 public String printUserWonItemHeader() 695 { 696 return "<br>"+ 697 printHTMLHighlighted("<p><h3>Items you won in the past 30 days.</h3>\n")+ 698 "<TABLE border=\"1\" summary=\"List of items\">\n"+ 699 "<THEAD>\n"+ 700 "<TR><TH>Designation<TH>Price you bought it<TH>Seller"+ 701 "<TBODY>\n"; 702 } 703 704 710 public String printUserBidsHeader() 711 { 712 return "<br>"+ 713 printHTMLHighlighted("<p><h3>Items you have bid on.</h3>\n")+ 714 "<TABLE border=\"1\" summary=\"Items You've bid on\">\n"+ 715 "<THEAD>\n"+ 716 "<TR><TH>Designation<TH>Initial Price<TH>Current price<TH>Your max bid<TH>Quantity"+ 717 "<TH>Start Date<TH>End Date<TH>Seller<TH>Put a new bid\n"+ 718 "<TBODY>\n"; 719 } 720 721 722 729 public String printUserBoughtItem(int id, String name, int qty, float buyNow, int sellerId, String sellerName) throws RemoteException 730 { 731 return "<TR><TD><a HREF=\""+BeanConfig.context+"/servlet/edu.rice.rubis.beans.servlets.ViewItem?itemId="+id+"\">"+name+"</a>\n"+ 732 "<TD>"+qty+"\n"+"<TD>"+buyNow+"\n"+ 733 "<TD><a HREF=\""+BeanConfig.context+"/servlet/edu.rice.rubis.beans.servlets.ViewUserInfo?userId="+sellerId+"\">"+sellerName+"</a>\n"; 734 } 735 736 743 public String printItemUserHasBidOn(int id, String name, float initialPrice, float maxBid, float currentPrice, int quantity, String startDate, String endDate, int sellerId, String sellerName, String username, String password) throws RemoteException 744 { 745 StringBuffer html = new StringBuffer ("<TR><TD><a HREF=\""+BeanConfig.context+"/servlet/edu.rice.rubis.beans.servlets.ViewItem?itemId="+id+"\">"+name+ 746 "<TD>"+initialPrice+"<TD>"+currentPrice+"<TD>"+maxBid+"<TD>"+quantity+"<TD>"+startDate+"<TD>"+endDate+ 747 "<TD><a HREF=\""+BeanConfig.context+"/servlet/edu.rice.rubis.beans.servlets.ViewUserInfo?userId="+sellerId+"\">"+sellerName+ 748 "<TD><a HREF=\""+BeanConfig.context+"/servlet/edu.rice.rubis.beans.servlets.PutBid?itemId="+id); 749 html.append("&nickname="+URLEncoder.encode(username)+"&password="+URLEncoder.encode(password)+"\"><IMG SRC=\""+BeanConfig.context+"/bid_now.jpg\" height=22 width=90></a>\n"); 750 return html.toString(); 751 } 752 753 754 761 public String printSell(int id, String name, float initialPrice, float maxBid, int quantity, float reservePrice, float buyNow, String startDate, String endDate) throws RemoteException 762 { 763 return "<TR><TD><a HREF=\""+BeanConfig.context+"/servlet/edu.rice.rubis.beans.servlets.ViewItem?itemId="+id+"\">"+name+ 764 "<TD>"+initialPrice+"<TD>"+maxBid+"<TD>"+quantity+"<TD>"+reservePrice+"<TD>"+buyNow+"<TD>"+startDate+"<TD>"+endDate+"\n"; 765 } 766 767 774 public String printUserWonItem(int id, String name, float maxBid, int sellerId, String sellerName) throws RemoteException 775 { 776 return "<TR><TD><a HREF=\""+BeanConfig.context+"/servlet/edu.rice.rubis.beans.servlets.ViewItem?itemId="+id+"\">"+name+"</a>\n"+ 777 "<TD>"+maxBid+"\n"+ 778 "<TD><a HREF=\""+BeanConfig.context+"/servlet/edu.rice.rubis.beans.servlets.ViewUserInfo?userId="+sellerId+"\">"+sellerName+"</a>\n"; 779 } 780 781 787 public String printSellHeader(String title) 788 { 789 return printHTMLHighlighted("<p><h3>"+title+"</h3>\n")+ 790 "<TABLE border=\"1\" summary=\"List of items\">\n"+ 791 "<THEAD>\n"+ 792 "<TR><TH>Designation<TH>Initial Price<TH>Current price<TH>Quantity<TH>ReservePrice<TH>Buy Now"+ 793 "<TH>Start Date<TH>End Date\n"+ 794 "<TBODY>\n"; 795 } 796 797 798 804 public String printItemFooter() 805 { 806 return "</TABLE>\n"; 807 } 808 809 815 public String printCommentHeader() 816 { 817 return "<DL>\n"; 818 } 819 820 827 public String printComment(String userName, String date, String comment, int fromUserId) throws RemoteException 828 { 829 return "<DT><b><BIG><a HREF=\""+BeanConfig.context+"/servlet/edu.rice.rubis.beans.servlets.ViewUserInfo?userId="+fromUserId+"\">"+userName+"</a></BIG></b>"+ 830 " wrote the "+date+"<DD><i>"+comment+"</i><p>\n"; 831 } 832 833 839 public String printCommentFooter() 840 { 841 return "</DL>\n"; 842 } 843 844 850 public String printHTMLHighlighted(String msg) 851 { 852 return "<TABLE width=\"100%\" bgcolor=\"#CCCCFF\">\n<TR><TD align=\"center\" width=\"100%\"><FONT size=\"4\" color=\"#000000\"><B>" + msg + "</B></FONT></TD></TR>\n</TABLE><p>\n"; 853 } 854 855 857 868 public void setMessageDrivenContext(MessageDrivenContext ctx) 869 { 870 messageDrivenContext = ctx; 871 if (dataSource == null) 872 { 873 try 875 { 876 initialContext = new InitialContext (); 877 dataSource = (DataSource )initialContext.lookup("java:comp/env/jdbc/rubis"); 878 } 879 catch (Exception e) 880 { 881 throw new EJBException ("Cannot get JNDI InitialContext"); 882 } 883 } 884 } 885 886 890 public void ejbCreate() 891 { 892 893 } 894 895 904 public void ejbRemove() {} 905 906 907 } 908 | Popular Tags |