?? shopservlet.java
字號(hào):
if (shoppingCart == null) {
shoppingCart = new Vector();
cartMap = new HashMap();
}
shoppingCart.add(itemID);
cartMap.put(itemID, "");
sessioncache.setAttribute(sessionId, "opera.cart", cartMap);
} catch (ShopException ex) {
request.setAttribute("opera.exception", ex.getMessage());
}
}
protected void doValidatePayment(
HttpServletRequest request,
HttpServletResponse response)
throws ServletException, IOException, ShopException {
String shipName = request.getParameter("ship_name");
String totalPurchase = request.getParameter("total_purchase");
//not doing validation at this time
//save sensitive information
//should not forward this information
String jspPath = request.getParameter("jsp_path");
if (jspPath == null)
jspPath = "shop/confirmation.jsp";
forwardToJSP(request, response, jspPath);
}
protected void doConfirmPayment(
HttpServletRequest request,
HttpServletResponse response)
throws ServletException, IOException, ShopException {
//changed the credit card
//if everything's going smooothly then do this
String jspPath = request.getParameter("jsp_path");
if (jspPath == null)
jspPath = "/shop/index.jsp";
HashMap cart = (HashMap) sessioncache.getAttribute(sessionId, "opera.cart");
String userID = (String) sessioncache.getAttribute(sessionId, "userid");
System.out.println("In Confirm Payment : userid : "+userID);
String totalPurchase = request.getParameter("total_purchase");
String shopID = request.getParameter("shop_id");
String paymentMethod = request.getParameter("payment_method");
int licenseType = Const.FIXED_USE_LICENSE_TYPE;
if (userID != null && cart != null) {
//save to db
String shopSQL = "INSERT INTO SHOP_TRANSACTION (transdate,userid, totalpurchase) VALUES(?,?,?)";
String insertLicenseSQL = "INSERT INTO OPERA_LICENSE_INFO( shopid,contentid,userid,licensetype,total,remaining) VALUES (?,?,?,?,?,?)";
String updateLicenseSQL = "UPDATE OPERA_LICENSE_INFO SET total=?,remaining=? WHERE shopid=? AND contentid=? AND userid=?";
String verifyLicenseSQL = "SELECT contentid,licensetype,total,remaining FROM OPERA_LICENSE_INFO WHERE shopid=? AND contentid=? AND userid=?";
int[] verifyTypes = new int[] {java.sql.Types.VARCHAR, java.sql.Types.INTEGER,java.sql.Types.INTEGER,java.sql.Types.INTEGER};
Iterator iter = cart.keySet().iterator();
String[] qtys = new String[cart.size()];
String[] items = new String[cart.size()];
java.sql.Date today = new java.sql.Date(new java.util.Date().getTime());
java.util.HashMap rightsCart = (java.util.HashMap) sessioncache.getAttribute(sessionId, "opera.rights_cart");
// if rightsCart is null, ERROR!
for (int i=0; iter.hasNext(); i++) {
items[i] = (String)iter.next();
qtys[i] = (String) cart.get(items[i]);
try {
RightsInfo rightsInfo = (RightsInfo) rightsCart.get(items[i]);
printRightsInfo(rightsInfo);
sms.updateFixedRightsInfo(rightsInfo);
/*String[] existingLic = DBUtil.getRecord(verifyLicenseSQL,verifyTypes,null, new String[] {shopID,items[i],userID});
if (existingLic != null) {
int quantity = Integer.parseInt(qtys[i]);
int total = Integer.parseInt(existingLic[2]) + quantity;
int remaining = Integer.parseInt(existingLic[3]) + quantity;
DBUtil.execute(updateLicenseSQL, new Object[] {new Integer(total), new Integer(remaining),shopID,items[i],userID});
} else {
DBUtil.execute( insertLicenseSQL, new Object[] {shopID, items[i], userID, new Integer(licenseType),qtys[i],qtys[i]});
}*/
} catch (Exception ex) {
ex.printStackTrace();
}
}
try {
DBUtil.execute(shopSQL, new Object[] {today, userID,Float.valueOf(totalPurchase)} );
} catch (Exception ex) {
ex.printStackTrace();
}
//HttpSession session = request.getSession();
//session.removeAttribute("userid");
//session.removeAttribute("opera.signin");
sessioncache.removeAttribute(sessionId, "opera.cart");
sessioncache.removeAttribute(sessionId, "opera.rights_cart");
sessioncache.removeAttribute(sessionId, "opera.coupon_id");
sessioncache.removeAttribute(sessionId, "opera.coupon");
sessioncache.setAttribute(sessionId, "opera.items_purchased", cart);
/*
int qty = 1;
String errorURL = request.getParameter("errorurl");
for (int i=0; i<items.length; i++) {
try {
qty = Integer.parseInt(qtys[i]);
LicenseInfo licInfo = new LicenseInfo(shopID, items[i],
userID, Const.FIXED_USE_LICENSE_TYPE, qty, qty, null, null);
licInfo.save();
} catch (Exception ex) {
ex.printStackTrace();
}
}
*/
}
forwardToJSP(request, response, jspPath);
}
protected void doBuyRights(
HttpServletRequest request,
HttpServletResponse response)
throws ServletException, IOException, ShopException, SQLException {
String jspPath = request.getParameter("jsp_path");
if (jspPath == null)
jspPath = "/shop/index.jsp";
System.out.println("Print inputs to ShopServlet : doBuyRights ");
String userID = request.getParameter("userID");
System.out.println("In doBuyRights : userID : "+userID);
String itemID = request.getParameter("item_id");
System.out.println("In doBuyRights : item_id : "+itemID);
String itemTitle = request.getParameter("item_title");
logStrMessage("itemTitle",itemTitle);
int numRights = 1;
String playMode = request.getParameter("PlayMode");
logStrMessage("playMode",playMode);
String numPlays = request.getParameter("NumPlays");
int numPlaysInt = 0;
int numRecordInt = 0;
logStrMessage("numPlays", numPlays);
//System.out.println("Play Mode "+ ((playMode==null)?"NULL!!":playMode));
String numDays = null;
if (numPlays == null) {
numPlays = "0";
numDays = request.getParameter("NumDays");
logStrMessage("numDays", numDays);
} else {
numPlaysInt = Integer.parseInt(numPlays);
}
String recordFlag = request.getParameter("Record");
logStrMessage("recordFlag",recordFlag);
String numRecord = null;
if (recordFlag != null) {
numRecord = request.getParameter("NumRecord");
if (numRecord != null)
numRecordInt = Integer.parseInt(numRecord);
else
numRecordInt = 5; //default value of 5 records
numRights = numRights+1;
System.out.println("numRights is "+numRights);
} else
numRecord = "0";
int totalItems = 0;
java.util.HashMap cart = (java.util.HashMap) sessioncache.getAttribute(sessionId, "opera.cart");
if (cart != null)
totalItems = cart.size();
else
cart = new java.util.HashMap();
cart.put(itemID, "1");
sessioncache.setAttribute(sessionId, "opera.cart", cart);
//System.out.println("Set session cart attribute.");
java.util.Hashtable historyTable = (java.util.Hashtable) sessioncache.getAttribute(sessionId, "opera.user_cart_history");
if (historyTable == null)
historyTable = new java.util.Hashtable();
if (itemID != null && itemTitle != null)
historyTable.put(itemID, itemTitle);
sessioncache.setAttribute(sessionId, "opera.user_cart_history", historyTable);
// Update related items table
java.util.Hashtable relProd = (java.util.Hashtable) sessioncache.getAttribute(sessionId, "opera.rel_items");
if (relProd == null) {
relProd = new Hashtable();
sessioncache.setAttribute(sessionId, "opera.rel_items", relProd);
}
// Remove the current item from the list of related items
relProd.remove(itemID);
// Get the related item
String relItemID = DBUtil.getField("SELECT relprod FROM OPERA_CONTENT_METADATA WHERE contentid = '" +
itemID + "'", java.sql.Types.VARCHAR, null);
if (relItemID != null && ! "".equals(relItemID) && cart.get(relItemID) == null) {
relProd.put(relItemID, "");
}
java.util.HashMap rightsCart = (java.util.HashMap) sessioncache.getAttribute(sessionId, "opera.rights_cart");
if (rightsCart == null)
rightsCart = new java.util.HashMap();
RightsInfo rightsInfo = conductor1.getUserRightsForContent(userID,itemID);
if (rightsInfo != null) {
System.out.println("ShopServlet: doBuyRights : rightsInfo is not null");
rightsInfo.remainingRights += 1;
if (rightsInfo.verbElements !=null){
boolean fwdInsert = false;
boolean revInsert = false;
for (int k=0; k< rightsInfo.verbElements.length; k++) {
if (rightsInfo.verbElements[k].verbName.equals("SimplePlay") && rightsInfo.verbElements[k].verbArgName.equals("COUNT")) {
int existingPlayNum = Integer.parseInt(rightsInfo.verbElements[k].verbArgValue);
Integer argVal = new Integer(existingPlayNum+numPlaysInt);
rightsInfo.verbElements[k].verbArgValue = argVal.toString();
}
if (playMode.equals("UnrestrictedPlay")){
if (rightsInfo.verbElements[k].verbName.equals("ForwardPlay") && rightsInfo.verbElements[k].verbArgName.equals("COUNT")) {
int existingPlayNum = Integer.parseInt(rightsInfo.verbElements[k].verbArgValue);
Integer argVal = new Integer(existingPlayNum+numPlaysInt);
rightsInfo.verbElements[k].verbArgValue = argVal.toString();
?? 快捷鍵說(shuō)明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號(hào)
Ctrl + =
減小字號(hào)
Ctrl + -