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:ips1ap101.lib.core.db.util.InterpreteSqlAbstracto.java

@Override
public String getStringCriterioBusqueda(CriterioBusqueda criterio) {
    OperadorComEnumeration comparacion = criterio.getComparacion();
    if (comparacion == null) {
        return null;
    }// w  w w .ja va 2s .com
    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;
        case ES_VERDADERO:
            string = columna + getIsTrue();
            break;
        case NO_ES_VERDADERO:
            string = columna + getIsNotTrue();
            break;
        case ES_FALSO:
            string = columna + getIsFalse();
            break;
        case NO_ES_FALSO:
            string = columna + getIsNotFalse();
            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_VERDADERO:
        string = columna + getIsTrue();
        break;
    case NO_ES_VERDADERO:
        string = columna + getIsNotTrue();
        break;
    case ES_FALSO:
        string = columna + getIsFalse();
        break;
    case NO_ES_FALSO:
        string = columna + getIsNotFalse();
        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.bluexml.side.Workflow.modeler.diagram.edit.ActionEditPart.java

@Override
protected void refreshHeaderLabel() {
    Action action = (Action) Utils.getElement(getGraphNode());
    if (StringUtils.trimToNull(action.getExpression()) != null) {
        getLabel().setText(action.getExpression());
    } else if (action.getScript().size() > 0) {
        getLabel().setText(action.getScript().get(0).getExpression());
    } else {//  w  w w.  j  a v  a  2  s. co  m
        super.refreshHeaderLabel();
    }
}

From source file:com.opengamma.web.position.WebPositionsResource.java

@POST
@Consumes(MediaType.APPLICATION_FORM_URLENCODED)
@Produces(MediaType.TEXT_HTML)/*from   ww  w  .  j  a  v a 2  s  .  c om*/
public Response postHTML(@FormParam("quantity") String quantityStr, @FormParam("idscheme") String idScheme,
        @FormParam("idvalue") String idValue) {
    quantityStr = StringUtils.replace(StringUtils.trimToNull(quantityStr), ",", "");
    BigDecimal quantity = quantityStr != null && NumberUtils.isNumber(quantityStr) ? new BigDecimal(quantityStr)
            : null;
    idScheme = StringUtils.trimToNull(idScheme);
    idValue = StringUtils.trimToNull(idValue);
    if (quantity == null || idScheme == null || idValue == null) {
        FlexiBean out = createRootData();
        if (quantityStr == null) {
            out.put("err_quantityMissing", true);
        }
        if (quantity == null) {
            out.put("err_quantityNotNumeric", true);
        }
        if (idScheme == null) {
            out.put("err_idschemeMissing", true);
        }
        if (idValue == null) {
            out.put("err_idvalueMissing", true);
        }
        String html = getFreemarker().build(HTML_DIR + "positions-add.ftl", out);
        return Response.ok(html).build();
    }
    ExternalIdBundle id = ExternalIdBundle.of(ExternalId.of(idScheme, idValue));
    UniqueId secUid = getSecurityUniqueId(id);
    if (secUid == null) {
        FlexiBean out = createRootData();
        out.put("err_idvalueNotFound", true);
        String html = getFreemarker().build(HTML_DIR + "positions-add.ftl", out);
        return Response.ok(html).build();
    }
    URI uri = addPosition(quantity, secUid);
    return Response.seeOther(uri).build();
}

From source file:com.opengamma.master.region.impl.RegionFileReader.java

/**
 * Parses the specified file to populate the master.
 * /*w  ww  .j a v  a  2 s .  c om*/
 * @param in  the input reader to read, not closed, not null
 */
public void parse(Reader in) {
    String name = null;
    try {
        Map<String, ManageableRegion> regions = new HashMap<String, ManageableRegion>();
        Map<UniqueId, Set<String>> subRegions = new HashMap<UniqueId, Set<String>>();

        // open CSV file
        @SuppressWarnings("resource")
        CSVReader reader = new CSVReader(in);
        List<String> columns = Arrays.asList(reader.readNext());

        // identify columns
        final int nameColumnIdx = columns.indexOf(NAME_COLUMN);
        final int formalNameColumnIdx = columns.indexOf(FORMAL_NAME_COLUMN);
        final int classificationColumnIdx = columns.indexOf(CLASSIFICATION_COLUMN);
        final int sovereignityColumnIdx = columns.indexOf(SOVEREIGNITY_COLUMN);
        final int countryColumnIdx = columns.indexOf(ISO_COUNTRY_2_COLUMN);
        final int currencyColumnIdx = columns.indexOf(ISO_CURRENCY_3_COLUMN);
        final int subRegionsColumnIdx = columns.indexOf(SUB_REGIONS_COLUMN);

        // parse
        String[] row = null;
        while ((row = reader.readNext()) != null) {
            name = row[nameColumnIdx].trim(); // the primary key
            String fullName = StringUtils.trimToNull(row[formalNameColumnIdx]);
            if (fullName == null) {
                fullName = name;
            }
            RegionClassification classification = RegionClassification
                    .valueOf(row[classificationColumnIdx].trim());
            String sovereignity = StringUtils.trimToNull(row[sovereignityColumnIdx]);
            String countryISO = StringUtils.trimToNull(row[countryColumnIdx]);
            String currencyISO = StringUtils.trimToNull(row[currencyColumnIdx]);
            Set<String> rowSubRegions = new HashSet<String>(Arrays.asList(row[subRegionsColumnIdx].split(";")));
            rowSubRegions = trim(rowSubRegions);

            ManageableRegion region = new ManageableRegion();
            region.setClassification(classification);
            region.setName(name);
            region.setFullName(fullName);
            if (countryISO != null) {
                region.setCountry(Country.of(countryISO));
                region.addExternalId(ExternalSchemes.financialRegionId(countryISO)); // TODO: looks odd
            }
            if (currencyISO != null) {
                region.setCurrency(Currency.of(currencyISO));
            }
            if (sovereignity != null) {
                ManageableRegion parent = regions.get(sovereignity);
                if (parent == null) {
                    throw new OpenGammaRuntimeException(
                            "Cannot find parent '" + sovereignity + "'  for '" + name + "'");
                }
                region.getParentRegionIds().add(parent.getUniqueId());
            }
            for (Entry<UniqueId, Set<String>> entry : subRegions.entrySet()) {
                if (entry.getValue().remove(name)) {
                    region.getParentRegionIds().add(entry.getKey());
                }
            }

            // store
            RegionDocument doc = getRegionMaster().add(new RegionDocument(region));
            if (rowSubRegions.size() > 0) {
                subRegions.put(doc.getUniqueId(), rowSubRegions);
            }
            regions.put(name, region);
        }
        for (Set<String> set : subRegions.values()) {
            if (set.size() > 0) {
                throw new OpenGammaRuntimeException("Cannot find children: " + set);
            }
        }

    } catch (Exception ex) {
        String detail = (name != null ? " while processing " + name : "");
        throw new OpenGammaRuntimeException("Cannot open region data file (or file I/O problem)" + detail, ex);
    }
}

From source file:eionet.meta.dao.domain.VocabularyFolder.java

/**
 * @param baseUri//from ww  w .j  av a 2s .c o m
 *            the baseUri to set
 */
public void setBaseUri(String baseUri) {
    this.baseUri = StringUtils.trimToNull(baseUri);
    if (StringUtils.isNotBlank(this.baseUri) && !StringUtils.endsWith(this.baseUri, "/")
            && !StringUtils.endsWith(this.baseUri, ":") && !StringUtils.endsWith(this.baseUri, "#")) {
        this.baseUri = this.baseUri + "/";
    }
}

From source file:com.opengamma.web.security.WebSecuritiesResource.java

@POST
@Consumes(MediaType.APPLICATION_FORM_URLENCODED)
@Produces(MediaType.TEXT_HTML)/*from  www  .j a  v a 2 s.  c  o m*/
public Response postHTML(@FormParam("idscheme") String idScheme, @FormParam("idvalue") String idValue) {
    idScheme = StringUtils.trimToNull(idScheme);
    idValue = StringUtils.trimToNull(idValue);
    FlexiBean out = createRootData();
    if (idScheme == null || idValue == null) {
        if (idScheme == null) {
            out.put("err_idschemeMissing", true);
        }
        if (idValue == null) {
            out.put("err_idvalueMissing", true);
        }
        out.put("idscheme", idScheme);
        out.put("idvalue", idValue);
        String html = getFreemarker().build(HTML_DIR + "securities-add.ftl", out);
        return Response.ok(html).build();
    }
    ExternalScheme scheme = ExternalScheme.of(idScheme);
    Collection<ExternalIdBundle> bundles = buildSecurityRequest(scheme, idValue);
    SecurityLoader securityLoader = data().getSecurityLoader();
    Map<ExternalIdBundle, UniqueId> loadedSecurities = securityLoader.loadSecurities(bundles);

    URI uri = null;
    if (bundles.size() == 1 && loadedSecurities.size() == 1) {
        ExternalIdBundle identifierBundle = bundles.iterator().next();
        uri = data().getUriInfo().getAbsolutePathBuilder()
                .path(loadedSecurities.get(identifierBundle).toLatest().toString()).build();
    } else {
        uri = uri(data(), buildRequestAsExternalIdBundle(scheme, bundles));
    }
    return Response.seeOther(uri).build();
}

From source file:com.opengamma.id.UniqueId.java

/**
 * Creates a unique instance./*from ww w.ja v  a2  s .c  o m*/
 * 
 * @param scheme  the scheme of the identifier, not empty, not null
 * @param value  the value of the identifier, not empty, not null
 * @param version  the version of the identifier, null if latest version
 */
private UniqueId(String scheme, String value, String version) {
    ArgumentChecker.notEmpty(scheme, "scheme");
    ArgumentChecker.notEmpty(value, "value");
    _scheme = scheme;
    _value = value;
    _version = StringUtils.trimToNull(version);
}

From source file:meta.proyecto.base.ProyectoJava.java

private static String getString(String key) {
    try {/*  www .  j  a  va  2 s  .  c  o  m*/
        String string = RB.getString(key);
        return StringUtils.trimToNull(string);
    } catch (Exception e) {
        return null;
    }
}

From source file:com.alibaba.otter.manager.web.home.module.action.DataMediaPairAction.java

/**
 * ?DataMediaPair/*from   w  ww  .j  av  a  2  s.c  om*/
 * 
 * @param dataMediaPairInfo
 * @throws Exception
 */
public void doBatchAdd(@FormGroup("batchDataMediaPairInfo") Group batchDataMediaPairInfo,
        @Param("pipelineId") Long pipelineId,
        @FormField(name = "formBatchDataMediaPairError", group = "batchDataMediaPairInfo") CustomErrors err,
        Navigator nav) throws Exception {
    String batchPairContent = batchDataMediaPairInfo.getField("batchPairContent").getStringValue();
    List<String> StringPairs = Arrays.asList(batchPairContent.split("\r\n"));
    try {
        for (String stringPair : StringPairs) {
            List<String> pairData = Arrays.asList(stringPair.split(","));
            if (pairData.size() < 4) {
                throw new ManagerException("[" + stringPair + "] the line not all parameters");
            }
            // build the pair source
            DataMedia sourceDataMedia = new DataMedia();
            DataMediaSource sourceDataMediaSource = dataMediaSourceService
                    .findById(Long.parseLong(StringUtils.trimToNull(pairData.get(2))));
            sourceDataMedia.setNamespace(StringUtils.trimToNull(pairData.get(0)));
            sourceDataMedia.setName(StringUtils.trimToNull(pairData.get(1)));
            sourceDataMedia.setSource(sourceDataMediaSource);
            Long sourceMediaId = dataMediaService.createReturnId(sourceDataMedia);
            sourceDataMedia.setId(sourceMediaId);
            // build the pair target
            DataMedia targetDataMedia = new DataMedia();
            Long weight = 5L;
            if (StringUtils.isNumeric(pairData.get(3)) && pairData.size() <= 5) {// ??
                DataMediaSource targetDataMediaSource = dataMediaSourceService
                        .findById(Long.parseLong(StringUtils.trimToNull(pairData.get(3))));
                targetDataMedia.setNamespace(StringUtils.trimToNull(pairData.get(0)));
                targetDataMedia.setName(StringUtils.trimToNull(pairData.get(1)));
                targetDataMedia.setSource(targetDataMediaSource);
                Long targetMediaId = dataMediaService.createReturnId(targetDataMedia);
                targetDataMedia.setId(targetMediaId);

                if (pairData.size() >= 5) {
                    weight = Long.parseLong(StringUtils.trimToNull(pairData.get(4)));
                }
            } else {
                DataMediaSource targetDataMediaSource = dataMediaSourceService
                        .findById(Long.parseLong(StringUtils.trimToNull(pairData.get(5))));
                targetDataMedia.setNamespace(StringUtils.trimToNull(pairData.get(3)));
                targetDataMedia.setName(StringUtils.trimToNull(pairData.get(4)));
                targetDataMedia.setSource(targetDataMediaSource);
                Long targetMediaId = dataMediaService.createReturnId(targetDataMedia);
                targetDataMedia.setId(targetMediaId);

                if (pairData.size() >= 7) {
                    weight = Long.parseLong(StringUtils.trimToNull(pairData.get(6)));
                }
            }

            // build the pair
            DataMediaPair dataMediaPair = new DataMediaPair();
            dataMediaPair.setSource(sourceDataMedia);
            dataMediaPair.setTarget(targetDataMedia);
            dataMediaPair.setPushWeight(weight);
            dataMediaPair.setPipelineId(pipelineId);

            dataMediaPairService.createIfNotExist(dataMediaPair);
        }
    } catch (Exception e) {
        err.setMessage("invalidBatchDataMediaPair");
        return;
    }
    nav.redirectToLocation("dataMediaPairList.htm?pipelineId=" + pipelineId);
}

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

/**
 * Extracts ICD9 codes from an ADT_A01 v2.5 structure.
 * /*from ww  w.  ja  va  2 s  .  c  o  m*/
 * @param adt
 * @return
 * @throws HL7Exception
 */
protected static String extractICD9Codes(final ADT_A01 adt) throws HL7Exception {

    String ret = null;

    if (adt.getDG1Reps() > 0) {

        final StringBuilder codes = new StringBuilder();

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

            if (adt.getDG1(i).getDiagnosisCodeDG1().getIdentifier().getValue() != null) {
                final String code = StringUtils
                        .trimToNull(adt.getDG1(i).getDiagnosisCodeDG1().getIdentifier().getValue());

                if (code != null && (codes.length() + code.length() + 1 < MAX_ICD9_LENGTH)) {
                    if (codes.length() > 0) {
                        codes.append("/");
                    }
                    codes.append(code);
                }
            }
        }

        ret = StringUtils.trimToNull(codes.toString());
    }
    return ret;
}