Search in sources :

Example 1 with ModelAndView

use of org.springframework.web.portlet.ModelAndView in project uPortal by Jasig.

the class SqlQueryPortletController method handleRenderRequest.

@Override
public ModelAndView handleRenderRequest(RenderRequest request, RenderResponse response) throws Exception {
    // find the configured SQL statement
    PortletPreferences preferences = request.getPreferences();
    String sqlQuery = preferences.getValue(SQL_QUERY_PARAM_NAME, null);
    String dsName = preferences.getValue(DATASOURCE_BEAN_NAME_PARAM_NAME, BasePortalJpaDao.PERSISTENCE_UNIT_NAME);
    String viewName = preferences.getValue(VIEW_PARAM_NAME, "jsp/SqlQuery/results");
    // Allow substituting attributes from the request and userInfo objects using the SPEL ${} notation..
    String spelSqlQuery = evaluateSpelExpression(sqlQuery, request);
    List<Map<String, Object>> results = null;
    String cacheKey = createCacheKey(spelSqlQuery, dsName);
    Cache cache = getCache(request);
    if (cache != null) {
        Element cachedElement = cache.get(cacheKey);
        if (cachedElement != null) {
            log.debug("Cache hit. Returning item for query: {}, substituted query: {}, from cache {} for key {}", sqlQuery, spelSqlQuery, cache.getName(), cacheKey);
            results = (List<Map<String, Object>>) cachedElement.getObjectValue();
        }
    }
    if (results == null) {
        // generate a JDBC template for the requested data source
        DataSource ds = (DataSource) getApplicationContext().getBean(dsName);
        JdbcTemplate template = new JdbcTemplate(ds);
        // Execute the SQL query and build a results object.  This result will consist of one
        // rowname -> rowvalue map for each row in the result set
        results = template.query(spelSqlQuery, new ColumnMapRowMapper());
        log.debug("found {} results for query {}", results.size(), spelSqlQuery);
        if (cache != null) {
            log.debug("Adding SQL results to cache {}, query: {}, substituted query: {}", cache.getName(), sqlQuery, spelSqlQuery);
            Element cachedElement = new Element(cacheKey, results);
            cache.put(cachedElement);
        }
    }
    // build the model
    ModelAndView modelandview = new ModelAndView(viewName);
    modelandview.addObject("results", results);
    return modelandview;
}
Also used : Element(net.sf.ehcache.Element) ModelAndView(org.springframework.web.portlet.ModelAndView) PortletPreferences(javax.portlet.PortletPreferences) ColumnMapRowMapper(org.springframework.jdbc.core.ColumnMapRowMapper) JdbcTemplate(org.springframework.jdbc.core.JdbcTemplate) Map(java.util.Map) Cache(net.sf.ehcache.Cache) DataSource(javax.sql.DataSource)

Example 2 with ModelAndView

use of org.springframework.web.portlet.ModelAndView in project uPortal by Jasig.

the class IFramePortletController method display.

@RenderMapping
protected ModelAndView display(RenderRequest req, RenderResponse res) throws Exception {
    Map<String, Object> model = new HashMap<String, Object>();
    // get the IFrame target URL and the configured height of the IFrame
    // window from the portlet preferences
    PortletPreferences prefs = req.getPreferences();
    for (final Map.Entry<String, String> attrEntry : IFRAME_ATTRS.entrySet()) {
        final String attr = attrEntry.getKey();
        final String defaultValue = attrEntry.getValue();
        model.put(attr, prefs.getValue(attr, defaultValue));
    }
    //Legacy support for url attribute
    if (model.get("src") == null) {
        model.put("src", prefs.getValue("url", IFRAME_ATTRS.get("src")));
    }
    // Fix for double scrollbars in specialized window states that control the whole window
    if (req.getWindowState().equals(IPortletRenderer.DETACHED) || req.getWindowState().equals(IPortletRenderer.EXCLUSIVE)) {
        model.put("onload", SCROLL_HEIGHT_ONLOAD_FIX);
    }
    return new ModelAndView("/jsp/IFrame/iframePortlet", "attrs", model);
}
Also used : LinkedHashMap(java.util.LinkedHashMap) HashMap(java.util.HashMap) ModelAndView(org.springframework.web.portlet.ModelAndView) PortletPreferences(javax.portlet.PortletPreferences) LinkedHashMap(java.util.LinkedHashMap) Map(java.util.Map) HashMap(java.util.HashMap) RenderMapping(org.springframework.web.portlet.bind.annotation.RenderMapping)

Example 3 with ModelAndView

use of org.springframework.web.portlet.ModelAndView in project uPortal by Jasig.

the class ImagePortletController method handleRenderRequestInternal.

