1 package org.infoglue.cms.util; 2 3 import java.util.HashMap ; 4 import java.util.Iterator ; 5 import java.util.Map ; 6 7 public class URLHelper { 8 private final static String CONTENT_ID = "contentId"; 9 private final static String SITE_NODE_ID = "siteNodeId"; 10 private final static String LANGUAGE_ID = "languageId"; 11 12 private String baseURL; 13 private Map parameters = new HashMap (); 14 15 18 public URLHelper(String baseURL, Integer contentID, Integer siteNodeID, Integer 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 30 public String getURL() { 31 if(!parameters.isEmpty()) { 32 StringBuffer sb = new StringBuffer (); 33 for(Iterator i = parameters.keySet().iterator(); i.hasNext(); ) { 34 String name = (String ) i.next(); 35 String value = (String ) parameters.get(name); 36 String parameter = name + "=" + value; 37 sb.append(parameter + (i.hasNext() ? "&" : "")); 38 } 39 return baseURL + "?" + sb.toString(); 40 } 41 return baseURL; 42 } 43 44 47 public void addParameter(String name, String value) { 48 parameters.put(name, value); 49 } 50 } 51 | Popular Tags |