コード例 #1
0
ファイル: WikiBase.java プロジェクト: Eljah/jamwiki
 public static WikiGroup getGroupRegisteredUser() {
   if (WikiUtil.isFirstUse() || WikiUtil.isUpgrade()) {
     throw new IllegalStateException(
         "Cannot retrieve group information prior to completing setup/upgrade");
   }
   if (WikiBase.GROUP_REGISTERED_USER == null) {
     try {
       WikiBase.GROUP_REGISTERED_USER =
           WikiBase.getDataHandler().lookupWikiGroup(WikiGroup.GROUP_REGISTERED_USER);
     } catch (Exception e) {
       throw new RuntimeException("Unable to retrieve registered users group", e);
     }
   }
   return WikiBase.GROUP_REGISTERED_USER;
 }
コード例 #2
0
ファイル: ServletUtil.java プロジェクト: Eljah/jamwiki
 /**
  * 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;
 }
コード例 #3
0
ファイル: TranslationServlet.java プロジェクト: Eljah/jamwiki
 private TreeSet retrieveTranslationCodes() throws Exception {
   TreeSet codes = new TreeSet();
   File propertyRoot = WikiUtil.getClassLoaderRoot();
   File[] files = propertyRoot.listFiles();
   File file;
   String filename;
   for (int i = 0; i < files.length; i++) {
     file = files[i];
     if (!file.isFile()) {
       continue;
     }
     filename = file.getName();
     if (!StringUtils.hasText(filename)) {
       continue;
     }
     if (!filename.startsWith("ApplicationResources_") || !filename.endsWith(".properties")) {
       continue;
     }
     String code =
         filename.substring(
             "ApplicationResources_".length(), filename.length() - ".properties".length());
     if (StringUtils.hasText(code)) {
       codes.add(code);
     }
   }
   return codes;
 }
コード例 #4
0
ファイル: JAMWikiDaoImpl.java プロジェクト: Eljah/jamwiki
 private Collection<GrantedAuthority> retrieveUserAuthorities(String username)
     throws DataAccessException {
   if (WikiUtil.isFirstUse()) {
     return new ArrayList<GrantedAuthority>();
   }
   // add authorities given to all users
   Collection<GrantedAuthority> results = new ArrayList<GrantedAuthority>();
   if (JAMWikiAuthenticationConfiguration.getDefaultGroupRoles() != null) {
     results.addAll(JAMWikiAuthenticationConfiguration.getDefaultGroupRoles());
   }
   // add authorities specific to this user
   if (!StringUtils.isBlank(username)) {
     // FIXME - log error for blank username?  RegisterServlet will trigger that.
     try {
       List<Role> roles = WikiBase.getDataHandler().getRoleMapUser(username);
       if (roles != null) {
         for (Role role : roles) {
           results.add(new RoleImpl(role));
         }
       }
     } catch (org.jamwiki.DataAccessException e) {
       throw new DataAccessResourceFailureException(
           "Unable to retrieve authorities for user: " + username, e);
     }
   }
   return results;
 }
コード例 #5
0
ファイル: TopicServlet.java プロジェクト: Eljah/jamwiki
 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);
 }
コード例 #6
0
ファイル: ImageProcessor.java プロジェクト: Eljah/jamwiki
 static {
   // manually set the ImageIO temp directory so that systems with incorrect defaults won't fail
   // when processing images.
   File directory = WikiUtil.getTempDirectory();
   if (directory.exists()) {
     ImageIO.setCacheDirectory(directory);
   }
 }
コード例 #7
0
ファイル: WikiUtil.java プロジェクト: Eljah/jamwiki
 /**
  * Determine if the system code has been upgraded from the configured system version. Thus if the
  * system is upgraded, this method returns <code>true</code>
  *
  * @return <code>true</code> if the system has been upgraded, <code>false</code> otherwise.
  */
 public static boolean isUpgrade() {
   if (WikiUtil.isFirstUse()) {
     return false;
   }
   WikiVersion oldVersion =
       new WikiVersion(Environment.getValue(Environment.PROP_BASE_WIKI_VERSION));
   WikiVersion currentVersion = new WikiVersion(WikiVersion.CURRENT_WIKI_VERSION);
   return oldVersion.before(currentVersion);
 }
