Package org.wikipediacleaner.api.data

Examples of org.wikipediacleaner.api.data.PageElementTag$Parameter


      // Check if inside a specific tag
      if (shouldCheck) {
        for (String tagName : exceptTags) {
          if (shouldCheck) {
            PageElementTag tag = analysis.getSurroundingTag(tagName, currentIndex);
            if (tag != null) {
              nextIndex = tag.getCompleteEndIndex();
              shouldCheck  = false;
            }
          }
        }
      }
View Full Code Here


    String contents = analysis.getContents();
    for (PageElementExternalLink link : links) {
      String text = link.getText();
      if ((text == null) || (text.trim().length() == 0)) {
        boolean hasError = false;
        PageElementTag refTag = analysis.getSurroundingTag(
            PageElementTag.TAG_WIKI_REF, link.getBeginIndex());
        if (link.hasSquare()) {
          hasError = true;
        } else {
          PageElementTemplate template = analysis.isInTemplate(link.getBeginIndex());
          if (template == null) {
            if (refTag != null) {
              hasError = true;
            }
          }
        }
        if (hasError) {
          if (errors == null) {
            return true;
          }
          result = true;
          String url = link.getLink();
          int endIndex = link.getEndIndex();
          String suffix =  "";
          if ((refTag != null) &&
              (refTag.getMatchingTag() != null) &&
              (refTag.getMatchingTag().getBeginIndex() > endIndex)) {
            while ((endIndex < refTag.getMatchingTag().getBeginIndex()) &&
                   (contents.charAt(endIndex) != '[') &&
                   (contents.charAt(endIndex) != ']')) {
              endIndex++;
            }
            if (endIndex > link.getEndIndex()) {
View Full Code Here

      for (Entry<String, List<PageElementTag>> entryValue : entryGroup.getValue().entrySet()) {
        List<PageElementTag> listTags = entryValue.getValue();
        if (listTags.size() > 1) {

          // Find main reference tag
          PageElementTag mainTag = PageElementTag.getMainRef(
              listTags, completeReferencesTags, analysis);
          if (mainTag != null) {

            // Create an error for each tag, except for the main tag
            String selectedName = mainTag.getParameter("name").getTrimmedValue();
            for (PageElementTag tag : listTags) {
              if (tag == mainTag) {
                CheckErrorResult errorResult = createCheckErrorResult(
                    analysis,
                    tag.getCompleteBeginIndex(), tag.getCompleteEndIndex(),
View Full Code Here

        // Check if a name already exists
        String replacement = null;
        List<String> possibleNames = refNamesByGroupAndValue.get(groupName).get(valueRef);
        if ((possibleNames != null) && (possibleNames.size() > 0)) {
          String selectedName = possibleNames.get(0);
          PageElementTag mainRef = PageElementTag.getMainRef(
              valueRefs, completeReferencesTags, analysis);
          if (mainRef != refTag) {
            String tmp = getClosedRefTag(groupName, selectedName, null);
            String message =
                GT._("A <ref> tag shares the same content, and is named \"{0}\".", selectedName) + "\n" +
View Full Code Here

      } else if (element instanceof PageElementLanguageLink) {
        style = doc.getStyle(ConfigurationValueStyle.LANGUAGE_LINK.getName());
      } else if (element instanceof PageElementParameter) {
        style = doc.getStyle(ConfigurationValueStyle.PROGRAMMING.getName());
      } else if (element instanceof PageElementTag) {
        PageElementTag tag = (PageElementTag) element;
        String name = tag.getNormalizedName();
        if (PageElementTag.TAG_WIKI_REF.equals(name) ||
            PageElementTag.TAG_WIKI_REFERENCES.equals(name)) {
          style = doc.getStyle(ConfigurationValueStyle.REFERENCE.getName());
          if (style != null) {
            endIndex = tag.getCompleteEndIndex();
          }
        }
        if (style == null) {
          style = doc.getStyle(ConfigurationValueStyle.TAG.getName());
        }
View Full Code Here

      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

    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

          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

    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

    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

TOP

Related Classes of org.wikipediacleaner.api.data.PageElementTag$Parameter

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.