Exemplo n.º 1
0
 private static void buildLayout(HttpServletRequest request, ModelAndView next) throws Exception {
   String virtualWikiName = JAMWikiServlet.getVirtualWikiFromURI(request);
   if (virtualWikiName == null) {
     logger.error("No virtual wiki available for page request " + request.getRequestURI());
     virtualWikiName = WikiBase.DEFAULT_VWIKI;
   }
   VirtualWiki virtualWiki = WikiBase.getHandler().lookupVirtualWiki(virtualWikiName);
   if (virtualWiki == null) {
     logger.error("No virtual wiki found for " + virtualWikiName);
     virtualWikiName = WikiBase.DEFAULT_VWIKI;
     virtualWiki = WikiBase.getHandler().lookupVirtualWiki(virtualWikiName);
   }
   String topic = JAMWikiServlet.getTopicFromRequest(request);
   if (topic == null) {
     topic = JAMWikiServlet.getTopicFromURI(request);
   }
   next.addObject(PARAMETER_TOPIC, topic);
   // build the layout contents
   String leftMenu =
       JAMWikiServlet.getCachedContent(
           request, virtualWikiName, WikiBase.SPECIAL_PAGE_LEFT_MENU, true);
   next.addObject("leftMenu", leftMenu);
   next.addObject("defaultTopic", virtualWiki.getDefaultTopicName());
   next.addObject("logo", Environment.getValue(Environment.PROP_BASE_LOGO_IMAGE));
   String bottomArea =
       JAMWikiServlet.getCachedContent(
           request, virtualWikiName, WikiBase.SPECIAL_PAGE_BOTTOM_AREA, true);
   next.addObject("bottomArea", bottomArea);
   next.addObject(PARAMETER_VIRTUAL_WIKI, virtualWikiName);
 }
Exemplo n.º 2
0
 /**
  * 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;
 }
Exemplo n.º 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;
   }
 }
Exemplo n.º 4
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);
 }
Exemplo n.º 5
0
 /**
  * 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);
 }
Exemplo n.º 6
0
 /**
  * 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));
 }