Java Code Examples for org.apache.commons.lang3.StringUtils#stripToNull()
The following examples show how to use
org.apache.commons.lang3.StringUtils#stripToNull() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: PackageJsonExtractor.java From synopsys-detect with Apache License 2.0 | 6 votes |
public Extraction extract(final PackageJson packageJson, final boolean includeDevDependencies) { final List<Dependency> dependencies = packageJson.dependencies.entrySet().stream() .map(this::entryToDependency) .collect(Collectors.toList()); if (includeDevDependencies) { final List<Dependency> devDependencies = packageJson.devDependencies.entrySet().stream() .map(this::entryToDependency) .collect(Collectors.toList()); dependencies.addAll(devDependencies); } final MutableMapDependencyGraph dependencyGraph = new MutableMapDependencyGraph(); dependencyGraph.addChildrenToRoot(dependencies); final CodeLocation codeLocation = new CodeLocation(dependencyGraph); final String projectName = StringUtils.stripToNull(packageJson.name); final String projectVersion = StringUtils.stripToNull(packageJson.version); return new Extraction.Builder() .success(codeLocation) .projectName(projectName) .projectVersion(projectVersion) .build(); }
Example 2
Source File: AuctionRequestFactory.java From prebid-server-java with Apache License 2.0 | 6 votes |
/** * Parses publisher.ext and returns parentAccount value from it. Returns null if any parsing error occurs. */ private String parentAccountIdFromExtPublisher(ObjectNode extPublisherNode) { if (extPublisherNode == null) { return null; } final ExtPublisher extPublisher; try { extPublisher = mapper.mapper().convertValue(extPublisherNode, ExtPublisher.class); } catch (IllegalArgumentException e) { return null; // not critical } final ExtPublisherPrebid extPublisherPrebid = extPublisher != null ? extPublisher.getPrebid() : null; return extPublisherPrebid != null ? StringUtils.stripToNull(extPublisherPrebid.getParentAccount()) : null; }
Example 3
Source File: EventUtil.java From prebid-server-java with Apache License 2.0 | 6 votes |
public static EventRequest from(RoutingContext context) { final MultiMap queryParams = context.request().params(); final String typeAsString = queryParams.get(TYPE_PARAMETER); final EventRequest.Type type = typeAsString.equals(WIN_TYPE) ? EventRequest.Type.win : EventRequest.Type.imp; final EventRequest.Format format = Objects.equals(queryParams.get(FORMAT_PARAMETER), IMAGE_FORMAT) ? EventRequest.Format.image : EventRequest.Format.blank; final EventRequest.Analytics analytics = Objects.equals(DISABLED_ANALYTICS, queryParams.get(ANALYTICS_PARAMETER)) ? EventRequest.Analytics.disabled : EventRequest.Analytics.enabled; final String timestampAsString = StringUtils.stripToNull(queryParams.get(TIMESTAMP_PARAMETER)); final Long timestamp = timestampAsString != null ? Long.valueOf(timestampAsString) : null; return EventRequest.builder() .type(type) .bidId(queryParams.get(BID_ID_PARAMETER)) .accountId(queryParams.get(ACCOUNT_ID_PARAMETER)) .bidder(queryParams.get(BIDDER_PARAMETER)) .timestamp(timestamp) .format(format) .analytics(analytics) .build(); }
Example 4
Source File: XmlRpcDataMarshaller.java From livingdoc-core with GNU General Public License v3.0 | 6 votes |
/** * Transforms the Vector of the Reference parameters into a Reference * Object.<br> * * @param xmlRpcParameters * @return the Reference. */ @SuppressWarnings(SUPPRESS_UNCHECKED) public static Reference toReference(List<Object> xmlRpcParameters) { Reference reference = null; if (!xmlRpcParameters.isEmpty()) { Requirement requirement = toRequirement((List<Object>)xmlRpcParameters.get(REFERENCE_REQUIREMENT_IDX)); Specification specification = toSpecification((List<Object>)xmlRpcParameters.get( REFERENCE_SPECIFICATION_IDX)); SystemUnderTest sut = toSystemUnderTest((List<Object>)xmlRpcParameters.get(REFERENCE_SUT_IDX)); String sections = StringUtils.stripToNull((String) xmlRpcParameters.get(REFERENCE_SECTIONS_IDX)); reference = Reference.newInstance(requirement, specification, sut, sections); Execution exe = toExecution((List<Object>) xmlRpcParameters.get(REFERENCE_LAST_EXECUTION_IDX)); reference.setLastExecution(exe); } return reference; }
Example 5
Source File: EventUtil.java From prebid-server-java with Apache License 2.0 | 5 votes |
public static void validateTimestamp(RoutingContext context) { final String timestamp = StringUtils.stripToNull(context.request().params().get(TIMESTAMP_PARAMETER)); if (timestamp != null) { try { Long.parseLong(timestamp); } catch (NumberFormatException e) { throw new IllegalArgumentException(String.format( "Timestamp '%s' query parameter is not valid number: %s", TIMESTAMP_PARAMETER, timestamp)); } } }
Example 6
Source File: EnvironmentBean.java From sailfish-core with Apache License 2.0 | 5 votes |
public void setCurrentVariableSet(String currentVariableSet) { logger.info("setCurrentVariableSet invoked {} currentVariableSet[{}]", getUser(), currentVariableSet); this.currentVariableSet = StringUtils.stripToNull(currentVariableSet); if(this.currentVariableSet == null) { this.variables = emptyList(); } else { this.variables = copyOf(BeanUtil.getSfContext().getConnectionManager().getVariableSet(currentVariableSet).keySet()); } }
Example 7
Source File: GemspecLineParser.java From synopsys-detect with Apache License 2.0 | 5 votes |
private String extractName(final String line) { final int openQuoteIndex = line.indexOf(QUOTE_TOKEN); if (openQuoteIndex < 0) { return ""; } final int closeQuoteIndex = line.indexOf(QUOTE_TOKEN, openQuoteIndex + 1); if (closeQuoteIndex < 0) { return ""; } final String name = line.substring(openQuoteIndex + 1, closeQuoteIndex); return StringUtils.stripToNull(name); }
Example 8
Source File: MailHost.java From gocd with Apache License 2.0 | 5 votes |
@Override @PostConstruct public void ensureEncrypted() { this.username = StringUtils.stripToNull(username); setPasswordIfNotBlank(password); }
Example 9
Source File: BackupService.java From gocd with Apache License 2.0 | 5 votes |
private String postBackupScriptFile() { BackupConfig backupConfig = backupConfig(); if (backupConfig != null) { String postBackupScript = backupConfig.getPostBackupScript(); return StringUtils.stripToNull(postBackupScript); } return null; }
Example 10
Source File: EventHubsOutputDescriptor.java From samza with Apache License 2.0 | 5 votes |
/** * Constructs an {@link OutputDescriptor} instance. * * @param streamId id of the stream * @param namespace namespace for the Event Hubs entity to produce to, not null * @param entityPath entity path for the Event Hubs entity to produce to, not null * @param valueSerde serde the values in the messages in the stream * @param systemDescriptor system descriptor this stream descriptor was obtained from */ EventHubsOutputDescriptor(String streamId, String namespace, String entityPath, Serde valueSerde, SystemDescriptor systemDescriptor) { super(streamId, KVSerde.of(new NoOpSerde<>(), valueSerde), systemDescriptor); this.namespace = StringUtils.stripToNull(namespace); this.entityPath = StringUtils.stripToNull(entityPath); if (this.namespace == null || this.entityPath == null) { throw new ConfigException(String.format("Missing namespace and entity path Event Hubs output descriptor in " + "system: {%s}, stream: {%s}", getSystemName(), streamId)); } }
Example 11
Source File: EventHubsInputDescriptor.java From samza with Apache License 2.0 | 5 votes |
/** * Constructs an {@link InputDescriptor} instance. * * @param streamId id of the stream * @param namespace namespace for the Event Hubs entity to consume from, not null * @param entityPath entity path for the Event Hubs entity to consume from, not null * @param valueSerde serde the values in the messages in the stream * @param systemDescriptor system descriptor this stream descriptor was obtained from */ EventHubsInputDescriptor(String streamId, String namespace, String entityPath, Serde valueSerde, SystemDescriptor systemDescriptor) { super(streamId, KVSerde.of(new NoOpSerde<>(), valueSerde), systemDescriptor, null); this.namespace = StringUtils.stripToNull(namespace); this.entityPath = StringUtils.stripToNull(entityPath); if (this.namespace == null || this.entityPath == null) { throw new ConfigException(String.format("Missing namespace and entity path Event Hubs input descriptor in " // + "system: {%s}, stream: {%s}", getSystemName(), streamId)); } }
Example 12
Source File: ScmMaterial.java From gocd with Apache License 2.0 | 4 votes |
@PostConstruct public void ensureEncrypted() { this.userName = StringUtils.stripToNull(this.userName); setPasswordIfNotBlank(password); }
Example 13
Source File: BasicLTIUtil.java From basiclti-util-java with Apache License 2.0 | 4 votes |
/** * * @param launch_info Variable is mutated by this method. * @param postProp Variable is mutated by this method. * @param descriptor * @return */ public static boolean parseDescriptor(Map<String, String> launch_info, Map<String, String> postProp, String descriptor) { Map<String, Object> tm = null; try { tm = XMLMap.getFullMap(descriptor.trim()); } catch (Exception e) { M_log.warning("BasicLTIUtil exception parsing BasicLTI descriptor: " + e.getMessage()); return false; } if (tm == null) { M_log.warning("Unable to parse XML in parseDescriptor"); return false; } String launch_url = StringUtils.stripToNull(XMLMap.getString(tm, "/basic_lti_link/launch_url")); String secure_launch_url = StringUtils.stripToNull(XMLMap.getString(tm, "/basic_lti_link/secure_launch_url")); if (launch_url == null && secure_launch_url == null) { return false; } setProperty(launch_info, "launch_url", launch_url); setProperty(launch_info, "secure_launch_url", secure_launch_url); // Extensions for hand-authored placements - The export process should scrub // these setProperty(launch_info, "key", StringUtils.stripToNull(XMLMap.getString(tm, "/basic_lti_link/x-secure/launch_key"))); setProperty(launch_info, "secret", StringUtils.stripToNull(XMLMap.getString(tm, "/basic_lti_link/x-secure/launch_secret"))); List<Map<String, Object>> theList = XMLMap.getList(tm, "/basic_lti_link/custom/parameter"); for (Map<String, Object> setting : theList) { dPrint("Setting=" + setting); String key = XMLMap.getString(setting, "/!key"); // Get the key attribute String value = XMLMap.getString(setting, "/"); // Get the value if (key == null || value == null) { continue; } key = "custom_" + mapKeyName(key); dPrint("key=" + key + " val=" + value); postProp.put(key, value); } return true; }
Example 14
Source File: BasicLTIUtil.java From basiclti-util-java with Apache License 2.0 | 4 votes |
/** * @deprecated See: {@link #parseDescriptor(Map, Map, String)} * @param launch_info Variable is mutated by this method. * @param postProp Variable is mutated by this method. * @param descriptor * @return */ public static boolean parseDescriptor(Properties launch_info, Properties postProp, String descriptor) { // this is an ugly copy/paste of the non-@deprecated method // could not convert data types as they variables get mutated (ugh) Map<String, Object> tm = null; try { tm = XMLMap.getFullMap(descriptor.trim()); } catch (Exception e) { M_log.warning("BasicLTIUtil exception parsing BasicLTI descriptor: " + e.getMessage()); return false; } if (tm == null) { M_log.warning("Unable to parse XML in parseDescriptor"); return false; } String launch_url = StringUtils.stripToNull(XMLMap.getString(tm, "/basic_lti_link/launch_url")); String secure_launch_url = StringUtils.stripToNull(XMLMap.getString(tm, "/basic_lti_link/secure_launch_url")); if (launch_url == null && secure_launch_url == null) { return false; } setProperty(launch_info, "launch_url", launch_url); setProperty(launch_info, "secure_launch_url", secure_launch_url); // Extensions for hand-authored placements - The export process should scrub these setProperty(launch_info, "key", StringUtils.stripToNull(XMLMap.getString(tm, "/basic_lti_link/x-secure/launch_key"))); setProperty(launch_info, "secret", StringUtils.stripToNull(XMLMap.getString(tm, "/basic_lti_link/x-secure/launch_secret"))); List<Map<String, Object>> theList = XMLMap.getList(tm, "/basic_lti_link/custom/parameter"); for (Map<String, Object> setting : theList) { dPrint("Setting=" + setting); String key = XMLMap.getString(setting, "/!key"); // Get the key attribute String value = XMLMap.getString(setting, "/"); // Get the value if (key == null || value == null) { continue; } key = "custom_" + mapKeyName(key); dPrint("key=" + key + " val=" + value); postProp.setProperty(key, value); } return true; }
Example 15
Source File: Reference.java From livingdoc-core with GNU General Public License v3.0 | 4 votes |
public void setSections(String sections) { this.sections = StringUtils.stripToNull(sections); }
Example 16
Source File: RepositoryType.java From livingdoc-core with GNU General Public License v3.0 | 4 votes |
public void setTestUrlFormat(String testUrlFormat) { this.testUrlFormat = StringUtils.stripToNull(testUrlFormat); }
Example 17
Source File: RepositoryType.java From livingdoc-core with GNU General Public License v3.0 | 4 votes |
public void setDocumentUrlFormat(String documentUrlFormat) { this.documentUrlFormat = StringUtils.stripToNull(documentUrlFormat); }
Example 18
Source File: Client.java From geoportal-server-harvester with Apache License 2.0 | 4 votes |
/** * Reads record. * * @param id records id * @return record * @throws IOException if error reading record * @throws URISyntaxException if invalid URI * @throws ParserConfigurationException if error parsing response * @throws SAXException if error parsing response * @throws XPathExpressionException if error parsing response * @throws TransformerException if error parsing response */ public String readRecord(String id) throws IOException, URISyntaxException, ParserConfigurationException, SAXException, XPathExpressionException, TransformerException { HttpGet request = new HttpGet(recordUri(id)); try (CloseableHttpResponse httpResponse = httpClient.execute(request); InputStream contentStream = httpResponse.getEntity().getContent();) { String reasonMessage = httpResponse.getStatusLine().getReasonPhrase(); String responseContent = IOUtils.toString(contentStream, "UTF-8"); LOG.trace(String.format("RESPONSE: %s, %s", responseContent, reasonMessage)); if (httpResponse.getStatusLine().getStatusCode()==429 || httpResponse.getStatusLine().getStatusCode()==503) { Date retryAfter = getRetryAfter(httpResponse); if (retryAfter!=null) { long delay = retryAfter.getTime()-System.currentTimeMillis(); if (delay>0) { LOG.debug(String.format("Harvestiong suspended for %d milliseconds.", delay)); try { Thread.sleep(delay); } catch (InterruptedException ex) { // ignore } } return readRecord(id); } } if (httpResponse.getStatusLine().getStatusCode() >= 400) { throw new HttpResponseException(httpResponse.getStatusLine().getStatusCode(), httpResponse.getStatusLine().getReasonPhrase()); } Document responseDoc = parseDocument(responseContent); XPath xPath = XPathFactory.newInstance().newXPath(); String errorCode = StringUtils.stripToNull((String) xPath.evaluate("/OAI-PMH/error/@code", responseDoc, XPathConstants.STRING)); if (errorCode != null) { throw new HttpResponseException(HttpStatus.SC_BAD_REQUEST, String.format("Invalid OAI-PMH response with code: %s", errorCode)); } Node metadataNode = (Node) xPath.evaluate("/OAI-PMH/GetRecord/record/metadata/*[1]", responseDoc, XPathConstants.NODE); if (metadataNode == null) { throw new IOException("Error reading metadata"); } Document metadataDocument = emptyDocument(); metadataDocument.appendChild(metadataDocument.importNode(metadataNode, true)); return XmlUtils.toString(metadataDocument); } }
Example 19
Source File: Client.java From geoportal-server-harvester with Apache License 2.0 | 4 votes |
/** * Lists all available ids. * * @param resumptionToken resumption token or <code>null</code> * @param since since date or <code>null</code> * @return list of the ids with the resumption token to continue * @throws IOException if error reading response * @throws URISyntaxException if invalid URI * @throws ParserConfigurationException if error parsing response * @throws SAXException if error parsing response * @throws XPathExpressionException if error parsing response */ public ListIdsResponse listIds(String resumptionToken, Date since) throws IOException, URISyntaxException, ParserConfigurationException, SAXException, XPathExpressionException { HttpGet request = new HttpGet(listIdsUri(resumptionToken, since)); try (CloseableHttpResponse httpResponse = httpClient.execute(request); InputStream contentStream = httpResponse.getEntity().getContent();) { String reasonMessage = httpResponse.getStatusLine().getReasonPhrase(); String responseContent = IOUtils.toString(contentStream, "UTF-8"); LOG.trace(String.format("RESPONSE: %s, %s", responseContent, reasonMessage)); if (httpResponse.getStatusLine().getStatusCode()==429 || httpResponse.getStatusLine().getStatusCode()==503) { Date retryAfter = getRetryAfter(httpResponse); if (retryAfter!=null) { long delay = retryAfter.getTime()-System.currentTimeMillis(); if (delay>0) { LOG.debug(String.format("Harvestiong suspended for %d milliseconds.", delay)); try { Thread.sleep(delay); } catch (InterruptedException ex) { // ignore } } return listIds(resumptionToken, since); } } if (httpResponse.getStatusLine().getStatusCode() >= 400) { throw new HttpResponseException(httpResponse.getStatusLine().getStatusCode(), httpResponse.getStatusLine().getReasonPhrase()); } Document responseDoc = parseDocument(responseContent); XPath xPath = XPathFactory.newInstance().newXPath(); String errorCode = StringUtils.stripToNull((String) xPath.evaluate("/OAI-PMH/error/@code", responseDoc, XPathConstants.STRING)); if (errorCode != null) { throw new HttpResponseException(HttpStatus.SC_BAD_REQUEST, String.format("Invalid OAI-PMH response with code: %s", errorCode)); } Node listIdentifiersNode = (Node) xPath.evaluate("/OAI-PMH/ListIdentifiers", responseDoc, XPathConstants.NODE); ListIdsResponse response = new ListIdsResponse(); if (listIdentifiersNode != null) { NodeList headerNodes = (NodeList) xPath.evaluate("header[not(@status=\"deleted\")]", listIdentifiersNode, XPathConstants.NODESET); if (headerNodes != null) { ArrayList<Header> headers = new ArrayList<>(); for (int i = 0; i < headerNodes.getLength(); i++) { Header header = new Header(); header.identifier = (String) xPath.evaluate("identifier", headerNodes.item(i), XPathConstants.STRING); header.datestamp = (String) xPath.evaluate("datestamp", headerNodes.item(i), XPathConstants.STRING); headers.add(header); } response.headers = headers.toArray(new Header[headers.size()]); } response.resumptionToken = StringUtils.trimToNull((String) xPath.evaluate("resumptionToken", listIdentifiersNode, XPathConstants.STRING)); } else { response.resumptionToken = null; } return response; } }
Example 20
Source File: CsvLibraryBuilder.java From sailfish-core with Apache License 2.0 | 3 votes |
private ScriptList parseScriptList(Map<String, String> row, long currentRecordNumber) throws InvalidRowException { String name = row.get(CsvHeader.Name.getFieldKey()); if(name == null) { throw new InvalidRowException(CsvHeader.Name.getFieldKey() + " is required for Script List"); } Set<String> serviceNames = parseServiceListReferences(row.get(CsvHeader.Services.getFieldKey())); String priorityString = row.get(CsvHeader.Priority.getFieldKey()); long priority = 0; boolean priorityParsed = true; if(StringUtils.isNotEmpty(priorityString)) { try { priority = Long.parseLong(priorityString); } catch(NumberFormatException e) { priorityParsed = false; } } String executor = StringUtils.defaultIfBlank(row.get(CsvHeader.Executor.getFieldKey()), null); String variableSet = StringUtils.stripToNull(row.get(CsvHeader.VariableSet.getFieldKey())); ScriptList result = new ScriptList(name, executor, serviceNames, parseApiOptions(row), priority, currentRecordNumber, variableSet); if (!priorityParsed) { result.addRejectCause(new ImportError(currentRecordNumber, "'Priority' value is not parsable to number (long)")); } return result; }