@Override public void beforeView( final HttpServletRequest request, final HttpServletResponse response, final ModelAndView modelAndView) { // Check to see if the controller has specified a Index/Follow directive for robots if (modelAndView != null && !modelAndView.getModel().containsKey("metaRobots")) { // Build a default directive String robotsValue = "no-index,no-follow"; if (RequestMethod.GET.name().equalsIgnoreCase(request.getMethod())) { if (request.isSecure()) { robotsValue = "no-index,follow"; } // Since no model attribute metaRobots can be set for JSON response, then configure that // servlet path in the xml. // If its a regular response and this setting has to be overriden then set model attribute // metaRobots else if (CollectionUtils.contains( getRobotIndexForJSONMapping().keySet().iterator(), request.getServletPath())) { robotsValue = getRobotIndexForJSONMapping().get(request.getServletPath()); } else { robotsValue = "index,follow"; } } else if (RequestMethod.POST.name().equalsIgnoreCase(request.getMethod())) { robotsValue = "no-index,no-follow"; } modelAndView.addObject("metaRobots", robotsValue); } if (modelAndView != null && modelAndView.getModel().containsKey("metatags")) { final MetaElementData metaElement = new MetaElementData(); metaElement.setName("robots"); metaElement.setContent((String) modelAndView.getModel().get("metaRobots")); ((List<MetaElementData>) modelAndView.getModel().get("metatags")).add(metaElement); } }
protected MetaElementData createMetaElement(final String name, final String content) { final MetaElementData element = new MetaElementData(); element.setName(name); element.setContent(content); return element; }