Exemplo n.º 1
0
  public void doView(RenderRequest request, RenderResponse response)
      throws PortletException, IOException {

    if (WindowState.MINIMIZED.equals(request.getWindowState())) {
      return;
    }

    if (WindowState.NORMAL.equals(request.getWindowState())) {
      normalView.include(request, response);
    } else {
      maximizedView.include(request, response);
    }
  }
Exemplo n.º 2
0
 /**
  * Override doDispatch method for handling custom portlet modes.
  *
  * @see javax.portlet.GenericPortlet#doDispatch(javax.portlet.RenderRequest,
  *     javax.portlet.RenderResponse)
  */
 protected void doDispatch(RenderRequest request, RenderResponse response)
     throws PortletException, IOException {
   if (!WindowState.MINIMIZED.equals(request.getWindowState())) {
     PortletMode mode = request.getPortletMode();
     if (CUSTOM_CONFIG_MODE.equals(mode)) {
       doCustomConfigure(request, response);
       return;
     }
   }
   super.doDispatch(request, response);
 }
  public void doView(RenderRequest request, RenderResponse response)
      throws PortletException, IOException {

    long clock = System.currentTimeMillis();

    try {
      System.out.println("hi: " + clock);
      log.debug("Rendering view.");

      if (WindowState.MINIMIZED.equals(request.getWindowState())) {
        return;
      }

      if (WindowState.NORMAL.equals(request.getWindowState())) {
        normalView.include(request, response);
      } else {
        maximizedView.include(request, response);
      }
    } finally {
      long duration = System.currentTimeMillis() - clock;
      log.debug(String.format("View rendering took %s ms.", duration));
    }
  }
Exemplo n.º 4
0
 protected void doEdit(RenderRequest request, RenderResponse response)
     throws PortletException, java.io.IOException {
   if (request.getParameter("type") != null && request.getParameter("type").equals("create")) {
     String page = request.getParameter("pageId");
     if (page == null) page = "1";
     int pageId = Integer.parseInt(page);
     request.setAttribute("pageId", pageId);
     if (request.getWindowState().equals(WindowState.MAXIMIZED))
       this.getPortletContext()
           .getRequestDispatcher(_PORTLET_JSP_PATH + "/email/emailPortletMaxEdit.jsp")
           .include(request, response);
     else
       this.getPortletContext()
           .getRequestDispatcher(_PORTLET_JSP_PATH + "/email/emailPortletEdit.jsp")
           .include(request, response);
   } else {
     PortletPreferences portletPreferences = request.getPreferences();
     String fullName = portletPreferences.getValue("fullName", null);
     String incomingType = portletPreferences.getValue("incomingType", null);
     String incoming = portletPreferences.getValue("incoming", null);
     String incomingPort = portletPreferences.getValue("incomingPort", null);
     String incomingSSL = portletPreferences.getValue("incomingSSL", null);
     String outgoing = portletPreferences.getValue("outgoing", null);
     String outgoingPort = portletPreferences.getValue("outgoingPort", null);
     String outgoingSSL = portletPreferences.getValue("outgoingSSL", null);
     String email = portletPreferences.getValue("email", null);
     String password = portletPreferences.getValue("password", null);
     String number = portletPreferences.getValue("number", "10");
     request.setAttribute("fullName", fullName);
     request.setAttribute("incomingType", incomingType);
     request.setAttribute("incoming", incoming);
     request.setAttribute("incomingPort", incomingPort);
     request.setAttribute("incomingSSL", incomingSSL);
     request.setAttribute("outgoing", outgoing);
     request.setAttribute("outgoingPort", outgoingPort);
     request.setAttribute("outgoingSSL", outgoingSSL);
     request.setAttribute("email", email);
     request.setAttribute("password", password);
     request.setAttribute("number", number);
     this.getPortletContext()
         .getRequestDispatcher(_PORTLET_JSP_PATH + "/email/emailPortletConfig.jsp")
         .include(request, response);
   }
 }
