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

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

Introduction

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

Prototype

public static String trimToEmpty(final String str) 

Source Link

Document

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

Usage

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

@Override
public ActionForward display(ActionMapping pActionMapping, ActionForm pActionForm,
        HttpServletRequest pHttpServletRequest, HttpServletResponse pHttpServletResponse) {
    User lLoggedInUser = AhpActionHelper.getLoggedInUser(pHttpServletRequest);
    EditQuestionForm lEditQuestionForm = (EditQuestionForm) pActionForm;
    String lNextPage = StringUtils.trimToEmpty(lEditQuestionForm.getNextPage());
    ActionForward lActionForward = pActionMapping.findForward(NavigateActions.DisplayEditQuestion.toString());
    if (NavigateActions.DisplayEditQuestion.toString().equals(lNextPage)
            || NavigateActions.DisplayEditQuestionNext.toString().equals(lNextPage)) {
        if (lEditQuestionForm.isSubmitAction(SubmitActions.EMPTY)) {
            Quiz lQuiz = (Quiz) pHttpServletRequest.getSession().getAttribute(QUIZ_UNDER_CREATION);
            if (lQuiz != null)
                lEditQuestionForm.setQuiz(lQuiz);
            this.setDefaultValues(lEditQuestionForm);
            pHttpServletRequest.getSession().removeAttribute(QUIZ_UNDER_CREATION);
        }//from w ww .  j a  va 2s  .  com
        if (lEditQuestionForm.isSubmitAction(SubmitActions.NEXT)) {
            Quiz lQuiz = (Quiz) pHttpServletRequest.getSession().getAttribute(QUIZ_UNDER_CREATION);
            if (lQuiz != null)
                lEditQuestionForm.setQuiz(lQuiz);
            this.setDefaultValues(lEditQuestionForm);
            pHttpServletRequest.getSession().removeAttribute(QUIZ_UNDER_CREATION);
        }
        if (lEditQuestionForm.isSubmitAction(SubmitActions.ADD_OPTION)) {
            Option lOption = new Option();
            lOption.setOptionDescription("");
            lEditQuestionForm.getOptions().add(lOption);
        }
        if (lEditQuestionForm.isSubmitAction(SubmitActions.DELETE_OPTION)) {
            int lDeleteIndex = Integer.parseInt(lEditQuestionForm.getHiddenDeleteOptionIndex());
            if (lEditQuestionForm.getOptions().size() > lDeleteIndex)
                lEditQuestionForm.getOptions().remove(lDeleteIndex);
            while (lEditQuestionForm.getOptions().size() < 3) {
                Option lOption = new Option();
                lOption.setOptionDescription("");
                lEditQuestionForm.getOptions().add(lOption);
            }
        }
        if (lEditQuestionForm.isSubmitAction(SubmitActions.RESET)) {
            this.setDefaultValues(lEditQuestionForm);
        }
    }
    if (NavigateActions.DisplayEditQuiz.toString().equals(lNextPage)) {

    }
    if (NavigateActions.DisplayEditQuizConfirmation.toString().equals(lNextPage)) {
        lActionForward = pActionMapping.findForward(NavigateActions.DisplayEditQuestionConfirmation.toString());
    }
    if (NavigateActions.DisplayEditQuizCancelled.toString().equals(lNextPage)) {
        lActionForward = pActionMapping.findForward(NavigateActions.DisplayQuizConsole.toString());
    }
    return lActionForward;
}

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

