Example usage for java.text Collator getInstance

List of usage examples for java.text Collator getInstance

Introduction

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

Prototype

public static synchronized Collator getInstance() 

Source Link

Document

Gets the Collator for the current default locale.

Usage

From source file:org.sakaiproject.assignment2.logic.utils.ComparatorsUtils.java

private static int sortByTitle(Assignment2 assign1, Assignment2 assign2) {
    String title1 = assign1.getTitle() != null ? assign1.getTitle() : "";
    String title2 = assign2.getTitle() != null ? assign2.getTitle() : "";
    return Collator.getInstance().compare(title1, title2);
}

From source file:org.fao.geonet.component.csw.GetDomain.java

public static List<Element> handlePropertyName(CatalogConfiguration catalogConfig, String[] propertyNames,
        ServiceContext context, boolean freq, int maxRecords, String cswServiceSpecificConstraint,
        LuceneConfig luceneConfig) throws Exception {

    List<Element> domainValuesList = new ArrayList<Element>();

    if (Log.isDebugEnabled(Geonet.CSW))
        Log.debug(Geonet.CSW, "Handling property names '" + Arrays.toString(propertyNames)
                + "' with max records of " + maxRecords);

    for (int i = 0; i < propertyNames.length; i++) {

        // Initialize list of values element.
        Element listOfValues = null;

        // Generate DomainValues element
        Element domainValues = new Element("DomainValues", Csw.NAMESPACE_CSW);

        // FIXME what should be the type ???
        domainValues.setAttribute("type", "csw:Record");

        String property = propertyNames[i].trim();

        // Set propertyName in any case.
        Element pn = new Element("PropertyName", Csw.NAMESPACE_CSW);
        domainValues.addContent(pn.setText(property));

        GeonetContext gc = (GeonetContext) context.getHandlerContext(Geonet.CONTEXT_NAME);
        SearchManager sm = gc.getBean(SearchManager.class);

        IndexAndTaxonomy indexAndTaxonomy = sm.getNewIndexReader(null);
        try {//from   ww  w .j  a  v a2s .  c  om
            GeonetworkMultiReader reader = indexAndTaxonomy.indexReader;
            BooleanQuery groupsQuery = (BooleanQuery) CatalogSearcher.getGroupsQuery(context);
            BooleanQuery query = null;

            // Apply CSW service specific constraint
            if (StringUtils.isNotEmpty(cswServiceSpecificConstraint)) {
                Query constraintQuery = CatalogSearcher
                        .getCswServiceSpecificConstraintQuery(cswServiceSpecificConstraint, luceneConfig);

                query = new BooleanQuery();

                BooleanClause.Occur occur = LuceneUtils.convertRequiredAndProhibitedToOccur(true, false);

                query.add(groupsQuery, occur);
                query.add(constraintQuery, occur);

            } else {
                query = groupsQuery;
            }

            List<Pair<String, Boolean>> sortFields = Collections
                    .singletonList(Pair.read(Geonet.SearchResult.SortBy.RELEVANCE, true));
            Sort sort = LuceneSearcher.makeSort(sortFields, context.getLanguage(), false);
            CachingWrapperFilter filter = null;

            Pair<TopDocs, Element> searchResults = LuceneSearcher.doSearchAndMakeSummary(maxRecords, 0,
                    maxRecords, context.getLanguage(), null, luceneConfig, reader, query, filter, sort, null,
                    false);
            TopDocs hits = searchResults.one();

            try {
                // Get mapped lucene field in CSW configuration
                String indexField = catalogConfig.getFieldMapping().get(property.toLowerCase());
                if (indexField != null)
                    property = indexField;

                // check if params asked is in the index using getFieldNames ?
                @SuppressWarnings("resource")
                FieldInfos fi = SlowCompositeReaderWrapper.wrap(reader).getFieldInfos();
                if (fi.fieldInfo(property) == null)
                    continue;

                boolean isRange = false;
                if (catalogConfig.getGetRecordsRangeFields().contains(property))
                    isRange = true;

                if (isRange)
                    listOfValues = new Element("RangeOfValues", Csw.NAMESPACE_CSW);
                else
                    listOfValues = new Element("ListOfValues", Csw.NAMESPACE_CSW);

                Set<String> fields = new HashSet<String>();
                fields.add(property);
                fields.add("_isTemplate");

                // parse each document in the index
                String[] fieldValues;
                Collator stringCollator = Collator.getInstance();
                stringCollator.setStrength(Collator.PRIMARY);
                SortedSet<String> sortedValues = new TreeSet<String>(stringCollator);
                ObjectKeyIntOpenHashMap duplicateValues = new ObjectKeyIntOpenHashMap();
                for (int j = 0; j < hits.scoreDocs.length; j++) {
                    DocumentStoredFieldVisitor selector = new DocumentStoredFieldVisitor(fields);
                    reader.document(hits.scoreDocs[j].doc, selector);
                    Document doc = selector.getDocument();

                    // Skip templates and subTemplates
                    String[] isTemplate = doc.getValues("_isTemplate");
                    if (isTemplate[0] != null && !isTemplate[0].equals("n"))
                        continue;

                    // Get doc values for specified property
                    fieldValues = doc.getValues(property);
                    if (fieldValues == null)
                        continue;

                    addtoSortedSet(sortedValues, fieldValues, duplicateValues);
                }

                SummaryComparator valuesComparator = new SummaryComparator(SortOption.FREQUENCY, Type.STRING,
                        context.getLanguage(), null);
                TreeSet<SummaryComparator.SummaryElement> sortedValuesFrequency = new TreeSet<SummaryComparator.SummaryElement>(
                        valuesComparator);
                ObjectKeyIntMapIterator entries = duplicateValues.entries();

                while (entries.hasNext()) {
                    entries.next();
                    sortedValuesFrequency.add(new SummaryComparator.SummaryElement(entries));
                }

                if (freq)
                    return createValuesByFrequency(sortedValuesFrequency);
                else
                    listOfValues.addContent(createValuesElement(sortedValues, isRange));

            } finally {
                // any children means that the catalog was unable to determine
                // anything about the specified parameter
                if (listOfValues != null && listOfValues.getChildren().size() != 0)
                    domainValues.addContent(listOfValues);

                // Add current DomainValues to the list
                domainValuesList.add(domainValues);
            }
        } finally {
            sm.releaseIndexReader(indexAndTaxonomy);
        }
    }
    return domainValuesList;

}

