示例#1
1
 /**
  * Returns any trailing period, comma, semicolon, or colon characters from the given string. This
  * method is useful when parsing raw HTML links, in which case trailing punctuation must be
  * removed. Note that only punctuation that is not previously matched is trimmed - if the input is
  * "http://example.com/page_(page)" then the trailing parantheses will not be trimmed.
  *
  * @param text The text from which trailing punctuation should be returned.
  * @return Any trailing punctuation from the given text, or an empty string otherwise.
  */
 private String extractTrailingPunctuation(String text) {
   if (StringUtils.isBlank(text)) {
     return "";
   }
   StringBuilder buffer = new StringBuilder();
   for (int i = text.length() - 1; i >= 0; i--) {
     char c = text.charAt(i);
     if (c == '.' || c == ';' || c == ',' || c == ':' || c == '(' || c == '[' || c == '{') {
       buffer.append(c);
       continue;
     }
     // if the value ends with ), ] or } then strip it UNLESS there is a matching
     // opening tag
     if (c == ')' || c == ']' || c == '}') {
       String closeChar = String.valueOf(c);
       String openChar = (c == ')') ? "(" : ((c == ']') ? "[" : "{");
       int pos = Utilities.findMatchingStartTag(text, i, openChar, closeChar);
       if (pos == -1) {
         buffer.append(c);
         continue;
       }
     }
     break;
   }
   if (buffer.length() == 0) {
     return "";
   }
   buffer = buffer.reverse();
   return buffer.toString();
 }
示例#2
0
 /**
  * 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.
  */
 public ModelAndView handleRequestInternal(
     HttpServletRequest request, HttpServletResponse response) {
   ModelAndView next = new ModelAndView("wiki");
   try {
     if (!Utilities.isAdmin(request)) {
       String redirect = "Special:Translation";
       next.addObject(
           "errorMessage",
           Utilities.getMessage("admin.message.loginrequired", request.getLocale()));
       viewLogin(request, next, redirect);
       loadDefaults(request, next, this.pageInfo);
       return next;
     }
     String function = request.getParameter("function");
     if (!StringUtils.hasText(function)) {
       view(request, next);
     } else {
       translate(request, next);
     }
     next.addObject("translations", new TreeMap(this.translations));
     next.addObject("codes", this.retrieveTranslationCodes());
     if (request.getParameter("language") != null)
       next.addObject("language", request.getParameter("language"));
   } catch (Exception e) {
     viewError(request, next, e);
   }
   loadDefaults(request, next, this.pageInfo);
   return next;
 }
示例#3
0
 /**
  * Build a URL to the topic page for a given topic. This method does NOT verify if the topic
  * exists or if it is a "Special:" page, simply returning the URL for the topic and virtual wiki.
  *
  * @param context The servlet context path. If this value is <code>null</code> then the resulting
  *     URL will NOT include context path, which breaks HTML links but is useful for servlet
  *     redirection URLs.
  * @param virtualWiki The virtual wiki for the link that is being created.
  * @param topicName The name of the topic for which a link is being built.
  * @param section The section of the page (#section) for which a link is being built.
  * @param queryString Query string parameters to append to the link.
  * @throws Exception Thrown if any error occurs while builing the link URL.
  */
 private static String buildTopicUrlNoEdit(
     String context, String virtualWiki, String topicName, String section, String queryString) {
   // TODO same as LinkUtil#buildTopicUrlNoEdit()
   if (StringUtils.isBlank(topicName) && !StringUtils.isBlank(section)) {
     return "#" + Utilities.encodeAndEscapeTopicName(section);
   }
   StringBuilder url = new StringBuilder();
   if (context != null) {
     url.append(context);
   }
   // context never ends with a "/" per servlet specification
   url.append('/');
   // get the virtual wiki, which should have been set by the parent servlet
   url.append(Utilities.encodeAndEscapeTopicName(virtualWiki));
   url.append('/');
   url.append(Utilities.encodeAndEscapeTopicName(topicName));
   if (!StringUtils.isBlank(queryString)) {
     if (queryString.charAt(0) != '?') {
       url.append('?');
     }
     url.append(queryString);
   }
   if (!StringUtils.isBlank(section)) {
     if (section.charAt(0) != '#') {
       url.append('#');
     }
     url.append(Utilities.encodeAndEscapeTopicName(section));
   }
   return url.toString();
 }
