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.util.STP.java

public static Object getObjeto(String string, TipoDatoParEnumeration tipo) {
    String cadena = StringUtils.trimToNull(string);
    if (cadena == null) {
        return null;
    }/*ww w .  jav  a  2 s  .  c  om*/
    Object objeto;
    switch (tipo) {
    case ALFANUMERICO:
        //              objeto = new String(string);
        objeto = cadena;
        break;
    case NUMERICO:
        try {
            objeto = new BigDecimal(cadena);
        } catch (NumberFormatException e) {
            objeto = null;
        }
        break;
    case FECHA_HORA:
        try {
            java.util.Date dateTime = TimeUtils.parse(cadena);
            objeto = dateTime == null ? null : new Timestamp(dateTime.getTime());
        } catch (RuntimeException e) {
            objeto = null;
        }
        break;
    case ENTERO:
        try {
            objeto = new Integer(new BigDecimal(cadena).intValue());
        } catch (NumberFormatException e) {
            objeto = null;
        }
        break;
    case ENTERO_GRANDE:
        try {
            objeto = new Long(new BigDecimal(cadena).longValue());
        } catch (NumberFormatException e) {
            objeto = null;
        }
        break;
    default:
        objeto = null;
        break;
    }
    return objeto;
}

From source file:com.thihy.jacoco.data.BundleCoverageDataReader.java

private IMethodCoverage readMethodCoverage() {
    try {/*w ww.j a va  2  s  . co m*/
        //         byte blocktype;
        //         if ((blocktype = in.readByte()) != BundleCoverageDataWriter.BLOCK_METHOD_COVERAGE_DATA) {
        //            throw new IOException(format("Unknown block type %x.", Byte.valueOf(blocktype)));
        //         }
        ISourceNode sourceNode = readSourceNode();
        String signature = StringUtils.trimToNull(in.readUTF());
        String desc = in.readUTF();
        return new MethodCoverage(sourceNode, signature, desc);
    } catch (final IOException e) {
        throw new RuntimeException(e);
    }
}

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

private Collection<ExternalIdBundle> buildSecurityRequest(final ExternalScheme identificationScheme,
        final String idValue) {
    if (idValue == null) {
        return Collections.emptyList();
    }/*  w  w  w.j  a v a2  s.  com*/
    final String[] identifiers = StringUtils.split(idValue, "\n");
    final List<ExternalIdBundle> result = new ArrayList<ExternalIdBundle>(identifiers.length);
    for (String identifier : identifiers) {
        identifier = StringUtils.trimToNull(identifier);
        if (identifier != null) {
            result.add(ExternalIdBundle.of(ExternalId.of(identificationScheme, identifier)));
        }
    }
    return result;
}

From source file:ips1ap101.lib.core.util.JS.java

private static String merge(String name, VelocityContext context) {
    String script = null;/*from www .  java  2 s  .  c o m*/
    if (VelocityEngineer.init()) {
        try {
            Template template = Velocity.getTemplate(name + "." + "vm");
            if (context == null) {
                context = new VelocityContext();
            }
            StringWriter writer = new StringWriter();
            template.merge(context, writer);
            script = StringUtils.trimToNull(writer.toString());
        } catch (ResourceNotFoundException | ParseErrorException | MethodInvocationException ex) {
            // ex.printStackTrace();
        }
    }
    return script;
}

From source file:com.bluexml.xforms.controller.alfresco.AlfrescoController.java

/**
 * Loads the properties files and passes them to the appropriate processor
 * for parsing.//from   w w w  .j  a  v  a 2s.  co  m
 * 
 * @return true if both files have been loaded. If any of the files was
 *         found neither at the
 *         specified location or at the default location, returns false. If
 *         true, the files may
 *         have been loaded from default locations instead of the given
 *         paths.
 */
