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

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

Introduction

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

Prototype

public static String trimToNull(final String str) 

Source Link

Document

Removes control characters (char <= 32) from both ends of this String returning null if the String is empty ("") after the trim or if it is null .

Usage

From source file:com.intuit.karate.ScriptEnv.java

public ScriptEnv refresh() { // immutable
    String karateEnv = StringUtils.trimToNull(env);
    if (karateEnv == null) {
        karateEnv = StringUtils.trimToNull(System.getProperty("karate.env"));
        if (karateEnv != null) {
            logger.debug("obtained 'karate.env' from system properties: {}", karateEnv);
        }/*from  w  ww  .j  a v  a  2 s  .c  o  m*/
    }
    return new ScriptEnv(test, karateEnv, featureDir, featureName, fileClassLoader);
}

From source file:com.threewks.thundr.configuration.PropertiesLoader.java

private Map<String, String> readProperties(String resourceAsString) {
    Map<String, String> properties = new LinkedHashMap<String, String>();
    Scanner scanner = new Scanner(resourceAsString);
    try {/*  w ww .  j  a  va  2 s  . c o  m*/
        while (scanner.hasNextLine()) {
            String line = scanner.nextLine();
            line = StringUtils.substringBefore(line, "#");
            line = StringUtils.trimToNull(line);
            String key = StringUtils.substringBefore(line, "=");
            String value = StringUtils.substringAfter(line, "=");
            if (key != null) {
                properties.put(key, value);
            }
        }
    } finally {
        scanner.close();
    }
    return properties;
}

From source file:hu.bme.mit.sette.common.model.runner.xml.InputElement.java

/**
 * Sets the heap.
 *
 * @param heap
 *            the new heap
 */
public void setHeap(String heap) {
    this.heap = StringUtils.trimToNull(heap);
}

From source file:de.micromata.genome.gwiki.page.impl.GWikiChangeCommentEditorArtefakt.java

@Override
public void onSave(GWikiContext ctx) {
    String text = ctx.getRequestParameter(partName + ".wikiText");
    String oldText = textPage.getStorageData();
    String ntext;/*from  w  ww  .ja  v a  2s  . c o  m*/
    String uname = ctx.getWikiWeb().getAuthorization().getCurrentUserName(ctx);
    int prevVersion = elementToEdit.getElementInfo().getProps().getIntValue(GWikiPropKeys.VERSION, 0);
    if (StringUtils.isNotBlank(text) == true) {
        Date now = new Date();
        ntext = "{changecomment:modifiedBy=" + uname + "|modifiedAt=" + GWikiProps.date2string(now)
                + "|version=" + (prevVersion + 1) + "}\n" + text + "\n{changecomment}\n"
                + StringUtils.defaultString(oldText);
    } else {
        ntext = oldText;
    }
    ntext = StringUtils.trimToNull(ntext);
    textPage.setStorageData(ntext);
}

From source file:com.alibaba.dubboadmin.web.mvc.governance.LoadbalancesController.java

@RequestMapping("")
public String index(HttpServletRequest request, HttpServletResponse response, Model model) {
    prepare(request, response, model, "index", "loadbalances");
    BindingAwareModelMap newModel = (BindingAwareModelMap) model;
    String service = (String) newModel.get("service");
    service = StringUtils.trimToNull(service);

    List<LoadBalance> loadbalances;
    if (service != null && service.length() > 0) {
        loadbalances = OverrideUtils.overridesToLoadBalances(overrideService.findByService(service));
    } else {/* ww w.java  2s .  c om*/
        loadbalances = OverrideUtils.overridesToLoadBalances(overrideService.findAll());
    }
    model.addAttribute("loadbalances", loadbalances);
    return "governance/screen/loadbalances/index";
}

From source file:com.norconex.importer.handler.tagger.AbstractCharStreamTagger.java

@Override
protected final void tagApplicableDocument(String reference, InputStream document, ImporterMetadata metadata,
        boolean parsed) throws ImporterHandlerException {

    String contentType = metadata.getString("Content-Type", "");
    contentType = StringUtils.substringBefore(contentType, ";");

    String charset = metadata.getString("Content-Encoding", null);
    if (charset == null) {
        charset = metadata.getString("charset", null);
    }//from w  w w  .ja v a2s.  com
    if (charset == null) {
        for (String type : metadata.getStrings("Content-Type")) {
            if (type.contains("charset")) {
                charset = StringUtils.trimToNull(StringUtils.substringAfter(type, "charset="));
                break;
            }
        }
    }
    if (StringUtils.isBlank(charset) || !CharEncoding.isSupported(charset)) {
        charset = CharEncoding.UTF_8;
    }
    try {
        InputStreamReader is = new InputStreamReader(document, charset);
        tagTextDocument(reference, is, metadata, parsed);
    } catch (UnsupportedEncodingException e) {
        throw new ImporterHandlerException(e);
    }
}

From source file:com.moviejukebox.plugin.MovieListingPluginCustomCsv.java

/**
 * Take a comma-separated list of field names and split them into separate fields
 *
 * @param aFields Text to split/*from ww  w.ja  va2 s .co  m*/
 * @return Number of fields found
 */
private int initFields(String aFields) {
    // Clear the current list (if there is one)
    mFields = new ArrayList<>();

    for (StringTokenizer t = new StringTokenizer(aFields, ","); t.hasMoreTokens();) {
        String st = StringUtils.trimToNull(t.nextToken());
        if (st != null) {
            mFields.add(st);
        }
    }
    return mFields.size();
}

From source file:hu.bme.mit.sette.common.descriptors.java.JavaClassWithMain.java

/**
 * Sets the name of the package.//from   ww  w.j  a  v a2  s  .  co m
 *
 * @param pPackageName
 *            The name of the package.
 */
public void setPackageName(final String pPackageName) {
    packageName = StringUtils.trimToNull(pPackageName);
}

From source file:alfio.controller.api.SpecialPriceApiController.java

@RequestMapping("/events/{eventName}/categories/{categoryId}/link-codes")
public List<SendCodeModification> linkAssigneeToCodes(@PathVariable("eventName") String eventName,
        @PathVariable("categoryId") int categoryId, @RequestParam("file") MultipartFile file,
        Principal principal) throws IOException {

    Validate.isTrue(StringUtils.isNotEmpty(eventName));
    try (InputStreamReader isr = new InputStreamReader(file.getInputStream())) {
        CSVReader reader = new CSVReader(isr);
        List<SendCodeModification> content = reader.readAll().stream().map(line -> {
            Validate.isTrue(line.length >= 4);
            return new SendCodeModification(StringUtils.trimToNull(line[0]), line[1], line[2], line[3]);
        }).collect(Collectors.toList());
        return specialPriceManager.linkAssigneeToCode(content, eventName, categoryId, principal.getName());
    }/*from  w  ww  . j a  va2  s.  c o  m*/
}

From source file:com.neocotic.bloggaer.web.listener.EntityRegistrationListener.java

@Override
public void contextInitialized(ServletContextEvent event) {
    logger.entering(event);/*from  w ww  . ja va  2 s.  c om*/

    try {
        for (String line : readLines()) {
            line = StringUtils.trimToNull(line);
            // Ensure line isn't empty or a comment.
            if (line != null && !line.startsWith("#")) {
                ObjectifyService.register(getClass().getClassLoader().loadClass(line));
                logger.config("Registered entity: " + line);
            }
        }
    } catch (Exception e) {
        e = new BloggaerRuntimeException(e);
        logger.throwing(e);
        throw (BloggaerRuntimeException) e;
    }

    logger.exiting();
}