Exemple #1
0
 /**
  * Modify the current ModelAndView object to create a Spring redirect response, meaning that the
  * view name becomes "redirect:" followed by the redirection target.
  *
  * @param next The current ModelAndView object, which will be reset by this method.
  * @param virtualWiki The virtual wiki name for the page being redirected to.
  * @param destination The topic or page name that is the redirection target. An example might be
  *     "Special:Login".
  */
 protected static void redirect(ModelAndView next, String virtualWiki, String destination)
     throws Exception {
   String target = LinkUtil.buildInternalLinkUrl(null, virtualWiki, destination);
   String view = ServletUtil.SPRING_REDIRECT_PREFIX + target;
   next.clear();
   next.setViewName(view);
 }
Exemple #2
0
 private void jumpTo(HttpServletRequest request, HttpServletResponse response, ModelAndView next)
     throws Exception {
   String virtualWiki = JAMWikiServlet.getVirtualWikiFromURI(request);
   String text = request.getParameter("text");
   // FIXME - if topic doesn't exist, should probably go to an edit page
   // or else give an error message
   // FIXME - need a better way to do redirects
   String redirectURL = LinkUtil.buildInternalLinkUrl(request.getContextPath(), virtualWiki, text);
   redirect(redirectURL, response);
 }
Exemple #3
0
 // FIXME - shouldn't need to pass in response
 private boolean register(
     HttpServletRequest request,
     HttpServletResponse response,
     ModelAndView next,
     WikiPageInfo pageInfo)
     throws Exception {
   pageInfo.setSpecial(true);
   pageInfo.setAction(WikiPageInfo.ACTION_REGISTER);
   pageInfo.setPageTitle(new WikiMessage("register.title"));
   String virtualWikiName = JAMWikiServlet.getVirtualWikiFromURI(request);
   WikiUser user = new WikiUser();
   String userIdString = request.getParameter("userId");
   if (StringUtils.hasText(userIdString)) {
     int userId = new Integer(userIdString).intValue();
     if (userId > 0) user = WikiBase.getHandler().lookupWikiUser(userId);
   }
   user.setLogin(request.getParameter("login"));
   user.setDisplayName(request.getParameter("displayName"));
   user.setEmail(request.getParameter("email"));
   String newPassword = request.getParameter("newPassword");
   if (StringUtils.hasText(newPassword)) {
     user.setEncodedPassword(Encryption.encrypt(newPassword));
   }
   // FIXME - need to distinguish between add & update
   user.setCreateIpAddress(request.getRemoteAddr());
   user.setLastLoginIpAddress(request.getRemoteAddr());
   next.addObject("newuser", user);
   Vector errors = validate(request, user);
   if (errors.size() > 0) {
     next.addObject("errors", errors);
     String oldPassword = request.getParameter("oldPassword");
     String confirmPassword = request.getParameter("confirmPassword");
     if (oldPassword != null) next.addObject("oldPassword", oldPassword);
     if (newPassword != null) next.addObject("newPassword", newPassword);
     if (confirmPassword != null) next.addObject("confirmPassword", confirmPassword);
     return false;
   } else {
     WikiBase.getHandler().writeWikiUser(user);
     request.getSession().setAttribute(JAMWikiServlet.PARAMETER_USER, user);
     VirtualWiki virtualWiki = WikiBase.getHandler().lookupVirtualWiki(virtualWikiName);
     String topic = virtualWiki.getDefaultTopicName();
     String redirect =
         LinkUtil.buildInternalLinkUrl(request.getContextPath(), virtualWikiName, topic);
     // FIXME - can a redirect be done with Spring?
     redirect(redirect, response);
     return true;
   }
 }
Exemple #4
0
 private StringBuffer nextPage(
     Pagination pagination, String baseUrl, int count, boolean previous) {
   HttpServletRequest request = (HttpServletRequest) this.pageContext.getRequest();
   StringBuffer output = new StringBuffer();
   try {
     Object[] objects = new Object[1];
     objects[0] = new Integer(pagination.getNumResults());
     if (pagination.getOffset() == 0 && previous) {
       output.append(
           Utilities.formatMessage("common.pagination.previous", request.getLocale(), objects));
       return output;
     }
     if (pagination.getNumResults() != count && !previous) {
       output.append(
           Utilities.formatMessage("common.pagination.next", request.getLocale(), objects));
       return output;
     }
     output.append("<a href=\"");
     String virtualWiki = Utilities.getVirtualWikiFromRequest(request);
     WikiLink wikiLink = LinkUtil.parseWikiLink(baseUrl);
     int offset = pagination.getOffset() + pagination.getNumResults();
     if (previous) {
       offset = pagination.getOffset() - pagination.getNumResults();
       if (offset < 0) offset = 0;
     }
     String query =
         LinkUtil.appendQueryParam(
             wikiLink.getQuery(), "num", new Integer(pagination.getNumResults()).toString());
     query += "&amp;offset=" + offset;
     wikiLink.setQuery(query);
     output.append(LinkUtil.buildInternalLinkUrl(request.getContextPath(), virtualWiki, wikiLink));
     output.append("\">");
     if (previous) {
       output.append(
           Utilities.formatMessage("common.pagination.previous", request.getLocale(), objects));
     } else {
       output.append(
           Utilities.formatMessage("common.pagination.next", request.getLocale(), objects));
     }
     output.append("</a>");
   } catch (Exception e) {
     logger.warning("Failure while building pagination element", e);
   }
   return output;
 }
