Example usage for org.apache.commons.lang3 StringUtils strip

List of usage examples for org.apache.commons.lang3 StringUtils strip

Introduction

In this page you can find the example usage for org.apache.commons.lang3 StringUtils strip.

Prototype

public static String strip(final String str) 

Source Link

Document

Strips whitespace from the start and end of a String.

This is similar to #trim(String) but removes whitespace.

Usage

From source file:ca.phon.session.RangeRecordFilter.java

public RangeRecordFilter(Session t, String ranges) throws ParseException {

    this.transcript = t;

    String[] splitRanges = ranges.split(",");
    for (String r : splitRanges) {
        Range range = rangeFromString(StringUtils.strip(r));
        this.ranges.add(range);
    }/*w  ww  . j av  a 2 s. co m*/

}

From source file:ch.cyberduck.core.s3.S3PresignedUrlProvider.java

/**
 * Generates a signed URL string that will grant access to an S3 resource (bucket or object)
 * to whoever uses the URL up until the time specified.
 *
 * @param host   Hostname//from   ww w.j  av a 2  s  .  c  o m
 * @param bucket the name of the bucket to include in the URL, must be a valid bucket name.
 * @param key    the name of the object to include in the URL, if null only the bucket name is used.
 * @param expiry Milliseconds
 * @return a URL signed in such a way as to grant access to an S3 resource to whoever uses it.
 */
public String create(final Host host, final String user, final String secret, final String bucket,
        final String region, final String key, final long expiry) {
    final String requestSignatureVersion;
    if (StringUtils.isNotBlank(region)) {
        requestSignatureVersion = S3Protocol.AuthenticationHeaderSignatureVersion.AWS4HMACSHA256.toString();
    } else {
        requestSignatureVersion = S3Protocol.AuthenticationHeaderSignatureVersion.AWS2.toString();
    }
    return new RestS3Service(new AWSCredentials(StringUtils.strip(user), StringUtils.strip(secret))) {
        @Override
        public String getEndpoint() {
            return host.getHostname();
        }
    }.createSignedUrlUsingSignatureVersion(requestSignatureVersion, region, "GET", bucket, key, null, null,
            expiry / 1000, false, true, false);
}

From source file:ca.phon.media.util.MediaLocator.java

/**
 * Get media include path as a list of/*  w w w .j a va2  s. co m*/
 * paths.
 * 
 * @param props
 * @return media include paths
 */
private static List<String> parseMediaIncludePaths() {
    List<String> retVal = new ArrayList<String>();

    final String includePath = PrefHelper.get(MEDIA_INCLUDE_PATH_PROP, null);
    if (includePath != null) {
        String[] paths = includePath.split(";");

        for (String path : paths) {
            if (StringUtils.strip(path).length() > 0) {
                retVal.add(path);
            }
        }
    }

    return retVal;
}

From source file:io.seldon.importer.articles.dynamicextractors.AllElementsTextListValueDynamicExtractor.java

@Override
public String extract(AttributeDetail attributeDetail, String url, Document articleDoc) throws Exception {

    String attrib_value = null;//www. j a v  a  2 s.  co m

    if ((attributeDetail.extractor_args != null) && (attributeDetail.extractor_args.size() >= 1)) {
        String cssSelector = attributeDetail.extractor_args.get(0);
        Elements elements = articleDoc.select(cssSelector);
        if (StringUtils.isNotBlank(cssSelector)) {
            if (elements != null) {
                StringBuilder sb = new StringBuilder();
                boolean isFirstInList = true;
                for (Element e : elements) {
                    String eText = e.text();
                    eText = StringUtils.strip(eText);
                    if (StringUtils.isBlank(eText))
                        continue;
                    eText = eText.toLowerCase();
                    if (isFirstInList) {
                        isFirstInList = false;
                    } else {
                        sb.append(",");
                    }
                    sb.append(eText);
                }
                attrib_value = sb.toString();
            }
        }
    }

    return attrib_value;
}

From source file:io.seldon.importer.articles.dynamicextractors.AllElementsAttrValueDynamicExtractor.java