public static boolean loadProperties(String formsFilePath, String messagesFilePath) {

    //
    // forms.properties
    boolean resForms;
    if (StringUtils.trimToNull(formsFilePath) != null) { // we may be setting a new path
        try {
            File theFile = new File(formsFilePath);
            InputStream stream = new FileInputStream(theFile);
            resForms = loadPropertiesFormsFromStream(stream);
            // keep the path so that a subsequent reload does not require re-giving the path
            formsPropertiesPath = formsFilePath;
        } catch (Exception e) {
            if (logger.isWarnEnabled()) {
                logger.warn("Configuration file 'forms.properties' not found at '" + formsFilePath
                        + "'. Will use defaults.", e);
            }
            resForms = loadPropertiesFormsDefault();
        }
    } else if (StringUtils.trimToNull(formsPropertiesPath) != null) { // reusing previous path
        try {
            File theFile = new File(formsPropertiesPath);
            InputStream stream = new FileInputStream(theFile);
            resForms = loadPropertiesFormsFromStream(stream);
        } catch (Exception e) {
            if (logger.isWarnEnabled()) {
                logger.warn("Configuration file 'forms.properties' not found at last location "
                        + formsPropertiesPath, e);
            }
            resForms = loadPropertiesFormsDefault();
        }
    } else {
        resForms = loadPropertiesFormsDefault();
    }
    if (resForms == false) {
        return false;
    }

    // messages.properties
    InputStream streamMsgs;
    if (StringUtils.trimToNull(messagesFilePath) != null) {
        try {
            File theFile = new File(messagesFilePath);
            streamMsgs = new FileInputStream(theFile);
            messagesPropertiesPath = messagesFilePath;
        } catch (Exception e) {
            if (logger.isWarnEnabled()) {
                logger.warn("Configuration file 'messages.properties' not found at '" + messagesFilePath
                        + "'. Will use defaults.", e);
            }
            streamMsgs = loadPropertiesMessagesDefaults();
        }
    } else if (StringUtils.trimToNull(messagesPropertiesPath) != null) {
        try {
            File theFile = new File(messagesPropertiesPath);
            streamMsgs = new FileInputStream(theFile);
        } catch (Exception e) {
            if (logger.isWarnEnabled()) {
                logger.error("Configuration file 'messages.properties' not found at last location "
                        + messagesPropertiesPath, e);
            }
            streamMsgs = loadPropertiesMessagesDefaults();
        }
    } else {
        streamMsgs = loadPropertiesMessagesDefaults();
    }

    if (streamMsgs == null) {
        return false;
    }
    MsgPool.setInputStream(streamMsgs);
    return true;
}

From source file:gov.nih.nci.caarray.util.owlparser.AbstractOntologyOwlParser.java

private void handleOntologyDescription(Element ontologyElement) throws ParseException {
    termSource = new TermSource();
    termSource.setName(name);//from w  w  w . java2 s. c o  m
    termSource.setUrl(url);
    Element versionElement = ontologyElement.element(getVersionInfoElementName());
    if (versionElement != null) {
        termSource.setVersion(StringUtils.trimToNull(versionElement.getText()));
    }
    processTermSource(termSource);
}

From source file:com.bluexml.xforms.generator.mapping.MappingGenerator.java

/**
 * As attribute type./*w  w  w .j  av a2 s  .co  m*/
 * 
 * @param classe
 *            the classe
 * @param attribute
 *            the attribute
 * @return the attribute type
 */
