Example usage for org.apache.commons.lang StringUtils trim

List of usage examples for org.apache.commons.lang StringUtils trim

Introduction

In this page you can find the example usage for org.apache.commons.lang StringUtils trim.

Prototype

public static String trim(String str) 

Source Link

Document

Removes control characters (char <= 32) from both ends of this String, handling null by returning null.

Usage

From source file:com.mks.zookeeper.addrs.url.UrlAddressReader.java

@Override
public String read() {
    String[] urls = StringUtils.split(url, SPLIT_CHAR);
    String addrs = null;//from  w  w  w  .j a  v a2  s  .  c  om
    for (String url : urls) {
        addrs = read(url);
    }
    if (StringUtils.isBlank(addrs))
        throw new ReaderException("empty!");
    return StringUtils.trim(addrs);
}

From source file:com.alibaba.otter.manager.web.webx.valve.auth.url.URLProtectedEditor.java

/**
 * ??Pattern,?URL/* w w  w  .java  2s .com*/
 */
private List<URLPatternHolder> convertTextToPatterns(String text) {
    List<URLPatternHolder> list = new ArrayList<URLPatternHolder>();
    if (StringUtils.isNotEmpty(text)) {
        BufferedReader br = new BufferedReader(new StringReader(text));
        int counter = 0;
        String line;
        while (true) {
            counter++;
            try {
                line = br.readLine();
            } catch (IOException ioe) {
                throw new IllegalArgumentException(ioe.getMessage());
            }
            if (line == null) {
                break;
            }
            line = StringUtils.trim(line);
            if (StringUtils.isBlank(line)) {
                continue;
            }
            if (logger.isDebugEnabled()) {
                logger.debug("Line " + counter + ": " + line);
            }
            list.add(convertStringToPattern(line));
        }
    }
    return list;
}

From source file:com.adobe.acs.commons.images.transformers.impl.SharpenImageTransformerImpl.java

@Override
public final Layer transform(final Layer layer, final ValueMap properties) {

    if (properties == null || properties.isEmpty()) {
        log.warn("Transform [ {} ] requires parameters.", TYPE);
        return layer;
    }//  w  ww  . j a  va 2  s  .  com

    log.debug("Transforming with [ {} ]", TYPE);

    String unsharpenMask = StringUtils.trim(properties.get(KEY_UNSHARP_MASK, String.class));

    try {
        if (!unsharpenMask.isEmpty()) {
            String[] param = unsharpenMask.split(",");

            // Support is provided for amount and radius only.
            if (param.length == NUM_SHARPEN_PARAMS) {
                float amount = Float.parseFloat(param[0]);
                float radius = Float.parseFloat(param[1]);
                layer.sharpen(amount, radius);
            } else {
                log.warn("Transform [ {} ] requires 2 parameters.", TYPE);
            }
        }
    } catch (NumberFormatException exception) {
        log.warn("Transform [ {} ] requires floating type values.", TYPE);
        log.error("Exception occured while parsing string to float", exception);
    }
    return layer;
}

From source file:com.alibaba.otter.manager.web.webx.valve.auth.action.ActionProtectedEditor.java

/**
 * ??Pattern,?URL/*from   w  w w  .  ja  v  a  2s .  c om*/
 */
private List<ActionPatternHolder> convertTextToPatterns(String text) {
    List<ActionPatternHolder> list = new ArrayList<ActionPatternHolder>();
    if (StringUtils.isNotEmpty(text)) {
        BufferedReader br = new BufferedReader(new StringReader(text));
        int counter = 0;
        String line;
        while (true) {
            counter++;
            try {
                line = br.readLine();
            } catch (IOException ioe) {
                throw new IllegalArgumentException(ioe.getMessage());
            }
            if (line == null) {
                break;
            }
            line = StringUtils.trim(line);
            if (StringUtils.isBlank(line)) {
                continue;
            }
            if (logger.isDebugEnabled()) {
                logger.debug("Line " + counter + ": " + line);
            }
            list.add(convertStringToPattern(line));
        }
    }
    return list;
}

From source file:io.kahu.hawaii.domain.AbstractDomainProperty.java

@Override
public final String getParsedValue() {
    if (isValueEmpty()) {
        return getValue();
    }/*from  w  ww  .j a v  a 2  s. c om*/
    if (hasCachedParsedValue()) {
        return getCachedParsedValue();
    }

    setParsedValue(parseValue(StringUtils.trim(getValue())));
    return getCachedParsedValue();
}

From source file:com.thoughtworks.go.config.ArtifactConfig.java

public void setSource(String source) {
    this.source = StringUtils.trim(source);
}

From source file:de.tsystems.mms.apm.performancesignature.ui.PerfSigTestActionTest.java

