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:hudson.plugins.sonar.SonarPublisher.java

@DataBoundConstructor
public SonarPublisher(String installationName, String branch, TriggersConfig triggers,
        String jobAdditionalProperties, String mavenOpts, String mavenInstallationName, String rootPom,
        String jdk, SettingsProvider settings, GlobalSettingsProvider globalSettings,
        boolean usePrivateRepository) {
    this.installationName = installationName;
    this.branch = branch;
    this.jdk = StringUtils.trimToNull(jdk);
    // Triggers// w w  w. j av  a 2s. c o m
    this.triggers = triggers;
    // Maven
    this.mavenOpts = mavenOpts;
    this.jobAdditionalProperties = jobAdditionalProperties;
    // Non Maven Project
    this.mavenInstallationName = StringUtils.trimToNull(mavenInstallationName);
    this.rootPom = rootPom;
    this.settings = settings != null ? settings : new DefaultSettingsProvider();
    this.globalSettings = globalSettings != null ? globalSettings : new DefaultGlobalSettingsProvider();
    this.usePrivateRepository = usePrivateRepository;
}

From source file:com.egt.core.db.util.InterpreteSqlAbstracto.java

@Override
public String getStringCriterioBusqueda(CriterioBusqueda criterio) {
    EnumOperadorCom comparacion = criterio.getComparacion();
    if (comparacion == null) {
        return null;
    }/*  ww w.ja va 2s  . c om*/
    String string = null;
    //      String columna = StringUtils.trimToNull(criterio.getColumna(dominio));
    String columna = StringUtils.trimToNull(criterio.getColumna());
    Object valor = criterio.getValor();
    if (columna == null) {
        if (valor != null && valor instanceof String) {
            String expresion = (String) valor;
            switch (comparacion) {
            case EXISTE:
                string = getExists() + "(" + expresion + ")";
                break;
            case NO_EXISTE:
                string = getNotExists() + "(" + expresion + ")";
                break;
            }
        }
        return string == null ? null : "(" + string.trim() + ")";
    }
    if (valor == null) {
        switch (comparacion) {
        case ES_NULO:
            string = columna + getIsNull();
            break;
        case NO_ES_NULO:
            string = columna + getIsNotNull();
            break;
        }
        return string == null ? null : "(" + string.trim() + ")";
    }
    switch (comparacion) {
    case ES_NULO:
        string = columna + getIsNull();
        break;
    case NO_ES_NULO:
        string = columna + getIsNotNull();
        break;
    case ES_IGUAL:
        string = columna + getEQ() + getStringDelimitado(valor);
        break;
    case NO_ES_IGUAL:
        string = columna + getNEQ() + getStringDelimitado(valor);
        break;
    case ES_MAYOR:
        string = columna + getGT() + getStringDelimitado(valor);
        break;
    case ES_MENOR_O_IGUAL:
        string = columna + getLTEQ() + getStringDelimitado(valor);
        break;
    case ES_MAYOR_O_IGUAL:
        string = columna + getGTEQ() + getStringDelimitado(valor);
        break;
    case ES_MENOR:
        string = columna + getLT() + getStringDelimitado(valor);
        break;
    case COMIENZA_POR:
        string = columna + getLike() + getStringDelimitado(getString(valor) + getLikeString());
        break;
    case NO_COMIENZA_POR:
        string = columna + getNotLike() + getStringDelimitado(getString(valor) + getLikeString());
        break;
    case CONTIENE:
        string = columna + getLike()
                + getStringDelimitado(getLikeString() + getString(valor) + getLikeString());
        break;
    case NO_CONTIENE:
        string = columna + getNotLike()
                + getStringDelimitado(getLikeString() + getString(valor) + getLikeString());
        break;
    case TERMINA_EN:
        string = columna + getLike() + getStringDelimitado(getLikeString() + getString(valor));
        break;
    case NO_TERMINA_EN:
        string = columna + getNotLike() + getStringDelimitado(getLikeString() + getString(valor));
        break;
    case ESTA_ENTRE:
        string = columna + getIn() + "(" + getString(valor) + ")";
        break;
    case NO_ESTA_ENTRE:
        string = columna + getNotIn() + "(" + getString(valor) + ")";
        break;
    case ES_NULO_O_ES_IGUAL:
        string = columna + getIsNullOr() + columna + getEQ() + getStringDelimitado(valor);
        break;
    case ES_NULO_O_NO_ES_IGUAL:
        string = columna + getIsNullOr() + columna + getNEQ() + getStringDelimitado(valor);
        break;
    case ES_NULO_O_ES_MAYOR:
        string = columna + getIsNullOr() + columna + getGT() + getStringDelimitado(valor);
        break;
    case ES_NULO_O_ES_MENOR_O_IGUAL:
        string = columna + getIsNullOr() + columna + getLTEQ() + getStringDelimitado(valor);
        break;
    case ES_NULO_O_ES_MAYOR_O_IGUAL:
        string = columna + getIsNullOr() + columna + getGTEQ() + getStringDelimitado(valor);
        break;
    case ES_NULO_O_ES_MENOR:
        string = columna + getIsNullOr() + columna + getLT() + getStringDelimitado(valor);
        break;
    case ES_NULO_O_COMIENZA_POR:
        string = columna + getIsNullOr() + columna + getLike()
                + getStringDelimitado(getString(valor) + getLikeString());
        break;
    case ES_NULO_O_NO_COMIENZA_POR:
        string = columna + getIsNullOr() + columna + getNotLike()
                + getStringDelimitado(getString(valor) + getLikeString());
        break;
    case ES_NULO_O_CONTIENE:
        string = columna + getIsNullOr() + columna + getLike()
                + getStringDelimitado(getLikeString() + getString(valor) + getLikeString());
        break;
    case ES_NULO_O_NO_CONTIENE:
        string = columna + getIsNullOr() + columna + getNotLike()
                + getStringDelimitado(getLikeString() + getString(valor) + getLikeString());
        break;
    case ES_NULO_O_TERMINA_EN:
        string = columna + getIsNullOr() + columna + getLike()
                + getStringDelimitado(getLikeString() + getString(valor));
        break;
    case ES_NULO_O_NO_TERMINA_EN:
        string = columna + getIsNullOr() + columna + getNotLike()
                + getStringDelimitado(getLikeString() + getString(valor));
        break;
    case ES_NULO_O_ESTA_ENTRE:
        string = columna + getIsNullOr() + columna + getIn() + "(" + getString(valor) + ")";
        break;
    case ES_NULO_O_NO_ESTA_ENTRE:
        string = columna + getIsNullOr() + columna + getNotIn() + "(" + getString(valor) + ")";
        break;
    }
    return StringUtils.isBlank(string) ? null : "(" + string.trim() + ")";
}

From source file:com.opengamma.web.region.WebRegionResource.java

@POST
@Consumes(MediaType.APPLICATION_FORM_URLENCODED)
@Produces(MediaType.APPLICATION_JSON)//from   ww  w  .  ja  v a2 s.c o m
public Response postJSON(@FormParam("name") String name, @FormParam("fullname") String fullName,
        @FormParam("classification") RegionClassification classification,
        @FormParam("country") String countryISO, @FormParam("currency") String currencyISO,
        @FormParam("timezone") String timeZoneId) {
    if (data().getRegion().isLatest() == false) {
        return Response.status(Status.FORBIDDEN).entity(getHTML()).build();
    }

    name = StringUtils.trimToNull(name);
    fullName = StringUtils.trimToNull(fullName);
    countryISO = StringUtils.trimToNull(countryISO);
    currencyISO = StringUtils.trimToNull(currencyISO);
    timeZoneId = StringUtils.trimToNull(timeZoneId);
    if (name == null || classification == null) {
        Response.status(Status.BAD_REQUEST);
    }
    if (fullName == null) {
        fullName = name;
    }
    URI uri = addRegion(name, fullName, classification, countryISO, currencyISO, timeZoneId);
    return Response.created(uri).build();
}

From source file:com.hand.hap.mybatis.util.OGNL.java

/**
 * FOR INTERNAL USE ONLY/*from  ww w  . ja  va2  s. c o  m*/
 * 
 * @param parameter
 * @return
 */
public static String getOrderByClause_TL(Object parameter) {
    if (parameter == null) {
        return null;
    }
    StringBuilder sb = new StringBuilder(64);
    if (parameter instanceof BaseDTO) {
        String sortName = ((BaseDTO) parameter).getSortname();
        Field[] ids = DTOClassInfo.getIdFields(parameter.getClass());
        if (StringUtil.isNotEmpty(sortName)) {
            if (!COL_PATTERN.matcher(sortName).matches()) {
                throw new RuntimeException("Invalid sortname:" + sortName);
            }
            String order = ((BaseDTO) parameter).getSortorder();
            if (!("ASC".equalsIgnoreCase(order) || "DESC".equalsIgnoreCase(order) || order == null)) {
                throw new RuntimeException("Invalid sortorder:" + order);
            }
            String columnName = unCamel(sortName);
            Field[] mlfs = DTOClassInfo.getMultiLanguageFields(parameter.getClass());
            for (Field f : mlfs) {
                if (f.getName().equals(columnName)) {
                    if (f.getAnnotation(MultiLanguageField.class) == null) {
                        sb.append("b.");
                    } else {
                        sb.append("t.");
                    }
                    break;
                }
            }

            sb.append(columnName).append(" ");
            sb.append(StringUtils.defaultIfEmpty(order, "ASC"));

            if (ids.length > 0 && !ids[0].getName().equals(sortName)) {
                sb.append(",b.").append(DTOClassInfo.getColumnName(ids[0])).append(" ASC");
            }
        } else {
            if (ids.length > 0) {
                sb.append("b.").append(DTOClassInfo.getColumnName(ids[0])).append(" ASC");
            }
        }
    }
    return StringUtils.trimToNull(sb.toString());
}

From source file:com.hmsinc.epicenter.classifier.lm.AbstractLMClassifier.java

/**
 * Evaluates the classifier's performance against a CSV file.
 * /*  w  ww.j a  v  a 2 s  .co m*/
 * The format of the test set should be "complaint,category", one per line.
 * 
 * @param testSet
 * @return
 */
@SuppressWarnings("unchecked")
public ClassifierEvaluator<String, ? extends com.aliasi.classify.Classification> test(final String testSet) {

    Validate.notNull(classifier, "Classifier has not been initialized!");
    ClassifierEvaluator<String, ? extends com.aliasi.classify.Classification> evaluator = null;

    BufferedReader br = null;
    try {

        br = new BufferedReader(new FileReader(testSet), ",".charAt(0));
        final CSVParser csv = new CSVParser(br);

        // FIXME: Not sure how to make this typesafe
        evaluator = new ClassifierEvaluator(classifier, classifier.categories());
        logger.info("Testing classifier using testing source: {}", testSet);

        String[] fields;
        while ((fields = csv.getLine()) != null) {

            if (fields.length == 2) {
                final String category = StringUtils.trimToNull(fields[1]);
                final String complaint = ClassifierUtils.filter(fields[0], stopwords).toString();
                if (category != null && complaint != null) {
                    evaluator.addCase(category, complaint);
                }
            }
        }

        if (logger.isDebugEnabled()) {
            logger.debug(evaluator.confusionMatrix().toString());
        }

    } catch (IOException e) {
        throw new RuntimeException(e);
    } finally {
        if (br != null) {
            try {
                br.close();
            } catch (IOException e) {
                throw new RuntimeException(e);
            }
        }
    }

    return evaluator;
}

From source file:com.bluexml.xforms.generator.forms.modelelement.ModelElementBindSimple.java

@Override
public Element getModelElement() {
    String bindId = XFormsGenerator.getId(MsgId.INT_GEN_PREFIX_BIND_FORM.getText());
    Element bindElement = XFormsGenerator.createElement("bind", XFormsGenerator.NAMESPACE_XFORMS);
    bindElement.setAttribute("nodeset", nodeset);
    bindElement.setAttribute("id", bindId);
    if (type != null) {
        // ** #1280
        String typeStr = type.toString();
        if ((typeStr.equalsIgnoreCase(MsgId.INT_TYPE_XSD_DATE.getText())
                || typeStr.equalsIgnoreCase(MsgId.INT_TYPE_XSD_DATETIME.getText())
                || typeStr.equalsIgnoreCase(MsgId.INT_TYPE_XSD_TIME.getText())) && isReadOnly()) {
            typeStr = "string";
            // there is not much use in setting the 'type' field, we do it for being consistent.
            type = new QName("string");
        }/*from   ww w .  j a va2s.  c  om*/
        // ** #1280
        bindElement.setAttribute("type", typeStr);
    }
    if (isRequired()) {
        String ref = getMultipleInputReference();
        if (ref != null) { // this bind is for an input with multiple values 
            //** #1420
            String reqExpr = "instance('minstance')/" + ref + "[1]/";
            reqExpr = reqExpr + MsgId.INT_INSTANCE_INPUT_MULT_VALUE + " eq ''";
            bindElement.setAttribute("required", reqExpr);
            //** #1420
        } else {
            bindElement.setAttribute("required", "true()");
            if (isAnAssociation() == false) {
                setConstraint("(. ne '')");
            }
        }
    } else {
        // if (getLengthConstraint() != null) {
        // bindElement.setAttribute("required", "not (string-length(.) = 0 or ("
        // + getLengthConstraint() + "))");
        // }
    }
    if (isReadOnly()) {
        bindElement.setAttribute("readonly", "true()");
    }
    if (isHidden()) {
        bindElement.setAttribute("relevant", "false()");
    } else {
        // ** #1340
        if (isRequired()) { // TO UPDATE in case regex fields no longer allow empty strings
            setRelevantAttrForGhostTemplate(bindElement);
        }
        // ** #1340
    }
    if (StringUtils.trimToNull(constraint) != null) {
        bindElement.setAttribute("constraint", constraint);
    }

    for (Element linkedElement : linkedElements) {
        linkedElement.setAttribute("bind", bindId);
    }

    return bindElement;
}

From source file:net.bulletin.pdi.xero.step.XeroGetStepMeta.java

public void setContainerElements(String containerElements) {
    this.containerElements = StringUtils.trimToNull(containerElements);
}

From source file:com.hmsinc.epicenter.integrator.service.event.AbstractHL7EventHandler.java

/**
 * Extracts a diagnosis from an ADT_A01 structure.
 * //from  w w  w.  j  a  va 2 s.c om
 * @param adt
 * @return
 * @throws HL7Exception
 */
protected static String extractDiagnosis(final ADT_A01 adt) throws HL7Exception {

    String ret = null;

    // ICD9 Description
    if (adt.getDG1Reps() > 0) {

        final StringBuilder descs = new StringBuilder();

        for (int i = 0; i < adt.getDG1Reps(); i++) {

            if (adt.getDG1(i).getDiagnosisDescription() != null) {
                final String desc = StringUtils.trimToNull(adt.getDG1(i).getDiagnosisDescription().getValue());

                if (desc != null && isValidComplaint(desc)
                        && (descs.length() + desc.length() + 1) < MAX_REASON_LENGTH) {
                    if (descs.length() > 0) {
                        descs.append("/");
                    }
                    descs.append(desc);
                }
            }
        }

        ret = StringUtils.trimToNull(descs.toString());
    }

    return ret;
}

From source file:ch.entwine.weblounge.taglib.WebloungeTag.java

/**
 * Adds the class to the css class attribute.
 * /*w  w w  .j  a  v a2 s.co m*/
 * @param c
 *          the class name
 */
protected void addCssClass(String c) {
    if (StringUtils.trimToNull(c) == null)
        return;
    if (css == null)
        css = c;
    else if (!css.startsWith(c + " ") && !css.endsWith(" " + c) && !css.contains(" " + c + " "))
        css += " " + c;
}

From source file:au.org.ala.names.parser.PhraseNameParser.java

@Override
public <T> ParsedName<T> parse(String scientificName) throws UnparsableException {
    ParsedName pn = super.parse(scientificName);
    if (pn.getType() != NameType.wellformed && isPhraseRank(pn.rank) && (!pn.authorsParsed
            || pn.specificEpithet == null || SPECIES_PATTERN.matcher(pn.specificEpithet).matches())) {
        //if the rank marker is sp. and the word after the rank marker is lower case check to see if removing the marker will result is a wellformed name
        if (SPECIES_PATTERN.matcher(pn.rank).matches()) {
            Matcher m1 = POTENTIAL_SPECIES_PATTERN.matcher(scientificName);
            //System.out.println(POTENTIAL_SPECIES_PATTERN.pattern());
            if (m1.find()) {
                //now reparse without the rankMarker
                String newName = m1.group(1) + m1.group(3) + StringUtils.defaultString(m1.group(4), "");
                pn = super.parse(newName);
                if (pn.getType() == NameType.wellformed)
                    return pn;
            }/*from  w  ww  .j  av a 2 s .  c  o m*/
        }
        //check to see if the name represents a phrase name
        Matcher m = PHRASE_PATTERN.matcher(scientificName);
        if (m.find()) {
            ALAParsedName alapn = new ALAParsedName(pn);
            alapn.setLocationPhraseDescription(StringUtils.trimToNull(m.group(3)));
            alapn.setPhraseVoucher(StringUtils.trimToNull(m.group(4)));
            alapn.setPhraseNominatingParty(StringUtils.trimToNull(m.group(5)));
            return alapn;
        }

    } else {
        //check for the situation where the subgenus was supplied without Title case.
        Matcher m = WRONG_CASE_INFRAGENERIC.matcher(scientificName);
        if (m.find()) {
            scientificName = WordUtils.capitalize(scientificName, '(');
            pn = super.parse(scientificName);
        }
    }

    return pn;
}