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:alpine.json.TrimmedStringArrayDeserializer.java

@Override
public String[] deserialize(JsonParser jsonParser, DeserializationContext context) throws IOException {
    final List<String> list = new ArrayList<>();
    final JsonNode node = jsonParser.readValueAsTree();
    if (node.isArray()) {
        final Iterator elements = node.elements();
        while (elements.hasNext()) {
            final JsonNode childNode = (JsonNode) elements.next();
            final String value = StringUtils.trimToNull(childNode.asText());
            if (value != null) {
                list.add(value);/*w ww  .j ava  2s .  c o m*/
            }
        }
    }
    if (list.size() == 0) {
        return null;
    } else {
        return list.toArray(new String[list.size()]);
    }
}

From source file:com.chiorichan.factory.event.PostJSMinProcessor.java

@EventHandler()
public void onEvent(PostEvalEvent event) {
    if (!event.context().contentType().equals("application/javascript-x")
            || !event.context().filename().endsWith("js"))
        return;/*  ww w  . ja  v a 2s  .  c  om*/

    // A simple way to ignore JS files that might already be minimized
    if (event.context().filename() != null && event.context().filename().toLowerCase().endsWith(".min.js"))
        return;

    String code = event.context().readString();
    List<SourceFile> externs = Lists.newArrayList();
    List<SourceFile> inputs = Arrays.asList(SourceFile.fromCode(
            (event.context().filename() == null || event.context().filename().isEmpty()) ? "fakefile.js"
                    : event.context().filename(),
            code));

    Compiler compiler = new Compiler();

    CompilerOptions options = new CompilerOptions();

    CompilationLevel.SIMPLE_OPTIMIZATIONS.setOptionsForCompilationLevel(options);

    compiler.compile(externs, inputs, options);

    event.context().resetAndWrite(StringUtils.trimToNull(compiler.toSource()));
}

From source file:com.jayway.restassured.config.MultiPartConfig.java

private MultiPartConfig(String defaultControlName, String defaultFileName, String defaultSubtype,
        boolean isUserConfigured) {
    this.defaultControlName = defaultControlName;
    this.defaultFileName = StringUtils.trimToNull(defaultFileName);
    this.defaultSubtype = StringUtils.trimToNull(defaultSubtype);
    AssertParameter.notNull(this.defaultControlName, "Default control name");
    AssertParameter.notNull(this.defaultSubtype, "Default subtype");
    this.isUserConfigured = isUserConfigured;
}

From source file:com.vaporwarecorp.mirror.util.JsonUtil.java

public static String textValue(JsonNode node, String key) {
    JsonNode keyNode = jsonNodeValue(node, key);
    if (keyNode != null) {
        return StringUtils.trimToNull(keyNode.textValue());
    }/*from w  w w.j ava  2 s.c o m*/
    return null;
}

From source file:com.norconex.collector.http.website.TestServlet.java

@Override
protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
    String testCaseKey = StringUtils.trimToNull(req.getParameter("case"));
    if (StringUtils.isBlank(testCaseKey)) {
        testCaseKey = "list";
    }/*from   w w  w .  j a  v a  2 s .c  om*/
    TestCase testCase = testCases.get(testCaseKey);
    if (testCase == null) {
        testCase = testCases.get("list");
    }
    try {
        testCase.doTestCase(req, resp);
        resp.flushBuffer();
    } catch (Exception e) {
        e.printStackTrace(resp.getWriter());
    }
}

From source file:com.chiorichan.factory.postprocessors.JSMinPostProcessor.java

@Override
public ByteBuf process(EvalMetaData meta, ByteBuf buf) throws Exception {
    // A simple way to ignore JS files that might already be minimized
    if (meta.fileName != null && meta.fileName.toLowerCase().endsWith(".min.js"))
        return buf;

    String code = buf.toString(Charset.defaultCharset());
    List<SourceFile> externs = Lists.newArrayList();
    List<SourceFile> inputs = Arrays.asList(SourceFile.fromCode(
            (meta.fileName == null || meta.fileName.isEmpty()) ? "fakefile.js" : meta.fileName, code));

    Compiler compiler = new Compiler();

    CompilerOptions options = new CompilerOptions();

    CompilationLevel.SIMPLE_OPTIMIZATIONS.setOptionsForCompilationLevel(options);

    compiler.compile(externs, inputs, options);

    return Unpooled.buffer().writeBytes(StringUtils.trimToNull(compiler.toSource()).getBytes());
}

From source file:de.micromata.genome.chronos.spi.HostUtils.java

/**
 * Enables settings of hostname within spring context (ref. genome logging).
 * // ww w .  jav a2  s.c o m
 * @param hostName May <code>null</code>
 * 
 */
public void setHostName(String hostName) {
    hostName = StringUtils.trimToNull(hostName);
    if (hostName != null) {
        HOSTNAME = hostName;
    }
}

From source file:com.threewks.thundr.user.controller.AuthenticatedFilter.java

public AuthenticatedFilter(SessionService<?> sessionService, String redirect) {
    super(sessionService);
    this.redirect = StringUtils.trimToNull(redirect);
}

From source file:com.goodhuddle.huddle.web.HuddleFilter.java

@Override
protected void doFilterInternal(HttpServletRequest request, HttpServletResponse response, FilterChain chain)
        throws ServletException, IOException {

    String huddleSlug = StringUtils.trimToNull(request.getHeader("huddle"));

    if (log.isTraceEnabled()) {
        log.trace("Processing request '{}' for Huddle with slug: '{}'", request.getRequestURL(), huddleSlug);
    }//from  ww  w . j av a  2 s . c om

    if (!request.getRequestURI().startsWith("/_huddles")) {
        Huddle huddle;
        if (huddleSlug != null) {
            if (huddleSlug.endsWith(".goodhuddle.com")) {
                huddleSlug = huddleSlug.substring(0, huddleSlug.length() - ".goodhuddle.com".length());
            }
            if (huddleSlug.startsWith("www.")) {
                huddleSlug = huddleSlug.substring("www.".length());
            }
            huddle = huddleService.getHuddle(huddleSlug);
        } else {
            List<Huddle> huddles = huddleService.getHuddles();
            if (huddles.size() == 1) {
                huddle = huddles.get(0);
            } else {
                huddle = null;
            }
        }

        huddleContext.setHuddle(huddle);
    }

    chain.doFilter(request, response);

}

From source file:de.knightsoftnet.validators.server.security.CsrfCookieHandler.java

/**
 * set csrf/xsrf cookie.//from  w w w .ja va2  s  .  co m
 */
public void setCookie(final HttpServletRequest prequest, final HttpServletResponse presponse)
        throws IOException {
    final CsrfToken csrf = (CsrfToken) prequest.getAttribute(CsrfToken.class.getName());
    if (csrf != null) {
        Cookie cookie = WebUtils.getCookie(prequest, ResourcePaths.XSRF_COOKIE);
        final String token = csrf.getToken();
        if (cookie == null || token != null && !token.equals(cookie.getValue())) {
            cookie = new Cookie(ResourcePaths.XSRF_COOKIE, token);
            cookie.setPath(StringUtils.defaultString(StringUtils.trimToNull(prequest.getContextPath()), "/"));
            presponse.addCookie(cookie);
        }
    }
}