List of usage examples for org.apache.commons.lang3 StringUtils chop
public static String chop(final String str)
Remove the last character from a String.
If the String ends in \r\n , then remove both of them.
StringUtils.chop(null) = null StringUtils.chop("") = "" StringUtils.chop("abc \r") = "abc " StringUtils.chop("abc\n") = "abc" StringUtils.chop("abc\r\n") = "abc" StringUtils.chop("abc") = "ab" StringUtils.chop("abc\nabc") = "abc\nab" StringUtils.chop("a") = "" StringUtils.chop("\r") = "" StringUtils.chop("\n") = "" StringUtils.chop("\r\n") = ""
From source file:org.kalypso.zml.ui.table.nat.tooltip.ZmlTableTooltip.java
private String getSourceTooltip(final IZmlModelValueCell cell) { final StringBuffer buffer = new StringBuffer(); try {// ww w . j av a 2s . c o m final Object value = cell.getValue(); final boolean aggregated = isAggregated(); if (!aggregated) buffer.append(buildInfoText(Messages.ZmlTableTooltip_3, value.toString())); final Integer status = cell.getStatus(); if (Objects.isNotNull(status) && !aggregated) buffer.append(buildInfoText(Messages.ZmlTableTooltip_4, getStatus(status))); final String source = cell.getDataSource(); if (Objects.isNotNull(source)) buffer.append(buildInfoText(Messages.ZmlTableTooltip_5, source)); final String href = cell.getHref(); if (Objects.isNotNull(href)) buffer.append(buildInfoText(Messages.ZmlTableTooltip_6, href)); } catch (final SensorException e) { KalypsoZmlUI.getDefault().getLog().log(StatusUtilities.statusFromThrowable(e)); } return StringUtils.chop(buffer.toString()); }
From source file:org.ligoj.app.plugin.id.resource.batch.AbstractBatchResource.java
protected <T extends AbstractBatchTask<B>> long batchInternal(final InputStream uploadedFile, final String[] columns, final String encoding, final String[] defaultColumns, final Class<B> batchType, final Class<T> taskType, final Boolean quiet) throws IOException { // Public identifier is based on system date final long id = System.currentTimeMillis(); // Check column's name validity final String[] sanitizeColumns = ArrayUtils.isEmpty(columns) ? defaultColumns : columns; checkHeaders(defaultColumns, sanitizeColumns); // Build CSV header from array final String csvHeaders = StringUtils.chop(ArrayUtils.toString(sanitizeColumns)).substring(1).replace(',', ';') + "\n"; // Build entries with prepended CSV header final String encSafe = ObjectUtils.defaultIfNull(encoding, StandardCharsets.UTF_8.name()); final ByteArrayInputStream input = new ByteArrayInputStream(csvHeaders.getBytes(encSafe)); final List<B> entries = csvForBean.toBean(batchType, new InputStreamReader(new SequenceInputStream(input, uploadedFile), encSafe)); entries.removeIf(Objects::isNull); // Validate them validator.validateCheck(entries);// w ww. j a v a2 s . c o m // Clone the context for the asynchronous import final BatchTaskVo<B> importTask = new BatchTaskVo<>(); importTask.setEntries(entries); importTask.setPrincipal(SecurityContextHolder.getContext().getAuthentication().getName()); importTask.setId(id); importTask.setQuiet(BooleanUtils.isTrue(quiet)); // Schedule the import final T task = SpringUtils.getBean(taskType); task.configure(importTask); executor.execute(task); // Also cleanup the previous tasks cleanup(); // Expose the task with internal identifier, based on current user PLUS the public identifier imports.put(importTask.getPrincipal() + "-" + importTask.getId(), importTask); // Return private task identifier return id; }
From source file:org.opennms.tools.jmxconfiggenerator.helper.NameTools.java
public static String trimByCamelCase(String name, Integer maxLength) { String result = ""; String[] nameParts = StringUtils.splitByCharacterTypeCamelCase(name); Integer charsOver = name.length() - maxLength; for (int i = 0; i < charsOver; i++) { Integer largest = 0;/*from w ww . j av a 2s .c o m*/ Integer index = 0; for (int j = 0; j < nameParts.length; j++) { if (nameParts[j].length() > largest) { largest = nameParts[j].length(); index = j; } } nameParts[index] = StringUtils.chop(nameParts[index]); } for (String namePart : nameParts) { result = result + namePart; } return result; }
From source file:org.xwiki.extension.repository.xwiki.internal.XWikiExtensionRepository.java
public XWikiExtensionRepository(ExtensionRepositoryDescriptor repositoryDescriptor, XWikiExtensionRepositoryFactory repositoryFactory, ExtensionLicenseManager licenseManager, HttpClientFactory httpClientFactory) throws Exception { super(repositoryDescriptor.getURI().getPath().endsWith("/") ? new DefaultExtensionRepositoryDescriptor(repositoryDescriptor.getId(), repositoryDescriptor.getType(), new URI(StringUtils.chop(repositoryDescriptor.getURI().toString()))) : repositoryDescriptor);//from w ww.java 2 s . c o m this.repositoryFactory = repositoryFactory; this.licenseManager = licenseManager; this.httpClientFactory = httpClientFactory; // Uri builders this.rootUriBuider = createUriBuilder(Resources.ENTRYPOINT); this.extensionVersionUriBuider = createUriBuilder(Resources.EXTENSION_VERSION); this.extensionVersionFileUriBuider = createUriBuilder(Resources.EXTENSION_VERSION_FILE); this.extensionVersionsUriBuider = createUriBuilder(Resources.EXTENSION_VERSIONS); this.searchUriBuider = createUriBuilder(Resources.SEARCH); // Setup preemptive authentication if (getDescriptor().getProperty("auth.user") != null) { // Create AuthCache instance AuthCache authCache = new BasicAuthCache(); // Generate BASIC scheme object and add it to the local // auth cache BasicScheme basicAuth = new BasicScheme(); authCache.put(new HttpHost(getDescriptor().getURI().getHost(), getDescriptor().getURI().getPort(), getDescriptor().getURI().getScheme()), basicAuth); // Add AuthCache to the execution context this.localContext = HttpClientContext.create(); this.localContext.setAuthCache(authCache); } }
From source file:ubic.gemma.core.apps.ArrayDesignSequenceAssociationCli.java
@SuppressWarnings("static-access") @Override// www . j a va 2s . c om protected void buildOptions() { super.buildOptions(); Option fileOption = Option.builder("f").argName("Input sequence file").hasArg().desc("Path to file (FASTA)") .longOpt("file").build(); this.addOption(fileOption); Option sequenceIdentifierOption = Option.builder("i").argName("Input identifier file").hasArg() .desc("Path to file (two columns with probe ids and sequence accessions)").longOpt("ids").build(); this.addOption(sequenceIdentifierOption); StringBuilder buf = new StringBuilder(); for (String lit : SequenceType.literals()) { buf.append(lit).append("\n"); } String seqtypes = buf.toString(); seqtypes = StringUtils.chop(seqtypes); Option sequenceTypeOption = Option.builder("y").required().argName("Sequence type").hasArg().desc(seqtypes) .longOpt("type").build(); this.addOption(sequenceTypeOption); this.addOption(Option.builder("s").argName("accession").desc("A single accession to update") .longOpt("sequence").build()); Option forceOption = Option.builder("force").desc( "Force overwriting of existing sequences; If biosequences are encountered that already have sequences filled in, " + "they will be overwritten; default is to leave them.") .build(); this.addOption(forceOption); Option taxonOption = Option.builder("t").argName("taxon") .desc("Taxon common name (e.g., human) for sequences (only required if array design is 'naive')") .build(); this.addOption(taxonOption); }
From source file:yoyo.framework.enterprise.domain.ConstraintsException.java
/** {@inheritDoc} */ @Override// www. j av a 2 s. co m public String getLocalizedMessage() { final Map<String, Object[]> causeMap = getCauseMap(); final StrBuilder builder = new StrBuilder(); for (final Entry<String, Object[]> entry : causeMap.entrySet()) { builder.appendln(EnterpriseBundle.formatMessage(entry.getKey(), entry.getValue())); } return StringUtils.chop(builder.toString()); }