KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > edu > rice > rubis > client > URLGenerator


1 /*
2  * RUBiS
3  * Copyright (C) 2002, 2003, 2004 French National Institute For Research In Computer
4  * Science And Control (INRIA).
5  * Contact: jmob@objectweb.org
6  *
7  * This library is free software; you can redistribute it and/or modify it
8  * under the terms of the GNU Lesser General Public License as published by the
9  * Free Software Foundation; either version 2.1 of the License, or any later
10  * version.
11  *
12  * This library is distributed in the hope that it will be useful, but WITHOUT
13  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
14  * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
15  * for more details.
16  *
17  * You should have received a copy of the GNU Lesser General Public License
18  * along with this library; if not, write to the Free Software Foundation,
19  * Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
20  *
21  * Initial developer(s): Emmanuel Cecchet, Julie Marguerite
22  * Contributor(s):
23  */

24  package edu.rice.rubis.client;
25
26 import java.net.URL JavaDoc;
27 import java.net.URLEncoder JavaDoc;
28
29 /**
30  * This abstract class provides the needed URLs to access all features of RUBiS.
31  * Only the function returning script names must be defined in subclasses else
32  * every URL is generated by this class.
33  *
34  * @author <a HREF="mailto:cecchet@rice.edu">Emmanuel Cecchet</a> and <a HREF="mailto:julie.marguerite@inrialpes.fr">Julie Marguerite</a>
35  * @version 1.0
36  */

