Example usage for org.apache.commons.lang StringUtils defaultIfBlank

List of usage examples for org.apache.commons.lang StringUtils defaultIfBlank

Introduction

In this page you can find the example usage for org.apache.commons.lang StringUtils defaultIfBlank.

Prototype

public static String defaultIfBlank(String str, String defaultStr) 

Source Link

Document

Returns either the passed in String, or if the String is whitespace, empty ("") or null, the value of defaultStr.

Usage

From source file:net.di2e.ecdr.commons.endpoint.rest.AbstractRestSearchEndpoint.java

protected QueryLanguage getQueryLanguage(MultivaluedMap<String, String> queryParams) {
    String lang = StringUtils.defaultIfBlank(queryParams.getFirst(SearchConstants.QUERYLANGUAGE_PARAMETER),
            queryConfiguration.getDefaultQueryLanguage());
    LOGGER.debug("Using query language that is associated with the name [{}]", lang);
    for (QueryLanguage queryLang : queryLanguageList) {
        if (StringUtils.equalsIgnoreCase(queryLang.getName(), lang)) {
            return queryLang;
        }/*from w w  w.j a v  a2  s  .c o  m*/
    }
    return null;
}

From source file:com.fortify.processrunner.RunProcessRunnerFromCLI.java

protected final void appendLogOptions(HelpPrinter hp) {
    hp.appendEmptyLn();/*from w  ww. j  av  a  2s. c o m*/
    hp.append(0, "Logging options:");
    hp.append(2,
            "Logging to file is disabled by default, but can be enabled using the -DlogLevel and -DlogFile options."
                    + " Note that contrary to all other options listed in the sections below, the logging options must be provided"
                    + " as Java options, i.e. they must appear before the -jar option.");
    hp.appendEmptyLn();
    hp.append(2, "-DlogLevel=<logLevel>");
    hp.append(4, "Specify the log level");
    hp.keyValueGroupBuilder().append("Default value", "DEBUG if -DlogFile is specified, OFF otherwise")
            .append("Current value", StringUtils.defaultIfBlank(LOG_LEVEL, "<none>"))
            .append("Allowed values", ImmutableMap.<String, String>builder().put("TRACE",
                    "Detailed log information; may result in large log files containing sensitive information")
                    .put("DEBUG",
                            "Debug information; may result in large log files containing sensitive information")
                    .put("INFO", "Log informational messages")
                    .put("WARN", "Log only warning, error or fatal messages")
                    .put("ERROR", "Log only error or fatal messages").put("FATAL", "Log only fatal messages")
                    .put("OFF", "Don't log to file").build())
            .append("Allowed sources", "Java option").build(4);
    hp.appendEmptyLn();
    hp.append(2, "-DlogFile=<logFile>");
    hp.append(4, "Specify the log file)");
    hp.keyValueGroupBuilder().append("Default value", getDefaultLogFileName())
            .append("Current value", StringUtils.defaultIfBlank(LOG_FILE, "<none>"))
            .append("Allowed sources", "Java option").build(4);
}

From source file:jenkins.plugins.git.GitSCMBuilder.java

/**
 * Configures the remote name to use for the git repository.
 *
 * @param remoteName the remote name to use for the git repository ({@code null} or the empty string are
 *                   equivalent to passing {@link AbstractGitSCMSource#DEFAULT_REMOTE_NAME}).
 * @return {@code this} for method chaining.
 *///from   ww w  .  j  a  v  a2  s .  co  m
@SuppressWarnings("unchecked")
@NonNull
public final B withRemoteName(@CheckForNull String remoteName) {
    this.remoteName = StringUtils.defaultIfBlank(remoteName, AbstractGitSCMSource.DEFAULT_REMOTE_NAME);
    return (B) this;
}

From source file:eu.europeana.portal2.web.presentation.model.FullDocPage.java

public String getThumbnailUrl() throws UnsupportedEncodingException {
    String thumbnail = "";
    if (shortcut.get("EdmObject") != null && shortcut.get("EdmObject").length > 0) {
        thumbnail = StringUtils.defaultIfBlank(shortcut.get("EdmObject")[0], "").trim();
    }/*  w  w w  .jav a  2s .  co  m*/
    return createImageUrl(thumbnail, getDocument().getEdmType(), "FULL_DOC");
}

From source file:eu.europeana.portal2.web.presentation.model.FullDocPage.java

