예제 #1
0
  public static PortletURL clone(
      LiferayPortletURL liferayPortletURL, boolean action, RenderResponse res)
      throws PortletException {

    LiferayPortletURL newURLImpl = null;

    if (action) {
      newURLImpl = (LiferayPortletURL) res.createActionURL();
    } else {
      newURLImpl = (LiferayPortletURL) res.createRenderURL();
    }

    newURLImpl.setPortletId(liferayPortletURL.getPortletId());

    WindowState windowState = liferayPortletURL.getWindowState();

    if (windowState != null) {
      newURLImpl.setWindowState(windowState);
    }

    PortletMode portletMode = liferayPortletURL.getPortletMode();

    if (portletMode != null) {
      newURLImpl.setPortletMode(portletMode);
    }

    newURLImpl.setParameters(liferayPortletURL.getParameterMap());

    return newURLImpl;
  }
  @Override
  public void render(RenderRequest portletReq, RenderResponse portletResp)
      throws PortletException, IOException {
    LOGGER.entering(LOG_CLASS, "main portlet render entry");

    long tid = Thread.currentThread().getId();
    portletReq.setAttribute(THREADID_ATTR, tid);

    PrintWriter writer = portletResp.getWriter();

    writer.write(
        "<div id=\"DispatcherTests_SPEC2_19_ForwardServletResource\">no resource output.</div>\n");
    ResourceURL resurl = portletResp.createResourceURL();
    resurl.setCacheability(PAGE);
    writer.write("<script>\n");
    writer.write("(function () {\n");
    writer.write("   var xhr = new XMLHttpRequest();\n");
    writer.write("   xhr.onreadystatechange=function() {\n");
    writer.write("      if (xhr.readyState==4 && xhr.status==200) {\n");
    writer.write(
        "         document.getElementById(\"DispatcherTests_SPEC2_19_ForwardServletResource\").innerHTML=xhr.responseText;\n");
    writer.write("      }\n");
    writer.write("   };\n");
    writer.write("   xhr.open(\"GET\",\"" + resurl.toString() + "\",true);\n");
    writer.write("   xhr.send();\n");
    writer.write("})();\n");
    writer.write("</script>\n");
  }
예제 #3
0
 public void doView(RenderRequest request, RenderResponse response)
     throws PortletException, IOException {
   String siteName = request.getPreferences().getValue("SRC", null);
   SSOSite site = null;
   if (siteName != null) {
     site = sso.getSiteByUrl(siteName);
   }
   if (site == null) {
     response.getWriter().print(NO_CREDENTIALS);
     return;
   } else {
     PasswordCredential pwc = SSOPortletUtil.getCredentialsForSite(sso, siteName, request);
     if (pwc != null) {
       request.setAttribute(SSO_REQUEST_ATTRIBUTE_USERNAME, pwc.getUserName());
       request.setAttribute(SSO_REQUEST_ATTRIBUTE_PASSWORD, pwc.getPassword());
     } else {
       response.getWriter().print(NO_CREDENTIALS);
       return;
     }
   }
   StatusMessage msg =
       (StatusMessage) PortletMessaging.consume(request, "SSOWebContent", "status");
   if (msg != null) {
     this.getContext(request).put("statusMsg", msg);
   }
   super.doView(request, response);
 }
예제 #4
0
 public void doEdit(RenderRequest request, RenderResponse response)
     throws IOException, PortletException {
   setRenderAttributes(request);
   response.setContentType("text/html");
   response.setTitle("Edit");
   PortletRequestDispatcher prd =
       getPortletContext().getRequestDispatcher("/WEB-INF/jsp/Browser/edit.jsp");
   prd.include(request, response);
 }
예제 #5
0
  /** Notify user that not logged in. */
  public void writeNotLoggedInPageHtml(
      RenderRequest request, RenderResponse response, Window window) throws IOException {
    response.setContentType("text/html");
    final BufferedWriter page =
        new BufferedWriter(new OutputStreamWriter(response.getPortletOutputStream(), "UTF-8"));

    page.write("<div class=\"portlet-msg-error\">Please login to use the mail portlet.</div>");

    page.close();
  }
