Example usage for org.apache.commons.lang StringUtils trimToNull

List of usage examples for org.apache.commons.lang StringUtils trimToNull

Introduction

In this page you can find the example usage for org.apache.commons.lang StringUtils trimToNull.

Prototype

public static String trimToNull(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:gov.nih.nci.cabig.caaers.web.ae.AbstractExpeditedAdverseEventInputCommand.java

public void initializeTreatmentInformation() {
    ExpeditedAdverseEventReport aeReport = getAeReport();
    TreatmentInformation treatmentInformation = aeReport.getTreatmentInformation();
    treatmentInformation.setTreatmentAssignment(aeReport.getReportingPeriod().getTreatmentAssignment());
    treatmentInformation.setTreatmentDescription(
            StringUtils.trimToNull(aeReport.getReportingPeriod().getTreatmentAssignmentDescription()));
    treatmentInformation.setFirstCourseDate(aeReport.getAssignment().getStartDateOfFirstCourse());
    treatmentInformation.getAdverseEventCourse().setDate(aeReport.getReportingPeriod().getStartDate());
    treatmentInformation.getAdverseEventCourse().setNumber(aeReport.getReportingPeriod().getCycleNumber());
    treatmentInformation.setTotalCourses(aeReport.getAssignment().getMaxCycleNumber());

}

From source file:com.egt.web.configuracion.basica.FragmentoFiltro.java

public void setValorTextoFiltro1(String valor) {
    this.getRecursoDataProvider().setCodigoFuncionSelect(StringUtils.trimToNull(valor));
}

From source file:com.egt.web.configuracion.basica.FragmentoFiltro.java

public String getUrlImagenTextoFiltro1() {
    String cx = this.getRecursoDataProvider().getCodigoFuncionSelect();
    cx = StringUtils.trimToNull(cx);
    return this.getRecursoDataProvider().isCodigoFuncionSelectModificado() ? URL_IMAGEN_WARNING
            : cx == null ? URL_IMAGEN_OK_DIMMED : URL_IMAGEN_OK;
}

From source file:com.partnet.automation.HtmlView.java

private String clickAndHandleAlert(WebElement elm, boolean accept, boolean throwIfNoAlertPresent) {
    String alertMsg = null;//w ww  .j a va  2s  .com
    LOG.debug("{} alert created by clicking button {}", accept ? "accept" : "dismiss", elm);

    Browser browser = getBrowser();

    // headless browsers need to inject javascript before the button is clicked
    // to handle the alert correctly
    if (browser.isHeadless()) {

        // webDriver.manage().deleteCookieNamed(ALERT_COOKIE_NAME);
        StringBuilder alertJs = new StringBuilder();

        alertJs.append("window.alert = window.confirm = function(msg){ ")
                // .append( "var date = new Date();")
                // .append( "date.setDate(date.getDate() + 1);")

                // cookies don't like to store new lines. This becomes a problem when
                // taking a screenshot for HTMLUNIT, and
                // transferring the cookie to PhantomJs.
                // This prevents newlines from being injected into the cookie. Later
                // on, the return string containing these
                // newline keywords will be replaced with actual newlines.
                .append("msg = msg.replace(/(\\r\\n|\\n|\\r)/gm, '" + ALERT_NEW_LINE_REPLACE + "');")
                .append("document.cookie = '" + ALERT_COOKIE_NAME + "=' + msg + '';").append("return %s;")
                .append("};");
        executeScript(String.format(alertJs.toString(), accept));
    }

    elm.click();

    if (browser.isHeadless()) {
        Cookie alertCookie = webDriver.manage().getCookieNamed(ALERT_COOKIE_NAME);

        for (Cookie cook : webDriver.manage().getCookies()) {
            System.err.print(cook.getName());
        }

        if (alertCookie != null) {
            // replace all newline keywords, to get original message
            alertMsg = StringUtils.trimToNull(alertCookie.getValue());

            if (alertMsg != null)
                alertMsg = alertMsg.replaceAll(ALERT_NEW_LINE_REPLACE, "\n");

            LOG.debug("Headless browser msg: {}", alertMsg);
        } else {
            LOG.debug("Cookie where headless alert messages are stored is null!");
        }

        if (StringUtils.isBlank(alertMsg)) {
            if (throwIfNoAlertPresent) {
                throw new NoAlertPresentException(
                        String.format("No alert message found for headless browser %s!", browser));
            }
        }
    } else {

        Alert alert;

        // IE needs to wait for the alert to appear because we are using native
        // events
        try {
            if (browser.isInternetExplorer()) {
                alert = waitForAlertToBePresent();
            } else {
                alert = webDriver.switchTo().alert();
            }

            alertMsg = alert.getText();

            if (accept) {
                alert.accept();
            } else {
                alert.dismiss();
            }
        } catch (NoAlertPresentException | TimeoutException e) {
            if (throwIfNoAlertPresent) {
                throw e;
            } else {
                LOG.debug("No alert is present! return...");
            }
            return null;
        }
    }

    LOG.debug("{} alert message: {}", accept ? "Accepted" : "Dismissed", alertMsg);
    return alertMsg;
}

From source file:net.sourceforge.fenixedu.domain.organizationalStructure.Party.java

public void setSocialSecurityNumber(String socialSecurityNumber) {
    socialSecurityNumber = StringUtils.trimToNull(socialSecurityNumber);
    if (socialSecurityNumber != null && !StringUtils.isBlank(socialSecurityNumber)) {
        if (getPartySocialSecurityNumber() != null
                && socialSecurityNumber.equals(getPartySocialSecurityNumber().getSocialSecurityNumber())) {
            return;
        }//from   w  w  w . j  a  v a 2  s. co  m

        final Party party = PartySocialSecurityNumber.readPartyBySocialSecurityNumber(socialSecurityNumber);
        if (party != null && party != this) {
            throw new DomainException("error.party.existing.contributor.number");
        } else {
            if (getPartySocialSecurityNumber() != null) {
                getPartySocialSecurityNumber().setSocialSecurityNumber(socialSecurityNumber);
            } else {
                new PartySocialSecurityNumber(this, socialSecurityNumber);
            }
        }
    }
}

From source file:ips1ap101.lib.base.util.StrUtils.java

public static Object getObjeto(String string) {
    Object objeto = null;/*w w  w  .ja va  2  s  .  co  m*/
    String cadena = StringUtils.trimToNull(string);
    if (cadena == null) {
        return null;
    }
    if (StringUtils.isNumeric(cadena)) {
        //          objeto = getObjeto(cadena, EnumTipoDatoParametro.ENTERO);
        objeto = getObjeto(cadena, Integer.class);
    }
    if (objeto == null && StringUtils.isNumeric(cadena)) {
        //          objeto = getObjeto(cadena, EnumTipoDatoParametro.ENTERO_GRANDE);
        objeto = getObjeto(cadena, BigInteger.class);
    }
    if (objeto == null && cadena.startsWith(BundleWebui.getString("id_prefix.string"))) {
        String substr = cadena.substring(1);
        if (StringUtils.isNumeric(substr)) {
            //              objeto = getObjeto(substr, EnumTipoDatoParametro.ENTERO_GRANDE);
            objeto = getObjeto(substr, BigInteger.class);
        }
    }
    if (objeto == null) {
        //          objeto = getObjeto(cadena, EnumTipoDatoParametro.NUMERICO);
        objeto = getObjeto(cadena, BigDecimal.class);
    }
    if (objeto == null) {
        //          objeto = getObjeto(cadena, EnumTipoDatoParametro.FECHA_HORA);
        objeto = getObjeto(cadena, Timestamp.class);
    }
    if (objeto == null) {
        //          objeto = getObjeto(cadena, EnumTipoDatoParametro.ALFANUMERICO);
        objeto = getObjeto(cadena, String.class);
    }
    return objeto;
}

From source file:com.egt.web.configuracion.basica.FragmentoFiltro.java

public String getValorTextoFiltro2() {
    return StringUtils.trimToNull(this.getRecursoDataProvider().getNombreFuncionSelect());
}

From source file:gov.nih.nci.cabig.caaers.rules.business.service.CaaersRulesEngineService.java

/**
 * This method will take care of reconciling the ruleset,by making sure that
 * 1. The ruleSet, has the correct package name
 * 2. The path-to-deploy is correct.//from   w  w w .  j  ava2 s  .  c  om
 *
 * Note: Backward compatiable with the old ruleset naming convention used.
  * @param ruleSet
 */
public void reconcileRuleSet(RuleSet ruleSet) {

    if (StringUtils.isBlank(ruleSet.getSubject()))
        return;

    String level = null;

    Organization org = null;
    Study study = null;

    String strOrgId = null;
    String strStudyId = null;

    String[] subjectParts = StringUtils.split(ruleSet.getSubject(), "||");
    if (subjectParts.length >= 4) {
        //new pattern
        level = subjectParts[1];
        String nciCode = null;
        String studyPrimaryId = null;
        if (level.equals(SPONSOR_DEFINED_STUDY_LEVEL) || level.equals(SPONSOR_LEVEL)) {
            nciCode = subjectParts[2].trim();
        }
        if (level.equals(INSTITUTION_DEFINED_STUDY_LEVEL) || level.equals(INSTITUTIONAL_LEVEL)) {
            nciCode = subjectParts[3].trim();
        }

        studyPrimaryId = subjectParts.length > 4 ? StringUtils.trimToNull(subjectParts[4]) : null;

        if (StringUtils.isNotBlank(nciCode))
            org = organizationDao.getByNCIcode(nciCode);
        if (StringUtils.isNotBlank(studyPrimaryId)) {
            OrganizationAssignedIdentifier id = new OrganizationAssignedIdentifier();
            id.setValue(studyPrimaryId);
            id.setType(OrganizationAssignedIdentifier.SPONSOR_IDENTIFIER_TYPE);
            study = studyDao.getByIdentifier(id);
        }

    } else {
        //old pattern
        String orgName = null;
        String studyShortTitle = null;
        if (StringUtils.equals(subjectParts[0],
                CategoryConfiguration.SPONSOR_DEFINED_STUDY_BASE.getDescription())) {
            level = SPONSOR_DEFINED_STUDY_LEVEL;
            orgName = subjectParts[1].trim();
            studyShortTitle = subjectParts[2].trim();
        } else if (StringUtils.equals(subjectParts[0],
                CategoryConfiguration.INSTITUTION_DEFINED_STUDY_BASE.getDescription())) {
            level = INSTITUTION_DEFINED_STUDY_LEVEL;
            orgName = subjectParts[1].trim();
            studyShortTitle = subjectParts[2].trim();
        } else if (StringUtils.equals(subjectParts[0], CategoryConfiguration.SPONSOR_BASE.getDescription())) {
            level = SPONSOR_LEVEL;
            orgName = subjectParts[1].trim();
        } else if (StringUtils.equals(subjectParts[0],
                CategoryConfiguration.INSTITUTION_BASE.getDescription())) {
            level = INSTITUTIONAL_LEVEL;
            orgName = subjectParts[1].trim();
        }

        if (StringUtils.isNotBlank(orgName))
            org = organizationDao.getByName(orgName);
        if (StringUtils.isNotBlank(studyShortTitle))
            study = studyDao.getByShortTitle(studyShortTitle);
    }

    //do validations - on organization
    if (StringUtils.equals(level, SPONSOR_LEVEL) || StringUtils.equals(level, INSTITUTIONAL_LEVEL)
            || StringUtils.equals(level, INSTITUTION_DEFINED_STUDY_LEVEL)
            || StringUtils.equals(level, SPONSOR_DEFINED_STUDY_LEVEL)) {
        if (org == null)
            throw new CaaersSystemException("RUL_011", "Unable to figureout the sponsor/institution");
    }

    //do validation - study
    if (StringUtils.equals(level, INSTITUTION_DEFINED_STUDY_LEVEL)
            || StringUtils.equals(level, SPONSOR_DEFINED_STUDY_LEVEL)) {
        if (study == null)
            throw new CaaersSystemException("RUL_021", "Could not figure out the study");
    }

    if (org != null)
        strOrgId = String.valueOf(org.getId());
    if (study != null)
        strStudyId = String.valueOf(study.getId());

    //update the package name on the ruleset
    RuleLevel ruleLevel = (StringUtils.isBlank(level) ? null : RuleLevel.getByName(level));
    RuleType ruleType = RuleType.getByName(ruleSet.getDescription());
    Integer orgId = (org != null) ? org.getId() : null;
    Integer studyId = study != null ? study.getId() : null;

    String newPackageName = constructPackageName(ruleType, ruleLevel, orgId, studyId);
    ruleSet.setName(newPackageName);

    //update the subject  \

    String nciCode = org == null ? "" : org.getNciInstituteCode();
    String studyPrimaryId = study == null ? "" : study.getPrimaryIdentifierValue();
    String newSubject = constructSubject(ruleType, ruleLevel, nciCode, studyPrimaryId);
    ruleSet.setSubject(newSubject);

    //update the path.
    String path = generatePath(level, ruleSet.getDescription(), org, org, study);
    for (Rule rule : ruleSet.getRule()) {
        List<Category> categories = rule.getMetaData().getCategory();
        if (categories == null) {
            categories = new ArrayList<Category>();
            rule.getMetaData().setCategory(categories);
        }
        if (categories.isEmpty()) {
            Category category = new Category();
            category.setMetaData(new MetaData());
            categories.add(category);
        }
        if (categories.get(0).getMetaData() == null) {
            categories.get(0).setMetaData(new MetaData());
        }

        rule.getMetaData().getCategory().get(0).setPath(path);
        rule.getMetaData().getCategory().get(0).getMetaData()
                .setName(RuleUtil.getStringWithoutSpaces(ruleSet.getDescription()));
    }

    if (log.isDebugEnabled()) {
        log.debug("New Package Name :" + newPackageName);
        log.debug("New Subject :" + newSubject);
        log.debug("New Path :" + path);
    }
}

From source file:edu.amc.sakai.user.JLDAPDirectoryProvider.java

/**
 * Locates a user directory entry using an email address
 * as a key. Updates the specified {@link org.sakaiproject.user.api.UserEdit}
 * with directory attributes if the search is successful.
 * The {@link org.sakaiproject.user.api.UserEdit} param is 
 * technically optional and will be ignored if <code>null</code>.
 * /*from  w w  w  .  ja  va  2 s  . c  o m*/
 * <p>
 * All {@link java.lang.Exception}s are logged and result in
 * a <code>false</code> return, as do searches which yield
 * no results. (A concession to backward compat.)
 * </p>
 * 
 * @param edit the {@link org.sakaiproject.user.api.UserEdit} to update
 * @param email the search key
 * @return boolean <code>true</code> if the search 
 *   completed without error and found a directory entry
 */
public boolean findUserByEmail(UserEdit edit, String email) {
    try {

        boolean useStdFilter = !(ldapAttributeMapper instanceof EidDerivedEmailAddressHandler);
        LdapUserData resolvedEntry = null;
        if (!(useStdFilter)) {
            try {
                String eid = StringUtils.trimToNull(
                        ((EidDerivedEmailAddressHandler) ldapAttributeMapper).unpackEidFromAddress(email));
                if (eid == null) { // shouldn't happen (see unpackEidFromEmail() javadoc)
                    throw new InvalidEmailAddressException("Attempting to unpack an EID from [" + email
                            + "] resulted in a null or empty string");
                }
                resolvedEntry = getUserByEid(eid, null);
            } catch (InvalidEmailAddressException e) {
                M_log.error("findUserByEmail(): Attempted to look up user at an invalid email address [" + email
                        + "]", e);
                useStdFilter = true; // fall back to std processing, we cant derive an EID from this addr
            }
        }

        // we do _only_ fall back to std processing if EidDerivedEmailAddressHandler actually
        // indicated it could not handle the given email addr. If it could handle the addr
        // but found no results, we honor that empty result set
        if (useStdFilter) { // value may have been changed in EidDerivedEmailAddressHandler block above
            String filter = ldapAttributeMapper.getFindUserByEmailFilter(email);
            resolvedEntry = (LdapUserData) searchDirectoryForSingleEntry(filter, null, null, null, null);
        }

        if (resolvedEntry == null) {
            if (M_log.isDebugEnabled()) {
                M_log.debug("findUserByEmail(): failed to find user by email [email = " + email + "]");
            }
            return false;
        }

        if (M_log.isDebugEnabled()) {
            M_log.debug("findUserByEmail(): found user by email [email = " + email + "]");
        }

        if (edit != null) {
            mapUserDataOntoUserEdit(resolvedEntry, edit);
        }

        return true;

    } catch (Exception e) {
        M_log.error("findUserByEmail(): failed [email = " + email + "]");
        M_log.debug("Exception: ", e);
        return false;
    }

    /*
            
    if ( M_log.isDebugEnabled() ) {
       M_log.debug("findUserByEmail(): [email = " + email + "]");
    }
            
    try {
            
       String filter = 
    ldapAttributeMapper.getFindUserByEmailFilter(email);
            
       // takes care of caching and everything
       LdapUserData mappedEntry = 
    (LdapUserData)searchDirectoryForSingleEntry(filter, 
          null, null, null, null);
            
       if ( mappedEntry == null ) {
    if ( M_log.isDebugEnabled() ) {
       M_log.debug("findUserByEmail(): failed to find user by email [email = " + email + "]");
    }
    return false;
       }
            
       if ( M_log.isDebugEnabled() ) {
    M_log.debug("findUserByEmail(): found user by email [email = " + email + "]");
       }
            
       if ( edit != null ) {
    mapUserDataOntoUserEdit(mappedEntry, edit);
       }
            
       return true;
            
    } catch (Exception e) {
       M_log.error("findUserByEmail(): failed [email = " + email + "]", e);
       return false;
    }
            
    */

}

From source file:com.egt.web.configuracion.basica.FragmentoFiltro.java

public void setValorTextoFiltro2(String valor) {
    this.getRecursoDataProvider().setNombreFuncionSelect(StringUtils.trimToNull(valor));
}