Examples of PageElementInternalLink


Examples of org.wikipediacleaner.api.data.PageElementInternalLink

        // Full tag <nowiki/>
        int beginIndex = tag.getBeginIndex();
        int endIndex = tag.getEndIndex();

        // Check for <nowiki/> just after an internal link
        PageElementInternalLink link = analysis.isInInternalLink(beginIndex - 1);
        if ((link != null) && (link.getEndIndex() == beginIndex)) {
          beginIndex = link.getBeginIndex();
          while ((endIndex < contents.length()) &&
                 (Character.isLetter(contents.charAt(endIndex)))) {
            endIndex++;
          }
        } else {
          // Check for <nowiki/> inside an internal link
          link = analysis.isInInternalLink(beginIndex);
          if (link != null) {
            int index = beginIndex;
            while ((index > link.getBeginIndex() + link.getTextOffset()) &&
                   (contents.charAt(index - 1) == ' ')) {
              index--;
            }
            if (index == link.getBeginIndex() + link.getTextOffset()) {
              index = endIndex;
              while ((index + 2 < link.getEndIndex()) &&
                     (contents.charAt(index) == ' ')) {
                index++;
              }
              if (index + 2 == link.getEndIndex()) {
                errorResult = createCheckErrorResult(
                    analysis, link.getBeginIndex(), link.getEndIndex());
                errorResult.addReplacement("");
              }
            }
          }
        }
        if (errorResult == null) {
          String textBefore = contents.substring(beginIndex, tag.getBeginIndex());
          String textAfter = contents.substring(tag.getEndIndex(), endIndex);
          errorResult = createCheckErrorResult(
              analysis, beginIndex, endIndex);
          if (link != null) {
            String displayed = link.getDisplayedTextNotTrimmed();
            if (displayed.endsWith(" ")) {
              errorResult.addReplacement(PageElementInternalLink.createInternalLink(
                  link.getFullLink(), displayed.trim()) + " " + textAfter);
            }
            errorResult.addReplacement(PageElementInternalLink.createInternalLink(
                link.getFullLink(), displayed + textAfter));
          }
          errorResult.addReplacement(textBefore + " " + textAfter);
          errorResult.addReplacement(textBefore + textAfter);
        }
      } else if (tag.isComplete()) {
View Full Code Here

Examples of org.wikipediacleaner.api.data.PageElementInternalLink

        int tmpIndex = currentIndex + aliasFound.length();
        while ((tmpIndex < contents.length()) && (contents.charAt(tmpIndex) == ' ')) {
          tmpIndex++;
        }
        if ((tmpIndex < contents.length()) && (contents.charAt(tmpIndex) == '[')) {
          PageElementInternalLink link = analysis.isInInternalLink(tmpIndex);
          if ((link != null) && (link.getBeginIndex() == tmpIndex)) {
            linkFound = true;
          }
        }
      }
View Full Code Here

Examples of org.wikipediacleaner.api.data.PageElementInternalLink

    String contents = analysis.getContents();
    for (PageElementExternalLink link : links) {
      if ((link.hasSquare()) &&
          (link.getText() != null) &&
          (!link.hasSecondSquare())) {
        PageElementInternalLink internalLink = analysis.isInInternalLink(link.getEndIndex());
        if ((internalLink != null) &&
            (internalLink.getBeginIndex() == link.getEndIndex())) {
          if (errors == null) {
            return true;
          }
          result = true;
          CheckErrorResult errorResult = createCheckErrorResult(
              analysis, link.getBeginIndex(), internalLink.getEndIndex());
          errorResult.addReplacement(
              contents.substring(link.getBeginIndex(), internalLink.getBeginIndex()) +
              internalLink.getDisplayedTextNotTrimmed());
          errors.add(errorResult);
        }
      }
    }
View Full Code Here

