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:org.hawkular.client.test.BaseTest.java
private String getPassword() { String password = System.getenv("HAWKULAR_PASSWORD"); if (StringUtils.trimToNull(password) == null) { Reporter.log("HAWKULAR_PASSWORD env not defined. Defaulting to 'password'"); password = "password"; }//from ww w . ja va 2s .c o m return password; }
From source file:org.hspconsortium.cwf.api.security.BasicAuthInterceptor.java
public BasicAuthInterceptor(String id, BasicAuthConfigurator config) { super(id, "Basic"); String username = StringUtils.trimToNull(config.getUsername()); String password = StringUtils.trimToEmpty(config.getPassword()); this.credentials = username == null ? null : encode(username, password); }
From source file:org.hspconsortium.cwf.fhir.client.FhirContext.java
public FhirContext(IFhirContextConfigurator config) { super(config.getVersion()); proxy = StringUtils.trimToNull(config.getProxy()); }
From source file:org.incode.eurocommercial.contactapp.fixture.scenarios.demo.ContactImport.java
@Override public java.util.List<Object> handleRow(final FixtureScript.ExecutionContext executionContext, final org.isisaddons.module.excel.dom.ExcelFixture excelFixture, final Object previousRow) { country = StringUtils.trimToNull(country); address = StringUtils.trimToNull(address); group = StringUtils.trimToNull(group); company = StringUtils.trimToNull(company); name = StringUtils.trimToNull(name); office = StringUtils.trimToNull(office); mobile = StringUtils.trimToNull(mobile); home = StringUtils.trimToNull(home); email = StringUtils.trimToNull(email); role = StringUtils.trimToNull(role); note = StringUtils.trimToNull(note); final ContactImport previousContactRow = (ContactImport) previousRow; if (previousContactRow != null) { if (country == null) country = previousContactRow.getCountry(); if (group == null) group = previousContactRow.getGroup(); }/*w w w . ja v a 2 s .c o m*/ if (office != null) office = office.replace("(0)", ""); if (mobile != null) mobile = mobile.replace("(0)", ""); if (home != null) home = home.replace("(0)", ""); Country country = countryRepository.findOrCreate(this.country); ContactGroup contactGroup = contactGroupRepository.findOrCreate(country, group); if (address != null) contactGroup.setAddress(address); if (disorder != null) { int displayOrder = disorder; contactGroup.setDisplayOrder(displayOrder); } Contact contact = null; if (name == null) { if (office != null) contactGroup.addContactNumber(office, ContactNumberType.OFFICE.title(), null); if (mobile != null) contactGroup.addContactNumber(mobile, ContactNumberType.MOBILE.title(), null); if (home != null) contactGroup.addContactNumber(home, ContactNumberType.HOME.title(), null); if (email != null) contactGroup.setEmail(email); } else { contact = contactRepository.findOrCreate(name, company, email, note, office, mobile, home); contact.addContactRole(contactGroup, role, null); if (company != null && company.equals("Eurocommercial")) { Country globalCountry = countryRepository.findOrCreate("Global"); ContactGroup ecpCompanyGroup = contactGroupRepository.findOrCreate(globalCountry, "ECP Company"); contact.addContactRole(ecpCompanyGroup, "Eurocommercial", null); } } executionContext.addResult(excelFixture, contact); return Collections.singletonList(contact); }
From source file:org.jasig.ssp.util.importer.job.csv.RawItemCsvReader.java
/** * Satisfies {@link FieldSetMapper} contract. * @param fs//from w w w .j a v a 2s. c o m * @return * @throws BindException */ @Override public RawItem mapFieldSet(FieldSet fs) throws BindException { if (fs == null) { return null; } Map<String, String> record = new LinkedHashMap<String, String>(); for (String columnName : this.columnNames) { record.put(columnName, StringUtils.trimToNull(fs.readString(columnName))); } RawItem item = new RawItem(); item.setResource(itemResource); item.setRecord(record); return item; }
From source file:org.kalypso.model.wspm.pdb.internal.waterlevel2d.AggregatedWaterlevel.java
/** build description from all waterlevels */ String getDescription() throws MismatchedDimensionException, FactoryException, TransformException { final ProjectedWaterlevel[] waterlevels = getWaterlevels(); final Set<String> descriptions = new LinkedHashSet<>(); for (final ProjectedWaterlevel waterlevel : waterlevels) { /* collect description, ignore blanks/empty */ final String description = waterlevel.getDescription(); descriptions.add(StringUtils.trimToNull(description)); }/*from w w w .j a v a 2s . co m*/ /* Build combined description without null elements */ descriptions.remove(null); final String joined = StringUtils.join(descriptions, ", "); //$NON-NLS-1$ final int maxLength = PdbMappingUtils.findLength(CrossSectionPart.class, CrossSectionPart.PROPERTY_DESCRIPTION); return StringUtils.abbreviate(joined, maxLength); }
From source file:org.kisoonlineapp.jsf.CalendarConverterInternal.java
@Override public Object getAsObject(FacesContext context, UIComponent component, String value) { final String trimmedValue = StringUtils.trimToNull(value); if (StringUtils.isBlank(trimmedValue)) { return null; }/*from w w w. j av a2s. c o m*/ final SimpleDateFormat sdf = createSimpleDateFormat(context, pattern); sdf.setLenient(false); final ParsePosition pos = new ParsePosition(0); final Date date = sdf.parse(trimmedValue, pos); if (pos.getErrorIndex() >= 0 || pos.getIndex() != trimmedValue.length()) { throw new ConverterException("Cannot parse " + trimmedValue); } final Calendar cal = kisoOnlineApp.getNow(); cal.setTime(date); return cal; }
From source file:org.kisoonlineapp.kisoonlineapp.csv.FieldInfo.java
/** * Format a value of this {@link FieldInfo}. * * @param value//w w w . j a v a 2s . c om * @return */ String formatValue(final String value) { String formattedValue = StringUtils.trimToNull(value); if (formattedValue == null && defaultValue == null) { return "null"; } else if (formattedValue == null && defaultValue != null) { formattedValue = defaultValue; } if (fixTime) { formattedValue = formattedValue + ":00"; } formattedValue = StringUtils.replace(formattedValue, "'", "''"); if (quoting) { formattedValue = "\'" + formattedValue + "\'"; } return formattedValue; }
From source file:org.ligoj.app.plugin.build.jenkins.JenkinsPluginResource.java
/** * Search the Jenkin's jobs matching to the given criteria. Name, display name and description are considered. * * @param node//www. j av a 2 s. c o m * the node to be tested with given parameters. * @param criteria * the search criteria. * @param view * The optional view URL. * @return job names matching the criteria. */ private List<Job> findAllByName(final String node, final String criteria, final String view) throws SAXException, IOException, ParserConfigurationException { // Prepare the context, an ordered set of jobs final Format format = new NormalizeFormat(); final String formatCriteria = format.format(criteria); final Map<String, String> parameters = pvResource.getNodeParameters(node); // Get the jobs and parse them final String url = StringUtils.trimToEmpty(view) + "api/xml?tree=jobs[name,displayName,description,color]"; final String jobsAsXml = StringUtils.defaultString(getResource(parameters, url), "<a/>"); final InputStream jobsAsInput = IOUtils.toInputStream(jobsAsXml, StandardCharsets.UTF_8); final Element hudson = (Element) xml.parse(jobsAsInput).getFirstChild(); final Map<String, Job> result = new TreeMap<>(); for (final Element jobNode : DomUtils.getChildElementsByTagName(hudson, "job")) { // Extract string data from this job final String name = StringUtils.trimToEmpty(DomUtils.getChildElementValueByTagName(jobNode, "name")); final String displayName = StringUtils .trimToEmpty(DomUtils.getChildElementValueByTagName(jobNode, "displayName")); final String description = StringUtils .trimToEmpty(DomUtils.getChildElementValueByTagName(jobNode, "description")); // Check the values of this job if (format.format(name).contains(formatCriteria) || format.format(displayName).contains(formatCriteria) || format.format(description).contains(formatCriteria)) { // Retrieve description and display name final Job job = new Job(); job.setName(StringUtils.trimToNull(displayName)); job.setDescription(StringUtils.trimToNull(description)); job.setId(name); job.setStatus(toStatus(DomUtils.getChildElementValueByTagName(jobNode, "color"))); result.put(format.format(ObjectUtils.defaultIfNull(job.getName(), job.getId())), job); } } return new ArrayList<>(result.values()); }
From source file:org.ligoj.app.plugin.build.jenkins.JenkinsPluginResource.java
/** * Return the node text without using document parser. * * @param xmlContent/*from w w w . j a v a 2 s.c om*/ * XML content. * @param node * the node name. * @return trimmed node text or <code>null</code>. */ private String getNodeText(final String xmlContent, final String node) { final Matcher matcher = Pattern.compile("<" + node + ">([^<]*)</" + node + ">") .matcher(ObjectUtils.defaultIfNull(xmlContent, "")); if (matcher.find()) { return StringUtils.trimToNull(matcher.group(1)); } return null; }