public void execute(Event<UIPortlet> event) throws Exception { UIPortlet uiPortlet = event.getSource(); String portletMode = null; Object changePortletModeAttribute = event.getRequestContext().getAttribute(CHANGE_PORTLET_MODE_EVENT); if (changePortletModeAttribute != null && changePortletModeAttribute instanceof String) { portletMode = (String) changePortletModeAttribute; } if (portletMode == null) { portletMode = event.getRequestContext().getRequestParameter(Constants.PORTAL_PORTLET_MODE); } if (portletMode == null) { portletMode = event.getRequestContext().getRequestParameter(UIComponent.OBJECTID); } if (portletMode == null) { portletMode = uiPortlet.getCurrentPortletMode().toString(); } log.trace( "Change portlet mode of " + uiPortlet.getPortletContext().getId() + " to " + portletMode); if (portletMode.equals(PortletMode.HELP.toString())) { uiPortlet.setCurrentPortletMode(PortletMode.HELP); } else if (portletMode.equals(PortletMode.EDIT.toString())) { uiPortlet.setCurrentPortletMode(PortletMode.EDIT); } else if (portletMode.equals(PortletMode.VIEW.toString())) { uiPortlet.setCurrentPortletMode(PortletMode.VIEW); } else { PortletMode customMode = new PortletMode(portletMode); uiPortlet.setCurrentPortletMode(customMode); } event.getRequestContext().addUIComponentToUpdateByAjax(uiPortlet); }
public String getEditModeContent() { StringBuilder portletContent = new StringBuilder(); try { PortalRequestContext prcontext = (PortalRequestContext) WebuiRequestContext.getCurrentInstance(); prcontext.ignoreAJAXUpdateOnPortlets(true); StatefulPortletContext portletContext = uiPortlet_.getPortletContext(); ExoPortletInvocationContext portletInvocationContext = new ExoPortletInvocationContext(prcontext, uiPortlet_); List<Cookie> requestCookies = new ArrayList<Cookie>(Arrays.asList(prcontext.getRequest().getCookies())); PortletInvocation portletInvocation = uiPortlet_.create(RenderInvocation.class, prcontext); RenderInvocation renderInvocation = (RenderInvocation) portletInvocation; // make sure we are in the EDIT mode, and not whatever the current portlet mode is for the // Portlet renderInvocation.setMode(Mode.create(PortletMode.EDIT.toString())); PortletInvocationResponse portletResponse = uiPortlet_.invoke(renderInvocation); portletContent.append(uiPortlet_.generateRenderMarkup(portletResponse, prcontext).toString()); } catch (Throwable ex) { WebuiRequestContext webuiRequest = WebuiRequestContext.getCurrentInstance(); portletContent.append( webuiRequest.getApplicationResourceBundle().getString("UIPortlet.message.RuntimeError")); log.error( "The portlet " + uiPortlet_.getName() + " could not be loaded. Check if properly deployed.", ExceptionUtil.getRootCause(ex)); } return portletContent.toString(); }
public void execute(Event<UIPortlet> event) throws Exception { UIPortlet uiPortlet = event.getSource(); PortalRequestContext context = (PortalRequestContext) event.getRequestContext(); List<UIPortlet> portletInstancesInPage = new ArrayList<UIPortlet>(); // UIPortalApplication uiPortal = uiPortlet.getAncestorOfType(UIPortalApplication.class); UIPortalApplication uiPortal = (UIPortalApplication) context.getUIApplication(); uiPortal.findComponentOfType(portletInstancesInPage, UIPortlet.class); EventsWrapper eventsWrapper = (EventsWrapper) event.getRequestContext().getAttribute(PORTLET_EVENTS); List<javax.portlet.Event> events = eventsWrapper.getEvents(); /* * Iterate over all the events that the processAction * has generated. Check among all the portlet instances deployed in the * page (usual layout or webos) which instance can be targeted by the * event and then process the event on the associated UIPortlet component */ while (events.size() > 0) { javax.portlet.Event nativeEvent = events.remove(0); QName eventName = nativeEvent.getQName(); for (Iterator<UIPortlet> iterator = portletInstancesInPage.iterator(); iterator.hasNext(); ) { UIPortlet uiPortletInPage = iterator.next(); if (uiPortletInPage.supportsProcessingEvent(eventName) && !eventsWrapper.isInvokedTooManyTimes(uiPortletInPage)) { List<javax.portlet.Event> newEvents = processEvent(uiPortletInPage, nativeEvent); eventsWrapper.increaseCounter(uiPortletInPage); if (context.useAjax()) { log.info( "Events were generated inside the scope of an AJAX call, hence will only refresh the targeted portlets"); event.getRequestContext().addUIComponentToUpdateByAjax(uiPortletInPage); } else { log.info( "Events were generated outside the scope of an AJAX call, hence will make a full render of the page"); context.ignoreAJAXUpdateOnPortlets(true); } if (newEvents != null && !newEvents.isEmpty()) { log.trace( "The portlet: " + uiPortletInPage.getPortletContext().getId() + " processEvent() method has generated new events itself"); events.addAll(newEvents); } } } } }
public void execute(Event<UIPortlet<S, C>> event) throws Exception { UIPortlet<S, C> uiPortlet = event.getSource(); log.trace("Serve Resource for portlet: " + uiPortlet.getPortletContext()); String resourceId = null; // PortalRequestContext context = (PortalRequestContext) event.getRequestContext(); HttpServletResponse response = context.getResponse(); // try { // Set the NavigationalState String navState = context.getRequestParameter(ExoPortletInvocationContext.NAVIGATIONAL_STATE_PARAM_NAME); if (navState != null) { uiPortlet.setNavigationalState(ParametersStateString.create(navState)); } // ResourceInvocation resourceInvocation = uiPortlet.create(ResourceInvocation.class, context); // set the resourceId to be used in case of a problem resourceId = resourceInvocation.getResourceId(); // PortletInvocationResponse portletResponse = uiPortlet.invoke(resourceInvocation); // int statusCode; MultiValuedPropertyMap<String> transportHeaders; String contentType; String charset; Object content; if (!(portletResponse instanceof ContentResponse)) { if (portletResponse instanceof ErrorResponse) { ErrorResponse errorResponse = (ErrorResponse) portletResponse; Throwable cause = errorResponse.getCause(); if (cause != null) { log.trace("Got error response from portlet", cause); } else if (errorResponse.getMessage() != null) { log.trace("Got error response from portlet:" + errorResponse.getMessage()); } else { log.trace("Got error response from portlet"); } } else { log.trace( "Unexpected response type [" + portletResponse + "]. Expected a ContentResponse or an ErrorResponse."); } statusCode = HttpServletResponse.SC_INTERNAL_SERVER_ERROR; contentType = null; charset = null; transportHeaders = null; content = null; } else { // ContentResponse piResponse = (ContentResponse) portletResponse; ResponseProperties properties = piResponse.getProperties(); transportHeaders = properties != null ? properties.getTransportHeaders() : null; // Look at status code if there is one and honour it String status = transportHeaders != null ? transportHeaders.getValue(ResourceResponse.HTTP_STATUS_CODE) : null; if (status != null) { try { statusCode = Integer.parseInt(status); } catch (NumberFormatException e) { statusCode = HttpServletResponse.SC_INTERNAL_SERVER_ERROR; } } else { statusCode = HttpServletResponse.SC_OK; } // contentType = piResponse.getContentType(); charset = piResponse.getEncoding(); // log.trace( "Try to get a resource of type: " + contentType + " for the portlet: " + uiPortlet.getPortletContext()); if (piResponse.getChars() != null) { content = piResponse.getChars(); } else if (piResponse.getBytes() != null) { content = piResponse.getBytes(); } else { content = null; } } // response.setStatus(statusCode); // Set content type if any if (contentType != null) { response.setContentType(contentType); } // Set encoding if (charset != null) { response.setCharacterEncoding(charset); } // Send headers if any if (transportHeaders != null) { sendHeaders(transportHeaders, context); } // Send body if any if (content instanceof String) { context.getWriter().write((String) content); } else if (content instanceof byte[]) { byte[] bytes = (byte[]) content; response.setContentLength(bytes.length); OutputStream stream = response.getOutputStream(); try { stream.write(bytes); } finally { Safe.close(stream); } } // response.flushBuffer(); } catch (Exception e) { if (!e.getClass().toString().contains("ClientAbortException")) { log.error( "Problem while serving resource " + (resourceId != null ? resourceId : "") + " for the portlet: " + uiPortlet.getPortletContext().getId(), e); } } finally { /** The resource method does not need to go through the render phase */ event.getRequestContext().setResponseComplete(true); } }