@Override
public ActionForward display(ActionMapping pActionMapping, ActionForm pActionForm,
        HttpServletRequest pHttpServletRequest, HttpServletResponse pHttpServletResponse) {
    User lLoggedInUser = AhpActionHelper.getLoggedInUser(pHttpServletRequest);
    EditQuizForm lEditQuizForm = (EditQuizForm) pActionForm;
    String lNextPage = StringUtils.trimToEmpty(lEditQuizForm.getNextPage());
    ActionForward lActionForward = pActionMapping.findForward(NavigateActions.DisplayEditQuiz.toString());
    if (NavigateActions.DisplayEditQuiz.toString().equals(lNextPage)) {
        // if ( lEditQuizForm.isSubmitAction( SubmitActions.EMPTY ) )
        // {// ww  w  .  j  a  v  a2 s  . c  o  m

        // }
        if (lEditQuizForm.isSubmitAction(SubmitActions.ADD_CATEGORY)) {
            Category lCategory = new Category();
            lCategory.setCategory("");
            lCategory.setQuiz(lEditQuizForm.getQuizUnderEdit());
            lCategory.setAudit(AhpBusinessDelegate.createAudit(lLoggedInUser));
            lEditQuizForm.getCategory().add(lCategory);
        } else if (lEditQuizForm.isSubmitAction(SubmitActions.DELETE_CATEGORY)) {
            int lDeleteIndex = lEditQuizForm.getHiddenDeleteCategoryIndex();
            if (lDeleteIndex != -1) {
                if (lEditQuizForm.getCategory().size() > lDeleteIndex) {
                    lEditQuizForm.getDeleteCategoryIdSet().add(new Long(lDeleteIndex));
                    lEditQuizForm.getCategory().remove(lDeleteIndex);
                }
            }
        } else if (lEditQuizForm.isSubmitAction(SubmitActions.ADD_SKILL_LEVEL)) {
            SkillLevel lSkillLevel = new SkillLevel();
            lSkillLevel.setSkillLevel("");
            lSkillLevel.setQuiz(lEditQuizForm.getQuizUnderEdit());
            lSkillLevel.setAudit(AhpBusinessDelegate.createAudit(lLoggedInUser));
            lEditQuizForm.getSkillLevel().add(lSkillLevel);
        } else if (lEditQuizForm.isSubmitAction(SubmitActions.DELETE_SKILL_LEVEL)) {
            int lDeleteIndex = lEditQuizForm.getHiddenDeleteSkillLevelIndex();
            if (lDeleteIndex != -1) {
                if (lEditQuizForm.getSkillLevel().size() > lDeleteIndex) {
                    lEditQuizForm.getDeleteSkillLevelIdSet().add(new Long(lDeleteIndex));
                    lEditQuizForm.getSkillLevel().remove(lDeleteIndex);
                }
            }
        } else if (lEditQuizForm.isSubmitAction(SubmitActions.SAVE_CHANGES)) {

        } else {
            Quiz lManagedQuizUnderEdit = this.mQuizService
                    .loadQuiz(lEditQuizForm.getQuizUnderEdit().getQuizId(), true);
            lEditQuizForm.setQuizName(lManagedQuizUnderEdit.getQuizName());
            lEditQuizForm.setQuizDescription(lManagedQuizUnderEdit.getQuizDescription());
            List<Category> categoryList = new ArrayList<Category>();
            categoryList.addAll(lManagedQuizUnderEdit.getCategories());
            lEditQuizForm.setCategory(categoryList);
            List<SkillLevel> skillLevelList = new ArrayList<SkillLevel>();
            skillLevelList.addAll(lManagedQuizUnderEdit.getSkillLevels());
            lEditQuizForm.setSkillLevel(skillLevelList);
        }
        lActionForward = pActionMapping.findForward(NavigateActions.DisplayEditQuiz.toString());
    }
    if (NavigateActions.DisplayEditQuestion.toString().equals(lNextPage)) {
        lActionForward = pActionMapping.findForward(NavigateActions.DisplayEditQuestion.toString());
    }
    return lActionForward;
}

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