From source file:com.architexa.diagrams.relo.parts.MoreItemsEditPart.java

private void buildMoreChildrenContextMenu(IMenuManager menu) {
    Map<String, Artifact> strToCUMap = getChildToLabelMap();
    String[] strArray = strToCUMap.keySet().toArray(new String[] {});
    Arrays.sort(strArray, Collator.getInstance());

    List<String> childList = new ArrayList<String>(Arrays.asList(strArray));
    List<String> tempList = new ArrayList<String>(Arrays.asList(strArray));
    boolean createMultipleMenus = childList.size() > MAX_LENGTH ? true : false;
    Iterator<String> itr = tempList.iterator();
    final List<ArtifactFragment> allAFsAdded = new ArrayList<ArtifactFragment>();
    while (!childList.isEmpty()) {
        String menuStrStart = childList.get(0);
        MenuManager subMenu;//from  w ww  .  j a  va2 s . c om

        if (createMultipleMenus) {
            subMenu = new MenuManager(menuStrStart + " - ...");
            subMenu.add(new Separator("main"));
            menu.add(subMenu);
        } else
            subMenu = (MenuManager) menu;
        int i = 0;
        while (i < MAX_LENGTH && itr.hasNext()) {
            String extraActionLbl = itr.next();
            childList.remove(extraActionLbl);
            MultiAddCommandAction action = getMultiAddCommandAction(extraActionLbl, strToCUMap, allAFsAdded);
            subMenu.appendToGroup("main", action);
            i++;
        }
    }
}

From source file:net.sourceforge.fenixedu.presentationTier.Action.publico.teachersBody.ShowTeachersBodyDispatchAction.java

