Example usage for org.springframework.util StringUtils split

List of usage examples for org.springframework.util StringUtils split

Introduction

In this page you can find the example usage for org.springframework.util StringUtils split.

Prototype

@Nullable
public static String[] split(@Nullable String toSplit, @Nullable String delimiter) 

Source Link

Document

Split a String at the first occurrence of the delimiter.

Usage

From source file:fr.xebia.springframework.concurrent.ThreadPoolExecutorFactory.java

public void setPoolSize(String poolSize) {
    if (!StringUtils.hasText(poolSize)) {
        return;/*w w w . java2 s.co  m*/
    }

    switch (StringUtils.countOccurrencesOf(poolSize, "-")) {
    case 0:
        this.corePoolSize = Integer.parseInt(poolSize);
        this.maximumPoolSize = this.corePoolSize;
        break;
    case 1:
        String[] splittedPoolSize = StringUtils.split(poolSize, "-");
        this.corePoolSize = Integer.parseInt(splittedPoolSize[0]);
        this.maximumPoolSize = Integer.parseInt(splittedPoolSize[1]);
        break;
    default:
        throw new BeanCreationException(this.beanName,
                "Invalid pool-size value [" + poolSize + "]: only single maximum integer "
                        + "(e.g. \"5\") and minimum-maximum range (e.g. \"3-5\") are supported.");
    }
}

From source file:com.btmatthews.atlas.jcr.impl.JCRTemplate.java

public Node getOrCreateNode(final Node node, final String intermediateType, final String leafType,
        final String path) {
    return getOrCreateNode(node, intermediateType, leafType, StringUtils.split(path, "/"));

}

From source file:org.jlot.web.api.error.DefaultRestErrorResolver.java

protected RestError toRestError(String exceptionConfig) {
    String[] values = StringUtils.commaDelimitedListToStringArray(exceptionConfig);
    if (values == null || values.length == 0) {
        throw new IllegalStateException(
                "Invalid config mapping.  Exception names must map to a string configuration.");
    }//w ww.j a  v  a 2  s  .  com

    RestError restError = new RestError();

    boolean statusCodeSet = false;
    boolean msgSet = false;
    boolean devMsgSet = false;
    boolean moreInfoSet = false;

    for (String value : values) {

        String trimmedVal = StringUtils.trimWhitespace(value);

        // check to see if the value is an explicitly named key/value pair:
        String[] pair = StringUtils.split(trimmedVal, "=");
        if (pair != null) {
            // explicit attribute set:
            String pairKey = StringUtils.trimWhitespace(pair[0]);
            if (!StringUtils.hasText(pairKey)) {
                pairKey = null;
            }
            String pairValue = StringUtils.trimWhitespace(pair[1]);
            if (!StringUtils.hasText(pairValue)) {
                pairValue = null;
            }
            if ("statusCode".equalsIgnoreCase(pairKey)) {
                int statusCode = getRequiredInt(pairKey, pairValue);
                restError.setStatusCode(statusCode);
                statusCodeSet = true;
            } else if ("msg".equalsIgnoreCase(pairKey)) {
                restError.setMessage(pairValue);
                msgSet = true;
            } else if ("devMsg".equalsIgnoreCase(pairKey)) {
                restError.setDeveloperMessage(pairValue);
                devMsgSet = true;
            } else if ("infoUrl".equalsIgnoreCase(pairKey)) {
                restError.setMoreInfoUrl(pairValue);
                moreInfoSet = true;
            }
        } else {
            // not a key/value pair - use heuristics to determine what value
            // is being set:
            int val;
            if (!statusCodeSet) {
                val = getInt("statusCode", trimmedVal);
                if (val > 0) {
                    restError.setStatusCode(val);
                    statusCodeSet = true;
                    continue;
                }
            }
            if (!moreInfoSet && trimmedVal.toLowerCase().startsWith("http")) {
                restError.setMoreInfoUrl(trimmedVal);
                moreInfoSet = true;
                continue;
            }
            if (!msgSet) {
                restError.setMessage(trimmedVal);
                msgSet = true;
                continue;
            }
            if (!devMsgSet) {
                restError.setDeveloperMessage(trimmedVal);
                devMsgSet = true;
                continue;
            }
            if (!moreInfoSet) {
                restError.setMoreInfoUrl(trimmedVal);
                moreInfoSet = true;
                // noinspection UnnecessaryContinue
                continue;
            }
        }
    }

    return restError;
}