Exemplo n.º 5
0
  @Override
  protected void writeAjaxPage(
      RenderRequest request, RenderResponse response, Window window, Application application)
      throws IOException, MalformedURLException, PortletException {
    MailApplication mailApplication = (MailApplication) application;

    // user is set in the portlet listener by the application
    if (mailApplication.getController().getUser() == null) {
      // normally, the portal takes care of this
      // this branch is in case the user has not been registered in the controller
      writeNotLoggedInPageHtml(request, response, window);
    } else if (PortletMode.VIEW.equals(request.getPortletMode())
        && WindowState.NORMAL.equals(request.getWindowState())) {
      mailApplication.writeViewPageHtml(request, response, window);
    } else {
      // this includes other modes as well as the maximized state
      super.writeAjaxPage(request, response, window, application);
    }
  }
  public static void render(RenderRequest request, RenderResponse response) throws IOException {
    BufferedResponseStream bufferedResponseStream = getBufferedResponseStream(request);
    if (bufferedResponseStream == null) {
      throw new IllegalStateException("BufferedResponseStream is null.");
    }
    synchronized (bufferedResponseStream) {
      // flush stream
      bufferedResponseStream.commit();

      if (request.getWindowState() != WindowState.MINIMIZED) {
        Reader r = bufferedResponseStream.getReader();
        Writer w = response.getWriter();
        char[] bytes = new char[FacesResponseConstants.BLOCK_SIZE];
        try {
          int length = r.read(bytes);
          while (length != -1) {
            if (length != 0) {
              w.write(bytes, 0, length);
            }
            length = r.read(bytes);
          }
        } finally {
          bytes = null;
        }
        w.flush();
      }
    }

    // cleanup
    //        if (FacesResponseUtil.isMyFacesFacesContext(request)) {
    // for MyFaces
    // MyFaces needs this workaround code because of the implementation
    // issue..
    // request.getPortletSession().removeAttribute(
    // FacesResponseConstants.BUFFERED_RESPONSE_STREAM);
    //        } else {
    //            // for JSF implementation whice does not pass FacesContext from
    //            // processAction to render
    //            request
    //                    .removeAttribute(FacesResponseConstants.BUFFERED_RESPONSE_STREAM);
    //        }
  }
  @RequestMapping(
      value = {"VIEW"},
      params = {"action=browseMobile"})
  public ModelAndView browseMobile(
      RenderRequest request, RenderResponse response, @RequestParam String dir) {
    this.init(request);

    final PortletPreferences prefs = request.getPreferences();
    boolean forceMaximized4Mobile =
        "true".equals(prefs.getValue(PREF_FORCE_MAXIMIZED_4_MOBILE, "true"));
    String forceWindowState4Mobile =
        forceMaximized4Mobile
            ? WindowState.MAXIMIZED.toString()
            : request.getWindowState().toString();

    String decodedDir = pathEncodingUtils.decodeDir(dir);

    ModelMap model;
    if (!(dir == null || dir.length() == 0 || decodedDir.equals(JsTreeFile.ROOT_DRIVE))) {
      if (this.serverAccess.formAuthenticationRequired(decodedDir, userParameters)) {
        ListOrderedMap parentPathes = pathEncodingUtils.getParentsEncPathes(decodedDir, null, null);
        // we want to get the (last-1) key of sortedmap "parentPathes"
        String parentDir = (String) parentPathes.get(parentPathes.size() - 2);
        model = new ModelMap("currentDir", dir);
        model.put("parentDir", parentDir);
        model.put(
            "username",
            this.serverAccess.getUserPassword(decodedDir, userParameters).getUsername());
        model.put(
            "password",
            this.serverAccess.getUserPassword(decodedDir, userParameters).getPassword());
        model.put("forceWindowState4Mobile", forceWindowState4Mobile);
        return new ModelAndView("authenticationForm-portlet-mobile", model);
      }
    }
    model = browse(dir);
    model.put("forceWindowState4Mobile", forceWindowState4Mobile);
    return new ModelAndView("view-portlet-mobile", model);
  }
