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:com.my.diff.MyDKCSVFileSource.java

/**
 * skips blank lines//from   www  . j  a  v  a2s.  c  o  m
 * 
 * @return null only when EOF is reached
 */
private String readLine() throws IOException {
    while (true) {
        String line = null;//lineReader.readNext();
        if (line == null)
            return null;
        line = StringUtils.trimToNull(line);
        if (line != null)
            return line;
    }
}

From source file:gov.nih.nci.firebird.web.action.sponsor.protocol.AbstractModifyProtocolAction.java

@Override
public void prepare() {
    super.prepare();
    if (getId(getProtocol()) == null) {
        setProtocol(getProtocolService().create());
    }//  ww w.  ja va2s . c  o  m
    setSponsor(lookupSponsor());
    configureLeadOrganizationMappings();
    agentList = StringUtils.trimToNull(getProtocol().getAgentListForDisplay());
}

From source file:com.redhat.rhn.frontend.action.kickstart.PowerManagementAction.java

/**
 * Returns a CobblerPowerSettingsUpdateCommand from form data.
 * With SSM empty form data means - do not change the value.
 * @param form the form//w  w w.j a v a2 s  . c  o  m
 * @param user currently logged in user
 * @param server server to update
 * @return the command
 */
public static CobblerPowerSettingsUpdateCommand getPowerSettingsUpdateCommandSSM(DynaActionForm form, User user,
        Server server) {
    return new CobblerPowerSettingsUpdateCommand(user, server, form.getString(POWER_TYPE),
            StringUtils.trimToNull(form.getString(POWER_ADDRESS)),
            StringUtils.trimToNull(form.getString(POWER_USERNAME)),
            StringUtils.trimToNull(form.getString(POWER_PASSWORD)),
            StringUtils.trimToNull(form.getString(POWER_ID)));
}

From source file:de.willuhn.jameica.hbci.gui.dialogs.CSVProfileStoreDialog.java

/**
 * Aktualisiert die UI nach Zeicheneingabe
 *///  www.j  a  va  2  s  .c  o  m
private void updateUI() {
    // Apply-Button deaktivieren, wenn nichts drin steht.
    final String text = StringUtils.trimToNull((String) name.getValue());
    getApply().setEnabled(text != null);

    // Hier brauchen wir nichts weiter checken
    if (text == null)
        return;

    getHint().setValue("");

    boolean found = false;
    boolean system = false;

    // Jetzt noch checken, ob wir ein existierendes Profil ueberschreiben und einen Warnhinweis anzeigen
    // Ausserdem einen Hinweis, wenn der User versucht, das System-Profil zu ueberschreiben
    for (Profile p : this.profiles) {
        if (p.getName().equals(text)) {
            found = true;
            system = p.isSystem();
        }
    }

    if (!found) {
        getHint().setColor(Color.SUCCESS);
        getHint().setValue(i18n.tr("Ein neues Profil wird angelegt."));
    }

    if (found && !system) {
        getHint().setColor(Color.LINK);
        getHint().setValue(i18n.tr("Existierendes Profil wird berschrieben."));
    }

    if (system) {
        getHint().setColor(Color.ERROR);
        getHint().setValue(i18n.tr("Das Default-Profil darf nicht berschrieben werden."));
        getApply().setEnabled(false);
    }
}

From source file:mitm.application.djigzo.impl.DLPPropertiesImpl.java

private String getDefaultQuarantineURL() throws HierarchicalPropertiesException {
    String defaultURL = StringUtils.trimToNull(portalProperties.getBaseURL());

    if (defaultURL != null) {
        defaultURL = MiscStringUtils.ensureEndsWith(defaultURL, "/") + DEFAULT_RELATIVE_QUARANTINE_URL;
    }/*  ww w .jav  a 2  s.  c om*/

    return defaultURL;
}

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

@PUT
@Consumes(MediaType.APPLICATION_FORM_URLENCODED)
@Produces(MediaType.TEXT_HTML)//  w  w w .j a  va2s.c om
public Response putHTML(@FormParam("name") String name, @FormParam("fullname") String fullName,
        @FormParam("classification") String 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);
    RegionClassification regionClassification = safeValueOf(RegionClassification.class, classification);
    if (name == null || regionClassification == null) {
        FlexiBean out = createRootData();
        if (name == null) {
            out.put("err_nameMissing", true);
        }
        if (regionClassification == null) {
            out.put("err_classificationMissing", true);
        }
        String html = getFreemarker().build(HTML_DIR + "region-update.ftl", out);
        return Response.ok(html).build();
    }
    if (fullName == null) {
        fullName = name;
    }
    URI uri = updateRegion(name, fullName, regionClassification, countryISO, currencyISO, timeZoneId);
    return Response.seeOther(uri).build();
}

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

