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.epam.catgenome.util.Utils.java

/**
 * Parses the original name of a file to remove its extension that matches the given one.
 * <p>//from  w w  w . j  a va  2s .  co m
 * It results in StringUtils.trimToNull() applied to <tt>fileName</tt> in the following
 * cases:
 * 1) <tt>fileName</tt> is <tt>null</tt> or consists of whitespaces only;
 * 2) <tt>extension</tt> is <tt>null</tt> or consists of whitespaces only;
 * 3) a call fileName.endsWith(extension) results with <tt>false</tt>; here both
 * <tt>fileName</tt> and <tt>extension</tt> are trimmed before checking.
 * <p>
 * Note:
 * It's expected <tt>extension</tt> starts with a dot that means e.g. '.txt' is correct,
 * but 'txt' is "illegal", because in such case the last dot won't be cut.
 *
 * @param fileName  {@code String} specifies the original filename including extension
 * @param extension {@code String} specifies the extension of a file that should be cut;
 *                  it should start with a dot - '.txt' is correct, 'txt' is illegal
 * @return {@code String}
 */
public static String removeFileExtension(final String fileName, final String extension) {
    String fn = StringUtils.trimToNull(fileName);
    String ext = StringUtils.trimToNull(extension);
    return fn == null || ext == null || !fn.endsWith(ext) ? fn
            : fn.substring(0, fn.length() - ext.length()).trim();
}

From source file:info.novatec.testit.livingdoc.confluence.actions.server.DemoSpaceAction.java

public void setPwd(String pwd) {
    this.pwd = StringUtils.trimToNull(pwd);
}

From source file:com.vaporwarecorp.mirror.feature.AbstractCommand.java

protected String text(JsonNode node, String key) {
    JsonNode keyNode = jsonNodeValue(node, key);
    if (keyNode != null) {
        keyNode = keyNode.get(0);/*from w ww .j  a v a 2 s  . com*/
        if (keyNode != null) {
            return StringUtils.trimToNull(keyNode.textValue());
        }
    }
    return null;
}

From source file:alfio.controller.DynamicResourcesController.java

@RequestMapping("/resources/js/google-analytics")
public void getGoogleAnalyticsScript(HttpSession session, HttpServletResponse response,
        @RequestParam("e") Integer eventId) throws IOException {
    response.setContentType("application/javascript");
    Optional<Event> ev = Optional.ofNullable(eventId)
            .flatMap(id -> Optional.ofNullable(eventRepository.findById(id)));
    ConfigurationPathKey pathKey = ev//from   w w w . j  a v  a  2  s.  c  o  m
            .map(e -> Configuration.from(e.getOrganizationId(), e.getId(), GOOGLE_ANALYTICS_KEY))
            .orElseGet(() -> Configuration.getSystemConfiguration(GOOGLE_ANALYTICS_KEY));
    final Optional<String> id = configurationManager.getStringConfigValue(pathKey);
    final String script;
    ConfigurationPathKey anonymousPathKey = ev
            .map(e -> Configuration.from(e.getOrganizationId(), e.getId(), GOOGLE_ANALYTICS_ANONYMOUS_MODE))
            .orElseGet(() -> Configuration.getSystemConfiguration(GOOGLE_ANALYTICS_ANONYMOUS_MODE));
    if (id.isPresent() && configurationManager.getBooleanConfigValue(anonymousPathKey, true)) {
        String trackingId = Optional
                .ofNullable(StringUtils.trimToNull((String) session.getAttribute("GA_TRACKING_ID")))
                .orElseGet(() -> UUID.randomUUID().toString());
        Map<String, Object> model = new HashMap<>();
        model.put("clientId", trackingId);
        model.put("account", id.get());
        script = templateManager.renderTemplate(TemplateResource.GOOGLE_ANALYTICS, model, Locale.ENGLISH);
    } else {
        script = id.map(x -> String.format(GOOGLE_ANALYTICS_SCRIPT, x)).orElse(EMPTY);
    }
    response.getWriter().write(script);
}

From source file:com.xylocore.cassandra.query.TableScanQueryBuilder.java

/**
 * FILLIN//from  w ww.  j  ava  2s.  c o  m
 * 
 * @param       aColumnName
 * @param       aAlias
 * 
 * @return
 */