From source file:co.adun.mvnejb3jpa.web.controller.InitiateLeadController.java

private List<LtLead> process(LeadModel model) throws BusinessException {

    List<LtLeadModel> ltLeadsModel = model.getLtLeadsModel();
    List<LtLead> ltLeads = new ArrayList<LtLead>();
    LtUser user = userService.getCurrentUser(WebSecurityContext.getUsername());

    DateFormat dateFormat = new SimpleDateFormat("MM/dd/yyyy", Locale.ENGLISH);

    for (LtLeadModel ltLeadModel : ltLeadsModel) {
        LtLead ltLead = ltLeadModel.getLtLead();

        if (ltLead != null && !StringUtils.isEmpty(ltLeadModel.getFormId())) {

            DateValueModel birthDateModel = ltLeadModel.getBirthDateModel();
            if (!StringUtils.isEmpty(birthDateModel.getValue())) {
                Date date = null;
                try {
                    date = dateFormat.parse(birthDateModel.getValue());
                } catch (ParseException e) {
                    logger.info(e.getMessage());
                }/*from w  w  w.j  ava2s. co m*/
                ltLead.getLtSubject().setBirthDate(date);
            }

            DateValueModel entryDateModel = ltLeadModel.getEntryDateModel();
            if (!StringUtils.isEmpty(entryDateModel.getValue())) {
                Date date = null;
                try {
                    date = dateFormat.parse(entryDateModel.getValue());
                } catch (ParseException e) {
                    logger.info(e.getMessage());
                }
                ltLead.getLtSubject().setEntryDate(date);
            }

            MissionCode missionCode = ltLead.getMissionCode();

            // if Mission Box is selected by not Supervisor and Analyst,
            // assign
            // Lead to mission box
            boolean assignToSup = false;
            boolean assignToAna = false;
            logger.info("Calling leadService.save");

            /*
             * If the Analyst is selected, the lead is assigned to the
             * analyst. If analyst is not selected and Supervisor is
             * selected, then the lead is assigned to the Supervisor
             */

            // assign to supervisor, if it is selected

            ValueModel analystModel = ltLeadModel.getAnalystModel();
            if (!StringUtils.isEmpty(analystModel.getValue())) {
                LtUser ltUserByLtAssignToUserId = new LtUser();
                ltUserByLtAssignToUserId.setId(new Long(analystModel.getValue()));
                ltLead.setLtUserByLtAssignToUserId(ltUserByLtAssignToUserId);
                assignToAna = true;
            }

            ValueModel supervisorModel = ltLeadModel.getSupervisorModel();
            logger.info("Supervisor model value=" + supervisorModel.getValue());
            if (!assignToAna) {
                if (!StringUtils.isEmpty(supervisorModel.getValue())) {
                    LtUser ltUserByLtAssignToUserId = new LtUser();
                    ltUserByLtAssignToUserId.setId(new Long(supervisorModel.getValue()));
                    ltLead.setLtUserByLtAssignToUserId(ltUserByLtAssignToUserId);
                    assignToSup = true;
                }
            }

            StatusCode statusCode = new StatusCode();
            if (!assignToSup && !assignToAna) {
                // TODO refactor to Constants
                if (missionCode != null) {
                    setMissionCodeToLead(missionCode, ltLead);
                } else {
                    ltLead.setMissionCode(null);
                }
                // set Lead to unassigned status, when it is not assigned to
                // a
                // person
                statusCode.setId(100L); // Unassigned cod
            }

            // Lead is in assigned status, when is is assigned to a person
            if (assignToSup == true || assignToAna == true) {
                statusCode.setId(101L); // assigned code
                ltLead.setMissionCode(null);
            }

            ltLead.setStatusCode(statusCode);

            LeadGeneratedFromCode leadGeneratedFromCode = ltLead.getLeadGeneratedFromCode();
            String abbreviation = leadGeneratedFromCode.getAbbreviation();
            if (!StringUtils.isEmpty(abbreviation) && !"Select...".equals(abbreviation)) {
                String[] strings = StringUtils.split(abbreviation, ":");
                if (strings != null) {
                    leadGeneratedFromCode.setId(new Long(strings[0]));
                    leadGeneratedFromCode.setAbbreviation(strings[1]);
                }
            }

            LeadTypeCode leadTypeCode = ltLead.getLeadTypeCode();
            abbreviation = leadTypeCode.getAbbreviation();
            if (!StringUtils.isEmpty(abbreviation) && !"Select...".equals(abbreviation)) {
                String[] strings = StringUtils.split(abbreviation, ":");
                if (strings != null) {
                    leadTypeCode.setId(new Long(strings[0]));
                    leadTypeCode.setAbbreviation(strings[1]);
                }
            }

            Set<LtLeadSource> ltLeadSources = new HashSet<LtLeadSource>();
            LtLeadSource ltLeadSource = ltLeadModel.getLtLeadSource();
            ContactTypeCode contactTypeCode = ltLeadSource.getContactTypeCode();
            abbreviation = contactTypeCode.getAbbreviation();
            if (!StringUtils.isEmpty(abbreviation) && !"Select...".equals(abbreviation)) {
                String[] strings = StringUtils.split(abbreviation, ":");
                if (strings != null) {
                    contactTypeCode.setId(new Long(strings[0]));
                    contactTypeCode.setAbbreviation(strings[1]);
                    ltLeadSource.setLtLead(ltLead);
                    ltLeadSources.add(ltLeadSource);
                }
            }
            ltLead.setLtLeadSources(ltLeadSources);

            Set<LtLeadComment> ltLeadComments = new HashSet<LtLeadComment>();
            LtLeadComment ltLeadComment = ltLeadModel.getLtLeadComment();
            if (ltLeadComment != null && !StringUtils.isEmpty(ltLeadComment.getLeadComment())) {
                ltLeadComments.add(ltLeadComment);
            }
            ltLead.setLtLeadComments(ltLeadComments);

            ClassAdmissionCode classAdmissionCode = ltLead.getLtSubject().getClassAdmissionCode();
            abbreviation = classAdmissionCode.getAbbreviation();
            if (!StringUtils.isEmpty(abbreviation) && !"Select...".equals(abbreviation)) {
                String[] strings = StringUtils.split(abbreviation, ":");
                if (strings != null) {
                    classAdmissionCode.setId(new Long(strings[0]));
                    classAdmissionCode.setAbbreviation(strings[1]);
                } else {
                    ltLead.getLtSubject().setClassAdmissionCode(null);
                }
            } else {
                ltLead.getLtSubject().setClassAdmissionCode(null);
            }

            CountryCode countryCode = ltLead.getLtSubject().getCountryCode();
            abbreviation = countryCode.getAbbreviation();
            if (!StringUtils.isEmpty(abbreviation) && !"Select...".equals(abbreviation)) {
                String[] strings = StringUtils.split(abbreviation, ":");
                if (strings != null) {
                    countryCode.setId(new Long(strings[0]));
                    countryCode.setAbbreviation(strings[1]);
                } else {
                    ltLead.getLtSubject().setCountryCode(null);
                }
            } else {
                ltLead.getLtSubject().setCountryCode(null);
            }

            GenderCode genderCode = ltLead.getLtSubject().getGenderCode();
            abbreviation = genderCode.getAbbreviation();
            if (!StringUtils.isEmpty(abbreviation) && !"Select...".equals(abbreviation)) {
                String[] strings = StringUtils.split(abbreviation, ":");
                if (strings != null) {
                    genderCode.setId(new Long(strings[0]));
                    genderCode.setAbbreviation(strings[1]);
                } else {
                    ltLead.getLtSubject().setGenderCode(null);
                }
            } else {
                ltLead.getLtSubject().setGenderCode(null);
            }

            Set<LtLeadSpecialProject> ltLeadSpecialProjects = new HashSet<LtLeadSpecialProject>();
            for (LtLeadSpecialProject ltLeadSpecialProject : ltLeadModel.getLtLeadSpecialProjects()) {
                SpecialProjectCode specialProjectCode = ltLeadSpecialProject.getSpecialProjectCode();
                abbreviation = specialProjectCode.getAbbreviation();
                if (!StringUtils.isEmpty(abbreviation) && !"Select...".equals(abbreviation)) {
                    String[] strings = StringUtils.split(abbreviation, ":");
                    if (strings != null) {
                        specialProjectCode.setId(new Long(strings[0]));
                        specialProjectCode.setAbbreviation(strings[1]);
                        ltLeadSpecialProject.setLtLead(ltLead);
                        ltLeadSpecialProjects.add(ltLeadSpecialProject);
                    }
                }
            }
            ltLead.setLtLeadSpecialProjects(ltLeadSpecialProjects);

            Set<LtSubjectCitizenshipCountry> ltSubjectCitizenshipCountries = new HashSet<LtSubjectCitizenshipCountry>();
            for (LtSubjectCitizenshipCountry ltSubjectCitizenshipCountry : ltLeadModel
                    .getLtSubjectCitizenshipCountries()) {
                CountryCode cocCountryCode = ltSubjectCitizenshipCountry.getCountryCode();
                abbreviation = cocCountryCode.getAbbreviation();
                if (!StringUtils.isEmpty(abbreviation) && !"Select...".equals(abbreviation)) {
                    String[] strings = StringUtils.split(abbreviation, ":");
                    if (strings != null) {
                        cocCountryCode.setId(new Long(strings[0]));
                        cocCountryCode.setAbbreviation(strings[1]);
                        ltSubjectCitizenshipCountry.setLtSubject(ltLead.getLtSubject());
                        ltSubjectCitizenshipCountries.add(ltSubjectCitizenshipCountry);
                    }
                }
            }
            ltLead.getLtSubject().setLtSubjectCitizenshipCountries(ltSubjectCitizenshipCountries);

            Set<LtAssociatedLead> ltAssociatedLeads = new HashSet<LtAssociatedLead>();
            Set<LtAssociatedSubject> ltAssociatedSubjects = new HashSet<LtAssociatedSubject>();
            List<AssociatedLeadModel> associates = ltLeadModel.getAssociateModel();
            for (AssociatedLeadModel associateModel : associates) {
                String id = associateModel.getValue();
                if (!StringUtils.isEmpty(id)) {

                    RelationshipCode code = associateModel.getRelationshipCode();
                    code.setId(PageModelUtils.getCode(code.getAbbreviation()));

                    LtSubject ltAssociate = ltLeadsModel.get(Integer.parseInt(id)).getLtLead().getLtSubject();
                    LtAssociatedSubject ltAssociatedSubject = new LtAssociatedSubject();
                    ltAssociatedSubject.setLtSubject(ltLead.getLtSubject());
                    ltAssociatedSubject.setLtSubjectAssociate(ltAssociate);
                    ltAssociatedSubject.setRelationshipCode(code);
                    ltAssociatedSubjects.add(ltAssociatedSubject);

                    LtLead ltAssociateLead = ltLeadsModel.get(Integer.parseInt(id)).getLtLead();
                    LtAssociatedLead ltAssociatedLead = new LtAssociatedLead();
                    ltAssociatedLead.setLtLeadByLtLeadId(ltLead);
                    ltAssociatedLead.setLtLeadByLtAssociatedLeadId(ltAssociateLead);
                    ltAssociatedLeads.add(ltAssociatedLead);
                }
            }
            ltLead.setLtAssociatedLeadsForLtLeadId(ltAssociatedLeads);
            ltLead.getLtSubject().setLtAssociatedSubjects(ltAssociatedSubjects);

            Set<LtLeadSubject> ltLeadSubjects = new HashSet<LtLeadSubject>();
            LtLeadSubject ltLeadSubject = ltLeadModel.getLtLeadSubject();
            ltLeadSubject.setLtLead(ltLead);
            ltLeadSubject.setLtSubject(ltLead.getLtSubject());
            ltLeadSubjects.add(ltLeadSubject);
            ltLead.setLtLeadSubjects(ltLeadSubjects);

            ltLead.setLtUserByCreateBy(user);
            ltLead.setLtUserByModifiedBy(user);

            ltLeads.add(ltLead);
        }
    }

    return ltLeads;
}

