Examples of WikiLink


Examples of dmir.wikipedia.WikiLink

            //ignore links to special pages
            if (anchorTarget.length() > 0
                && !specialPattern.matcher(anchorTarget).matches()){

                WikiLink wl = new WikiLink();
                wl.setAnchorTarget( anchorTarget );
                links.add(wl);
            }
           
        } else if (disambPattern.matcher(rawText).find()) {
           
            isDisambig = true;
           
            matcher = linkPattern.matcher(rawText);
            while(matcher.find()) {

                String anchorTarget = matcher.group(2).trim().replace(' ', '_');
               
                //ignore links to special pages
                if (anchorTarget.length() == 0
                    || specialPattern.matcher(anchorTarget).matches()) continue;

                WikiLink wl = new WikiLink();
                wl.setAnchorTarget( anchorTarget );
                links.add(wl);
            }
        } else {
            //get infobox content
            this.infobox = getInfobox(rawText);
           
           
            //remove templates
            StringBuilder step0 = removeTemplates(rawText);
           
            //remove image and file links
            StringBuilder step05 = removeMediaLinks(step0);
           
            //remove html comments
            StringBuffer step1 = new StringBuffer();
            matcher = commentsPattern.matcher(step05);
            while(matcher.find()) {
                matcher.appendReplacement(step1, "");
            }
            matcher.appendTail(step1);
           
            //remove misc elements (eg, quotes)
            StringBuffer step2 = new StringBuffer();
            matcher = otherMarkupPattern.matcher(step1);
            while(matcher.find()) {
                matcher.appendReplacement(step2, "");
            }
            matcher.appendTail(step2);
           
            //replace html tags by whitespace
            StringBuffer step3 = new StringBuffer();
            matcher = tagsPattern.matcher(step2);
            while(matcher.find()) {
                matcher.appendReplacement(step3, " ");
            }
            matcher.appendTail(step3);
           
            //clean the text
            StringBuffer step35 = new StringBuffer();
            matcher = cleanPattern.matcher(step3);
            while(matcher.find()) {
                matcher.appendReplacement(step35, "");
            }
            matcher.appendTail(step35);
           
            // normalize whites
            StringBuffer step4 = new StringBuffer();
            matcher = whitesPattern.matcher(step35);
            while(matcher.find()) {
                matcher.appendReplacement(step4, " ");
            }
            matcher.appendTail(step4);

            //replace urls with a token
            StringBuffer step5 = new StringBuffer();
            matcher = urlPattern.matcher(step4);
            while(matcher.find()) {
                matcher.appendReplacement(step5, "URLTOKEN");
            }
            matcher.appendTail(step5);
           
            // Extract and Clean Links / Categories
            this.cleanText = new StringBuilder(step5);
            matcher = linkPattern.matcher(step5);
            int offset = 0;
            while(matcher.find()) {
                String anchorTarget = matcher.group(2).trim();
                if (anchorTarget.length() == 0) continue;
               
                String anchorText = matcher.group(4);
                if (anchorText == null) {
                    anchorText = anchorTarget;
                } else {
                    Matcher whitesMatcher = whitesPattern.matcher(anchorText);
                    StringBuffer sb = new StringBuffer();
                    while(whitesMatcher.find()) {
                        whitesMatcher.appendReplacement(sb, " ");
                    }
                    whitesMatcher.appendTail(sb);
                    anchorText = sb.toString().trim();
                }
               
                Matcher specialMatcher = null;
                if ((specialMatcher = categoryPattern.matcher(anchorTarget)).matches()) {
                    anchorText = specialMatcher.group(1);
                    categories.add(anchorText);
                } else if ((specialMatcher = specialPattern.matcher(anchorTarget)).matches()) {
                    anchorText = "";
                } else {
                    WikiLink wl = new WikiLink();
                    wl.setStart( matcher.start() - offset );
                    wl.setLength( anchorText.length() );
                    wl.setAnchorTarget( anchorTarget );
                    wl.setAnchorText( anchorText );

                    links.add(wl);
                }
               
                cleanText.delete(matcher.start() - offset, matcher.end() - offset);
View Full Code Here

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

Examples of org.jamwiki.utils.WikiLink

      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

Examples of org.jamwiki.utils.WikiLink

      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

Examples of org.jamwiki.utils.WikiLink

      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

Examples of org.jamwiki.utils.WikiLink

  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

Examples of org.jamwiki.utils.WikiLink

    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

Examples of org.jamwiki.utils.WikiLink

    }
    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

Examples of org.jamwiki.utils.WikiLink

        // 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

Examples of org.jamwiki.utils.WikiLink

  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
TOP
Copyright © 2018 www.massapi.com. 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.