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

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

Introduction

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

Prototype

public static String defaultString(final String str, final String defaultStr) 

Source Link

Document

Returns either the passed in String, or if the String is null , the value of defaultStr .

 StringUtils.defaultString(null, "NULL")  = "NULL" StringUtils.defaultString("", "NULL")    = "" StringUtils.defaultString("bat", "NULL") = "bat" 

Usage

From source file:com.epam.catgenome.manager.reference.ReferenceManager.java

/**
 * Validates and parses the given to make sure that all mandatory properties,
 * describing genome data, are provided.
 * <p>//from  www  .j a v a  2s  . c  o  m
 * The default values will be assigned in cases when it is possible to do. E.g., to treat omitted
 * custom name for a genome it's possible to use an original name of corresponded file without
 * extension.
 *
 * @param path {@code File}     Path to fasta file
 * @param name {@code String}   Alternative name
 */
private String parse(final String path, final String name) {
    Assert.notNull(path, getMessage(MessageCode.RESOURCE_NOT_FOUND));
    // checks that an original file name is provided, because it is used as a name
    // for a genome if custom name isn't specified
    String fileName = StringUtils.trimToNull(FilenameUtils.getName(path));
    Assert.notNull(fileName, getMessage(MessageCode.MANDATORY_FILE_NAME));
    // checks that file is in one of supported formats
    boolean supported = false;
    final Collection<String> formats = FastaUtils.getFastaExtensions();
    for (final String ext : formats) {
        if (fileName.endsWith(ext)) {
            supported = true;
            fileName = Utils.removeFileExtension(fileName, ext);
            break;
        }
    }
    if (!supported) {
        throw new IllegalArgumentException(
                getMessage("error.reference.illegal.file.type", StringUtils.join(formats, ", ")));
    }
    // if no custom name is provided for a genome, then a file name without extension should be
    // used by default
    return StringUtils.defaultString(StringUtils.trimToNull(name), fileName);
}

From source file:de.gbv.ole.Marc21ToOleBulk.java

/**
 * Liest aus Subfeld f des MARC-Felds die optionale Location und
 * schreibt sie in das Exemplar.//w  w w  . j a v a 2  s .  c  om
 * @param field     MARC-Feld, das die Location enthalten kann
 * @param exemplar das Exemplar
 */
final static void fetchLocation(final DataField field, Exemplar exemplar) {
    String location = optionalSubfield(field, 'f');
    location = StringUtils.defaultString(convertLocation.get(location), location);
    exemplar.location = location;
}

From source file:com.mirth.connect.client.ui.LoginPanel.java