public TableScanQueryBuilder<T> column(String aColumnName, String aAlias) {
    Validate.notBlank(aColumnName);

    aAlias = StringUtils.trimToNull(aAlias);

    if (aAlias == null) {
        aAlias = aColumnName;
    }

    columnsOfInterest.put(aColumnName, aAlias);

    return this;
}

From source file:net.lmxm.ute.executers.tasks.subversion.SubversionWorkingCopyUtils.java

/**
 * Update working copy.//from  www  .ja  va2s .  c o m
 *
 * @param path the path
 */
public void updateWorkingCopy(final String path) {
    final String prefix = "updateWorkingCopy() :";

    LOGGER.debug("{} entered, path={}", prefix, path);

    final String pathTrimmed = StringUtils.trimToNull(path);

    checkNotNull(pathTrimmed, "Path must not be blank");
    checkState(isWorkingCopy(pathTrimmed), "Path must be a working copy root");

    try {
        LOGGER.debug("{} start updating working copy", prefix);

        getJobStatusChangeEventBus().important(SUBVERSION_UPDATE_STARTED, pathTrimmed);

        final DefaultSVNOptions options = SVNWCUtil.createDefaultOptions(true);
        final SVNClientManager clientManager = SVNClientManager.newInstance(options);
        clientManager.setAuthenticationManager(getAuthenticationManager());

        final SVNUpdateClient updateClient = clientManager.getUpdateClient();
        updateClient.setEventHandler(new EventHandler(getJobStatusChangeEventBus()));
        updateClient.doUpdate(new File(pathTrimmed), SVNRevision.HEAD, SVNDepth.INFINITY, true, false);

        getJobStatusChangeEventBus().important(SUBVERSION_UPDATE_FINISHED, pathTrimmed);

        LOGGER.debug("{} finished updating working copy", prefix);
    } catch (final SVNAuthenticationException e) {
        LOGGER.error("SVNAuthenticationException caught exporting a file", e);
        getJobStatusChangeEventBus().error(SUBVERSION_AUTHENTICATION_FAILED);
        throw new TaskExecuterException(ExceptionResourceType.SUBVERSION_AUTHENTICATION_FAILED, e);
    } catch (final SVNException e) {
        LOGGER.error("SVNException caught while updating working copy", e);
        getJobStatusChangeEventBus().error(SUBVERSION_UPDATE_ERROR, pathTrimmed);
        throw new TaskExecuterException(ExceptionResourceType.SUBVERSION_UPDATE_ERROR, e);
    }

    LOGGER.debug("{} leaving", prefix);
}

From source file:info.novatec.testit.livingdoc.confluence.actions.server.DemoSpaceAction.java

public void setUsername(String username) {
    this.username = StringUtils.trimToNull(username);
}

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

/**
 * Loads the consolidated {@code entities.properties} file and returns the all the lines that it contains.
 * /*from  w  ww .  j a va 2s.  co m*/
 * @return The lines within the properties file.
 */
private String[] readLines() throws Exception {
    logger.entering();

    InputStream input = null;
    String[] lines = null;
    try {
        input = getClass().getClassLoader()
                .getResourceAsStream(StringUtils.trimToNull(System.getProperty(FILE_PATH_PROPERTY)));
        lines = StringUtils.split(new Scanner(input).useDelimiter("\\A").next());
    } finally {
        try {
            input.close();
        } catch (Exception e) {
        }
    }
    if (lines == null)
        lines = new String[0];

    logger.exiting(lines);
    return lines;
}

From source file:hoot.services.controllers.job.ReviewResourceMarkTest.java

private MarkItemsReviewedResponse execMark(final String mapId, final String markAll,
        final MarkItemsReviewedRequest markItemsReviewedRequest) throws Exception {
    WebResource resource = resource().path("/review");
    if (mapId != null) {
        resource = resource.queryParam("mapId", mapId);
    }/* w w w .j  av a2  s . c om*/
    if (StringUtils.trimToNull(markAll) != null) {
        resource = resource.queryParam("markAll", markAll);
    }
    return resource.type(MediaType.APPLICATION_JSON).accept(MediaType.APPLICATION_JSON)
            .put(MarkItemsReviewedResponse.class, markItemsReviewedRequest);
}

From source file:com.vaporwarecorp.mirror.feature.AbstractCommand.java

protected String textValue(JsonNode node, String key) {
    JsonNode keyNode = jsonNodeValue(node, key);
    if (keyNode != null) {
        return StringUtils.trimToNull(keyNode.textValue());
    }/*from www  . j  a  va 2 s  .c om*/
    return null;
}