@Override
protected ModelAndView handleRenderRequestInternal(RenderRequest request, RenderResponse response) throws Exception {
    final Map<String, Object> model = new HashMap<String, Object>();
    final PortletPreferences preferences = request.getPreferences();
    final PortletWebRequest webRequest = new PortletWebRequest(request);
    // retrieve configuration information about the image from the portlet
    // preferences
    model.put("uri", getPreference("img-uri", webRequest, preferences));
    model.put("width", getPreference("img-width", webRequest, preferences));
    model.put("height", getPreference("img-height", webRequest, preferences));
    model.put("border", getPreference("img-border", webRequest, preferences));
    model.put("link", getPreference("img-link", webRequest, preferences));
    model.put("caption", getPreference("caption", webRequest, preferences));
    model.put("subcaption", getPreference("subcaption", webRequest, preferences));
    model.put("alt", getPreference("alt-text", webRequest, preferences));
    return new ModelAndView("/jsp/Image/imagePortlet", model);
}
Also used : PortletWebRequest(org.springframework.web.portlet.context.PortletWebRequest) HashMap(java.util.HashMap) ModelAndView(org.springframework.web.portlet.ModelAndView) PortletPreferences(javax.portlet.PortletPreferences)

Example 4 with ModelAndView

use of org.springframework.web.portlet.ModelAndView in project uPortal by Jasig.

the class JspInvokerPortletController method render.

@RenderMapping
protected ModelAndView render(RenderRequest req, RenderResponse res) {
    final Map<String, Object> model = new HashMap<String, Object>();
    @SuppressWarnings("unchecked") final Map<String, String> userInfo = (Map<String, String>) req.getAttribute(PortletRequest.USER_INFO);
    model.put("userInfo", userInfo);
    logger.debug("Invoking with userInfo={}", userInfo);
    // Can access property values in JSP using ${properties.getProperty('propertyName')}
    model.put("properties", properties.getPropertyResolver());
    // Determine if guest user.
    IPerson person = personManager.getPerson(portalRequestUtils.getPortletHttpRequest(req));
    model.put("authenticated", !person.isGuest());
    model.putAll(getBeans(req));
    model.putAll(getPreferences(req));
    addSecurityRoleChecksToModel(req, model);
    final String viewLocation = getViewLocation(req);
    return new ModelAndView(viewLocation, model);
}
Also used : IPerson(org.apereo.portal.security.IPerson) HashMap(java.util.HashMap) ModelAndView(org.springframework.web.portlet.ModelAndView) HashMap(java.util.HashMap) Map(java.util.Map) RenderMapping(org.springframework.web.portlet.bind.annotation.RenderMapping)

Example 5 with ModelAndView

use of org.springframework.web.portlet.ModelAndView in project uPortal by Jasig.

the class MessageEntityTranslationController method postTranslation.

@ResourceMapping
@RequestMapping(params = "action=postTranslation")
public ModelAndView postTranslation(@RequestParam("id") String code, @RequestParam("locale") String localeStr, @RequestParam("value") String value) {
    final Locale locale = LocaleManager.parseLocale(localeStr);
    if (locale != null && StringUtils.hasText(code) && StringUtils.hasText(value)) {
        final Message message = messageDao.getMessage(code, locale);
        if (message != null) {
            message.setValue(value);
            messageDao.updateMessage(message);
        } else {
            // if message is not found in the backend storage, a new one must be created
            messageDao.createMessage(code, locale, value);
        }
    }
    return new ModelAndView("json");
}
Also used : Locale(java.util.Locale) Message(org.apereo.portal.i18n.Message) ModelAndView(org.springframework.web.portlet.ModelAndView) ResourceMapping(org.springframework.web.portlet.bind.annotation.ResourceMapping) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Aggregations

ModelAndView (org.springframework.web.portlet.ModelAndView)15 HashMap (java.util.HashMap)7 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)7 PortletPreferences (javax.portlet.PortletPreferences)6 ResourceMapping (org.springframework.web.portlet.bind.annotation.ResourceMapping)6 RenderMapping (org.springframework.web.portlet.bind.annotation.RenderMapping)4 LinkedHashMap (java.util.LinkedHashMap)3 Map (java.util.Map)3 HttpServletRequest (javax.servlet.http.HttpServletRequest)3 IPortletDefinition (org.apereo.portal.portlet.om.IPortletDefinition)3 IPerson (org.apereo.portal.security.IPerson)3 ArrayList (java.util.ArrayList)2 Locale (java.util.Locale)2 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)2 Message (org.apereo.portal.i18n.Message)2 DataTable (com.google.visualization.datasource.datatable.DataTable)1 List (java.util.List)1 PortletSession (javax.portlet.PortletSession)1 HttpServletResponse (javax.servlet.http.HttpServletResponse)1 DataSource (javax.sql.DataSource)1