示例#4
0
 private void setProperties(HttpServletRequest request, ModelAndView next) throws Exception {
   Environment.setValue(
       Environment.PROP_BASE_FILE_DIR, request.getParameter(Environment.PROP_BASE_FILE_DIR));
   Environment.setValue(
       Environment.PROP_FILE_DIR_FULL_PATH,
       request.getParameter(Environment.PROP_FILE_DIR_FULL_PATH));
   Environment.setValue(
       Environment.PROP_FILE_DIR_RELATIVE_PATH,
       request.getParameter(Environment.PROP_FILE_DIR_RELATIVE_PATH));
   Environment.setValue(
       Environment.PROP_BASE_PERSISTENCE_TYPE,
       request.getParameter(Environment.PROP_BASE_PERSISTENCE_TYPE));
   if (Environment.getValue(Environment.PROP_BASE_PERSISTENCE_TYPE)
       .equals(WikiBase.PERSISTENCE_EXTERNAL)) {
     Environment.setValue(
         Environment.PROP_DB_DRIVER, request.getParameter(Environment.PROP_DB_DRIVER));
     Environment.setValue(
         Environment.PROP_DB_TYPE, request.getParameter(Environment.PROP_DB_TYPE));
     Environment.setValue(Environment.PROP_DB_URL, request.getParameter(Environment.PROP_DB_URL));
     Environment.setValue(
         Environment.PROP_DB_USERNAME, request.getParameter(Environment.PROP_DB_USERNAME));
     Encryption.setEncryptedProperty(
         Environment.PROP_DB_PASSWORD, request.getParameter(Environment.PROP_DB_PASSWORD), null);
     next.addObject("dbPassword", request.getParameter(Environment.PROP_DB_PASSWORD));
   } else {
     WikiDatabase.setupDefaultDatabase(Environment.getInstance());
   }
   Environment.setValue(Environment.PROP_FILE_SERVER_URL, Utilities.getServerUrl(request));
   Environment.setValue(Environment.PROP_SERVER_URL, Utilities.getServerUrl(request));
 }
示例#5
0
 protected static void setupSpecialPage(
     Locale locale,
     String virtualWiki,
     String topicName,
     WikiUser user,
     boolean adminOnly,
     Connection conn)
     throws Exception {
   logger.info("Setting up special page " + virtualWiki + " / " + topicName);
   String contents = Utilities.readSpecialPage(locale, topicName);
   Topic topic = new Topic();
   topic.setName(topicName);
   topic.setVirtualWiki(virtualWiki);
   topic.setTopicContent(contents);
   topic.setAdminOnly(adminOnly);
   // FIXME - hard coding
   TopicVersion topicVersion =
       new TopicVersion(
           user, user.getLastLoginIpAddress(), "Automatically created by system setup", contents);
   WikiBase.getDataHandler()
       .writeTopic(
           topic,
           topicVersion,
           Utilities.parserDocument(topic.getTopicContent(), virtualWiki, topicName),
           true,
           conn);
 }
示例#6
0
 public static File getClassLoaderFile(String fileName) throws FileNotFoundException {
   try {
     return Utilities.getClassLoaderFile(fileName);
   } catch (FileNotFoundException e) {
     // ignore
   }
   return new File(Utilities.getClassLoaderRoot(), fileName);
 }