Exemplo n.º 8
0
  public ActionForward render(
      ActionMapping mapping,
      ActionForm form,
      PortletConfig config,
      RenderRequest req,
      RenderResponse res)
      throws Exception {

    String orderBy = req.getParameter("orderBy");
    User user = _getUser(req);
    orderBy = (UtilMethods.isSet(orderBy) ? orderBy : "name");
    _loadStructures(
        req,
        user,
        WebKeys.STRUCTURES_VIEW_COUNT,
        WebKeys.Structure.STRUCTURES,
        WebKeys.STRUCTURE_QUERY);
    if (req.getWindowState().equals(WindowState.NORMAL)) {
      return mapping.findForward("portlet.ext.formhandler.view");
    } else {
      return mapping.findForward("portlet.ext.formhandler.view_form");
    }
  }
  @RequestMapping(
      value = {"VIEW"},
      params = {"action=browseStandard"})
  public ModelAndView browseStandard(RenderRequest request, RenderResponse response, String dir) {
    this.init(request);
    final PortletPreferences prefs = request.getPreferences();
    boolean useDoubleClick = "true".equals(prefs.getValue(PREF_USE_DOUBLE_CLICK, "true"));
    boolean useCursorWaitDialog =
        "true".equals(prefs.getValue(PREF_USE_CURSOR_WAIT_DIALOG, "false"));

    ModelMap model = new ModelMap();
    model.put("useDoubleClick", useDoubleClick);
    model.put("useCursorWaitDialog", useCursorWaitDialog);
    if (dir == null) dir = "";
    model.put("defaultPath", dir);

    boolean fullViewOnlyMaximized =
        "true".equals(prefs.getValue(PREF_FULL_VIEW_ONLY_MAXIMIZED, "true"));
    boolean fullView =
        !fullViewOnlyMaximized || WindowState.MAXIMIZED.equals(request.getWindowState());
    model.put("fullView", fullView);

    return new ModelAndView("view-portlet", model);
  }
