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

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

Introduction

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

Prototype

public static String trimToEmpty(final String str) 

Source Link

Document

Removes control characters (char <= 32) from both ends of this String returning an empty String ("") if the String is empty ("") after the trim or if it is null .

Usage

From source file:com.neatresults.mgnltweaks.ui.action.SaveFieldFormAction.java

private void setProperty(Node node, String propertyName, AbstractJcrNodeAdapter nodeAdapter)
        throws RepositoryException {
    com.vaadin.data.Property prop = nodeAdapter.getItemProperty(propertyName);
    if (prop == null || prop.getValue() == null) {
        // someone didn't set the property
        return;//from   www. j a  v a 2s  .c  om
    }
    Object val = prop.getValue();

    if (val instanceof String) {
        node.setProperty(propertyName, StringUtils.trimToEmpty(((String) prop.getValue())));
    } else if (val instanceof Boolean) {
        node.setProperty(propertyName, ((Boolean) val).toString());
    } else {
        node.setProperty(propertyName, prop.getValue().toString());
    }
}

From source file:ke.co.tawi.babblesms.server.beans.account.Account.java

/**
 * @param apiUsername the apiUsername to set
 *///from  w ww  .ja  v a  2s .  c  o  m
public void setApiUsername(String apiUsername) {
    this.apiUsername = StringUtils.trimToEmpty(apiUsername);
}

From source file:com.threewks.thundr.http.URLEncoder.java

/**
 * Decodes the given query parameter string into key value pairs.
 * //w ww .j  a  v a  2 s.c o  m
 * If the given string begins with '?', it will be stripped off. Pairs are decoded before being returned.
 * 
 * @param query
 * @return
 */
public static Map<String, List<String>> decodeQueryString(String query) {
    query = StringUtils.trimToEmpty(query);
    query = StringUtils.removeStart(query, "?");
    Map<String, List<String>> results = new LinkedHashMap<>();
    if (StringUtils.isNotBlank(query)) {
        for (String pair : query.split("&")) {
            String[] parts = StringUtils.split(pair, "=", 2);
            String key = unescape(parts[0]);
            String value = parts.length > 1 ? unescape(parts[1]) : null;
            List<String> existing = results.get(key);
            if (existing == null) {
                existing = new ArrayList<>();
                results.put(key, existing);
            }
            existing.add(value);
        }
    }
    return results;
}

From source file:com.omertron.themoviedbapi.model.PersonCredit.java

public void setAdult(String adult) {
    this.adult = StringUtils.trimToEmpty(adult);
}

From source file:com.xpn.xwiki.plugin.svg.SVGMacro.java

/**
 * Main macro execution method, replaces the macro instance with the generated output.
 * //  ww  w .j  av a  2  s . co m
 * @param writer the place where to write the output
 * @param params the parameters this macro is called with
 * @throws IllegalArgumentException if the mandatory argument ({@code text}) is missing
 * @throws IOException if the output cannot be written
 * @see org.radeox.macro.BaseMacro#execute(Writer, MacroParameter)
 */
@Override
public void execute(Writer writer, MacroParameter params) throws IllegalArgumentException, IOException {
    RenderContext context = params.getContext();
    RenderEngine engine = context.getRenderEngine();

    XWikiContext xcontext = ((XWikiRadeoxRenderEngine) engine).getXWikiContext();
    XWiki xwiki = xcontext.getWiki();

    SVGPlugin plugin = (SVGPlugin) xwiki.getPlugin("svg", xcontext);
    // If the SVG plugin is not loaded, exit.
    if (plugin == null) {
        writer.write("Plugin not loaded");
        return;
    }
    // {svg:alternate text|height|width}
    StringBuffer str = new StringBuffer();
    String text = params.get("text", 0);
    String height = params.get("height", 1);
    if (StringUtils.isBlank(height) || "none".equals(height) || !StringUtils.isNumeric(height.trim())) {
        height = "400";
    }
    String width = params.get("width", 2);
    if (StringUtils.isBlank(width) || "none".equals(width) || !StringUtils.isNumeric(width.trim())) {
        width = "400";
    }
    try {
        int intHeight = Integer.parseInt(height.trim());
        int intWidth = Integer.parseInt(width.trim());
        String svgtext = StringUtils.trimToEmpty(params.getContent());
        str.append("<img src=\"");
        // The SVG plugin generates the image and returns an URL for accessing it.
        str.append(plugin.getSVGImageURL(svgtext, intHeight, intWidth, xcontext));
        str.append("\" ");
        str.append("height=\"" + height + "\" ");
        str.append("width=\"" + width + "\" ");
        str.append("alt=\"");
        str.append(text);
        str.append("\" />");
        writer.write(str.toString());
    } catch (Throwable t) {
        XWikiException e = new XWikiException(XWikiException.MODULE_XWIKI_PLUGINS,
                XWikiException.ERROR_XWIKI_UNKNOWN, "SVG Issue", t);
        writer.write("Exception converting SVG: " + e.getFullMessage());
    }
}

