1 24 package edu.rice.rubis.client; 25 26 import java.net.URL ; 27 import java.net.URLEncoder ; 28 29 37 38 public abstract class URLGenerator 39 { 40 private static final String protocol = "http"; 41 private String webSiteName; 42 private int webSitePort; 43 private String HTMLPath; 44 private String scriptPath; 45 46 51 public abstract String AboutMeScript(); 52 53 58 public abstract String BrowseCategoriesScript(); 59 60 65 public abstract String BrowseRegionsScript(); 66 67 72 public abstract String BuyNowScript(); 73 74 79 public abstract String BuyNowAuthScript(); 80 81 86 public abstract String PutBidScript(); 87 88 93 public abstract String PutBidAuthScript(); 94 95 100 public abstract String PutCommentScript(); 101 102 107 public abstract String PutCommentAuthScript(); 108 109 114 public abstract String RegisterItemScript(); 115 116 121 public abstract String RegisterUserScript(); 122 123 128 public abstract String SearchItemsByCategoryScript(); 129 130 135 public abstract String SearchItemsByRegionScript(); 136 137 142 public abstract String SellItemFormScript(); 143 144 145 150 public abstract String StoreBuyNowScript(); 151 152 157 public abstract String StoreBidScript(); 158 159 164 public abstract String StoreCommentScript(); 165 166 171 public abstract String ViewBidHistoryScript(); 172 173 178 public abstract String ViewItemScript(); 179 180 185 public abstract String ViewUserInfoScript(); 186 187 188 197 public URLGenerator(String host, int port, String HTMLFilesPath, String ScriptFilesPath) 198 { 199 webSiteName = host; 200 HTMLPath = HTMLFilesPath; 201 scriptPath = ScriptFilesPath; 202 webSitePort = port; 203 } 204 205 214 public void setWebSiteName(String host) 215 { 216 webSiteName = host; 217 } 218 219 228 public void setHTMLPath(String p) 229 { 230 HTMLPath = p; 231 } 232 233 234 243 public void setScriptPath(String p) 244 { 245 scriptPath = p; 246 } 247 248 249 254 public void setWebSitePort(int p) 255 { 256 webSitePort = p; 257 } 258 259 260 267 protected String convertFloatToStringDatabaseFormat(float f) 268 { 269 String result = Float.toString(f); 270 int E = result.indexOf('E'); 271 if (E != -1) 272 274 result = result.substring(0,E+1)+"+"+result.substring(E+1); 275 return result; 276 } 277 278 282 283 288 public URL genericHTMLFile(String filename) 289 { 290 try 291 { 292 URL url = new URL (protocol, webSiteName, webSitePort, filename); 293 return url; 294 } 295 catch (java.net.MalformedURLException e) 296 { 297 System.out.println("Error while generating the URL corresponding to the file: "+e.getMessage()); 298 return null; 299 } 300 } 301 302 306 310 public URL homePage() 311 { 312 try 313 { 314 URL url = new URL (protocol, webSiteName, webSitePort, HTMLPath+"/index.html"); 315 return url; 316 } 317 catch (java.net.MalformedURLException e) 318 { 319 System.out.println("Error while generating home page URL: "+e.getMessage()); 320 return null; 321 } 322 } 323 324 325 329 333 public URL register() 334 { 335 try 336 { 337 URL url = new URL (protocol, webSiteName, webSitePort, HTMLPath+"/register.html"); 338 return url; 339 } 340 catch (java.net.MalformedURLException e) 341 { 342 System.out.println("Error while generating register page URL: "+e.getMessage()); 343 return null; 344 } 345 } 346 347 359 public URL registerUser(String firstname, String lastname, String nickname, 360 String email, String password,String regionName) 361 { 362 try 363 { 364 firstname = URLEncoder.encode(firstname); 365 lastname = URLEncoder.encode(lastname); 366 nickname = URLEncoder.encode(nickname); 367 email = URLEncoder.encode(email); 368 password = URLEncoder.encode(password); 369 regionName = URLEncoder.encode(regionName); 370 URL url = new URL (protocol, webSiteName, webSitePort, scriptPath+"/"+RegisterUserScript()+"?firstname="+firstname+"&lastname="+ 371 lastname+"&nickname="+nickname+"&email="+email+"&password="+password+"®ion="+regionName); 372 return url; 373 } 374 catch (java.net.MalformedURLException e) 375 { 376 System.out.println("Error while generating register user page URL: "+e.getMessage()); 377 return null; 378 } 379 } 380 381 382 386 390 public URL browse() 391 { 392 try 393 { 394 URL url = new URL (protocol, webSiteName, webSitePort, HTMLPath+"/browse.html"); 395 return url; 396 } 397 catch (java.net.MalformedURLException e) 398 { 399 System.out.println("Error while generating browse page URL: "+e.getMessage()); 400 return null; 401 } 402 } 403 404 405 411 public URL browseCategories() 412 { 413 try 414 { 415 URL url = new URL (protocol, webSiteName, webSitePort, scriptPath+"/"+BrowseCategoriesScript()); 416 return url; 417 } 418 catch (java.net.MalformedURLException e) 419 { 420 System.out.println("Error while generating Browse Categories script URL: "+e.getMessage()); 421 return null; 422 } 423 } 424 425 431 public URL browseRegions() 432 { 433 try 434 { 435 URL url = new URL (protocol, webSiteName, webSitePort, scriptPath+"/"+BrowseRegionsScript()); 436 return url; 437 } 438 catch (java.net.MalformedURLException e) 439 { 440 System.out.println("Error while generating Browse Regions script URL: "+e.getMessage()); 441 return null; 442 } 443 } 444 445 456 public URL browseItemsInCategory(int categoryId, String categoryName, int page, int nbOfItems) 457 { 458 try 459 { 460 categoryName = URLEncoder.encode(categoryName); 461 URL url = new URL (protocol, webSiteName, webSitePort, scriptPath+"/"+SearchItemsByCategoryScript()+ 462 "?category="+categoryId+"&categoryName="+categoryName+"&page="+page+"&nbOfItems="+nbOfItems); 463 return url; 464 } 465 catch (java.net.MalformedURLException e) 466 { 467 System.out.println("Error while generating 'browse all items in a category' script URL: "+e.getMessage()); 468 return null; 469 } 470 } 471 472 479 public URL browseCategoriesInRegion(String regionName) 480 { 481 regionName = URLEncoder.encode(regionName); 482 try 483 { 484 URL url = new URL (protocol, webSiteName, webSitePort, scriptPath+"/"+BrowseCategoriesScript()+"?region="+regionName); 485 return url; 486 } 487 catch (java.net.MalformedURLException e) 488 { 489 System.out.println("Error while generating 'browse all categories in a region' script URL: "+e.getMessage()); 490 return null; 491 } 492 } 493 494 505 public URL browseItemsInRegion(int categoryId, String categoryName, int regionId, int page, int nbOfItems) 506 { 507 try 508 { 509 categoryName = URLEncoder.encode(categoryName); 510 URL url = new URL (protocol, webSiteName, webSitePort, scriptPath+"/"+SearchItemsByRegionScript()+ 511 "?region="+regionId+"&category="+categoryId+"&categoryName="+categoryName+"&page="+page+"&nbOfItems="+nbOfItems); 512 return url; 513 } 514 catch (java.net.MalformedURLException e) 515 { 516 System.out.println("Error while generating 'browse all items in a category in a region' script URL: "+e.getMessage()); 517 return null; 518 } 519 } 520 521 527 public URL viewItem(int itemId) 528 { 529 try 530 { 531 URL url = new URL (protocol, webSiteName, webSitePort, scriptPath+"/"+ViewItemScript()+"?itemId="+itemId); 532 return url; 533 } 534 catch (java.net.MalformedURLException e) 535 { 536 System.out.println("Error while generating 'View Item' script URL: "+e.getMessage()); 537 return null; 538 } 539 } 540 541 547 public URL viewBidHistory(int itemId) 548 { 549 try 550 { 551 URL url = new URL (protocol, webSiteName, webSitePort, scriptPath+"/"+ViewBidHistoryScript()+"?itemId="+itemId); 552 return url; 553 } 554 catch (java.net.MalformedURLException e) 555 { 556 System.out.println("Error while generating 'View Bid History' script URL: "+e.getMessage()); 557 return null; 558 } 559 } 560 561 567 public URL viewUserInformation(int userId) 568 { 569 try 570 { 571 URL url = new URL (protocol, webSiteName, webSitePort, scriptPath+"/"+ViewUserInfoScript()+"?userId="+userId); 572 return url; 573 } 574 catch (java.net.MalformedURLException e) 575 { 576 System.out.println("Error while generating 'View User Information' script URL: "+e.getMessage()); 577 return null; 578 } 579 } 580 581 582 586 595 public URL putCommentAuth(int itemId, int toId) 596 { 597 try 598 { 599 URL url = new URL (protocol, webSiteName, webSitePort, scriptPath+"/"+PutCommentAuthScript()+"?itemId="+itemId+"&to="+toId); 600 return url; 601 } 602 catch (java.net.MalformedURLException e) 603 { 604 System.out.println("Error while generating 'Comment on an user' script URL: "+e.getMessage()); 605 return null; 606 } 607 } 608 609 619 public URL putComment(int itemId, int toId, String name, String pwd) 620 { 621 try 622 { 623 name = URLEncoder.encode(name); 624 pwd = URLEncoder.encode(pwd); 625 URL url = new URL (protocol, webSiteName, webSitePort, scriptPath+"/"+PutCommentScript()+"?itemId="+itemId+"&to="+toId+"&nickname="+name+"&password="+pwd); 626 return url; 627 } 628 catch (java.net.MalformedURLException e) 629 { 630 System.out.println("Error while generating 'Put Comment on another user' script URL: "+e.getMessage()); 631 return null; 632 } 633 } 634 635 645 public URL storeComment(int itemId, int toId, int fromId, int rating, String comment) 646 { 647 try 648 { 649 comment = URLEncoder.encode(comment); 650 URL url = new URL (protocol, webSiteName, webSitePort, scriptPath+"/"+StoreCommentScript()+"?itemId="+itemId+"&to="+toId+"&from="+fromId+"&rating="+rating+"&comment="+comment); 651 return url; 652 } 653 catch (java.net.MalformedURLException e) 654 { 655 System.out.println("Error while generating StoreComment script URL: "+e.getMessage()); 656 return null; 657 } 658 } 659 660 661 665 672 public URL putBidAuth(int itemId) 673 { 674 try 675 { 676 URL url = new URL (protocol, webSiteName, webSitePort, scriptPath+"/"+PutBidAuthScript()+"?itemId="+itemId); 677 return url; 678 } 679 catch (java.net.MalformedURLException e) 680 { 681 System.out.println("Error while generating 'Bid now on an Item' script URL: "+e.getMessage()); 682 return null; 683 } 684 } 685 686 696 public URL putBid(int itemId, String name, String pwd) 697 { 698 try 699 { 700 name = URLEncoder.encode(name); 701 pwd = URLEncoder.encode(pwd); 702 URL url = new URL (protocol, webSiteName, webSitePort, scriptPath+"/"+PutBidScript()+"?itemId="+itemId+"&nickname="+name+"&password="+pwd); 703 return url; 704 } 705 catch (java.net.MalformedURLException e) 706 { 707 System.out.println("Error while generating 'Put bid on an Item' script URL: "+e.getMessage()); 708 return null; 709 } 710 } 711 712 724 public URL storeBid(int itemId, int userId, float minBid, float bid, float maxBid, int qty, int maxQty) 725 { 726 try 727 { 728 URL url = new URL (protocol, webSiteName, webSitePort, scriptPath+"/"+StoreBidScript()+"?itemId="+itemId+"&userId="+userId+"&minBid="+convertFloatToStringDatabaseFormat(minBid)+"&maxQty="+maxQty+"&bid="+convertFloatToStringDatabaseFormat(bid)+"&maxBid="+convertFloatToStringDatabaseFormat(maxBid)+"&qty="+qty); 729 return url; 730 } 731 catch (java.net.MalformedURLException e) 732 { 733 System.out.println("Error while generating 'Store bid' script URL: "+e.getMessage()); 734 return null; 735 } 736 } 737 738 739 743 750 public URL buyNowAuth(int itemId) 751 { 752 try 753 { 754 URL url = new URL (protocol, webSiteName, webSitePort, scriptPath+"/"+BuyNowAuthScript()+"?itemId="+itemId); 755 return url; 756 } 757 catch (java.net.MalformedURLException e) 758 { 759 System.out.println("Error while generating 'Buy now auth' script URL: "+e.getMessage()); 760 return null; 761 } 762 } 763 764 772 public URL buyNow(int itemId, String name, String pwd) 773 { 774 try 775 { 776 name = URLEncoder.encode(name); 777 pwd = URLEncoder.encode(pwd); 778 URL url = new URL (protocol, webSiteName, webSitePort, scriptPath+"/"+BuyNowScript()+"?itemId="+itemId+"&nickname="+name+"&password="+pwd); 779 return url; 780 } 781 catch (java.net.MalformedURLException e) 782 { 783 System.out.println("Error while generating 'Buy Now' script URL: "+e.getMessage()); 784 return null; 785 } 786 } 787 788 789 795 public URL storeBuyNow(int itemId, int userId, int qty, int maxQty) 796 { 797 try 798 { 799 URL url = new URL (protocol, webSiteName, webSitePort, scriptPath+"/"+StoreBuyNowScript()+"?itemId="+itemId+"&userId="+userId+"&qty="+qty+"&maxQty="+maxQty); 800 return url; 801 } 802 catch (java.net.MalformedURLException e) 803 { 804 System.out.println("Error while generating 'Store Buy Now' script URL: "+e.getMessage()); 805 return null; 806 } 807 } 808 809 810 814 818 public URL sell() 819 { 820 try 821 { 822 URL url = new URL (protocol, webSiteName, webSitePort, HTMLPath+"/sell.html"); 823 return url; 824 } 825 catch (java.net.MalformedURLException e) 826 { 827 System.out.println("Error while generating sell page URL: "+e.getMessage()); 828 return null; 829 } 830 } 831 832 841 public URL selectCategoryToSellItem(String name, String pwd) 842 { 843 try 844 { 845 name = URLEncoder.encode(name); 846 pwd = URLEncoder.encode(pwd); 847 URL url = new URL (protocol, webSiteName, webSitePort, scriptPath+"/"+BrowseCategoriesScript()+"?nickname="+name+"&password="+pwd); 848 return url; 849 } 850 catch (java.net.MalformedURLException e) 851 { 852 System.out.println("Error while generating 'Select category to sell item' script URL: "+e.getMessage()); 853 return null; 854 } 855 } 856 857 866 public URL sellItemForm(int categoryId, int userId) 867 { 868 try 869 { 870 URL url = new URL (protocol, webSiteName, webSitePort, scriptPath+"/"+SellItemFormScript()+"?user="+userId+"&category="+categoryId); 871 return url; 872 } 873 catch (java.net.MalformedURLException e) 874 { 875 System.out.println("Error while generating 'Sell item form' script URL: "+e.getMessage()); 876 return null; 877 } 878 } 879 880 894 public URL registerItem(String name, String description, float initialPrice, 895 float reservePrice, float buyNow, int duration, 896 int quantity, int userId, int categoryId) 897 { 898 try 899 { 900 name = URLEncoder.encode(name); 901 description = URLEncoder.encode(description); 902 URL url = new URL (protocol, webSiteName, webSitePort, scriptPath+"/"+RegisterItemScript()+"?name="+name+"&description="+description+ 903 "&initialPrice="+convertFloatToStringDatabaseFormat(initialPrice)+"&reservePrice="+convertFloatToStringDatabaseFormat(reservePrice)+ 904 "&buyNow="+convertFloatToStringDatabaseFormat(buyNow)+"&duration="+duration+"&quantity="+quantity+"&userId="+userId+"&categoryId="+categoryId); 905 return url; 906 } 907 catch (java.net.MalformedURLException e) 908 { 909 System.out.println("Error while generating 'Register item' script URL: "+e.getMessage()); 910 return null; 911 } 912 } 913 914 918 923 public URL aboutMe() 924 { 925 try 926 { 927 URL url = new URL (protocol, webSiteName, webSitePort, HTMLPath+"/about_me.html"); 928 return url; 929 } 930 catch (java.net.MalformedURLException e) 931 { 932 System.out.println("Error while generating about_me page URL: "+e.getMessage()); 933 return null; 934 } 935 } 936 937 946 public URL aboutMe(String name, String pwd) 947 { 948 try 949 { 950 name = URLEncoder.encode(name); 951 pwd = URLEncoder.encode(pwd); 952 URL url = new URL (protocol, webSiteName, webSitePort, scriptPath+"/"+AboutMeScript()+"?nickname="+name+"&password="+pwd); 953 return url; 954 } 955 catch (java.net.MalformedURLException e) 956 { 957 System.out.println("Error while generating 'About Me' script URL: "+e.getMessage()); 958 return null; 959 } 960 } 961 962 } 963 | Popular Tags |