Package org.jamwiki.utils

Examples of org.jamwiki.utils.WikiLink


   * viewed (without the namespace).
   *
   * @return Name of the page.
   */
  public String getPagename() {
    WikiLink wikiLink = LinkUtil.parseWikiLink(this.getTopicName());
    return wikiLink.getArticle();
  }
View Full Code Here


   *
   * @return <code>true</code> if the page currently being viewed is a user
   *         page, otherwise <code>false</code>.
   */
  public boolean isUserPage() {
    WikiLink wikiLink = LinkUtil.parseWikiLink(this.getTopicName());
    if (wikiLink.getNamespace().equals(NamespaceHandler.NAMESPACE_USER)) {
      return true;
    }
    if (wikiLink.getNamespace()
        .equals(NamespaceHandler.NAMESPACE_USER_COMMENTS)) {
      return true;
    }
    return false;
  }
View Full Code Here

    // Topic cacheTopic = (Topic)cacheElement.getObjectValue();
    // return (cacheTopic == null || (!deleteOK && cacheTopic.getDeleteDate() !=
    // null)) ? null : new Topic(cacheTopic);
    // }
    // }
    WikiLink wikiLink = LinkUtil.parseWikiLink(topicName);
    String namespace = wikiLink.getNamespace();
    boolean caseSensitive = true;
    if (namespace != null) {
      if (namespace.equals(NamespaceHandler.NAMESPACE_SPECIAL)) {
        // invalid namespace
        return null;
View Full Code Here

     * (name.equals(MAGIC_PAGES_IN_NAMESPACE)) { } if
     * (name.equals(MAGIC_PAGES_IN_NAMESPACE_NS)) { } if
     * (name.equals(MAGIC_PAGES_IN_NAMESPACE_NS_R)) { }
     */
    // page values
    WikiLink wikiLink = LinkUtil.parseWikiLink(parserInput.getTopicName());
    if (name.equals(MAGIC_FULL_PAGE_NAME)) {
      return parserInput.getTopicName();
    }
    if (name.equals(MAGIC_FULL_PAGE_NAME_E)) {
      return Utilities.encodeAndEscapeTopicName(parserInput.getTopicName());
    }
    if (name.equals(MAGIC_PAGE_NAME)) {
      return wikiLink.getArticle();
    }
    if (name.equals(MAGIC_PAGE_NAME_E)) {
      return Utilities.encodeAndEscapeTopicName(wikiLink.getArticle());
    }
    if (name.equals(MAGIC_SUB_PAGE_NAME)) {
      String topic = wikiLink.getArticle();
      int pos = topic.lastIndexOf('/');
      if (pos != -1 && pos < topic.length()) {
        topic = topic.substring(pos + 1);
      }
      return topic;
    }
    if (name.equals(MAGIC_SUB_PAGE_NAME_E)) {
      String topic = wikiLink.getArticle();
      int pos = topic.lastIndexOf('/');
      if (pos != -1 && pos < topic.length()) {
        topic = topic.substring(pos + 1);
      }
      return Utilities.encodeAndEscapeTopicName(topic);
    }
    if (name.equals(MAGIC_BASE_PAGE_NAME)) {
      String topic = wikiLink.getArticle();
      int pos = topic.lastIndexOf('/');
      if (pos != -1 && pos < topic.length()) {
        topic = topic.substring(0, pos);
      }
      return topic;
    }
    if (name.equals(MAGIC_BASE_PAGE_NAME_E)) {
      String topic = wikiLink.getArticle();
      int pos = topic.lastIndexOf('/');
      if (pos != -1 && pos < topic.length()) {
        topic = topic.substring(0, pos);
      }
      return Utilities.encodeAndEscapeTopicName(topic);
    }
    if (name.equals(MAGIC_NAMESPACE)) {
      return wikiLink.getNamespace();
    }
    if (name.equals(MAGIC_NAMESPACE_E)) {
      return Utilities.encodeAndEscapeTopicName(wikiLink.getNamespace());
    }
    if (name.equals(MAGIC_TALK_SPACE)) {
      String namespace = wikiLink.getNamespace();
      return NamespaceHandler.getCommentsNamespace(namespace);
    }
    if (name.equals(MAGIC_TALK_SPACE_E)) {
      String namespace = wikiLink.getNamespace();
      return Utilities.encodeAndEscapeTopicName(NamespaceHandler
          .getCommentsNamespace(namespace));
    }
    if (name.equals(MAGIC_SUBJECT_SPACE) || name.equals(MAGIC_ARTICLE_SPACE)) {
      String namespace = wikiLink.getNamespace();
      return NamespaceHandler.getMainNamespace(namespace);
    }
    if (name.equals(MAGIC_SUBJECT_SPACE_E)
        || name.equals(MAGIC_ARTICLE_SPACE_E)) {
      String namespace = wikiLink.getNamespace();
      return Utilities.encodeAndEscapeTopicName(NamespaceHandler
          .getMainNamespace(namespace));
    }

    // if (name.equals(MAGIC_TALK_PAGE_NAME)) {
View Full Code Here

   * @return The parsed content.
   * @throws ParserException Thrown if any error occurs during parsing.
   */
  protected String parseRedirect(ParserOutput parserOutput, String raw) throws ParserException {
    String redirect = this.isRedirect(parserInput, raw, JFlexParser.MODE_LAYOUT);
    WikiLink wikiLink = JFlexParserUtil.parseWikiLink("[[" + redirect + "]]");
    String style = "redirect";
    String virtualWiki = this.parserInput.getVirtualWiki();
    try {
      // see if the redirect link starts with a virtual wiki
      if (wikiLink.getColon() && !StringUtils.isBlank(wikiLink.getNamespace())) {
        if (WikiBase.getDataHandler().lookupVirtualWiki(wikiLink.getNamespace()) != null) {
          virtualWiki = wikiLink.getNamespace();
          wikiLink.setDestination(wikiLink.getDestination().substring(virtualWiki.length() + NamespaceHandler.NAMESPACE_SEPARATOR.length()));
        }
      }
      if (!LinkUtil.isExistingArticle(virtualWiki, wikiLink.getDestination())) {
        style = "edit redirect";
      }
      return LinkUtil.buildInternalLinkHtml(this.parserInput.getContext(), virtualWiki, wikiLink, null, style, null, false);
    } catch (DataAccessException e) {
      throw new ParserException(e);
View Full Code Here

   *
   */
  private String buildInternalLinkUrl(ParserInput parserInput, int mode, String raw) {
    String context = parserInput.getContext();
    String virtualWiki = parserInput.getVirtualWiki();
    WikiLink wikiLink = JFlexParserUtil.parseWikiLink(raw);
    if (wikiLink == null) {
      // invalid link
      return raw;
    }
    if (StringUtils.isBlank(wikiLink.getDestination()) && StringUtils.isBlank(wikiLink.getSection())) {
      // invalid topic
      return raw;
    }
    try {
      if (!wikiLink.getColon() && !StringUtils.isBlank(wikiLink.getNamespace()) && wikiLink.getNamespace().equals(NamespaceHandler.NAMESPACE_IMAGE)) {
        // parse as an image
        return this.parseImageLink(parserInput, mode, wikiLink);
      }
      if (!StringUtils.isBlank(wikiLink.getNamespace()) && InterWikiHandler.isInterWiki(wikiLink.getNamespace())) {
        // inter-wiki link
        return LinkUtil.interWiki(wikiLink);
      }
      if (wikiLink.getColon() && !StringUtils.isBlank(wikiLink.getNamespace())) {
        if (WikiBase.getDataHandler().lookupVirtualWiki(wikiLink.getNamespace()) != null) {
          virtualWiki = wikiLink.getNamespace();
          wikiLink.setDestination(wikiLink.getDestination().substring(virtualWiki.length() + NamespaceHandler.NAMESPACE_SEPARATOR.length()));
        }
      }
      if (StringUtils.isBlank(wikiLink.getText()) && !StringUtils.isBlank(wikiLink.getDestination())) {
        wikiLink.setText(wikiLink.getDestination());
        if (!StringUtils.isBlank(wikiLink.getSection())) {
          wikiLink.setText(wikiLink.getText() + "#" + Utilities.decodeAndEscapeTopicName(wikiLink.getSection(), true));
        }
      } else if (StringUtils.isBlank(wikiLink.getText()) && !StringUtils.isBlank(wikiLink.getSection())) {
        wikiLink.setText(Utilities.decodeAndEscapeTopicName("#" + wikiLink.getSection(), true));
      } else {
        wikiLink.setText(JFlexParserUtil.parseFragment(parserInput, wikiLink.getText(), mode));
      }
      if (StringUtils.equals(wikiLink.getDestination(), parserInput.getTopicName())) {
        // same page, bold the text and return
        return "<b>" + (StringUtils.isBlank(wikiLink.getText()) ? wikiLink.getDestination() : wikiLink.getText()) + "</b>";
      }
      // do not escape text html - already done by parser
      return LinkUtil.buildInternalLinkHtml(context, virtualWiki, wikiLink, wikiLink.getText(), null, null, false);
    } catch (DataAccessException e) {
      logger.severe("Failure while parsing link " + raw, e);
      return "";
    } catch (ParserException e) {
      logger.severe("Failure while parsing link " + raw, e);
View Full Code Here

  /**
   *
   */
  private String processLinkContent(ParserInput parserInput, ParserOutput parserOutput, int mode, String raw) {
    WikiLink wikiLink = JFlexParserUtil.parseWikiLink(raw);
    if (StringUtils.isBlank(wikiLink.getDestination()) && StringUtils.isBlank(wikiLink.getSection())) {
      // no destination or section
      return raw;
    }
    return this.buildInternalLinkUrl(parserInput, mode, raw);
  }
View Full Code Here

  /**
   *
   */
  private String processLinkMetadata(ParserInput parserInput, ParserOutput parserOutput, int mode, String raw) throws ParserException {
    WikiLink wikiLink = JFlexParserUtil.parseWikiLink(raw);
    if (StringUtils.isBlank(wikiLink.getDestination()) && StringUtils.isBlank(wikiLink.getSection())) {
      return raw;
    }
    String result = raw;
    if (!wikiLink.getColon() && StringUtils.equals(wikiLink.getNamespace(), NamespaceHandler.NAMESPACE_CATEGORY)) {
      String sortKey = wikiLink.getText();
      if (!StringUtils.isBlank(sortKey)) {
        sortKey = JFlexParserUtil.parseFragment(parserInput, sortKey, JFlexParser.MODE_PREPROCESS);
      }
      parserOutput.addCategory(wikiLink.getDestination(), sortKey);
      if (mode > JFlexParser.MODE_MINIMAL) {
        // keep the category around in minimal parsing mode, otherwise suppress it from the output
        result = "";
      }
    }
    if (!StringUtils.isBlank(wikiLink.getDestination())) {
      parserOutput.addLink(wikiLink.getDestination());
    }
    return result;
  }
View Full Code Here

  @Override
  public void appendInternalLink(String topic, String hashSection,
      String topicDescription, String cssClass, boolean parseRecursive) {
    try {
      WikiLink wikiLink;
      if (hashSection != null) {
        wikiLink = LinkUtil.parseWikiLink(topic + "#" + hashSection);
      } else {
        wikiLink = LinkUtil.parseWikiLink(topic);
      }
      String destination = wikiLink.getDestination();
      String virtualWiki = fParserInput.getVirtualWiki();
      String section = wikiLink.getSection();
      String query = wikiLink.getQuery();
      String href = LinkUtil.buildTopicUrlNoEdit(fContextPath, virtualWiki,
          destination, section, query);
      // buildTopicUrlNoEdit(fContextPath, virtualWiki, destination,
      // section, query);
      String style = "";
View Full Code Here

  @Override
  public void appendInterWikiLink(String namespace, String title,
      String topicDescription) {
    String hrefLink = getInterwikiMap().get(namespace.toLowerCase());
    if (hrefLink != null) {
      WikiLink wikiLink = LinkUtil.parseWikiLink(namespace
          + NamespaceHandler.NAMESPACE_SEPARATOR + title + "|"
          + topicDescription);
      String destination = wikiLink.getDestination();
      destination = destination.substring(wikiLink.getNamespace().length()
          + NamespaceHandler.NAMESPACE_SEPARATOR.length());
      hrefLink = hrefLink.replace("${title}", Utilities
          .encodeAndEscapeTopicName(title));
      TagNode aTagNode = new TagNode("a");
      aTagNode.addAttribute("href", hrefLink, true);
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.