public ActionForward showProfessorshipsByExecutionDegree(ActionMapping mapping, ActionForm actionForm,
        HttpServletRequest request, HttpServletResponse response) throws FenixActionException {

    DynaActionForm executionDegreeForm = (DynaActionForm) actionForm;
    String executionDegreeId = (String) executionDegreeForm.get("executionDegreeId");

    Integer semester = (Integer) executionDegreeForm.get("semester");
    Integer teacherType = (Integer) executionDegreeForm.get("teacherType");
    String searchDetails = (String) executionDegreeForm.get("searchDetails");
    try {/*from  w w  w .  ja v  a2  s . com*/

        List detailedProfessorShipsListofLists = ReadProfessorshipsAndResponsibilitiesByExecutionDegreeAndExecutionPeriod
                .run(executionDegreeId, semester, teacherType);

        if ((detailedProfessorShipsListofLists != null) && (!detailedProfessorShipsListofLists.isEmpty())) {

            Collections.sort(detailedProfessorShipsListofLists, new Comparator() {

                @Override
                public int compare(Object o1, Object o2) {

                    List list1 = (List) o1;
                    List list2 = (List) o2;
                    DetailedProfessorship dt1 = (DetailedProfessorship) list1.iterator().next();
                    DetailedProfessorship dt2 = (DetailedProfessorship) list2.iterator().next();

                    return Collator.getInstance().compare(
                            dt1.getInfoProfessorship().getInfoExecutionCourse().getNome(),
                            dt2.getInfoProfessorship().getInfoExecutionCourse().getNome());
                }

            });

            request.setAttribute("detailedProfessorShipsListofLists", detailedProfessorShipsListofLists);
        }

        InfoExecutionDegree degree = ReadExecutionDegreeByOID.run(executionDegreeId);

        request.setAttribute("searchType", "Consulta Por Curso");
        request.setAttribute("searchTarget",
                degree.getInfoDegreeCurricularPlan().getInfoDegree().getDegreeType() + " em "
                        + degree.getInfoDegreeCurricularPlan().getInfoDegree().getNome());
        request.setAttribute("searchDetails", searchDetails);
        request.setAttribute("semester", semester);
        request.setAttribute("teacherType", teacherType);
        request.setAttribute("executionDegree", degree);

    } catch (FenixServiceException e) {
        throw new FenixActionException(e);
    }

    return mapping.findForward("showProfessorships");
}

From source file:edu.cornell.mannlib.vitro.webapp.dao.jena.VitroJenaSDBModelMaker.java

private ExtendedIterator<String> listModelNames(Model metadataModel) {
    Set<String> modelNameSet = new HashSet<String>();

    Iterator<RDFNode> metadataNameIt = metadataModel
            .listObjectsOfProperty(metadataModel.getProperty(HAS_NAMED_MODEL_URI));
    while (metadataNameIt.hasNext()) {
        RDFNode rdfNode = metadataNameIt.next();
        if (rdfNode.isLiteral()) {
            modelNameSet.add(((Literal) rdfNode).getLexicalForm());
        }//from  www . j  ava 2  s .c  o  m
    }

    Iterator<Node> storeNameIt = StoreUtils.storeGraphNames(getStore());
    while (storeNameIt.hasNext()) {
        Node node = storeNameIt.next();
        modelNameSet.add(node.getURI());
    }

    List<String> modelNameList = new ArrayList<String>();
    modelNameList.addAll(modelNameSet);
    Collections.sort(modelNameList, Collator.getInstance());

    return WrappedIterator.create(modelNameList.iterator());
}

From source file:org.sakaiproject.assignment2.logic.utils.ComparatorsUtils.java

private static int sortByName(AssignmentSubmission submission1, AssignmentSubmission submission2) {
    String sortName1 = null;//from w  ww  .  j  a v  a2  s .c  o  m
    String sortName2 = null;
    try {
        User u1 = UserDirectoryService.getUser(submission1.getUserId());
        sortName1 = u1.getSortName() != null ? u1.getSortName() : "";
    } catch (UserNotDefinedException unde) {
        log.error("user with id " + submission1.getUserId() + " not defined");
    }

    try {
        User u2 = UserDirectoryService.getUser(submission2.getUserId());
        sortName2 = u2.getSortName() != null ? u2.getSortName() : "";

    } catch (UserNotDefinedException unde) {
        log.error("user with id " + submission2.getUserId() + " not defined");
    }

    return Collator.getInstance().compare(sortName1, sortName2);
}