public String getThumbnailUrlUnescaped() throws UnsupportedEncodingException {
    String thumbnail = "";
    if (shortcut.get("EdmObject") != null && shortcut.get("EdmObject").length > 0) {
        thumbnail = StringUtils.defaultIfBlank(shortcut.get("EdmObject")[0], "").trim();
    }//from w  ww.j  a v  a2 s  . co m
    return createImageUrl(thumbnail, getDocument().getEdmType(), "FULL_DOC");
}

From source file:com.fortify.processrunner.RunProcessRunnerFromCLI.java

/**
 * Get the base command for running this utility
 * @return/*from  ww  w  . ja  va2 s .  c o  m*/
 */
protected String getBaseCommand() {
    return "java [-DlogLevel=<logLevel>] [-DlogFile=<logFile>] -jar "
            + StringUtils.defaultIfBlank(getJarName(), "<jar name>");
}

From source file:adalid.util.meta.sql.MetaPlatformSql.java

private void readFile(WriterContext templateWriterContext, TemplateBean templateBean) {
    File templatePropertiesFile = templateBean.getPropertiesFile();
    VelocityContext fileContext = templateWriterContext.getVelocityContextClone();
    Properties properties = mergeProperties(fileContext, templatePropertiesFile);
    putStrings(fileContext, properties);
    String userPath = pathString(USER_DIR);
    String temptype = StringUtils.defaultIfBlank(properties.getProperty(TP_TYPE), TP_TYPE_VELOCITY);
    String template = StringUtils.trimToNull(properties.getProperty(TP_TEMPLATE));
    String filePath = StringUtils.trimToNull(properties.getProperty(TP_PATH));
    String filePack = StringUtils.trimToNull(properties.getProperty(TP_PACKAGE));
    String fileName = StringUtils.trimToNull(properties.getProperty(TP_FILE));
    String preserve = StringUtils.trimToNull(properties.getProperty(TP_PRESERVE));
    String charset1 = StringUtils.trimToNull(properties.getProperty(TP_ENCODING));
    String charset2 = StringUtils.trimToNull(properties.getProperty(TP_CHARSET));
    String disabled = properties.getProperty(TP_DISABLED, Boolean.FALSE.toString());
    String disabledMissing = properties.getProperty(TP_DISABLED_MISSING);
    String executeCommand = StringUtils.trimToNull(properties.getProperty(TP_EXECUTE_COMMAND));
    String executeDirectory = StringUtils.trimToNull(properties.getProperty(TP_EXECUTE_DIRECTORY));
    String forEach = StringUtils.trimToNull(properties.getProperty(TP_FOR_EACH));
    String hint = ", check property \"{0}\" at file \"{1}\"";
    if (ArrayUtils.contains(TP_TYPE_ARRAY, temptype)) {
    } else {/*from   w  w  w .j  ava2 s . c  o  m*/
        String pattern = "failed to obtain a valid template type" + hint;
        String message = MessageFormat.format(pattern, TP_TYPE, templatePropertiesFile);
        logger.error(message);
        errors++;
        return;
    }
    if (template == null) {
        String pattern = "failed to obtain a valid template name" + hint;
        String message = MessageFormat.format(pattern, TP_TEMPLATE, templatePropertiesFile);
        logger.error(message);
        errors++;
        return;
    }
    if (fileName == null) {
        String pattern = "failed to obtain a valid file name" + hint;
        String message = MessageFormat.format(pattern, TP_FILE, templatePropertiesFile);
        logger.error(message);
        errors++;
        return;
    }
    String templatePathString = pathString(template);
    String templatePath = StringUtils.substringBeforeLast(templatePathString, FILE_SEPARATOR);
    fileContext.put(VC_TEMPLATE, StringEscapeUtils.escapeJava(templatePathString));
    fileContext.put(VC_TEMPLATE_PATH, StringUtils.replace(templatePath, FILE_SEPARATOR, "/"));
    fileContext.put(VC_FILE, fileName);
    if (filePath == null) {
        filePath = userPath;
    } else {
        filePath = pathString(filePath);
        if (isRelativePath(filePath)) {
            if (filePath.startsWith(FILE_SEPARATOR)) {
                filePath = userPath + filePath;
            } else {
                filePath = userPath + FILE_SEPARATOR + filePath;
            }
        }
    }
    fileContext.put(VC_PATH, StringEscapeUtils.escapeJava(filePath));
    if (filePack != null) {
        filePath += FILE_SEPARATOR + pathString(StringUtils.replace(filePack, ".", "/"));
        fileContext.put(VC_PACKAGE, dottedString(filePack));
    }
    File path = new File(filePath);
    String fullname = path.getPath() + FILE_SEPARATOR + fileName;
    fileContext.put(VC_FILE_PATH, StringEscapeUtils.escapeJava(filePath));
    fileContext.put(VC_FILE_NAME, StringEscapeUtils.escapeJava(fileName));
    fileContext.put(VC_FILE_PATH_NAME, StringEscapeUtils.escapeJava(fullname));
    fileContext.put(VC_FILE_PATH_FILE, path);
    /**/
    templateBean.setPath(templatePathString);
    templateBean.setType(temptype);
    templateBean.setEncoding(charset1);
    templateBean.setForEach(forEach);
    templateBean.setTargetPath(filePath);
    templateBean.setTargetPackage(filePack);
    templateBean.setTargetFile(fileName);
    templateBean.setTargetFileEncoding(charset2);
    templateBean.setExecuteCommand(executeCommand);
    templateBean.setExecuteDirectory(executeDirectory);
    templateBean.setDisabled(BitUtils.valueOf(disabled));
    templateBean.setDisabledWhenMissing(BitUtils.valueOf(disabledMissing));
    templateBean.setPreserveExistingFile(BitUtils.valueOf(preserve));
    templateBean.setBytes(0);
    templateBean.setLines(0);
}