37
38 public abstract class URLGenerator
39 {
40   private static final String JavaDoc protocol = "http";
41   private String JavaDoc webSiteName;
42   private int webSitePort;
43   private String JavaDoc HTMLPath;
44   private String JavaDoc scriptPath;
45
46   /**
47    * Returns the name of the About Me script according to the implementation (PHP, EJB or Servlets).
48    *
49    * @return About Me script name
50    */

51   public abstract String JavaDoc AboutMeScript();
52
53   /**
54    * Returns the name of the Browse Categories script according to the implementation (PHP, EJB or Servlets).
55    *
56    * @return Browse Categories script name
57    */

58   public abstract String JavaDoc BrowseCategoriesScript();
59
60   /**
61    * Returns the name of the Browse Regions script according to the implementation (PHP, EJB or Servlets).
62    *
63    * @return Browse Regions script name
64    */

65   public abstract String JavaDoc BrowseRegionsScript();
66
67   /**
68    * Returns the name of the Buy Now script according to the implementation (PHP, EJB or Servlets).
69    *
70    * @return Buy Now script name
71    */

72   public abstract String JavaDoc BuyNowScript();
73
74   /**
75    * Returns the name of the Buy Now Auth script according to the implementation (PHP, EJB or Servlets).
76    *
77    * @return Buy Now Auth script name
78    */

79   public abstract String JavaDoc BuyNowAuthScript();
80
81   /**
82    * Returns the name of the Put Bid script according to the implementation (PHP, EJB or Servlets).
83    *
84    * @return Put Bid script name
85    */

86   public abstract String JavaDoc PutBidScript();
87
88   /**
89    * Returns the name of the Put Bid Auth script according to the implementation (PHP, EJB or Servlets).
90    *
91    * @return Put Bid Auth script name
92    */

93   public abstract String JavaDoc PutBidAuthScript();
94
95   /**
96    * Returns the name of the Put Comment script according to the implementation (PHP, EJB or Servlets).
97    *
98    * @return Put Comment script name
99    */

100   public abstract String JavaDoc PutCommentScript();
101
102   /**
103    * Returns the name of the Put Comment Auth script according to the implementation (PHP, EJB or Servlets).
104    *
105    * @return Put Comment Auth script name
106    */

107   public abstract String JavaDoc PutCommentAuthScript();
108
109   /**
110    * Returns the name of the Register Item script according to the implementation (PHP, EJB or Servlets).
111    *
112    * @return Register Item script name
113    */

114   public abstract String JavaDoc RegisterItemScript();
115
116   /**
117    * Returns the name of the Register User script according to the implementation (PHP, EJB or Servlets).
118    *
119    * @return Register User script name
120    */

121   public abstract String JavaDoc RegisterUserScript();
122
123   /**
124    * Returns the name of the Search Items By Category script according to the implementation (PHP, EJB or Servlets).
125    *
126    * @return Search Items By Category script name
127    */

128   public abstract String JavaDoc SearchItemsByCategoryScript();
129
130   /**
131    * Returns the name of the Search Items By Region script according to the implementation (PHP, EJB or Servlets).
132    *
133    * @return Search Items By Region script name
134    */

135   public abstract String JavaDoc SearchItemsByRegionScript();
136
137   /**
138    * Returns the name of the Sell Item Form script according to the implementation (PHP, EJB or Servlets).
139    *
140    * @return Sell Item Form script name
141    */

142   public abstract String JavaDoc SellItemFormScript();
143
144
145   /**
146    * Returns the name of the Store Buy Now script according to the implementation (PHP, EJB or Servlets).
147    *
148    * @return Store Buy Now script name
149    */

150   public abstract String JavaDoc StoreBuyNowScript();
151
152   /**
153    * Returns the name of the Store Bid script according to the implementation (PHP, EJB or Servlets).
154    *
155    * @return Store Bid script name
156    */

157   public abstract String JavaDoc StoreBidScript();
158
159   /**
160    * Returns the name of the Store Comment script according to the implementation (PHP, EJB or Servlets).
161    *
162    * @return Store Comment script name
163    */

164   public abstract String JavaDoc StoreCommentScript();
165
166   /**
167    * Returns the name of the View Bid History script according to the implementation (PHP, EJB or Servlets).
168    *
169    * @return View Bid History script name
170    */

171   public abstract String JavaDoc ViewBidHistoryScript();
172
173   /**
174    * Returns the name of the View Item script according to the implementation (PHP, EJB or Servlets).
175    *
176    * @return View Item script name
177    */

178   public abstract String JavaDoc ViewItemScript();
179
180   /**
181    * Returns the name of the View User Info script according to the implementation (PHP, EJB or Servlets).
182    *
183    * @return View User Info script name
184    */

185   public abstract String JavaDoc ViewUserInfoScript();
186
187
188   /**
189    * Set the name and port of the Web site running RUBiS as well as the
190    * directories where the HTML and scripts reside.
191    *
192    * @param host Web site address
193    * @param port HTTP server port
194    * @param HTMLFilesPath path where HTML files reside
195    * @param ScriptFilesPath path to the script files
196    */

197   public URLGenerator(String JavaDoc host, int port, String JavaDoc HTMLFilesPath, String JavaDoc ScriptFilesPath)
198   {
199     webSiteName = host;
200     HTMLPath = HTMLFilesPath;
201     scriptPath = ScriptFilesPath;
202     webSitePort = port;
203   }
204
205   /** Set the web site name.
206    * For example:
207    * <pre>
208    * URLGenerator urlGen = new URLGenerator();
209    * urlGen.setWebSiteName("www.testbed.cs.rice.edu");
210    * </pre>
211    *
212    * @param host location
213    */

214   public void setWebSiteName(String JavaDoc host)
215   {
216     webSiteName = host;
217   }
218
219   /** Set the location where the HTML files reside on the web site.
220    * For example:
221    * <pre>
222    * URLGenerator urlGen = new URLGenerator();
223    * urlGen.setHTMLPath("/EJB_HTML");
224    * </pre>
225    *
226    * @param p HTML files path
227    */

228   public void setHTMLPath(String JavaDoc p)
229   {
230     HTMLPath = p;
231   }
232
233
234   /** Set the location where the script files reside on the web site.
235    * For example:
236    * <pre>
237    * URLGenerator urlGen = new URLGenerator();
238    * urlGen.setScriptPath("/servlet");
239    * </pre>
240    *
241    * @param p HTML files path
242    */

243   public void setScriptPath(String JavaDoc p)
244   {
245     scriptPath = p;
246   }
247
248
249   /**
250    * Set the value of http server port.
251    *
252    * @param p http server port
253    */

254   public void setWebSitePort(int p)
255   {
256     webSitePort = p;
257   }
258
259
260   /**
261    * Return the string representing a float number in a format understandable by the database.
262    * This function needs to be fixed since it still does not work with large number.
263    *
264    * @param f the float value to convert
265    * @return a string representing the float conforming to database representation.
266    */

267   protected String JavaDoc convertFloatToStringDatabaseFormat(float f)
268   {
269     String JavaDoc result = Float.toString(f);
270     int E = result.indexOf('E');
271     if (E != -1)
272     /* We have something like 1.2345E6 but the database needs 1.2345E+6
273        So, we need to add the + */

274       result = result.substring(0,E+1)+"+"+result.substring(E+1);
275     return result;
276   }
277
278   // ===========================================================
279
// ==================== URL Generation =======================
280
// ===========================================================
281

282
283   /** URL to the page corresponding to the file.
284    *
285    * @param filename file name
286    * @return the URL corresponding to the file
287    */

288   public URL JavaDoc genericHTMLFile(String JavaDoc filename)
289   {
290     try
291     {
292       URL JavaDoc url = new URL JavaDoc(protocol, webSiteName, webSitePort, filename);
293       return url;
294     }
295     catch (java.net.MalformedURLException JavaDoc e)
296     {
297       System.out.println("Error while generating the URL corresponding to the file: "+e.getMessage());
298       return null;
299     }
300   }
301
302   // =====================================================
303
// ==================== Home page ======================
304
// =====================================================
305

306   /** URL to the home page of the web site.
307    *
308    * @return home page URL
309    */

310   public URL JavaDoc homePage()
311   {
312     try
313     {
314       URL JavaDoc url = new URL JavaDoc(protocol, webSiteName, webSitePort, HTMLPath+"/index.html");
315       return url;
316     }
317     catch (java.net.MalformedURLException JavaDoc e)
318     {
319       System.out.println("Error while generating home page URL: "+e.getMessage());
320       return null;
321     }
322   }
323
324
325   // =====================================================
326
// ==================== Register =======================
327
// =====================================================
328

329   /** URL to the register user page of the web site.
330    *
331    * @return register user page URL
332    */

333   public URL JavaDoc register()
334   {
335     try
336     {
337       URL JavaDoc url = new URL JavaDoc(protocol, webSiteName, webSitePort, HTMLPath+"/register.html");
338       return url;
339     }
340     catch (java.net.MalformedURLException JavaDoc e)
341     {
342       System.out.println("Error while generating register page URL: "+e.getMessage());
343       return null;
344     }
345   }
346
347   /** Register a new user in the database. You must provide all
348    * information that are requested by the web page.
349    *
350    * @param firstname user's first name
351    * @param lastname user's last name
352    * @param nickname user's nick name (login name)
353    * @param email user's email address
354    * @param password user's password
355    * @param regionName region name where the user live (warning it is case sensitive)
356    *
357    * @return URL to use to register a new user
358    */

359   public URL JavaDoc registerUser(String JavaDoc firstname, String JavaDoc lastname, String JavaDoc nickname,
360                          String JavaDoc email, String JavaDoc password,String JavaDoc 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 JavaDoc url = new URL JavaDoc(protocol, webSiteName, webSitePort, scriptPath+"/"+RegisterUserScript()+"?firstname="+firstname+"&lastname="+
371       lastname+"&nickname="+nickname+"&email="+email+"&password="+password+"&region="+regionName);
372       return url;
373     }
374     catch (java.net.MalformedURLException JavaDoc e)
375     {
376       System.out.println("Error while generating register user page URL: "+e.getMessage());
377       return null;
378     }
379   }
380
381
382   // =====================================================
383
// ==================== Browsing =======================
384
// =====================================================
385

