Package org.wikipediacleaner.api.data

Examples of org.wikipediacleaner.api.data.Page


    Object attrPage = attributes.getAttribute(MWPaneFormatter.ATTRIBUTE_PAGE);
    Object attrPageElement = attributes.getAttribute(MWPaneFormatter.ATTRIBUTE_PAGE_ELEMENT);
    Object attrTemplateMatcher = attributes.getAttribute(MWPaneFormatter.ATTRIBUTE_TEMPLATE_MATCHER);
    Object attrText = attributes.getAttribute(MWPaneFormatter.ATTRIBUTE_TEXT);

    Page page = (attrPage instanceof Page) ? (Page) attrPage : null;
    TemplateMatcher matcher = (attrTemplateMatcher instanceof TemplateMatcher) ?
        (TemplateMatcher) attrTemplateMatcher : null;
    MWPaneDisambiguationMenuCreator menu = new MWPaneDisambiguationMenuCreator();

    // Manage TemplateMatcher
    if (attrPageElement instanceof PageElementTemplate) {
      PageElementTemplate template = (PageElementTemplate) attrPageElement;

      String templateTitle = getWikipedia().getWikiConfiguration().getPageTitle(
          Namespace.TEMPLATE,
          template.getTemplateName());
      JPopupMenu popup = menu.createPopupMenu(templateTitle);
      if ((matcher != null) &&
          (matcher.getExplanation() != null) &&
          (matcher.getExplanation().length() > 0)) {
        menu.addDisabledText(popup, "→ " + matcher.getExplanation() + " ←");
      }
      menu.addCurrentChapter(popup, position, pageAnalysis);

      menu.addSeparator(popup);
      Page templatePage = DataManager.getPage(getWikipedia(), templateTitle, null, null, null);

      menu.addReplaceTemplate(
          getWikipedia(), popup, template, matcher,
          page, pageAnalysis.getPage(), element, textPane);
      menu.addAnalyze(getWikipedia(), popup, page);
View Full Code Here


    }
    Component source = (Component) e.getSource();
    if ((pane == null) || (pageProvider == null)) {
      return;
    }
    Page page = pageProvider.getPage();
    if ((page == null) || (page.getContents() == null)) {
      return;
    }

    // Check current page
    boolean article = (page.isArticle());
    boolean redirect = article && page.isRedirect();

    // Check configuration
    WPCConfiguration wpcConfig = page.getWikipedia().getConfiguration();
    List<String> texts = wpcConfig.getStringList(
        WPCConfigurationStringList.INSERT_TEXTS);
    List<String> redirectCategories = null;
    List<String> redirectTemplates = null;
    if (redirect) {
View Full Code Here

   */
  public void actionAddText(String text) {
    if ((text == null) || (pageProvider == null)) {
      return;
    }
    Page page = pageProvider.getPage();
    if (page == null) {
      return;
    }
    try {
      pane.getDocument().insertString(
View Full Code Here

   */
  public void actionAddCategory(String categoryName) {
    if ((categoryName == null) || (pageProvider == null)) {
      return;
    }
    Page page = pageProvider.getPage();
    if (page == null) {
      return;
    }
    String contents = pane.getText();
    PageAnalysis analysis = page.getAnalysis(contents, false);

    // Check that the category isn't already applied
    List<PageElementCategory> categories = analysis.getCategories();
    for (PageElementCategory category : categories) {
      if (Page.areSameTitle(categoryName, category.getCategory())) {
        return;
      }
    }

    // Find where to add the category
    int index = contents.length();
    if (!categories.isEmpty()) {
      index = categories.get(categories.size() - 1).getEndIndex();
    } else {
      List<PageElementLanguageLink> langLinks = analysis.getLanguageLinks();
      if ((langLinks != null) && (!langLinks.isEmpty())) {
        index = langLinks.get(0).getBeginIndex();
      }
    }

    // Add the category
    StringBuilder newContents = new StringBuilder();
    if (index > 0) {
      newContents.append(contents.substring(0, index));
    }
    newContents.append("\n");
    newContents.append(PageElementCategory.createCategory(
        page.getWikipedia(), categoryName, null));
    if (index < contents.length()) {
      if (contents.charAt(index) != '\n') {
        newContents.append('\n');
      }
      newContents.append(contents.substring(index));
View Full Code Here

   */
  public void actionAddTemplate(String templateName) {
    if ((templateName == null) || (pageProvider == null)) {
      return;
    }
    Page page = pageProvider.getPage();
    if (page == null) {
      return;
    }
    String contents = pane.getText();
    PageAnalysis analysis = page.getAnalysis(contents, false);

    // Check that the template isn't already applied
    List<PageElementTemplate> templates = analysis.getTemplates(templateName);
    if ((templates != null) && (!templates.isEmpty())) {
      return;
View Full Code Here

   */
  public void actionPerformed(ActionEvent e) {
    if (pageProvider == null) {
      return;
    }
    Page page = pageProvider.getPage();
    if (page == null) {
      return;
    }

    String reason = Utilities.askForValue(
        parent,
        GT._("Do you want to delete this page on Wikipedia ?\nPlease, enter the reason for deleting the page"),
        "", null);
    if ((reason == null) || (reason.trim().length() == 0)) {
      return;
    }
    API api = APIFactory.getAPI();
    try {
      EnumWikipedia wiki = page.getWikipedia();
      api.deletePage(
          wiki, page, wiki.formatComment(reason.trim(), false));
      if (listener != null) {
        listener.pageDeleted(page.getTitle());
      }
    } catch (APIException ex) {
      Utilities.displayError(parent, ex);
    }
  }
View Full Code Here

    API api = APIFactory.getAPI();
    String link = api.getLanguageLink(from, getWikipedia(), pageName);
    if (link != null) {
      return link;
    }
    Page original = DataManager.getPage(from, pageName, null, null, null);
    //api.retrieveLinksWithRedirects(from, original, null, null);
    api.initializeRedirect(from, Collections.singletonList(original));
    if (!original.isRedirect()) {
      return link;
    }
    api.retrieveContents(from, Collections.singletonList(original), false, true);
    link = api.getLanguageLink(from, getWikipedia(), original.getRedirectTitle());
    if (link == null) {
      return null;
    }
    String destination = original.getRedirectDestination();
    int anchorPos = destination.indexOf('#');
    if (anchorPos < 0) {
      return link;
    }
    return link + destination.substring(anchorPos);
View Full Code Here

          }
        }
      }

      API api = APIFactory.getAPI();
      Page category = DataManager.getPage(toWikipedia, "Category:" + title, null, null, null);
      api.retrieveContents(toWikipedia, Collections.singletonList(category), false, false);
      if (category.isExisting() == null) {
        Utilities.displayWarning(
            textPane.getParent(),
            GT._(
                "Unable to find if category {0} exists in \"{1}\".",
                new Object[] { title, toWikipedia.toString() }));
        return;
      }
      if (Boolean.TRUE.equals(category.isExisting())) {
        String replace = categoryName + ":" + title + ((order != null) ? "|" + order : "");
        int answer = Utilities.displayYesNoWarning(
            textPane.getParent(),
            GT._(
                "The category {0} exists in \"{1}\".\n" +
View Full Code Here

   * @throws APIException
   */
  private void constructBackLinks(List<Page> pages) throws APIException {
    final API api = APIFactory.getAPI();
    for (String pageName : elementNames) {
      Page page = DataManager.getPage(getWikipedia(), pageName, null, null, null);
      api.retrieveBackLinks(getWikipedia(), page, true);
      List<Page> tmpPages = page.getRelatedPages(Page.RelatedPages.BACKLINKS);
      if (tmpPages != null) {
        for (Page tmpPage : tmpPages) {
          if (!pages.contains(tmpPage)) {
            pages.add(tmpPage);
          }
View Full Code Here

   * @throws APIException
   */
  private void constructCategoryMembers(List<Page> pages) throws APIException {
    final API api = APIFactory.getAPI();
    for (String pageName : elementNames) {
      Page page = DataManager.getPage(getWikipedia(), pageName, null, null, null);
      api.retrieveCategoryMembers(getWikipedia(), page, 0, true);
      List<Page> tmpPages = page.getRelatedPages(Page.RelatedPages.CATEGORY_MEMBERS);
      if (tmpPages != null) {
        for (Page tmpPage : tmpPages) {
          if (!pages.contains(tmpPage)) {
            pages.add(tmpPage);
          }
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.