From source file:com.novation.eligibility.rest.spring.web.servlet.handler.DefaultRestErrorResolver.java

protected RestError toRestError(String exceptionConfig) {
    String[] values = StringUtils.commaDelimitedListToStringArray(exceptionConfig);
    if (values == null || values.length == 0) {
        throw new IllegalStateException(
                "Invalid config mapping.  Exception names must map to a string configuration.");
    }//from  w w w.  j a v  a  2s  .  c  om

    RestError.Builder builder = new RestError.Builder();

    boolean statusSet = false;
    boolean codeSet = false;
    boolean msgSet = false;
    boolean devMsgSet = false;
    boolean moreInfoSet = false;

    for (String value : values) {

        String trimmedVal = StringUtils.trimWhitespace(value);

        //check to see if the value is an explicitly named key/value pair:
        String[] pair = StringUtils.split(trimmedVal, "=");
        if (pair != null) {
            //explicit attribute set:
            String pairKey = StringUtils.trimWhitespace(pair[0]);
            if (!StringUtils.hasText(pairKey)) {
                pairKey = null;
            }
            String pairValue = StringUtils.trimWhitespace(pair[1]);
            if (!StringUtils.hasText(pairValue)) {
                pairValue = null;
            }
            if ("status".equalsIgnoreCase(pairKey)) {
                int statusCode = getRequiredInt(pairKey, pairValue);
                builder.setStatus(statusCode);
                statusSet = true;
            } else if ("code".equalsIgnoreCase(pairKey)) {
                int code = getRequiredInt(pairKey, pairValue);
                builder.setCode(code);
                codeSet = true;
            } else if ("msg".equalsIgnoreCase(pairKey)) {
                builder.setMessage(pairValue);
                msgSet = true;
            } else if ("devMsg".equalsIgnoreCase(pairKey)) {
                builder.setDeveloperMessage(pairValue);
                devMsgSet = true;
            } else if ("infoUrl".equalsIgnoreCase(pairKey)) {
                builder.setMoreInfoUrl(pairValue);
                moreInfoSet = true;
            }
        } else {
            //not a key/value pair - use heuristics to determine what value is being set:
            int val;
            if (!statusSet) {
                val = getInt("status", trimmedVal);
                if (val > 0) {
                    builder.setStatus(val);
                    statusSet = true;
                    continue;
                }
            }
            if (!codeSet) {
                val = getInt("code", trimmedVal);
                if (val > 0) {
                    builder.setCode(val);
                    codeSet = true;
                    continue;
                }
            }
            if (!moreInfoSet && trimmedVal.toLowerCase().startsWith("http")) {
                builder.setMoreInfoUrl(trimmedVal);
                moreInfoSet = true;
                continue;
            }
            if (!msgSet) {
                builder.setMessage(trimmedVal);
                msgSet = true;
                continue;
            }
            if (!devMsgSet) {
                builder.setDeveloperMessage(trimmedVal);
                devMsgSet = true;
                continue;
            }
            if (!moreInfoSet) {
                builder.setMoreInfoUrl(trimmedVal);
                moreInfoSet = true;
                //noinspection UnnecessaryContinue
                continue;
            }
        }
    }

    return builder.build();
}

From source file:com.oolong.platform.web.error.DefaultRestErrorResolver.java

protected RestError toRestError(String exceptionConfig) {
    String[] values = StringUtils.commaDelimitedListToStringArray(exceptionConfig);
    if (values == null || values.length == 0) {
        throw new IllegalStateException(
                "Invalid config mapping.  Exception names must map to a string configuration.");
    }//ww  w.  j a  v a  2  s.c o m

    RestError.Builder builder = new RestError.Builder();

    boolean statusSet = false;
    boolean codeSet = false;
    boolean msgSet = false;
    boolean devMsgSet = false;
    boolean moreInfoSet = false;

    for (String value : values) {

        String trimmedVal = StringUtils.trimWhitespace(value);

        // check to see if the value is an explicitly named key/value pair:
        String[] pair = StringUtils.split(trimmedVal, "=");
        if (pair != null) {
            // explicit attribute set:
            String pairKey = StringUtils.trimWhitespace(pair[0]);
            if (!StringUtils.hasText(pairKey)) {
                pairKey = null;
            }
            String pairValue = StringUtils.trimWhitespace(pair[1]);
            if (!StringUtils.hasText(pairValue)) {
                pairValue = null;
            }
            if ("status".equalsIgnoreCase(pairKey)) {
                int statusCode = getRequiredInt(pairKey, pairValue);
                builder.setStatus(statusCode);
                statusSet = true;
            } else if ("code".equalsIgnoreCase(pairKey)) {
                int code = getRequiredInt(pairKey, pairValue);
                builder.setCode(code);
                codeSet = true;
            } else if ("msg".equalsIgnoreCase(pairKey)) {
                builder.setMessage(pairValue);
                msgSet = true;
            } else if ("devMsg".equalsIgnoreCase(pairKey)) {
                builder.setDeveloperMessage(pairValue);
                devMsgSet = true;
            } else if ("infoUrl".equalsIgnoreCase(pairKey)) {
                builder.setMoreInfoUrl(pairValue);
                moreInfoSet = true;
            }
        } else {
            // not a key/value pair - use heuristics to determine what value
            // is being set:
            int val;
            if (!statusSet) {
                val = getInt("status", trimmedVal);
                if (val > 0) {
                    builder.setStatus(val);
                    statusSet = true;
                    continue;
                }
            }
            if (!codeSet) {
                val = getInt("code", trimmedVal);
                if (val > 0) {
                    builder.setCode(val);
                    codeSet = true;
                    continue;
                }
            }
            if (!moreInfoSet && trimmedVal.toLowerCase().startsWith("http")) {
                builder.setMoreInfoUrl(trimmedVal);
                moreInfoSet = true;
                continue;
            }
            if (!msgSet) {
                builder.setMessage(trimmedVal);
                msgSet = true;
                continue;
            }
            if (!devMsgSet) {
                builder.setDeveloperMessage(trimmedVal);
                devMsgSet = true;
                continue;
            }
            if (!moreInfoSet) {
                builder.setMoreInfoUrl(trimmedVal);
                moreInfoSet = true;
                // noinspection UnnecessaryContinue
                continue;
            }
        }
    }

    return builder.build();
}

From source file:com.yang.oa.commons.exception.DefaultRestErrorResolver.java

protected RestError toRestError(String exceptionConfig) {
    String[] values = StringUtils.commaDelimitedListToStringArray(exceptionConfig);
    if (values == null || values.length == 0) {
        throw new IllegalStateException(
                "Invalid config mapping.  Exception names must map to a string configuration.");
    }/*from www  .  jav a  2  s  .  c o  m*/
    System.out.println("??" + exceptionConfig);
    RestError.Builder builder = new RestError.Builder();

    boolean statusSet = false;
    boolean codeSet = false;
    boolean msgSet = false;
    boolean devMsgSet = false;
    boolean moreInfoSet = false;

    for (String value : values) {

        String trimmedVal = StringUtils.trimWhitespace(value);

        //check to see if the value is an explicitly named key/value pair:
        String[] pair = StringUtils.split(trimmedVal, "=");
        if (pair != null) {
            //explicit attribute set:
            String pairKey = StringUtils.trimWhitespace(pair[0]);
            if (!StringUtils.hasText(pairKey)) {
                pairKey = null;
            }
            String pairValue = StringUtils.trimWhitespace(pair[1]);
            if (!StringUtils.hasText(pairValue)) {
                pairValue = null;
            }
            if ("status".equalsIgnoreCase(pairKey)) {
                int statusCode = getRequiredInt(pairKey, pairValue);
                builder.setStatus(statusCode);
                statusSet = true;
            } else if ("code".equalsIgnoreCase(pairKey)) {
                int code = getRequiredInt(pairKey, pairValue);
                builder.setCode(code);
                codeSet = true;
            } else if ("msg".equalsIgnoreCase(pairKey)) {
                builder.setMessage(pairValue);
                msgSet = true;
            } else if ("devMsg".equalsIgnoreCase(pairKey)) {
                builder.setDeveloperMessage(pairValue);
                devMsgSet = true;
            } else if ("infoUrl".equalsIgnoreCase(pairKey)) {
                builder.setMoreInfoUrl(pairValue);
                moreInfoSet = true;
            }
        } else {
            //not a key/value pair - use heuristics to determine what value is being set:
            int val;
            if (!statusSet) {
                val = getInt("status", trimmedVal);
                if (val > 0) {
                    builder.setStatus(val);
                    statusSet = true;
                    continue;
                }
            }
            if (!codeSet) {
                val = getInt("code", trimmedVal);
                if (val > 0) {
                    builder.setCode(val);
                    codeSet = true;
                    continue;
                }
            }
            if (!moreInfoSet && trimmedVal.toLowerCase().startsWith("http")) {
                builder.setMoreInfoUrl(trimmedVal);
                moreInfoSet = true;
                continue;
            }
            if (!msgSet) {
                builder.setMessage(trimmedVal);
                msgSet = true;
                continue;
            }
            if (!devMsgSet) {
                builder.setDeveloperMessage(trimmedVal);
                devMsgSet = true;
                continue;
            }
            if (!moreInfoSet) {
                builder.setMoreInfoUrl(trimmedVal);
                moreInfoSet = true;
                //noinspection UnnecessaryContinue
                continue;
            }
        }
    }

    return builder.build();
}

