Package

Source Code of PortletControllerServlet

import java.io.IOException;
import java.io.PrintWriter;
//import java.text.DateFormat;
import java.lang.Integer;
//import java.util.Enumeration;

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

import include.dbcommunication.*;
import include.auth.Validation;


// import database.*;

/**
* Servlet implementation class for Servlet: MainServlet2
*
*/
@SuppressWarnings("serial")
public class PortletControllerServlet extends javax.servlet.http.HttpServlet implements
    javax.servlet.Servlet {


  public PortletControllerServlet() {
    super();
  }

  protected void doPost(HttpServletRequest request,
      HttpServletResponse response) throws ServletException, IOException {
   
    PrintWriter out = response.getWriter();
    utils.Utils u = new utils.Utils();

    String rid = request.getParameter("rid");
    String sid = request.getParameter("sid");
    String portletAction = request.getParameter("action");

    System.out.println("RID: " + rid);
    System.out.println("SID: "+ sid);
    System.out.println("ACTION: "+portletAction);
    Validation v = new Validation();
    String login = v.validate(sid);
    System.out.println("LOGIN: "+login);
    response.setContentType("text/xml");

    if (rid==null || portletAction == null)
      return;

    out.print("<?xml version=\"1.0\" encoding=\"UTF-8\"?>");
    out.print("<portlet-response>");
    System.out.println("<rid>" + u.getSafeName(rid) + "</rid>");
    out.print("<rid>" + u.getSafeName(rid) + "</rid>");
   

    if (portletAction.equals("conf_create")) {
      System.out.println("tworzymy nowe okno");
      WindowAdder communicator = new WindowAdder();
      communicator.addWindow(sid, rid);
      System.out.println("stworzylem");
     
    } else if (portletAction.equals("conf_close")) {
      System.out.println("[pctl] WindowClose");
      WindowRemover communicator = new WindowRemover();
      communicator.removeWindow(sid, rid);
     
    } else if (portletAction.equals("conf_resize")) {
     
      DesktopUpdater desktopCommunicator = new DesktopUpdater();
      village.webservice.user.Window newWindow[] = new village.webservice.user.Window[1];     
      DataGetter dataCommunicator = new DataGetter();
      Integer i = 0;
      village.webservice.user.Window list[] = null;
      village.webservice.user.UserData ud = dataCommunicator.get(sid);
      list = ud.getWindows();
      /* find the window to resize */
      String currentRid = list[i].getRid();
      if (currentRid.indexOf('@') != -1)
        currentRid = currentRid.substring(0, currentRid.indexOf('@'));
      System.out.println("Rid = "+rid);
      while (!(currentRid.equals(rid.substring(0, rid.indexOf('@'))))) {
        System.out.println("CurrentRid = "+currentRid);
        i++;
        currentRid = list[i].getRid();
        if (currentRid.indexOf('@') != -1)
          currentRid = currentRid.substring(0, currentRid.indexOf('@'));
      }
      Integer height = Integer.parseInt(request.getParameter("height"));
      Integer width = Integer.parseInt(request.getParameter("width"));
      newWindow[0] = list[i];
      newWindow[0].setH(height);
      newWindow[0].setW(width);
      System.out.println("HEIGHT : "+height+", WIDTH : "+width);
      desktopCommunicator.updateDesktop(sid, newWindow);
       
    } else if (portletAction.equals("conf_move")) {

      DesktopUpdater desktopCommunicator = new DesktopUpdater();
      village.webservice.user.Window newWindow[] = new village.webservice.user.Window[1];   
      DataGetter dataCommunicator = new DataGetter();
      Integer i = 0;
      village.webservice.user.Window list[] = null;
      village.webservice.user.UserData ud = dataCommunicator.get(sid);
      list = ud.getWindows();
      /* find the window to move */
      String currentRid = list[i].getRid();
      if (currentRid.indexOf('@') != -1)
        currentRid = currentRid.substring(0, currentRid.indexOf('@'));
      System.out.println("Rid = "+rid);
      while (!(currentRid.equals(rid.substring(0, rid.indexOf('@'))))) {
        System.out.println("CurrentRid = "+currentRid);
        i++;
        currentRid = list[i].getRid();
        if (currentRid.indexOf('@') != -1)
          currentRid = currentRid.substring(0, currentRid.indexOf('@'));
      }
      String x_px = request.getParameter("left");
      Integer x = Integer.parseInt(x_px.substring(0, x_px.length() - 2));
      String y_px = request.getParameter("top");
      Integer y = Integer.parseInt(y_px.substring(0, y_px.length() - 2));
      newWindow[0] = list[i];
      newWindow[0].setX(x);
      newWindow[0].setY(y);
      System.out.println("MOVE-X : "+x+", MOVE-Y : "+y);
      desktopCommunicator.updateDesktop(sid, newWindow);

    } else if (portletAction.equals("conf_min")) {
     
      System.out.println("Bylo min\n");
      DesktopUpdater desktopCommunicator = new DesktopUpdater();
      village.webservice.user.Window newWindow[] = new village.webservice.user.Window[1];     
      DataGetter dataCommunicator = new DataGetter();
      Integer i = 0;
      village.webservice.user.Window list[] = null;
      village.webservice.user.UserData ud = dataCommunicator.get(sid);
      list = ud.getWindows();
      /* find the window to min */
      String currentRid = list[i].getRid();
      if (currentRid.indexOf('@') != -1)
        currentRid = currentRid.substring(0, currentRid.indexOf('@'));
      System.out.println("Rid = "+rid);
      while (!(currentRid.equals(rid.substring(0, rid.indexOf('@'))))) {
        System.out.println("CurrentRid = "+currentRid);
        i++;
        currentRid = list[i].getRid();
        if (currentRid.indexOf('@') != -1)
          currentRid = currentRid.substring(0, currentRid.indexOf('@'));
      }
      newWindow[0] = list[i];
      System.out.println("[pc]LastMin = "+newWindow[0].getBar());     
      newWindow[0].setBar(!(newWindow[0].getBar()));
      System.out.println("[pc]NextMin = "+newWindow[0].getBar());
      desktopCommunicator.updateDesktop(sid, newWindow);
     
    } else if (portletAction.equals("conf_max")) {
     
      System.out.println("Bylo max\n");
      DesktopUpdater desktopCommunicator = new DesktopUpdater();
      village.webservice.user.Window newWindow[] = new village.webservice.user.Window[1];     
      DataGetter dataCommunicator = new DataGetter();
      Integer i = 0;
      village.webservice.user.Window list[] = null;
      village.webservice.user.UserData ud = dataCommunicator.get(sid);
      list = ud.getWindows();
      /* find the window to max */
      String currentRid = list[i].getRid();
      if (currentRid.indexOf('@') != -1)
        currentRid = currentRid.substring(0, currentRid.indexOf('@'));
      System.out.println("Rid = "+rid);
      while (!(currentRid.equals(rid.substring(0, rid.indexOf('@'))))) {
        System.out.println("CurrentRid = "+currentRid);
        i++;
        currentRid = list[i].getRid();
        if (currentRid.indexOf('@') != -1)
          currentRid = currentRid.substring(0, currentRid.indexOf('@'));
      }
      newWindow[0] = list[i];
      newWindow[0].setFullscreen(!(newWindow[0].getFullscreen()));
      desktopCommunicator.updateDesktop(sid, newWindow);
     
    } else {
      /* portlet-specific request */
      Executor communicator = new Executor();

      /*
      // DEBUG: (requires including Enumeration)
      String tmpString = null;
      System.out.println("[pctl] calling executor w/ request:");
      for (Enumeration e = request.getParameterNames(); e.hasMoreElements(); ) {
        tmpString = (String) e.nextElement();
        System.out.println("[pctl] ParamName="+tmpString);
        System.out.println("[pctl] ParamVal="+(String) request.getParameter(tmpString));
         }
      */
      out.print(communicator.execute(sid, request));
    }
    out.print("</portlet-response>");
  }
 
}
TOP

Related Classes of PortletControllerServlet

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.