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.baidu.cc.FilterableConfigItemChangedCallable.java

/**
 * default constructor//from   ww  w .j a v  a2  s  .com
 * 
 * @param method target method
 * @param target target bean
 * @param filerKeyStr filter keys set from annotation
 */
public FilterableConfigItemChangedCallable(Method method, Object target, String filerKeyStr) {
    super();
    Assert.notNull(method, "property 'method' should not be null");
    this.method = method;
    //check method
    Class<?>[] parameterTypes = method.getParameterTypes();
    if (parameterTypes == null || parameterTypes.length != 1 || !List.class.equals(parameterTypes[0])) {
        throw new RuntimeException("Invalid method. @ConfigChangeNotifer method only "
                + "has one parameter and type is List<'" + ChangedConfigItem.class.getName() + ">'");
    }

    this.target = target;
    filerKeys = new HashSet<String>();
    if (StringUtils.isNotBlank(filerKeyStr)) {
        String[] split = StringUtils.split(filerKeyStr, ",");
        for (String string : split) {
            filerKeys.add(StringUtils.trim(string));
        }
    }

}

From source file:com.boozallen.cognition.ingest.storm.bolt.csv.CsvLogRecordParser.java

public void parse(Reader fileReader, String fileType, LogRecordCollector collector) throws IOException {
    try (CSVReader csvReader = new CSVReader(fileReader, config.getDelimiter(),
            CSVParser.DEFAULT_QUOTE_CHARACTER, CSVParser.NULL_CHARACTER);) {

        long line = 0;

        String[] headers = csvReader.readNext();
        line++;//from  w w  w .  j a v  a2s  . co  m
        String[] fieldNames = constructFieldNames(headers, fileType, config.isCleanKeysForES());

        String[] record = null;
        while ((record = csvReader.readNext()) != null) {
            if (record.length != headers.length) {
                // unmatched record length
                LOGGER.warn("Unmatched record column count detected at line {} - header: {} record: {}", line,
                        headers.length, record.length);
                continue;
            }
            LogRecord logRecord = new LogRecord();
            for (int i = 0; i < fieldNames.length; i++) {
                if (config.isSkipBlankFields() && StringUtils.isBlank(record[i])) {
                    // skip
                } else {
                    String value = config.isTrimFieldValue() ? StringUtils.trim(record[i]) : record[i];
                    logRecord.setValue(fieldNames[i], value);
                }
            }
            collector.emit(logRecord);
        }
    }
}

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

public void setSrc(String src) {
    this.src = StringUtils.trim(src);
}

From source file:jp.ikedam.jenkins.plugins.viewcopy_builder.SetDescriptionOperation.java

@DataBoundConstructor
public SetDescriptionOperation(String description) {
    this.description = StringUtils.trim(description);
}

From source file:jp.ikedam.jenkins.plugins.scoringloadbalancer.preferences.BuildPreference.java

/**
 * Constructor.//from  ww  w .j a  v  a2 s  .  c om
 * 
 * Initialized with values a user configured.
 * 
 * @param labelExpression
 * @param preference
 */
@DataBoundConstructor
public BuildPreference(String labelExpression, int preference) {
    this.labelExpression = StringUtils.trim(labelExpression);
    this.preference = preference;
}

From source file:com.incapture.slate.model.node.IndexNode.java

@Override
public String getContent() {
    String template = TemplateRepo.INSTANCE.getTemplate("indexNode");
    CompiledTemplate compiled = TemplateCompiler.compileTemplate(template);
    Map<String, Object> vars = new HashMap<>();
    vars.put("title", getTitle());
    vars.put("languages", languages);
    vars.put("tocFooters", tocFooters);
    vars.put("includeFiles", createIncludeFilesList());
    vars.put("isSearchable", isSearchable);
    return StringUtils.trim(TemplateRuntime.execute(compiled, vars).toString());
}

From source file:com.haulmont.cuba.web.gui.components.WebAbstractTextField.java

@Override
public <V> V getValue() {
    String value = super.getValue();
    if (isTrimming()) {
        value = StringUtils.trim(value);
    }//w  w w.  j a v  a2s.c o  m
    value = Strings.emptyToNull(value);

    Datatype datatype = getActualDatatype();
    if (value != null && datatype != null) {
        try {
            return (V) datatype.parse(value, locale);
        } catch (ParseException e) {
            Logger log = LoggerFactory.getLogger(WebAbstractTextField.class);
            log.debug("Unable to parse value of component {}\n{}", getId(), e.getMessage());
            return null;
        }
    } else {
        return (V) value;
    }
}

From source file:com.adobe.acs.commons.contentfinder.querybuilder.impl.viewhandler.GQLToQueryBuilderConverter.java

