List of usage examples for java.text Collator getInstance
public static Collator getInstance(Locale desiredLocale)
From source file:com.jeans.iservlet.controller.impl.ExportController.java
/** * ?????/*from www . ja v a 2 s .co m*/ * * @param storedOnly * ??? * @return * @throws IOException */ @RequestMapping(method = RequestMethod.POST, value = "/accessories") public ResponseEntity<byte[]> exportAccessories(@RequestParam boolean storedOnly) throws IOException { StringBuilder fn = new StringBuilder(getCurrentCompany().getName()); Date n = new Date(); String today = (new SimpleDateFormat("yyyyMMdd")).format(n); String now = (new SimpleDateFormat("yyyy-MM-dd HHmmss")).format(n); Workbook wb = new XSSFWorkbook(); fn.append(" - ???(").append(today).append(").xlsx"); Sheet sheet = wb.createSheet(now); // // ?10?? Font font = wb.createFont(); font.setBoldweight(Font.BOLDWEIGHT_BOLD); font.setFontName(""); font.setFontHeightInPoints((short) 10); // ????????? CellStyle cellStyle = wb.createCellStyle(); cellStyle.setAlignment(CellStyle.ALIGN_CENTER); cellStyle.setVerticalAlignment(CellStyle.VERTICAL_CENTER); cellStyle.setFont(font); cellStyle.setDataFormat(HSSFDataFormat.getBuiltinFormat("text")); cellStyle.setWrapText(false); // 20 Row row = sheet.createRow(0); row.setHeightInPoints(20); Cell cell = null; for (int i = 0; i < 7; i++) { cell = row.createCell(i, Cell.CELL_TYPE_STRING); cell.setCellStyle(cellStyle); cell.setCellValue(ACS_HEADERS[i]); sheet.setColumnWidth(i, ACS_HEADERS_WIDTH[i] * 256); } List<Accessory> acs = acsService.listAccessories(getCurrentCompany(), storedOnly); Collections.sort(acs, new Comparator<Accessory>() { @Override public int compare(Accessory o1, Accessory o2) { int ret = o1.getType().compareTo(o2.getType()); if (ret == 0) { ret = Collator.getInstance(java.util.Locale.CHINA).compare(o1.getName(), o2.getName()); if (ret == 0) { ret = Collator.getInstance(java.util.Locale.CHINA).compare(o1.getBrand(), o2.getBrand()); if (ret == 0) { ret = Collator.getInstance(java.util.Locale.CHINA).compare(o1.getModel(), o2.getModel()); } } } return ret; } }); // DataFormat df = wb.createDataFormat(); // ?10? Font dFont = wb.createFont(); dFont.setFontName(""); dFont.setFontHeightInPoints((short) 10); // ?1??????? CellStyle cellStyleString = wb.createCellStyle(); cellStyleString.setAlignment(CellStyle.ALIGN_CENTER); cellStyleString.setVerticalAlignment(CellStyle.VERTICAL_CENTER); cellStyleString.setFont(dFont); cellStyleString.setDataFormat(HSSFDataFormat.getBuiltinFormat("text")); cellStyleString.setWrapText(false); // ?2??????(#)??? CellStyle cellStyleQuantity = sheet.getWorkbook().createCellStyle(); cellStyleQuantity.setAlignment(CellStyle.ALIGN_RIGHT); cellStyleQuantity.setVerticalAlignment(CellStyle.VERTICAL_CENTER); cellStyleQuantity.setFont(dFont); cellStyleQuantity.setDataFormat(df.getFormat("#")); cellStyleQuantity.setWrapText(false); int rowNumber = 1; for (Accessory ac : acs) { // 20 Row dRow = sheet.createRow(rowNumber); dRow.setHeightInPoints(20); Cell dCell = null; dCell = dRow.createCell(0, Cell.CELL_TYPE_STRING); dCell.setCellStyle(cellStyleString); dCell.setCellValue(ac.getType().getTitle()); dCell = dRow.createCell(1, Cell.CELL_TYPE_STRING); dCell.setCellStyle(cellStyleString); dCell.setCellValue(ac.getName()); dCell = dRow.createCell(2, Cell.CELL_TYPE_STRING); dCell.setCellStyle(cellStyleString); dCell.setCellValue(ac.getBrand()); dCell = dRow.createCell(3, Cell.CELL_TYPE_STRING); dCell.setCellStyle(cellStyleString); dCell.setCellValue(ac.getModel()); dCell = dRow.createCell(4, Cell.CELL_TYPE_NUMERIC); dCell.setCellStyle(cellStyleQuantity); dCell.setCellValue(null == ac.getStorage() ? 0 : ac.getStorage().getQuantity()); dCell = dRow.createCell(5, Cell.CELL_TYPE_STRING); dCell.setCellStyle(cellStyleString); dCell.setCellValue(ac.getUnit()); dCell = dRow.createCell(6, Cell.CELL_TYPE_STRING); dCell.setCellStyle(cellStyleString); dCell.setCellValue(ac.getDescription()); rowNumber++; } String filename = null; if (isIE()) { filename = URLEncoder.encode(fn.toString(), "UTF-8").replaceAll("\\+", "%20"); } else { filename = new String(fn.toString().getBytes("UTF-8"), "iso8859-1"); } response.setContentType("application/vnd.openxmlformats-officedocument.spreadsheetml.sheet"); response.setHeader("Content-disposition", "attachment; filename=" + filename); BufferedOutputStream out = new BufferedOutputStream(response.getOutputStream(), 4096); wb.write(out); wb.close(); out.close(); return null; }
From source file:net.ontopia.topicmaps.query.impl.basic.QueryProcessor.java
private Collator getCollator(String _locale) { Locale locale = getLocale(_locale); if (locale == null) return null; return Collator.getInstance(locale); }
From source file:com.flexive.shared.FxSharedUtils.java
/** * Returns a collator for the calling user's locale. * * @return a collator for the calling user's locale. *//* w w w . j ava 2 s. c om*/ public static Collator getCollator() { return Collator.getInstance(FxContext.getUserTicket().getLanguage().getLocale()); }
From source file:org.alfresco.repo.jscript.People.java
private List<NodeRef> getSortedPeopleObjects(List<NodeRef> peopleRefs, final String sortBy, Boolean sortAsc) { if (sortBy == null) { return peopleRefs; }// w w w. j a v a2s . com //make copy of peopleRefs because it can be unmodifiable list. List<NodeRef> sortedPeopleRefs = new ArrayList<NodeRef>(peopleRefs); final Collator col = Collator.getInstance(I18NUtil.getLocale()); final NodeService nodeService = services.getNodeService(); final int orderMultiplicator = ((sortAsc == null) || sortAsc) ? 1 : -1; Collections.sort(sortedPeopleRefs, new Comparator<NodeRef>() { @Override public int compare(NodeRef n1, NodeRef n2) { Serializable p1 = getProperty(n1); Serializable p2 = getProperty(n2); if ((p1 instanceof Long) && (p2 instanceof Long)) { return Long.compare((Long) p1, (Long) p2) * orderMultiplicator; } return col.compare(p1.toString(), p2) * orderMultiplicator; } public Serializable getProperty(NodeRef nodeRef) { Serializable result; if ("fullName".equalsIgnoreCase(sortBy)) { String firstName = (String) nodeService.getProperty(nodeRef, ContentModel.PROP_FIRSTNAME); String lastName = (String) nodeService.getProperty(nodeRef, ContentModel.PROP_LASTNAME); String fullName = firstName; if (lastName != null && lastName.length() > 0) { fullName = fullName + " " + lastName; } result = fullName; } else if ("jobtitle".equalsIgnoreCase(sortBy)) { result = nodeService.getProperty(nodeRef, ContentModel.PROP_JOBTITLE); } else if ("email".equalsIgnoreCase(sortBy)) { result = nodeService.getProperty(nodeRef, ContentModel.PROP_EMAIL); } else if ("usage".equalsIgnoreCase(sortBy)) { result = nodeService.getProperty(nodeRef, ContentModel.PROP_SIZE_CURRENT); } else if ("quota".equalsIgnoreCase(sortBy)) { result = nodeService.getProperty(nodeRef, ContentModel.PROP_SIZE_QUOTA); } else { // Default result = nodeService.getProperty(nodeRef, ContentModel.PROP_USERNAME); } if (result == null) { result = ""; } return result; } }); return sortedPeopleRefs; }
From source file:com.microsoft.tfs.client.eclipse.sync.SynchronizeSubscriber.java
/** * Given a list of paths, this will remove any duplicates. It uses a * Collator to detect duplicates for Unicode safety. * * @param paths//w w w . j a v a 2 s . co m * List of paths to uniqueify * @return List of unique paths specified */ private List<String> getUniquePaths(final List<String> paths) { final Collator collator = Collator.getInstance(Locale.US); final ArrayList<String> uniquePaths = new ArrayList<String>(); for (final String givenPath : paths) { boolean duplicate = false; for (final String existingPath : uniquePaths) { if (collator.compare(givenPath, existingPath) == 0) { duplicate = true; break; } } if (!duplicate) { uniquePaths.add(givenPath); } } return uniquePaths; }
From source file:com.chaqianma.jd.fragment.PersonalAssetsFragment.java
private void sortList(List<String> arrs) { Collections.sort(arrs, Collator.getInstance(java.util.Locale.CHINA)); }
From source file:com.chaqianma.jd.fragment.CompanyInfoFragment.java
/** * ?? * * @param arrs */ private void sortList(List<String> arrs) { Collections.sort(arrs, Collator.getInstance(java.util.Locale.CHINA)); }
From source file:org.apache.nifi.web.api.dto.DtoFactory.java
public ReportingTaskDTO createReportingTaskDto(final ReportingTaskNode reportingTaskNode) { final ReportingTaskDTO dto = new ReportingTaskDTO(); dto.setId(reportingTaskNode.getIdentifier()); dto.setName(reportingTaskNode.getName()); dto.setType(reportingTaskNode.getReportingTask().getClass().getName()); dto.setSchedulingStrategy(reportingTaskNode.getSchedulingStrategy().name()); dto.setSchedulingPeriod(reportingTaskNode.getSchedulingPeriod()); dto.setState(reportingTaskNode.getScheduledState().name()); dto.setActiveThreadCount(reportingTaskNode.getActiveThreadCount()); dto.setAnnotationData(reportingTaskNode.getAnnotationData()); dto.setComments(reportingTaskNode.getComments()); final Map<String, String> defaultSchedulingPeriod = new HashMap<>(); defaultSchedulingPeriod.put(SchedulingStrategy.TIMER_DRIVEN.name(), SchedulingStrategy.TIMER_DRIVEN.getDefaultSchedulingPeriod()); defaultSchedulingPeriod.put(SchedulingStrategy.CRON_DRIVEN.name(), SchedulingStrategy.CRON_DRIVEN.getDefaultSchedulingPeriod()); dto.setDefaultSchedulingPeriod(defaultSchedulingPeriod); // sort a copy of the properties final Map<PropertyDescriptor, String> sortedProperties = new TreeMap<>( new Comparator<PropertyDescriptor>() { @Override/*w w w .j a va 2 s.c om*/ public int compare(PropertyDescriptor o1, PropertyDescriptor o2) { return Collator.getInstance(Locale.US).compare(o1.getName(), o2.getName()); } }); sortedProperties.putAll(reportingTaskNode.getProperties()); // get the property order from the reporting task final ReportingTask reportingTask = reportingTaskNode.getReportingTask(); final Map<PropertyDescriptor, String> orderedProperties = new LinkedHashMap<>(); final List<PropertyDescriptor> descriptors = reportingTask.getPropertyDescriptors(); if (descriptors != null && !descriptors.isEmpty()) { for (PropertyDescriptor descriptor : descriptors) { orderedProperties.put(descriptor, null); } } orderedProperties.putAll(sortedProperties); // build the descriptor and property dtos dto.setDescriptors(new LinkedHashMap<String, PropertyDescriptorDTO>()); dto.setProperties(new LinkedHashMap<String, String>()); for (final Map.Entry<PropertyDescriptor, String> entry : orderedProperties.entrySet()) { final PropertyDescriptor descriptor = entry.getKey(); // store the property descriptor dto.getDescriptors().put(descriptor.getName(), createPropertyDescriptorDto(descriptor)); // determine the property value - don't include sensitive properties String propertyValue = entry.getValue(); if (propertyValue != null && descriptor.isSensitive()) { propertyValue = "********"; } // set the property value dto.getProperties().put(descriptor.getName(), propertyValue); } // add the validation errors final Collection<ValidationResult> validationErrors = reportingTaskNode.getValidationErrors(); if (validationErrors != null && !validationErrors.isEmpty()) { final List<String> errors = new ArrayList<>(); for (final ValidationResult validationResult : validationErrors) { errors.add(validationResult.toString()); } dto.setValidationErrors(errors); } return dto; }
From source file:org.apache.nifi.web.api.dto.DtoFactory.java
public ControllerServiceDTO createControllerServiceDto(final ControllerServiceNode controllerServiceNode) { final ControllerServiceDTO dto = new ControllerServiceDTO(); dto.setId(controllerServiceNode.getIdentifier()); dto.setName(controllerServiceNode.getName()); dto.setType(controllerServiceNode.getControllerServiceImplementation().getClass().getName()); dto.setState(controllerServiceNode.getState().name()); dto.setAnnotationData(controllerServiceNode.getAnnotationData()); dto.setComments(controllerServiceNode.getComments()); // sort a copy of the properties final Map<PropertyDescriptor, String> sortedProperties = new TreeMap<>( new Comparator<PropertyDescriptor>() { @Override/*w w w . j a va2s . co m*/ public int compare(PropertyDescriptor o1, PropertyDescriptor o2) { return Collator.getInstance(Locale.US).compare(o1.getName(), o2.getName()); } }); sortedProperties.putAll(controllerServiceNode.getProperties()); // get the property order from the controller service final ControllerService controllerService = controllerServiceNode.getControllerServiceImplementation(); final Map<PropertyDescriptor, String> orderedProperties = new LinkedHashMap<>(); final List<PropertyDescriptor> descriptors = controllerService.getPropertyDescriptors(); if (descriptors != null && !descriptors.isEmpty()) { for (PropertyDescriptor descriptor : descriptors) { orderedProperties.put(descriptor, null); } } orderedProperties.putAll(sortedProperties); // build the descriptor and property dtos dto.setDescriptors(new LinkedHashMap<String, PropertyDescriptorDTO>()); dto.setProperties(new LinkedHashMap<String, String>()); for (final Map.Entry<PropertyDescriptor, String> entry : orderedProperties.entrySet()) { final PropertyDescriptor descriptor = entry.getKey(); // store the property descriptor dto.getDescriptors().put(descriptor.getName(), createPropertyDescriptorDto(descriptor)); // determine the property value - don't include sensitive properties String propertyValue = entry.getValue(); if (propertyValue != null && descriptor.isSensitive()) { propertyValue = "********"; } // set the property value dto.getProperties().put(descriptor.getName(), propertyValue); } // create the reference dto's dto.setReferencingComponents( createControllerServiceReferencingComponentsDto(controllerServiceNode.getReferences())); // add the validation errors final Collection<ValidationResult> validationErrors = controllerServiceNode.getValidationErrors(); if (validationErrors != null && !validationErrors.isEmpty()) { final List<String> errors = new ArrayList<>(); for (final ValidationResult validationResult : validationErrors) { errors.add(validationResult.toString()); } dto.setValidationErrors(errors); } return dto; }
From source file:nz.ac.otago.psyanlab.common.designer.ExperimentDesignerActivity.java
Collator getCollater() { Locale locale = Locale.getDefault(); Collator collator = Collator.getInstance(locale); collator.setStrength(Collator.SECONDARY); return collator; }