Examples of PageElementTitle


Examples of org.wikipediacleaner.api.data.PageElementTitle

    }

    // Analyzing titles
    String contents = analysis.getContents();
    for (int i = 0; i < titles.size(); i++) {
      PageElementTitle title = titles.get(i);
      PageElementTitle nextTitle = (i + 1 < titles.size()) ? titles.get(i + 1) : null;
      if ((nextTitle == null) ||
          (nextTitle.getLevel() <= title.getLevel())) {
        boolean textFound = false;
        int lastPos = (nextTitle != null) ? nextTitle.getBeginIndex() : contents.length();
        int pos = title.getEndIndex();
        PageElementComment commentFound = null;
        while (!textFound && (pos < lastPos)) {
          char currentChar = contents.charAt(pos);
          if (Character.isWhitespace(currentChar)) {
            pos++;
          } else if (currentChar == '<') {
            PageElementComment comment = analysis.isInComment(pos);
            if (comment != null) {
              pos = comment.getEndIndex();
              if (commentFound == null) {
                commentFound = comment;
              }
            } else {
              textFound = true;
            }
          } else {
            textFound = true;
          }
        }
        if (!textFound && (title.getFirstLevel() <= maxLevel)) {
          if (errors == null) {
            return true;
          }
          result = true;
          if (commentFound != null) {
            lastPos = commentFound.getBeginIndex();
          }
          CheckErrorResult errorResult = createCheckErrorResult(
              analysis, title.getBeginIndex(), lastPos);
          if (texts != null) {
            for (String text : texts) {
              String replacement =
                  contents.substring(title.getBeginIndex(), title.getEndIndex()) + "\n" +
                  text + "\n\n";
              errorResult.addReplacement(replacement, GT._("Add {0}", text));
            }
          }
          errorResult.addReplacement("", GT._("Delete section"));
          if ((nextTitle != null) && (nextTitle.getLevel() == title.getLevel())) {
            errorResult.addEditTocAction();
          }
          errors.add(errorResult);
        }
      }
View Full Code Here

Examples of org.wikipediacleaner.api.data.PageElementTitle

    // Initialization
    List<PageElementTitle> titles = analysis.getTitles();
    if ((titles == null) || (titles.isEmpty())) {
      return false;
    }
    PageElementTitle firstTitle = titles.get(0);
    List<PageElement> tocs = getToCs(analysis, firstTitle.getEndIndex(), Integer.MAX_VALUE);
    if ((tocs == null) || (tocs.isEmpty())) {
      return false;
    }

    // Check every table of contents
    boolean result = false;
    for (PageElement toc : tocs) {
      if (toc.getBeginIndex() >= firstTitle.getEndIndex()) {
        if (errors == null) {
          return true;
        }
        result = true;
        CheckErrorResult errorResult = createCheckErrorResult(
View Full Code Here

Examples of org.wikipediacleaner.api.data.PageElementTitle

      } else {
        if (errors == null) {
          return true;
        }
        result = true;
        PageElementTitle previousTitle = knownTitles.get(titleValue);
        if (previousTitle != null) {
          CheckErrorResult errorResult = createCheckErrorResult(
              analysis,
              previousTitle.getBeginIndex(), previousTitle.getEndIndex(),
              ErrorLevel.CORRECT);
          errors.add(errorResult);
          knownTitles.put(titleValue, null);
        }
        CheckErrorResult errorResult = createCheckErrorResult(
View Full Code Here

Examples of org.wikipediacleaner.api.data.PageElementTitle

    // Fix double headlines
    int lastIndex = 0;
    StringBuilder buffer = new StringBuilder();
    for (int i = 1; i < titles.size(); i++) {
      PageElementTitle previousTitle = titles.get(i - 1);
      PageElementTitle currentTitle = titles.get(i);
      if ((previousTitle.getLevel() == currentTitle.getLevel()) &&
          (previousTitle.getTitle().equals(currentTitle.getTitle()))) {

        // Analyze if first title can be removed
        String betweenTitles = contents.substring(
            previousTitle.getEndIndex(), currentTitle.getBeginIndex()).trim();
        boolean shouldRemove = false;
        if (betweenTitles.length() == 0) {
          shouldRemove = true;
        } else {
          int tmpIndex = currentTitle.getEndIndex();
          while ((tmpIndex < contents.length()) &&
                 (Character.isWhitespace(contents.charAt(tmpIndex)))) {
            tmpIndex++;
          }
          if ((tmpIndex < contents.length()) &&
              (contents.startsWith(betweenTitles, tmpIndex))) {
            shouldRemove = true;
          }
        }
        if (shouldRemove) {
          if (previousTitle.getBeginIndex() > lastIndex) {
            buffer.append(contents.substring(lastIndex, previousTitle.getBeginIndex()));
            lastIndex = previousTitle.getBeginIndex();
          }
          lastIndex = currentTitle.getBeginIndex();
        } else {

          // Analyze if second title can be removed
          PageElementTitle nextTitle = (i + 1 < titles.size()) ? titles.get(i + 1) : null;
          String afterTitle = contents.substring(
              currentTitle.getEndIndex(),
              (nextTitle != null) ? nextTitle.getBeginIndex() : contents.length()).trim();
          if (afterTitle.length() == 0) {
            shouldRemove = true;
          } else {
            int tmpIndex = previousTitle.getEndIndex();
            while ((tmpIndex < contents.length()) &&
                   (Character.isWhitespace(contents.charAt(tmpIndex)))) {
              tmpIndex++;
            }
            if ((tmpIndex < contents.length()) &&
                (contents.startsWith(afterTitle, tmpIndex))) {
              shouldRemove = true;
            }
          }
          if (shouldRemove) {
            if (currentTitle.getBeginIndex() > lastIndex) {
              buffer.append(contents.substring(lastIndex, currentTitle.getBeginIndex()));
              lastIndex = currentTitle.getBeginIndex();
            }
            lastIndex = (nextTitle != null) ? nextTitle.getBeginIndex() : contents.length();
          }
        }
      }
    }
    if (lastIndex == 0) {
View Full Code Here

Examples of org.wikipediacleaner.api.data.PageElementTitle

    }

    // Analyzing titles
    int previousLevel = 0;
    for (int i = 0; i < titles.size(); i++) {
      PageElementTitle title = titles.get(i);
      if ((title.getLevel() > previousLevel) &&
          (title.getLevel() > 2)) {
        int j = i + 1;
        int count = 0;
        while ((j < titles.size()) &&
               (titles.get(j).getLevel() >= title.getLevel())) {
          if (titles.get(j).getLevel() == title.getLevel()) {
            count++;
          }
          j++;
        }
        if (count == 0) {
          if (errors == null) {
            return true;
          }
          result = true;
          CheckErrorResult errorResult = createCheckErrorResult(
              analysis, title.getBeginIndex(), title.getEndIndex());
          errorResult.addEditTocAction();
          errors.add(errorResult);
        }
      }
      previousLevel = title.getLevel();
    }
    return result;
  }
View Full Code Here

Examples of org.wikipediacleaner.api.data.PageElementTitle

    Vector<Integer> offsets = new Vector<Integer>();
    List<PageElementTitle> titles = analysis.getTitles();
    for (int index = 0; index < titles.size(); index++) {

      // Compute current offset
      PageElementTitle title = titles.get(index);
      offsets.setSize(title.getLevel());
      int offset = 0;
      for (Integer levelOffset : offsets) {
        if (levelOffset != null) {
          offset += levelOffset.intValue();
        }
      }

      // Replace title if needed
      if (offset > 0) {
        if (lastIndex < title.getBeginIndex()) {
          tmp.append(contents.substring(lastIndex, title.getBeginIndex()));
          lastIndex = title.getBeginIndex();
        }
        tmp.append(PageElementTitle.createTitle(
            title.getLevel() - offset, title.getTitle(), title.getAfterTitle()));
        if (title.getAfterTitle() != null) {
          tmp.append(title.getAfterTitle());
        }
        lastIndex = title.getEndIndex();
      }

      // Compute level offset
      int levelOffset = Integer.MAX_VALUE;
      for (int index2 = index + 1;
           (index2 < titles.size()) && (titles.get(index2).getLevel() > title.getLevel());
           index2++) {
        levelOffset = Math.min(
            levelOffset,
            titles.get(index2).getLevel() - title.getLevel() - 1);
      }
      offsets.add(Integer.valueOf(levelOffset));
      if ((levelOffset == 0) &&
          (index + 1 < titles.size()) &&
          (titles.get(index + 1).getLevel() > title.getLevel() + 1)) {
        offsets.add(Integer.valueOf(titles.get(index + 1).getLevel() - title.getLevel() - 1));
      }
    }
    if (lastIndex == 0) {
      return contents;
    }
View Full Code Here

Examples of org.wikipediacleaner.api.data.PageElementTitle

    // Searching for last headline
    Collection<PageElementTitle> titles = analysis.getTitles();
    if ((titles == null) || (titles.isEmpty())) {
      return false;
    }
    PageElementTitle title = null;
    for (PageElementTitle tmpTitle : titles) {
      if ((title == null) || (title.getBeginIndex() < tmpTitle.getBeginIndex())) {
        title = tmpTitle;
      }
    }
    if (title == null) {
      return false;
    }

    // Checking every category
    boolean result = false;
    for (PageElementCategory category : analysis.getCategories()) {
      if (category.getBeginIndex() < title.getBeginIndex()) {
        if (errors == null) {
          return true;
        }
        result = true;
        CheckErrorResult errorResult = createCheckErrorResult(
View Full Code Here

Examples of org.wikipediacleaner.api.data.PageElementTitle

    if ((refs == null) || (refs.isEmpty())) {
      return false;
    }
    boolean result = false;
    for (PageElementTag ref : refs) {
      PageElementTitle title = analysis.isInTitle(ref.getCompleteBeginIndex());
      if (title != null) {
        if (errors == null) {
          return true;
        }
        result = true;
View Full Code Here

Examples of org.wikipediacleaner.api.data.PageElementTitle

    if ((links == null) || (links.isEmpty())) {
      return false;
    }
    boolean result = false;
    for (PageElementInternalLink link : links) {
      PageElementTitle title = analysis.isInTitle(link.getBeginIndex());
      if (title != null) {
        if (errors == null) {
          return true;
        }
        result = true;
View Full Code Here

Examples of org.wikipediacleaner.api.data.PageElementTitle

    if (treeNode == null) {
      return;
    }
    Object nodeInfo = treeNode.getUserObject();
    if (nodeInfo instanceof PageElementTitle) {
      PageElementTitle title = (PageElementTitle) nodeInfo;
      try {
        textPane.setCaretPosition(title.getBeginIndex());
        textPane.moveCaretPosition(title.getEndIndex());
      } catch (IllegalArgumentException e2) {
        //
      }
      textPane.requestFocusInWindow();
    }
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.