/**
 * @param adt/*ww  w. ja v a  2  s.  c  o  m*/
 * @return
 * @throws HL7Exception
 */
protected static String extractReason(final ADT_A01 adt) {

    String ret = null;

    final CE complaint = adt.getPV2().getAdmitReason();
    final StrBuilder reasonBuf = new StrBuilder();

    final String complaintId = StringUtils.trimToNull(complaint.getIdentifier().getValue());
    final String complaintText = StringUtils.trimToNull(complaint.getText().getValue());
    if (complaintId != null && isValidComplaint(complaintId)) {
        reasonBuf.append(complaintId);
    }
    if (complaintText != null && isValidComplaint(complaintText)) {
        if (reasonBuf.length() > 0) {
            reasonBuf.append(" ");
        }
        reasonBuf.append(complaintText);
    }
    ret = StringUtils.trimToNull(reasonBuf.toString());

    return ret;
}

From source file:com.opengamma.web.config.WebConfigsResource.java

@POST
@Consumes(MediaType.APPLICATION_FORM_URLENCODED)
@Produces(MediaType.APPLICATION_JSON)//from   w ww. j a va2  s  . c  o  m
public Response postJSON(@FormParam("name") String name, @FormParam("configJSON") String json,
        @FormParam("configXML") String xml, @FormParam("type") String typeName) {
    name = StringUtils.trimToNull(name);
    json = StringUtils.trimToNull(json);
    xml = StringUtils.trimToNull(xml);
    typeName = StringUtils.trimToNull(typeName);

    final Class<?> type = (typeName != null ? data().getTypeMap().get(typeName) : null);
    Response result = null;
    if (name == null || type == null || isEmptyConfigData(json, xml)) {
        result = Response.status(Status.BAD_REQUEST).build();
    } else {
        Object configObj = null;
        if (json != null) {
            configObj = parseJSON(json);
        } else if (xml != null) {
            configObj = parseXML(xml, type);
        }
        if (configObj == null) {
            result = Response.status(Status.BAD_REQUEST).build();
        } else {
            ConfigItem<?> item = ConfigItem.of(configObj);
            item.setName(name);
            item.setType(type);
            ConfigDocument doc = new ConfigDocument(item);
            ConfigDocument added = data().getConfigMaster().add(doc);
            URI uri = data().getUriInfo().getAbsolutePathBuilder()
                    .path(added.getUniqueId().toLatest().toString()).build();
            result = Response.created(uri).build();
        }
    }
    return result;
}

From source file:com.bluexml.side.clazz.service.alfresco.CommonServices.java

public static Object getFirstMetainfoValue(ModelElement element, String key, String defaultValue) {
    MetaInfo firstMetainfo = getFirstMetainfo(element, key);
    if (firstMetainfo != null) {
        String multilineValue = StringUtils.trimToNull(firstMetainfo.getMultilineValue());
        String value = StringUtils.trimToNull(firstMetainfo.getValue());
        EList<EObject> eObjectValue = firstMetainfo.getEObjectValue();
        if (multilineValue != null) {
            return multilineValue;
        } else if (value != null) {
            return value;
        } else if (eObjectValue != null && eObjectValue.size() > 0) {
            return eObjectValue;
        }//  w  w w .j  av  a  2 s  .  c  o  m
    }
    return defaultValue;
}

From source file:com.eyeq.pivot4j.query.QueryAdapter.java

/**
 * @param exp/*from   w  w  w. j a v a 2s  . c om*/
 * @param evaluator
 */
protected void evaluate(ExpressionParameter exp, ExpressionEvaluator evaluator) {
    String expression = StringUtils.trimToNull(exp.getExpression());

    if (expression == null) {
        exp.setResult("");
    } else {
        Object result = evaluator.evaluate("${" + exp.getExpression() + "}", model.getExpressionContext());

        exp.setResult(ObjectUtils.toString(result));
    }
}