Exemplo n.º 10
0
  protected void doView(RenderRequest request, RenderResponse response)
      throws PortletException, java.io.IOException {
    String page = request.getParameter("pageId");
    if (page == null || page.trim().length() < 1) page = "1";
    int pageId = Integer.parseInt(page);
    if (request.getPortletSession().getAttribute("mails", PortletSession.PORTLET_SCOPE) == null
        || request.getParameter("refresh") != null
        || request.getParameter("newPage") != null) {
      PortletPreferences portletPreferences = request.getPreferences();
      UserProfile userProfile =
          this.getUserService(request).getUserProfileById(this.getUser(request).getId());
      String name = null;
      if (userProfile != null) name = userProfile.getName();
      if ((name == null || name.length() <= 0) && this.getUser(request) != null)
        name = this.getUser(request).getDisplayName();
      String fullName = portletPreferences.getValue("fullName", name);
      String incomingType = portletPreferences.getValue("incomingType", null);
      String incoming = portletPreferences.getValue("incoming", null);
      String incomingPort = portletPreferences.getValue("incomingPort", null);
      String incomingSSL = portletPreferences.getValue("incomingSSL", null);
      String outgoing = portletPreferences.getValue("outgoing", null);
      String outgoingPort = portletPreferences.getValue("outgoingPort", null);
      String outgoingSSL = portletPreferences.getValue("outgoingSSL", null);
      String email = portletPreferences.getValue("email", null);
      String password = portletPreferences.getValue("password", null);
      String number = portletPreferences.getValue("number", "10");
      if (incoming == null || outgoing == null || email == null || password == null) {
        request.setAttribute("incomingPort", "110");
        request.setAttribute("outgoingPort", "25");
        request.setAttribute("number", number);
        this.getPortletContext()
            .getRequestDispatcher(_PORTLET_JSP_PATH + "/email/emailPortletConfig.jsp")
            .include(request, response);
      } else {
        int row = Integer.parseInt(number);
        if (request.getParameter("refresh") != null) pageId = 1;
        List<MailBean> mails = null;
        EmailClient client =
            new EmailClient(
                email,
                password,
                incomingType,
                incoming,
                incomingPort,
                incomingSSL,
                outgoing,
                outgoingPort,
                outgoingPort);
        try {
          mails = client.getMessage(EmailClient.SHOW_MESSAGES, pageId, row);
        } catch (Exception e) {
          request.setAttribute("error", e.getMessage());
        }
        int count = 0;
        int unread = 0;
        if (mails != null && mails.size() > 0) {
          count = mails.get(0).getTotal();
          unread = mails.get(0).getUnreadCount();
        }
        int pages = count / row;
        if (count % row != 0) pages++;

        request.getPortletSession().setAttribute("mails", mails, PortletSession.PORTLET_SCOPE);
        request.getPortletSession().setAttribute("totalCount", count, PortletSession.PORTLET_SCOPE);
        request
            .getPortletSession()
            .setAttribute("unreadCount", unread, PortletSession.PORTLET_SCOPE);
        request.getPortletSession().setAttribute("pages", pages, PortletSession.PORTLET_SCOPE);
        request.getPortletSession().setAttribute("row", row, PortletSession.PORTLET_SCOPE);
        request.setAttribute("pageId", pageId);
        request.setAttribute("totalCount", count);
        request.setAttribute("unreadCount", unread);
        request.setAttribute("pages", pages);
        request.setAttribute("row", row);
        request.setAttribute("mails", mails);
        if (request.getWindowState().equals(WindowState.MAXIMIZED))
          this.getPortletContext()
              .getRequestDispatcher(_PORTLET_JSP_PATH + "/email/emailPortletMaxView.jsp")
              .include(request, response);
        else
          this.getPortletContext()
              .getRequestDispatcher(_PORTLET_JSP_PATH + "/email/emailPortletView.jsp")
              .include(request, response);
      }
    } else {
      if (request.getParameter("mailId") != null) {
        int index = Integer.parseInt(request.getParameter("mailId"));
        List<MailBean> mails =
            (List<MailBean>)
                request.getPortletSession().getAttribute("mails", PortletSession.PORTLET_SCOPE);
        MailBean mail = mails.get(index);
        if (mail.getContent() == null) {
          PortletPreferences portletPreferences = request.getPreferences();
          String incomingType = portletPreferences.getValue("incomingType", null);
          String incoming = portletPreferences.getValue("incoming", null);
          String incomingPort = portletPreferences.getValue("incomingPort", null);
          String incomingSSL = portletPreferences.getValue("incomingSSL", null);
          String outgoing = portletPreferences.getValue("outgoing", null);
          String outgoingPort = portletPreferences.getValue("outgoingPort", null);
          String outgoingSSL = portletPreferences.getValue("outgoingSSL", null);
          String email = portletPreferences.getValue("email", null);
          String password = portletPreferences.getValue("password", null);
          EmailClient client =
              new EmailClient(
                  email,
                  password,
                  incomingType,
                  incoming,
                  incomingPort,
                  incomingSSL,
                  outgoing,
                  outgoingPort,
                  outgoingPort);
          try {
            mail = client.getMessageDetail(mails.get(index).getMsg());
            int unread =
                (Integer)
                    request
                        .getPortletSession()
                        .getAttribute("unreadCount", PortletSession.PORTLET_SCOPE);
            if (mails.get(index).getFlag() == 1) unread--;
            if (unread < 0) unread = 0;
            request
                .getPortletSession()
                .setAttribute("unreadCount", unread, PortletSession.PORTLET_SCOPE);
            // request.getPortletSession().removeAttribute("mails",PortletSession.PORTLET_SCOPE);
          } catch (Exception e) {
            request.setAttribute("error", e.getMessage());
          }
          mails.set(index, mail);
        }
        request.setAttribute("currentMail", mail);
        request.setAttribute("pageId", pageId);
      } else {

        List<MailBean> mails =
            (List<MailBean>)
                request.getPortletSession().getAttribute("mails", PortletSession.PORTLET_SCOPE);
        int row =
            (Integer) request.getPortletSession().getAttribute("row", PortletSession.PORTLET_SCOPE);
        int count =
            (Integer)
                request
                    .getPortletSession()
                    .getAttribute("totalCount", PortletSession.PORTLET_SCOPE);
        int unread =
            (Integer)
                request
                    .getPortletSession()
                    .getAttribute("unreadCount", PortletSession.PORTLET_SCOPE);
        int pages =
            (Integer)
                request.getPortletSession().getAttribute("pages", PortletSession.PORTLET_SCOPE);
        List<MailBean> pageMails = new ArrayList<MailBean>();
        request.setAttribute("pageId", pageId);
        request.setAttribute("totalCount", count);
        request.setAttribute("unreadCount", unread);
        request.setAttribute("pages", pages);
        request.setAttribute("row", row);
        request.setAttribute("mails", mails);
      }
      if (request.getWindowState().equals(WindowState.MAXIMIZED))
        this.getPortletContext()
            .getRequestDispatcher(_PORTLET_JSP_PATH + "/email/emailPortletMaxView.jsp")
            .include(request, response);
      else
        this.getPortletContext()
            .getRequestDispatcher(_PORTLET_JSP_PATH + "/email/emailPortletView.jsp")
            .include(request, response);
    }
  }