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:org.ahp.vinavidai.console.form.QuizConsoleForm.java

@Override
public ActionErrors validate(ActionMapping pActionMapping, HttpServletRequest pHttpServletRequest) {
    ActionErrors lActionErrors = new ActionErrors();
    String lSubmitAction = StringUtils.trimToNull(this.getSubmitAction());
    if (lSubmitAction != null && SubmitActions.NEXT.toString().equals((lSubmitAction))) {
    }//from   ww w  .  j  a va 2s .  c o  m
    return lActionErrors;
}

From source file:org.ahp.vinavidai.quiz.action.ProcessCreateQuizConfirmation.java

@Override
public ActionForward process(ActionMapping pActionMapping, ActionForm pActionForm,
        HttpServletRequest pHttpServletRequest, HttpServletResponse pHttpServletResponse) {
    User lLoggedInUser = AhpActionHelper.getLoggedInUser(pHttpServletRequest);
    CreateQuestionForm lCreateQuestionForm = (CreateQuestionForm) pActionForm;
    String lSubmitAction = StringUtils.trimToNull(lCreateQuestionForm.getSubmitAction());
    lCreateQuestionForm.setNextPage(NavigateActions.DisplayCreateQuizConfirmation.toString());
    return pActionMapping.findForward(NavigateActions.DisplayCreateQuizConfirmation.toString());
}

From source file:org.ahp.vinavidai.quiz.form.CreateQuestionForm.java

@Override
public ActionErrors validate(ActionMapping pActionMapping, HttpServletRequest pHttpServletRequest) {
    ActionErrors lActionErrors = new ActionErrors();
    String lSubmitAction = StringUtils.trimToNull(this.getSubmitAction());
    if (lSubmitAction != null) {
        if (lSubmitAction.equals(SubmitActions.CONTINUE.toString())
                || lSubmitAction.equals(SubmitActions.COMPLETE.toString())
                || lSubmitAction.equals(SubmitActions.NEXT.toString())) {
            QuestionValidator.validateCreateQuestionForm(this, lActionErrors);
        }//from w  w w.  ja  v a  2s  . c o  m
        if (lSubmitAction.equals(SubmitActions.CANCEL.toString())) {
        }
        if (lSubmitAction.equals(SubmitActions.GO.toString())) {
        }
    }
    return lActionErrors;
}

From source file:org.ahp.vinavidai.quiz.form.EditQuestionForm.java

@Override
public ActionErrors validate(ActionMapping pActionMapping, HttpServletRequest pHttpServletRequest) {
    ActionErrors lActionErrors = new ActionErrors();
    String lSubmitAction = StringUtils.trimToNull(this.getSubmitAction());
    if (lSubmitAction != null) {
        if (lSubmitAction.equals(SubmitActions.CONTINUE.toString())
                || lSubmitAction.equals(SubmitActions.COMPLETE.toString())
                || lSubmitAction.equals(SubmitActions.NEXT.toString())) {
            QuestionValidator.validateEditQuestionForm(this, lActionErrors);
        }//from   w w w.  ja  v a  2 s . c o  m
        if (lSubmitAction.equals(SubmitActions.CANCEL.toString())) {
        }
        if (lSubmitAction.equals(SubmitActions.GO.toString())) {
        }
    }
    return lActionErrors;
}

From source file:org.ahp.vinavidai.test.controller.TestInfo.java

@RequestMapping(method = RequestMethod.GET)
public String displayTestInfo(HttpServletRequest pHttpServletRequest, ModelMap pModelMap) {
    TestInfoCommand lTestInfoCommand = new TestInfoCommand();
    String lTestAccessKey = (String) pHttpServletRequest.getParameter("accessKey");
    if (StringUtils.trimToNull(lTestAccessKey) != null) {
        Test lTest = this.mTestService.loadTest(lTestAccessKey);
        lTestInfoCommand.setAccessKey(lTestAccessKey);
        lTestInfoCommand.setTest(lTest);
    }/*from w w w .  j  a v a2s . com*/
    pModelMap.put("testInfo", lTestInfoCommand);
    return "/test/TestInfo.jsp";
}

From source file:org.apache.marmotta.platform.ldp.webservices.PreferHeader.java

/**
 * Parse a PreferHeader./*w ww . ja v a2 s .  c  o  m*/
 * @param headerValue the header value to parse
 * @return the parsed PreferHeader
 */