Exemple #5
0
 /**
  * Action used when redirecting to a login page.
  *
  * @param request The servlet request object.
  * @param next The Spring ModelAndView object.
  * @param topic The topic to be redirected to. Valid examples are "Special:Admin",
  *     "StartingPoints", etc.
  */
 protected void viewLogin(HttpServletRequest request, ModelAndView next, String topic)
     throws Exception {
   this.pageInfo = new WikiPageInfo();
   String virtualWikiName = JAMWikiServlet.getVirtualWikiFromURI(request);
   String redirect = request.getParameter("redirect");
   if (!StringUtils.hasText(redirect)) {
     if (!StringUtils.hasText(topic)) {
       VirtualWiki virtualWiki = WikiBase.getHandler().lookupVirtualWiki(virtualWikiName);
       topic = virtualWiki.getDefaultTopicName();
     }
     redirect =
         LinkUtil.buildInternalLinkUrl(
             request.getContextPath(), virtualWikiName, topic, null, request.getQueryString());
   }
   next.addObject("redirect", redirect);
   this.pageInfo.setPageTitle(new WikiMessage("login.title"));
   this.pageInfo.setPageAction(JAMWikiServlet.ACTION_LOGIN);
   this.pageInfo.setSpecial(true);
 }
Exemple #6
0
 private StringBuffer buildOption(int num, Pagination pagination, String baseUrl) {
   HttpServletRequest request = (HttpServletRequest) this.pageContext.getRequest();
   StringBuffer output = new StringBuffer();
   try {
     if (num == pagination.getNumResults()) {
       output.append(num);
       return output;
     }
     output.append("<a href=\"");
     String virtualWiki = Utilities.getVirtualWikiFromRequest(request);
     WikiLink wikiLink = LinkUtil.parseWikiLink(baseUrl);
     String query =
         LinkUtil.appendQueryParam(wikiLink.getQuery(), "num", new Integer(num).toString());
     query += "&amp;offset=0";
     wikiLink.setQuery(query);
     output.append(LinkUtil.buildInternalLinkUrl(request.getContextPath(), virtualWiki, wikiLink));
     output.append("\">");
     output.append(num);
     output.append("</a>");
   } catch (Exception e) {
     logger.warning("Failure while building pagination element", e);
   }
   return output;
 }
Exemple #7
0
 private void search(HttpServletRequest request, HttpServletResponse response, ModelAndView next)
     throws Exception {
   String virtualWiki = JAMWikiServlet.getVirtualWikiFromURI(request);
   try {
     String searchField = request.getParameter("text");
     if (request.getParameter("text") == null) {
       this.pageInfo.setPageTitle("Special:Search");
     } else {
       String message =
           Utilities.getMessage("searchresult.title", request.getLocale(), searchField);
       this.pageInfo.setPageTitle(message);
     }
     // forward back to the search page if the request is blank or null
     if (!StringUtils.hasText(searchField)) {
       this.pageInfo.setPageAction(JAMWikiServlet.ACTION_SEARCH);
       this.pageInfo.setSpecial(true);
       return;
     }
     // grab search engine instance and find
     boolean fuzzy = false;
     if (request.getParameter("fuzzy") != null) fuzzy = true;
     SearchEngine sedb = WikiBase.getSearchEngineInstance();
     Collection results = sedb.findMultiple(virtualWiki, searchField, fuzzy);
     StringBuffer contents = new StringBuffer();
     if (results != null && results.size() > 0) {
       Iterator it = results.iterator();
       while (it.hasNext()) {
         SearchResultEntry result = (SearchResultEntry) it.next();
         contents.append("<p>");
         contents.append("<div class=\"searchresult\">");
         contents.append("<a href=\"");
         contents.append(
             LinkUtil.buildInternalLinkUrl(
                 request.getContextPath(), virtualWiki, result.getTopic()));
         if (result.getFoundWord().length() > 0) {
           contents.append("?highlight=");
           contents.append(Utilities.encodeURL(result.getFoundWord()));
         }
         contents.append("\">" + result.getTopic() + "</a>");
         contents.append("</div>");
         if (result.getTextBefore().length() > 0
             || result.getTextAfter().length() > 0
             || result.getFoundWord().length() > 0) {
           contents.append("<br />");
           contents.append(result.getTextBefore());
           contents.append("<a style=\"background:yellow\" href=\"");
           contents.append(
               LinkUtil.buildInternalLinkUrl(
                   request.getContextPath(), virtualWiki, result.getTopic()));
           contents.append("?highlight=");
           contents.append(Utilities.encodeURL(result.getFoundWord()));
           contents.append("\">");
           contents.append(result.getFoundWord());
           contents.append("</a> ");
           contents.append(result.getTextAfter());
         }
         contents.append("</p>");
       }
     } else {
       next.addObject("text", searchField);
       contents.append("<p>");
       String message =
           Utilities.getMessage("searchresult.notfound", request.getLocale(), searchField);
       contents.append(message);
       contents.append("</p>");
     }
     next.addObject("results", contents.toString());
     next.addObject("titlelink", "Special:Search");
     this.pageInfo.setPageAction(JAMWikiServlet.ACTION_SEARCH_RESULTS);
     this.pageInfo.setSpecial(true);
     return;
   } catch (Exception e) {
     logger.error(e);
     throw e;
   }
 }