Search in sources :

Example 6 with IPortalUrlBuilder

use of org.apereo.portal.url.IPortalUrlBuilder in project uPortal by Jasig.

the class LayoutRESTController method getRESTController.

/**
     * A REST call to get a json feed of the current users layout. Intent was to provide a layout
     * document without per-tab information for mobile device rendering.
     *
     * @param request The servlet request. Utilized to get the users instance and eventually there
     *     layout
     * @param tab The tab name of which you would like to filter; optional; if not provided, will
     *     return entire layout.
     * @return json feed of the layout
     * @deprecated Use /api/v4-3/dlm/layout.json. It has much more information about portlets and
     *     includes regions and breakout per tab
     */
@Deprecated
@RequestMapping(value = "/layoutDoc", method = RequestMethod.GET)
public ModelAndView getRESTController(HttpServletRequest request, @RequestParam(value = "tab", required = false) String tab) {
    final IPerson person = personManager.getPerson(request);
    List<LayoutPortlet> portlets = new ArrayList<LayoutPortlet>();
    try {
        final IUserInstance ui = userInstanceManager.getUserInstance(request);
        final IUserPreferencesManager upm = ui.getPreferencesManager();
        final IUserProfile profile = upm.getUserProfile();
        final DistributedUserLayout userLayout = userLayoutStore.getUserLayout(person, profile);
        Document document = userLayout.getLayout();
        NodeList portletNodes = null;
        if (tab != null) {
            NodeList folders = document.getElementsByTagName("folder");
            for (int i = 0; i < folders.getLength(); i++) {
                Node node = folders.item(i);
                if (tab.equalsIgnoreCase(node.getAttributes().getNamedItem("name").getNodeValue())) {
                    TabListOfNodes tabNodes = new TabListOfNodes();
                    tabNodes.addAllChannels(node.getChildNodes());
                    portletNodes = tabNodes;
                    break;
                }
            }
        } else {
            portletNodes = document.getElementsByTagName("channel");
        }
        for (int i = 0; i < portletNodes.getLength(); i++) {
            try {
                NamedNodeMap attributes = portletNodes.item(i).getAttributes();
                IPortletDefinition def = portletDao.getPortletDefinitionByFname(attributes.getNamedItem("fname").getNodeValue());
                LayoutPortlet portlet = new LayoutPortlet(def);
                portlet.setNodeId(attributes.getNamedItem("ID").getNodeValue());
                //get alt max URL
                String alternativeMaximizedLink = def.getAlternativeMaximizedLink();
                if (alternativeMaximizedLink != null) {
                    portlet.setUrl(alternativeMaximizedLink);
                    portlet.setAltMaxUrl(true);
                } else {
                    // get the maximized URL for this portlet
                    final IPortalUrlBuilder portalUrlBuilder = urlProvider.getPortalUrlBuilderByLayoutNode(request, attributes.getNamedItem("ID").getNodeValue(), UrlType.RENDER);
                    final IPortletWindowId targetPortletWindowId = portalUrlBuilder.getTargetPortletWindowId();
                    if (targetPortletWindowId != null) {
                        final IPortletUrlBuilder portletUrlBuilder = portalUrlBuilder.getPortletUrlBuilder(targetPortletWindowId);
                        portletUrlBuilder.setWindowState(WindowState.MAXIMIZED);
                    }
                    portlet.setUrl(portalUrlBuilder.getUrlString());
                    portlet.setAltMaxUrl(false);
                }
                portlets.add(portlet);
            } catch (Exception e) {
                log.warn("Exception construction JSON representation of mobile portlet", e);
            }
        }
        ModelAndView mv = new ModelAndView();
        mv.addObject("layout", portlets);
        mv.setViewName("json");
        return mv;
    } catch (Exception e) {
        log.error("Error retrieving user layout document", e);
    }
    return null;
}
Also used : NamedNodeMap(org.w3c.dom.NamedNodeMap) IPortletUrlBuilder(org.apereo.portal.url.IPortletUrlBuilder) NodeList(org.w3c.dom.NodeList) Node(org.w3c.dom.Node) ArrayList(java.util.ArrayList) ModelAndView(org.springframework.web.servlet.ModelAndView) Document(org.w3c.dom.Document) IPortalUrlBuilder(org.apereo.portal.url.IPortalUrlBuilder) IUserInstance(org.apereo.portal.user.IUserInstance) IPerson(org.apereo.portal.security.IPerson) TabListOfNodes(org.apereo.portal.rest.layout.TabListOfNodes) IUserProfile(org.apereo.portal.IUserProfile) IUserPreferencesManager(org.apereo.portal.IUserPreferencesManager) DistributedUserLayout(org.apereo.portal.layout.dlm.DistributedUserLayout) LayoutPortlet(org.apereo.portal.layout.LayoutPortlet) IPortletWindowId(org.apereo.portal.portlet.om.IPortletWindowId) IPortletDefinition(org.apereo.portal.portlet.om.IPortletDefinition) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 7 with IPortalUrlBuilder