@Override
public ActionForward display(ActionMapping pActionMapping, ActionForm pActionForm,
        HttpServletRequest pHttpServletRequest, HttpServletResponse pHttpServletResponse) {
    ManageQuizForm lManageQuizForm = (ManageQuizForm) pActionForm;
    ActionForward lActionForward = pActionMapping.findForward(NavigateActions.DisplayViewQuiz.toString());
    String lSubmitAction = StringUtils.trimToEmpty(lManageQuizForm.getSubmitAction());
    String lHiddenEditOperation = StringUtils.trimToEmpty(lManageQuizForm.getHiddenEditOperation());
    if (lManageQuizForm.isSubmitAction(SubmitActions.RETURN_TO_MANAGE_QUIZ)) {
        lManageQuizForm.getPaginationData().setOperation(PaginationOperations.ComboSubmit.toString());
        lManageQuizForm.getPaginationData()
                .setHiddenSelectedComboValue(lManageQuizForm.getPaginationData().getSelectedPage());
        lActionForward = pActionMapping.findForward(NavigateActions.DisplayManageQuiz.toString());
    }/* ww  w .  j a  v a 2  s.co  m*/
    if (lManageQuizForm.isSubmitAction(SubmitActions.EDIT)) {
        lActionForward = pActionMapping.findForward(NavigateActions.DisplayEditQuiz.toString());
        pHttpServletRequest.setAttribute(QUIZ_UNDER_EDIT, lManageQuizForm.getSelectedQuiz());
    }
    if (lManageQuizForm.isSubmitAction(SubmitActions.DELETE)) {
        pHttpServletRequest.setAttribute(QUIZ_UNDER_DELETE, lManageQuizForm.getSelectedQuiz());
        lActionForward = pActionMapping.findForward(NavigateActions.DisplayDeleteQuiz.toString());
    }
    if (lHiddenEditOperation.equals("View Quiz")) {
        for (Quiz lViewQuiz : lManageQuizForm.getQuizResults()) {
            if (lViewQuiz.getQuizId().longValue() == (lManageQuizForm.getHiddenSelectedItemId())) {
                lManageQuizForm.setSelectedQuiz(lViewQuiz);
                break;
            }
        }
    }
    lManageQuizForm.setHiddenEditOperation(null);
    lManageQuizForm.setHiddenSelectedItemId(0);
    return lActionForward;
}

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

@Override
public ActionForward process(ActionMapping pActionMapping, ActionForm pActionForm,
        HttpServletRequest pHttpServletRequest, HttpServletResponse pHttpServletResponse) {
    User lLoggedInUser = AhpActionHelper.getLoggedInUser(pHttpServletRequest);
    ManageQuizForm lDeleteQuizForm = (ManageQuizForm) pActionForm;
    String lSubmitAction = StringUtils.trimToEmpty(lDeleteQuizForm.getSubmitAction());
    if (lDeleteQuizForm.isSubmitAction(SubmitActions.RETURN_TO_MANAGE_QUIZ)) {
        lDeleteQuizForm.getPaginationData().setOperation(PaginationOperations.ComboSubmit.toString());
        lDeleteQuizForm.getPaginationData()
                .setHiddenSelectedComboValue(lDeleteQuizForm.getPaginationData().getSelectedPage());
        lDeleteQuizForm.setNextPage(NavigateActions.DisplayManageQuiz.toString());
    } else if (lDeleteQuizForm.isSubmitAction(SubmitActions.CONFIRM_DELETE)) {
        this.deleteQuiz(lDeleteQuizForm, lLoggedInUser);
        lDeleteQuizForm.setNextPage(NavigateActions.DisplayManageQuiz.toString());
    } else {//from w  w  w  .  j a v  a  2  s.  c  o m
        lDeleteQuizForm.setNextPage(NavigateActions.DisplayDeleteQuiz.toString());
    }
    return pActionMapping.findForward(NavigateActions.DisplayDeleteQuiz.toString());
}

From source file:org.ahp.vinavidai.quiz.manage.action.ManageQuiz.java

