List of usage examples for org.springframework.web.servlet View View
View
From source file:com.nominanuda.springmvc.StaticViewResolver.java
public View resolveViewName(String viewName, Locale locale) throws Exception { URL url = resolve(viewName, locale); if (url == null) { return null; } else {//from w ww .j a va 2s .c om if (cache) { View cv = findCachedView(url); if (cv != null) { return cv; } } final byte[] barr = io.readAndClose(url.openStream()); View v = new View() { public void render(Map<String, ?> model, HttpServletRequest request, HttpServletResponse response) throws Exception { response.setContentLength(barr.length); response.setContentType(contentType); OutputStream os = response.getOutputStream(); os.write(barr); os.flush(); } public String getContentType() { return contentType; } }; if (cache) { storeCachedView(url, v); } return v; } }
From source file:com.betfair.tornjak.monitor.web.PingController.java
public ModelAndView handleRequestInternal(HttpServletRequest request, HttpServletResponse response) throws Exception { return new ModelAndView(new View() { public String getContentType() { return "text/html"; }/*from ww w. j a va 2 s . c o m*/ public void render(Map model, HttpServletRequest request, HttpServletResponse response) throws Exception { StatusAggregator sa = monitorRegistry.getStatusAggregator(); Status status = (sa == null) ? FAIL : sa.getStatus(); // webping only supports OK or FAIL response if (status == WARN) { status = OK; } response.getWriter().print(webping.replace("${status}", status.name())); } }, "status", ""); }
From source file:org.mashupmedia.controller.remote.RemoteLibraryController.java
@RequestMapping(value = "/connect/{libraryType}/{uniqueName}", method = RequestMethod.GET) public ModelAndView handleConnectRemoteLibrary(HttpServletRequest request, @PathVariable String libraryType, @PathVariable String uniqueName, Model model) throws IOException { Library remoteLibrary = getRemoteLibrary(uniqueName, request, false); if (remoteLibrary == null) { logger.info("Unable to connect to remote library, unknown host: " + request.getRemoteHost()); return null; }/* ww w . j a v a 2 s .c o m*/ File file = FileHelper.getLibraryXmlFile(remoteLibrary.getId()); final String xml = FileUtils.readFileToString(file, Encoding.UTF8.getEncodingString()); ModelAndView modelAndView = new ModelAndView(new View() { @Override public void render(Map<String, ?> model, HttpServletRequest request, HttpServletResponse response) throws Exception { response.setContentType(getContentType()); response.getWriter().print(xml); } @Override public String getContentType() { return WebContentType.XML.getContentType(); } }); return modelAndView; }
From source file:org.mashupmedia.controller.ajax.AjaxLibraryController.java
private ModelAndView getRemoteShares(Library library) { List<RemoteShare> remoteShares = library.getRemoteShares(); final JSONArray jsonArray = new JSONArray(); if (remoteShares == null || remoteShares.isEmpty()) { remoteShares = new ArrayList<RemoteShare>(); }/*from w w w. ja v a 2 s .c o m*/ for (RemoteShare remoteShare : remoteShares) { JSONObject remoteSharePropertiesJson = new JSONObject(); remoteSharePropertiesJson.put("createdBy", remoteShare.getCreatedBy().getName()); remoteSharePropertiesJson.put("createdOn", DateHelper.parseToText(remoteShare.getCreatedOn(), DateFormatType.SHORT_DISPLAY_WITH_TIME)); remoteSharePropertiesJson.put("id", remoteShare.getId()); String lastAccessedValue = ""; Date lastAccessed = remoteShare.getLastAccessed(); if (lastAccessed != null) { lastAccessedValue = DateHelper.parseToText(remoteShare.getLastAccessed(), DateFormatType.SHORT_DISPLAY_WITH_TIME); } remoteSharePropertiesJson.put("lastAccessed", lastAccessedValue); remoteSharePropertiesJson.put("remoteUrl", StringUtils.trimToEmpty(remoteShare.getRemoteUrl())); remoteSharePropertiesJson.put("totalPlayedMediaItems", remoteShare.getTotalPlayedMediaItems()); remoteSharePropertiesJson.put("uniqueName", StringUtils.trimToEmpty(remoteShare.getUniqueName())); remoteSharePropertiesJson.put("status", remoteShare.getStatusType().toString()); JSONObject remoteShareJson = new JSONObject(); remoteShareJson.put("remoteShare", remoteSharePropertiesJson); jsonArray.add(remoteShareJson); } ModelAndView modelAndView = new ModelAndView(new View() { @Override public void render(Map<String, ?> model, HttpServletRequest request, HttpServletResponse response) throws Exception { response.setContentType(getContentType()); response.getWriter().print(jsonArray.toString()); } @Override public String getContentType() { return WebContentType.JSON.getContentType(); } }); return modelAndView; }