Package org.jamwiki.utils

Examples of org.jamwiki.utils.WikiLink


   * @param raw The raw Wiki link text.
   * @return A WikiLink object that represents the link.
   */
  protected static WikiLink parseWikiLink(String raw) {
    if (StringUtils.isBlank(raw)) {
      return new WikiLink();
    }
    raw = raw.trim();
    String suffix = ((!raw.endsWith("]]")) ? raw.substring(raw.lastIndexOf("]]") + 2) : null);
    // for performance reasons use String methods rather than regex
    // private static final Pattern WIKI_LINK_PATTERN = Pattern.compile("\\[\\[\\s*(\\:\\s*)?\\s*(.+?)(\\s*\\|\\s*(.+))?\\s*\\]\\]([a-z]*)");
    raw = raw.substring(raw.indexOf("[[") + 2, raw.lastIndexOf("]]")).trim();
    boolean colon = false;
    if (raw.startsWith(":")) {
      colon = true;
      raw = raw.substring(1).trim();
    }
    String text = null;
    int pos = raw.indexOf('|');
    if (pos != -1 && pos != (raw.length() - 1)) {
      text = raw.substring(pos + 1).trim();
      raw = raw.substring(0, pos).trim();
    }
    WikiLink wikiLink = LinkUtil.parseWikiLink(raw);
    wikiLink.setColon(colon);
    wikiLink.setText(text);
    if (!StringUtils.isBlank(suffix)) {
      wikiLink.setText((StringUtils.isBlank(text) ? wikiLink.getDestination() : text) + suffix);
    }
    return wikiLink;
  }
View Full Code Here


      return topic;
    }
    topic = new Topic();
    topic.setName(topicName);
    // topic.setVirtualWiki(virtualWiki);
    WikiLink wikiLink = LinkUtil.parseWikiLink(topicName);
    String namespace = wikiLink.getNamespace();
    topic.setTopicType(WikiUtil.findTopicTypeForNamespace(namespace));
    return topic;
  }