예제 #6
0
 /* (non-Javadoc)
  * @see javax.portlet.GenericPortlet#doView(javax.portlet.RenderRequest, javax.portlet.RenderResponse)
  */
 @Override
 protected void doView(RenderRequest request, RenderResponse response)
     throws PortletException, IOException, UnavailableException {
   response.setContentType("text/html");
   PrintWriter writer = response.getWriter();
   writer.write("Hello World!");
   writer.write(
       "<html><head></head><body><a href=\"/FileDownloadExample/Download.do?FileId=XXX.pdf\">Download</a></body></html>");
   writer.close();
 }
예제 #7
0
  @Override
  public void doView(RenderRequest renderRequest, RenderResponse renderResponse)
      throws IOException, PortletException {

    renderResponse.setContentType(ContentTypes.TEXT_HTML_UTF8);

    PrintWriter printWriter = renderResponse.getWriter();

    printWriter.print("Welcome to ".concat(ReleaseInfo.getReleaseInfo()).concat("."));
  }
  public void doEdit(RenderRequest request, RenderResponse response)
      throws PortletException, IOException {

    response.setContentType("text/html");
    PrintWriter out = response.getWriter();
    String title = getTitleString(request);
    if (title != null) response.setTitle(title);

    Context context = new VelocityContext();
    context.put("tlang", rb);
    context.put("validator", validator);
    sendAlert(request, context);

    PortletURL url = response.createActionURL();
    context.put("actionUrl", url.toString());
    context.put("doCancel", "sakai.cancel");
    context.put("doUpdate", "sakai.update");

    // get current site
    Placement placement = ToolManager.getCurrentPlacement();
    String siteId = "";

    // find the right LTIContent object for this page
    String source = placement.getPlacementConfig().getProperty(SOURCE);
    Long key = getContentIdFromSource(source);
    if (key == null) {
      out.println(rb.getString("get.info.notconfig"));
      M_log.warn("Cannot find content id placement=" + placement.getId() + " source=" + source);
      return;
    }

    Map<String, Object> content = m_ltiService.getContent(key);
    if (content == null) {
      out.println(rb.getString("get.info.notconfig"));
      M_log.warn("Cannot find content item placement=" + placement.getId() + " key=" + key);
      return;
    }

    // attach the ltiToolId to each model attribute, so that we could have the tool configuration
    // page for multiple tools
    String foundLtiToolId = content.get(m_ltiService.LTI_TOOL_ID).toString();
    Map<String, Object> tool = m_ltiService.getTool(Long.valueOf(foundLtiToolId));
    if (tool == null) {
      out.println(rb.getString("get.info.notconfig"));
      M_log.warn("Cannot find tool placement=" + placement.getId() + " key=" + foundLtiToolId);
      return;
    }

    String[] contentToolModel = m_ltiService.getContentModel(Long.valueOf(foundLtiToolId));
    String formInput = m_ltiService.formInput(content, contentToolModel);
    context.put("formInput", formInput);

    vHelper.doTemplate(vengine, "/vm/edit.vm", context, out);
  }
  /* set the Portlet's default Edit: it's a simple <form> */
  public void doEdit(RenderRequest renderRequest, RenderResponse renderResponse)
      throws IOException, PortletException {

    renderResponse.setContentType("text/html");
    PortletURL saveSettingsStatisticsURL = renderResponse.createActionURL();
    saveSettingsStatisticsURL.setParameter(
        "saveSettingsGoogleMapsUtility", "saveSettingsGoogleMapsUtility");
    renderRequest.setAttribute(
        "saveSettingsGoogleMapsUtilityURL", saveSettingsStatisticsURL.toString());

    include(editJSP, renderRequest, renderResponse);
  }
예제 #10
0
  @Override
  public void doView(RenderRequest renderRequest, RenderResponse renderResponse)
      throws IOException {

    renderResponse.setContentType(ContentTypes.TEXT_HTML);

    PrintWriter printWriter = renderResponse.getWriter();

    printWriter.write("<a href=\"");
    printWriter.write(String.valueOf(renderResponse.createActionURL()));
    printWriter.write("\">Send Event</a>");

    printWriter.close();
  }
 public void flushContentToWrappedResponse() throws IOException {
   if (caw != null) {
     pw.flush();
     caw.writeTo(response.getWriter());
     caw.reset();
   } else if (bawos != null) {
     try {
       bawos.writeTo(response.getWriter(), response.getCharacterEncoding());
     } catch (IllegalStateException ise) {
       bawos.writeTo(response.getPortletOutputStream());
     }
     bawos.resetByteArray();
   }
 }
예제 #12
0
  /*
   * (non-Javadoc)
   * @see
   * org.exoplatform.webui.core.UIPortletApplication#processRender(org.exoplatform
   * .webui.application.WebuiApplication,
   * org.exoplatform.webui.application.WebuiRequestContext)
   */
  public void processRender(WebuiApplication app, WebuiRequestContext context) throws Exception {
    PortletRequestContext pContext = (PortletRequestContext) context;
    PortletMode newMode = pContext.getApplicationMode();
    PortletPreferences preferences = pContext.getRequest().getPreferences();
    Boolean sharedCache = "true".equals(preferences.getValue(ENABLE_CACHE, "true"));

    if (context.getRemoteUser() == null
        || (Utils.isLiveMode()
            && sharedCache
            && !Utils.isPortalEditMode()
            && Utils.isPortletViewMode(pContext))) {
      WCMService wcmService = getApplicationComponent(WCMService.class);
      pContext
          .getResponse()
          .setProperty(MimeResponse.EXPIRATION_CACHE, "" + wcmService.getPortletExpirationCache());
      if (log.isTraceEnabled())
        log.trace("SCV rendering : cache set to " + wcmService.getPortletExpirationCache());
    }

    if (!newMode.equals(mode)) {
      activateMode(newMode);
      mode = newMode;
    }

    Node nodeView = null;
    if (uiPresentation != null) {
      nodeView = uiPresentation.getNodeView();
      if (nodeView != null) {
        TemplateService templateService = getApplicationComponent(TemplateService.class);
        uiPresentation
            .getChild(UIPresentation.class)
            .setTemplatePath(templateService.getTemplatePath(nodeView, false));
      }
    }

    if (uiPresentation != null && uiPresentation.isContextual() && nodeView != null) {
      RenderResponse response = context.getResponse();
      Element title = response.createElement("title");
      title.setTextContent(uiPresentation.getTitle(nodeView));
      response.addProperty(MimeResponse.MARKUP_HEAD_ELEMENT, title);
    }

    if (context.getRemoteUser() != null && WCMComposer.MODE_EDIT.equals(Utils.getCurrentMode())) {
      pContext.getJavascriptManager().loadScriptResource(ResourceScope.SHARED, "content-selector");
      pContext.getJavascriptManager().loadScriptResource(ResourceScope.SHARED, "quick-edit");
    }

    setId(UISingleContentViewerPortlet.class.getSimpleName() + pContext.getWindowId());
    super.processRender(app, context);
  }
 public void render(String viewName, Map model, RenderRequest request, RenderResponse response)
     throws Exception {
   TestBean tb = (TestBean) model.get("testBean");
   if (tb == null) {
     tb = (TestBean) model.get("myCommand");
   }
   if (tb.getName().endsWith("myDefaultName")) {
     assertTrue(tb.getDate().getYear() == 107);
   }
   Errors errors = (Errors) model.get(BindingResult.MODEL_KEY_PREFIX + "testBean");
   if (errors == null) {
     errors = (Errors) model.get(BindingResult.MODEL_KEY_PREFIX + "myCommand");
   }
   if (errors.hasFieldErrors("date")) {
     throw new IllegalStateException();
   }
   List<TestBean> testBeans = (List<TestBean>) model.get("testBeanList");
   response
       .getWriter()
       .write(
           viewName
               + "-"
               + tb.getName()
               + "-"
               + errors.getFieldError("age").getCode()
               + "-"
               + testBeans.get(0).getName()
               + "-"
               + model.get("myKey"));
 }