private void loginButtonActionPerformed(java.awt.event.ActionEvent evt)// GEN-FIRST:event_loginButtonActionPerformed
{// GEN-HEADEREND:event_loginButtonActionPerformed
    errorPane.setVisible(false);//w w  w. j a  v  a 2s.c om

    SwingWorker<Void, Void> worker = new SwingWorker<Void, Void>() {

        public Void doInBackground() {
            boolean errorOccurred = false;

            try {
                String server = serverName.getText();
                client = new Client(server, PlatformUI.HTTPS_PROTOCOLS, PlatformUI.HTTPS_CIPHER_SUITES);
                PlatformUI.SERVER_URL = server;

                // Attempt to login
                LoginStatus loginStatus = null;
                try {
                    loginStatus = client.login(username.getText(), String.valueOf(password.getPassword()));
                } catch (ClientException ex) {
                    ex.printStackTrace();

                    if (ex instanceof UnauthorizedException) {
                        UnauthorizedException e2 = (UnauthorizedException) ex;
                        if (e2.getResponse() != null && e2.getResponse() instanceof LoginStatus) {
                            loginStatus = (LoginStatus) e2.getResponse();
                        }
                    }

                    // Leave loginStatus null, the error message will be set to the default
                }

                // If SUCCESS or SUCCESS_GRACE_PERIOD
                if ((loginStatus != null) && ((loginStatus.getStatus() == LoginStatus.Status.SUCCESS)
                        || (loginStatus.getStatus() == LoginStatus.Status.SUCCESS_GRACE_PERIOD))) {
                    try {
                        String serverName = client.getServerSettings().getServerName();
                        if (!StringUtils.isBlank(serverName)) {
                            PlatformUI.SERVER_NAME = serverName;
                        } else {
                            PlatformUI.SERVER_NAME = null;
                        }
                    } catch (ClientException e) {
                        PlatformUI.SERVER_NAME = null;
                    }

                    try {
                        String database = (String) client.getAbout().get("database");
                        if (!StringUtils.isBlank(database)) {
                            PlatformUI.SERVER_DATABASE = database;
                        } else {
                            PlatformUI.SERVER_DATABASE = null;
                        }
                    } catch (ClientException e) {
                        PlatformUI.SERVER_DATABASE = null;
                    }

                    try {
                        Map<String, String[]> map = client.getProtocolsAndCipherSuites();
                        PlatformUI.SERVER_HTTPS_SUPPORTED_PROTOCOLS = map
                                .get(MirthSSLUtil.KEY_SUPPORTED_PROTOCOLS);
                        PlatformUI.SERVER_HTTPS_ENABLED_CLIENT_PROTOCOLS = map
                                .get(MirthSSLUtil.KEY_ENABLED_CLIENT_PROTOCOLS);
                        PlatformUI.SERVER_HTTPS_ENABLED_SERVER_PROTOCOLS = map
                                .get(MirthSSLUtil.KEY_ENABLED_SERVER_PROTOCOLS);
                        PlatformUI.SERVER_HTTPS_SUPPORTED_CIPHER_SUITES = map
                                .get(MirthSSLUtil.KEY_SUPPORTED_CIPHER_SUITES);
                        PlatformUI.SERVER_HTTPS_ENABLED_CIPHER_SUITES = map
                                .get(MirthSSLUtil.KEY_ENABLED_CIPHER_SUITES);
                    } catch (ClientException e) {
                    }

                    PlatformUI.USER_NAME = StringUtils.defaultString(loginStatus.getUpdatedUsername(),
                            username.getText());
                    setStatus("Authenticated...");
                    new Mirth(client);
                    LoginPanel.getInstance().setVisible(false);

                    User currentUser = PlatformUI.MIRTH_FRAME.getCurrentUser(PlatformUI.MIRTH_FRAME);
                    Properties userPreferences = new Properties();
                    Set<String> preferenceNames = new HashSet<String>();
                    preferenceNames.add("firstlogin");
                    preferenceNames.add("checkForNotifications");
                    preferenceNames.add("showNotificationPopup");
                    preferenceNames.add("archivedNotifications");
                    try {
                        userPreferences = client.getUserPreferences(currentUser.getId(), preferenceNames);

                        // Display registration dialog if it's the user's first time logging in
                        String firstlogin = userPreferences.getProperty("firstlogin");
                        if (firstlogin == null || BooleanUtils.toBoolean(firstlogin)) {
                            new FirstLoginDialog(currentUser);
                        } else if (loginStatus.getStatus() == LoginStatus.Status.SUCCESS_GRACE_PERIOD) {
                            new ChangePasswordDialog(currentUser, loginStatus.getMessage());
                        }

                        // Check for new notifications from update server if enabled
                        String checkForNotifications = userPreferences.getProperty("checkForNotifications");
                        if (checkForNotifications == null || BooleanUtils.toBoolean(checkForNotifications)) {
                            Set<Integer> archivedNotifications = new HashSet<Integer>();
                            String archivedNotificationString = userPreferences
                                    .getProperty("archivedNotifications");
                            if (archivedNotificationString != null) {
                                archivedNotifications = ObjectXMLSerializer.getInstance()
                                        .deserialize(archivedNotificationString, Set.class);
                            }
                            // Update the Other Tasks pane with the unarchived notification count
                            int unarchivedNotifications = ConnectServiceUtil.getNotificationCount(
                                    PlatformUI.SERVER_ID, PlatformUI.SERVER_VERSION,
                                    LoadedExtensions.getInstance().getExtensionVersions(),
                                    archivedNotifications, PlatformUI.HTTPS_PROTOCOLS,
                                    PlatformUI.HTTPS_CIPHER_SUITES);
                            PlatformUI.MIRTH_FRAME.updateNotificationTaskName(unarchivedNotifications);

                            // Display notification dialog if enabled and if there are new notifications
                            String showNotificationPopup = userPreferences.getProperty("showNotificationPopup");
                            if (showNotificationPopup == null
                                    || BooleanUtils.toBoolean(showNotificationPopup)) {
                                if (unarchivedNotifications > 0) {
                                    new NotificationDialog();
                                }
                            }
                        }
                    } catch (ClientException e) {
                        PlatformUI.MIRTH_FRAME.alertThrowable(PlatformUI.MIRTH_FRAME, e);
                    }

                    PlatformUI.MIRTH_FRAME.sendUsageStatistics();
                } else {
                    errorOccurred = true;
                    if (loginStatus != null) {
                        errorTextArea.setText(loginStatus.getMessage());
                    } else {
                        errorTextArea.setText(ERROR_MESSAGE);
                    }
                }
            } catch (Throwable t) {
                errorOccurred = true;
                errorTextArea.setText(ERROR_MESSAGE);
                t.printStackTrace();
            }

            if (errorOccurred) {
                errorPane.setVisible(true);
                loggingIn.setVisible(false);
                loginMain.setVisible(true);
                loginProgress.setIndeterminate(false);
                password.grabFocus();
            }

            return null;
        }

        public void done() {
        }
    };
    worker.execute();

    loggingIn.setVisible(true);
    loginMain.setVisible(false);
    loginProgress.setIndeterminate(true);
}