@SuppressWarnings("squid:S3776")
public static Map<String, String> addOrder(final SlingHttpServletRequest request, Map<String, String> map,
        final String queryString) {
    if (has(request, CF_ORDER)) {

        int count = 1;
        for (String value : getAll(request, CF_ORDER)) {
            value = StringUtils.trim(value);
            final String orderGroupId = String.valueOf(GROUP_ORDERBY_USERDEFINED + count) + SUFFIX_ORDERBY;
            boolean sortAsc = false;

            if (StringUtils.startsWith(value, "-")) {
                value = StringUtils.removeStart(value, "-");
            } else if (StringUtils.startsWith(value, "+")) {
                sortAsc = true;//from  ww  w.j a  va2s  .  c o m
                value = StringUtils.removeStart(value, "+");
            }

            map.put(orderGroupId, StringUtils.trim(value));
            map.put(orderGroupId + ".sort", sortAsc ? Predicate.SORT_ASCENDING : Predicate.SORT_DESCENDING);

            count++;
        }

    } else {

        final boolean isPage = isPage(request);
        final boolean isAsset = isAsset(request);
        final String prefix = getPropertyPrefix(request);

        if (StringUtils.isNotBlank(queryString)) {
            map.put(GROUP_ORDERBY_SCORE + SUFFIX_ORDERBY, AT + JcrConstants.JCR_SCORE);
            map.put(GROUP_ORDERBY_SCORE + SUFFIX_ORDERBY_SORT, Predicate.SORT_DESCENDING);
        }

        String modifiedOrderProperty = AT + JcrConstants.JCR_LASTMODIFIED;
        if (isPage) {
            modifiedOrderProperty = AT + prefix + NameConstants.PN_PAGE_LAST_MOD;
        } else if (isAsset) {
            modifiedOrderProperty = AT + prefix + JcrConstants.JCR_LASTMODIFIED;
        }

        map.put(GROUP_ORDERBY_MODIFIED + SUFFIX_ORDERBY, modifiedOrderProperty);
        map.put(GROUP_ORDERBY_MODIFIED + SUFFIX_ORDERBY_SORT, Predicate.SORT_DESCENDING);
    }

    return map;
}

From source file:gemlite.core.webapp.demo.OrderController.java

@RequestMapping(value = "/customer", method = RequestMethod.POST)
@ResponseBody/*w w  w  .j  av a2 s.  co m*/
public ModelAndView post(HttpServletRequest request, ModelAndView modelAndView) {

    List<Customer> list = new ArrayList<Customer>();
    modelAndView = new ModelAndView("demo/customer");
    String c_name = StringUtils.trim((String) request.getParameter("c_name"));
    boolean c_like = StringUtils.equals((String) request.getParameter("c_like"), "on");
    String c_id = StringUtils.trim((String) request.getParameter("c_id"));
    Integer c_age_begin = StringUtils.isEmpty((String) request.getParameter("c_age_begin")) ? null
            : Integer.valueOf((String) request.getParameter("c_age_begin"));
    Integer c_age_end = StringUtils.isEmpty((String) request.getParameter("c_age_end")) ? null
            : Integer.valueOf((String) request.getParameter("c_age_end"));
    String c_tel = StringUtils.trim((String) request.getParameter("c_tel"));
    getConnection();
    if (StringUtils.isNotEmpty(c_name) && StringUtils.isNotEmpty(c_id) && !c_like) {
        CustomerDBKey key = new CustomerDBKey();
        key.setName(c_name);
        key.setId_num(c_id);
        RemoteResult rr = LogicServices.createRequestWithFilter("customer", "QueryByCustomerDBKey", key, key);
        if (rr != null) {
            Customer cust = rr.getResult(Customer.class);
            if (cust != null)
                list.add(cust);
        }
    } else if (c_like && StringUtils.isNotEmpty(c_name)) {
        RemoteResult rr = LogicServices.createHeavyRequest("QueryByCustomerNameLike", c_name);
        if (rr != null)
            list = rr.getResult(List.class);
    } else if (!c_like && StringUtils.isNotEmpty(c_name) && StringUtils.isEmpty(c_id)) {

        RemoteResult rr = LogicServices.createRequestWithFilter("customer", "QueryByCustomerName", c_name,
                c_name);
        if (rr != null)
            list = rr.getResult(List.class);
    }

    else if (StringUtils.isNotEmpty(c_id)) {
        RemoteResult rr = LogicServices.createHeavyRequest("QueryByCustomerID", c_id);
        if (rr != null)
            list = rr.getResult(List.class);
    }

    else if (StringUtils.isNotEmpty(c_tel)) {

        RemoteResult rr = LogicServices.createRequestWithFilter("CustomerIndex04", "GetNamesFromTel", c_tel,
                c_tel);
        if (rr != null)
            list = rr.getResult(List.class);
    } else if (c_age_begin != null && c_age_end != null) {
        Map map = new HashMap();
        if (c_age_begin != 0)
            map.put("min", c_age_begin);
        if (c_age_end != 0)
            map.put("max", c_age_end);

        RemoteResult rr = LogicServices.createHeavyRequest("QueryByCustomerAgeRange", map);
        if (rr != null)
            list = rr.getResult(List.class);
    }

    modelAndView.addObject("list", list);
    // set user's query terms
    modelAndView.addObject("c_name", c_name);
    modelAndView.addObject("c_id", c_id);
    modelAndView.addObject("c_age_begin", c_age_begin);
    modelAndView.addObject("c_age_end", c_age_end);
    modelAndView.addObject("c_tel", c_tel);

    return modelAndView;
}

From source file:hydrograph.ui.expression.editor.styletext.ExpressionEditorStyledText.java

@Override
public void insert(String string) {
    if (!StringUtils.startsWith(StringUtils.trim(string), Messages.CANNOT_SEARCH_INPUT_STRING)) {
        super.insert(string);
        this.setFocus();
        this.setSelection(this.getText().length() + 100);
    }//from  w w  w. j  ava2  s.c  o m
}