⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 subcategoryactions.java

📁 噶额外噶外骨骼感广泛高热感 就 啊啊
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
/*
 * @author                        : Sujatha
 * @Version                       : 1.0
 *
 * Development Environment        : Oracle9i JDeveloper
 * Name of the File               : SubCategoryActions.java
 * Creation/Modification History  :
 *
 * Sujatha   16-Jan-2003      Created
 *
 */
package oracle.otnsamples.vsm.actions.owner;


// IO and servlet APIs
import java.io.IOException;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import oracle.otnsamples.util.MessageCache;
import oracle.otnsamples.util.ServiceLocator;
import oracle.otnsamples.vsm.services.Administration;
import oracle.otnsamples.vsm.services.AdministrationHome;
import oracle.otnsamples.vsm.services.CategoryException;
import oracle.otnsamples.vsm.services.ShopException;
import oracle.otnsamples.vsm.services.ShopOwner;
import oracle.otnsamples.vsm.services.ShopOwnerHome;
import oracle.otnsamples.vsm.services.data.Category;
import oracle.otnsamples.vsm.services.data.Shop;
import oracle.otnsamples.vsm.services.data.SubCategory;

import org.apache.struts.action.ActionError;
import org.apache.struts.action.ActionErrors;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;
import org.apache.struts.actions.DispatchAction;


/**
 * This action class is used to maintain subcategory information like add, edit
 *  or delete subcategories.
 *  
 * @author Sujatha
 * @version 1.0
 */
public class SubCategoryActions extends DispatchAction {
  /**
   * This is the action called from the Struts framework to retrieve the
   * category associated with the shop. This category will be required to add
   * subcategory information.
   *
   * @param mapping The ActionMapping used to select this instance.
   * @param form The optional ActionForm bean for this request.
   * @param request The HTTP Request we are processing.
   * @param response The HTTP Response we are processing.
   */
  public ActionForward addSubCategoryForm(
                                          ActionMapping mapping, ActionForm form,
                                          HttpServletRequest request,
                                          HttpServletResponse response)
                                          throws IOException, ServletException {

    ShopOwnerHome shopHome       = null;
    ShopOwner shopBean           = null;
    AdministrationHome adminHome = null;
    Administration adminBean     = null;
    Shop shop                    = null;
    ActionForward forward        = mapping.findForward("display");
    Category category            = null;

    try {

      String langID = request.getLocale().getLanguage();
      shopHome =
        (ShopOwnerHome) ServiceLocator.getLocator().getService("ShopOwner");
      shopBean   = shopHome.create();

      // Fetch the category of the shop
      shop =
        shopBean.getShopDetails(
                                (String) request.getSession().getAttribute("shopID"),
                                langID);
      adminHome =
        (AdministrationHome) ServiceLocator.getLocator().getService("Administration");
      adminBean  = adminHome.create();

      // Get the category details
      category = adminBean.findCategory(shop.getCategoryId(), langID);
      request.setAttribute("category", category);

    } catch(ShopException ex) {
      servlet.log("EditShopDetailsFormError", ex);
      ActionErrors errors = new ActionErrors();
      errors.add("ShopError", new ActionError("common.error", ex.getMessage()));
      saveErrors(request, errors);

      return mapping.findForward("error");
    } catch(Exception ex) {
      servlet.log("EditShopDetailsFormError", ex);
      ActionErrors errors = new ActionErrors();
      errors.add("ShopError", new ActionError("common.error", ex.getMessage()));
      saveErrors(request, errors);

      return mapping.findForward("error");
    } finally {

      try {

        if(shopBean != null) {
          shopBean.remove();
        }

        if(adminBean != null) {
          adminBean.remove();
        }
      } catch(Exception ex) {
      }
    }

    return forward;
  }
  /**
   * This is the action called from the Struts framework to add subcategories
   *
   * @param mapping The ActionMapping used to select this instance.
   * @param form The optional ActionForm bean for this request.
   * @param request The HTTP Request we are processing.
   * @param response The HTTP Response we are processing.
   */
  public ActionForward addSubCategory(
                                      ActionMapping mapping, ActionForm form,
                                      HttpServletRequest request,
                                      HttpServletResponse response)
                               throws IOException, 
                                      ServletException {

    ShopOwnerHome shopHome = null;
    ShopOwner shopBean     = null;
    Shop shop              = null;
    String[] subCatNames   = null;
    String catID           = (String) request.getParameter("catID");
    String shopID          =
      (String) request.getSession().getAttribute("shopID");
    ActionForward forward  = mapping.findForward("success");

    try {

      String langID = request.getLocale().getLanguage();
      shopHome =
        (ShopOwnerHome) ServiceLocator.getLocator().getService("ShopOwner");
      shopBean   = shopHome.create();

      // Get the list of subcategory names specified by user
      subCatNames = (String[]) request.getParameterValues("subCatNames");

      // Construct value object to pass subcategory information to the subcategory
      // service
      SubCategory subCategory =
        new SubCategory(null, shopID, null, catID, langID);

      for(int i = 0; i < subCatNames.length; i++) {
        subCategory.setName(subCatNames [ i ]);
        shopBean.addSubcategory(subCategory);
      }

      request.setAttribute(
                           "message",
                           MessageCache.getMessage(
                                                   "message.addsubcategory.success",
                                                   getLocale(request)));

    } catch(CategoryException ex) {
      servlet.log("AddSubCategoryError", ex);    
      request.setAttribute(
                           "message",
                           MessageCache.getMessage(
                                                   ex.getMessageCode(),
                                                   getLocale(request)));

      Category category =
        new Category(catID, request.getParameter("catName"), null, null);
      request.setAttribute("category", category);
      forward = mapping.findForward("display");
    } catch(Exception ex) {
      servlet.log("AddSubCategoryError", ex);    
      ActionErrors errors = new ActionErrors();
      errors.add("ShopError", new ActionError("common.error", ex.getMessage()));
      saveErrors(request, errors);

      return mapping.findForward("error");
    } finally {

      try {

        if(shopBean != null) {
          shopBean.remove();
        }
      } catch(Exception ex) {
      }
    }

    return forward;
  }
  /**
   * This is the action called from the Struts framework to get the list of
   * subcategories associated with this shop
   *
   * @param mapping The ActionMapping used to select this instance.
   * @param form The optional ActionForm bean for this request.
   * @param request The HTTP Request we are processing.
   * @param response The HTTP Response we are processing.
   */
  public ActionForward listSubCategoryForm(
                                           ActionMapping mapping,
                                           ActionForm form,
                                           HttpServletRequest request,
                                           HttpServletResponse response)
                                    throws IOException, 
                                           ServletException {

    ShopOwnerHome shopHome       = null;
    ShopOwner shopBean           = null;
    AdministrationHome adminHome = null;
    Administration adminBean     = null;
    Shop shop                    = null;
    ActionForward forward        = mapping.findForward("manageSubCatForm");
    Category category            = null;

    try {

      String langID = request.getLocale().getLanguage();
      shopHome =
        (ShopOwnerHome) ServiceLocator.getLocator().getService("ShopOwner");
      shopBean = shopHome.create();

      SubCategory[] subCategories =
        shopBean.getSubCategories(

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -