@ProcessAction(name = "searchBookAction") public void searchBook(ActionRequest request, ActionResponse response) throws PortletException, IOException { logger.info("Inside search Book action"); request.setAttribute("myaction", "searchBookAction"); PortletRequestDispatcher dispatcher = request .getPortletSession() .getPortletContext() .getRequestDispatcher(response.encodeURL("/myservlet/bookServlet")); dispatcher.include(request, response); response.setRenderParameter("myaction", "showSearchResults"); // --store the search criteria in session request .getPortletSession() .setAttribute( "authorNameSearchField", request.getParameter("authorNameSearchField"), PortletSession.APPLICATION_SCOPE); request .getPortletSession() .setAttribute( "bookNameSearchField", request.getParameter("bookNameSearchField"), PortletSession.APPLICATION_SCOPE); // retrieving the matchingBooks request attribute set by BookServlet and // store it in session request .getPortletSession() .setAttribute("matchingBooks", request.getAttribute("matchingBooks")); }
@SuppressWarnings("unchecked") @ProcessAction(name = "addBookAction") public void addBook(ActionRequest request, ActionResponse response) throws PortletException, IOException { logger.info("addBook action invoked"); if (!request.isUserInRole("administrator")) { response.setRenderParameter("myaction", "error"); response.setRenderParameter( "exceptionMsg", "You are not authorized for this action. You must have Administrator role."); return; } request.setAttribute("myaction", "addBookAction"); PortletRequestDispatcher dispatcher = request .getPortletSession() .getPortletContext() .getRequestDispatcher(response.encodeURL("/myservlet/bookServlet")); dispatcher.include(request, response); Map<String, String> map = (Map<String, String>) request.getAttribute("errors"); if (map != null && !map.isEmpty()) { response.setRenderParameter("myaction", "addBookAction"); } else { response.setRenderParameter("myaction", "showCatalog"); } }
protected void doView(RenderRequest request, RenderResponse response) throws PortletException, IOException { _log.debug("VIEW"); // Portlet preferences PortletPreferences prefs = request.getPreferences(); String users = prefs.getValue("users", "root"); // Business Invocation BlogAPI blogService = blogService(); ArrayList<Blog> blogs = blogService.getBlogs(); // Checking Admin rights if (request.getUserPrincipal() != null && request.getUserPrincipal().getName() != null) { for (String user : users.split(",")) if (user.equals(request.getUserPrincipal().getName())) { request.setAttribute("admin", request.getUserPrincipal().getName()); break; } } else { request.setAttribute("admin", null); } request.setAttribute("blogs", blogs); // Controlling the view String view = "/jsp/management.jsp"; PortletRequestDispatcher prd = getPortletContext().getRequestDispatcher(view); prd.include(request, response); }
// 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; }
@Override protected void doProcessCommand(PortletRequest portletRequest, PortletResponse portletResponse) throws Exception { try { copyArticle(portletRequest); } catch (Exception e) { if (e instanceof NoSuchArticleException || e instanceof PrincipalException) { SessionErrors.add(portletRequest, e.getClass()); PortletSession portletSession = portletRequest.getPortletSession(); PortletContext portletContext = portletSession.getPortletContext(); PortletRequestDispatcher portletRequestDispatcher = portletContext.getRequestDispatcher("/html/portlet/journal/error.jsp"); portletRequestDispatcher.include(portletRequest, portletResponse); } else if (e instanceof DuplicateArticleIdException || e instanceof ArticleIdException) { SessionErrors.add(portletRequest, e.getClass()); } else { throw e; } } }
public void serveResource( ActionMapping actionMapping, ActionForm actionForm, PortletConfig portletConfig, ResourceRequest resourceRequest, ResourceResponse resourceResponse) throws Exception { String resourceID = resourceRequest.getResourceID(); if (Validator.isNull(resourceID)) { return; } PortletContext portletContext = portletConfig.getPortletContext(); PortletRequestDispatcher portletRequestDispatcher = portletContext.getRequestDispatcher(resourceID); if (portletRequestDispatcher == null) { return; } portletRequestDispatcher.forward(resourceRequest, resourceResponse); }
private void showPrintableCatalog(RenderRequest request, RenderResponse response) throws PortletException, IOException { PortletRequestDispatcher dispatcher = request .getPortletSession() .getPortletContext() .getRequestDispatcher(response.encodeURL("/myservlet/bookServlet")); dispatcher.include(request, response); }
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); }
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); }
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); }
protected void include(String path, RenderRequest renderRequest, RenderResponse renderResponse) throws IOException, PortletException { PortletRequestDispatcher portletRequestDispatcher = getPortletContext().getRequestDispatcher(path); if (portletRequestDispatcher == null) { log.error(path + " is not a valid include"); } else { portletRequestDispatcher.include(renderRequest, renderResponse); } }
/* (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); }
/** * 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); }
/** 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); }
@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); }
public void doView(RenderRequest request, RenderResponse response) throws PortletException, IOException { String sYourName = (String) request.getParameter("yourname"); if (sYourName != null) { PortletRequestDispatcher prd = getPortletContext().getRequestDispatcher("/jsp/hello.jsp"); prd.include(request, response); } else { PortletRequestDispatcher prd = getPortletContext().getRequestDispatcher("/jsp/welcome.jsp"); prd.include(request, response); } }
public void doView(RenderRequest request, RenderResponse response) { try { setRenderAttributes(request); response.setContentType("text/html"); PortletRequestDispatcher prd = getPortletContext().getRequestDispatcher("/WEB-INF/jsp/Browser/browser.jsp"); prd.include(request, response); } catch (Exception e) { e.printStackTrace(); } }
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); } }
/** Include a page. */ private void include(RenderRequest request, RenderResponse response, String pageName) throws PortletException { response.setContentType(request.getResponseContentType()); if (!StringUtil.isDefined(pageName)) { throw new NullPointerException("null or empty page name"); } try { PortletRequestDispatcher dispatcher = getPortletContext().getRequestDispatcher("/portlets/jsp/lastPublications/" + pageName); dispatcher.include(request, response); } catch (IOException ioe) { log("Could not include a page", ioe); throw new PortletException(ioe); } }
/** * Serve the resource as specified in the given request to the given response, using the * PortletContext's request dispatcher. * * <p>This is roughly equivalent to Portlet 2.0 GenericPortlet. * * @param request the current resource request * @param response the current resource response * @param context the current Portlet's PortletContext * @throws PortletException propagated from Portlet API's forward method * @throws IOException propagated from Portlet API's forward method */ public static void serveResource( ResourceRequest request, ResourceResponse response, PortletContext context) throws PortletException, IOException { String id = request.getResourceID(); if (id != null) { if (!PortletUtils.isProtectedResource(id)) { PortletRequestDispatcher rd = context.getRequestDispatcher(id); if (rd != null) { rd.forward(request, response); return; } } response.setProperty(ResourceResponse.HTTP_STATUS_CODE, "404"); } }
/** * 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); }
// Validate obtained access token with usage of concrete OAuthProvider and save it to session if // it's valid protected AccessToken validateAccessToken( PortletRequest request, PortletResponse response, OAuthProvider oauthProvider, AccessToken accessToken) throws PortletException, IOException { AccessToken previousAccessToken = (AccessToken) request.getPortletSession().getAttribute(ATTRIBUTE_ACCESS_TOKEN); if (isValidationNeeded(accessToken, previousAccessToken)) { // Validate accessToken try { accessToken = getOAuthProvider().validateTokenAndUpdateScopes(accessToken); } catch (OAuthApiException oe) { String jspPage; if (oe.getExceptionCode() == OAuthApiExceptionCode.ACCESS_TOKEN_ERROR) { request.setAttribute( ATTRIBUTE_ERROR_MESSAGE, oauthProvider.getFriendlyName() + " access token is invalid."); request.setAttribute(ATTRIBUTE_OAUTH_PROVIDER, oauthProvider); jspPage = "/jsp/error/token.jsp"; } else if (oe.getExceptionCode() == OAuthApiExceptionCode.IO_ERROR) { oe.printStackTrace(); request.setAttribute( ATTRIBUTE_ERROR_MESSAGE, "I/O error happened. See server.log for more details"); jspPage = "/jsp/error/error.jsp"; } else { // Some unexpected error throw new PortletException(oe); } PortletRequestDispatcher prd = filterConfig.getPortletContext().getRequestDispatcher(jspPage); prd.include(request, response); return null; } if (!accessToken.equals(previousAccessToken)) { saveAccessToken(request, response, accessToken); } } return accessToken; }
/** * 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()); HttpServletRequest req = (HttpServletRequest) request; ServletRequest sreq = (ServletRequest) request; System.out.println("TEST--->" + req.getQueryString()); System.out.println("TEST2--->" + sreq.getParameter("param")); // 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, VIEW_JSP)); rd.include(request, response); }
@Override public void serveResource(ResourceRequest portletReq, ResourceResponse portletResp) throws PortletException, IOException { LOGGER.entering(LOG_CLASS, "main portlet serveResource entry"); long tid = Thread.currentThread().getId(); portletReq.setAttribute(THREADID_ATTR, tid); PrintWriter writer = portletResp.getWriter(); // Now do the actual dispatch String target = SERVLET_PREFIX + "DispatcherTests_SPEC2_19_ForwardServletResource_servlet" + SERVLET_SUFFIX + "?" + QUERY_STRING; PortletRequestDispatcher rd = portletConfig.getPortletContext().getRequestDispatcher(target); rd.forward(portletReq, portletResp); }
@ProcessAction(name = "removeBookAction") public void removeBook(ActionRequest request, ActionResponse response) throws PortletException, IOException { logger.info("Inside removeBook action method"); if (!request.isUserInRole("administrator")) { response.setRenderParameter("myaction", "error"); response.setRenderParameter( "exceptionMsg", "You are not authorized for this action. You must have Administrator role."); return; } request.setAttribute("myaction", "removeBookAction"); PortletRequestDispatcher dispatcher = request .getPortletSession() .getPortletContext() .getRequestDispatcher(response.encodeURL("/myservlet/bookServlet")); dispatcher.include(request, response); response.setRenderParameter("myaction", "showCatalog"); }
@Override public void processAction(ActionRequest portletReq, ActionResponse portletResp) throws PortletException, IOException { LOGGER.entering(LOG_CLASS, "main portlet processAction entry"); portletResp.setRenderParameters(portletReq.getParameterMap()); long tid = Thread.currentThread().getId(); portletReq.setAttribute(THREADID_ATTR, tid); StringWriter writer = new StringWriter(); // Now do the actual dispatch String target = JSP_PREFIX + "DispatcherReqRespTests3_SPEC2_19_IncludeJSPActionResponse" + JSP_SUFFIX + "?" + QUERY_STRING; PortletRequestDispatcher rd = portletConfig.getPortletContext().getRequestDispatcher(target); rd.include(portletReq, portletResp); }
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)); } }
@Override public void doFilter(RenderRequest request, RenderResponse response, FilterChain chain) throws IOException, PortletException { String username = request.getRemoteUser(); if (username == null) { request.setAttribute( ATTRIBUTE_ERROR_MESSAGE, "No content available for anonymous user. You need to login first."); PortletRequestDispatcher prd = filterConfig.getPortletContext().getRequestDispatcher("/jsp/error/error.jsp"); prd.include(request, response); return; } OAuthProvider oauthProvider = getOAuthProvider(); if (oauthProvider == null) { String errorMessage = "OAuth provider '" + oauthProviderKey + "' not available"; request.setAttribute(ATTRIBUTE_ERROR_MESSAGE, errorMessage); PortletRequestDispatcher prd = filterConfig.getPortletContext().getRequestDispatcher("/jsp/error/error.jsp"); prd.include(request, response); return; } AccessToken accessToken = loadAccessTokenOrRedirectToObtainIt(username, oauthProvider, request, response); if (accessToken != null) { accessToken = validateAccessToken(request, response, oauthProvider, accessToken); if (accessToken != null) { requestContext.saveOAuthInfo(oauthProvider, accessToken); chain.doFilter(request, response); } } }
@Override public void doView(RenderRequest request, RenderResponse response) throws PortletException, IOException { try { String view = VIEW_FORM_PAGE; String viewType = request.getParameter("viewType"); if (viewType == null) { viewType = (String) request.getPortletSession().getAttribute("viewType"); } // Set global preferences request.setAttribute(TITLE, request.getPreferences().getValue(PREF_TITLE, null)); request.setAttribute( INTRODUCTION_MESSAGE, request.getPreferences().getValue(PREF_INTRODUCTION_MESSAGE, null)); User user = PortalUtils.getUser(request); Project project = PortalUtils.getProject(request); Task task = (Task) request.getPortletSession().getAttribute("task"); int projectId = project == null ? -1 : project.getId(); String projectIdOfLists = request.getParameter(PROJECT_ID_OF_LISTS); int pidOfLists = projectIdOfLists == null ? -1 : Integer.parseInt(projectIdOfLists); LOG.debug("doView: pidOfLists -- " + pidOfLists); // Clean up session request.getPortletSession().removeAttribute(VIEW_TYPE); request.getPortletSession().removeAttribute(PROJECT_ID_OF_LISTS); if (SAVE_FAILURE.equals(viewType)) { // Prep the form to show errors... request.setAttribute( ACTION_ERROR, request.getPreferences().getValue(PREF_FAILURE_MESSAGE, null)); // Show the form with any errors provided PortalUtils.processErrors(request, task.getErrors()); } else if (SAVE_SUCCESS.equals(viewType)) { // Save Success request.setAttribute( SUCCESS_MESSAGE, request.getPreferences().getValue(PREF_SUCCESS_MESSAGE, null)); view = VIEW_MESSAGE_PAGE; } else { if (!user.isLoggedIn()) { // If user is not logged in, redirect view = VIEW_MESSAGE_PAGE; request.setAttribute(ACTION_ERROR, "You need to be logged in to perform this action"); } else if (projectId <= 0) { request.setAttribute(ACTION_ERROR, "No project was specified"); view = VIEW_MESSAGE_PAGE; } else { view = VIEW_FORM_PAGE; try { Connection db = PortalUtils.useConnection(request); int userProfileId = user.getProfileProjectId(); Project userProfile; if (userProfileId == -1) { view = VIEW_MESSAGE_PAGE; request.setAttribute(ACTION_ERROR, "No profile is available to bookmark."); } else { userProfile = ProjectUtils.loadProject(userProfileId); if (pidOfLists == -1) { pidOfLists = userProfile.getId(); } // check the user has permissions to add/delete from lists for the project whose lists // are being modified // these will be used by the view to dynamically show/hide functionality request.setAttribute( CAN_ADD_LIST, ProjectUtils.hasAccess(pidOfLists, user, "project-lists-add")); request.setAttribute( CAN_DELETE_FROM_LIST, ProjectUtils.hasAccess(pidOfLists, user, "project-lists-delete")); ProjectList projectList = findUserProjects(db, user); ProjectList availableProjects = new ProjectList(); // Profile needs to appear on top so remove it from list and don't add twice availableProjects.add(userProfile); for (int i = 0; i != projectList.size(); i++) { Project p = projectList.get(i); if (p.getId() != userProfile.getId()) { availableProjects.add(p); } } TaskCategoryList availableLists = getAvailableLists(db, pidOfLists); String errorMessage = (String) request.getPortletSession().getAttribute(ACTION_ERROR); if (StringUtils.hasText(errorMessage)) { request.setAttribute(ACTION_ERROR, errorMessage); } Map<Integer, TaskCategory> usedLists = findExistingTaskCategorysForProjects(db, pidOfLists, project.getId()); request.setAttribute(PROJECT_ID_OF_LISTS, pidOfLists); request.setAttribute(PROJECT, project); request.setAttribute(AVAILABLE_LISTS, availableLists); request.setAttribute(USER_PROFILE, userProfile); request.setAttribute(AVAILABLE_PROJECTS, availableProjects); request.setAttribute(USED_LIST_MAP, usedLists); } } catch (SQLException e) { e.printStackTrace(); view = VIEW_MESSAGE_PAGE; request.setAttribute( ACTION_ERROR, "An error occurred processing your request. Please try again."); } } } // Clean up session request.getPortletSession().removeAttribute(ACTION_ERROR); PortletContext context = getPortletContext(); PortletRequestDispatcher requestDispatcher = context.getRequestDispatcher(view); requestDispatcher.include(request, response); } catch (Exception e) { e.printStackTrace(); throw new PortletException(e); } }
protected void doEdit(RenderRequest rRequest, RenderResponse rResponse) throws PortletException, IOException { rResponse.setContentType("text/html"); PortletRequestDispatcher prd = getPortletContext().getRequestDispatcher("/jsp/edit.jsp"); prd.include(rRequest, rResponse); }