Package org.wikipediacleaner.api.data

Examples of org.wikipediacleaner.api.data.Page


    if ((doc == null) || (internalLink == null)) {
      return;
    }

    // Check if the link should be formatted
    Page link = findPage(internalLink.getLink());
    if (link == null) {
      return;
    }

    // Format the link
    String contents = pageAnalysis.getContents();
    boolean disambiguation = Boolean.TRUE.equals(link.isDisambiguationPage());
    String text = internalLink.getDisplayedText();
    int start = internalLink.getBeginIndex();
    int end = internalLink.getEndIndex();
    while ((end < contents.length()) &&
           (Character.isLetter(contents.charAt(end))) &&
           (Character.getType(contents.charAt(end)) != Character.OTHER_LETTER)) {
      end++;
    }
    if (end > internalLink.getEndIndex()) {
      text = text + contents.substring(internalLink.getEndIndex(), end);
    }
    ConfigurationValueStyle styleType = null;
    if (disambiguation) {
      styleType = ConfigurationValueStyle.INTERNAL_LINK_DAB;

      // Check if a template is after the link to ask for help
      List<String> templatesAfter = wikipedia.getConfiguration().getStringList(
          WPCConfigurationStringList.TEMPLATES_AFTER_HELP_ASKED);
      if ((templatesAfter != null) && !templatesAfter.isEmpty()) {
        int maxSize = contents.length();
        int currentPos = end;
        while ((currentPos < maxSize) && (contents.charAt(currentPos) == ' ')) {
          currentPos++;
        }
        if ((currentPos < maxSize) && (contents.charAt(currentPos) == '{')) {
          PageElementTemplate nextTemplate = pageAnalysis.isInTemplate(currentPos);
          if (nextTemplate != null) {
            for (String templateAfter : templatesAfter) {
              if (Page.areSameTitle(templateAfter, nextTemplate.getTemplateName())) {
                styleType = ConfigurationValueStyle.HELP_REQUESTED;
                end = nextTemplate.getEndIndex();
              }
            }
          }
        }
      }

      List<String> commentsAfter = wikipedia.getConfiguration().getStringList(
          WPCConfigurationStringList.COMMENTS_FOR_DAB_LINK);
      if ((commentsAfter != null) && !commentsAfter.isEmpty()) {
        int maxSize = contents.length();
        int currentPos = end;
        while ((currentPos < maxSize) && (contents.charAt(currentPos) == ' ')) {
          currentPos++;
        }
        if ((currentPos < maxSize) && (contents.charAt(currentPos) == '<')) {
          PageElementComment comment = pageAnalysis.isInComment(currentPos);
          if (comment != null) {
            for (String commentAfter : commentsAfter) {
              String comment2 = comment.getComment();
              if ((comment2 != null) && (comment2.length() >= commentAfter.length())) {
                comment2 = comment2.substring(0, commentAfter.length());
                if (comment2.equalsIgnoreCase(commentAfter)) {
                  styleType = ConfigurationValueStyle.INTERNAL_LINK_NORMAL;
                  end = comment.getEndIndex();
                }
              }
            }
          }
        }
      }
    } else if (link.isRedirect()) {
      styleType = ConfigurationValueStyle.INTERNAL_LINK_REDIRECT;
    } else if (Boolean.TRUE.equals(link.isExisting())) {
      styleType = ConfigurationValueStyle.INTERNAL_LINK_NORMAL;
    } else {
      styleType = ConfigurationValueStyle.INTERNAL_LINK_MISSING;
    }
    Style attr = doc.getStyle(styleType.getName());