@Override
public String extract(AttributeDetail attributeDetail, String url, Document articleDoc) throws Exception {
    String attrib_value = null;/*from   w  ww.  j a va  2s . c  om*/

    if ((attributeDetail.extractor_args != null) && (attributeDetail.extractor_args.size() >= 2)) {
        String cssSelector = attributeDetail.extractor_args.get(0);
        String attributeName = attributeDetail.extractor_args.get(1);
        Elements elements = articleDoc.select(cssSelector);
        if (StringUtils.isNotBlank(cssSelector)) {
            if (elements != null) {
                StringBuilder sb = new StringBuilder();
                boolean isFirstInList = true;
                for (Element e : elements) {
                    String eText = e.attr(attributeName);
                    eText = StringUtils.strip(eText);
                    eText = eText.toLowerCase();
                    if (StringUtils.isBlank(eText))
                        continue;
                    if (isFirstInList) {
                        isFirstInList = false;
                    } else {
                        sb.append(",");
                    }
                    sb.append(eText);
                }
                attrib_value = sb.toString();
            }
        }
    }

    return attrib_value;
}

From source file:io.seldon.importer.articles.AttributesImporterUtils.java

public static List<String> getTagsPartsFromMultipleElement(Elements tagsElements) {
    List<String> tagsParts = new ArrayList<String>();

    for (Element e : tagsElements) {
        String tag = e.text();/*  w w w  .  j av a  2 s .  c  om*/
        tag = StringUtils.strip(tag);
        tag = tag.toLowerCase();
        tagsParts.add(tag);
    }

    return tagsParts;
}

From source file:io.cloudslang.content.utils.OtherUtilities.java

/**
 * Given an ip port string, it checks if it's a valid ip port with a regex (see ipPortPattern attribute)
 *
 * @param portStr the string to check if it's a valid ip port
 * @return true if it's a valid ip port, false otherwise
 *///from   w  w w  .  j  a va2 s.  co m
public static boolean isValidIpPort(@NotNull final String portStr) {
    return ipPortPattern.matcher(StringUtils.strip(portStr)).matches();
}

From source file:io.stallion.plugins.StallionJavaPlugin.java

public List<String> getSqlMigrations() {
    URL resource = getClass().getResource("/sql/migrations.txt");
    if (resource != null) {
        try {// ww  w  . j  a  v a 2 s.  c o m
            List<String> migrations = list();
            Log.fine("Found /sql/migrations file for plugin {0}", getClass().getCanonicalName());
            for (String migration : IOUtils.toString(resource, UTF8).split("\\n")) {
                migration = StringUtils.strip(migration);
                if (migration.startsWith("#") || migration.startsWith("//")) {
                    continue;
                }
                if (!empty(migration)) {
                    migrations.add(migration);
                }
            }
            return migrations;
        } catch (IOException e) {
            throw new RuntimeException(e);
        }
    }
    return list();
}

From source file:com.utdallas.s3lab.smvhunter.enumerate.UIEnumerator.java

public static String execSpecial(String command) throws Exception {
    String cmd[] = { "/bin/bash", "-c", command };

    logger.info("command executed: " + command);
    Process pr = Runtime.getRuntime().exec(cmd);

    String result = IOUtils.toString(pr.getInputStream());
    pr.destroy();//from  w w w  . ja v a2  s  . com
    return StringUtils.strip(result);
}

From source file:io.nosorog.core.ScriptLoader.java

/**
 * Load a {@link Script} from {@link InputStream}.
 * @param is stream to read from/*  w  ww.jav  a2 s.co m*/
 * @return script object
 * @throws IOException if IOException has occurred while reading from the stream
 * @throws ScriptException if an error occurred while processing imports or injections
 */
public Script load(InputStream is) throws IOException, ScriptException {

    StringWriter body = new StringWriter();
    PrintWriter pw = new PrintWriter(body);

    try (BufferedReader reader = new BufferedReader(new InputStreamReader(is, "UTF-8"))) {

        String line;
        boolean flag = false;
        Collection<Node> nodes = new ArrayList<>();

        while ((line = reader.readLine()) != null) {

            pw.println(line);

            if (StringUtils.strip(line).equals("/**")) {
                flag = true;
                continue;
            }

            if (StringUtils.strip(line).equals("*/")) {
                flag = false;
                continue;
            }

            if (flag) {
                try {
                    Node node = parseHeader(line);
                    if (node != null) {
                        nodes.add(node);
                    }
                } catch (ParseException ex) {
                    LOG.log(Level.SEVERE, null, ex);
                }
            }

        }

        return Script.builder(nodes, body.getBuffer().toString(), classLoader).build();

    }

}