1 27 package olstore.util; 28 29 import javax.servlet.http.HttpServletRequest; 30 31 import java.math.BigDecimal; 32 import java.text.DecimalFormat; 33 34 37 public class WebUtils { 38 39 public static final String ITEMURL = "/olstore/views/ItemView.jsp?itemPK="; 40 private static DecimalFormat format = new DecimalFormat ( "###,###,###.00" ); 41 42 46 public static boolean isEmpty ( String str ) { 47 if ( str == null || str.equals("") ) { 48 return true; 49 } else { 50 return false; 51 } 52 } 53 54 60 public static String getValue ( String name, HttpServletRequest request ) { 61 String value = null; 62 value = (String) request.getAttribute ( name ); 63 if ( ! isEmpty(value) ) { 64 return value; 65 } 66 value = (String) request.getParameter ( name ); 67 if ( isEmpty(value) ) { 68 return null; 69 } 70 return value; 71 } 72 73 public static String getItemURL ( String itemPK ) { 74 return ITEMURL + itemPK ; 75 } 76 77 public static String getItemURL ( Integer itemPK ) { 78 return getItemURL ( itemPK.toString() ); 79 } 80 81 public static String getItemInterestURL ( Integer itemPK ) { 82 return getItemURL ( itemPK ) + "&interest=true"; 83 } 84 85 public static String getItemPurchaseURL ( Integer itemPK ) { 86 return getItemURL ( itemPK ) + "&purchase=true"; 87 } 88 89 public static String getItemEditURL ( String itemPK ) { 90 return "/olstore/admin/createItem.do?itemId="+itemPK ; 91 } 92 93 public static String getItemEditURL ( Integer itemPK ) { 94 return getItemEditURL ( itemPK.toString() ) ; 95 } 96 97 public static String getTypeViewURL ( String type ) { 98 return "/olstore/views/index.jsp?type="+type; 99 } 100 101 105 109 public static String costDisplay (BigDecimal f){ 110 return format.format ( f.doubleValue() ); 111 } 112 } 113 | Popular Tags |