コード例 #8
0
ファイル: EditServlet.java プロジェクト: Eljah/jamwiki
 /** Functionality to handle the "Preview" button being clicked. */
 private void preview(HttpServletRequest request, ModelAndView next, WikiPageInfo pageInfo)
     throws Exception {
   String topicName = WikiUtil.getTopicFromRequest(request);
   String virtualWiki = pageInfo.getVirtualWikiName();
   String contents = (String) request.getParameter("contents");
   Topic previewTopic = new Topic(virtualWiki, topicName);
   previewTopic.setTopicContent(contents);
   next.addObject("editPreview", "true");
   ServletUtil.viewTopic(request, next, pageInfo, null, previewTopic, false, false);
 }
コード例 #9
0
ファイル: SearchServlet.java プロジェクト: Eljah/jamwiki
 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);
   }
 }
コード例 #10
0
 /**
  * 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());
 }
コード例 #11
0
ファイル: ServletUtil.java プロジェクト: Eljah/jamwiki
 /**
  * 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;
 }
コード例 #12
0
ファイル: EditServlet.java プロジェクト: Eljah/jamwiki
 private void resolve(HttpServletRequest request, ModelAndView next, WikiPageInfo pageInfo)
     throws Exception {
   String topicName = WikiUtil.getTopicFromRequest(request);
   String virtualWiki = pageInfo.getVirtualWikiName();
   Topic lastTopic = WikiBase.getDataHandler().lookupTopic(virtualWiki, topicName, false, null);
   String contents1 = lastTopic.getTopicContent();
   String contents2 = request.getParameter("contents");
   next.addObject("lastTopicVersionId", lastTopic.getCurrentVersionId());
   next.addObject("contentsResolve", contents2);
   this.loadDiff(request, next, pageInfo, contents1, contents2);
   this.loadEdit(request, next, pageInfo, contents1, virtualWiki, topicName, false);
   next.addObject("editResolve", "true");
 }
コード例 #13
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));
 }
コード例 #14
0
ファイル: EditServlet.java プロジェクト: Eljah/jamwiki
 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"));
 }
コード例 #15
0
ファイル: ServletUtil.java プロジェクト: Eljah/jamwiki
 /**
  * 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);
 }
コード例 #16
0
ファイル: ServletUtil.java プロジェクト: Eljah/jamwiki
 /**
  * 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);
 }
コード例 #17
0
ファイル: AbstractHeadingTag.java プロジェクト: Eljah/jamwiki
 private String buildSectionEditLink(ParserInput parserInput, int section) throws ParserException {
   if (!parserInput.getAllowSectionEdit()) {
     return "";
   }
   if (parserInput.getLocale() == null) {
     logger.info(
         "Unable to build section edit links for "
             + parserInput.getTopicName()
             + " - locale is empty");
     return "";
   }
   // FIXME - template inclusion causes section edits to break, so disable for now
   Integer inclusion = (Integer) parserInput.getTempParam(TemplateTag.TEMPLATE_INCLUSION);
   boolean disallowInclusion = (inclusion != null && inclusion > 0);
   if (disallowInclusion) {
     return "";
   }
   String url = "";
   try {
     url =
         LinkUtil.buildEditLinkUrl(
             parserInput.getContext(),
             parserInput.getVirtualWiki(),
             parserInput.getTopicName(),
             null,
             section);
   } catch (DataAccessException e) {
     logger.error(
         "Failure while building link for topic "
             + parserInput.getVirtualWiki()
             + " / "
             + parserInput.getTopicName(),
         e);
   }
   // arguments are edit link URL and edit label text
   Object[] args = new Object[2];
   args[0] = url;
   args[1] = Utilities.formatMessage("common.sectionedit", parserInput.getLocale());
   try {
     return WikiUtil.formatFromTemplate(TEMPLATE_HEADER_EDIT_LINK, args);
   } catch (IOException e) {
     throw new ParserException(e);
   }
 }
コード例 #18
0
ファイル: ServletUtil.java プロジェクト: Eljah/jamwiki
 /**
  * Initialize topic values for a Topic object. This method will check to see if a topic with the
  * specified name exists, and if it does exist then that topic will be returned. Otherwise a new
  * topic will be initialized, setting initial parameters such as topic name, virtual wiki, and
  * topic type.
  *
  * @param virtualWiki The virtual wiki name for the topic being initialized.
  * @param topicName The name of the topic being initialized.
  * @return A new topic object with basic fields initialized, or if a topic with the given name
  *     already exists then the pre-existing topic is returned.
  * @throws Exception Thrown if any error occurs while retrieving or initializing the topic object.
  */
 protected static Topic initializeTopic(String virtualWiki, String topicName) throws Exception {
   WikiUtil.validateTopicName(topicName);
   Topic topic = WikiBase.getDataHandler().lookupTopic(virtualWiki, topicName, false, null);
   if (topic != null) {
     return topic;
   }
   topic = new Topic();
   topic.setName(topicName);
   topic.setVirtualWiki(virtualWiki);
   WikiLink wikiLink = LinkUtil.parseWikiLink(topicName);
   String namespace = wikiLink.getNamespace();
   if (namespace != null) {
     if (namespace.equals(NamespaceHandler.NAMESPACE_CATEGORY)) {
       topic.setTopicType(Topic.TYPE_CATEGORY);
     } else if (namespace.equals(NamespaceHandler.NAMESPACE_TEMPLATE)) {
       topic.setTopicType(Topic.TYPE_TEMPLATE);
     }
   }
   return topic;
 }