From source file:org.entitypedia.games.common.api.handlers.DefaultExceptionDetailsResolver.java

private ExceptionDetails toExceptionDetails(String exceptionConfig) {
    String[] values = StringUtils.commaDelimitedListToStringArray(exceptionConfig);
    if (values == null || values.length == 0) {
        throw new IllegalStateException(
                "Invalid config mapping.  Exception names must map to a string configuration.");
    }/*from   ww  w  .  ja v  a2 s . com*/

    ExceptionDetails result = new ExceptionDetails();

    for (String value : values) {
        String trimmedVal = StringUtils.trimWhitespace(value);

        //check to see if the value is an explicitly named key/value pair:
        String[] pair = StringUtils.split(trimmedVal, "=");
        if (pair != null) {
            //explicit attribute set:
            String pairKey = StringUtils.trimWhitespace(pair[0]);
            if (!StringUtils.hasText(pairKey)) {
                pairKey = null;
            }
            String pairValue = StringUtils.trimWhitespace(pair[1]);
            if (!StringUtils.hasText(pairValue)) {
                pairValue = null;
            }
            if ("status".equalsIgnoreCase(pairKey)) {
                result.setStatus(getRequiredInt(pairKey, pairValue));
            } else if ("msg".equalsIgnoreCase(pairKey)) {
                result.setErrorMessage(pairValue);
            } else if ("emsg".equalsIgnoreCase(pairKey)) {
                result.setExplanationMessage(pairValue);
            } else if ("wmsg".equalsIgnoreCase(pairKey)) {
                result.setWhatToDoMessage(pairValue);
            } else if ("infoUrl".equalsIgnoreCase(pairKey)) {
                result.setMoreInfoUrl(pairValue);
            } else if ("target".equalsIgnoreCase(pairKey)) {
                result.setExceptionClass(pairValue);
            }
        }
    }

    return result;
}

