Examples of PageElementTag


Examples of org.wikipediacleaner.api.data.PageElementTag

      return false;
    }
    String contents = analysis.getContents();
    int level = 0;
    boolean result = false;
    PageElementTag level0Tag = null;
    int tagIndex = 0;
    while (tagIndex < tags.size()) {
      PageElementTag tag = tags.get(tagIndex);
      tagIndex++;

      if (tag.isFullTag()) {
        // Full tag
        if (level > 0) {
          if (errors == null) {
            return true;
          }
          result = true;
          CheckErrorResult errorResult = createCheckErrorResult(
              analysis,
              tag.getBeginIndex(), tag.getEndIndex());
          errorResult.addReplacement("");
          errors.add(errorResult);
        }
      } else if (tag.isEndTag()) {
        // Closing tag
        level--;
        if (level < 0) {
          level = 0;
          if (errors == null) {
            return true;
          }
          result = true;
          CheckErrorResult errorResult = createCheckErrorResult(
              analysis,
              tag.getBeginIndex(), tag.getEndIndex());
          errorResult.addReplacement("");
          errors.add(errorResult);
        }
      } else {
        if (level == 0) {
          level0Tag = tag;
        } else if (level > 0) {
          if (errors == null) {
            return true;
          }
          result = true;

          // Manage double small tags on the same text
          boolean doubleSmall = false;
          if ((tag.getMatchingTag() != null) &&
              (level0Tag != null) &&
              (level0Tag.getMatchingTag() != null)) {
            if ((level0Tag.getEndIndex() == tag.getBeginIndex()) &&
                (tag.getMatchingTag().getEndIndex() == level0Tag.getMatchingTag().getBeginIndex())) {
              doubleSmall = true;
            }
          }

          if (level0Tag != null) {
            int possibleEnd = getPossibleEnd(analysis, level0Tag);
            if (possibleEnd > 0) {
              CheckErrorResult errorResult = createCheckErrorResult(
                  analysis,
                  level0Tag.getBeginIndex(), possibleEnd,
                  ErrorLevel.WARNING);
              errorResult.addReplacement(
                  contents.substring(level0Tag.getBeginIndex(), possibleEnd) + "</small>",
                  "<small>...</small>");
              errors.add(errorResult);
            } else {
              CheckErrorResult errorResult = createCheckErrorResult(
                  analysis,
                  level0Tag.getBeginIndex(),
                  level0Tag.getEndIndex(),
                  ErrorLevel.CORRECT);
              errors.add(errorResult);
              if (level0Tag.getMatchingTag() != null) {
                errorResult = createCheckErrorResult(
                    analysis,
                    level0Tag.getMatchingTag().getBeginIndex(),
                    level0Tag.getMatchingTag().getEndIndex(),
                    ErrorLevel.CORRECT);
                errors.add(errorResult);
              }
            }
            level0Tag = null;
          }

          int possibleEnd = getPossibleEnd(analysis, tag);
          if (possibleEnd > 0) {
            CheckErrorResult errorResult = createCheckErrorResult(
                analysis, tag.getBeginIndex(), possibleEnd);
            errorResult.addReplacement(
                contents.substring(tag.getBeginIndex(), possibleEnd) + "</small>",
                "<small>...</small>");
            errors.add(errorResult);
          } else {
            CheckErrorResult errorResult = createCheckErrorResult(
                analysis,
                tag.getCompleteBeginIndex(),
                tag.getCompleteEndIndex());
            if (doubleSmall) {
              errorResult.addReplacement(
                  contents.substring(tag.getEndIndex(), tag.getMatchingTag().getBeginIndex()),
                  GT._("Remove <small> tags"));
            }
            if (!tag.isComplete() && !tag.isFullTag() && !tag.isEndTag()) {
              errorResult.addReplacement(
                  PageElementTag.createTag(PageElementTag.TAG_HTML_SMALL, true, false));
            }
            errors.add(errorResult);
            if (tag.isComplete()) {
              tagIndex = PageElementTag.getMatchingTagIndex(tags, tagIndex);
            }
          }
        }
        level++;
View Full Code Here

Examples of org.wikipediacleaner.api.data.PageElementTag

    String contents = analysis.getContents();
    List<PageElementTag> tags = analysis.getCompleteTags(PageElementTag.TAG_WIKI_GALLERY);
    for (PageElementTag tag : tags) {
      removeArea(chunks, tag.getBeginIndex(), tag.getEndIndex());
      if (tag.isComplete() && !tag.isEndTag() && (tag.getMatchingTag() != null)) {
        PageElementTag endTag = tag.getMatchingTag();
        int beginIndex = tag.getEndIndex();
        int tmpIndex = beginIndex;
        while (tmpIndex <= endTag.getBeginIndex()) {
          if ((tmpIndex == endTag.getBeginIndex()) ||
              (contents.charAt(tmpIndex) == '\n')) {
            String line = contents.substring(beginIndex, tmpIndex).trim();
            int colonIndex = line.indexOf(':');
            if ((colonIndex > 0) && (imageNamespace.isPossibleName(line.substring(0, colonIndex)))) {
              int pipeIndex = line.indexOf('|', colonIndex);
              if (pipeIndex < 0) {
                removeArea(chunks, beginIndex, tmpIndex + 1);
              } else {
                removeArea(chunks, beginIndex, beginIndex + pipeIndex + 1);
              }
            } else {
              removeArea(chunks, beginIndex, tmpIndex + 1);
            }
            beginIndex = tmpIndex + 1;
          }
          tmpIndex++;
        }
        removeArea(chunks, endTag.getBeginIndex(), endTag.getEndIndex());
      }
    }
  }
View Full Code Here

Examples of org.wikipediacleaner.api.data.PageElementTag

          while ((currentPos > beginLineIndex) &&
                 (Character.isWhitespace(contents.charAt(currentPos)))) {
            currentPos--;
          }
          if (contents.charAt(currentPos) == '>') {
            PageElementTag tag = analysis.isInTag(currentPos);
            if (tag != null) {
              String name = tag.getNormalizedName();
              if (PageElementTag.TAG_HTML_BR.equals(name)) {
                breakFound = true;
                shouldStop = false;
                beginError = tag.getBeginIndex();
                currentPos = beginError - 1;
              } else if (!breakFound) {
                /*if (PageElementTag.TAG_WIKI_MATH.equals(name)) {
                  tagAfter = true;
                  shouldStop = false;
View Full Code Here

Examples of org.wikipediacleaner.api.data.PageElementTag

    List<PageElementTag> galleryTags = analysis.getCompleteTags(PageElementTag.TAG_WIKI_GALLERY);
    String contents = analysis.getContents();
    boolean result = false;
    for (PageElementTag galleryTag : galleryTags) {
      if (galleryTag.getMatchingTag() != null) {
        PageElementTag endTag = galleryTag.getMatchingTag();
        int beginIndex = galleryTag.getEndIndex();
        int tmpIndex = beginIndex;
        while (tmpIndex <= endTag.getBeginIndex()) {
          if ((tmpIndex == endTag.getBeginIndex()) ||
              (contents.charAt(tmpIndex) == '\n')) {
            String line = contents.substring(beginIndex, tmpIndex).trim();
            int colonIndex = line.indexOf(':');
            if ((colonIndex > 0) && (imageNamespace.isPossibleName(line.substring(0, colonIndex)))) {
              int pipeIndex = line.indexOf('|', colonIndex);
View Full Code Here

Examples of org.wikipediacleaner.api.data.PageElementTag

    int maxTags = tags.size();
    while (tagIndex < maxTags) {

      // Group tags separated only by punctuation characters
      int firstTagIndex = tagIndex;
      PageElementTag firstTag = tags.get(firstTagIndex);
      int lastTagIndex = PageElementTag.groupTags(tags, firstTagIndex, contents, ",;.\'", separator);
      PageElementTag lastTag = tags.get(lastTagIndex);
      tagIndex = lastTagIndex + 1;

      // Remove possible whitespace characters before first reference
      int tmpIndex = firstTag.getBeginIndex() - 1;
      while ((tmpIndex >= 0) &&
             (Character.isWhitespace(contents.charAt(tmpIndex)))) {
        tmpIndex--;
      }

      // Check if previous character is a punctuation
      boolean punctuationFoundBefore = false;
      boolean punctuationFoundBetween = false;
      char punctuation = ' ';
      for (int currentTagIndex = firstTagIndex; currentTagIndex <= lastTagIndex; currentTagIndex++) {
        PageElementTag currentTag = tags.get(currentTagIndex);
        if ((currentTagIndex == firstTagIndex) ||
            (currentTag.isFullTag()) ||
            (!currentTag.isEndTag())) {
          int testIndex = currentTag.getBeginIndex() - 1;
          while ((testIndex >= 0) && (Character.isWhitespace(contents.charAt(testIndex)))) {
            testIndex--;
          }
          if (testIndex >= 0) {
            char currentPunctuation = contents.charAt(testIndex);
View Full Code Here

Examples of org.wikipediacleaner.api.data.PageElementTag

    String contents = analysis.getContents();
    for (PageElementInternalLink link : links) {
      // Check if it is an error
      boolean errorFound = Page.areSameTitle(pageTitle, link.getFullLink());
      if (errorFound) {
        PageElementTag tagIncludeOnly = analysis.getSurroundingTag(
            PageElementTag.TAG_WIKI_INCLUDEONLY, link.getBeginIndex());
        if (tagIncludeOnly != null) {
          errorFound = false;
        }
      }

      // Report error
      if (errorFound) {
        if (errors == null) {
          return true;
        }
        result = true;
        PageElementTag tagImagemap = analysis.getSurroundingTag(
            PageElementTag.TAG_WIKI_IMAGEMAP, link.getBeginIndex());
        if (tagImagemap != null) {
          int previousCR = getPreviousCR(contents, link.getBeginIndex());
          int nextCR = getNextCR(contents, link.getEndIndex());
          nextCR = Math.min(nextCR, tagImagemap.getMatchingTag().getBeginIndex());
          CheckErrorResult errorResult = createCheckErrorResult(
              analysis, previousCR, nextCR);
          if ((previousCR > tagImagemap.getEndIndex()) &&
              (contents.charAt(nextCR) == '\n')) {
            errorResult.addReplacement("", GT._("Delete"));
          }
          errors.add(errorResult);
        } else {
View Full Code Here

Examples of org.wikipediacleaner.api.data.PageElementTag

    String pageTitle = analysis.getPage().getTitle();
    Collection<PageElementInternalLink> links = analysis.getInternalLinks();
    int currentIndex = 0;
    for (PageElementInternalLink link : links) {
      if (Page.areSameTitle(pageTitle, link.getFullLink())) {
        PageElementTag tagImagemap = analysis.getSurroundingTag(
            PageElementTag.TAG_WIKI_IMAGEMAP, link.getBeginIndex());
        if (tagImagemap != null) {
          int previousCR = getPreviousCR(contents, link.getBeginIndex());
          int nextCR = getNextCR(contents, link.getEndIndex());
          nextCR = Math.min(nextCR, tagImagemap.getMatchingTag().getBeginIndex());
          if ((previousCR > tagImagemap.getEndIndex()) &&
              (contents.charAt(nextCR) == '\n')) {
            if (previousCR > currentIndex) {
              newContents.append(contents.substring(currentIndex, previousCR));
              currentIndex = nextCR;
            }
View Full Code Here

Examples of org.wikipediacleaner.api.data.PageElementTag

        if ((group != null) && (group.getValue() != null)) {
          groupName = group.getValue();
        }
 
        // Check if a <references> tag already exist for this group
        PageElementTag firstTag = firstTags.get(groupName);
        if (firstTag == null) {
          firstTags.put(groupName, referencesTag);
        } else {
          if (errors == null) {
            return true;
          }
          result = true;
          if (!tagUsed.contains(groupName)) {
            tagUsed.add(groupName);
            CheckErrorResult errorResult = createCheckErrorResult(
                analysis,
                firstTag.getCompleteBeginIndex(),
                firstTag.getCompleteEndIndex(),
                ErrorLevel.CORRECT);
            errorResult.addReplacement("");
            errors.add(errorResult);
          }
          CheckErrorResult errorResult = createCheckErrorResult(
View Full Code Here

Examples of org.wikipediacleaner.api.data.PageElementTag

              int tmpIndex = paramValueStartIndex + currentPos;
              PageElementComment comment = analysis.isInComment(tmpIndex);
              if (comment != null) {
                currentPos = comment.getEndIndex() - 1 - paramValueStartIndex;
              } else {
                PageElementTag tag = analysis.isInTag(tmpIndex);
                if ((tag != null) &&
                    (tag.getBeginIndex() == tmpIndex) &&
                    ((PageElementTag.TAG_WIKI_MATH.equals(tag.getNormalizedName())) ||
                     (PageElementTag.TAG_WIKI_NOWIKI.equals(tag.getNormalizedName())) ||
                     (PageElementTag.TAG_WIKI_SOURCE.equals(tag.getNormalizedName())) ||
                     (PageElementTag.TAG_WIKI_SCORE.equals(tag.getNormalizedName())) ||
                     (PageElementTag.TAG_WIKI_SYNTAXHIGHLIGHT.equals(tag.getNormalizedName())))) {
                  currentPos = tag.getCompleteEndIndex() - 1 - paramValueStartIndex;
                }
              }
              break;
            case '[':
              squareBracketsCount++;
View Full Code Here

Examples of org.wikipediacleaner.api.data.PageElementTag

    List<PageElementTag> refTags = analysis.getTags(PageElementTag.TAG_WIKI_REF);
    if ((refTags != null) && (refTags.size() > 0)) {
      Iterator<PageElementTag> itRefTags = refTags.iterator();
      while (!refFound && itRefTags.hasNext()) {
        boolean usefulRef = true;
        PageElementTag refTag = itRefTags.next();
        if (analysis.getSurroundingTag(PageElementTag.TAG_WIKI_NOWIKI, refTag.getBeginIndex()) != null) {
          usefulRef =  false;
        }
        if (usefulRef) {
          refFound = true;
        }
      }
    }
    if (!refFound) {
      return false;
    }

    // Analyzing text for <references> tags
    List<PageElementTag> referencesTags = analysis.getTags(PageElementTag.TAG_WIKI_REFERENCES);
    if (referencesTags != null) {
      for (PageElementTag referencesTag : referencesTags) {
        if (referencesTag.isComplete()) {
          return false;
        }
      }
    }

    // Search for templates like {{References}}
    String templates = getSpecificProperty(
        "templates", true, true, false);
    if (templates == null) {
      templates = getSpecificProperty(
          "references_templates", true, true, false);
    }
    List<String> referencesTemplates = null;
    if (templates != null) {
      referencesTemplates = WPCConfiguration.convertPropertyToStringList(templates);
    }
    if (referencesTemplates != null) {
      List<PageElementTemplate> allTemplates = analysis.getTemplates();
      int templateNum = allTemplates.size();
      while (templateNum > 0) {
        templateNum--;
        PageElementTemplate template = allTemplates.get(templateNum);
        for (String referencesTemplate : referencesTemplates) {
          if (Page.areSameTitle(template.getTemplateName(), referencesTemplate)) {
            return false;
          }
        }
      }
    }

    // Try to make some suggestions
    if (errors == null) {
      return true;
    }
    String contents = analysis.getContents();
    if (referencesTags != null) {
      for (PageElementTag referencesTag : referencesTags) {
        CheckErrorResult errorResult = createCheckErrorResult(
            analysis, referencesTag.getBeginIndex(), referencesTag.getEndIndex());
        if (referencesTags.size() == 1) {
          errorResult.addReplacement(
              PageElementTag.createTag(PageElementTag.TAG_WIKI_REFERENCES, true, true),
              GT._("Close tag"));
        }
        errors.add(errorResult);
        if (referencesTags.size() == 1) {
          int index = referencesTag.getEndIndex();
          boolean ok = true;
          while (ok && (index < contents.length())) {
            char currentChar = contents.charAt(index);
            if (Character.isWhitespace(currentChar)) {
              index++;
            } else if (currentChar == '<') {
              PageElementTag tag = analysis.isInTag(index);
              if ((tag != null) &&
                  (tag.getBeginIndex() == index) &&
                  (PageElementTag.TAG_WIKI_REF.equals(tag.getNormalizedName()))) {
                index = tag.getCompleteEndIndex();
              } else {
                if (contents.startsWith("</references/>", index)) {
                  errorResult = createCheckErrorResult(analysis, index, index + 14);
                  errorResult.addReplacement(PageElementTag.createTag(
                      PageElementTag.TAG_WIKI_REFERENCES, true, false), true);
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.