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;
}
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);
}
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);
}
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);
}
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");
}
Aggregations