Package com.tubeonfire.ajax.admin

Source Code of com.tubeonfire.ajax.admin.ProcessPage

package com.tubeonfire.ajax.admin;

import java.io.IOException;
import java.util.Calendar;

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

import com.tubeonfire.entity.Page;
import com.tubeonfire.model.admin.PageModel;

@SuppressWarnings("serial")
public class ProcessPage extends HttpServlet {
  public void doGet(HttpServletRequest request, HttpServletResponse response)
      throws IOException {
    String action = request.getParameter("action");
    if (action != null && action.equals("delete")) {
      try {
        String id = request.getParameter("id");
        Page obj = PageModel.getById(id);
        if (obj != null) {
          PageModel.delete(obj);
          response.getWriter().print("");
        } else {
          response.getWriter()
              .print("Action fails ! Page's not exits or has been deleted !");
        }
      } catch (Exception e) {
        response.getWriter().print("Action fails ! Please try again !");
      }

    } else if (action != null && action.equals("deactive")) {
      try {
        String id = request.getParameter("id");
        Page obj = PageModel.getById(id);
        if (obj != null) {
          obj.setUpdated(Calendar.getInstance().getTime());
          obj.setStatus(2);
          PageModel.insert(obj);
          response.getWriter().print("");
        } else {
          response.getWriter()
              .print("Action fails ! Page's not exits or has been deleted !");
        }
      } catch (Exception e) {
        response.getWriter().print("Action fails ! Please try again !");
      }

    } else if (action != null && action.equals("active")) {
      try {
        String id = request.getParameter("id");
        Page obj = PageModel.getById(id);
        if (obj != null) {
          obj.setUpdated(Calendar.getInstance().getTime());
          obj.setStatus(1);
          PageModel.insert(obj);
          response.getWriter().print("");
        } else {
          response.getWriter()
              .print("Action fails ! Page's not exits or has been deleted !");
        }
      } catch (Exception e) {
        response.getWriter().print("Action fails ! Please try again !");
      }

    } else if (action != null && action.equals("delete-all")) {
      try {
        String strIds = (String) request.getParameter("ids");
        String[] ids = strIds.split(",");
        for (int i = 0; i < ids.length; i++) {
          if (!ids[i].isEmpty()) {
            Page obj = PageModel.getById(ids[i]);
            if (obj != null) {
              PageModel.delete(obj);
            }
          }
        }
        response.getWriter().print("");
      } catch (Exception e) {
        response.getWriter().print("Action fails ! Please try again !");
      }
    }
  }
}
TOP

Related Classes of com.tubeonfire.ajax.admin.ProcessPage

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.