386   /** URL to the browse page of the web site.
387    *
388    * @return browse page URL
389    */

390   public URL JavaDoc browse()
391   {
392     try
393     {
394       URL JavaDoc url = new URL JavaDoc(protocol, webSiteName, webSitePort, HTMLPath+"/browse.html");
395       return url;
396     }
397     catch (java.net.MalformedURLException JavaDoc e)
398     {
399       System.out.println("Error while generating browse page URL: "+e.getMessage());
400       return null;
401     }
402   }
403
404
405   /** Access the Browse Categories page of RUBiS that lists all
406    * available categories. The user can then select a category
407    * to view all items in that category.
408    *
409    * @return Browse categories script URL
410    */

411   public URL JavaDoc browseCategories()
412   {
413     try
414     {
415       URL JavaDoc url = new URL JavaDoc(protocol, webSiteName, webSitePort, scriptPath+"/"+BrowseCategoriesScript());
416       return url;
417     }
418     catch (java.net.MalformedURLException JavaDoc e)
419     {
420       System.out.println("Error while generating Browse Categories script URL: "+e.getMessage());
421       return null;
422     }
423   }
424
425   /** Access the Browse Regions page of RUBiS that lists all
426    * available region. The user can then select a region
427    * to view all categories available in that region.
428    *
429    * @return Browse regions script URL
430    */