示例#7
0
 private void view(HttpServletRequest request, ModelAndView next, WikiPageInfo pageInfo)
     throws Exception {
   if (Utilities.currentUser(request) != null) {
     next.addObject("newuser", Utilities.currentUser(request));
   }
   pageInfo.setSpecial(true);
   pageInfo.setAction(WikiPageInfo.ACTION_REGISTER);
   pageInfo.setPageTitle(new WikiMessage("register.title"));
 }
示例#8
0
 public static File retrieveFile(String directory, String fileName) {
   fileName = encodeTopicName(fileName);
   String fullName = directory + fileName;
   try {
     return Utilities.getClassLoaderFile(fullName);
   } catch (FileNotFoundException e) {
   }
   try {
     return new File(Utilities.getClassLoaderRoot(), fullName);
   } catch (FileNotFoundException e) {
   }
   return null;
 }
示例#9
0
 public static String getTopicFromURI(HttpServletRequest request) throws Exception {
   String uri = request.getRequestURI().trim();
   // FIXME - needs testing on other platforms
   uri = Utilities.convertEncoding(uri, "ISO-8859-1", "UTF-8");
   if (uri == null || uri.length() <= 0) {
     throw new Exception("URI string is empty");
   }
   int slashIndex = uri.lastIndexOf('/');
   if (slashIndex == -1) {
     throw new Exception("No topic in URL: " + uri);
   }
   String topic = uri.substring(slashIndex + 1);
   topic = Utilities.decodeURL(topic);
   return topic;
 }
示例#10
0
 /**
  * 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 (!Utilities.isAdmin(request)) {
     WikiMessage errorMessage = new WikiMessage("admin.message.loginrequired");
     return ServletUtil.viewLogin(request, pageInfo, "Special:Admin", errorMessage);
   }
   String function = request.getParameter("function");
   if (!StringUtils.hasText(function)) {
     view(request, next, pageInfo, null);
   } else if (function.equals("refreshIndex")) {
     refreshIndex(request, next, pageInfo);
   } else if (function.equals("properties")) {
     properties(request, next, pageInfo);
   } else if (function.equals("addVirtualWiki")) {
     addVirtualWiki(request, next, pageInfo);
   } else if (function.equals("recentChanges")) {
     recentChanges(request, next, pageInfo);
   } else if (function.equals("spamFilter")) {
     spamFilter(request, next, pageInfo);
   }
   return next;
 }
示例#11
0
 /**
  * Retrieve the content of a topic from the cache, or if it is not yet in the cache then add it to
  * the cache.
  *
  * @param context The servlet context for the topic being retrieved. May be <code>null</code> if
  *     the <code>cook</code> parameter is set to <code>false</code>.
  * @param locale The locale for the topic being retrieved. May be <code>null</code> if the <code>
  *     cook</code> parameter is set to <code>false</code>.
  * @param virtualWiki The virtual wiki for the topic being retrieved.
  * @param topicName The name of the topic being retrieved.
  * @param cook A parameter indicating whether or not the content should be parsed before it is
  *     added to the cache. Stylesheet content (CSS) is not parsed, but most other content is
  *     parsed.
  * @return The parsed or unparsed (depending on the <code>cook</code> parameter) topic content.
  */
 protected static String cachedContent(
     String context, Locale locale, String virtualWiki, String topicName, boolean cook) {
   String content = null;
   String key = WikiCache.key(virtualWiki, topicName);
   Element cacheElement = WikiCache.retrieveFromCache(WikiBase.CACHE_PARSED_TOPIC_CONTENT, key);
   if (cacheElement != null) {
     content = (String) cacheElement.getObjectValue();
     return (content == null) ? null : new String(content);
   }
   try {
     Topic topic = WikiBase.getDataHandler().lookupTopic(virtualWiki, topicName, false, null);
     content = topic.getTopicContent();
     if (cook) {
       ParserInput parserInput = new ParserInput();
       parserInput.setContext(context);
       parserInput.setLocale(locale);
       parserInput.setVirtualWiki(virtualWiki);
       parserInput.setTopicName(topicName);
       content = Utilities.parse(parserInput, null, content);
     }
     WikiCache.addToCache(WikiBase.CACHE_PARSED_TOPIC_CONTENT, key, content);
   } catch (Exception e) {
     logger.warning("error getting cached page " + virtualWiki + " / " + topicName, e);
     return null;
   }
   return content;
 }