コード例 #19
0
ファイル: EditServlet.java プロジェクト: Eljah/jamwiki
 private void edit(HttpServletRequest request, ModelAndView next, WikiPageInfo pageInfo)
     throws Exception {
   String topicName = WikiUtil.getTopicFromRequest(request);
   String virtualWiki = pageInfo.getVirtualWikiName();
   Topic topic = loadTopic(virtualWiki, topicName);
   // topic name might be updated by loadTopic
   topicName = topic.getName();
   Integer lastTopicVersionId = retrieveLastTopicVersionId(request, topic);
   next.addObject("lastTopicVersionId", lastTopicVersionId);
   String contents = (String) request.getParameter("contents");
   if (isPreview(request)) {
     preview(request, next, pageInfo);
   } else if (isShowChanges(request)) {
     showChanges(request, next, pageInfo, virtualWiki, topicName, lastTopicVersionId);
   } else if (!StringUtils.isBlank(request.getParameter("topicVersionId"))) {
     // editing an older version
     Integer topicVersionId = Integer.valueOf(request.getParameter("topicVersionId"));
     TopicVersion topicVersion = WikiBase.getDataHandler().lookupTopicVersion(topicVersionId);
     if (topicVersion == null) {
       throw new WikiException(new WikiMessage("common.exception.notopic"));
     }
     contents = topicVersion.getVersionContent();
     if (!lastTopicVersionId.equals(topicVersionId)) {
       next.addObject("topicVersionId", topicVersionId);
     }
   } else if (!StringUtils.isBlank(request.getParameter("section"))) {
     // editing a section of a topic
     int section = Integer.valueOf(request.getParameter("section"));
     String[] sliceResults =
         ParserUtil.parseSlice(
             request.getContextPath(), request.getLocale(), virtualWiki, topicName, section);
     contents = sliceResults[1];
     String sectionName = sliceResults[0];
     String editComment = "/* " + sectionName + " */ ";
     next.addObject("editComment", editComment);
   } else {
     // editing a full new or existing topic
     contents = (topic == null) ? "" : topic.getTopicContent();
   }
   this.loadEdit(request, next, pageInfo, contents, virtualWiki, topicName, true);
 }