From source file:com.github.hateoas.forms.spring.AffordanceBuilder.java

/**
 * Returns a {@link UriComponentsBuilder} obtained from the current servlet mapping with the host tweaked in case the request contains
 * an {@code X-Forwarded-Host} header and the scheme tweaked in case the request contains an {@code X-Forwarded-Ssl} header
 *
 * @return builder//from  w ww .j a va  2s.c  o  m
 */
static UriComponentsBuilder getBuilder() {

    HttpServletRequest request = getCurrentRequest();
    ServletUriComponentsBuilder builder = ServletUriComponentsBuilder.fromServletMapping(request);

    String forwardedSsl = request.getHeader("X-Forwarded-Ssl");

    if (StringUtils.hasText(forwardedSsl) && forwardedSsl.equalsIgnoreCase("on")) {
        builder.scheme("https");
    }

    String host = request.getHeader("X-Forwarded-Host");

    if (!StringUtils.hasText(host)) {
        return builder;
    }

    String[] hosts = StringUtils.commaDelimitedListToStringArray(host);
    String hostToUse = hosts[0];

    if (hostToUse.contains(":")) {

        String[] hostAndPort = StringUtils.split(hostToUse, ":");

        builder.host(hostAndPort[0]);
        builder.port(Integer.parseInt(hostAndPort[1]));
    } else {
        builder.host(hostToUse);
        builder.port(-1); // reset port if it was forwarded from default port
    }

    String port = request.getHeader("X-Forwarded-Port");

    if (StringUtils.hasText(port)) {
        builder.port(Integer.parseInt(port));
    }

    return builder;
}

From source file:co.adun.mvnejb3jpa.web.controller.InitiateLeadController.java

/**
 * Set Mission code to Lead for commits.
 * //from  ww  w  .  j a v  a2s .  c  o  m
 * @param missionCode
 * @param ltLead
 */

private void setMissionCodeToLead(MissionCode missionCode, LtLead ltLead) {

    String abbreviation = missionCode.getAbbreviation();
    if (!StringUtils.isEmpty(abbreviation)) {
        String[] strings = StringUtils.split(abbreviation, ":");
        if (strings != null && !"None".equalsIgnoreCase(strings[1])) {
            missionCode.setId(new Long(strings[0]));
            missionCode.setAbbreviation(strings[1]);
        } else {
            ltLead.setMissionCode(null);
        }
    }

}