From source file:com.google.code.siren4j.converter.ReflectingConverter.java

/**
 * Determine entity class by first using the name set on the Siren entity and then if not found using the actual class
 * name, though it is preferable to use the first option to not tie to a language specific class.
 *
 * @param obj//from   w  ww .jav  a2s  .  c  om
 * @param name
 * @return
 */
public String[] getEntityClass(Object obj, String name, Siren4JEntity entityAnno) {
    Class<?> clazz = obj.getClass();
    String[] compClass = entityAnno == null ? null : entityAnno.entityClass();
    //If entity class specified then use it.
    if (compClass != null && !ArrayUtils.isEmpty(compClass)) {
        return compClass;
    }
    //Else use name or class.
    List<String> entityClass = new ArrayList<String>();
    entityClass.add(StringUtils.defaultString(name, clazz.getName()));
    if (obj instanceof CollectionResource) {
        String tag = getCollectionClassTag();
        if (StringUtils.isNotBlank(tag)) {
            entityClass.add(tag);
        }
    }
    return entityClass.toArray(new String[] {});
}

From source file:com.thinkbiganalytics.ingest.TableMergeSyncSupport.java

protected List<PartitionBatch> toPartitionBatches(PartitionSpec spec, ResultSet rs) throws SQLException {
    Vector<PartitionBatch> v = new Vector<>();
    int count = rs.getMetaData().getColumnCount();
    while (rs.next()) {
        String[] values = new String[count];
        for (int i = 1; i <= count; i++) {
            Object oVal = rs.getObject(i);
            String sVal = (oVal == null ? "" : oVal.toString());
            values[i - 1] = StringUtils.defaultString(sVal, "");
        }//from  www  . j a v a  2  s  .c o  m
        Long numRecords = rs.getLong(count);
        v.add(new PartitionBatch(numRecords, spec, values));
    }
    logger.info("Number of partitions [" + v.size() + "]");

    return v;
}

From source file:com.gargoylesoftware.htmlunit.html.HtmlFormTest.java

/**
 * Utility for {@link #submitRequestCharset()}
 * @param headerCharset the charset for the content type header if not null
 * @param metaCharset the charset for the meta http-equiv content type tag if not null
 * @param formCharset the charset for the form's accept-charset attribute if not null
 * @param expectedRequestCharset the charset expected for the form submission
 * @throws Exception if the test fails/*from  ww  w.ja  v  a 2  s  .  c o m*/
 */
private void submitRequestCharset(final String headerCharset, final String metaCharset,
        final String formCharset, final String expectedRequestCharset) throws Exception {

    final String formAcceptCharset;
    if (formCharset == null) {
        formAcceptCharset = "";
    } else {
        formAcceptCharset = " accept-charset='" + formCharset + "'";
    }

    final String metaContentType;
    if (metaCharset == null) {
        metaContentType = "";
    } else {
        metaContentType = "<meta http-equiv='Content-Type' content='text/html; charset=" + metaCharset + "'>\n";
    }

    final String html = "<html><head><title>foo</title>\n" + metaContentType + "</head><body>\n"
            + "<form name='form1' method='post' action='foo'" + formAcceptCharset + ">\n"
            + "<input type='text' name='textField' value='foo'/>\n"
            + "<input type='text' name='nonAscii' value='Flo\u00DFfahrt'/>\n"
            + "<input type='submit' name='button' value='foo'/>\n" + "</form></body></html>";
    final WebClient client = getWebClientWithMockWebConnection();
    final MockWebConnection webConnection = getMockWebConnection();

    String contentType = "text/html";
    if (headerCharset != null) {
        contentType += ";charset=" + headerCharset;
    }
    webConnection.setDefaultResponse(html, 200, "ok", contentType);
    final HtmlPage page = client.getPage(getDefaultUrl());

    final String firstPageEncoding = StringUtils.defaultString(metaCharset, headerCharset)
            .toUpperCase(Locale.ROOT);
    assertEquals(firstPageEncoding, page.getPageEncoding());

    final HtmlForm form = page.getFormByName("form1");
    form.getInputByName("button").click();

    assertEquals(expectedRequestCharset, webConnection.getLastWebRequest().getCharset());
}

From source file:no.kantega.publishing.common.data.Multimedia.java

public void setAltname(String altname) {
    this.altname = StringUtils.defaultString(altname, "");
}

From source file:no.kantega.publishing.common.data.Multimedia.java

public void setAuthor(String author) {
    this.author = StringUtils.defaultString(author, "");
}

From source file:no.kantega.publishing.common.data.Multimedia.java

public void setDescription(String description) {
    this.description = StringUtils.defaultString(description, "");
}

From source file:no.kantega.publishing.common.data.Multimedia.java

public void setUsage(String usage) {
    this.usage = StringUtils.defaultString(usage, "");
}