1 package org.paneris.jammyjoes.controller; 2 3 import org.melati.template.ServletTemplateContext; 4 import org.melati.util.UTF8URLEncoder; 5 6 public class ParameterProvider { 7 8 ServletTemplateContext context; 9 String[] pathInfo; 10 11 public ParameterProvider(ServletTemplateContext tc, String[] pathInfo) { 12 this.context = tc; 13 this.pathInfo = pathInfo; 14 } 15 16 public String getParam(String param, int pos) { 17 String result = nulled(context.getForm(param)); 18 if (result != null) { 19 return result; 20 } 21 if (pos > -1 && pos < pathInfo.length) { 22 result = nulled(pathInfo[pos]); 23 } 24 if (result != null) { 25 return UTF8URLEncoder.decode(result); 26 } 27 return result; 28 } 29 30 public String nulled(String string) { 31 String result = string == null ? null : string; 32 result = "".equals(string) ? null : result; 33 result = "_".equals(string) ? null : result; 34 return result; 35 } 36 37 public Integer getParamAsInt(String param, int pos) { 38 String in = getParam(param, pos); 39 return in == null ? null : new Integer(in); 40 41 } 42 43 }