private AttributeType processAttribute(AbstractClass classe, Attribute attribute) {
    String result;

    AttributeType attributeType = objectFactory.createAttributeType();
    attributeType.setName(attribute.getName());
    attributeType.setAlfrescoName(getAlfrescoNameForAttribute(classe, attribute));
    attributeType.setType(attribute.getTyp().getLiteral());

    if (classe instanceof Clazz) {
        attributeType.setClassType(copyClassType(getClassType((Clazz) classe)));
    } else if (classe instanceof Aspect) {
        attributeType.setAspectType(copyAspectType(getAspectType((Aspect) classe)));
    }

    if (attribute.getValueList() != null) {
        attributeType.setEnumQName(ModelTools.getCompleteName(attribute.getValueList()));
    }

    //
    // properties stored as attributes if different from the default
    result = ModelTools.getMetaInfoValue(attribute, "multiple");
    if (result != null) {
        if (StringUtils.equalsIgnoreCase(result, "true")) {
            attributeType.setMultiple(true);
        }
    }

    boolean isDisabled = false;
    result = ModelTools.getMetaInfoValue(attribute, "read-only");
    if (result != null) {
        isDisabled = (StringUtils.equalsIgnoreCase(result, "true"));
        attributeType.setReadOnly(isDisabled);
    }

    String initialValue = attribute.getInitialValue();
    if (StringUtils.trimToNull(initialValue) != null) {
        attributeType.setDefault(initialValue);
    }

    String fieldSize = ModelTools.getMetaInfoValue(attribute, "size");
    if ((fieldSize != null) && (!fieldSize.equals("0"))) {
        attributeType.setFieldSize(fieldSize);
    }

    return attributeType;
}

From source file:fsl.ta.toms.roms.dao.impl.RoadCompliancyDAOImpl.java

/*************************************************************************************************************/

@SuppressWarnings("unchecked")
@Override//from  w w  w. j a v  a 2 s. c o  m
public List<VehicleDO> findVehiclesByCriteria(VehicleCriteriaBO criteria) {
    StringBuffer queryString = new StringBuffer();

    queryString.append(" from VehicleDO v where 1=1 ");

    //Vehicle ID
    if (StringUtils.trimToNull(criteria.getVehicleId()) != null) {
        queryString.append(" and upper(v.vehicleId) = '").append(criteria.getVehicleId().toUpperCase())
                .append("'");
    }

    //Plate Reg No
    if (StringUtils.trimToNull(criteria.getPlateRegNo()) != null) {
        queryString.append(" and upper(v.plateRegNo) = '").append(criteria.getPlateRegNo().toUpperCase())
                .append("'");
    }

    //Engine Num
    if (StringUtils.trimToNull(criteria.getEngineNo()) != null) {
        queryString.append(" and upper(v.engineNo) = '").append(criteria.getEngineNo().toUpperCase())
                .append("'");
    }

    //Chassis Num
    if (StringUtils.trimToNull(criteria.getChassisNo()) != null) {
        queryString.append(" and upper(v.chassisNo) = '").append(criteria.getChassisNo().toUpperCase())
                .append("'");
    }

    //Colour
    if (StringUtils.trimToNull(criteria.getColour()) != null) {
        queryString.append(" and upper(v.colour) = '").append(criteria.getColour().toUpperCase()).append("'");
    }

    //Year
    if (criteria.getYear() != null) {
        queryString.append(" and v.year = ").append(criteria.getYear());
    }

    return hibernateTemplate.find(queryString.toString());

}

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

/**
 * Sets related base uri if input is not empty string.
 *
 * @param relatedConceptBaseURI//from  ww  w  .  j  a v  a  2s.c  o  m
 *            base uri
 */
public void setRelatedConceptBaseURI(String relatedConceptBaseURI) {
    this.relatedConceptBaseURI = StringUtils.trimToNull(relatedConceptBaseURI);
    if (StringUtils.isNotBlank(this.relatedConceptBaseURI)
            && !StringUtils.endsWith(this.relatedConceptBaseURI, "/")
            && !StringUtils.endsWith(this.relatedConceptBaseURI, ":")
            && !StringUtils.endsWith(this.relatedConceptBaseURI, "#")) {
        this.relatedConceptBaseURI += "/";
    }
}

From source file:mp.platform.cyclone.webservices.CyclosWebServicesClientFactory.java

/**
 * Sets the server root url/*  w w  w . j av a2s .c om*/
 */
public void setServerRootUrl(final String serverRootUrl) {
    this.serverRootUrl = StringUtils.trimToNull(serverRootUrl);
    // Remove the trailing slash, if any
    if (this.serverRootUrl != null && this.serverRootUrl.endsWith("/")) {
        this.serverRootUrl = this.serverRootUrl.substring(0, this.serverRootUrl.length() - 1);
    }
    invalidateCache();
}