View Full Code Here


      return;
    }
    for (TemplateMatcher matcher : matchers) {
      String linkTo = matcher.linksTo(pageAnalysis.getPage(), template);
      if (linkTo != null) {
        Page link = findPage(linkTo);
        if (link != null) {
          formatTemplate(doc, link, template, matcher);
          return;
        }
      }
View Full Code Here

        int fixedEndHistory = 0;
        JMenu submenuView = new JMenu(GT._("External Viewer"));
        JMenu submenuHistory = new JMenu(GT._("History"));
        Iterator<Page> iter = page.getRedirectIteratorWithPage();
        while (iter.hasNext()) {
          Page pageTmp = iter.next();
          fixedBeginView += addItem(
              submenuView, pageTmp, null, true,
              new ActionExternalViewer(wiki, pageTmp.getTitle()));
          fixedBeginHistory += addItem(
              submenuHistory, pageTmp, null, true,
              new ActionExternalViewer(
                  wiki, pageTmp.getTitle(), ActionExternalViewer.ACTION_HISTORY));
        }
        if ((links != null) && (links.size() > 0) && showLinks) {
          fixedBeginView += addSeparator(submenuView);
          fixedBeginHistory += addSeparator(submenuHistory);
   
          for (Page p : links) {
            if (p.isRedirect()) {
              JMenu submenuRedirectView = new JMenu(p.getTitle());
              JMenu submenuRedirectHistory = new JMenu(p.getTitle());
              Iterator<Page> itPage = p.getRedirectIteratorWithPage();
              while (itPage.hasNext()) {
                Page redirect = itPage.next();
                addItem(
                    submenuRedirectView, redirect, null, true,
                    new ActionExternalViewer(wiki, redirect.getTitle()));
                addItem(
                    submenuRedirectHistory, redirect, null, true,
                    new ActionExternalViewer(
                        wiki, redirect.getTitle(), ActionExternalViewer.ACTION_HISTORY));
              }
              submenuView.add(submenuRedirectView);
              submenuHistory.add(submenuRedirectHistory);
            } else {
              addItem(
                  submenuView, p, null, true,
                  new ActionExternalViewer(wiki, p.getTitle()));
              addItem(
                  submenuHistory, p, null, true,
                  new ActionExternalViewer(
                      wiki, p.getTitle(), ActionExternalViewer.ACTION_HISTORY));
            }
          }

          fixedEndView += addSeparator(submenuView);
          fixedEndHistory += addSeparator(submenuHistory);

          iter = page.getRedirectIteratorWithPage();
          while (iter.hasNext()) {
            Page pageTmp = iter.next();
            fixedEndView += addItem(
                submenuView, pageTmp, null, true,
                new ActionExternalViewer(wiki, pageTmp.getTitle()));
            fixedEndHistory += addItem(
                submenuHistory, pageTmp, null, true,
                new ActionExternalViewer(
                    wiki, pageTmp.getTitle(), ActionExternalViewer.ACTION_HISTORY));
          }
        }
        addSubmenu(popup, submenuView, fixedBeginView, fixedEndView);
        addSubmenu(popup, submenuHistory, fixedBeginHistory, fixedEndHistory);
      } else {
View Full Code Here

      int fixedBegin = 0;
      int fixedEnd = 0;
      JMenu submenuAnalyze = new JMenu(GT._("Analyze"));
      Iterator<Page> iter = page.getRedirectIteratorWithPage();
      while (iter.hasNext()) {
        Page pageTmp = iter.next();
        menuItem = new JMenuItem(pageTmp.getTitle());
        updateFont(menuItem, pageTmp);
        action = new ActionFullAnalysis(wiki, pageTmp.getTitle());
        menuItem.addActionListener(action);
        submenuAnalyze.add(menuItem);
        fixedBegin++;
      }
      if ((links != null) && (links.size() > 0)) {
        fixedBegin += addSeparator(submenuAnalyze);
 
        for (Page p : links) {
          menuItem = new JMenuItem(p.getTitle());
          updateFont(menuItem, p);
          action = new ActionFullAnalysis(wiki, p.getTitle());
          menuItem.addActionListener(action);
          submenuAnalyze.add(menuItem);
        }

        fixedEnd += addSeparator(submenuAnalyze);

        iter = page.getRedirectIteratorWithPage();
        while (iter.hasNext()) {
          Page pageTmp = iter.next();
          menuItem = new JMenuItem(pageTmp.getTitle());
          updateFont(menuItem, pageTmp);
          action = new ActionFullAnalysis(wiki, pageTmp.getTitle());
          menuItem.addActionListener(action);
          submenuAnalyze.add(menuItem);
          fixedEnd++;
        }
      }
View Full Code Here

        popup.add(menuItem);
      } else {
        JMenu submenuView = new JMenu(GT._("Disambiguation analysis"));
        Iterator<Page> iter = page.getRedirectIteratorWithPage();
        while (iter.hasNext()) {
          Page pageTmp = iter.next();
          JMenuItem menuItem = new JMenuItem(pageTmp.getTitle());
          updateFont(menuItem, pageTmp);
          ActionListener action = new ActionDisambiguationAnalysis(wiki, pageTmp.getTitle());
          menuItem.addActionListener(action);
          submenuView.add(menuItem);
        }
        popup.add(submenuView);
      }
View Full Code Here

        String warningTemplateName = configuration.getString(WPCConfigurationString.DAB_WARNING_TEMPLATE);
        setText(GT._("Retrieving talk pages including {0}", "{{" + warningTemplateName + "}}"));
        String templateTitle = wikiConfiguration.getPageTitle(
            Namespace.TEMPLATE,
            warningTemplateName);
        Page warningTemplate = DataManager.getPage(
            wikipedia, templateTitle, null, null, null);
        api.retrieveEmbeddedIn(
            wikipedia, warningTemplate,
            configuration.getEncyclopedicTalkNamespaces(),
            false);
        List<Page> warningTalkPages = warningTemplate.getRelatedPages(Page.RelatedPages.EMBEDDED_IN);
 
        // Construct list of articles with warning
        setText(GT._("Constructing list of articles with warning"));
        HashSet<Page> tmpWarningPages = new HashSet<Page>();
        for (Page warningPage : warningTalkPages) {
          String title = warningPage.getTitle();
          String todoSubpage = configuration.getString(WPCConfigurationString.TODO_SUBPAGE);
          if (title.endsWith("/" + todoSubpage)) {
            title = title.substring(0, title.length() - 1 - todoSubpage.length());
          }
          int colonIndex = title.indexOf(':');
          if (colonIndex >= 0) {
            for (Integer namespace : configuration.getEncyclopedicTalkNamespaces()) {
              Namespace namespaceTalk = wikiConfiguration.getNamespace(namespace);
              if ((namespaceTalk != null) &&
                  (namespaceTalk.isPossibleName(title.substring(0, colonIndex)))) {
                String tmpTitle = title.substring(colonIndex + 1);
                if (namespace != Namespace.MAIN_TALK) {
                  tmpTitle = wikiConfiguration.getPageTitle(namespace - 1, tmpTitle);
                }
                if ((start.length() == 0) || (start.compareTo(tmpTitle) < 0)) {
                  Page page = DataManager.getPage(wikipedia, tmpTitle, null, null, null);
                  if (!tmpWarningPages.contains(page)) {
                    tmpWarningPages.add(page);
                  }
                }
              }
            }
          }
        }
        if (getWindow() != null) {
          int answer = getWindow().displayYesNoWarning(GT._(
              "Analysis found {0} articles with disambiguation warning {1}.\n" +
              "Do you want to update the disambiguation warnings ?",
              new Object[] { Integer.valueOf(tmpWarningPages.size()), "{{" + warningTemplateName + "}}" }));
          if (answer != JOptionPane.YES_OPTION) {
            return Integer.valueOf(0);
          }
        }

        // Sort the list of articles
        warningPages.addAll(tmpWarningPages);
        tmpWarningPages.clear();
        Collections.sort(warningPages, PageComparator.getTitleFirstComparator());
        if (warningPages.isEmpty()) {
          return Integer.valueOf(0);
        }
      }

      // Working with sublists
      UpdateDabWarningTools tools = new UpdateDabWarningTools(wikipedia, this, true, automaticEdit);
      tools.setContentsAvailable(contentsAvailable);
      tools.setLinksAvailable(linksAvailable);
      tools.setDabInformationAvailable(dabInformationAvailable);
      if (!useList) {
        setText(GT._("Retrieving disambiguation pages"));
        tools.preloadDabPages();
      }
      String lastTitle = null;
      int countUnsaved = 0;
      while (!warningPages.isEmpty()) {
        // Creating sublist
        int size = Math.min(10, warningPages.size());
        List<Page> sublist = new ArrayList<Page>(size);
        while ((sublist.size() < size) && (warningPages.size() > 0)) {
          Page page = warningPages.remove(0);
          if ((start.length() == 0) || (start.compareTo(page.getTitle()) < 0)) {
            sublist.add(page);
          }
        }
        if (sublist.isEmpty()) {
          displayResult(stats, startTime);
View Full Code Here

    if (textPane == null) {
      return;
    }

    // Create popup menu
    Page originalPage = textPane.getWikiPage();
    PageAnalysis pageAnalysis = originalPage.getAnalysis(textPane.getText(), true);
    JPopupMenu popup = createPopup(textPane, position, pageAnalysis);
    if (popup == null) {
      popup = createDefaultPopup(textPane, position, pageAnalysis);
    }
View Full Code Here

    if (link == null) {
      return null;
    }

    // Initialization
    Page page = DataManager.getPage(wikipedia, link.getLink(), null, null, null);

    // Menu creation
    BasicMenuCreator menu = new BasicMenuCreator();
    JPopupMenu popup = menu.createPopupMenu(GT._(
        "Page: {0}",
        limitTextLength(page.getTitle(), 50)));
    menu.addCurrentChapter(popup, position, pageAnalysis);
    menu.addSeparator(popup);
    menu.addView(wikipedia, popup, page, false);
    menu.addAnalyze(wikipedia, popup, page);
    menu.addDisambiguation(wikipedia, popup, page);
View Full Code Here

      return null;
    }

    // Initialization
    EnumWikipedia otherWikipedia = EnumWikipedia.getWikipedia(link.getLanguage());
    Page otherPage = null;
    if (otherWikipedia != null) {
      otherPage = DataManager.getPage(otherWikipedia, link.getLink(), null, null, null);
    }

    // Menu creation
View Full Code Here

    // Initialization
    String fullName = wikipedia.getWikiConfiguration().getPageTitle(
        Namespace.IMAGE,
        image.getImage());
    Page page = DataManager.getPage(wikipedia, fullName, null, null, null);

    // Menu creation
    BasicMenuCreator menu = new BasicMenuCreator();
    JPopupMenu popup = menu.createPopupMenu(GT._(
        "Image: {0}",
View Full Code Here

TOP

Related Classes of org.wikipediacleaner.api.data.Page

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.