예제 #14
0
  @Override
  public void render(RenderRequest renderRequest, RenderResponse renderResponse)
      throws IOException, PortletException {

    PortletURL portletURL = renderResponse.createRenderURL();

    portletURL.setParameter("mvcPath", "hello_soy_description");

    template.put("descriptionURL", portletURL.toString());

    String path = getPath(renderRequest, renderResponse);

    if (Validator.equals(path, "hello_soy_edit")) {
      portletURL.setParameter("mvcPath", "hello_soy_view");
    } else {
      portletURL.setParameter("mvcPath", "hello_soy_edit");
    }

    template.put("portletURL", portletURL.toString());

    ThemeDisplay themeDisplay = (ThemeDisplay) renderRequest.getAttribute(WebKeys.THEME_DISPLAY);

    User user = themeDisplay.getUser();

    template.put("userName", user.getFirstName());

    super.render(renderRequest, renderResponse);
  }
 @RequestMapping
 public void myHandle(RenderResponse response) throws IOException {
   if (this.portletContext == null || this.session == null || this.request == null) {
     throw new IllegalStateException();
   }
   response.getWriter().write("myView");
 }
예제 #16
0
  public static PortletURL getCurrent(RenderRequest req, RenderResponse res) {
    PortletURL portletURL = res.createRenderURL();

    Enumeration enu = req.getParameterNames();

    while (enu.hasMoreElements()) {
      String param = (String) enu.nextElement();
      String[] values = req.getParameterValues(param);

      boolean addParam = true;

      // Don't set paramter values that are over 32 kb. See LEP-1755.

      for (int i = 0; i < values.length; i++) {
        if (values[i].length() > _CURRENT_URL_PARAMETER_THRESHOLD) {
          addParam = false;

          break;
        }
      }

      if (addParam) {
        portletURL.setParameter(param, values);
      }
    }

    return portletURL;
  }
  @Override
  public String render(RenderRequest renderRequest, RenderResponse renderResponse)
      throws PortletException {

    Portlet portlet = null;

    try {
      portlet = ActionUtil.getPortlet(renderRequest);
    } catch (PrincipalException pe) {
      SessionErrors.add(renderRequest, pe.getClass());

      return "/error.jsp";
    } catch (Exception e) {
      throw new PortletException(e);
    }

    try {
      renderResponse.setTitle(ActionUtil.getTitle(portlet, renderRequest));

      renderRequest = ActionUtil.getWrappedRenderRequest(renderRequest, null);

      return "/publish_portlet.jsp";
    } catch (Exception e) {
      SessionErrors.add(renderRequest, e.getClass());

      return "/error.jsp";
    }
  }
  // Read access token from DB and display error message if it's not available
  protected AccessToken loadAccessTokenOrRedirectToObtainIt(
      String username, OAuthProvider oauthProvider, RenderRequest request, RenderResponse response)
      throws IOException, PortletException {
    // Try requestContext first. Otherwise obtain OAuthProvider via API
    AccessToken accessToken = requestContext.getAccessToken(oauthProviderKey);
    if (accessToken == null) {
      accessToken = oauthProvider.loadAccessToken(username);
    }

    if (accessToken == null) {
      // Will be processed by method AbstractSocialPortlet.actionRedirectToOAuthFlow
      PortletURL actionURL = response.createActionURL();
      actionURL.setParameter(
          ActionRequest.ACTION_NAME, AbstractSocialPortlet.ACTION_OAUTH_REDIRECT);

      request.setAttribute(
          ATTRIBUTE_ERROR_MESSAGE,
          oauthProvider.getFriendlyName() + " access token not available for you.");
      request.setAttribute(ATTRIBUTE_OAUTH_PROVIDER, oauthProvider);
      PortletRequestDispatcher prd =
          filterConfig.getPortletContext().getRequestDispatcher("/jsp/error/token.jsp");
      prd.include(request, response);
    }

    return accessToken;
  }
  public static void addPortletBreadcrumbEntries(
      MBMessage message, HttpServletRequest request, RenderResponse renderResponse)
      throws Exception {

    if (message.getCategoryId() == MBCategoryConstants.DISCUSSION_CATEGORY_ID) {

      return;
    }

    MBCategory category = null;

    if (message.getCategoryId() != MBCategoryConstants.DEFAULT_PARENT_CATEGORY_ID) {

      category = message.getCategory();
    }

    addPortletBreadcrumbEntries(category, request, renderResponse);

    PortletURL portletURL = renderResponse.createRenderURL();

    portletURL.setParameter("mvcRenderCommandName", "/message_boards/view_message");
    portletURL.setParameter("messageId", String.valueOf(message.getMessageId()));

    PortalUtil.addPortletBreadcrumbEntry(request, message.getSubject(), portletURL.toString());
  }