Examples of org.wikipediacleaner.api.data.PageElementInternalLink

    int currentIndex = contents.indexOf("[[");
    boolean result = false;
    while (currentIndex >= 0) {
      boolean shouldCount = true;
      if (shouldCount) {
        PageElementInternalLink link = analysis.isInInternalLink(currentIndex);
        if ((link != null) && (link.getBeginIndex() == currentIndex)) {
          shouldCount = false;
        }
      }
      if (shouldCount) {
        PageElementImage image = analysis.isInImage(currentIndex);
        if ((image != null) && (image.getBeginIndex() == currentIndex)) {
          shouldCount = false;
        }
      }
      if (shouldCount) {
        PageElementCategory category = analysis.isInCategory(currentIndex);
        if ((category != null) && (category.getBeginIndex() == currentIndex)) {
          shouldCount = false;
        }
      }
      if (shouldCount) {
        PageElementLanguageLink link = analysis.isInLanguageLink(currentIndex);
        if ((link != null) && (link.getBeginIndex() == currentIndex)) {
          shouldCount = false;
        }
      }
      if (shouldCount) {
        PageElementInterwikiLink link = analysis.isInInterwikiLink(currentIndex);
        if ((link != null) && (link.getBeginIndex() == currentIndex)) {
          shouldCount = false;
        }
      }
      if (shouldCount) {
        PageElementExternalLink link = analysis.isInExternalLink(currentIndex + 1);
        if ((link != null) && (link.getBeginIndex() == currentIndex + 1)) {
          shouldCount = false;
        }
      }
      if (shouldCount) {
        if ((analysis.isInComment(currentIndex) != null) ||
            (analysis.getSurroundingTag(PageElementTag.TAG_WIKI_NOWIKI, currentIndex) != null) ||
            (analysis.getSurroundingTag(PageElementTag.TAG_WIKI_MATH, currentIndex) != null) ||
            (analysis.getSurroundingTag(PageElementTag.TAG_WIKI_SCORE, currentIndex) != null) ||
            (analysis.getSurroundingTag(PageElementTag.TAG_WIKI_SOURCE, currentIndex) != null) ||
            (analysis.getSurroundingTag(PageElementTag.TAG_WIKI_SYNTAXHIGHLIGHT, currentIndex) != null) ||
            (analysis.isInTag(currentIndex) != null)) {
          shouldCount = false;
        }
      }
      if (shouldCount) {
        PageElementTemplate template = analysis.isInTemplate(currentIndex + 2);
        if ((template != null) && (contents.startsWith("]]", template.getEndIndex()))) {
          shouldCount = false;
        }
      }
      if (shouldCount) {
        if (errors == null) {
          return true;
        }
        result = true;
       
        // Check if there is a potential end
        int tmpIndex = currentIndex + 2;
        boolean errorReported = false;
        boolean finished = false;
        while (!finished && (tmpIndex < maxLength)) {
          char tmpChar = contents.charAt(tmpIndex);
          if (REJECTED_CHARS.indexOf(tmpChar) >= 0) {
            finished = true;
          } else if (tmpChar == ']') {
            int tmpIndex2 = tmpIndex + 1;
            while ((tmpIndex2 < maxLength) &&
                   (contents.charAt(tmpIndex2) != ']') &&
                   (REJECTED_CHARS.indexOf(contents.charAt(tmpIndex2)) < 0)) {
              tmpIndex2++;
            }
            String suffix = "";
            if ((tmpIndex2 < maxLength) && (contents.charAt(tmpIndex2) == ']')) {
              suffix = contents.substring(tmpIndex + 1, tmpIndex2 + 1);
            } else {
              tmpIndex2 = tmpIndex;
            }
            CheckErrorResult errorResult = createCheckErrorResult(
                analysis, currentIndex, tmpIndex2 + 1);

            // Check if the situation is something like [[http://....] (replacement: [http://....])
            boolean protocolFound = PageElementExternalLink.isPossibleProtocol(contents, currentIndex + 2);
            if (protocolFound) {
              errorResult.addReplacement(contents.substring(currentIndex + 1, tmpIndex2 + 1));
            }

            errorResult.addReplacement(contents.substring(currentIndex, tmpIndex + 1) + "]" + suffix);
            if (suffix.length() > 0) {
              errorResult.addReplacement(contents.substring(currentIndex, tmpIndex) + suffix + "]");
            }
            errors.add(errorResult);
            errorReported = true;
            finished = true;
          } else if (tmpChar == '}') {
            int lastChar = tmpIndex;
            if ((lastChar + 1 < maxLength) && (contents.charAt(lastChar + 1) == '}')) {
              lastChar++;
            }
            CheckErrorResult errorResult = createCheckErrorResult(
                analysis, currentIndex, lastChar + 1);
            errorResult.addReplacement(contents.substring(currentIndex, tmpIndex) + "]]");
            errorResult.addReplacement("{{" + contents.substring(currentIndex + 2, tmpIndex) + "}}");
            errors.add(errorResult);
            errorReported = true;
            finished = true;
          }
          tmpIndex++;
        }

        // Default
        if (!errorReported) {
          CheckErrorResult errorResult = createCheckErrorResult(
              analysis, currentIndex, currentIndex + 2);
          errorResult.addReplacement("", GT._("Delete"));
          errors.add(errorResult);
        }
      }
      currentIndex = contents.indexOf("[[", currentIndex + 2);
    }

    // Analyze each internal link to see if it contains a [
    for (PageElementInternalLink link : analysis.getInternalLinks()) {
      String text = link.getText();
      if (text != null) {
        text = cleanText(text);
        if (text != null) {
          if (errors == null) {
            return true;
          }
          result = true;
          CheckErrorResult errorResult = createCheckErrorResult(
              analysis, link.getBeginIndex(), link.getEndIndex());
          errorResult.addReplacement(PageElementInternalLink.createInternalLink(
              link.getLink(), link.getAnchor(), text));
          errors.add(errorResult);
        }
      }
    }

    // Analyze each image to see if it contains a [
    for (PageElementImage image : analysis.getImages()) {
      String text = image.getDescription();
      String modifiedText = cleanText(text);
      String alt = image.getAlternateDescription();
      String modifiedAlt = cleanText(alt);
      if ((modifiedText != null) || (modifiedAlt != null)) {
        if (errors == null) {
          return true;
        }
        result = true;
        CheckErrorResult errorResult = createCheckErrorResult(
            analysis, image.getBeginIndex(), image.getEndIndex());
        errorResult.addReplacement(image.getDescriptionReplacement(
            (modifiedText != null) ? modifiedText : text,
            (modifiedAlt != null) ? modifiedAlt : alt));
        errors.add(errorResult);
      }
    }

    // Analyze each external link to see if it has a [ before
    for (PageElementExternalLink link : analysis.getExternalLinks()) {
      int begin = link.getBeginIndex();
      if (link.hasSquare()) {
        if ((begin > 0) && (contents.charAt(begin - 1) == '[')) {
          int end = link.getEndIndex();
          if ((end >= contents.length()) || (contents.charAt(end) != ']')) {
            if (errors == null) {
              return true;
            }
            result = true;
View Full Code Here

Examples of org.wikipediacleaner.api.data.PageElementInternalLink

      return null;
    }

    // Menu for internal link
    if (element instanceof PageElementInternalLink) {
      PageElementInternalLink internalLink = (PageElementInternalLink) element;
      return createDefaultPopupInternalLink(textPane, position, pageAnalysis, internalLink);
    }

    // Menu for image
    if (element instanceof PageElementImage) {
View Full Code Here

Examples of org.wikipediacleaner.api.data.PageElementInternalLink

    int currentIndex = contents.indexOf("]]");
    boolean result = false;
    while (currentIndex > 0) {
      boolean shouldCount = true;
      if (shouldCount) {
        PageElementInternalLink link = analysis.isInInternalLink(currentIndex);
        if ((link != null) &&
            ((link.getEndIndex() == currentIndex + 2) ||
             (link.getEndIndex() == currentIndex + 3))) {
          shouldCount = false;
        }
      }
      if (shouldCount) {
        PageElementImage image = analysis.isInImage(currentIndex);
        if ((image != null) && (image.getEndIndex() == currentIndex + 2)) {
          shouldCount = false;
        }
      }
      if (shouldCount) {
        PageElementCategory category = analysis.isInCategory(currentIndex);
        if ((category != null) && (category.getEndIndex() == currentIndex + 2)) {
          shouldCount = false;
        }
      }
      if (shouldCount) {
        PageElementLanguageLink link = analysis.isInLanguageLink(currentIndex);
        if ((link != null) && (link.getEndIndex() == currentIndex + 2)) {
          shouldCount = false;
        }
      }
      if (shouldCount) {
        PageElementInterwikiLink link = analysis.isInInterwikiLink(currentIndex);
        if ((link != null) && (link.getEndIndex() == currentIndex + 2)) {
          shouldCount = false;
        }
      }
      if (shouldCount &&
          (analysis.isInComment(currentIndex) != null) ||
          (analysis.getSurroundingTag(PageElementTag.TAG_WIKI_NOWIKI, currentIndex) != null) ||
          (analysis.getSurroundingTag(PageElementTag.TAG_WIKI_MATH, currentIndex) != null) ||
          (analysis.getSurroundingTag(PageElementTag.TAG_WIKI_SCORE, currentIndex) != null) ||
          (analysis.getSurroundingTag(PageElementTag.TAG_WIKI_SOURCE, currentIndex) != null) ||
          (analysis.getSurroundingTag(PageElementTag.TAG_WIKI_SYNTAXHIGHLIGHT, currentIndex) != null) ||
          (analysis.isInTag(currentIndex) != null)) {
        shouldCount = false;
      }
      if (shouldCount) {
        PageElementTemplate template = analysis.isInTemplate(currentIndex - 1);
        if ((template != null) &&
            (template.getEndIndex() == currentIndex) &&
            (contents.startsWith("[[", template.getBeginIndex() - 2))) {
          shouldCount = false;
        }
      }
      if (shouldCount) {
        PageElementExternalLink link = analysis.isInExternalLink(currentIndex);
        if ((link != null) &&
            (link.getEndIndex() == currentIndex + 1)) {
          if ((link.getBeginIndex() == 0) ||
              (contents.charAt(link.getBeginIndex() - 1) != '[')) {
            if (errors == null) {
              return true;
            }
            result = true;
            CheckErrorResult errorResult = createCheckErrorResult(
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.