From source file:org.nimbustools.messaging.query.security.QueryAuthenticationFilter.java

private String getStringToSign_v1(HttpServletRequest request) {

    // Request must mapped to into a canonical string format. See:
    // http://docs.amazonwebservices.com/AWSEC2/latest/DeveloperGuide/using-query-api.html#query-authentication

    final StringBuilder buf = new StringBuilder();

    Collator stringCollator = Collator.getInstance();
    stringCollator.setStrength(Collator.PRIMARY);

    final Set<String> sortedKeys = new TreeSet<String>(stringCollator);

    final Enumeration paramNames = request.getParameterNames();
    while (paramNames.hasMoreElements()) {
        String param = (String) paramNames.nextElement();

        // don't include signature in canonical query string
        if (!param.equals(this.signatureParameter)) {
            sortedKeys.add(param);//from  w  w  w  . ja va2  s. c  o m
        }
    }
    for (String key : sortedKeys) {
        String[] values = request.getParameterValues(key);

        for (String val : values) {
            buf.append(key).append(val);
        }
    }
    return buf.toString();
}

From source file:com.architexa.diagrams.relo.parts.MoreItemsEditPart.java

public List<MultiAddCommandAction> getAllMemberMenuActions() {
    Map<String, Artifact> strToCUMap = getChildToLabelMap();

    String[] strArray = strToCUMap.keySet().toArray(new String[] {});
    Arrays.sort(strArray, Collator.getInstance());

    final List<ArtifactFragment> allAFsAdded = new ArrayList<ArtifactFragment>();
    List<MultiAddCommandAction> addActions = new ArrayList<MultiAddCommandAction>();
    for (String extraActionLbl : strArray) {
        MultiAddCommandAction action = getMultiAddCommandAction(extraActionLbl, strToCUMap, allAFsAdded);
        addActions.add(action);/*  w ww.  ja  v a  2 s .  c o m*/
    }

    EditDomain editDomain = getRoot().getViewer().getEditDomain();

    // when using a view (views not supported byu exploration server)
    if (!(editDomain instanceof DefaultEditDomain))
        return addActions;

    RSEEditor editor = (RSEEditor) ((DefaultEditDomain) editDomain).getEditorPart();
    if (editor.rseInjectableOICMenuController.createMenu(addActions, this))
        return null;
    return addActions;
}

From source file:net.ontopia.topicmaps.nav2.impl.basic.NavigatorConfiguration.java

@Override
public List getPluginGroups() {
    // gather all different groups
    Set groups = new HashSet();
    Iterator it = plugins.values().iterator();
    while (it.hasNext()) {
        PluginIF plugin = (PluginIF) it.next();
        groups.addAll(plugin.getGroups());
    }//from   ww  w.  j  av  a 2  s  .co m
    // sort the groups alphabetically
    List allGroups = new ArrayList(groups);
    Comparator comparator = Collator.getInstance();
    Collections.sort(allGroups, comparator);
    return allGroups;
}

From source file:com.microsoft.tfs.client.common.ui.controls.connect.ServerTypeSelectControl.java

private void populateServersCombo() {
    final ServerList serverList = ServerListManagerFactory
            .getServerListProvider(DefaultPersistenceStoreProvider.INSTANCE).getServerList();

    final Set<ServerListConfigurationEntry> servers = serverList.getServers();
    final List<String> list = new ArrayList<String>(servers.size());
    for (final ServerListConfigurationEntry entry : servers) {
        list.add(entry.getURI().toString());
    }//from   www.  ja  va  2s .  c om
    Collections.sort(list, Collator.getInstance());
    serverCombo.setItems(list.toArray(new String[list.size()]));
    proposalProvider.setProposals(list);
}