Package org.wikipediacleaner.api.data

Examples of org.wikipediacleaner.api.data.Namespace


    if (analysis == null) {
      return false;
    }

    // Check category name space
    Namespace categoryNamespace = analysis.getWikiConfiguration().getNamespace(Namespace.CATEGORY);
    if (categoryNamespace == null) {
      return false;
    }
    String preferredCategory = categoryNamespace.getTitle();
    if (preferredCategory == null) {
      preferredCategory = PageElementCategory.DEFAULT_NAME;
    }

    // Check every category
View Full Code Here


      PageAnalysis analysis,
      Collection<CheckErrorResult> errors, boolean onlyAutomatic) {
    if (analysis == null) {
      return false;
    }
    Namespace categoryNamespace = analysis.getWikiConfiguration().getNamespace(Namespace.CATEGORY);
    if (categoryNamespace == null) {
      return false;
    }
    Collection<PageElementCategory> categories = analysis.getCategories();
    if (categories == null) {
      return false;
    }
    boolean result = false;
    for (PageElementCategory category : categories) {
      String namespace = category.getCategoryNotTrimmed().trim();
      boolean lowerCaseNamespace = false;
      if ((namespace != null) &&
          (namespace.length() > 0) &&
          (Character.isLowerCase(namespace.charAt(0)))) {
        lowerCaseNamespace = true;
        namespace = "" + Character.toUpperCase(namespace.charAt(0)) + namespace.substring(1);
      }
      String categoryName = category.getNameNotTrimmed();
      if (categoryName != null) {
        categoryName = categoryName.trim();
      }
      boolean lowerCaseName = false;
      if ((categoryName != null) &&
          (categoryName.length() > 0) &&
          (Character.isLowerCase(categoryName.charAt(0)))) {
        lowerCaseName = true;
        categoryName = "" + Character.toUpperCase(categoryName.charAt(0)) + categoryName.substring(1);
      }
      String categorySort = category.getSort();
      if ("".equals(categorySort)) {
        categorySort = category.getSortNotTrimmed();
      }
      /*boolean lowerCaseSort = false;
      if ((categorySort != null) &&
          (categorySort.length() > 0) &&
          (Character.isLowerCase(categorySort.charAt(0)))) {
        lowerCaseSort = true;
        categorySort = "" + Character.toUpperCase(categorySort.charAt(0)) + categorySort.substring(1);
      }*/
      if (lowerCaseNamespace || lowerCaseName) {
        if (errors == null) {
          return true;
        }
        result = true;
        CheckErrorResult errorResult = createCheckErrorResult(
            analysis, category.getBeginIndex(), category.getEndIndex());
        if (categorySort != null) {
          errorResult.addReplacement(
              "[[" + categoryNamespace.getTitle() + ":" + categoryName + "|" + categorySort + "]]");
        } else {
          errorResult.addReplacement(
              "[[" + categoryNamespace.getTitle() + ":" + categoryName + "]]");
        }
        errors.add(errorResult);
      }
    }
    return result;
View Full Code Here

   */
  public String getPageTitle(int namespaceId, String title) {
    if (namespaceId == Namespace.MAIN) {
      return title;
    }
    Namespace namespace = getNamespace(namespaceId);
    if (namespace != null) {
      int colonIndex = title.indexOf(':');
      if (colonIndex > 0) {
        String possibleNamespace = title.substring(0, colonIndex);
        if (namespace.isPossibleName(possibleNamespace)) {
          title = title.substring(colonIndex + 1);
        }
      }
      return namespace.getTitle() + ":" + namespace.getCaseSensitiveness().normalize(title);
    }
    return title;
  }
View Full Code Here

    // Check category name space
    if (EnumWikipedia.EN.equals(analysis.getWikipedia())) {
      return false;
    }
    Namespace categoryNamespace = analysis.getWikiConfiguration().getNamespace(Namespace.CATEGORY);
    if (categoryNamespace == null) {
      return false;
    }
    String preferredCategory = categoryNamespace.getTitle();
    if (PageElementCategory.DEFAULT_NAME.equalsIgnoreCase(preferredCategory)) {
      return false;
    }

    // Check every category
    List<PageElementCategory> categories = analysis.getCategories();
    boolean result = false;
    String contents = analysis.getContents();
    for (PageElementCategory category : categories) {
      if (PageElementCategory.DEFAULT_NAME.equalsIgnoreCase(category.getCategory())) {
        if (errors == null) {
          return true;
        }
        result = true;
        CheckErrorResult errorResult = createCheckErrorResult(
            analysis, category.getBeginIndex(), category.getEndIndex());
        errorResult.addPossibleAction(
            GT._("Check category"),
            new CheckCategoryLinkActionProvider(
                EnumWikipedia.EN, analysis.getWikipedia(),
                category.getName(), category.getSort()));
        List<String> replacements = new ArrayList<String>();
        if ((preferredCategory != null) &&
            (categoryNamespace.isPossibleName(preferredCategory))) {
          replacements.add(preferredCategory);
        }
        if (!replacements.contains(categoryNamespace.getCanonicalTitle())) {
          replacements.add(categoryNamespace.getCanonicalTitle());
        }
        for (String alias : categoryNamespace.getAliases()) {
          if (!replacements.contains(alias)) {
            replacements.add(alias);
          }
        }
        for (String replacement : replacements) {
View Full Code Here

    if (analysis == null) {
      return false;
    }

    boolean result = false;
    Namespace fileNamespace = analysis.getWikiConfiguration().getNamespace(Namespace.IMAGE);
    String contents = analysis.getContents();
    for (PageElementInternalLink link : analysis.getInternalLinks()) {
      // Finding possible namespace
      String namespace = null;
      if (link.getLink() != null) {
        int colonPos = link.getLink().indexOf(':');
        if (colonPos > 0) {
          namespace = link.getLink().substring(0, colonPos).trim();
        }
      }

      // Analyze link text
      String text = link.getText();
      if ((text != null) &&
          ((namespace == null) || (!fileNamespace.isPossibleName(namespace)))) {
        int levelSquareBrackets = 0;
        int levelCurlyBrackets = 0;
        ArrayList<Integer> pipeIndex = new ArrayList<Integer>();
        int currentPos = 0;
        while (currentPos < text.length()) {
View Full Code Here

    if (analysis == null) {
      return false;
    }

    // Case sensitiveness
    Namespace namespace = analysis.getWikiConfiguration().getNamespace(Namespace.CATEGORY);
    EnumCaseSensitiveness sensitive = EnumCaseSensitiveness.UNKNOWN;
    if (namespace != null) {
      sensitive = namespace.getCaseSensitiveness();
    }

    // Group categories by name
    List<PageElementCategory> categories = analysis.getCategories();
    if ((categories == null) || (categories.isEmpty())) {
View Full Code Here

   *
   * @param chunks List of chunks of text.
   * @param analysis Page analysis.
   */
  private void removeGalleryTags(List<ContentsChunk> chunks, PageAnalysis analysis) {
    Namespace imageNamespace = analysis.getWikiConfiguration().getNamespace(Namespace.IMAGE);
    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);
View Full Code Here

      int colonIndex = categoryName.indexOf(':');
      if (colonIndex < 0) {
        categoryName = getWiki().getWikiConfiguration().getPageTitle(
            Namespace.CATEGORY, categoryName);
      } else {
        Namespace namespaceCategory = getWiki().getWikiConfiguration().getNamespace(Namespace.CATEGORY);
        if (!namespaceCategory.isPossibleName(categoryName.substring(0, colonIndex))) {
          categoryName = getWiki().getWikiConfiguration().getPageTitle(Namespace.CATEGORY, categoryName);
        }
      }
      boolean shouldAnalyze = true;
      if (currentDepth > depth) {
View Full Code Here

        String title = currentNode.getText();
        String canonical = currentNode.getAttributeValue("canonical");
        String id = currentNode.getAttributeValue("id");
        EnumCaseSensitiveness caseSensitiveness = EnumCaseSensitiveness.getCase(currentNode.getAttributeValue("case"));
        boolean subPages = (currentNode.getAttribute("subpages") != null);
        Namespace ns = new Namespace(id, title, canonical, caseSensitiveness, subPages);
        namespaces.put(ns.getId(), ns);
      }

      // Retrieve name space aliases
      xpa = XPath.newInstance("/api/query/namespacealiases/ns");
      results = xpa.selectNodes(root);
      iter = results.iterator();
      while (iter.hasNext()) {
        Element currentNode = (Element) iter.next();
        Integer nsId = null;
        try {
          nsId = Integer.parseInt(currentNode.getAttributeValue("id"));
          Namespace namespace = namespaces.get(nsId);
          if (namespace != null) {
            namespace.addAlias(currentNode.getText());
          }
        } catch (NumberFormatException e) {
          //
        }
      }
View Full Code Here

    if (analysis == null) {
      return false;
    }

    // Retrieve image name space
    Namespace imageNamespace = analysis.getWikiConfiguration().getNamespace(Namespace.IMAGE);

    // Analyze each gallery tag
    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);
              boolean description = false;
              if ((pipeIndex >= 0) && (pipeIndex + 1 < line.length())) {
                if (line.substring(pipeIndex + 1).trim().length() > 0) {
                  description = true;
View Full Code Here

TOP

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

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.