Example usage for java.lang String CASE_INSENSITIVE_ORDER

List of usage examples for java.lang String CASE_INSENSITIVE_ORDER

Introduction

In this page you can find the example usage for java.lang String CASE_INSENSITIVE_ORDER.

Prototype

Comparator CASE_INSENSITIVE_ORDER

To view the source code for java.lang String CASE_INSENSITIVE_ORDER.

Click Source Link

Document

A Comparator that orders String objects as by compareToIgnoreCase .

Usage

From source file:de.zib.scalaris.examples.wikipedia.bliki.WikiServlet.java

/**
 * Creates a {@link WikiPageBean} object with the rendered content of a
 * given revision.//from  ww w  . ja va  2 s  .c  om
 * 
 * @param title
 *            the title of the article to render
 * @param result
 *            the revision to render (must be successful and contain a
 *            revision)
 * @param renderer
 *            the renderer to use (0=plain text, 1=Bliki)
 * @param request
 *            the request object
 * @param connection
 *            connection to the database
 * @param page
 *            the bean for the page (the rendered content will be added to
 *            this object)
 * @param noRedirect
 *            if <tt>true</tt>, a redirect will be shown as such, otherwise
 *            the content of the redirected page will be show
 * @param wikiModel
 *            the wiki model to use
 * @param topLevel
 *            if this function is called from inside
 *            {@link #renderRevision()}, this will be <tt>false</tt>,
 *            otherwise always use <tt>true</tt>
 */
private void renderRevision(final String title, final RevisionResult result, final int renderer,
        final HttpServletRequest request, final Connection connection, final WikiPageBean page,
        final boolean noRedirect, final MyWikiModel wikiModel, final boolean topLevel) {
    // set the page's contents according to the renderer used
    // (categories are included in the content string, so they only
    // need special handling the wiki renderer is used)
    NormalisedTitle titleN = NormalisedTitle.fromUnnormalised(title, namespace);
    wikiModel.setNamespaceName(namespace.getNamespaceByNumber(titleN.namespace));
    wikiModel.setPageName(titleN.title);
    if (renderer > 0) {
        String mainText = wikiModel.renderPageWithCache(result.revision.unpackedText());
        if (titleN.namespace.equals(MyNamespace.CATEGORY_NAMESPACE_KEY)) {
            ValueResult<List<NormalisedTitle>> catPagesResult = getPagesInCategory(connection, titleN);
            page.addStats(catPagesResult.stats);
            page.getInvolvedKeys().addAll(catPagesResult.involvedKeys);
            if (catPagesResult.success) {
                final TreeSet<String> subCategories = new TreeSet<String>(String.CASE_INSENSITIVE_ORDER);
                final TreeSet<String> categoryPages = new TreeSet<String>(String.CASE_INSENSITIVE_ORDER);
                final List<NormalisedTitle> tplPages = new ArrayList<NormalisedTitle>(
                        catPagesResult.value.size());

                for (NormalisedTitle pageInCat : catPagesResult.value) {
                    if (pageInCat.namespace.equals(MyNamespace.CATEGORY_NAMESPACE_KEY)) {
                        subCategories.add(pageInCat.title);
                    } else if (pageInCat.namespace.equals(MyNamespace.TEMPLATE_NAMESPACE_KEY)) {
                        tplPages.add(pageInCat);
                        categoryPages.add(pageInCat.denormalise(namespace));
                    } else {
                        categoryPages.add(pageInCat.denormalise(namespace));
                    }
                }
                if (!tplPages.isEmpty()) {
                    // all pages using a template are in the category of the template, too
                    ValueResult<List<NormalisedTitle>> tplResult = getPagesInTemplates(connection, tplPages,
                            title);
                    page.addStats(tplResult.stats);
                    page.getInvolvedKeys().addAll(tplResult.involvedKeys);
                    if (tplResult.success) {
                        for (NormalisedTitle pageInTplOfCat : tplResult.value) {
                            if (pageInTplOfCat.namespace.equals(MyNamespace.CATEGORY_NAMESPACE_KEY)) {
                                subCategories.add(pageInTplOfCat.title);
                            } else if (pageInTplOfCat.namespace.equals(MyNamespace.TEMPLATE_NAMESPACE_KEY)) {
                                // TODO: go into recursion?! -> for now, just add the template
                                //                                  tplPages.add(pageInTplOfCat);
                                categoryPages.add(pageInTplOfCat.denormalise(namespace));
                            } else {
                                categoryPages.add(pageInTplOfCat.denormalise(namespace));
                            }
                        }
                    } else {
                        if (tplResult.connect_failed) {
                            setParam_error(request, "ERROR: DB connection failed");
                        } else {
                            setParam_error(request, "ERROR: template page lists unavailable");
                        }
                        addToParam_notice(request, "error getting pages using templates: " + tplResult.message);
                    }
                }
                page.setSubCategories(subCategories);
                page.setCategoryPages(categoryPages);
            } else {
                if (catPagesResult.connect_failed) {
                    setParam_error(request, "ERROR: DB connection failed");
                } else {
                    setParam_error(request, "ERROR: category page list unavailable");
                }
                addToParam_notice(request, "error getting category pages: " + catPagesResult.message);
            }
        }
        page.setTitle(title);
        page.setVersion(result.revision.getId());
        String redirectedPageName = wikiModel.getRedirectLink();
        if (redirectedPageName != null) {
            if (noRedirect) {
                if (topLevel) {
                    page.setContentSub("Redirect page");
                }
                mainText = wikiModel.renderRedirectPage(redirectedPageName);
                page.setDate(Revision.stringToCalendar(result.revision.getTimestamp()));
            } else {
                final String safeTitle = StringEscapeUtils.escapeHtml(title);
                final String redirectUrl = wikiModel.getWikiBaseURL().replace("${title}", title);
                page.setContentSub("(Redirected from <a href=\"" + redirectUrl + "&redirect=no\" title=\""
                        + safeTitle + "\">" + title + "</a>)");
                // add the content from the page directed to:
                wikiModel.tearDown();
                wikiModel.setUp();

                RevisionResult redirectResult = getRevision(connection, redirectedPageName, namespace);
                page.addStats(redirectResult.stats);
                page.getInvolvedKeys().addAll(redirectResult.involvedKeys);
                if (redirectResult.success) {
                    renderRevision(redirectedPageName, redirectResult, renderer, request, connection, page,
                            true, wikiModel, false);
                    return;
                } else {
                    // non-existing/non-successful page is like redirect=no
                    mainText = wikiModel.renderRedirectPage(redirectedPageName);
                    page.setDate(Revision.stringToCalendar(result.revision.getTimestamp()));
                }
            }
        } else {
            setSubPageNav(title, page, wikiModel);
        }
        page.setPage(mainText);
        page.setCategories(wikiModel.getCategories().keySet());
        page.addStats(wikiModel.getStats());
        page.getInvolvedKeys().addAll(wikiModel.getInvolvedKeys());
    } else if (renderer == 0) {
        // for debugging, show all parameters:
        StringBuilder sb = new StringBuilder();
        for (Enumeration<?> req_pars = request.getParameterNames(); req_pars.hasMoreElements();) {
            String element = (String) req_pars.nextElement();
            sb.append(element + " = ");
            sb.append(request.getParameter(element) + "\n");
        }
        sb.append("\n\n");
        for (Enumeration<?> headers = request.getHeaderNames(); headers.hasMoreElements();) {
            String element = (String) headers.nextElement();
            sb.append(element + " = ");
            sb.append(request.getHeader(element) + "\n");
        }
        page.setPage("<p>WikiText:<pre>" + StringEscapeUtils.escapeHtml(result.revision.unpackedText())
                + "</pre></p>" + "<p>Version:<pre>"
                + StringEscapeUtils.escapeHtml(String.valueOf(result.revision.getId())) + "</pre></p>"
                + "<p>Last change:<pre>" + StringEscapeUtils.escapeHtml(result.revision.getTimestamp())
                + "</pre></p>" + "<p>Request Parameters:<pre>" + StringEscapeUtils.escapeHtml(sb.toString())
                + "</pre></p>");
        page.setTitle(title);
        page.setVersion(result.revision.getId());
        page.setDate(Revision.stringToCalendar(result.revision.getTimestamp()));
    }
    page.setNotice(getParam_notice(request));
    page.setError(getParam_error(request));
    page.setWikiTitle(siteinfo.getSitename());
    page.setWikiNamespace(namespace);
}

From source file:org.apache.jsp.people_jsp.java

private String listItems(HttpServletRequest request, HttpServletResponse response) {
      StringBuffer people = new StringBuffer();
      Map<String, String> listOfPeople = getListOfAllPeople(request, response);

      if (listOfPeople.size() > 0) {
          people.append("<table class=\"listTable\" cellpadding=\"3\" cellspacing=\"1\" width=\"100%\" >");

          // Sort the sources alphabetically
          List<String> sortedKeys = new ArrayList<String>(listOfPeople.keySet());
          Collections.sort(sortedKeys, String.CASE_INSENSITIVE_ORDER);

          // Filter the list
          List<String> sortedAndFilteredKeys = new ArrayList<String>();
          for (String key : sortedKeys) {
              if (listFilter.length() > 0) {
                  if (key.toLowerCase().contains(listFilter.toLowerCase()))
                      sortedAndFilteredKeys.add(key);
              } else {
                  sortedAndFilteredKeys.add(key);
              }/*from w w  w  .ja v  a2 s. co m*/
          }

          // If the user has filtered the list down we might need to adjust our page calculations
          // e.g. 20 total items might = 2 pages but filtered down to 5 items there would only be 1
          // Calculate first item to start with with
          // Page = 1, item = 1
          // Page = X, item = ( ( currentPage - 1 ) * itemsToShowPerPage ) + 1;
          int startItem = 1;
          int endItem = startItem + itemsToShowPerPage - 1;
          if (currentPage > 1) {
              startItem = ((currentPage - 1) * itemsToShowPerPage) + 1;
              endItem = (startItem + itemsToShowPerPage) - 1;
          }

          int currentItem = 1;
          for (String key : sortedAndFilteredKeys) {
              if (currentItem >= startItem && currentItem <= endItem) {
                  String name = key;
                  String id = listOfPeople.get(key).toString();
                  String editLink = "";
                  String deleteLink = "";

                  String listFilterString = "";
                  if (listFilter.length() > 0)
                      listFilterString = "&listFilterStr=" + listFilter;

                  editLink = "<a href=\"people.jsp?action=edit&personid=" + id + "&page=" + currentPage
                          + listFilterString + "\" title=\"Edit User Account\">" + name + "</a>";
                  deleteLink = "<a href=\"people.jsp?action=delete&personid=" + id + listFilterString
                          + "\" title=\"Delete User Account\" "
                          + "onclick='return confirm(\"Do you really wish to delete the user account for: " + name
                          + "?\");'><img src=\"image/delete_x_button.png\" border=0></a>";

                  // Create the HTML table row
                  people.append("<tr>");
                  people.append("<td bgcolor=\"white\" width=\"100%\">" + editLink + "</td>");
                  people.append("<td align=\"center\" bgcolor=\"white\">" + deleteLink + "</td>");
                  people.append("</tr>");
              }
              currentItem++;
          }

          // Calculate number of pages, current page, page links...
          people.append("<tr><td colspan=\"2\" align=\"center\" class=\"subTableFooter\">");
          // --------------------------------------------------------------------------------
          // Create base URL for each page
          StringBuffer baseUrl = new StringBuffer();
          baseUrl.append("people.jsp?");
          String actionString = (action.length() > 0) ? "action=" + action : "";
          String personIdString = (personid.length() > 0) ? "personid=" + personid : "";
          if (actionString.length() > 0)
              baseUrl.append(actionString);
          if (actionString.length() > 0 && personIdString.length() > 0)
              baseUrl.append("&");
          if (personIdString.length() > 0)
              baseUrl.append(personIdString);
          if (actionString.length() > 0 || personIdString.length() > 0)
              baseUrl.append("&");
          baseUrl.append("page=");
          people.append(createPageString(sortedAndFilteredKeys.size(), itemsToShowPerPage, currentPage,
                  baseUrl.toString()));
          people.append("</td></tr>");
          // --------------------------------------------------------------------------------
          people.append("</table>");
      } else {
          people.append("No user accounts were retrieved");
      }

      return people.toString();
  }

From source file:de.acosix.alfresco.mtsupport.repo.sync.TenantAwareChainingUserRegistrySynchronizer.java

protected Pair<Integer, Integer> processAuthorityDeletions(final String id, final String batchId,
        final UserRegistry userRegistry, final boolean isFullSync, final boolean splitTxns) {
    final String zoneId = asZoneId(id);
    final Set<String> groupsToDelete = new HashSet<>();
    final Set<String> usersToDelete = new HashSet<>();

    final Pair<Integer, Integer> counts = new Pair<>(Integer.valueOf(0), Integer.valueOf(0));
    if (isFullSync) {
        final Set<String> allZoneGroups = new TreeSet<>();
        final Set<String> allZoneUsers = this.personService.getUserNamesAreCaseSensitive() ? new TreeSet<>()
                : new TreeSet<>(String.CASE_INSENSITIVE_ORDER);

        this.inReadOnlyTransaction(() -> {
            allZoneGroups.addAll(this.authorityService.getAllAuthoritiesInZone(zoneId, AuthorityType.GROUP));
            allZoneUsers.addAll(this.authorityService.getAllAuthoritiesInZone(zoneId, AuthorityType.USER));
            return null;
        }, splitTxns);/*from  w  ww  . j  a va 2  s . c om*/

        groupsToDelete.addAll(allZoneGroups);
        groupsToDelete.removeAll(userRegistry.getGroupNames());

        usersToDelete.addAll(allZoneUsers);
        final String currentDomain = TenantUtil.getCurrentDomain();
        for (final String userName : userRegistry.getPersonNames()) {
            final String domainUser;
            final String primaryDomain = this.tenantService.getPrimaryDomain(userName);
            if (!EqualsHelper.nullSafeEquals(primaryDomain, currentDomain)) {
                domainUser = this.tenantService.getDomainUser(userName, currentDomain);
            } else {
                domainUser = userName;
            }
            usersToDelete.remove(domainUser);
        }

        final Set<String> authoritiesToDelete = new TreeSet<>();
        authoritiesToDelete.addAll(groupsToDelete);
        authoritiesToDelete.addAll(usersToDelete);

        if (!authoritiesToDelete.isEmpty() && (this.allowDeletions || this.syncDelete)) {
            @SuppressWarnings("deprecation")
            final BatchProcessor<String> deletionProcessor = new BatchProcessor<>(
                    SyncProcess.AUTHORITY_DELETION.getTitle(batchId),
                    this.transactionService.getRetryingTransactionHelper(), authoritiesToDelete,
                    this.workerThreads, USER_REGISTRY_ENTITY_BATCH_SIZE, this.applicationEventPublisher,
                    LogFactory.getLog(TenantAwareChainingUserRegistrySynchronizer.class), this.loggingInterval);

            final AuthorityDeleter deleter = new AuthorityDeleter(zoneId, groupsToDelete, usersToDelete,
                    this.allowDeletions, this.createComponentLookupCallback());
            deletionProcessor.process(deleter, splitTxns);

            counts.setFirst(Integer.valueOf(usersToDelete.size()));
            counts.setSecond(Integer.valueOf(groupsToDelete.size()));
        }
    }
    return counts;
}

From source file:com.lrodriguez.SVNBrowser.java

private Comparator persistSortBy(HttpServletRequest request) {
    HttpSession session = request.getSession();
    Comparator comparator = (Comparator) session.getAttribute(SORT_BY);
    if (request.getParameter(SORT_BY) == null) {
        if (session.getAttribute(SORT_BY) == null) {
            comparator = Sorter.DATE_REVERSE_COMPARATOR;//default
        }/*from  w  w w . ja  v  a  2 s.  com*/
    } else {
        if (session.getAttribute(SORT_BY) == null) {
            if ("togglePath".equals(request.getParameter(SORT_BY))) {
                comparator = Sorter.PATH_INSENSITIVE_REVERSE_COMPARATOR;
            } else if ("toggleAuthor".equals(request.getParameter(SORT_BY))) {
                comparator = String.CASE_INSENSITIVE_ORDER;
            } else {
                comparator = Sorter.DATE_REVERSE_COMPARATOR;//default
            }
        } else {
            if ("togglePath".equals(request.getParameter(SORT_BY))) {
                if (Sorter.PATH_INSENSITIVE_COMPARATOR.equals(comparator)) {
                    comparator = Sorter.PATH_INSENSITIVE_REVERSE_COMPARATOR;
                } else {
                    comparator = Sorter.PATH_INSENSITIVE_COMPARATOR;
                }
            } else if ("toggleAuthor".equals(request.getParameter(SORT_BY))) {
                if (Sorter.AUTHOR_COMPARATOR.equals(comparator)) {
                    comparator = Sorter.AUTHOR_REVERSE_COMPARATOR;
                } else {
                    comparator = Sorter.AUTHOR_COMPARATOR;
                }
            } else if ("toggleDate".equals(request.getParameter(SORT_BY))) {
                if (Sorter.DATE_COMPARATOR.equals(comparator)) {
                    comparator = Sorter.DATE_REVERSE_COMPARATOR;
                } else {
                    comparator = Sorter.DATE_COMPARATOR;
                }
            } else if ("toggleRevision".equals(request.getParameter(SORT_BY))) {
                if (Sorter.REV_COMPARATOR.equals(comparator)) {
                    comparator = Sorter.REV__REVERSE_COMPARATOR;
                } else {
                    comparator = Sorter.REV_COMPARATOR;
                }
            }
        }

    }
    session.setAttribute(SORT_BY, comparator);
    return comparator;
}

From source file:cgeo.geocaching.connector.gc.GCParser.java

public static List<PocketQueryList> searchPocketQueryList() {

    final Parameters params = new Parameters();

    final String page = GCLogin.getInstance().getRequestLogged("http://www.geocaching.com/pocket/default.aspx",
            params);/*from  www . j  av  a2 s  .  c o m*/

    if (StringUtils.isBlank(page)) {
        Log.e("GCParser.searchPocketQueryList: No data from server");
        return null;
    }

    String subPage = StringUtils.substringAfter(page, "class=\"PocketQueryListTable");
    if (StringUtils.isEmpty(subPage)) {
        Log.e("GCParser.searchPocketQueryList: class \"PocketQueryListTable\" not found on page");
        return Collections.emptyList();
    }

    List<PocketQueryList> list = new ArrayList<PocketQueryList>();

    final MatcherWrapper matcherPocket = new MatcherWrapper(GCConstants.PATTERN_LIST_PQ, subPage);

    while (matcherPocket.find()) {
        int maxCaches;
        try {
            maxCaches = Integer.parseInt(matcherPocket.group(1));
        } catch (NumberFormatException e) {
            maxCaches = 0;
            Log.e("GCParser.searchPocketQueryList: Unable to parse max caches", e);
        }
        final String guid = Html.fromHtml(matcherPocket.group(2)).toString();
        final String name = Html.fromHtml(matcherPocket.group(3)).toString();
        final PocketQueryList pqList = new PocketQueryList(guid, name, maxCaches);
        list.add(pqList);
    }

    // just in case, lets sort the resulting list
    Collections.sort(list, new Comparator<PocketQueryList>() {

        @Override
        public int compare(PocketQueryList left, PocketQueryList right) {
            return String.CASE_INSENSITIVE_ORDER.compare(left.getName(), right.getName());
        }
    });

    return list;
}

From source file:com.microsoft.tfs.core.clients.versioncontrol.Workstation.java

/**
 * Private method to remove from the cache workspaces associated with the
 * specified repository. It returns the WorkspaceInfo objects that are
 * removed from the cache./*from w  w w. j a  v  a 2 s . com*/
 */
private List<WorkspaceInfo> removeCachedWorkspaceInfo(final VersionControlClient client,
        final Workspace[] workspaces, final boolean saveConfigFile) {
    final Map<String, Workspace> workspacesDict = new TreeMap<String, Workspace>(String.CASE_INSENSITIVE_ORDER);

    for (final Workspace toBeRemoved : workspaces) {
        // We will look up in our hash table using
        // workspacename;workspaceowner.
        workspacesDict.put(toBeRemoved.getQualifiedName(), toBeRemoved);
    }

    final List<WorkspaceInfo> infoRemovedList = new ArrayList<WorkspaceInfo>();

    synchronized (cacheMutex) {
        final WorkspaceInfo[] allWorkspaceInfo = getAllLocalWorkspaceInfo();
        for (final WorkspaceInfo workspaceInfo : allWorkspaceInfo) {
            // The server match is by name or guid since the guid match
            // fails if the database is re-installed.
            if (Workspace.matchServerURI(workspaceInfo.getServerURI(), client.getConnection().getBaseURI())
                    || workspaceInfo.getServerGUID().equals(client.getServerGUID())) {
                // If the workspace was specified for removal, or if we
                // happen to find a workspace
                // whose URI matches ours but has a different server GUID,
                // remove it.
                if (workspacesDict.containsKey(workspaceInfo.getQualifiedName())
                        || !workspaceInfo.getServerGUID().equals(client.getServerGUID())) {
                    getCache().removeWorkspace(workspaceInfo);
                    infoRemovedList.add(workspaceInfo);
                }
            }
        }

        if (saveConfigFile) {
            saveConfigIfDirty();
        }
    }

    return infoRemovedList;
}

From source file:com.healthmarketscience.jackcess.Database.java

/**
 * @return The names of all of the user tables (String)
 * @usage _general_method_/*from   w w w .  j  a  v a  2s . com*/
 */
public Set<String> getTableNames() throws IOException {
    if (_tableNames == null) {
        Set<String> tableNames = new TreeSet<String>(String.CASE_INSENSITIVE_ORDER);
        _tableFinder.getTableNames(tableNames, false);
        _tableNames = tableNames;
    }
    return _tableNames;
}

From source file:com.healthmarketscience.jackcess.Database.java

/**
 * @return The names of all of the system tables (String).  Note, in order
 *         to read these tables, you must use {@link #getSystemTable}.
 *         <i>Extreme care should be taken if modifying these tables
 *         directly!</i>./*from  www  .  j  av  a 2 s .c o  m*/
 * @usage _intermediate_method_
 */
public Set<String> getSystemTableNames() throws IOException {
    Set<String> sysTableNames = new TreeSet<String>(String.CASE_INSENSITIVE_ORDER);
    _tableFinder.getTableNames(sysTableNames, true);
    return sysTableNames;
}

From source file:com.ichi2.anki.CardEditor.java

private void actualizeTagDialog(StyledDialog ad) {
    TreeSet<String> tags = new TreeSet<String>(String.CASE_INSENSITIVE_ORDER);
    for (String tag : mCol.getTags().all()) {
        tags.add(tag);/* ww  w. ja  v  a 2 s  . co m*/
    }
    tags.addAll(selectedTags);
    int len = tags.size();
    allTags = new String[len];
    boolean[] checked = new boolean[len];
    int i = 0;
    for (String t : tags) {
        allTags[i++] = t;
        if (selectedTags.contains(t)) {
            checked[i - 1] = true;
        }
    }
    ad.setMultiChoiceItems(allTags, checked, new DialogInterface.OnClickListener() {
        @Override
        public void onClick(DialogInterface arg0, int which) {
            String tag = allTags[which];
            if (selectedTags.contains(tag)) {
                Log.i(AnkiDroidApp.TAG, "unchecked tag: " + tag);
                selectedTags.remove(tag);
            } else {
                Log.i(AnkiDroidApp.TAG, "checked tag: " + tag);
                selectedTags.add(tag);
            }
        }
    });
}