@LocalData
@Test/*  w  w w .  ja  va  2s .  c  o  m*/
public void testTestReportPage() throws Exception {
    Project proj = (Project) j.jenkins.getItem(TEST_PROJECT_WITH_HISTORY);
    assertNotNull("We should have a project named " + TEST_PROJECT_WITH_HISTORY, proj);

    Run<?, ?> build = proj.getBuildByNumber(11157);
    assertNotNull("We should have a build with number 11157", build);
    JenkinsRule.WebClient wc = j.createWebClient();
    HtmlPage testReport = wc.getPage(build, "testReport");

    assertEquals(testReport.getByXPath("//*[@id=\"main-panel\"]/table[2]/tbody/tr/td[1]/div[1]/a").size(), 11);
    j.assertXPath(testReport, "//*[contains(@id,\"collapseid\")]/div/table/tbody/tr[1]/td[1]/b");
    j.assertXPathValue(testReport, "//*[contains(@id,\"collapseid\")]/div/table/tbody/tr[1]/td[1]/b/text()",
            "PurePaths - PurePath CPU Duration (ms)");
    j.assertXPath(testReport, "//*[contains(@id,\"collapseid\")]/div/p/text()[2]");
    assertEquals(StringUtils
            .trim(((DomText) testReport.getByXPath("//*[contains(@id,\"collapseid\")]/div/p/text()[2]").get(0))
                    .getWholeText()),
            "Status: Failed\n" + "        ");
}

From source file:com.nanyou.framework.jdbc.sql.dynamic.DynamicSql.java

private void findChildren(DynamicParent parent, String sql) {
    try {//from   ww  w .j a v  a2 s .c  o  m
        sql = StringUtils.remove(sql, ";");

        BufferedReader in = new BufferedReader(new StringReader(sql));
        while (true) {
            String line = in.readLine();
            if (line == null) {
                break;
            }
            if (StringUtils.trim(line).startsWith("--<")) {
                line = StringUtils.trim(line);
                line = new String(line.substring(3, line.lastIndexOf('>')));
                StringTokenizer st = new StringTokenizer(line, "= \t");
                String tagName = st.nextToken();
                SqlTag child = new SqlTag();
                child.setName(tagName);
                child.setHandler(SqlTagHandlerFactory.getSqlTagHandler(tagName));
                while (st.hasMoreTokens()) {
                    String key = st.nextToken();
                    String value = StringUtils.remove(st.nextToken(), "\"");
                    if ("prepend".equalsIgnoreCase(key)) {
                        child.setPrependAttr(value);
                    } else if ("property".equalsIgnoreCase(key)) {
                        child.setPropertyAttr(value);
                    } else if ("open".equalsIgnoreCase(key)) {
                        child.setOpenAttr(value);
                    } else if ("close".equalsIgnoreCase(key)) {
                        child.setCloseAttr(value);
                    } else if ("conjunction".equalsIgnoreCase(key)) {
                        child.setConjunctionAttr(value);
                    } else if ("compareProperty".equalsIgnoreCase(key)) {
                        child.setComparePropertyAttr(value);
                    } else if ("compareValue".equalsIgnoreCase(key)) {
                        child.setCompareValueAttr(value);
                    }
                }
                String endTagName = "</" + tagName + ">";
                StringBuffer sb = new StringBuffer();
                while (true) {
                    line = in.readLine();
                    if (line == null) {
                        break;
                    }
                    if (line.indexOf(endTagName) > 0) {
                        break;
                    }
                    sb.append(line).append("\n");
                }
                findChildren(child, sb.toString());
                parent.addChild(child);
            } else {
                SqlText child = new SqlText();
                ((SqlText) child).setText(line);
                parent.addChild(child);
            }
        }
    } catch (Exception ex) {
        throw new RuntimeException(ex);
    }
}

From source file:edu.duke.cabig.c3pr.webservice.integration.XMLUtils.java

/**
 * @param n1//from   ww w  .  j av  a 2  s. com
 * @param n2
 * @return
 */
private static boolean isTextNodeEqual(Node n1, Node n2) {
    final String v1 = StringUtils.trim(normalize(n1.getNodeValue() + ""));
    final String v2 = StringUtils.trim(normalize(n2.getNodeValue() + ""));
    final boolean eq = StringUtils.equals(v1, v2);
    if (!eq) {
        log.info("Text nodes are not equal: " + v1 + " and " + v2);
    }
    return eq;

}

From source file:br.com.bluesoft.guardian.faker.Internet.java

/**
 * Generates a random image url based on the lorempixel service. All the images provided by this service are released
 * under the creative commons license (CC BY-SA). For more information, please visit: http://lorempixel.com/
 *
 * @return an url to a random image.//from   w ww  .j ava  2  s.  co  m
 * @see <a href="http://lorempixel.com/">lorempixel - Placeholder Images for every case</a>
 */
public String image() {
    String[] dimension = StringUtils.split(fakeValuesService.fetchString("internet.image_dimension"), 'x');
    if (dimension.length == 0)
        return "";
    return image(Integer.valueOf(StringUtils.trim(dimension[0])),
            Integer.valueOf(StringUtils.trim(dimension[1])), randomService.nextBoolean(), null);
}