public static PreferHeader valueOf(String headerValue) {
    if (StringUtils.isBlank(headerValue)) {
        log.error("Empty Prefer-Header - what should I do now?");
        throw new InvalidArgumentException();
    }

    String pref = null, val = null;
    final Map<String, String> params = new LinkedHashMap<>();
    final String[] parts = headerValue.split("\\s*;\\s");
    for (int i = 0; i < parts.length; i++) {
        final String part = parts[i];
        final String[] kv = part.split("\\s*=\\s*", 2);
        if (i == 0) {
            pref = StringUtils.trimToNull(kv[0]);
            if (kv.length > 1) {
                val = StringUtils.trimToNull(StringUtils.removeStart(StringUtils.removeEnd(kv[1], "\""), "\""));
            }
        } else {
            String p, pval = null;
            p = StringUtils.trimToNull(kv[0]);
            if (kv.length > 1) {
                pval = StringUtils
                        .trimToNull(StringUtils.removeStart(StringUtils.removeEnd(kv[1], "\""), "\""));
            }
            params.put(p, pval);
        }
    }

    final PreferHeader header = new PreferHeader(pref);
    header.preferenceValue = val;
    header.params = params;

    return header;
}

From source file:org.apache.samza.config.JavaStorageConfig.java

public String getChangelogStream(String storeName) {

    // If the config specifies 'stores.<storename>.changelog' as '<system>.<stream>' combination - it will take precedence.
    // If this config only specifies <astream> and there is a value in job.changelog.system=<asystem> -
    // these values will be combined into <asystem>.<astream>
    String systemStream = StringUtils.trimToNull(get(String.format(CHANGELOG_STREAM, storeName), null));

    String systemStreamRes;/*  w  w  w .j  a va  2s  .co m*/
    if (systemStream != null && !systemStream.contains(".")) {
        String changelogSystem = getChangelogSystem();
        // contains only stream name
        if (changelogSystem != null) {
            systemStreamRes = changelogSystem + "." + systemStream;
        } else {
            throw new SamzaException("changelog system is not defined:" + systemStream);
        }
    } else {
        systemStreamRes = systemStream;
    }

    if (systemStreamRes != null) {
        systemStreamRes = StreamManager.createUniqueNameForBatch(systemStreamRes, this);
    }
    return systemStreamRes;
}

From source file:org.apache.samza.config.StorageConfig.java

/**
 * If the config specifies 'stores.&lt;storename&gt;.changelog' as '&lt;system&gt;.&lt;stream&gt;' combination - it will take
 * precedence./*from  w w  w  . j  av  a  2 s.  c o m*/
 * If this config only specifies &lt;astream&gt; and there is a value in job.changelog.system=&lt;asystem&gt; - these values will
 * be combined into &lt;asystem&gt;.&lt;astream&gt;
 */
public Optional<String> getChangelogStream(String storeName) {
    String systemStream = StringUtils.trimToNull(get(String.format(CHANGELOG_STREAM, storeName), null));

    String systemStreamRes;
    if (systemStream != null && !systemStream.contains(".")) {
        Optional<String> changelogSystem = getChangelogSystem();
        // contains only stream name
        if (changelogSystem.isPresent()) {
            systemStreamRes = changelogSystem.get() + "." + systemStream;
        } else {
            throw new SamzaException("changelog system is not defined:" + systemStream);
        }
    } else {
        systemStreamRes = systemStream;
    }

    if (systemStreamRes != null) {
        systemStreamRes = StreamManager.createUniqueNameForBatch(systemStreamRes, this);
    }
    return Optional.ofNullable(systemStreamRes);
}

From source file:org.apereo.services.persondir.support.SimpleUsernameAttributeProvider.java

@Override
public String getUsernameFromQuery(final Map<String, List<Object>> query) {
    final List<Object> usernameAttributeValues = query.get(this.usernameAttribute);

    if (usernameAttributeValues == null || usernameAttributeValues.size() == 0) {
        return null;
    }/*from  w  w  w. j av a  2 s.  co  m*/

    final Object firstValue = usernameAttributeValues.get(0);
    if (firstValue == null) {
        return null;
    }

    final String username = StringUtils.trimToNull(String.valueOf(firstValue));
    if (username == null || username.contains(IPersonAttributeDao.WILDCARD)) {
        return null;
    }

    return username;
}

From source file:org.brekka.pegasus.core.services.impl.UsernamePasswordServiceImpl.java

protected byte[] deriveUsername(String username) {
    username = StringUtils.trimToNull(username);
    PegasusUtils.checkNotNull(username, "username");
    SystemDerivedKeySpecType spec = config.getSystemDerivedKeySpec();
    if (!config.getUserNameCaseSensitive()) {
        username = username.toUpperCase();
    }/*from   www  .j  ava  2s .  c  o m*/
    byte[] data = toBytes(username);
    DerivedKey derivedKey = derivedKeyCryptoService.apply(data, spec.getSalt(), null,
            CryptoProfile.Static.of(spec.getCryptoProfile()));
    return derivedKey.getDerivedKey();
}