List of usage examples for org.apache.commons.lang3 StringUtils trimToNull
public static String trimToNull(final String str)
Removes control characters (char <= 32) from both ends of this String returning null if the String is empty ("") after the trim or if it is null .
From source file:com.intuit.karate.cucumber.KarateJunitFormatter.java
@Override public void done() { try {//from ww w . ja v a 2 s.co m String featureName = StringUtils.trimToNull(testCase.feature.getName()); if (featureName == null) { featureName = featurePath; } rootElement.setAttribute("name", featureName); testCount = Integer.valueOf(rootElement.getAttribute("tests")); failCount = rootElement.getElementsByTagName("failure").getLength(); rootElement.setAttribute("failures", String.valueOf(failCount)); skipCount = rootElement.getElementsByTagName("skipped").getLength(); rootElement.setAttribute("skipped", String.valueOf(skipCount)); timeTaken = sumTimes(rootElement.getElementsByTagName("testcase")); rootElement.setAttribute("time", formatTime(timeTaken)); printStatsToConsole(); if (rootElement.getElementsByTagName("testcase").getLength() == 0) { addDummyTestCase(); // to avoid failed Jenkins jobs } TransformerFactory transfac = TransformerFactory.newInstance(); Transformer trans = transfac.newTransformer(); trans.setOutputProperty(OutputKeys.INDENT, "yes"); StreamResult result = new StreamResult(out); DOMSource source = new DOMSource(doc); trans.transform(source, result); } catch (TransformerException e) { throw new CucumberException("Error while transforming.", e); } logger.trace("<< {}", reportPath); }
From source file:com.esri.geoportal.commons.agp.client.AgpClient.java
/** * Adds item./*from w w w.j a va 2 s . com*/ * @param owner user name * @param folderId folder id (optional) * @param title title * @param description description * @param url URL * @param thumbnailUrl thumbnail url * @param itemType item type (must be a URL type) * @param extent extent * @param typeKeywords type keywords * @param tags tags tags * @param token token * @return add item response * @throws URISyntaxException if invalid URL * @throws IOException if operation fails */ public ItemResponse addItem(String owner, String folderId, String title, String description, URL url, URL thumbnailUrl, ItemType itemType, Double[] extent, String[] typeKeywords, String[] tags, String token) throws IOException, URISyntaxException { URIBuilder builder = new URIBuilder(addItemUri(owner, StringUtils.trimToNull(folderId))); HttpPost req = new HttpPost(builder.build()); HashMap<String, String> params = new HashMap<>(); params.put("f", "json"); params.put("title", title); params.put("description", description); params.put("type", itemType.getTypeName()); params.put("url", url.toExternalForm()); if (thumbnailUrl != null) { params.put("thumbnailurl", thumbnailUrl.toExternalForm()); } if (extent != null && extent.length == 4) { params.put("extent", Arrays.asList(extent).stream().map(Object::toString).collect(Collectors.joining(","))); } if (typeKeywords != null) { params.put("typeKeywords", Arrays.asList(typeKeywords).stream().collect(Collectors.joining(","))); } if (tags != null) { params.put("tags", Arrays.asList(tags).stream().collect(Collectors.joining(","))); } params.put("token", token); req.setEntity(createEntity(params)); return execute(req, ItemResponse.class); }
From source file:alfio.manager.SpecialPriceManager.java
public boolean sendCodeToAssignee(List<SendCodeModification> input, String eventName, int categoryId, String username) {//from w w w . j av a 2 s.c om final Event event = eventManager.getSingleEvent(eventName, username); final Organization organization = eventManager.loadOrganizer(event, username); Set<SendCodeModification> set = new LinkedHashSet<>(input); checkCodeAssignment(set, categoryId, event, username); Validate.isTrue(set.stream().allMatch(IS_CODE_PRESENT), "There are missing codes. Please check input file."); List<ContentLanguage> eventLanguages = i18nManager.getEventLanguages(event.getLocales()); Validate.isTrue(!eventLanguages.isEmpty(), "No locales have been defined for the event. Please check the configuration"); ContentLanguage defaultLocale = eventLanguages.contains(ContentLanguage.ENGLISH) ? ContentLanguage.ENGLISH : eventLanguages.get(0); set.forEach(m -> { Locale locale = Locale.forLanguageTag(StringUtils.defaultString(StringUtils.trimToNull(m.getLanguage()), defaultLocale.getLanguage())); Map<String, Object> model = TemplateResource.prepareModelForSendReservedCode(organization, event, m, eventManager.getEventUrl(event)); notificationManager.sendSimpleEmail(event, m.getEmail(), messageSource.getMessage("email-code.subject", new Object[] { event.getDisplayName() }, locale), () -> templateManager.renderTemplate(event, TemplateResource.SEND_RESERVED_CODE, model, locale)); int marked = specialPriceRepository.markAsSent(ZonedDateTime.now(event.getZoneId()), m.getAssignee().trim(), m.getEmail().trim(), m.getCode().trim()); Validate.isTrue(marked == 1, "Expected exactly one row updated, got " + marked); }); return true; }
From source file:com.squarespace.template.plugins.platform.SocialFormatters.java
private static String getLocationString(JsonNode location) { StringBuilder sb = new StringBuilder(); String addressLine1 = location.path("addressLine1").asText(); String addressLine2 = location.path("addressLine2").asText(); String addressCountry = location.path("addressCountry").asText(); if (StringUtils.trimToNull(addressLine1) != null) { sb.append(addressLine1);/* w ww . j a v a 2 s. co m*/ } if (StringUtils.trimToNull(addressLine2) != null) { if (sb.length() > 0) { sb.append(", "); } sb.append(addressLine2); } if (StringUtils.trimToNull(addressCountry) != null) { if (sb.length() > 0) { sb.append(", "); } sb.append(addressCountry); } return sb.toString(); }
From source file:com.moviejukebox.tools.PropertiesUtil.java
/** * Look for both keys in the property list and warn if the old one was found * * @param newKey/* w w w . j a v a 2 s. co m*/ * @param oldKey * @return */ private static String getReplacedKeyValue(String newKey, String oldKey) { String oldProperty = StringUtils.trimToNull(PROPS.getProperty(oldKey)); String newProperty = StringUtils.trimToNull(PROPS.getProperty(newKey)); String returnValue; if (newProperty == null && oldProperty != null) { // We found the old property, but not the new LOG.warn("Property '{}' has been deprecated and will be removed; please use '{}' instead.", oldKey, newKey); returnValue = oldProperty; } else if (newProperty != null && oldProperty != null) { // We found both properties, so warn about the old one LOG.warn( "Property '{}' is no longer used, but was found in your configuration files, please remove it.", oldKey); returnValue = newProperty; } else { returnValue = newProperty; } return returnValue; }
From source file:com.webbfontaine.valuewebb.utils.TTMailUtils.java
public List<String> getSMSRecepientsForResponseOk() { StringBuilder smsRecepients = new StringBuilder(SMS_BODY_LENGTH); if (ApplicationProperties.isApplicantSMSEnabled()) { if (!StringUtils.isEmpty(ttGen.getAppTel())) { smsRecepients.append(ttGen.getAppTel()).append(','); }// w w w .jav a2 s.c o m } if (ApplicationProperties.isImporterSMSEnabled()) { Company company = loadCompany(); if (company != null) { String tel = company.getTel(); if (!StringUtils.isEmpty(tel)) { smsRecepients.append(tel).append(','); } } } if (StringUtils.trimToNull(ApplicationProperties.getAdditionalSmsList()) != null) { smsRecepients.append(Arrays.asList(ApplicationProperties.getAdditionalSmsList())); } return extractRecepients(smsRecepients.toString()); }
From source file:com.norconex.collector.http.url.impl.GenericCanonicalLinkDetector.java
@Override public void loadFromXML(Reader in) throws IOException { XMLConfiguration xml = ConfigurationUtil.newXMLConfiguration(in); ContentType[] cts = ContentType/*from w w w.j av a 2 s . c o m*/ .valuesOf(StringUtils.split(StringUtils.trimToNull(xml.getString("contentTypes")), ", ")); if (!ArrayUtils.isEmpty(cts)) { setContentTypes(cts); } }
From source file:eu.chocolatejar.eclipse.plugin.cleaner.Main.java
/** * Returns a command line option or a default value if the value is empty or * <code>null</code>.//from w w w. j a va 2 s . c om * * @param option * command line option, for example --source * @param defautlValue * @return never <code>null</code>, unless default value is * <code>null</code> */ String getParam(String option, String defautlValue) { String returnValue = null; if (input.hasOption(option)) { returnValue = StringUtils.trimToNull(input.getOptionValue(option)); } if (returnValue != null) { return returnValue; } return defautlValue; }
From source file:ltistarter.lti.LTIRequest.java
/** * @param paramName the request parameter name * @return the value of the parameter OR null if there is none */// ww w . j a v a 2 s .c o m public String getParam(String paramName) { String value = null; if (this.httpServletRequest != null && paramName != null) { value = StringUtils.trimToNull(this.httpServletRequest.getParameter(paramName)); } return value; }
From source file:com.webbfontaine.valuewebb.search.custom.UserCriterion.java
private void makeCaseInsensitive(Criterion criterion) { SimpleExpression simpleExpression;// w w w . j ava 2 s. c om if (type == STRING && criterion instanceof SimpleExpression) { simpleExpression = (SimpleExpression) criterion; if (StringUtils.trimToNull((String) value) != null) { simpleExpression.ignoreCase(); } } }