View Full Code Here

      output.append(num);
      return output;
    }
    output.append("<a href=\"");
    String virtualWiki = WikiUtil.getVirtualWikiFromRequest(request);
    WikiLink wikiLink = LinkUtil.parseWikiLink(baseUrl);
    String query = LinkUtil.appendQueryParam(wikiLink.getQuery(), "num", Integer.toString(num));
    query += "&amp;offset=0";
    wikiLink.setQuery(query);
    try {
      output.append(LinkUtil.buildTopicUrl(request.getContextPath(), virtualWiki, wikiLink));
    } catch (DataAccessException e) {
      logger.warning("Failure while building pagination element", e);
      return new StringBuilder();
View Full Code Here

      output.append(Utilities.formatMessage("common.pagination.next", request.getLocale(), objects));
      return output;
    }
    output.append("<a href=\"");
    String virtualWiki = WikiUtil.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", Integer.toString(pagination.getNumResults()));
    query += "&amp;offset=" + offset;
    wikiLink.setQuery(query);
    try {
      output.append(LinkUtil.buildTopicUrl(request.getContextPath(), virtualWiki, wikiLink));
    } catch (DataAccessException e) {
      logger.warning("Failure while building pagination element", e);
      return new StringBuilder();
View Full Code Here

  public int doEndTag() throws JspException {
    String tagTarget = null;
    if (!StringUtils.isBlank(this.target)) {
      tagTarget = this.target;
    }
    WikiLink wikiLink = LinkUtil.parseWikiLink(this.value);
    String tagText = buildLinkText();
    HttpServletRequest request = (HttpServletRequest)this.pageContext.getRequest();
    String url = null;
    String virtualWiki = WikiUtil.getVirtualWikiFromRequest(request);
    if (!StringUtils.isBlank(this.queryParams)) {
      wikiLink.setQuery(this.queryParams);
    }
    try {
      if (!StringUtils.isBlank(tagText)) {
        // return formatted link of the form "<a href="/wiki/en/Special:Edit">text</a>"
        url = LinkUtil.buildInternalLinkHtml(request.getContextPath(), virtualWiki, wikiLink, tagText, this.style, tagTarget, true);
View Full Code Here

    if (StringUtils.isBlank(moveDestination)) {
      next.addObject("messageObject", new WikiMessage("move.exception.nodestination"));
      this.view(request, next, pageInfo);
      return false;
    }
    WikiLink fromWikiLink = LinkUtil.parseWikiLink(moveFrom);
    WikiLink destinationWikiLink = LinkUtil.parseWikiLink(moveDestination);
    if (!StringUtils.equals(fromWikiLink.getNamespace(), destinationWikiLink.getNamespace())) {
      // do not allow moving into or out of image & category namespace
      if (StringUtils.equals(fromWikiLink.getNamespace(), NamespaceHandler.NAMESPACE_CATEGORY)
          || StringUtils.equals(fromWikiLink.getNamespace(), NamespaceHandler.NAMESPACE_CATEGORY_COMMENTS)
          || StringUtils.equals(destinationWikiLink.getNamespace(), NamespaceHandler.NAMESPACE_CATEGORY)
          || StringUtils.equals(destinationWikiLink.getNamespace(), NamespaceHandler.NAMESPACE_CATEGORY_COMMENTS)
        ) {
        next.addObject("messageObject", new WikiMessage("move.exception.namespacecategory"));
        this.view(request, next, pageInfo);
        return false;
      } else if (StringUtils.equals(fromWikiLink.getNamespace(), NamespaceHandler.NAMESPACE_IMAGE)
          || StringUtils.equals(fromWikiLink.getNamespace(), NamespaceHandler.NAMESPACE_IMAGE_COMMENTS)
          || StringUtils.equals(destinationWikiLink.getNamespace(), NamespaceHandler.NAMESPACE_IMAGE)
          || StringUtils.equals(destinationWikiLink.getNamespace(), NamespaceHandler.NAMESPACE_IMAGE_COMMENTS)
        ) {
        next.addObject("messageObject", new WikiMessage("move.exception.namespaceimage"));
        this.view(request, next, pageInfo);
        return false;
      }
View Full Code Here

    }
    sectionName = sectionName.trim();
    String additionalComment = matcher.group(3);
    HttpServletRequest request = (HttpServletRequest)this.pageContext.getRequest();
    String virtualWiki = WikiUtil.getVirtualWikiFromRequest(request);
    WikiLink wikiLink = LinkUtil.parseWikiLink(this.topic + "#" + sectionName);
    StringBuilder result = new StringBuilder();
    result.append("<span class=\"").append(CSS_SECTION_COMMENT).append("\">");
    try {
      result.append(LinkUtil.buildInternalLinkHtml(request.getContextPath(), virtualWiki, wikiLink, "&rarr;", null, null, false));
    } catch (DataAccessException e) {
View Full Code Here

        // String watchlistLink = "Special:Watchlist?topic="
        // + Utilities.encodeAndEscapeTopicName(pageName);
        // links.put(watchlistLink, new WikiMessage(watchlistLabel));
        // }
        if (pageInfo.isUserPage()) {
          WikiLink wikiLink = LinkUtil.parseWikiLink(pageName);
          String contributionsLink = "Special:Contributions?contributor="
              + Utilities.encodeAndEscapeTopicName(wikiLink.getArticle());
          links.put(contributionsLink, new WikiMessage(
              "tab.common.contributions"));
        }
        String linkToLink = "Special:LinkTo?topic="
            + Utilities.encodeAndEscapeTopicName(pageName);
View Full Code Here

  private void loadEdit(HttpServletRequest request, ModelAndView next,
      WikiPageInfo pageInfo, String contents, String virtualWiki,
      String topicName, boolean useSection) throws Exception {
    pageInfo.setPageTitle(new WikiMessage("edit.title", topicName));
    pageInfo.setTopicName(topicName);
    WikiLink wikiLink = LinkUtil.parseWikiLink(topicName);
    String namespace = wikiLink.getNamespace();
    if (namespace != null
        && namespace.equals(NamespaceHandler.NAMESPACE_CATEGORY)) {
      ServletUtil.loadCategoryContent(next, virtualWiki, topicName);
    }
    if (request.getParameter("editComment") != null) {
View Full Code Here

   *         the main namespace.
   * @see #getPagename
   * @see #getTopicName
   */
  public String getNamespace() {
    WikiLink wikiLink = LinkUtil.parseWikiLink(this.getTopicName());
    return wikiLink.getNamespace();
  }
View Full Code Here

TOP

Related Classes of org.jamwiki.utils.WikiLink

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.