示例#12
0
 private Vector validate(HttpServletRequest request, WikiUser user) throws Exception {
   Vector errors = new Vector();
   if (!StringUtils.hasText(user.getLogin())) {
     errors.add(new WikiMessage("error.loginempty"));
   }
   if (!Utilities.validateUserName(user.getLogin())) {
     errors.add(new WikiMessage("common.exception.name", user.getLogin()));
   }
   String oldPassword = request.getParameter("oldPassword");
   if (user.getUserId() > 0
       && WikiBase.getHandler().lookupWikiUser(user.getLogin(), oldPassword, false) == null) {
     errors.add(new WikiMessage("register.error.oldpasswordinvalid"));
   }
   String newPassword = request.getParameter("newPassword");
   String confirmPassword = request.getParameter("confirmPassword");
   if (user.getUserId() < 1 && !StringUtils.hasText(newPassword)) {
     errors.add(new WikiMessage("register.error.passwordempty"));
   }
   if (StringUtils.hasText(newPassword) || StringUtils.hasText(confirmPassword)) {
     if (!StringUtils.hasText(newPassword)) {
       errors.add(new WikiMessage("error.newpasswordempty"));
     } else if (!StringUtils.hasText(confirmPassword)) {
       errors.add(new WikiMessage("error.passwordconfirm"));
     } else if (!newPassword.equals(confirmPassword)) {
       errors.add(new WikiMessage("admin.message.passwordsnomatch"));
     }
   }
   return errors;
 }
示例#13
0
  @Override
  public void appendInterWikiLink(String namespace, String title, String topicDescription) {
    String hrefLink = getInterwikiMap().get(namespace.toLowerCase());
    if (hrefLink != null) {
      String virtualWiki = fParserInput.getVirtualWiki();
      WikiLink wikiLink =
          LinkUtil.parseWikiLink(
              virtualWiki, namespace + Namespace.SEPARATOR + title + "|" + topicDescription);
      String destination = wikiLink.getDestination();
      destination =
          destination.substring(
              wikiLink.getNamespace().getLabel(virtualWiki).length()
                  + Namespace.SEPARATOR.length());
      hrefLink = hrefLink.replace("${title}", Utilities.encodeAndEscapeTopicName(title));
      TagNode aTagNode = new TagNode("a");
      aTagNode.addAttribute("href", hrefLink, true);
      aTagNode.addAttribute("class", "interwiki", false);

      pushNode(aTagNode);
      WikipediaParser.parseRecursive(topicDescription.trim(), this, false, true);
      popNode();

    } else {
      append(new ContentToken(topicDescription));
    }
  }
示例#14
0
 private void view(HttpServletRequest request, ModelAndView next, WikiPageInfo pageInfo)
     throws Exception {
   String virtualWiki = Utilities.getVirtualWikiFromURI(request);
   Pagination pagination = Utilities.buildPagination(request, next);
   WikiUser user = Utilities.currentUser();
   if (!user.hasRole(Role.ROLE_USER)) {
     throw new WikiException(new WikiMessage("watchlist.error.loginrequired"));
   }
   Collection changes =
       WikiBase.getDataHandler().getWatchlist(virtualWiki, user.getUserId(), pagination);
   next.addObject("numChanges", new Integer(changes.size()));
   next.addObject("changes", changes);
   pageInfo.setPageTitle(new WikiMessage("watchlist.title"));
   pageInfo.setContentJsp(JSP_WATCHLIST);
   pageInfo.setSpecial(true);
 }