コード例 #20
0
ファイル: TranslationServlet.java プロジェクト: Eljah/jamwiki
 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);
 }
コード例 #21
0
ファイル: SearchServlet.java プロジェクト: Eljah/jamwiki
 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);
 }
コード例 #22
0
ファイル: ServletUtil.java プロジェクト: Eljah/jamwiki
 /**
  * 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);
 }
コード例 #23
0
ファイル: SetupServlet.java プロジェクト: Eljah/jamwiki
 /**
  * This method handles the request after its parent class receives control.
  *
  * @param request - Standard HttpServletRequest object.
  * @param response - Standard HttpServletResponse object.
  * @return A <code>ModelAndView</code> object to be handled by the rest of the Spring framework.
  */
 protected ModelAndView handleJAMWikiRequest(
     HttpServletRequest request,
     HttpServletResponse response,
     ModelAndView next,
     WikiPageInfo pageInfo)
     throws Exception {
   if (!WikiUtil.isFirstUse()) {
     throw new WikiException(new WikiMessage("setup.error.notrequired"));
   }
   String function =
       (request.getParameter("function") == null)
           ? request.getParameter("override")
           : request.getParameter("function");
   if (function == null) {
     function = "";
   }
   try {
     if (!SystemUtils.isJavaVersionAtLeast(MINIMUM_JDK_VERSION)) {
       throw new WikiException(
           new WikiMessage(
               "setup.error.jdk",
               Integer.valueOf(MINIMUM_JDK_VERSION).toString(),
               System.getProperty("java.version")));
     }
     if (!StringUtils.isBlank(function) && initialize(request, next, pageInfo)) {
       ServletUtil.redirect(
           next,
           WikiBase.DEFAULT_VWIKI,
           Environment.getValue(Environment.PROP_BASE_DEFAULT_TOPIC));
     } else {
       view(request, next, pageInfo);
     }
   } catch (Exception e) {
     handleSetupError(request, next, pageInfo, e);
   }
   return next;
 }
