List of usage examples for org.springframework.ui Model hashCode
@HotSpotIntrinsicCandidate public native int hashCode();
From source file:org.jasig.portlet.newsreader.mvc.portlet.reader.NewsController.java
@RenderMapping(params = "action=fullStory") public ModelAndView fullStory(@RequestParam Long activeFeed, @RequestParam int itemIndex, @RequestParam int page, RenderRequest request, RenderResponse response, Model model) throws Exception { log.trace("fullStory (NewsController)"); //Security check that the feed belongs to the user String setName = request.getPreferences().getValue("newsSetName", "default"); NewsSet set = setCreationService.getNewsSet(setName, request); List<NewsConfiguration> feeds = new ArrayList<NewsConfiguration>(); feeds.addAll(set.getNewsConfigurations()); Collections.sort(feeds);/*from w w w. j a v a 2 s .c o m*/ JSONArray jsonFeeds = new JSONArray(); List<String> knownFeeds = new ArrayList<String>(); for (NewsConfiguration feed : feeds) { if (feed.isDisplayed()) { JSONObject jsonFeed = new JSONObject(); jsonFeed.put("id", feed.getId()); jsonFeed.put("name", feed.getNewsDefinition().getName()); jsonFeeds.add(jsonFeed); knownFeeds.add(String.valueOf(feed.getId())); } } log.debug("Known feeds: " + knownFeeds.toString()); model.addAttribute("feeds", jsonFeeds); if (!knownFeeds.contains(activeFeed.toString())) { activeFeed = null; model.addAttribute("message", "Not allowed."); log.debug("Not allowd."); } model.addAttribute("activeFeed", activeFeed); NewsConfiguration feedConfig = newsStore.getNewsConfiguration(activeFeed); log.debug("On render Active feed is " + feedConfig.getId()); try { // get an instance of the adapter for this feed INewsAdapter adapter = (INewsAdapter) applicationContext .getBean(feedConfig.getNewsDefinition().getClassName()); // retrieve the feed from this adaptor NewsFeed sharedFeed = adapter.getSyndFeed(feedConfig, page); if (sharedFeed != null) { NewsFeedItem item = sharedFeed.getEntries().get(itemIndex); model.addAttribute("storyTitle", item.getTitle()); FullStory fullStory = item.getFullStory(); model.addAttribute("fullStory", fullStory.getFullStoryText()); } else { log.warn("Failed to get feed from adapter."); model.addAttribute("message", "The news \"" + feedConfig.getNewsDefinition().getName() + "\" is currently unavailable."); } PortletPreferences prefs = request.getPreferences(); model.addAttribute("feedView", prefs.getValue("feedView", "select")); } catch (NoSuchBeanDefinitionException ex) { log.error("News class instance could not be found: " + ex.getMessage()); model.addAttribute("message", "The news \"" + feedConfig.getNewsDefinition().getName() + "\" is currently unavailable."); } catch (NewsException ex) { log.warn(ex); model.addAttribute("message", "The news \"" + feedConfig.getNewsDefinition().getName() + "\" is currently unavailable."); } catch (Exception ex) { log.error(ex); model.addAttribute("message", "The news \"" + feedConfig.getNewsDefinition().getName() + "\" is currently unavailable."); } String etag = String.valueOf(model.hashCode()); String requestEtag = request.getETag(); // if the request ETag matches the hash for this response, send back // an empty response indicating that cached content should be used if (request.getETag() != null && etag.equals(requestEtag)) { response.getCacheControl().setExpirationTime(1); response.getCacheControl().setUseCachedContent(true); // returning null appears to cause the response to be committed // before returning to the portal, so just use an empty view return new ModelAndView("empty", Collections.<String, String>emptyMap()); } // create new content with new validation tag response.getCacheControl().setETag(etag); response.getCacheControl().setExpirationTime(1); String viewName = viewResolver.getFullStoryView(request); return new ModelAndView(viewName, model.asMap()); }