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

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

Introduction

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

Prototype

public static String trimToNull(final 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:org.gbif.ipt.action.manage.TranslationAction.java

@Override
public void prepare() {
    super.prepare();
    notFound = true;//  w  ww . ja va  2s .  c o m

    try {
        // get mapping sequence id from parameters as setters are not called yet
        String midStr = StringUtils.trimToNull(req.getParameter(REQ_PARAM_MAPPINGID));
        if (midStr != null) {
            mid = Integer.valueOf(midStr);
            mapping = resource.getMapping(req.getParameter(REQ_PARAM_ROWTYPE), mid);
        }
    } catch (Exception e) {
        LOG.error("An exception was encountered: " + e.getMessage(), e);
    }
    if (mapping != null) {
        field = mapping.getField(req.getParameter(REQ_PARAM_TERM));
        if (field != null) {
            notFound = false;
            property = mapping.getExtension().getProperty(field.getTerm());
            if (property.getVocabulary() != null) {
                vocabTerms = vocabManager.getI18nVocab(property.getVocabulary().getUriString(),
                        getLocaleLanguage(), true);
            }
            if (!trans.isLoaded(mapping.getExtension().getRowType(), field.getTerm())) {
                reloadSourceValues();
            }
        }
    }
}

From source file:org.gbif.ipt.action.manage.TranslationAction.java

/**
 * Clears the existing translation, reloads the source values, and repopulates existing translations.
 * The key of each entry in the translation.sourceValues map, e.g. {{"k1", "obs"}, {"k2", "spe"}} corresponds to each
 * entry in the translation.translatedValues map, e.g. {{"k1", "Observation"}, {"k2", "Specimen"}}.
 *//*from w w  w. j  a v a 2 s .  c o  m*/
void reloadSourceValues() {
    try {
        String midStr = StringUtils.trimToNull(req.getParameter(REQ_PARAM_MAPPINGID));
        if (midStr != null) {
            mid = Integer.valueOf(midStr);
            mapping = resource.getMapping(req.getParameter(REQ_PARAM_ROWTYPE), mid);
        }
        // reinitialize translation, including maps
        trans.setTmap(this.mapping.getExtension().getRowType(), property, new TreeMap<String, String>(),
                new TreeMap<String, String>());
        // reload new values
        int i = 1;
        for (String val : sourceManager.inspectColumn(mapping.getSource(), field.getIndex(), 1000, 10000)) {
            StringBuilder key = new StringBuilder();
            key.append('k');
            key.append(i);
            getSourceValuesMap().put(key.toString(), val);
            i++;
        }
        // keep existing translations
        if (field.getTranslation() != null) {
            for (Entry<String, String> entry : field.getTranslation().entrySet()) {
                // only keep entries with values mapped that exist in the newly reloaded map
                if (entry.getValue() != null && getSourceValuesMap().containsValue(entry.getKey())) {
                    for (Entry<String, String> sourceValueEntry : getSourceValuesMap().entrySet()) {
                        if (sourceValueEntry.getValue().equals(entry.getKey())) {
                            getTmap().put(sourceValueEntry.getKey(), entry.getValue());
                        }
                    }
                }
            }
        }
        // bring it to user's attention, that the source values have been reloaded
        addActionMessage(getText("manage.translation.reloaded.values",
                new String[] { String.valueOf(getSourceValuesMap().size()), field.getTerm().toString() }));

    } catch (SourceException e) {
        // if an error has occurred, bring it to the user's attention
        addActionError(getText("manage.translation.reloaded.fail",
                new String[] { field.getTerm().toString(), e.getMessage() }));
    }
}

From source file:org.gbif.ipt.model.AgentBase.java

/**
 * @param homepageURL the homepageURL to set
 *//*from   w  w w . ja v  a2 s.  c  o  m*/
public void setHomepageURL(@Nullable String homepageURL) {
    this.homepageURL = StringUtils.trimToNull(homepageURL);
}

From source file:org.gbif.ipt.model.AgentBase.java

/**
 * @param name the name to set
 */
public void setName(@NotNull String name) {
    this.name = StringUtils.trimToNull(name);
}

From source file:org.gbif.ipt.model.AgentBase.java

/**
 * @param primaryContactAddress the primaryContactAddress to set
 *//*w w w.  j  av  a2  s  . c  o  m*/
public void setPrimaryContactAddress(@Nullable String primaryContactAddress) {
    this.primaryContactAddress = StringUtils.trimToNull(primaryContactAddress);
}

From source file:org.gbif.ipt.model.AgentBase.java

/**
 * @param primaryContactDescription the primaryContactDescription to set
 *//*from  w  w w . j  a  v  a  2 s  .  c  o  m*/
public void setPrimaryContactDescription(@Nullable String primaryContactDescription) {
    this.primaryContactDescription = StringUtils.trimToNull(primaryContactDescription);
}

From source file:org.gbif.ipt.model.AgentBase.java

/**
 * @param primaryContactEmail the primaryContactEmail to set
 *///  w w w.  j a va2s .co  m
public void setPrimaryContactEmail(@Nullable String primaryContactEmail) {
    this.primaryContactEmail = StringUtils.trimToNull(primaryContactEmail);
}

From source file:org.gbif.ipt.model.AgentBase.java

public void setPrimaryContactFirstName(@Nullable String primaryContactFirstName) {
    this.primaryContactFirstName = StringUtils.trimToNull(primaryContactFirstName);
}

From source file:org.gbif.ipt.model.AgentBase.java

public void setPrimaryContactLastName(@Nullable String primaryContactLastName) {
    this.primaryContactLastName = StringUtils.trimToNull(primaryContactLastName);
}

From source file:org.gbif.ipt.model.AgentBase.java

/**
 * @param primaryContactName the primaryContactName to set
 *///from w w w.  j ava2  s  .  c o m
public void setPrimaryContactName(@Nullable String primaryContactName) {
    this.primaryContactName = StringUtils.trimToNull(primaryContactName);
}