// Decompiled by Jad v1.5.7g. Copyright 2000 Pavel Kouznetsov.
// Jad home page: http://www.geocities.com/SiliconValley/Bridge/8617/jad.html
// Decompiler options: packimports(3) fieldsfirst ansi 
// Source File Name:   AdContentAction.java

package com.keyshop.shop.channel.controller;

import com.keyshop.pub.controller.PubAction;
import com.keyshop.pub.model.PubBean;
import com.keyshop.pub.util.*;
import com.keyshop.shop.channel.bo.AdContentBO;
import com.keyshop.shop.channel.model.AdContent;
import com.keyshop.shop.channel.model.AdElement;
import com.keyshop.shop.channel.util.ChannelConst;
import java.io.File;
import java.util.*;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.apache.struts.action.*;
import org.apache.struts.upload.FormFile;
import org.apache.struts.upload.MultipartRequestHandler;

// Referenced classes of package com.keyshop.shop.channel.controller:
//            AdContentForm

public class AdContentAction extends PubAction
{

    public AdContentAction()
    {
    }

    public void initClassName()
    {
        boClass = "com.keyshop.shop.channel.bo.AdContentBO";
        beanClass = "com.keyshop.shop.channel.model.AdContent";
        formBeanClass = "com.keyshop.shop.channel.controller.AdContentForm";
    }

    public ActionForward performChangecategory(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response)
    {
        return mapping.findForward("add");
    }

    public ActionForward performChange(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response)
    {
        performEdit(mapping, form, request, response);
        return mapping.findForward("add");
    }

    public ActionForward performEdit(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response)
    {
        AdContentForm iform = (AdContentForm)form;
        try
        {

        }
        catch(Exception ex)
        {
            ex.printStackTrace();
        }
        iform.setPageType("edit");
        return mapping.findForward("add");
    }

    private boolean updateAdElement(FormFile file, AdElement el)
    {
        int w = 0;
        int h = 0;
        String width = httpRequest.getParameter("width" + el.getColumIndex());
        String height = httpRequest.getParameter("height" + el.getColumIndex());
        String url = httpRequest.getParameter("linkurl" + el.getColumIndex());
    
        try
        {
            if(file != null && file.getFileData() != null && file.getFileSize() > 0)
            {
                String contentType = file.getContentType();
                if(contentType.indexOf(ChannelConst.FILETYPE_FLASH) != -1)
                    el.setFileType(ChannelConst.FILETYPE_FLASH);
                else
                    el.setFileType(ChannelConst.FILETYPE_IMG);
                String currentFilePath = fileRoot + File.separator + el.getFileType() + File.separator + el.getColumIndex();
                if(!currentFilePath.endsWith("/"))
                    currentFilePath = currentFilePath + "/";
                String root = httpRequest.getRealPath(currentFilePath);
                String oldFilePath = "";
                if(!StringUtil.isEmpty(el.getFileName()))
                    oldFilePath = httpRequest.getRealPath(el.getFileName());
                File rootDirectory = new File(root);
                if(!rootDirectory.exists() || !rootDirectory.isDirectory())
                    rootDirectory.mkdirs();
                if(file != null && file.getFileSize() > 0)
                {
                    String fileName = FileUtil.updateImageFileByRelPath(root, oldFilePath, file);
                    el.setFileName(currentFilePath + fileName);
                }
            }
        }
        catch(Exception ex)
        {
            ex.printStackTrace();
        }
        return true;
    }

    protected String getSelectSQL()
    {
        String sql = "select a from AdContent as a ";
   
        return sql;
    }

    public ActionForward execute(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response)
    {
        try
        {
            actionType = request.getParameter("actionType");
            if(!StringUtil.isEmpty(actionType) && !actionType.equalsIgnoreCase("add") && !actionType.equalsIgnoreCase("list") && !actionType.equalsIgnoreCase("edit") && !actionType.equalsIgnoreCase("update") && !actionType.equalsIgnoreCase("save"))
                actionType.equalsIgnoreCase("remove");
        }
        catch(Exception ex)
        {
            ex.printStackTrace();
        }
        return super.execute(mapping, form, request, response);
    }

    protected boolean isObjectExisted(PubBean bean)
    {
        if(bean != null)
        {
            AdContent ad = (AdContent)bean;
      
        }
        return false;
    }
}