From source file:com.qq.tars.service.template.TemplateService.java

public List<ProfileTemplate> queryTemplate(String templateName, String parentsName) {
    templateName = StringUtils.trimToEmpty(templateName);
    parentsName = StringUtils.trimToEmpty(parentsName);
    return templateMapper.queryTemplate(templateName, parentsName);
}

From source file:com.omertron.themoviedbapi.methods.TmdbLists.java

/**
 * This method lets users create a new list. A valid session id is required.
 *
 * @param sessionId//from ww  w.j av a  2  s  .c  o m
 * @param name
 * @param description
 * @return The list id
 * @throws MovieDbException
 */
public String createList(String sessionId, String name, String description) throws MovieDbException {
    TmdbParameters parameters = new TmdbParameters();
    parameters.add(Param.SESSION_ID, sessionId);

    String jsonBody = new PostTools().add(PostBody.NAME, StringUtils.trimToEmpty(name))
            .add(PostBody.DESCRIPTION, StringUtils.trimToEmpty(description)).build();

    URL url = new ApiUrl(apiKey, MethodBase.LIST).buildUrl(parameters);
    String webpage = httpTools.postRequest(url, jsonBody);

    try {
        return MAPPER.readValue(webpage, ListStatusCode.class).getListId();
    } catch (IOException ex) {
        throw new MovieDbException(ApiExceptionType.MAPPING_FAILED, "Failed to create list", url, ex);
    }
}

From source file:com.chessix.vas.service.ClasService.java

String getClasId(final String clasId) {
    return StringUtils.lowerCase(StringUtils.trimToEmpty(clasId));
}

From source file:gov.nih.nci.caintegrator.web.action.study.management.CopyStudyAction.java

private void doValidateCopy(StudyConfiguration original) {
    setStudyConfiguration(new StudyConfiguration());
    String name = "Copy of ".concat(StringUtils.trimToEmpty(original.getStudy().getShortTitleText()));
    getStudyConfiguration().getStudy().setShortTitleText(name);
    if (!StringUtils.trimToEmpty(original.getStudy().getLongTitleText()).isEmpty()) {
        getStudyConfiguration().getStudy().setLongTitleText(
                "Copy of ".concat(StringUtils.trimToEmpty(original.getStudy().getLongTitleText())));
    }//from w  w w.  j  av a 2s  .co  m
    getStudyConfiguration().getStudy().setPubliclyAccessible(original.getStudy().isPubliclyAccessible());
    validate();
}

From source file:com.nesscomputing.syslog4j.impl.unix.socket.UnixSocketSyslogConfig.java

public void setFamily(String family) {
    if (family == null) {
        throw new SyslogRuntimeException("Family cannot be null for class \"%s\"", this.getClass().getName());
    }/*w  w w  .j  av a 2s  . c  o m*/

    if ("AF_UNIX".equalsIgnoreCase(StringUtils.trimToEmpty(family))) {
        this.family = SyslogConstants.AF_UNIX;

    } else {
        throw new SyslogRuntimeException("Family must be \"AF_UNIX\" for class \"%s\"",
                this.getClass().getName());
    }
}