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:org.biouno.unochoice.ChoiceParameter.java

/**
 * Constructor called from Jelly with parameters.
 *
 * @param name name//www .  j av  a 2s. com
 * @param description description
 * @param randomName parameter random generated name (uuid)
 * @param script script
 * @param choiceType choice type
 * @param filterable filter flag
 */
@DataBoundConstructor
public ChoiceParameter(String name, String description, String randomName, Script script, String choiceType,
        Boolean filterable) {
    super(name, description, randomName, script);
    this.choiceType = StringUtils.defaultIfBlank(choiceType, PARAMETER_TYPE_SINGLE_SELECT);
    this.filterable = filterable;
}

From source file:org.biouno.unochoice.DynamicReferenceParameter.java

/**
 * Constructor called from Jelly with parameters.
 *
 * @param name name/*from w  w  w.j ava2 s.co m*/
 * @param description description
 * @param script script
 * @param choiceType choice type
 * @param referencedParameters referenced parameters
 * @param omitValueField used in the UI to decide whether to include a hidden empty <input name=value>.
 * <code>false</code> by default.
 * @deprecated see JENKINS-32149
 */
public DynamicReferenceParameter(String name, String description, Script script, String choiceType,
        String referencedParameters, Boolean omitValueField) {
    super(name, description, script, referencedParameters);
    this.choiceType = StringUtils.defaultIfBlank(choiceType, PARAMETER_TYPE_SINGLE_SELECT);
    this.omitValueField = BooleanUtils.toBooleanDefaultIfNull(omitValueField, Boolean.FALSE);
}

From source file:org.biouno.unochoice.DynamicReferenceParameter.java

/**
 * Constructor called from Jelly with parameters.
 *
 * @param name name// w  ww . j  a v a2s  .com
 * @param description description
 * @param randomName parameter random generated name (uuid)
 * @param script script
 * @param choiceType choice type
 * @param referencedParameters referenced parameters
 * @param omitValueField used in the UI to decide whether to include a hidden empty &lt;input name=value&gt;.
 * <code>false</code> by default.
 */
@DataBoundConstructor
public DynamicReferenceParameter(String name, String description, String randomName, Script script,
        String choiceType, String referencedParameters, Boolean omitValueField) {
    super(name, description, randomName, script, referencedParameters);
    this.choiceType = StringUtils.defaultIfBlank(choiceType, PARAMETER_TYPE_SINGLE_SELECT);
    this.omitValueField = BooleanUtils.toBooleanDefaultIfNull(omitValueField, Boolean.FALSE);
}

From source file:org.cloudbees.literate.jenkins.promotions.PromotionConfiguration.java

@NonNull
public String getDisplayName() {
    return StringUtils.defaultIfBlank(displayName, name);
}

From source file:org.cloudbees.literate.jenkins.promotions.PromotionProject.java

@NonNull
public String getDisplayName() {
    return StringUtils.defaultIfBlank(getConfiguration().getDisplayName(), name);
}

From source file:org.codice.ddf.catalog.content.impl.FileSystemStorageProviderTest.java

public CreateStorageResponse assertContentItemWithQualifier(String data, String mimeTypeRawData,
        String filename, String id, String qualifier) throws Exception {
    // Simulates what ContentFrameworkImpl would do
    String uuid = StringUtils.defaultIfBlank(id, UUID.randomUUID().toString().replaceAll("-", ""));
    ByteSource byteSource = new ByteSource() {
        @Override// w ww . j a  va  2s . c  o  m
        public InputStream openStream() throws IOException {
            return IOUtils.toInputStream(data);
        }
    };
    ContentItem contentItem = new ContentItemImpl(uuid, qualifier, byteSource, mimeTypeRawData, filename,
            byteSource.size(), mock(Metacard.class));
    CreateStorageRequest createRequest = new CreateStorageRequestImpl(Collections.singletonList(contentItem),
            null);
    CreateStorageResponse createResponse = provider.create(createRequest);
    List<ContentItem> createdContentItems = createResponse.getCreatedContentItems();
    ContentItem createdContentItem = createdContentItems.get(0);

    assertNotNull(createdContentItem);
    String createdId = createdContentItem.getId();
    assertNotNull(createdId);
    assertThat(createdId, equalTo(uuid));

    String contentUri = createdContentItem.getUri();
    LOGGER.debug("contentUri = {}", contentUri);
    assertNotNull(contentUri);
    String expectedContentUri = ContentItem.CONTENT_SCHEME + ":" + uuid
            + ((StringUtils.isNotBlank(qualifier)) ? "#" + qualifier : "");
    assertThat(contentUri, equalTo(expectedContentUri));

    assertTrue(createdContentItem.getSize() > 0);
    String createdMimeType = createdContentItem.getMimeTypeRawData().replace(";", "");
    List<String> createdMimeTypeArr = new ArrayList<>(Arrays.asList(createdMimeType.split(" ")));
    List<String> givenMimeTypeArr = new ArrayList<>(Arrays.asList(mimeTypeRawData.replace(";", "").split(" ")));
    assertEquals(createdMimeTypeArr.size(), givenMimeTypeArr.size());
    givenMimeTypeArr.removeAll(createdMimeTypeArr);
    assertThat(givenMimeTypeArr.size(), is(0));
    provider.commit(createRequest);
    return createResponse;
}

