Ejemplo n.º 1
0
 protected void loadDefaults(
     HttpServletRequest request, ModelAndView next, WikiPageInfo pageInfo) {
   // load cached top area, nav bar, etc.
   try {
     this.buildLayout(request, next);
   } catch (Exception e) {
     logger.error("Unable to build default page layout", e);
   }
   // add link to user page and comments page
   WikiUser user = Utilities.currentUser(request);
   if (user != null) {
     next.addObject("userpage", WikiBase.NAMESPACE_USER + user.getLogin());
     next.addObject("usercomments", WikiBase.NAMESPACE_USER_COMMENTS + user.getLogin());
     next.addObject("adminUser", new Boolean(user.getAdmin()));
   }
   if (!this.pageInfo.getSpecial()) {
     // FIXME - this is really ugly
     String article = this.pageInfo.getTopicName();
     String comments = WikiBase.NAMESPACE_COMMENTS + article;
     if (article != null && article.startsWith(WikiBase.NAMESPACE_COMMENTS)) {
       int pos = WikiBase.NAMESPACE_COMMENTS.length();
       article = article.substring(pos);
       comments = WikiBase.NAMESPACE_COMMENTS + article;
     } else if (article != null && article.startsWith(WikiBase.NAMESPACE_SPECIAL)) {
       int pos = WikiBase.NAMESPACE_SPECIAL.length();
       article = article.substring(pos);
       comments = WikiBase.NAMESPACE_COMMENTS + article;
     } else if (article != null && article.startsWith(WikiBase.NAMESPACE_USER_COMMENTS)) {
       int pos = WikiBase.NAMESPACE_USER_COMMENTS.length();
       comments = article;
       article = WikiBase.NAMESPACE_USER + article.substring(pos);
     } else if (article != null && article.startsWith(WikiBase.NAMESPACE_USER)) {
       int pos = WikiBase.NAMESPACE_USER.length();
       comments = WikiBase.NAMESPACE_USER_COMMENTS + article.substring(pos);
     } else if (article != null && article.startsWith(WikiBase.NAMESPACE_IMAGE_COMMENTS)) {
       int pos = WikiBase.NAMESPACE_IMAGE_COMMENTS.length();
       comments = article;
       article = WikiBase.NAMESPACE_IMAGE + article.substring(pos);
     } else if (article != null && article.startsWith(WikiBase.NAMESPACE_IMAGE)) {
       int pos = WikiBase.NAMESPACE_IMAGE.length();
       comments = WikiBase.NAMESPACE_IMAGE_COMMENTS + article.substring(pos);
     }
     next.addObject("article", article);
     next.addObject("comments", comments);
     String editLink = "Special:Edit?topic=" + Utilities.encodeURL(this.pageInfo.getTopicName());
     if (StringUtils.hasText(request.getParameter("topicVersionId"))) {
       editLink += "&topicVersionId=" + request.getParameter("topicVersionId");
     }
     next.addObject("edit", editLink);
   }
   next.addObject(JAMWikiServlet.PARAMETER_TOPIC, this.pageInfo.getTopicName());
   if (!StringUtils.hasText(this.pageInfo.getTopicName())) {
     try {
       next.addObject(JAMWikiServlet.PARAMETER_TOPIC, JAMWikiServlet.getTopicFromURI(request));
     } catch (Exception e) {
       logger.error("Unable to load topic value in JAMWikiServlet", e);
     }
   }
   next.addObject(JAMWikiServlet.PARAMETER_ADMIN, new Boolean(this.pageInfo.getAdmin()));
   next.addObject(JAMWikiServlet.PARAMETER_SPECIAL, new Boolean(this.pageInfo.getSpecial()));
   next.addObject(JAMWikiServlet.PARAMETER_TITLE, this.pageInfo.getPageTitle());
   next.addObject(JAMWikiServlet.PARAMETER_ACTION, this.pageInfo.getPageAction());
   // reset pageInfo object - seems not to reset with each servlet call
   this.pageInfo = new WikiPageInfo();
 }
Ejemplo n.º 2
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;
   }
 }