예제 #20
0
  @Override
  public void addPortletBreadcrumbEntries(
      Folder folder, HttpServletRequest request, RenderResponse renderResponse) throws Exception {

    String strutsAction = ParamUtil.getString(request, "struts_action");

    long groupId = ParamUtil.getLong(request, "groupId");

    PortletURL portletURL = renderResponse.createRenderURL();

    if (strutsAction.equals("/document_library/select_file_entry")
        || strutsAction.equals("/document_library/select_folder")
        || strutsAction.equals("/document_library_display/select_folder")
        || strutsAction.equals("/dynamic_data_mapping/select_document_library")
        || strutsAction.equals("/image_gallery_display/select_folder")) {

      ThemeDisplay themeDisplay = (ThemeDisplay) request.getAttribute(WebKeys.THEME_DISPLAY);

      portletURL.setParameter("struts_action", strutsAction);
      portletURL.setParameter("groupId", String.valueOf(groupId));
      portletURL.setWindowState(LiferayWindowState.POP_UP);

      PortalUtil.addPortletBreadcrumbEntry(
          request, themeDisplay.translate("home"), portletURL.toString());
    } else {
      portletURL.setParameter("struts_action", "/document_library/view");
    }

    addPortletBreadcrumbEntries(folder, request, portletURL);
  }
예제 #21
0
  /**
   * Serve up the <code>edit</code> mode.
   *
   * @see javax.portlet.GenericPortlet#doEdit(javax.portlet.RenderRequest,
   *     javax.portlet.RenderResponse)
   */
  public void doEdit(RenderRequest request, RenderResponse response)
      throws PortletException, IOException {
    // Set the MIME type for the render response
    response.setContentType(request.getResponseContentType());

    // Check if portlet session exists
    Vlado2PortletSessionBean sessionBean = getSessionBean(request);
    if (sessionBean == null) {
      response.getWriter().println("<b>NO PORTLET SESSION YET</b>");
      return;
    }

    // Invoke the JSP to render
    PortletRequestDispatcher rd =
        getPortletContext().getRequestDispatcher(getJspFilePath(request, EDIT_JSP));
    rd.include(request, response);
  }