From source file:org.codice.ddf.spatial.ogc.csw.catalog.common.source.CswFilterDelegate.java

protected String mapPropertyName(String propertyName) {
    if (isAnyText(propertyName) || isMetadata(propertyName)) {
        propertyName = CswConstants.ANY_TEXT;
    } else if (isAnyGeo(propertyName)) {
        propertyName = CswConstants.BBOX_PROP;
    }// ww w.j a  v a2  s .  c om
    propertyName = StringUtils.defaultIfBlank(cswSourceConfiguration.getMetacardMapping(propertyName),
            propertyName);

    return propertyName;
}

From source file:org.codice.solr.factory.impl.HttpSolrClientFactory.java

public static void createSolrCore(String url, String coreName, String configFileName,
        CloseableHttpClient httpClient) throws IOException, SolrServerException {

    try (CloseableHttpClient closeableHttpClient = httpClient;
            HttpSolrClient client = (httpClient != null
                    ? new HttpSolrClient.Builder(url).withHttpClient(closeableHttpClient).build()
                    : new HttpSolrClient.Builder(url).build())) {

        HttpResponse ping = client.getHttpClient().execute(new HttpHead(url));
        if (ping != null && ping.getStatusLine().getStatusCode() == 200) {
            ConfigurationFileProxy configProxy = new ConfigurationFileProxy(ConfigurationStore.getInstance());
            configProxy.writeSolrConfiguration(coreName);
            if (!solrCoreExists(client, coreName)) {
                LOGGER.debug("Solr({}): Creating Solr core", coreName);

                String configFile = StringUtils.defaultIfBlank(configFileName, DEFAULT_SOLRCONFIG_XML);
                String solrDir;/*from   w  w w .  j a  v a2  s  .  c o  m*/

                if (AccessController.doPrivileged(
                        (PrivilegedAction<Boolean>) () -> System.getProperty(SOLR_DATA_DIR) != null)) {
                    solrDir = AccessController
                            .doPrivileged((PrivilegedAction<String>) () -> System.getProperty(SOLR_DATA_DIR));
                } else {
                    solrDir = Paths.get(
                            AccessController.doPrivileged(
                                    (PrivilegedAction<String>) () -> System.getProperty("karaf.home")),
                            "data", "solr").toString();
                }

                String instanceDir = Paths.get(solrDir, coreName).toString();

                String dataDir = Paths.get(instanceDir, "data").toString();

                CoreAdminRequest.createCore(coreName, instanceDir, client, configFile, DEFAULT_SCHEMA_XML,
                        dataDir, dataDir);
            } else {
                LOGGER.debug("Solr({}): Solr core already exists; reloading it", coreName);
                CoreAdminRequest.reloadCore(coreName, client);
            }
        } else {
            LOGGER.debug("Solr({}): Unable to ping Solr core at {}", coreName, url);
            throw new SolrServerException("Unable to ping Solr core");
        }
    }
}

From source file:org.codice.solr.factory.impl.HttpSolrClientFactory.java

@Override
public org.codice.solr.client.solrj.SolrClient newClient(String core) {
    String solrUrl = StringUtils.defaultIfBlank(
            AccessController.doPrivileged((PrivilegedAction<String>) () -> System.getProperty(SOLR_HTTP_URL)),
            getDefaultHttpsAddress());//w w  w  .j  av a  2  s  .com
    final String coreUrl = solrUrl + "/" + core;
    final String solrDataDir = AccessController
            .doPrivileged((PrivilegedAction<String>) () -> System.getProperty(SOLR_DATA_DIR));

    if (solrDataDir != null) {
        ConfigurationStore.getInstance().setDataDirectoryPath(solrDataDir);
    }
    LOGGER.debug("Solr({}): Creating an HTTP Solr client using url [{}]", core, coreUrl);
    return new SolrClientAdapter(core, () -> createSolrHttpClient(solrUrl, core, coreUrl));
}

From source file:org.codice.solr.factory.SolrClientFactory.java

private static void createSolrCore(String url, String coreName, String configFileName, HttpClient httpClient)
        throws IOException, SolrServerException {
    HttpSolrClient client;//  www  .ja  va2  s .  c o m
    if (httpClient != null) {
        client = new HttpSolrClient(url, httpClient);
    } else {
        client = new HttpSolrClient(url);
    }

    HttpResponse ping = client.getHttpClient().execute(new HttpHead(url));
    if (ping != null && ping.getStatusLine().getStatusCode() == 200) {
        if (!solrCoreExists(client, coreName)) {
            LOGGER.debug("Creating Solr core {}", coreName);

            String configFile = StringUtils.defaultIfBlank(configFileName, DEFAULT_SOLRCONFIG_XML);

            String instanceDir = Paths.get(System.getProperty("karaf.home"), "data", "solr", coreName)
                    .toString();

            CoreAdminRequest.createCore(coreName, instanceDir, client, configFile, DEFAULT_SCHEMA_XML);
        } else {
            LOGGER.debug("Solr core ({}) already exists - reloading it", coreName);
            CoreAdminRequest.reloadCore(coreName, client);
        }
    } else {
        LOGGER.debug("Unable to ping Solr core {}", coreName);
        throw new SolrServerException("Unable to ping Solr core");
    }
}