Search in sources :

Example 6 with SpelParseException

use of org.springframework.expression.spel.SpelParseException in project uPortal by Jasig.

the class SearchPortletController method modifySearchResultLinkTitle.

/**
     * Since portlets don't have access to the portlet definition to create a useful search results
     * link using something like the portlet definition's title, post-process the link text and for
     * those portlets whose type is present in the substitution set, replace the title with the
     * portlet definition's title.
     *
     * @param result Search results object (may be modified)
     * @param httpServletRequest HttpServletRequest
     * @param portletWindowId Portlet Window ID
     */
protected void modifySearchResultLinkTitle(SearchResult result, final HttpServletRequest httpServletRequest, final IPortletWindowId portletWindowId) {
    // If the title contains a SpEL expression, parse it with the portlet definition in the evaluation context.
    if (result.getType().size() > 0 && result.getTitle().contains("${")) {
        final IPortletWindow portletWindow = this.portletWindowRegistry.getPortletWindow(httpServletRequest, portletWindowId);
        final IPortletEntity portletEntity = portletWindow.getPortletEntity();
        final IPortletDefinition portletDefinition = portletEntity.getPortletDefinition();
        final SpELEnvironmentRoot spelEnvironment = new SpELEnvironmentRoot(portletDefinition);
        try {
            result.setTitle(spELService.getValue(result.getTitle(), spelEnvironment));
        } catch (SpelParseException | SpelEvaluationException e) {
            result.setTitle("(Invalid portlet title) - see details in log file");
            logger.error("Invalid Spring EL expression {} in search result portlet title", result.getTitle(), e);
        }
    }
}
Also used : SpelParseException(org.springframework.expression.spel.SpelParseException) SpelEvaluationException(org.springframework.expression.spel.SpelEvaluationException) IPortletEntity(org.apereo.portal.portlet.om.IPortletEntity) IPortletWindow(org.apereo.portal.portlet.om.IPortletWindow) IPortletDefinition(org.apereo.portal.portlet.om.IPortletDefinition)

Aggregations

SpelParseException (org.springframework.expression.spel.SpelParseException)6 InternalParseException (org.springframework.expression.spel.InternalParseException)5 IPortletDefinition (org.apereo.portal.portlet.om.IPortletDefinition)1 IPortletEntity (org.apereo.portal.portlet.om.IPortletEntity)1 IPortletWindow (org.apereo.portal.portlet.om.IPortletWindow)1 SpelEvaluationException (org.springframework.expression.spel.SpelEvaluationException)1 SpelNodeImpl (org.springframework.expression.spel.ast.SpelNodeImpl)1