示例#15
0
 private String processAuthenticationRequiredException(HttpServletRequest request)
     throws JspException {
   String key =
       (String)
           request
               .getSession()
               .getAttribute(JAMWikiAuthenticationConstants.JAMWIKI_AUTHENTICATION_REQUIRED_KEY);
   String uri =
       (String)
           request
               .getSession()
               .getAttribute(
                   JAMWikiAuthenticationConstants.JAMWIKI_AUTHENTICATION_REQUIRED_URI_KEY);
   if (key == null) {
     return null;
   }
   Object[] params = {uri};
   String message = Utilities.formatMessage(key, ServletUtil.retrieveUserLocale(request), params);
   request
       .getSession()
       .removeAttribute(JAMWikiAuthenticationConstants.JAMWIKI_AUTHENTICATION_REQUIRED_KEY);
   request
       .getSession()
       .removeAttribute(JAMWikiAuthenticationConstants.JAMWIKI_AUTHENTICATION_REQUIRED_URI_KEY);
   return formatMessage(message);
 }
示例#16
0
 /**
  * Utility methods for retrieving property files from the class path, based on code from the
  * org.apache.log4j.helpers.Loader class.
  *
  * @param filename Given a filename return a File object for the file. The filename may be
  *     relative to the class path or the directory from which the JVM was initialized.
  * @return Returns a file representing the filename, or <code>null</code> if the file cannot be
  *     found.
  */
 private static File retrievePropertyFile(String filename) {
   File file = null;
   try {
     file = Utilities.getClassLoaderFile(filename);
     return file; // NOPMD
   } catch (Exception e) {
     // NOPMD file might not exist
   }
   try {
     file = new File(Utilities.getClassLoaderRoot(), filename);
     return file; // NOPMD
   } catch (Exception e) {
     logger.severe("Error while searching for resource " + filename, e);
   }
   return null;
 }
示例#17
0
 /**
  * Return the default upload directory (/webapp-root/upload/) as a String.
  *
  * @return The default upload directory (/webapp-root/upload/) as a String.
  */
 private static String retrieveDefaultUploadDirectory() {
   try {
     return new File(Utilities.getWebappRoot(), "upload").getPath();
   } catch (Exception e) {
     logger.severe("Failure while trying to retrieve default file upload directory", e);
   }
   return "";
 }
示例#18
0
 private String processAuthorizationException(HttpServletRequest request) throws JspException {
   String key = (String) request.getParameter("message");
   if (key == null) {
     return null;
   }
   String message = Utilities.formatMessage(key, ServletUtil.retrieveUserLocale(request));
   return formatMessage(message);
 }
示例#19
0
 /**
  * Return the default relative upload directory (/context/upload/) as a String.
  *
  * @return The default relative upload directory (/context/upload/) as a String.
  */
 private static String retrieveDefaultRelativeUploadDirectory() {
   try {
     return "/" + Utilities.getWebappRoot().getName() + "/upload/";
   } catch (Exception e) {
     logger.severe("Failure while trying to retrieve default file upload directory", e);
   }
   return "";
 }
示例#20
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;
 }
示例#21
0
 public static String getTopicFromRequest(HttpServletRequest request) throws Exception {
   String topic = request.getParameter(JAMWikiServlet.PARAMETER_TOPIC);
   if (topic == null) {
     topic = (String) request.getAttribute(JAMWikiServlet.PARAMETER_TOPIC);
   }
   if (topic == null) return null;
   topic = Utilities.decodeURL(topic);
   return topic;
 }
示例#22
0
 private String buildTocText(JFlexLexer lexer, String tagText) throws ParserException {
   // since the TOC isn't part of the editable content use a copy of the parser input/
   // and an empty output.
   ParserInput tmpParserInput = new ParserInput(lexer.getParserInput());
   ParserOutput parserOutput = new ParserOutput();
   String tocText =
       this.processTocText(tmpParserInput, parserOutput, tagText, JFlexParser.MODE_PROCESS);
   return Utilities.stripMarkup(tocText);
 }
