📄 confirmorderaction.java
字号:
/*
* Copyright 2006 Borys Burnayev
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.rdacorp.petstore.web.action;
import java.util.Collection;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.apache.struts.action.Action;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;
import com.rdacorp.petstore.domain.CreditCardCompany;
import com.rdacorp.petstore.domain.State;
/**
* @author Borys Burnayev
*/
public class ConfirmOrderAction extends Action {
public ActionForward execute(ActionMapping mapping, ActionForm form, HttpServletRequest request,
HttpServletResponse response) throws Exception {
PetStoreSession session = new PetStoreSession(request.getSession());
PetStoreApplication application = session.getApplication();
OrderSummary summary = new OrderSummary();
MaintainOrderForm maintainOrderForm = (MaintainOrderForm) form;
maintainOrderForm.setCreditCardNumber("1111111111111111");
Collection<CreditCardCompany> ccTypes = application.getCreditCardCompanies();
Integer selectedCCTypeID = maintainOrderForm.getCreditCardType();
CreditCardCompany ccCompany = CreditCardCompany.findByID(ccTypes, selectedCCTypeID);
session.setCreditCardCompany(ccCompany);
summary.setCcType(ccCompany.getName());
summary.setCcNumber(maintainOrderForm.getCreditCardNumber());
String expiration = null;
switch (maintainOrderForm.getExpirationMonth()) {
case 1:
expiration = "January";
break;
case 2:
expiration = "February";
break;
case 3:
expiration = "March";
break;
case 4:
expiration = "April";
break;
case 5:
expiration = "May";
break;
case 6:
expiration = "June";
break;
case 7:
expiration = "July";
break;
case 8:
expiration = "August";
break;
case 9:
expiration = "September";
break;
case 10:
expiration = "October";
break;
case 11:
expiration = "November";
break;
case 12:
expiration = "December";
break;
default:
break;
}
summary.setExpiration(expiration + " " + maintainOrderForm.getExpirationYear());
summary.setBillingName(maintainOrderForm.getBillingFirstName() + " " + maintainOrderForm.getBillingLastName());
String billingAddressLine2 = maintainOrderForm.getBillingAddressLine2();
String billingAddress = maintainOrderForm.getBillingAddressLine1()
+ (billingAddressLine2 != null && billingAddressLine2.trim().length() > 0 ? (", " + billingAddressLine2)
: "");
summary.setBillingAddress(billingAddress);
Collection<State> states = application.getStates();
Integer selectedBillingStateID = Integer.parseInt(maintainOrderForm.getBillingState());
Integer selectedShippingStateID = Integer.parseInt(maintainOrderForm.getShippingState());
State billingState = State.findByID(states, selectedBillingStateID);
State shippingState = State.findByID(states, selectedShippingStateID);
String billingStateDescription = billingState.getDescription();
String shippingStateDescription = shippingState.getDescription();
session.setBillingState(billingState);
session.setShippingState(shippingState);
summary.setBillingCity(maintainOrderForm.getBillingCity() + ", " + billingStateDescription + " "
+ maintainOrderForm.getBillingZip());
summary.setBillingPhone(maintainOrderForm.getBillingPhone());
summary.setShippingName(maintainOrderForm.getShippingFirstName() + " " + maintainOrderForm.getShippingLastName());
String shippingAddressLine2 = maintainOrderForm.getShippingAddressLine2();
String shippingAddress = maintainOrderForm.getShippingAddressLine1()
+ (shippingAddressLine2 != null && shippingAddressLine2.trim().length() > 0 ? (", " + shippingAddressLine2)
: "");
summary.setShippingAddress(shippingAddress);
summary.setShippingCity(maintainOrderForm.getShippingCity() + ", " + shippingStateDescription + " "
+ maintainOrderForm.getShippingZip());
summary.setShippingPhone(maintainOrderForm.getShippingPhone());
request.setAttribute("orderSummary", summary);
return mapping.findForward("success");
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -