Example usage for java.text Collator TERTIARY

List of usage examples for java.text Collator TERTIARY

Introduction

In this page you can find the example usage for java.text Collator TERTIARY.

Prototype

int TERTIARY

To view the source code for java.text Collator TERTIARY.

Click Source Link

Document

Collator strength value.

Usage

From source file:org.jahia.services.search.facets.SimpleJahiaJcrFacets.java

private NamedList<Object> sortValuesAfterChoiceListRenderer(NamedList<Object> values,
        ChoiceListRenderer renderer, ExtendedPropertyDefinition fieldPropertyType, Locale locale) {
    try {/*from  w w  w . j a  v  a  2s .  c o m*/
        //use case-insensitive and locale aware collator
        Collator collator = Collator.getInstance(locale);
        collator.setStrength(Collator.TERTIARY);
        Map<String, Integer> sortedLabels = new TreeMap<>(collator);
        int i = 0;
        boolean resolveReference = renderer instanceof NodeReferenceChoiceListRenderer ? true : false;
        JCRSessionWrapper currentUserSession = resolveReference
                ? JCRSessionFactory.getInstance().getCurrentUserSession(session.getWorkspace().getName(),
                        locale)
                : null;

        for (Map.Entry<String, Object> facetValueEntry : values) {
            String facetValueKey = facetValueEntry.getKey();
            sortedLabels.put(renderer.getStringRendering(locale, fieldPropertyType,
                    resolveReference
                            ? currentUserSession
                                    .getNode(StringUtils.substring(facetValueKey, facetValueKey.indexOf('/')))
                            : facetValueKey),
                    i++);
        }

        NamedList<Object> sortedValues = new NamedList<>();
        for (Integer index : sortedLabels.values()) {
            sortedValues.add(values.getName(index), values.getVal(index));
        }
        return sortedValues;
    } catch (RepositoryException | UnsupportedOperationException e) {
        logger.warn("Exception while sorting label rendered facet values, fallback to default sorting", e);
        return values;
    }
}