431   public URL JavaDoc browseRegions()
432   {
433     try
434     {
435       URL JavaDoc url = new URL JavaDoc(protocol, webSiteName, webSitePort, scriptPath+"/"+BrowseRegionsScript());
436       return url;
437     }
438     catch (java.net.MalformedURLException JavaDoc e)
439     {
440       System.out.println("Error while generating Browse Regions script URL: "+e.getMessage());
441       return null;
442     }
443   }
444
445   /**
446    * URL to the 'browse all items in a category' script. You must
447    * provide both the category id and category name.
448    *
449    * @param categoryId category id
450    * @param categoryName category name
451    * @param page page to view (0=first page)
452    * @param nbOfItems number of items to display per page
453    *
454    * @return 'browse all items in a category' script URL
455    */

456   public URL JavaDoc browseItemsInCategory(int categoryId, String JavaDoc categoryName, int page, int nbOfItems)
457   {
458     try
459     {
460       categoryName = URLEncoder.encode(categoryName);
461       URL JavaDoc url = new URL JavaDoc(protocol, webSiteName, webSitePort, scriptPath+"/"+SearchItemsByCategoryScript()+
462                         "?category="+categoryId+"&categoryName="+categoryName+"&page="+page+"&nbOfItems="+nbOfItems);
463       return url;
464     }
465     catch (java.net.MalformedURLException JavaDoc 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   /** URL to the 'browse all categories in a region' script. You must
473    * provide the region name.
474    *
475    * @param regionName region name
476    *
477    * @return 'browse all categories in a region' script URL
478    */

479   public URL JavaDoc browseCategoriesInRegion(String JavaDoc regionName)
480   {
481     regionName = URLEncoder.encode(regionName);
482     try
483     {
484       URL JavaDoc url = new URL JavaDoc(protocol, webSiteName, webSitePort, scriptPath+"/"+BrowseCategoriesScript()+"?region="+regionName);
485       return url;
486     }
487     catch (java.net.MalformedURLException JavaDoc 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   /** URL to the 'browse all items in a category in a region' script. You must
495    * provide the category id, category name and region id.
496    *
497    * @param categoryId category id
498    * @param categoryName category name
499    * @param regionId region id
500    * @param page page to view (0=first page)
501    * @param nbOfItems number of items to display per page
502    *
503    * @return 'browse all items in a category in a region' script URL
504    */

505   public URL JavaDoc browseItemsInRegion(int categoryId, String JavaDoc categoryName, int regionId, int page, int nbOfItems)
506   {
507     try
508     {
509       categoryName = URLEncoder.encode(categoryName);
510       URL JavaDoc url = new URL JavaDoc(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 JavaDoc 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   /** URL to the 'View Item' script. You must provide the item id.
522    *
523    * @param itemId item identifier
524    *
525    * @return 'View Item' script URL
526    */

527   public URL JavaDoc viewItem(int itemId)
528   {
529     try
530     {
531       URL JavaDoc url = new URL JavaDoc(protocol, webSiteName, webSitePort, scriptPath+"/"+ViewItemScript()+"?itemId="+itemId);
532       return url;
533     }
534     catch (java.net.MalformedURLException JavaDoc e)
535     {
536       System.out.println("Error while generating 'View Item' script URL: "+e.getMessage());
537       return null;
538     }
539   }
540
541   /** URL to the 'View Bid History' script. You must provide the item id.
542    *
543    * @param itemId item identifier
544    *
545    * @return 'View Bid History' script URL
546    */

547   public URL JavaDoc viewBidHistory(int itemId)
548   {
549     try
550     {
551       URL JavaDoc url = new URL JavaDoc(protocol, webSiteName, webSitePort, scriptPath+"/"+ViewBidHistoryScript()+"?itemId="+itemId);
552       return url;
553     }
554     catch (java.net.MalformedURLException JavaDoc e)
555     {
556       System.out.println("Error while generating 'View Bid History' script URL: "+e.getMessage());
557       return null;
558     }
559   }
560
561   /** URL to the 'View User Information' script. You must provide the user id.
562    *
563    * @param userId user identifier
564    *
565    * @return 'View User Information' script URL
566    */

567   public URL JavaDoc viewUserInformation(int userId)
568   {
569     try
570     {
571       URL JavaDoc url = new URL JavaDoc(protocol, webSiteName, webSitePort, scriptPath+"/"+ViewUserInfoScript()+"?userId="+userId);
572       return url;
573     }
574     catch (java.net.MalformedURLException JavaDoc e)
575     {
576       System.out.println("Error while generating 'View User Information' script URL: "+e.getMessage());
577       return null;
578     }
579   }
580
581
582   // =====================================================
583
// ==================== Comments =======================
584
// =====================================================
585

586   /** URL to the 'Comment on an user' script.
587    * You must provide the item id and the user id of the receiver of this comment.
588    * This will lead to a user authentification.
589    *
590    * @param itemId item identifier
591    * @param toId receiver user identifier
592    *
593    * @return 'Comment on an user' script URL
594    */

595   public URL JavaDoc putCommentAuth(int itemId, int toId)
596   {
597     try
598     {
599       URL JavaDoc url = new URL JavaDoc(protocol, webSiteName, webSitePort, scriptPath+"/"+PutCommentAuthScript()+"?itemId="+itemId+"&to="+toId);
600       return url;
601     }
602     catch (java.net.MalformedURLException JavaDoc e)
603     {
604       System.out.println("Error while generating 'Comment on an user' script URL: "+e.getMessage());
605       return null;
606     }
607   }
608
609   /** URL to the 'Put Comment on another user' script.
610    * This is the page the user can access when it has been successfully authenticated.
611    *
612    * @param itemId item identifier
613    * @param toId receiver user identifier
614    * @param name user's name
615    * @param pwd user's password
616    *
617    * @return 'Put Comment on another user' script URL
618    */

619   public URL JavaDoc putComment(int itemId, int toId, String JavaDoc name, String JavaDoc pwd)
620   {
621     try
622     {
623       name = URLEncoder.encode(name);
624       pwd = URLEncoder.encode(pwd);
625       URL JavaDoc url = new URL JavaDoc(protocol, webSiteName, webSitePort, scriptPath+"/"+PutCommentScript()+"?itemId="+itemId+"&to="+toId+"&nickname="+name+"&password="+pwd);
626       return url;
627     }
628     catch (java.net.MalformedURLException JavaDoc 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   /** URL to the 'StoreComment' script. This action really stores a new comment in the database.
636    *
637    * @param itemId item identifier
638    * @param toId receiver user identifier
639    * @param fromId author user identifier
640    * @param rating user's rating generally a value between -5 and +5
641    * @param comment the comment text itself
642    *
643    * @return 'Store Comment' script URL
644    */

645   public URL JavaDoc storeComment(int itemId, int toId, int fromId, int rating, String JavaDoc comment)
646   {
647     try
648     {
649       comment = URLEncoder.encode(comment);
650       URL JavaDoc url = new URL JavaDoc(protocol, webSiteName, webSitePort, scriptPath+"/"+StoreCommentScript()+"?itemId="+itemId+"&to="+toId+"&from="+fromId+"&rating="+rating+"&comment="+comment);
651       return url;
652     }
653     catch (java.net.MalformedURLException JavaDoc e)
654     {
655       System.out.println("Error while generating StoreComment script URL: "+e.getMessage());
656       return null;
657     }
658   }
659
660
661   // ====================================================
662
// ==================== Bidding =======================
663
// ====================================================
664

665   /** URL to the 'Bid now on an Item' script. You must provide the item id.
666    * This will lead to a user authentification.
667    *
668    * @param itemId item identifier
669    *
670    * @return 'Bid Now' script URL
671    */

672   public URL JavaDoc putBidAuth(int itemId)
673   {
674     try
675     {
676       URL JavaDoc url = new URL JavaDoc(protocol, webSiteName, webSitePort, scriptPath+"/"+PutBidAuthScript()+"?itemId="+itemId);
677       return url;
678     }
679     catch (java.net.MalformedURLException JavaDoc 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   /** URL to the 'Put bid on an Item' script.
687    * This is the page the user can access when it has been successfully authenticated.
688    * You must provide the item id, user name and password.
689    *
690    * @param itemId item identifier
691    * @param name user's name
692    * @param pwd user's password
693    *
694    * @return 'Put Bid' script URL
695    */

696   public URL JavaDoc putBid(int itemId, String JavaDoc name, String JavaDoc pwd)
697   {
698     try
699     {
700       name = URLEncoder.encode(name);
701       pwd = URLEncoder.encode(pwd);
702       URL JavaDoc url = new URL JavaDoc(protocol, webSiteName, webSitePort, scriptPath+"/"+PutBidScript()+"?itemId="+itemId+"&nickname="+name+"&password="+pwd);
703       return url;
704     }
705     catch (java.net.MalformedURLException JavaDoc 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   /** URL to the 'Store bid' script. This action really stores a new bid in the database.
713    *
714    * @param itemId item identifier
715    * @param userId user identifier
716    * @param minBid minimum authorized bid
717    * @param bid user's bid
718    * @param maxBid user's maximum bid
719    * @param qty quantity user is asking for
720    * @param maxQty total available quantity for selling
721    *
722    * @return 'Store Bid' script URL
723    */

724   public URL JavaDoc storeBid(int itemId, int userId, float minBid, float bid, float maxBid, int qty, int maxQty)
725   {
726     try
727     {
728       URL JavaDoc url = new URL JavaDoc(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 JavaDoc e)
732     {
733       System.out.println("Error while generating 'Store bid' script URL: "+e.getMessage());
734       return null;
735     }
736   }
737
738
739   // ===================================================
740
// ==================== Buying =======================
741
// ===================================================
742

743   /** URL to the 'Buy now an Item' script. You must provide the item id.
744    * This will lead to a user authentification.
745    *
746    * @param itemId item identifier
747    *
748    * @return 'Buy Now' script URL
749    */

750   public URL JavaDoc buyNowAuth(int itemId)
751   {
752     try
753     {
754       URL JavaDoc url = new URL JavaDoc(protocol, webSiteName, webSitePort, scriptPath+"/"+BuyNowAuthScript()+"?itemId="+itemId);
755       return url;
756     }
757     catch (java.net.MalformedURLException JavaDoc e)
758     {
759       System.out.println("Error while generating 'Buy now auth' script URL: "+e.getMessage());
760       return null;
761     }
762   }
763
764   /** URL to the 'buy now' script. This action displays the item information and ask the user to confirm he want to buy it.
765    *
766    * @param itemId item identifier
767    * @param name user's name
768    * @param pwd user's password
769    *
770    * @return 'Buy Now' script URL
771    */

772   public URL JavaDoc buyNow(int itemId, String JavaDoc name, String JavaDoc pwd)
773   {
774     try
775     {
776       name = URLEncoder.encode(name);
777       pwd = URLEncoder.encode(pwd);
778       URL JavaDoc url = new URL JavaDoc(protocol, webSiteName, webSitePort, scriptPath+"/"+BuyNowScript()+"?itemId="+itemId+"&nickname="+name+"&password="+pwd);
779       return url;
780     }
781     catch (java.net.MalformedURLException JavaDoc e)
782     {
783       System.out.println("Error while generating 'Buy Now' script URL: "+e.getMessage());
784       return null;
785     }
786   }
787
788
789   /** URL to the 'store buy now' script. This action really buys an item and update the database (if authentication is successfull).
790    *
791    * @param itemId item identifier
792    * @param userId user's identifier
793    * @return 'Store Buy Now' script URL
794    */

795   public URL JavaDoc storeBuyNow(int itemId, int userId, int qty, int maxQty)
796   {
797     try
798     {
799       URL JavaDoc url = new URL JavaDoc(protocol, webSiteName, webSitePort, scriptPath+"/"+StoreBuyNowScript()+"?itemId="+itemId+"&userId="+userId+"&qty="+qty+"&maxQty="+maxQty);
800       return url;
801     }
802     catch (java.net.MalformedURLException JavaDoc e)
803     {
804       System.out.println("Error while generating 'Store Buy Now' script URL: "+e.getMessage());
805       return null;
806     }
807   }
808
809
810   // ====================================================
811
// ==================== Selling =======================
812
// ====================================================
813

814   /** URL to the sell page of the web site.
815    *
816    * @return sell page URL
817    */

818   public URL JavaDoc sell()
819   {
820     try
821     {
822       URL JavaDoc url = new URL JavaDoc(protocol, webSiteName, webSitePort, HTMLPath+"/sell.html");
823       return url;
824     }
825     catch (java.net.MalformedURLException JavaDoc e)
826     {
827       System.out.println("Error while generating sell page URL: "+e.getMessage());
828       return null;
829     }
830   }
831
832   /** URL to the 'Select category to sell item' script.
833    * This is the page the user can access when it has been successfully authenticated.
834    * You must provide the user's name and password.
835    *
836    * @param name user's name
837    * @param pwd user's password
838    *
839    * @return 'Select category to sell item' script URL
840    */

841   public URL JavaDoc selectCategoryToSellItem(String JavaDoc name, String JavaDoc pwd)
842   {
843     try
844     {
845       name = URLEncoder.encode(name);
846       pwd = URLEncoder.encode(pwd);
847       URL JavaDoc url = new URL JavaDoc(protocol, webSiteName, webSitePort, scriptPath+"/"+BrowseCategoriesScript()+"?nickname="+name+"&password="+pwd);
848       return url;
849     }
850     catch (java.net.MalformedURLException JavaDoc 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   /** URL to the 'Sell item form' script.
858    * This is the page the user accesses ones it has choosen a category.
859    * You must provide the user id and the category id.
860    *
861    * @param categoryId category identifier
862    * @param userId user identifier
863    *
864    * @return 'Sell item form' script URL
865    */

866   public URL JavaDoc sellItemForm(int categoryId, int userId)
867   {
868     try
869     {
870       URL JavaDoc url = new URL JavaDoc(protocol, webSiteName, webSitePort, scriptPath+"/"+SellItemFormScript()+"?user="+userId+"&category="+categoryId);
871       return url;
872     }
873     catch (java.net.MalformedURLException JavaDoc e)
874     {
875       System.out.println("Error while generating 'Sell item form' script URL: "+e.getMessage());
876       return null;
877     }
878   }
879
880   /** URL to the 'Register item' script. This action really stores a new item in the database.
881    *
882    * @param name item name
883    * @param description item description
884    * @param initialPrice item initial price
885    * @param reservePrice item reserve price (0 if none)
886    * @param buyNow item 'buy now' price (0 if none)
887    * @param duration duration of the auction in days (usually no more than 7 days)
888    * @param quantity quantity to sell of this item
889    * @param userId user identifier
890    * @param categoryId category identifier
891    *
892    * @return 'Register item' script URL
893    */

894   public URL JavaDoc registerItem(String JavaDoc name, String JavaDoc 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 JavaDoc url = new URL JavaDoc(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 JavaDoc e)
908     {
909       System.out.println("Error while generating 'Register item' script URL: "+e.getMessage());
910       return null;
911     }
912   }
913
914   // =====================================================
915
// ==================== About Me =======================
916
// =====================================================
917

918   /** URL to the "About Me" page of the web site.
919    * This leads to a user authentication.
920    *
921    * @return 'About Me' page URL
922    */

923   public URL JavaDoc aboutMe()
924   {
925     try
926     {
927       URL JavaDoc url = new URL JavaDoc(protocol, webSiteName, webSitePort, HTMLPath+"/about_me.html");
928       return url;
929     }
930     catch (java.net.MalformedURLException JavaDoc e)
931     {
932       System.out.println("Error while generating about_me page URL: "+e.getMessage());
933       return null;
934     }
935   }
936
937   /** URL to the 'About Me' script.
938    * This is the page the user can access when it has been successfully authenticated.
939    * You must provide the user's name and password.
940    *
941    * @param name user's name
942    * @param pwd user's password
943    *
944    * @return 'About Me' script URL
945    */

946   public URL JavaDoc aboutMe(String JavaDoc name, String JavaDoc pwd)
947   {
948     try
949     {
950       name = URLEncoder.encode(name);
951       pwd = URLEncoder.encode(pwd);
952       URL JavaDoc url = new URL JavaDoc(protocol, webSiteName, webSitePort, scriptPath+"/"+AboutMeScript()+"?nickname="+name+"&password="+pwd);
953       return url;
954     }
955     catch (java.net.MalformedURLException JavaDoc 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