コード例 #24
0
ファイル: ServletUtil.java プロジェクト: Eljah/jamwiki
 /**
  * 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 pageTitle The title of the page being rendered.
  * @param topic The Topic object for the topic being displayed.
  * @param sectionEdit Set to <code>true</code> if edit links should be displayed for each section
  *     of the topic.
  * @throws Exception Thrown if any error occurs during processing.
  */
 protected static void viewTopic(
     HttpServletRequest request,
     ModelAndView next,
     WikiPageInfo pageInfo,
     WikiMessage pageTitle,
     Topic topic,
     boolean sectionEdit)
     throws Exception {
   // FIXME - what should the default be for topics that don't exist?
   if (topic == null) {
     throw new WikiException(new WikiMessage("common.exception.notopic"));
   }
   WikiUtil.validateTopicName(topic.getName());
   if (topic.getTopicType() == Topic.TYPE_REDIRECT
       && (request.getParameter("redirect") == null
           || !request.getParameter("redirect").equalsIgnoreCase("no"))) {
     Topic child = Utilities.findRedirectedTopic(topic, 0);
     if (!child.getName().equals(topic.getName())) {
       pageInfo.setRedirectName(topic.getName());
       pageTitle = new WikiMessage("topic.title", child.getName());
       topic = child;
     }
   }
   String virtualWiki = topic.getVirtualWiki();
   String topicName = topic.getName();
   WikiUser user = Utilities.currentUser();
   if (sectionEdit && !ServletUtil.isEditable(virtualWiki, topicName, user)) {
     sectionEdit = false;
   }
   ParserInput parserInput = new ParserInput();
   parserInput.setContext(request.getContextPath());
   parserInput.setLocale(request.getLocale());
   parserInput.setWikiUser(user);
   parserInput.setTopicName(topicName);
   parserInput.setUserIpAddress(request.getRemoteAddr());
   parserInput.setVirtualWiki(virtualWiki);
   parserInput.setAllowSectionEdit(sectionEdit);
   ParserDocument parserDocument = new ParserDocument();
   String content = Utilities.parse(parserInput, parserDocument, topic.getTopicContent());
   // FIXME - the null check should be unnecessary
   if (parserDocument != null && parserDocument.getCategories().size() > 0) {
     LinkedHashMap categories = new LinkedHashMap();
     for (Iterator iterator = parserDocument.getCategories().keySet().iterator();
         iterator.hasNext(); ) {
       String key = (String) iterator.next();
       String value =
           key.substring(
               NamespaceHandler.NAMESPACE_CATEGORY.length()
                   + NamespaceHandler.NAMESPACE_SEPARATOR.length());
       categories.put(key, value);
     }
     next.addObject("categories", categories);
   }
   topic.setTopicContent(content);
   if (topic.getTopicType() == Topic.TYPE_CATEGORY) {
     loadCategoryContent(next, virtualWiki, topic.getName());
   }
   if (topic.getTopicType() == Topic.TYPE_IMAGE || topic.getTopicType() == Topic.TYPE_FILE) {
     Collection fileVersions =
         WikiBase.getDataHandler().getAllWikiFileVersions(virtualWiki, topicName, true);
     for (Iterator iterator = fileVersions.iterator(); iterator.hasNext(); ) {
       // update version urls to include web root path
       WikiFileVersion fileVersion = (WikiFileVersion) iterator.next();
       String url =
           FilenameUtils.normalize(
               Environment.getValue(Environment.PROP_FILE_DIR_RELATIVE_PATH)
                   + "/"
                   + fileVersion.getUrl());
       url = FilenameUtils.separatorsToUnix(url);
       fileVersion.setUrl(url);
     }
     next.addObject("fileVersions", fileVersions);
     if (topic.getTopicType() == Topic.TYPE_IMAGE) {
       next.addObject("topicImage", new Boolean(true));
     } else {
       next.addObject("topicFile", new Boolean(true));
     }
   }
   pageInfo.setSpecial(false);
   pageInfo.setTopicName(topicName);
   next.addObject(ServletUtil.PARAMETER_TOPIC_OBJECT, topic);
   if (pageTitle != null) {
     pageInfo.setPageTitle(pageTitle);
   }
 }
コード例 #25
0
ファイル: WikiUtil.java プロジェクト: Eljah/jamwiki
 /**
  * Retrieve a topic name from the servlet request. This method will retrieve a request parameter
  * matching the PARAMETER_TOPIC value, and will decode it appropriately.
  *
  * @param request The servlet request object.
  * @return The decoded topic name retrieved from the request.
  */
 public static String getTopicFromRequest(HttpServletRequest request) {
   return WikiUtil.getParameterFromRequest(request, WikiUtil.PARAMETER_TOPIC, true);
 }
コード例 #26
0
ファイル: EditServlet.java プロジェクト: Eljah/jamwiki
 /** Functionality to handle the "Save" button being clicked. */
 private void save(HttpServletRequest request, ModelAndView next, WikiPageInfo pageInfo)
     throws Exception {
   String topicName = WikiUtil.getTopicFromRequest(request);
   String virtualWiki = pageInfo.getVirtualWikiName();
   Topic topic = loadTopic(virtualWiki, topicName);
   Topic lastTopic = WikiBase.getDataHandler().lookupTopic(virtualWiki, topicName, false, null);
   if (lastTopic != null
       && !lastTopic.getCurrentVersionId().equals(retrieveLastTopicVersionId(request, topic))) {
     // someone else has edited the topic more recently
     resolve(request, next, pageInfo);
     return;
   }
   String contents = request.getParameter("contents");
   String sectionName = "";
   if (!StringUtils.isBlank(request.getParameter("section"))) {
     // load section of topic
     int section = Integer.valueOf(request.getParameter("section"));
     ParserOutput parserOutput = new ParserOutput();
     String[] spliceResult =
         ParserUtil.parseSplice(
             parserOutput,
             request.getContextPath(),
             request.getLocale(),
             virtualWiki,
             topicName,
             section,
             contents);
     contents = spliceResult[1];
     sectionName = parserOutput.getSectionName();
   }
   if (contents == null) {
     logger.warning("The topic " + topicName + " has no content");
     throw new WikiException(new WikiMessage("edit.exception.nocontent", topicName));
   }
   // strip line feeds
   contents = StringUtils.remove(contents, '\r');
   String lastTopicContent =
       (lastTopic != null) ? StringUtils.remove(lastTopic.getTopicContent(), '\r') : "";
   if (lastTopic != null && StringUtils.equals(lastTopicContent, contents)) {
     // topic hasn't changed. redirect to prevent user from refreshing and re-submitting
     ServletUtil.redirect(next, virtualWiki, topic.getName());
     return;
   }
   String editComment = request.getParameter("editComment");
   if (handleSpam(request, next, topicName, contents, editComment)) {
     this.loadEdit(request, next, pageInfo, contents, virtualWiki, topicName, false);
     return;
   }
   // parse for signatures and other syntax that should not be saved in raw form
   WikiUser user = ServletUtil.currentWikiUser();
   ParserInput parserInput = new ParserInput();
   parserInput.setContext(request.getContextPath());
   parserInput.setLocale(request.getLocale());
   parserInput.setWikiUser(user);
   parserInput.setTopicName(topicName);
   parserInput.setUserDisplay(ServletUtil.getIpAddress(request));
   parserInput.setVirtualWiki(virtualWiki);
   ParserOutput parserOutput = ParserUtil.parseMetadata(parserInput, contents);
   // parse signatures and other values that need to be updated prior to saving
   contents = ParserUtil.parseMinimal(parserInput, contents);
   topic.setTopicContent(contents);
   if (!StringUtils.isBlank(parserOutput.getRedirect())) {
     // set up a redirect
     topic.setRedirectTo(parserOutput.getRedirect());
     topic.setTopicType(TopicType.REDIRECT);
   } else if (topic.getTopicType() == TopicType.REDIRECT) {
     // no longer a redirect
     topic.setRedirectTo(null);
     topic.setTopicType(TopicType.ARTICLE);
   }
   int charactersChanged = StringUtils.length(contents) - StringUtils.length(lastTopicContent);
   TopicVersion topicVersion =
       new TopicVersion(
           user, ServletUtil.getIpAddress(request), editComment, contents, charactersChanged);
   if (request.getParameter("minorEdit") != null) {
     topicVersion.setEditType(TopicVersion.EDIT_MINOR);
   }
   WikiBase.getDataHandler()
       .writeTopic(topic, topicVersion, parserOutput.getCategories(), parserOutput.getLinks());
   // update watchlist
   WikiUserDetailsImpl userDetails = ServletUtil.currentUserDetails();
   if (!userDetails.hasRole(Role.ROLE_ANONYMOUS)) {
     Watchlist watchlist = ServletUtil.currentWatchlist(request, virtualWiki);
     boolean watchTopic = (request.getParameter("watchTopic") != null);
     if (watchlist.containsTopic(topicName) != watchTopic) {
       WikiBase.getDataHandler()
           .writeWatchlistEntry(watchlist, virtualWiki, topicName, user.getUserId());
     }
   }
   // redirect to prevent user from refreshing and re-submitting
   String target = topic.getName();
   if (!StringUtils.isBlank(sectionName)) {
     target += "#" + sectionName;
   }
   ServletUtil.redirect(next, virtualWiki, target);
 }
コード例 #27
0
ファイル: ServletUtil.java プロジェクト: Eljah/jamwiki
 /**
  * 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;
 }
コード例 #28
0
ファイル: WikiBase.java プロジェクト: Eljah/jamwiki
 /** Reload the data handler, user handler, and other basic wiki data structures. */
 public static void reload() throws Exception {
   WikiBase.dataHandler = WikiUtil.dataHandlerInstance();
   WikiBase.searchEngine = WikiUtil.searchEngineInstance();
 }