@Override
public ActionForward paginate(ActionMapping pActionMapping, ActionForm pActionForm,
        HttpServletRequest pHttpServletRequest, HttpServletResponse pHttpServletResponse) {
    ManageQuizForm lManageQuizForm = (ManageQuizForm) pActionForm;
    String lHiddenEditOperation = StringUtils.trimToEmpty(lManageQuizForm.getHiddenEditOperation());
    if (lHiddenEditOperation.equals(SubmitActions.VIEW_QUIZ.getValue())) {
        return pActionMapping.findForward(NavigateActions.DisplayViewQuiz.toString());
    }// w  w w .j av a2  s.  com
    if (lManageQuizForm.isSubmitAction(SubmitActions.DELETE)) {
        Quiz lQuizUnderEdit = null;
        for (Quiz lQuiz : lManageQuizForm.getQuizResults()) {
            if (lQuiz.getQuizId().longValue() == lManageQuizForm.getSelectedQuizId()) {
                lQuizUnderEdit = lQuiz;
                break;
            }
        }
        pHttpServletRequest.setAttribute(QUIZ_UNDER_DELETE, lQuizUnderEdit);
        return pActionMapping.findForward(NavigateActions.DisplayEditQuiz.toString());
    }
    if (lManageQuizForm.isSubmitAction(SubmitActions.PUBLISH)) {
        Quiz lQuizUnderPublish = null;
        for (Quiz lQuiz : lManageQuizForm.getQuizResults()) {
            if (lQuiz.getQuizId().longValue() == lManageQuizForm.getSelectedQuizId()) {
                lQuizUnderPublish = lQuiz;
                break;
            }
        }
        pHttpServletRequest.setAttribute(QUIZ_UNDER_PUBLISH, lQuizUnderPublish);
        return pActionMapping.findForward(NavigateActions.DisplayPublishQuiz.toString());
    }
    if (lManageQuizForm.isSubmitAction(SubmitActions.EDIT)) {
        Quiz lQuizUnderEdit = null;
        for (Quiz lQuiz : lManageQuizForm.getQuizResults()) {
            if (lQuiz.getQuizId().longValue() == lManageQuizForm.getSelectedQuizId()) {
                lQuizUnderEdit = lQuiz;
                break;
            }
        }
        pHttpServletRequest.setAttribute(QUIZ_UNDER_EDIT, lQuizUnderEdit);
        return pActionMapping.findForward(NavigateActions.DisplayEditQuiz.toString());
    }
    ManageQuizSearchResults lManageQuizSearchResults = this.mQuizSearchService
            .searchQuiz((ManageQuizSearchCriteria) lManageQuizForm.getPaginationSearchCriteria());
    lManageQuizForm.getPaginationData().setTotalRecords(lManageQuizSearchResults.getTotalRecords());
    lManageQuizForm.setQuizResults(lManageQuizSearchResults.getQuizResults());
    // Load Next/Previous flags
    loadPageFlags(lManageQuizForm);

    int lSelectedPage = lManageQuizForm.getPaginationData().getSelectedPage();
    if (lSelectedPage == 0) {
        lManageQuizForm.getPaginationData().setSelectedPage(1);
    }
    // Pagination List
    lManageQuizForm.getPaginationData().setComboPageRange(super.loadComboPageRange(lManageQuizForm));
    return pActionMapping.findForward(NavigateActions.DisplayManageQuiz.toString());
}

From source file:org.apache.metron.stellar.common.shell.cli.StellarShell.java

@Override
public int execute(ConsoleOperation output) throws InterruptedException {

    // grab the user the input
    String expression = StringUtils.trimToEmpty(output.getBuffer());
    if (StringUtils.isNotBlank(expression)) {

        // execute the expression
        StellarResult result = executor.execute(expression);

        if (result.isSuccess()) {
            // on success
            result.getValue().ifPresent(v -> writeLine(v.toString()));

        } else if (result.isError()) {
            // on error
            result.getException().ifPresent(e -> writeLine(ERROR_PROMPT + e.getMessage()));
            result.getException().ifPresent(e -> e.printStackTrace());

        } else if (result.isTerminate()) {
            // on quit
            handleQuit();//from  w w  w.  ja  va  2 s. co  m

        } else {
            // should never happen
            throw new IllegalStateException(
                    "An execution result is neither a success nor a failure. Please file a bug report.");
        }
    }

    return 0;
}

