/** * Utility method used when redirecting to a login page. * * @param request The servlet request object. * @param pageInfo The current WikiPageInfo object, which contains information needed for * rendering the final JSP page. * @param topic The topic to be redirected to. Valid examples are "Special:Admin", * "StartingPoints", etc. * @param messageObject A WikiMessage object to be displayed on the login page. * @return Returns a ModelAndView object corresponding to the login page display. * @throws Exception Thrown if any error occurs during processing. */ protected static ModelAndView viewLogin( HttpServletRequest request, WikiPageInfo pageInfo, String topic, WikiMessage messageObject) throws Exception { ModelAndView next = new ModelAndView("wiki"); pageInfo.reset(); String virtualWikiName = WikiUtil.getVirtualWikiFromURI(request); String target = request.getParameter("target"); if (!StringUtils.hasText(target)) { if (!StringUtils.hasText(topic)) { VirtualWiki virtualWiki = WikiBase.getDataHandler().lookupVirtualWiki(virtualWikiName); topic = virtualWiki.getDefaultTopicName(); } target = topic; if (StringUtils.hasText(request.getQueryString())) { target += "?" + request.getQueryString(); } } next.addObject("target", target); pageInfo.setPageTitle(new WikiMessage("login.title")); pageInfo.setContentJsp(JSP_LOGIN); pageInfo.setSpecial(true); if (messageObject != null) { next.addObject("messageObject", messageObject); } return next; }
/** * FIXME - override the parent method to determine if processing should occur. Needed due to the * fact that different virtual wikis may be used. */ protected boolean requiresLogout(HttpServletRequest request, HttpServletResponse response) { String uri = request.getRequestURI(); int pathParamIndex = uri.indexOf(';'); if (pathParamIndex > 0) { // strip everything after the first semi-colon uri = uri.substring(0, pathParamIndex); } String virtualWiki = WikiUtil.getVirtualWikiFromURI(request); return uri.endsWith( request.getContextPath() + "/" + virtualWiki + this.getFilterProcessesUrl()); }
private void jumpTo(HttpServletRequest request, ModelAndView next, WikiPageInfo pageInfo) throws Exception { String virtualWiki = WikiUtil.getVirtualWikiFromURI(request); String topic = request.getParameter("text"); if (WikiBase.exists(virtualWiki, topic)) { ServletUtil.redirect(next, virtualWiki, topic); } else { next.addObject("notopic", new WikiMessage("topic.notcreated", topic)); this.search(request, next, pageInfo); } }
/** * Allow subclasses to modify the redirection message. * * @param request the request * @param response the response * @param url the URL to redirect to * @throws IOException in the event of any failure */ protected void sendRedirect(HttpServletRequest request, HttpServletResponse response, String url) throws IOException { String targetUrl = url; if ("/DEFAULT_VIRTUAL_WIKI".equals(url)) { // ugly, but a hard-coded constant seems to be the only way to // allow a dynamic url value String virtualWikiName = WikiUtil.getVirtualWikiFromURI(request); if (!StringUtils.hasText(virtualWikiName)) { virtualWikiName = WikiBase.DEFAULT_VWIKI; } String topicName = Environment.getValue(Environment.PROP_BASE_DEFAULT_TOPIC); try { VirtualWiki virtualWiki = WikiBase.getDataHandler().lookupVirtualWiki(virtualWikiName); topicName = virtualWiki.getDefaultTopicName(); } catch (Exception e) { logger.warning("Unable to retrieve default topic for virtual wiki", e); } targetUrl = request.getContextPath() + "/" + virtualWikiName + "/" + topicName; } else if (url != null && !url.startsWith("http://") && !url.startsWith("https://")) { String virtualWiki = WikiUtil.getVirtualWikiFromURI(request); targetUrl = request.getContextPath() + "/" + virtualWiki + url; } response.sendRedirect(response.encodeRedirectURL(targetUrl)); }
/** * Utility method used when viewing a topic. * * @param request The current servlet request object. * @param next The current Spring ModelAndView object. * @param pageInfo The current WikiPageInfo object, which contains information needed for * rendering the final JSP page. * @param topicName The topic being viewed. This value must be a valid topic that can be loaded as * a org.jamwiki.model.Topic object. * @throws Exception Thrown if any error occurs during processing. */ protected static void viewTopic( HttpServletRequest request, ModelAndView next, WikiPageInfo pageInfo, String topicName) throws Exception { String virtualWiki = WikiUtil.getVirtualWikiFromURI(request); if (!StringUtils.hasText(virtualWiki)) { virtualWiki = WikiBase.DEFAULT_VWIKI; } Topic topic = ServletUtil.initializeTopic(virtualWiki, topicName); if (topic.getTopicId() <= 0) { // topic does not exist, display empty page next.addObject("notopic", new WikiMessage("topic.notcreated", topicName)); } WikiMessage pageTitle = new WikiMessage("topic.title", topicName); viewTopic(request, next, pageInfo, pageTitle, topic, true); }
protected void writeTopic(HttpServletRequest request, String editComment) throws Exception { String virtualWiki = WikiUtil.getVirtualWikiFromURI(request); String topicName = NamespaceHandler.NAMESPACE_JAMWIKI + NamespaceHandler.NAMESPACE_SEPARATOR + Utilities.decodeFromRequest(filename(request)); String contents = "<pre><nowiki>\n" + Utilities.readFile(filename(request)) + "\n</nowiki></pre>"; Topic topic = WikiBase.getDataHandler().lookupTopic(virtualWiki, topicName, false, null); if (topic == null) { topic = new Topic(); topic.setVirtualWiki(virtualWiki); topic.setName(topicName); } topic.setTopicContent(contents); topic.setReadOnly(true); topic.setTopicType(Topic.TYPE_SYSTEM_FILE); WikiUser user = Utilities.currentUser(); TopicVersion topicVersion = new TopicVersion(user, request.getRemoteAddr(), editComment, contents); WikiBase.getDataHandler().writeTopic(topic, topicVersion, null, true, null); }
private void search(HttpServletRequest request, ModelAndView next, WikiPageInfo pageInfo) throws Exception { String virtualWiki = WikiUtil.getVirtualWikiFromURI(request); String searchField = request.getParameter("text"); if (request.getParameter("text") == null) { pageInfo.setPageTitle(new WikiMessage("search.title")); } else { pageInfo.setPageTitle(new WikiMessage("searchresult.title", searchField)); } // forward back to the search page if the request is blank or null if (!StringUtils.hasText(searchField)) { pageInfo.setContentJsp(JSP_SEARCH); pageInfo.setSpecial(true); return; } // grab search engine instance and find Collection results = WikiBase.getSearchEngine().findResults(virtualWiki, searchField); next.addObject("searchField", searchField); next.addObject("results", results); pageInfo.setContentJsp(JSP_SEARCH_RESULTS); pageInfo.setSpecial(true); }
/** * This method ensures that the left menu, logo, and other required values have been loaded into * the session object. * * @param request The servlet request object. * @param next A ModelAndView object corresponding to the page being constructed. */ private static void buildLayout(HttpServletRequest request, ModelAndView next) { String virtualWikiName = WikiUtil.getVirtualWikiFromURI(request); if (virtualWikiName == null) { logger.severe("No virtual wiki available for page request " + request.getRequestURI()); virtualWikiName = WikiBase.DEFAULT_VWIKI; } VirtualWiki virtualWiki = retrieveVirtualWiki(virtualWikiName); // build the layout contents String leftMenu = ServletUtil.cachedContent( request.getContextPath(), request.getLocale(), virtualWikiName, WikiBase.SPECIAL_PAGE_LEFT_MENU, true); next.addObject("leftMenu", leftMenu); next.addObject("defaultTopic", virtualWiki.getDefaultTopicName()); next.addObject("virtualWiki", virtualWiki.getName()); next.addObject("logo", Environment.getValue(Environment.PROP_BASE_LOGO_IMAGE)); String bottomArea = ServletUtil.cachedContent( request.getContextPath(), request.getLocale(), virtualWiki.getName(), WikiBase.SPECIAL_PAGE_BOTTOM_AREA, true); next.addObject("bottomArea", bottomArea); next.addObject(ServletUtil.PARAMETER_VIRTUAL_WIKI, virtualWiki.getName()); Integer cssRevision = new Integer(0); try { cssRevision = WikiBase.getDataHandler() .lookupTopic(virtualWiki.getName(), WikiBase.SPECIAL_PAGE_STYLESHEET, false, null) .getCurrentVersionId(); } catch (Exception e) { } next.addObject("cssRevision", cssRevision); }
/** * Build a map of links and the corresponding link text to be used as the tab menu links for the * WikiPageInfo object. */ private static LinkedHashMap buildTabMenu(HttpServletRequest request, WikiPageInfo pageInfo) { LinkedHashMap links = new LinkedHashMap(); WikiUser user = Utilities.currentUser(); String pageName = pageInfo.getTopicName(); String virtualWiki = WikiUtil.getVirtualWikiFromURI(request); try { if (pageInfo.getAdmin()) { if (user.hasRole(Role.ROLE_SYSADMIN)) { links.put("Special:Admin", new WikiMessage("tab.admin.configuration")); links.put("Special:Maintenance", new WikiMessage("tab.admin.maintenance")); links.put("Special:Roles", new WikiMessage("tab.admin.roles")); } if (user.hasRole(Role.ROLE_TRANSLATE)) { links.put("Special:Translation", new WikiMessage("tab.admin.translations")); } } else if (pageInfo.getSpecial()) { links.put(pageName, new WikiMessage("tab.common.special")); } else { String article = Utilities.extractTopicLink(pageName); String comments = Utilities.extractCommentsLink(pageName); links.put(article, new WikiMessage("tab.common.article")); links.put(comments, new WikiMessage("tab.common.comments")); if (ServletUtil.isEditable(virtualWiki, pageName, user)) { String editLink = "Special:Edit?topic=" + Utilities.encodeForURL(pageName); if (StringUtils.hasText(request.getParameter("topicVersionId"))) { editLink += "&topicVersionId=" + request.getParameter("topicVersionId"); } links.put(editLink, new WikiMessage("tab.common.edit")); } String historyLink = "Special:History?topic=" + Utilities.encodeForURL(pageName); links.put(historyLink, new WikiMessage("tab.common.history")); if (ServletUtil.isMoveable(virtualWiki, pageName, user)) { String moveLink = "Special:Move?topic=" + Utilities.encodeForURL(pageName); links.put(moveLink, new WikiMessage("tab.common.move")); } if (user.hasRole(Role.ROLE_USER)) { Watchlist watchlist = WikiUtil.currentWatchlist(request, virtualWiki); boolean watched = (watchlist.containsTopic(pageName)); String watchlistLabel = (watched) ? "tab.common.unwatch" : "tab.common.watch"; String watchlistLink = "Special:Watchlist?topic=" + Utilities.encodeForURL(pageName); links.put(watchlistLink, new WikiMessage(watchlistLabel)); } if (pageInfo.isUserPage()) { WikiLink wikiLink = LinkUtil.parseWikiLink(pageName); String contributionsLink = "Special:Contributions?contributor=" + Utilities.encodeForURL(wikiLink.getArticle()); links.put(contributionsLink, new WikiMessage("tab.common.contributions")); } String linkToLink = "Special:LinkTo?topic=" + Utilities.encodeForURL(pageName); links.put(linkToLink, new WikiMessage("tab.common.links")); if (user.hasRole(Role.ROLE_ADMIN)) { String manageLink = "Special:Manage?topic=" + Utilities.encodeForURL(pageName); links.put(manageLink, new WikiMessage("tab.common.manage")); } String printLink = "Special:Print?topic=" + Utilities.encodeForURL(pageName); links.put(printLink, new WikiMessage("tab.common.print")); } } catch (Exception e) { logger.severe("Unable to build tabbed menu links", e); } return links; }