private void view( HttpServletRequest request, HttpServletResponse response, ModelAndView next, WikiPageInfo pageInfo) throws Exception { String topicName = WikiUtil.getTopicFromURI(request); if (StringUtils.isBlank(topicName)) { String virtualWikiName = pageInfo.getVirtualWikiName(); VirtualWiki virtualWiki = WikiBase.getDataHandler().lookupVirtualWiki(virtualWikiName); topicName = virtualWiki.getRootTopicName(); } String virtualWiki = pageInfo.getVirtualWikiName(); if (StringUtils.isBlank(virtualWiki)) { virtualWiki = VirtualWiki.defaultVirtualWiki().getName(); } Topic topic = ServletUtil.initializeTopic(virtualWiki, topicName); if (topic.getTopicId() <= 0) { // topic does not exist, return 404 and display empty page response.setStatus(HttpServletResponse.SC_NOT_FOUND); WikiMessage wikiMessage = new WikiMessage("topic.notcreated"); // topic name is escaped from WikiUtil.getTopicFromURI, so do not double-escape wikiMessage.setParamsWithoutEscaping(new String[] {topicName}); next.addObject("notopic", wikiMessage); } WikiMessage pageTitle = new WikiMessage("topic.title", topicName); ServletUtil.viewTopic(request, next, pageInfo, pageTitle, topic, true, true); }
/** * Examine the request object, and see if the requested topic or page matches a given value. * * @param request The servlet request object. * @param value The value to match against the current topic or page name. * @return <code>true</code> if the value matches the current topic or page name, <code>false * </code> otherwise. */ protected static boolean isTopic(HttpServletRequest request, String value) { try { String topic = WikiUtil.getTopicFromURI(request); if (!StringUtils.hasText(topic)) { return false; } if (value != null && topic.equals(value)) { return true; } } catch (Exception e) { } return false; }
private ModelAndView loginRequired(HttpServletRequest request, WikiPageInfo pageInfo) throws Exception { String topicName = WikiUtil.getTopicFromRequest(request); String virtualWiki = pageInfo.getVirtualWikiName(); WikiUserDetailsImpl user = ServletUtil.currentUserDetails(); if (ServletUtil.isEditable(virtualWiki, topicName, user)) { return null; } if (!user.hasRole(Role.ROLE_EDIT_EXISTING)) { WikiMessage messageObject = new WikiMessage("login.message.edit"); return ServletUtil.viewLogin( request, pageInfo, WikiUtil.getTopicFromURI(request), messageObject); } if (!user.hasRole(Role.ROLE_EDIT_NEW) && WikiBase.getDataHandler().lookupTopic(virtualWiki, topicName, false, null) == null) { WikiMessage messageObject = new WikiMessage("login.message.editnew"); return ServletUtil.viewLogin( request, pageInfo, WikiUtil.getTopicFromURI(request), messageObject); } Topic topic = WikiBase.getDataHandler().lookupTopic(virtualWiki, topicName, false, null); if (topic == null) { // this should never trigger, but better safe than sorry... return null; } if (topic.getAdminOnly()) { WikiMessage messageObject = new WikiMessage("login.message.editadmin", topicName); return ServletUtil.viewLogin( request, pageInfo, WikiUtil.getTopicFromURI(request), messageObject); } if (topic.getReadOnly()) { throw new WikiException(new WikiMessage("error.readonly")); } // it should be impossible to get here... throw new WikiException( new WikiMessage("error.unknown", "Unable to determine topic editing permissions")); }
/** * This method ensures that values required for rendering a JSP page have been loaded into the * ModelAndView object. Examples of values that may be handled by this method include topic name, * username, etc. * * @param request The current servlet request object. * @param next The current ModelAndView object. * @param pageInfo The current WikiPageInfo object, containing basic page rendering information. */ protected static void loadDefaults( HttpServletRequest request, ModelAndView next, WikiPageInfo pageInfo) throws Exception { if (next.getViewName() != null && next.getViewName().startsWith(ServletUtil.SPRING_REDIRECT_PREFIX)) { // if this is a redirect, no need to load anything return; } // load cached top area, nav bar, etc. ServletUtil.buildLayout(request, next); if (!StringUtils.hasText(pageInfo.getTopicName())) { pageInfo.setTopicName(WikiUtil.getTopicFromURI(request)); } pageInfo.setUserMenu(ServletUtil.buildUserMenu()); pageInfo.setTabMenu(ServletUtil.buildTabMenu(request, pageInfo)); next.addObject(ServletUtil.PARAMETER_PAGE_INFO, pageInfo); }