From source file:org.apache.metron.stellar.common.shell.DefaultStellarShellExecutor.java

@Override
public StellarResult execute(String expression) {

    // if only whitespace, there is nothing to do
    expression = StringUtils.trimToEmpty(expression);
    if (StringUtils.isBlank(expression)) {
        return noop();
    }/* w  w w. java 2 s  . c  om*/

    // is this a special command?
    for (SpecialCommand command : specials) {
        if (command.getMatcher().apply(expression)) {
            return command.execute(expression, this);
        }
    }

    // otherwise, this must be a stellar expression
    return executeStellar(expression);
}

From source file:org.apache.metron.stellar.common.shell.specials.MagicDefineGlobal.java

@Override
public StellarResult execute(String command, StellarShellExecutor executor) {

    // grab the expression in '%define <assign-expression>'
    String assignExpr = StringUtils.trimToEmpty(command.substring(MAGIC_DEFINE.length()));
    if (StringUtils.length(assignExpr) < 1) {
        return error(MAGIC_DEFINE + " missing assignment expression");
    }/*  w ww  . j a v a 2 s. c  o  m*/

    // the expression must be an assignment
    if (!StellarAssignment.isAssignment(assignExpr)) {
        return error(MAGIC_DEFINE + " expected assignment expression");
    }

    // execute the expression
    StellarAssignment expr = StellarAssignment.from(assignExpr);
    StellarResult result = executor.execute(expr.getStatement());

    // execution must be successful
    if (!result.isSuccess()) {
        return error(MAGIC_DEFINE + " expression execution failed");
    }

    // expression should have a result
    if (!result.getValue().isPresent()) {
        return error(MAGIC_DEFINE + " expression produced no result");
    }

    // alter the global configuration
    Object value = result.getValue().get();
    executor.getGlobalConfig().put(expr.getVariable(), value);

    return success(value);
}

From source file:org.apache.metron.stellar.common.shell.specials.MagicListFunctions.java

@Override
public StellarResult execute(String command, StellarShellExecutor executor) {

    // if '%functions FOO' then show only functions that contain 'FOO'
    String startsWith = StringUtils.trimToEmpty(command.substring(MAGIC_FUNCTIONS.length()));
    Predicate<String> nameFilter = (name -> true);
    if (StringUtils.isNotBlank(startsWith)) {
        nameFilter = (name -> name.contains(startsWith));
    }/*from w  ww  . j  a  v a  2  s . co  m*/

    // '%functions' -> list all functions in scope
    String functions = StreamSupport
            .stream(executor.getFunctionResolver().getFunctionInfo().spliterator(), false)
            .map(info -> String.format("%s", info.getName())).filter(nameFilter).sorted()
            .collect(Collectors.joining(", "));

    return StellarResult.success(functions);
}

From source file:org.apache.metron.stellar.common.shell.specials.MagicUndefineGlobal.java

@Override
public StellarResult execute(String command, StellarShellExecutor executor) {
    StellarResult result;/*from   www.j av a 2s  . c  o m*/

    String variable = StringUtils.trimToEmpty(command.substring(MAGIC_UNDEFINE.length()));
    if (StringUtils.isNotBlank(variable)) {

        // remove the variable from the globals
        Map<String, Object> globals = executor.getGlobalConfig();
        globals.remove(variable);
        result = noop();

    } else {
        result = error(String.format("%s expected name of global, got '%s'", MAGIC_UNDEFINE, variable));
    }

    return result;
}