KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > infoglue > cms > util > URLHelper


1 package org.infoglue.cms.util;
2
3 import java.util.HashMap JavaDoc;
4 import java.util.Iterator JavaDoc;
5 import java.util.Map JavaDoc;
6
7 public class URLHelper {
8     private final static String JavaDoc CONTENT_ID = "contentId";
9     private final static String JavaDoc SITE_NODE_ID = "siteNodeId";
10     private final static String JavaDoc LANGUAGE_ID = "languageId";
11     
12     private String JavaDoc baseURL;
13     private Map JavaDoc parameters = new HashMap JavaDoc();
14     
15     /*
16      *
17      */

18     public URLHelper(String JavaDoc baseURL, Integer JavaDoc contentID, Integer JavaDoc siteNodeID, Integer JavaDoc languageID) {
19         this.baseURL = baseURL;
20         addParameter(CONTENT_ID, contentID.toString());
21         addParameter(SITE_NODE_ID, siteNodeID.toString());
22         addParameter(LANGUAGE_ID, languageID.toString());
23     }
24     
25     
26     
27     /**
28      *
29      */

30     public String JavaDoc getURL() {
31         if(!parameters.isEmpty()) {
32             StringBuffer JavaDoc sb = new StringBuffer JavaDoc();
33             for(Iterator JavaDoc i = parameters.keySet().iterator(); i.hasNext(); ) {
34                 String JavaDoc name = (String JavaDoc) i.next();
35                 String JavaDoc value = (String JavaDoc) parameters.get(name);
36                 String JavaDoc parameter = name + "=" + value;
37                 sb.append(parameter + (i.hasNext() ? "&" : ""));
38             }
39             return baseURL + "?" + sb.toString();
40         }
41         return baseURL;
42     }
43     
44     /**
45      *
46      */

47     public void addParameter(String JavaDoc name, String JavaDoc value) {
48         parameters.put(name, value);
49     }
50 }
51
Popular Tags