List of usage examples for org.apache.commons.lang StringUtils strip
public static String strip(String str)
Strips whitespace from the start and end of a String.
From source file:org.openhab.binding.unifi.internal.api.util.UniFiTidyLowerCaseStringDeserializer.java
@Override public String deserialize(JsonElement json, Type type, JsonDeserializationContext context) throws JsonParseException { String s = json.getAsJsonPrimitive().getAsString(); return StringUtils.lowerCase(StringUtils.strip(s)); }
From source file:org.openhab.binding.unifi.internal.UniFiClientThingConfig.java
public UniFiClientThingConfig tidy() { cid = StringUtils.lowerCase(StringUtils.strip(cid)); site = StringUtils.lowerCase(StringUtils.strip(site)); return this; }
From source file:org.openhab.binding.wemo.internal.WemoGenericBindingProvider.java
private void parseAndAddBindingConfig(Item item, String bindingConfigs) throws BindingConfigParseException { String bindingConfig = StringUtils.substringBefore(bindingConfigs, ","); String bindingConfigTail = StringUtils.substringAfter(bindingConfigs, ","); WemoBindingConfig newConfig = new WemoBindingConfig(); parseBindingConfig(newConfig, item, bindingConfig); addBindingConfig(item, newConfig);// w w w .j av a 2 s. c om while (StringUtils.isNotBlank(bindingConfigTail)) { bindingConfig = StringUtils.substringBefore(bindingConfigTail, ","); bindingConfig = StringUtils.strip(bindingConfig); bindingConfigTail = StringUtils.substringAfter(bindingConfig, ","); parseBindingConfig(newConfig, item, bindingConfig); addBindingConfig(item, newConfig); } }
From source file:org.openmrs.module.clinicalsummary.web.controller.WebUtils.java
/** * Parse expression into a list of string. This method will extract any value between with " and " * * @param expression the string expression * @return list of string element. Each element is a non-blank string * @see org.apache.commons.lang.StringUtils#isNotBlank(String) *///from w ww . j av a2s. c om public static Collection<String> parse(final String expression) { String processedExpression = expression; Collection<String> terms = new TreeSet<String>(); if (expression.contains("\"")) { for (int i = 0; i < expression.length(); i++) { String s = expression.substring(i, i + 1); if (StringUtils.equals(s, "\"")) { // we already make sure that (i + 1) is a valid character, now check the next one after (i + 1) int j = i + 1; boolean found = false; while (j < expression.length() && !found) { s = expression.substring(j, j + 1); if (StringUtils.equals(s, "\"")) found = true; j++; } // get the actual string value String term = expression.substring(i, j); // skip until the end of the param name i = i + term.length(); processedExpression = expression.substring(i); // add the new term to the term list terms.add(term.replace("\"", "")); } } } for (String term : processedExpression.split("\\s*,\\s*")) if (!StringUtils.isNotEmpty(StringUtils.strip(term))) terms.add(term); return terms; }
From source file:org.opentestsystem.shared.test.pagedriver.FastPageDriver.java
protected void loadResourcesInLogs(String resourceDirName, int firstResource, int lastResource) throws AssertionError { // Waste time reading all the static files. long t_timeout = getInteractionResponse().getTimeoutTime(); ClassLoader cl = Thread.currentThread().getContextClassLoader(); for (int i = firstResource; i <= lastResource; i++) { long t_left = t_timeout - System.currentTimeMillis(); if (t_left < 0) { throw new AssertionError("Login shell load took too long."); }//w w w . jav a2s .c o m String resourceName = String.format("student-requests/%s/%09d-request.txt", resourceDirName, i); try (InputStream is = cl.getResourceAsStream(resourceName); BufferedReader reader = new BufferedReader(new InputStreamReader(is))) { // Get method final String method = reader.readLine(); // Get the original URL, and map it to the current server final String originalURL = reader.readLine(); String templateBaseUrl = getTemplateBaseUrl(resourceDirName, i); assertTrue("Unexpected source URL in template file", originalURL.startsWith(templateBaseUrl)); final String path = originalURL.substring(templateBaseUrl.length()); final URL requestURL = new URL(getInteractionContext().getBaseUrl(), path); // Get the request headers String line = reader.readLine(); while (!StringUtils.equals("Headers:", line)) { line = reader.readLine(); } final Map<String, List<String>> headers = new HashMap<>(); while (!StringUtils.equals(line = reader.readLine(), "Body:")) { if (StringUtils.isBlank(line)) { continue; } String[] keyValuePair = StringUtils.split(line, ":", 2); if (keyValuePair.length != 2) { continue; } String key = StringUtils.strip(keyValuePair[0]); List<String> headerList = headers.get(key); if (headerList == null) { headerList = new ArrayList<>(); headers.put(key, headerList); } headerList.add(StringUtils.strip(keyValuePair[1])); } // Get the request body, if any reader.mark(6); char[] buffer = new char[6]; reader.read(buffer); if (Arrays.equals(NULL_CHARS, buffer)) { getInteractionContext().buildResponse(method, requestURL, headers, null, t_left); } else { reader.reset(); getInteractionContext().buildResponse(method, requestURL, headers, reader, t_left); } } catch (IOException | NullPointerException | AssertionError e) { _logger.warn( String.format("Error while parsing template file %s:\r\n%s ", resourceName, e.toString())); } } }
From source file:org.sonar.api.rules.Rule.java
/** * Sets the rule description//w w w . j ava 2 s . co m */ public Rule setDescription(String description) { this.description = StringUtils.strip(description); return this; }
From source file:org.structr.web.entity.html.HtmlElement.java
public static String extractFunctions(SecurityContext securityContext, AbstractNode page, AbstractNode startNode, String pageId, String componentId, AbstractNode viewComponent, String source) throws FrameworkException { // re-use matcher from previous calls Matcher functionMatcher = threadLocalFunctionMatcher.get(); functionMatcher.reset(source);/*from w ww.j av a2 s. c om*/ if (functionMatcher.matches()) { String viewComponentId = viewComponent != null ? viewComponent.getProperty(AbstractNode.uuid) : null; String functionGroup = functionMatcher.group(1); String parameter = functionMatcher.group(2); String functionName = functionGroup.substring(0, functionGroup.length()); Function<String, String> function = functions.get(functionName); if (function != null) { // store thread "state" in function function.setDataId(viewComponentId); function.setPageId(pageId); if (parameter.contains(",")) { String[] parameters = split(parameter); String[] results = new String[parameters.length]; // collect results from comma-separated function parameter for (int i = 0; i < parameters.length; i++) { results[i] = extractFunctions(securityContext, page, startNode, pageId, componentId, viewComponent, StringUtils.strip(parameters[i])); } return function.apply(results); } else { String result = extractFunctions(securityContext, page, startNode, pageId, componentId, viewComponent, StringUtils.strip(parameter)); return function.apply(new String[] { result }); } } } // if any of the following conditions match, the literal source value is returned if (StringUtils.isNotBlank(source) && StringUtils.isNumeric(source)) { // return numeric value return source; } else if (source.startsWith("\"") && source.endsWith("\"")) { return source.substring(1, source.length() - 1); } else if (source.startsWith("'") && source.endsWith("'")) { return source.substring(1, source.length() - 1); } else { // return property key return convertValueForHtml(getReferencedProperty(securityContext, page, startNode, pageId, componentId, viewComponent, source)); } }
From source file:org.telscenter.sail.webapp.domain.impl.Projectcode.java
/** * Constructor * * @param projectcode */ public Projectcode(String projectcode) { this.projectcode = StringUtils.strip(projectcode); }
From source file:org.telscenter.sail.webapp.domain.impl.Projectcode.java
/** * Constructor/* ww w . j a va2s .co m*/ * * @param runcode * @param periodname */ public Projectcode(String runcode, String periodname) { this.projectcode = StringUtils.strip(runcode + SEPARATOR + periodname); }
From source file:org.telscenter.sail.webapp.domain.impl.Projectcode.java
/** * @param projectcode the projectcode to set */ public void setProjectcode(String projectcode) { this.projectcode = StringUtils.strip(projectcode); }