예제 #22
0
  protected void remoteRender(RenderRequest renderRequest, RenderResponse renderResponse)
      throws Exception {

    ThemeDisplay themeDisplay = (ThemeDisplay) renderRequest.getAttribute(WebKeys.THEME_DISPLAY);

    OAuthRequest oAuthRequest = new OAuthRequest(Verb.GET, getServerPortletURL());

    setRequestParameters(renderRequest, renderResponse, oAuthRequest);

    Response response = getResponse(themeDisplay.getUser(), oAuthRequest);

    renderResponse.setContentType(ContentTypes.TEXT_HTML);

    PrintWriter printWriter = renderResponse.getWriter();

    printWriter.write(response.getBody());
  }
 private void showPrintableCatalog(RenderRequest request, RenderResponse response)
     throws PortletException, IOException {
   PortletRequestDispatcher dispatcher =
       request
           .getPortletSession()
           .getPortletContext()
           .getRequestDispatcher(response.encodeURL("/myservlet/bookServlet"));
   dispatcher.include(request, response);
 }
예제 #24
0
  public void doView(RenderRequest request, RenderResponse response)
      throws PortletException, IOException {
    // set return content type
    response.setContentType("text/html;charset=utf-8");

    request.setAttribute("news", getNews());
    PortletRequestDispatcher reqDispatcher = getPortletContext().getRequestDispatcher(PATHOGEN_JSP);
    reqDispatcher.include(request, response);
  }
 private void showPrefsInfo(RenderRequest request, RenderResponse response)
     throws PortletException, IOException {
   PortletRequestDispatcher dispatcher =
       request
           .getPortletSession()
           .getPortletContext()
           .getRequestDispatcher(response.encodeURL("/WEB-INF/jsp/preferences.jsp"));
   dispatcher.include(request, response);
 }
 @Override
 public DelegationResponse doRender(
     RenderRequest renderRequest,
     RenderResponse renderResponse,
     DelegationRequest delegationRequest)
     throws IOException {
   return this.doRender(
       renderRequest, renderResponse, delegationRequest, renderResponse.getWriter());
 }
예제 #27
0
  @Override
  protected void doView(RenderRequest request, RenderResponse response)
      throws PortletException, IOException {
    response.setContentType("text/html");

    PortletRequestDispatcher dispatcher =
        getPortletContext().getRequestDispatcher("/WEB-INF/jsp/view.jsp");

    dispatcher.include(request, response);
  }
예제 #28
0
  /**
   * Serve up the <code>view</code> mode.
   *
   * @see javax.portlet.GenericPortlet#doView(javax.portlet.RenderRequest,
   *     javax.portlet.RenderResponse)
   */
  public void doView(RenderRequest request, RenderResponse response)
      throws PortletException, IOException {
    // Set the MIME type for the render response
    response.setContentType(request.getResponseContentType());

    // Invoke the JSP to render
    PortletRequestDispatcher rd =
        getPortletContext().getRequestDispatcher(getJspFilePath(request, VIEW_JSP));
    rd.include(request, response);
  }
예제 #29
0
 /* (non-Javadoc)
  * @see javax.portlet.GenericPortlet#doView(javax.portlet.RenderRequest, javax.portlet.RenderResponse)
  */
 @Override
 protected void doView(RenderRequest request, RenderResponse response)
     throws PortletException, IOException, UnavailableException {
   response.setContentType("text/html");
   String username = request.getParameter("usernameFromAction");
   request.setAttribute("usernameFromDoView", username);
   String jspPath = (username != null && !username.isEmpty()) ? "/hello.jsp" : "/view.jsp";
   PortletRequestDispatcher prd = getPortletContext().getRequestDispatcher(jspPath);
   prd.include(request, response);
 }
예제 #30
0
  /** Serve up the custom <code>config</code> mode. */
  protected void doCustomConfigure(RenderRequest request, RenderResponse response)
      throws PortletException, IOException {
    // Set the MIME type for the render response
    response.setContentType(request.getResponseContentType());

    // Invoke the JSP to render
    PortletRequestDispatcher rd =
        getPortletContext().getRequestDispatcher(getJspFilePath(request, CONFIG_JSP));
    rd.include(request, response);
  }