1 package edu.rice.rubbos.client; 2 3 import java.net.URL ; 4 import java.net.URLEncoder ; 5 6 14 15 public abstract class URLGenerator 16 { 17 private static final String protocol = "http"; 18 private String webSiteName; 19 private int webSitePort; 20 private String HTMLPath; 21 private String scriptPath; 22 23 24 29 public abstract String SearchScript(); 30 31 32 37 public abstract String BrowseCategoriesScript(); 38 39 44 public abstract String StoriesOfTheDayScript(); 45 46 51 public abstract String OlderStoriesScript(); 52 53 58 public abstract String SubmitStoryScript(); 59 60 65 public abstract String PostCommentScript(); 66 67 72 public abstract String RegisterUserScript(); 73 74 79 public abstract String BrowseStoriesByCategoryScript(); 80 81 86 public abstract String StoreCommentScript(); 87 88 93 public abstract String StoreStoryScript(); 94 95 100 public abstract String ViewStoryScript(); 101 102 107 public abstract String ViewCommentScript(); 108 109 114 public abstract String ModerateCommentScript(); 115 116 121 public abstract String StoreModerateLogScript(); 122 123 128 public abstract String AuthorTasksScript(); 129 130 135 public abstract String ReviewStoriesScript(); 136 137 142 public abstract String AcceptStoryScript(); 143 144 149 public abstract String RejectStoryScript(); 150 151 152 161 public URLGenerator(String host, int port, String HTMLFilesPath, String ScriptFilesPath) 162 { 163 webSiteName = host; 164 HTMLPath = HTMLFilesPath; 165 scriptPath = ScriptFilesPath; 166 webSitePort = port; 167 } 168 169 178 public void setWebSiteName(String host) 179 { 180 webSiteName = host; 181 } 182 183 192 public void setHTMLPath(String p) 193 { 194 HTMLPath = p; 195 } 196 197 198 207 public void setScriptPath(String p) 208 { 209 scriptPath = p; 210 } 211 212 213 218 public void setWebSitePort(int p) 219 { 220 webSitePort = p; 221 } 222 223 224 231 protected String convertFloatToStringDatabaseFormat(float f) 232 { 233 String result = Float.toString(f); 234 int E = result.indexOf('E'); 235 if (E != -1) 236 238 result = result.substring(0,E+1)+"+"+result.substring(E+1); 239 return result; 240 } 241 242 246 247 252 public URL genericHTMLFile(String filename) 253 { 254 try 255 { 256 URL url = new URL (protocol, webSiteName, webSitePort, filename); 257 return url; 258 } 259 catch (java.net.MalformedURLException e) 260 { 261 System.out.println("Error while generating the URL corresponding to the file: "+e.getMessage()); 262 return null; 263 } 264 } 265 266 270 275 public URL homePage() 276 { 277 try 278 { 279 URL url = new URL (protocol, webSiteName, webSitePort, scriptPath+"/"+StoriesOfTheDayScript()); 280 return url; 281 } 282 catch (java.net.MalformedURLException e) 283 { 284 System.out.println("Error while generating home page URL: "+e.getMessage()); 285 return null; 286 } 287 } 288 289 290 294 298 public URL register() 299 { 300 try 301 { 302 URL url = new URL (protocol, webSiteName, webSitePort, HTMLPath+"/register.html"); 303 return url; 304 } 305 catch (java.net.MalformedURLException e) 306 { 307 System.out.println("Error while generating register page URL: "+e.getMessage()); 308 return null; 309 } 310 } 311 312 323 public URL registerUser(String firstname, String lastname, String nickname, 324 String email, String password) 325 { 326 try 327 { 328 firstname = URLEncoder.encode(firstname); 329 lastname = URLEncoder.encode(lastname); 330 nickname = URLEncoder.encode(nickname); 331 email = URLEncoder.encode(email); 332 password = URLEncoder.encode(password); 333 URL url = new URL (protocol, webSiteName, webSitePort, scriptPath+"/"+RegisterUserScript()+"?firstname="+firstname+"&lastname="+ 334 lastname+"&nickname="+nickname+"&email="+email+"&password="+password); 335 return url; 336 } 337 catch (java.net.MalformedURLException e) 338 { 339 System.out.println("Error while generating register user page URL: "+e.getMessage()); 340 return null; 341 } 342 } 343 344 345 349 353 public URL browse() 354 { 355 try 356 { 357 URL url = new URL (protocol, webSiteName, webSitePort, HTMLPath+"/browse.html"); 358 return url; 359 } 360 catch (java.net.MalformedURLException e) 361 { 362 System.out.println("Error while generating browse page URL: "+e.getMessage()); 363 return null; 364 } 365 } 366 367 368 374 public URL browseCategories() 375 { 376 try 377 { 378 URL url = new URL (protocol, webSiteName, webSitePort, scriptPath+"/"+BrowseCategoriesScript()); 379 return url; 380 } 381 catch (java.net.MalformedURLException e) 382 { 383 System.out.println("Error while generating Browse Categories script URL: "+e.getMessage()); 384 return null; 385 } 386 } 387 388 393 public URL StoriesOfTheDay() 394 { 395 try 396 { 397 URL url = new URL (protocol, webSiteName, webSitePort, scriptPath+"/"+StoriesOfTheDayScript()); 398 return url; 399 } 400 catch (java.net.MalformedURLException e) 401 { 402 System.out.println("Error while generating Stories of the day script URL: "+e.getMessage()); 403 return null; 404 } 405 } 406 407 418 public URL OlderStories(int day, int month, int year, int page, int nbOfStories) 419 { 420 try 421 { 422 URL url = new URL (protocol, webSiteName, webSitePort, scriptPath+"/"+OlderStoriesScript()+ 423 "?day="+day+"&month="+month+"&year="+year+"&page="+page+"&nbOfStories="+nbOfStories); 424 return url; 425 } 426 catch (java.net.MalformedURLException e) 427 { 428 System.out.println("Error while generating Older stories script URL: "+e.getMessage()); 429 return null; 430 } 431 } 432 433 444 public URL browseStoriesByCategory(int categoryId, String categoryName, int page, int nbOfStories) 445 { 446 try 447 { 448 categoryName = URLEncoder.encode(categoryName); 449 URL url = new URL (protocol, webSiteName, webSitePort, scriptPath+"/"+BrowseStoriesByCategoryScript()+ 450 "?category="+categoryId+"&categoryName="+categoryName+"&page="+page+"&nbOfStories="+nbOfStories); 451 return url; 452 } 453 catch (java.net.MalformedURLException e) 454 { 455 System.out.println("Error while generating 'browse all stories in a category' script URL: "+e.getMessage()); 456 return null; 457 } 458 } 459 460 466 public URL viewStory(int storyId) 467 { 468 try 469 { 470 URL url = new URL (protocol, webSiteName, webSitePort, scriptPath+"/"+ViewStoryScript()+"?storyId="+storyId); 471 return url; 472 } 473 catch (java.net.MalformedURLException e) 474 { 475 System.out.println("Error while generating 'View Story' script URL: "+e.getMessage()); 476 return null; 477 } 478 } 479 480 481 491 public URL search(String keyword, String searchType, int page, int nbOfStories) 492 { 493 try 494 { 495 URL url; 496 if (keyword == null) 497 url = new URL (protocol, webSiteName, webSitePort, scriptPath+"/"+SearchScript()); 498 else 499 url = new URL (protocol, webSiteName, webSitePort, scriptPath+"/"+SearchScript()+ 500 "?type="+URLEncoder.encode(searchType)+"&search="+URLEncoder.encode(keyword)+"&page="+page+"&nbOfStories="+nbOfStories); 501 return url; 502 } 503 catch (java.net.MalformedURLException e) 504 { 505 System.out.println("Error while generating 'Search' script URL: "+e.getMessage()); 506 return null; 507 } 508 } 509 510 514 523 public URL postComment(int storyId, int parent, String comment_table) 524 { 525 try 526 { 527 comment_table = URLEncoder.encode(comment_table); 528 URL url = new URL (protocol, webSiteName, webSitePort, scriptPath+"/"+PostCommentScript()+"?storyId="+storyId+"&parent="+parent+"&comment_table="+comment_table); 529 return url; 530 } 531 catch (java.net.MalformedURLException e) 532 { 533 System.out.println("Error while generating 'Post Comment' script URL: "+e.getMessage()); 534 return null; 535 } 536 } 537 538 539 551 public URL storeComment(String name, String pwd, int storyId, int parent, String subject, String body, String comment_table) 552 { 553 try 554 { 555 name = URLEncoder.encode(name); 556 pwd = URLEncoder.encode(pwd); 557 subject = URLEncoder.encode(subject); 558 body = URLEncoder.encode(body); 559 URL url = new URL (protocol, webSiteName, webSitePort, scriptPath+"/"+StoreCommentScript()+"?comment_table="+comment_table 560 +"&nickname="+name+"&password="+pwd+"&storyId="+storyId+"&parent="+parent+"&subject="+subject+"&body="+body); 561 return url; 562 } 563 catch (java.net.MalformedURLException e) 564 { 565 System.out.println("Error while generating StoreComment script URL: "+e.getMessage()); 566 return null; 567 } 568 } 569 570 571 582 public URL viewComment(int commentId, int filter, int display, int storyId, String comment_table) 583 { 584 try 585 { 586 URL url = new URL (protocol, webSiteName, webSitePort, scriptPath+"/"+ViewCommentScript()+"?commentId="+commentId+"&filter="+filter+ 587 "&display="+display+"&storyId="+storyId+"&comment_table="+comment_table); 588 return url; 589 } 590 catch (java.net.MalformedURLException e) 591 { 592 System.out.println("Error while generating 'View comment' script URL: "+e.getMessage()); 593 return null; 594 } 595 } 596 597 598 606 public URL moderateComment(int commentId, String comment_table) 607 { 608 try 609 { 610 URL url = new URL (protocol, webSiteName, webSitePort, scriptPath+"/"+ModerateCommentScript()+ 611 "?commentId="+commentId+"&comment_table="+comment_table); 612 return url; 613 } 614 catch (java.net.MalformedURLException e) 615 { 616 System.out.println("Error while generating 'View comment' script URL: "+e.getMessage()); 617 return null; 618 } 619 } 620 621 622 632 public URL storeModerateLog(String name, String pwd, int commentId, int rating, String comment_table) 633 { 634 try 635 { 636 name = URLEncoder.encode(name); 637 pwd = URLEncoder.encode(pwd); 638 URL url = new URL (protocol, webSiteName, webSitePort, scriptPath+"/"+StoreModerateLogScript()+"?comment_table="+comment_table 639 +"&nickname="+name+"&password="+pwd+"&commentId="+commentId+"&rating="+rating); 640 return url; 641 } 642 catch (java.net.MalformedURLException e) 643 { 644 System.out.println("Error while generating StoreComment script URL: "+e.getMessage()); 645 return null; 646 } 647 } 648 649 650 654 658 public URL submitStory() 659 { 660 try 661 { 662 URL url = new URL (protocol, webSiteName, webSitePort, scriptPath+"/"+SubmitStoryScript()); 663 return url; 664 } 665 catch (java.net.MalformedURLException e) 666 { 667 System.out.println("Error while generating 'Submit Story' script URL: "+e.getMessage()); 668 return null; 669 } 670 } 671 672 673 683 public URL storeStory(String name, String pwd, String title, String body, int categoryId) 684 { 685 try 686 { 687 name = URLEncoder.encode(name); 688 pwd = URLEncoder.encode(pwd); 689 title = URLEncoder.encode(title); 690 body = URLEncoder.encode(body); 691 URL url = new URL (protocol, webSiteName, webSitePort, scriptPath+"/"+StoreStoryScript()+"?nickname="+name+"&password="+pwd+"&category="+categoryId+"&title="+title+"&body="+body); 692 return url; 693 } 694 catch (java.net.MalformedURLException e) 695 { 696 System.out.println("Error while generating 'Store Story' script URL: "+e.getMessage()); 697 return null; 698 } 699 } 700 701 702 706 710 public URL authorLogin() 711 { 712 try 713 { 714 URL url = new URL (protocol, webSiteName, webSitePort, HTMLPath+"/author.html"); 715 return url; 716 } 717 catch (java.net.MalformedURLException e) 718 { 719 System.out.println("Error while generating 'Author login' URL: "+e.getMessage()); 720 return null; 721 } 722 } 723 724 725 732 public URL authorTasks(String name, String pwd) 733 { 734 try 735 { 736 name = URLEncoder.encode(name); 737 pwd = URLEncoder.encode(pwd); 738 URL url = new URL (protocol, webSiteName, webSitePort, scriptPath+"/"+AuthorTasksScript()+"?nickname="+name+"&password="+pwd); 739 return url; 740 } 741 catch (java.net.MalformedURLException e) 742 { 743 System.out.println("Error while generating 'Author tasks' script URL: "+e.getMessage()); 744 return null; 745 } 746 } 747 748 752 public URL reviewStories() 753 { 754 try 755 { 756 URL url = new URL (protocol, webSiteName, webSitePort, scriptPath+"/"+ReviewStoriesScript()); 757 return url; 758 } 759 catch (java.net.MalformedURLException e) 760 { 761 System.out.println("Error while generating 'Review Stories' script URL: "+e.getMessage()); 762 return null; 763 } 764 } 765 766 772 public URL acceptStory(int storyId) 773 { 774 try 775 { 776 URL url = new URL (protocol, webSiteName, webSitePort, scriptPath+"/"+AcceptStoryScript()+"?storyId="+storyId); 777 return url; 778 } 779 catch (java.net.MalformedURLException e) 780 { 781 System.out.println("Error while generating 'Accept Story' script URL: "+e.getMessage()); 782 return null; 783 } 784 } 785 786 787 793 public URL rejectStory(int storyId) 794 { 795 try 796 { 797 URL url = new URL (protocol, webSiteName, webSitePort, scriptPath+"/"+RejectStoryScript()+"?storyId="+storyId); 798 return url; 799 } 800 catch (java.net.MalformedURLException e) 801 { 802 System.out.println("Error while generating 'Reject Story' script URL: "+e.getMessage()); 803 return null; 804 } 805 } 806 807 } 808 | Popular Tags |