From source file:net.di2e.ecdr.commons.query.rest.parsers.BasicQueryParser.java

@Override
public String getGeoRSSFormat(MultivaluedMap<String, String> queryParameters) {
    return StringUtils.defaultIfBlank(queryParameters.getFirst(SearchConstants.GEORSS_RESULT_FORMAT_PARAMETER),
            null);/*from   w w  w  . j  a  v  a 2s .co  m*/
}

From source file:ips1ap101.lib.core.db.util.VistaFuncionWrapper.java

private String select(boolean distinct, List<String> columns, String from, String where, List<String> groupBy,
        List<String> orderBy) throws ExcepcionAplicacion {
    return "SELECT " + (distinct ? "DISTINCT " : "") + StringUtils.join(columns, ", ") + from
            + StringUtils.defaultIfBlank(where, "") + group(groupBy) + order(orderBy);
}

From source file:elaborate.editor.publish.PublishTask.java

Map<String, Object> getProjectData(Project project, List<EntryData> entries,
        Map<Long, List<String>> thumbnails) {
    Map<String, String> metadataMap = project.getMetadataMap();
    for (String key : ProjectMetadataFields.ANNOTATIONTYPE_FIELDS) {
        metadataMap.remove(key);/*w w  w.jav  a 2  s.  c om*/
    }
    Map<String, Object> map = Maps.newHashMap();
    map.put("id", project.getId());
    map.put("title", StringUtils.defaultIfBlank(metadataMap.remove(ProjectMetadataFields.PUBLICATION_TITLE),
            project.getTitle()));
    map.put("publicationDate", new DateTime().toString("yyyy-MM-dd HH:mm"));
    map.put("entries", entries);

    map.put("levels", ImmutableList.of(project.getLevel1(), project.getLevel2(), project.getLevel3()));
    List<String> publishableTextLayers = settings.getTextLayers();
    map.put("textLayers", publishableTextLayers.isEmpty() ? project.getTextLayers() : publishableTextLayers);

    map.put("thumbnails", thumbnails);
    // map.put("entryMetadataFields", project.getProjectEntryMetadataFieldnames());
    // map.put("baseURL", getBaseURL(getBasename(project)));
    map.put("baseURL", getBaseURL(project.getName()));
    map.put("annotationIndex", ANNOTATION_INDEX_JSON);
    map.put("multivaluedFacetIndex", calculateMultivaluedFacetIndex(entries));

    addIfNotNull(map, "textFont", metadataMap.remove(ProjectMetadataFields.TEXT_FONT));
    addIfNotNull(map, "entryTermSingular", metadataMap.remove(ProjectMetadataFields.ENTRYTERM_SINGULAR));
    addIfNotNull(map, "entryTermPlural", metadataMap.remove(ProjectMetadataFields.ENTRYTERM_PLURAL));
    map.put("metadata", metadataMap);

    // Map<String, String> settingsMap = ProjectService.instance().getProjectSettings(project.getId(), project.getModifier());
    // Map<String, Object> projectSettings = Maps.newHashMap();
    // projectSettings.putAll(settingsMap);
    // projectSettings.put("levels", ImmutableList.of(project.getLevel1(), project.getLevel2(), project.getLevel3()));
    //
    // List<String> publishableTextLayers = settings.getTextLayers();
    // projectSettings.put("textLayers", publishableTextLayers.isEmpty() ? project.getTextLayers() : publishableTextLayers);
    //
    // map.put("settings", projectSettings);
    return map;
}