1 23 24 package org.dbforms.servlets.reports; 25 26 import org.apache.commons.logging.Log; 27 import org.apache.commons.logging.LogFactory; 28 29 import org.dbforms.config.Field; 30 31 32 import org.dbforms.taglib.TextFormatterUtil; 33 import org.dbforms.util.MessageResources; 34 import org.dbforms.util.ParseUtil; 35 import org.dbforms.util.Util; 36 37 import java.io.File ; 38 import java.util.Map ; 39 40 44 import java.sql.Connection ; 45 46 import java.util.Locale ; 47 48 import javax.servlet.ServletContext ; 49 import javax.servlet.http.HttpServletRequest ; 50 51 52 53 59 public class ReportParameter { 60 private static Log logCat = LogFactory.getLog(ReportParameter.class); 61 private Connection connection; 62 private HttpServletRequest request; 63 private Locale locale; 64 private ServletContext context; 65 private String reportPath; 66 private Map attributes; 67 68 76 public ReportParameter(ServletContext context, 77 HttpServletRequest request, 78 Map attributes, 79 Connection connection, 80 String reportPath) { 81 this.context = context; 82 this.request = request; 83 this.connection = connection; 84 this.reportPath = reportPath; 85 this.attributes = attributes; 86 this.locale = MessageResources.getLocale(request); 87 } 88 89 94 public Connection getConnection() { 95 return connection; 96 } 97 98 99 104 public String getContextPath() { 105 return context.getRealPath("") + File.separator; 106 } 107 108 public String getBaseURL() { 109 return Util.getBaseURL(request); 110 } 111 112 119 public String getMessage(String msg) { 120 return MessageResources.getMessage(request, msg); 121 } 122 123 124 131 public String getParameter(String param) { 132 return ParseUtil.getParameter(request, param); 133 } 134 135 142 public Object getAttribute(String key) { 143 return attributes.get(key); 144 } 145 146 151 public String getReportPath() { 152 return reportPath; 153 } 154 155 156 165 public String getStringValue(Object obj, 166 String pattern) { 167 try { 168 Field field = new Field(); 169 field.setTypeByObject(obj); 170 return TextFormatterUtil.FormatText(field, locale, pattern, obj); 171 } catch (Exception e) { 172 logCat.error(e); 173 174 return e.getMessage(); 175 } 176 } 177 178 179 187 public String getStringValue(Object obj) { 188 return getStringValue(obj, null); 189 } 190 } 191 | Popular Tags |