示例#23
0
 private ModelAndView loginRequired(HttpServletRequest request) throws Exception {
   String topicName = JAMWikiServlet.getTopicFromRequest(request);
   String virtualWiki = JAMWikiServlet.getVirtualWikiFromURI(request);
   if (!StringUtils.hasText(topicName) || !StringUtils.hasText(virtualWiki)) {
     return null;
   }
   if (Environment.getBooleanValue(Environment.PROP_TOPIC_FORCE_USERNAME)
       && Utilities.currentUser(request) == null) {
     WikiMessage errorMessage = new WikiMessage("edit.exception.login");
     return viewLogin(request, JAMWikiServlet.getTopicFromURI(request), errorMessage);
   }
   Topic topic = WikiBase.getHandler().lookupTopic(virtualWiki, topicName);
   if (topic != null && topic.getAdminOnly() && !Utilities.isAdmin(request)) {
     WikiMessage errorMessage = new WikiMessage("edit.exception.loginadmin", topicName);
     return viewLogin(request, JAMWikiServlet.getTopicFromURI(request), errorMessage);
   }
   return null;
 }
示例#24
0
 private void update(HttpServletRequest request, ModelAndView next, WikiPageInfo pageInfo)
     throws Exception {
   WikiUser user = Utilities.currentUser();
   if (!user.hasRole(Role.ROLE_USER)) {
     throw new WikiException(new WikiMessage("watchlist.error.loginrequired"));
   }
   String topicName = Utilities.getTopicFromRequest(request);
   String virtualWiki = Utilities.getVirtualWikiFromURI(request);
   Watchlist watchlist = Utilities.currentWatchlist(request, virtualWiki);
   WikiBase.getDataHandler()
       .writeWatchlistEntry(watchlist, virtualWiki, topicName, user.getUserId(), null);
   String article = Utilities.extractTopicLink(topicName);
   if (watchlist.containsTopic(topicName)) {
     // added to watchlist
     next.addObject("message", new WikiMessage("watchlist.caption.added", article));
   } else {
     // removed from watchlist
     next.addObject("message", new WikiMessage("watchlist.caption.removed", article));
   }
   this.view(request, next, pageInfo);
 }
示例#25
0
 private String processLegacyLogin(HttpServletRequest request) throws JspException {
   WikiMessage messageObject = (WikiMessage) request.getAttribute("messageObject");
   if (messageObject == null) {
     return null;
   }
   String message =
       Utilities.formatMessage(
           messageObject.getKey(),
           ServletUtil.retrieveUserLocale(request),
           messageObject.getParams());
   return formatMessage(message);
 }
示例#26
0
 private String pagination(String baseUrl, int count) {
   HttpServletRequest request = (HttpServletRequest) this.pageContext.getRequest();
   Pagination pagination = Utilities.buildPagination(request, null);
   StringBuffer output = new StringBuffer();
   output.append(this.nextPage(pagination, baseUrl, count, true));
   output.append("&#160;|&#160;");
   output.append(this.nextPage(pagination, baseUrl, count, false));
   output.append("&#160;&#160;(");
   output.append(this.numResults(pagination, baseUrl));
   output.append(")");
   return output.toString();
 }
示例#27
0
 /**
  * Parse a template string of the form "param1|param2|param3" into tokens (param1, param2, and
  * param3 in the example), handling such cases as "param1|[[foo|bar]]|param3" correctly.
  */
 protected static List<String> tokenizeParamString(String content) {
   List<String> tokens = new ArrayList<String>();
   int pos = 0;
   int endPos = -1;
   String substring = "";
   String value = "";
   while (pos < content.length()) {
     substring = content.substring(pos);
     endPos = -1;
     if (substring.startsWith("{{{")) {
       // template parameter
       endPos = Utilities.findMatchingEndTag(content, pos, "{{{", "}}}");
     } else if (substring.startsWith("{{")) {
       // template
       endPos = Utilities.findMatchingEndTag(content, pos, "{{", "}}");
     } else if (substring.startsWith("[[")) {
       // link
       endPos = Utilities.findMatchingEndTag(content, pos, "[[", "]]");
     } else if (substring.startsWith("{|")) {
       // table
       endPos = Utilities.findMatchingEndTag(content, pos, "{|", "|}");
     } else if (content.charAt(pos) == '|') {
       // new token
       tokens.add(value);
       value = "";
       pos++;
       continue;
     }
     if (endPos != -1) {
       value += content.substring(pos, endPos);
       pos = endPos;
     } else {
       value += content.charAt(pos);
       pos++;
     }
   }
   // add the last one
   tokens.add(value);
   return tokens;
 }