use of org.apereo.portal.url.IPortalUrlBuilder in project uPortal by Jasig.

the class PortletURLProviderImpl method getType.

/* (non-Javadoc)
     * @see org.apache.pluto.container.PortletURLProvider#getType()
     */
@Override
public TYPE getType() {
    final IPortalUrlBuilder portalUrlBuilder = this.portletUrlBuilder.getPortalUrlBuilder();
    final UrlType urlType = portalUrlBuilder.getUrlType();
    return urlType.getPortletUrlType();
}
Also used : IPortalUrlBuilder(org.apereo.portal.url.IPortalUrlBuilder) UrlType(org.apereo.portal.url.UrlType)

Example 8 with IPortalUrlBuilder

use of org.apereo.portal.url.IPortalUrlBuilder in project uPortal by Jasig.

the class PortalController method actionRequest.

@RequestMapping(headers = { "org.apereo.portal.url.UrlType=ACTION" })
public void actionRequest(HttpServletRequest request, HttpServletResponse response) throws IOException {
    final IPortalRequestInfo portalRequestInfo = this.urlSyntaxProvider.getPortalRequestInfo(request);
    final IPortletRequestInfo portletRequestInfo = portalRequestInfo.getTargetedPortletRequestInfo();
    final IPortalUrlBuilder actionRedirectUrl;
    if (portletRequestInfo != null) {
        final IPortletWindowId targetWindowId = portletRequestInfo.getPortletWindowId();
        actionRedirectUrl = this.portalUrlProvider.getPortalUrlBuilderByPortletWindow(request, targetWindowId, UrlType.RENDER);
    } else {
        final String targetedLayoutNodeId = portalRequestInfo.getTargetedLayoutNodeId();
        if (targetedLayoutNodeId != null) {
            actionRedirectUrl = this.portalUrlProvider.getPortalUrlBuilderByLayoutNode(request, targetedLayoutNodeId, UrlType.RENDER);
        } else {
            actionRedirectUrl = this.portalUrlProvider.getDefaultUrl(request);
        }
    }
    //Stuff the action-redirect URL builder into the request so other code can use it during request processing
    this.portalUrlProvider.convertToPortalActionUrlBuilder(request, actionRedirectUrl);
    if (portletRequestInfo != null) {
        final IPortletWindowId targetWindowId = portletRequestInfo.getPortletWindowId();
        try {
            this.portletExecutionManager.doPortletAction(targetWindowId, request, response);
        } catch (RuntimeException e) {
            this.logger.error("Exception thrown while executing portlet action for: " + portletRequestInfo, e);
            //TODO this should be a constant right?
            actionRedirectUrl.setParameter("portletActionError", targetWindowId.toString());
        }
    }
    sendRedirect(actionRedirectUrl, response);
}
Also used : IPortalRequestInfo(org.apereo.portal.url.IPortalRequestInfo) IPortletRequestInfo(org.apereo.portal.url.IPortletRequestInfo) IPortalUrlBuilder(org.apereo.portal.url.IPortalUrlBuilder) IPortletWindowId(org.apereo.portal.portlet.om.IPortletWindowId) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 9 with IPortalUrlBuilder

use of org.apereo.portal.url.IPortalUrlBuilder in project uPortal by Jasig.

the class PortletErrorController method executeReset.

/**
     * @param request
     * @param response
     * @throws Exception
     */
@RequestMapping("VIEW")
public void executeReset(ActionRequest request, ActionResponse response) throws Exception {
    final String windowId = request.getParameter("failedPortletWindowId");
    if (StringUtils.isNotBlank(windowId)) {
        HttpServletRequest httpRequest = this.portalRequestUtils.getPortletHttpRequest(request);
        IPortletWindowId portletWindowId = this.portletWindowRegistry.getPortletWindowId(httpRequest, windowId);
        HttpServletResponse httpResponse = this.portalRequestUtils.getOriginalPortalResponse(request);
        this.portletRenderer.doReset(portletWindowId, httpRequest, httpResponse);
        IPortalUrlBuilder builder = this.portalUrlProvider.getPortalUrlBuilderByPortletWindow(httpRequest, portletWindowId, UrlType.RENDER);
        response.sendRedirect(builder.getUrlString());
    }
}
Also used : HttpServletRequest(javax.servlet.http.HttpServletRequest) HttpServletResponse(javax.servlet.http.HttpServletResponse) IPortalUrlBuilder(org.apereo.portal.url.IPortalUrlBuilder) IPortletWindowId(org.apereo.portal.portlet.om.IPortletWindowId) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 10 with IPortalUrlBuilder

use of org.apereo.portal.url.IPortalUrlBuilder in project uPortal by Jasig.

the class PortletErrorController method renderError.

/**
     * Render the error portlet view.
     *
     * @param request
     * @param response
     * @param model
     * @return the name of the view to display
     * @throws Exception
     */
@RequestMapping("VIEW")
public String renderError(RenderRequest request, RenderResponse response, ModelMap model) throws Exception {
    HttpServletRequest httpRequest = this.portalRequestUtils.getPortletHttpRequest(request);
    IPortletWindowId currentFailedPortletWindowId = (IPortletWindowId) request.getAttribute(REQUEST_ATTRIBUTE__CURRENT_FAILED_PORTLET_WINDOW_ID);
    model.addAttribute("portletWindowId", currentFailedPortletWindowId);
    Exception cause = (Exception) request.getAttribute(REQUEST_ATTRIBUTE__CURRENT_EXCEPTION_CAUSE);
    model.addAttribute("exception", cause);
    final String rootCauseMessage = ExceptionUtils.getRootCauseMessage(cause);
    model.addAttribute("rootCauseMessage", rootCauseMessage);
    // Maintenance Mode?
    if (cause != null && cause instanceof MaintenanceModeException) {
        return "/jsp/PortletError/maintenance";
    }
    IUserInstance userInstance = this.userInstanceManager.getUserInstance(httpRequest);
    if (hasAdminPrivileges(userInstance)) {
        IPortletWindow window = this.portletWindowRegistry.getPortletWindow(httpRequest, currentFailedPortletWindowId);
        window.setRenderParameters(new ParameterMap());
        IPortalUrlBuilder adminRetryUrl = this.portalUrlProvider.getPortalUrlBuilderByPortletWindow(httpRequest, currentFailedPortletWindowId, UrlType.RENDER);
        model.addAttribute("adminRetryUrl", adminRetryUrl.getUrlString());
        final IPortletWindow portletWindow = portletWindowRegistry.getPortletWindow(httpRequest, currentFailedPortletWindowId);
        final IPortletEntity parentPortletEntity = portletWindow.getPortletEntity();
        final IPortletDefinition parentPortletDefinition = parentPortletEntity.getPortletDefinition();
        model.addAttribute("channelDefinition", parentPortletDefinition);
        StringWriter stackTraceWriter = new StringWriter();
        cause.printStackTrace(new PrintWriter(stackTraceWriter));
        model.addAttribute("stackTrace", stackTraceWriter.toString());
        return "/jsp/PortletError/detailed";
    }
    // no admin privileges, return generic view
    return "/jsp/PortletError/generic";
}
Also used : ParameterMap(org.apereo.portal.url.ParameterMap) IPortalUrlBuilder(org.apereo.portal.url.IPortalUrlBuilder) IPortletWindow(org.apereo.portal.portlet.om.IPortletWindow) HttpServletRequest(javax.servlet.http.HttpServletRequest) IUserInstance(org.apereo.portal.user.IUserInstance) StringWriter(java.io.StringWriter) IPortletEntity(org.apereo.portal.portlet.om.IPortletEntity) IPortletWindowId(org.apereo.portal.portlet.om.IPortletWindowId) IPortletDefinition(org.apereo.portal.portlet.om.IPortletDefinition) PrintWriter(java.io.PrintWriter) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Aggregations

IPortalUrlBuilder (org.apereo.portal.url.IPortalUrlBuilder)17 IPortletUrlBuilder (org.apereo.portal.url.IPortletUrlBuilder)11 IPortletWindowId (org.apereo.portal.portlet.om.IPortletWindowId)8 HttpServletRequest (javax.servlet.http.HttpServletRequest)7 IPortletWindow (org.apereo.portal.portlet.om.IPortletWindow)6 UrlType (org.apereo.portal.url.UrlType)5 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)5 IPortletDefinition (org.apereo.portal.portlet.om.IPortletDefinition)4 PortletUrlParameter (org.apereo.portal.search.PortletUrlParameter)3 URL (java.net.URL)2 PortletUrl (org.apereo.portal.search.PortletUrl)2 PortletUrlType (org.apereo.portal.search.PortletUrlType)2 SearchResult (org.apereo.portal.search.SearchResult)2 SearchResults (org.apereo.portal.search.SearchResults)2 IPerson (org.apereo.portal.security.IPerson)2 IUserInstance (org.apereo.portal.user.IUserInstance)2 Document (org.w3c.dom.Document)2 PrintWriter (java.io.PrintWriter)1 StringWriter (java.io.StringWriter)1 UnsupportedEncodingException (java.io.UnsupportedEncodingException)1