📄 pageaddressaction.java
字号:
/*******************************************************************************
* ***** BEGIN LICENSE BLOCK Version: MPL 1.1
*
* The contents of this file are subject to the Mozilla Public License Version
* 1.1 (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.mozilla.org/MPL/
*
* Software distributed under the License is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License for
* the specific language governing rights and limitations under the License.
*
* The Original Code is the OpenCustomer CRM.
*
* The Initial Developer of the Original Code is Thomas Bader (Bader & Jene
* Software-Ingenieurb黵o). Portions created by the Initial Developer are
* Copyright (C) 2005 the Initial Developer. All Rights Reserved.
*
* Contributor(s): Thomas Bader <thomas.bader@bader-jene.de>
*
* ***** END LICENSE BLOCK *****
*/
package org.opencustomer.application.web.module.crm.company.edit;
import java.io.IOException;
import java.util.List;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.apache.log4j.Logger;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;
import org.apache.struts.action.ActionMessages;
import org.opencustomer.application.db.vo.crm.AddressVO;
import org.opencustomer.application.db.vo.crm.CompanyVO;
import org.opencustomer.application.web.module.crm.company.Constants;
public class PageAddressAction extends DefaultPageAction<PageAddressForm>
{
private static Logger log = Logger.getLogger(PageAddressAction.class);
public ActionForward execute(ActionMapping mapping, PageAddressForm form, HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException
{
int status = STATUS_DEFAULT;
request.getSession().setAttribute(Constants.COMPANY_PAGE, PAGE_ADDRESSES);
ActionMessages errors = new ActionMessages();
if (this.isTokenValid(request) && (form.getDoSave() != null || form.isAnyPage()))
{
CompanyVO company = (CompanyVO) request.getSession().getAttribute(Constants.COMPANY_COMPANY);
List<AddressVO> addresses = (List<AddressVO>) request.getSession().getAttribute(Constants.COMPANY_ADDRESSES);
if (log.isDebugEnabled())
log.debug("save button pressed");
AddressVO companyAddress = getAddressVO(addresses, AddressVO.Type.COMPANY, true);
if (companyAddress != null)
{
companyAddress.setName1(form.getCompanyAddressName1());
companyAddress.setName2(form.getCompanyAddressName2());
companyAddress.setName3(form.getCompanyAddressName3());
companyAddress.setStreet(form.getCompanyAddressStreet());
companyAddress.setZip(form.getCompanyAddressZip());
companyAddress.setCity(form.getCompanyAddressCity());
}
AddressVO postalAddress = getAddressVO(addresses, AddressVO.Type.POSTAL, true);
if (postalAddress != null)
{
postalAddress.setName1(form.getPostalAddressName1());
postalAddress.setName2(form.getPostalAddressName2());
postalAddress.setName3(form.getPostalAddressName3());
postalAddress.setStreet(form.getPostalAddressStreet());
postalAddress.setPostbox(form.getPostalAddressPostbox());
postalAddress.setZip(form.getPostalAddressZip());
postalAddress.setCity(form.getPostalAddressCity());
}
AddressVO billingAddress = getAddressVO(addresses, AddressVO.Type.BILLING, true);
if (billingAddress != null)
{
billingAddress.setName1(form.getBillingAddressName1());
billingAddress.setName2(form.getBillingAddressName2());
billingAddress.setName3(form.getBillingAddressName3());
billingAddress.setStreet(form.getBillingAddressStreet());
billingAddress.setPostbox(form.getBillingAddressPostbox());
billingAddress.setZip(form.getBillingAddressZip());
billingAddress.setCity(form.getBillingAddressCity());
}
AddressVO deliveryAddress = getAddressVO(addresses, AddressVO.Type.BILLING, true);
if (deliveryAddress != null)
{
deliveryAddress.setName1(form.getDeliveryAddressName1());
deliveryAddress.setName2(form.getDeliveryAddressName2());
deliveryAddress.setName3(form.getDeliveryAddressName3());
deliveryAddress.setStreet(form.getDeliveryAddressStreet());
deliveryAddress.setZip(form.getDeliveryAddressZip());
deliveryAddress.setCity(form.getDeliveryAddressCity());
}
if (form.isAnyPage())
status = STATUS_PAGE;
else
status = STATUS_SAVE;
}
else if (this.isTokenValid(request) && form.getDoCancel() != null)
{
if (log.isDebugEnabled())
log.debug("cancel button pressed");
status = STATUS_BACK;
}
else if (this.isTokenValid(request) && form.getDoDelete() != null)
{
if (log.isDebugEnabled())
log.debug("delete button pressed");
status = STATUS_DELETE;
}
else
{
if (log.isDebugEnabled())
log.debug("fill form from session");
CompanyVO company = (CompanyVO) request.getSession().getAttribute(Constants.COMPANY_COMPANY);
List<AddressVO> addresses = (List<AddressVO>) request.getSession().getAttribute(Constants.COMPANY_ADDRESSES);
AddressVO companyAddress = getAddressVO(addresses, AddressVO.Type.COMPANY, false);
if (companyAddress != null)
{
form.setCompanyAddressName1(companyAddress.getName1());
form.setCompanyAddressName2(companyAddress.getName2());
form.setCompanyAddressName3(companyAddress.getName3());
form.setCompanyAddressStreet(companyAddress.getStreet());
form.setCompanyAddressZip(companyAddress.getZip());
form.setCompanyAddressCity(companyAddress.getCity());
}
AddressVO postalAddress = getAddressVO(addresses, AddressVO.Type.POSTAL, false);
if (postalAddress != null)
{
form.setPostalAddressName1(postalAddress.getName1());
form.setPostalAddressName2(postalAddress.getName2());
form.setPostalAddressName3(postalAddress.getName3());
form.setPostalAddressStreet(postalAddress.getStreet());
form.setPostalAddressPostbox(postalAddress.getPostbox());
form.setPostalAddressZip(postalAddress.getZip());
form.setPostalAddressCity(postalAddress.getCity());
}
AddressVO deliveryAddress = getAddressVO(addresses, AddressVO.Type.DELIVERY, false);
if (deliveryAddress != null)
{
form.setDeliveryAddressName1(deliveryAddress.getName1());
form.setDeliveryAddressName2(deliveryAddress.getName2());
form.setDeliveryAddressName3(deliveryAddress.getName3());
form.setDeliveryAddressStreet(deliveryAddress.getStreet());
form.setDeliveryAddressZip(deliveryAddress.getZip());
form.setDeliveryAddressCity(deliveryAddress.getCity());
}
AddressVO billingAddress = getAddressVO(addresses, AddressVO.Type.BILLING, false);
if (billingAddress != null)
{
form.setBillingAddressName1(billingAddress.getName1());
form.setBillingAddressName2(billingAddress.getName2());
form.setBillingAddressName3(billingAddress.getName3());
form.setBillingAddressStreet(billingAddress.getStreet());
form.setBillingAddressPostbox(billingAddress.getPostbox());
form.setBillingAddressZip(billingAddress.getZip());
form.setBillingAddressCity(billingAddress.getCity());
}
}
if (!errors.isEmpty())
saveErrors(request, errors);
if (log.isDebugEnabled())
log.debug("status = " + status);
switch (status)
{
case STATUS_BACK:
SaveAction.removeAttributes(request);
return mapping.findForward("back");
case STATUS_DELETE:
return mapping.findForward("company.edit.delete");
case STATUS_SAVE:
return mapping.findForward("save");
default:
return findPageForward(mapping, form);
}
}
private AddressVO getAddressVO(List<AddressVO> addresses, AddressVO.Type type, boolean create)
{
AddressVO foundValue = null;
for (AddressVO address : addresses)
{
if (type.equals(address.getType()))
{
if (log.isDebugEnabled())
log.debug("address found for " + type);
foundValue = address;
break;
}
}
if (create && foundValue == null)
{
if (log.isDebugEnabled())
log.debug("create address for " + type);
foundValue = new AddressVO();
foundValue.setType(type);
addresses.add(foundValue);
}
return foundValue;
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -