Package org.wikipediacleaner.api.data

Examples of org.wikipediacleaner.api.data.PageAnalysis


    }
    Namespace templateNamespace = getWikipedia().getWikiConfiguration().getNamespace(Namespace.TEMPLATE);
    if (templateNamespace == null) {
      return text;
    }
    PageAnalysis analysis = page.getAnalysis(text, true);
    Collection<PageElementTemplate> templates = analysis.getTemplates();
    Map<String, String> interwikis = new HashMap<String, String>();
    StringBuilder newText = new StringBuilder();
    int lastPosition = 0;
    for (PageElementTemplate template : templates) {
      String templateName = template.getTemplateName();
View Full Code Here


   * Update table of contents tree.
   */
  private void updateTreeToc() {
    MWPaneTitleTreeNode rootNode = new MWPaneTitleTreeNode(null);
    MWPaneTitleTreeNode lastNode = rootNode;
    PageAnalysis pageAnalysis = textPane.getWikiPage().getAnalysis(textPane.getText(), true);
    List<PageElementTitle> titles = pageAnalysis.getTitles();
    for (PageElementTitle title : titles) {
      while ((lastNode != null) &&
             (lastNode.getInitialTitleLevel() >= title.getLevel())) {
        if (lastNode.getParent() != null) {
          lastNode = (MWPaneTitleTreeNode) lastNode.getParent();
View Full Code Here

   */
  private PageElementTemplate getExistingTemplateTodoLink(Page talkPage, String contents) {
    PageElementTemplate templateTodoLink = null;
    List<String> todoLinkTemplates = configuration.getStringList(WPCConfigurationStringList.TODO_LINK_TEMPLATES);
    if (todoLinkTemplates != null) {
      PageAnalysis analysis = talkPage.getAnalysis(contents, true);
      for (String todoLink : todoLinkTemplates) {
        List<PageElementTemplate> templates = analysis.getTemplates(todoLink);
        if ((templates != null) && (templates.size() > 0)) {
          templateTodoLink = templates.get(0);
        }
      }
    }
View Full Code Here

    listLinks.clearSelection();
    listErrors.clearSelection();

    // Update links information
    Page page = getPage();
    PageAnalysis analysis = page.getAnalysis(page.getContents(), true);
    mapLinksTotalCount = new HashMap<String, Integer>();
    mapLinksHelpNeededCount = new HashMap<String, Integer>();
    if (page.getLinks() != null) {
      List<Page> links = page.getLinks();
      modelLinks.setElements(links);
      countOccurrences(analysis, true);
      for (Page p : links) {
        if ((p != null) &&
            (Boolean.TRUE.equals(p.isDisambiguationPage()))) {
          InternalLinkCount count = analysis.getLinkCount(p);
          if ((count != null) && (count.getTotalLinkCount() > 0)) {
            mapLinksTotalCount.put(p.getTitle(), Integer.valueOf(count.getTotalLinkCount()));
            mapLinksHelpNeededCount.put(p.getTitle(), Integer.valueOf(count.getHelpNeededCount()));
          }
        }
      }
    }
    selectLinks(0);
    modelLinks.updateLinkCount();

    // Update fix redirects menu
    createFixRedirectsMenu();

    // Check Wiki
    modelErrors.clear();
    initializeInitialErrors(allAlgorithms);
    if (getInitialErrors() != null) {
      for (CheckErrorPage error : getInitialErrors()) {
        modelErrors.addElement(error);
      }
    }
    listErrors.clearSelection();

    if (firstReload) {
      firstReload = false;

      // Check page contents
      Page pageLoaded = getPage();
      if ((pageLoaded != null) &&
          (Boolean.FALSE.equals(pageLoaded.isExisting()))) {
        List<Page> similarPages = pageLoaded.getRelatedPages(Page.RelatedPages.SIMILAR_PAGES);
        if ((similarPages != null) && (similarPages.size() > 0)) {
          String answer = Utilities.askForValue(
              getParentComponent(),
              GT._(
                  "Page {0} doesn''t exist, do you want to load a similar page ?",
                  pageLoaded.getTitle()),
              similarPages.toArray(), true,
              similarPages.get(0).toString(), null);
          if ((answer != null) && (answer.trim().length() > 0)) {
            Controller.runFullAnalysis(answer, null, getWikipedia());
          }
          dispose();
          return;
        }
        int answer = Utilities.displayYesNoWarning(
            getParentComponent(),
            GT._(
                "Page {0} doesn''t exist, do you still want to analyze it ?",
                pageLoaded.getTitle()));
        if (answer != JOptionPane.YES_OPTION) {
          dispose();
          return;
        }
      }

      // Configuration depending on the type of page
      boolean isArticle = (getPage() != null) && (getPage().isArticle());
      if (isArticle) {
        WPCConfiguration wpcConfig = getConfiguration();
        boolean isbnErrors = Page.areSameTitle(
            getPage().getTitle(),
            wpcConfig.getString(WPCConfigurationString.ISBN_ERRORS_PAGE));
        Integer namespace = getPage().getNamespace();
        Configuration config = Configuration.getConfiguration();
        if (getPage().isInMainNamespace()) {
          chkUpdateDabWarning.setSelected(config.getBoolean(
              null,
              ConfigurationValueBoolean.UPDATE_DAB_WARNING));
          chkCreateDabWarning.setSelected(!isbnErrors && config.getBoolean(
              null,
              ConfigurationValueBoolean.CREATE_DAB_WARNING));
        } else if ((namespace != null) &&
                   (wpcConfig.isEncyclopedicNamespace(namespace))) {
          chkUpdateDabWarning.setSelected(config.getBoolean(
              null,
              ConfigurationValueBoolean.UPDATE_DAB_WARNING_ENCY));
          chkCreateDabWarning.setSelected(!isbnErrors && config.getBoolean(
              null,
              ConfigurationValueBoolean.CREATE_DAB_WARNING_ENCY));
        } else {
          chkUpdateDabWarning.setSelected(config.getBoolean(
              null,
              ConfigurationValueBoolean.UPDATE_DAB_WARNING_ALL));
          chkCreateDabWarning.setSelected(!isbnErrors && config.getBoolean(
              null,
              ConfigurationValueBoolean.CREATE_DAB_WARNING_ALL));
        }
      }
    }
    updateComponentState();

    // Edit warning if needed
    boolean automaticFix = true;
    WPCConfiguration wpcConfig = getWikipedia().getConfiguration();
    List<String[]> warningTemplates = wpcConfig.getStringArrayList(
        WPCConfigurationStringList.EDIT_WARNING_TEMPLATES);
    if ((warningTemplates != null) && (!warningTemplates.isEmpty())) {
      StringBuilder tmp = new StringBuilder(GT._(
          "\"{0}\" has been tagged with the following templates, be careful when editing:",
          getPage().getTitle()));
      boolean found = false;
      for (String[] warningTemplate : warningTemplates) {
        if ((warningTemplate.length > 0) && (warningTemplate[0] != null)) {
          List<PageElementTemplate> templates = analysis.getTemplates(warningTemplate[0]);
          for (PageElementTemplate template : templates) {
            tmp.append("\n* ");
            tmp.append(template.getTemplateName());
            if ((warningTemplate.length > 1) && (warningTemplate[1] != null)) {
              String message = template.getParameterValue(warningTemplate[1]);
View Full Code Here

    }
    if (titles.size() == 0) {
      return;
    }
    String currentText = getTextContents().getText();
    PageAnalysis analysis = getPage().getAnalysis(currentText, false);
    StringBuilder buffer = new StringBuilder();
    int lastPosition = 0;
    Collection<PageElementInternalLink> links = analysis.getInternalLinks();
    for (PageElementInternalLink link : links) {
      boolean shouldChange = false;
      for (String title : titles) {
        if (Page.areSameTitle(title, link.getLink())) {
          shouldChange = true;
View Full Code Here

    // Count previous selected errors
    int previousCount = countSelectedErrors(getPage().getLastAnalysis());

    getTextContents().resetAttributes();
    PageAnalysis analysis = getPage().getAnalysis(getTextContents().getText(), true);
    countOccurrences(analysis, false);
    listLinks.repaint();

    // Check for new errors
    analysis.shouldCheckSpelling(shouldCheckSpelling());
    List<CheckErrorPage> errorsFound = CheckError.analyzeErrors(
        allAlgorithms, analysis, false);
    if (errorsFound != null) {
      for (CheckErrorPage tmpError : errorsFound) {
        boolean errorFound = false;
View Full Code Here

TOP

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

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.