示例#28
0
 private void addVirtualWiki(HttpServletRequest request, ModelAndView next, WikiPageInfo pageInfo)
     throws Exception {
   WikiUser user = Utilities.currentUser(request);
   try {
     VirtualWiki virtualWiki = new VirtualWiki();
     if (StringUtils.hasText(request.getParameter("virtualWikiId"))) {
       virtualWiki.setVirtualWikiId(new Integer(request.getParameter("virtualWikiId")).intValue());
     }
     virtualWiki.setName(request.getParameter("name"));
     virtualWiki.setDefaultTopicName(
         Utilities.encodeForURL(request.getParameter("defaultTopicName")));
     WikiBase.getDataHandler().writeVirtualWiki(virtualWiki, null);
     if (!StringUtils.hasText(request.getParameter("virtualWikiId"))) {
       WikiBase.getDataHandler().setupSpecialPages(request.getLocale(), user, virtualWiki, null);
     }
     next.addObject("message", new WikiMessage("admin.message.virtualwikiadded"));
   } catch (Exception e) {
     logger.severe("Failure while adding virtual wiki", e);
     next.addObject("message", new WikiMessage("admin.message.virtualwikifail", e.getMessage()));
   }
   view(request, next, pageInfo, null);
 }
示例#29
0
 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);
 }
示例#30
0
 /**
  * Action used when viewing a topic.
  *
  * @param request The servlet request object.
  * @param next The Spring ModelAndView object.
  * @param topicName The topic being viewed. This value must be a valid topic that can be loaded as
  *     a org.jamwiki.model.Topic object.
  */
 protected void viewTopic(
     HttpServletRequest request,
     ModelAndView next,
     WikiMessage pageTitle,
     Topic topic,
     boolean sectionEdit)
     throws Exception {
   // FIXME - what should the default be for topics that don't exist?
   String contents = "";
   if (topic == null) {
     throw new WikiException(new WikiMessage("common.exception.notopic"));
   }
   String virtualWiki = topic.getVirtualWiki();
   String topicName = topic.getName();
   String displayName = request.getRemoteAddr();
   WikiUser user = Utilities.currentUser(request);
   ParserInfo parserInfo = new ParserInfo(request.getContextPath(), request.getLocale());
   parserInfo.setWikiUser(user);
   parserInfo.setTopicName(topicName);
   parserInfo.setUserIpAddress(request.getRemoteAddr());
   parserInfo.setVirtualWiki(virtualWiki);
   parserInfo.setAllowSectionEdit(sectionEdit);
   contents = Utilities.parse(parserInfo, topic.getTopicContent(), topicName);
   if (StringUtils.hasText(request.getParameter("highlight"))) {
     // search servlet highlights search terms, so add that here
     contents = AbstractSearchEngine.highlightHTML(contents, request.getParameter("highlight"));
   }
   topic.setTopicContent(contents);
   if (topic.getTopicType() == Topic.TYPE_IMAGE) {
     List fileVersions =
         WikiBase.getHandler().getAllWikiFileVersions(virtualWiki, topicName, true);
     next.addObject("fileVersions", fileVersions);
   }
   this.pageInfo.setSpecial(false);
   this.pageInfo.setTopicName(topicName);
   next.addObject(JAMWikiServlet.PARAMETER_TOPIC_OBJECT, topic);
   this.pageInfo.setPageTitle(pageTitle);
 }