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

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

Introduction

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

Prototype

public static String defaultString(String str) 

Source Link

Document

Returns either the passed in String, or if the String is null, an empty String ("").

Usage

From source file:biz.netcentric.cq.tools.actool.installationhistory.impl.HistoryUtils.java

public static void setHistoryNodeProperties(final Node historyNode, AcInstallationHistoryPojo history)
        throws ValueFormatException, VersionException, LockException, ConstraintViolationException,
        RepositoryException {//  w  w w. j  a  v a2 s .c  o m

    historyNode.setProperty(PROPERTY_INSTALLATION_DATE, history.getInstallationDate().toString());
    historyNode.setProperty(PROPERTY_SUCCESS, history.isSuccess());
    historyNode.setProperty(PROPERTY_EXECUTION_TIME, history.getExecutionTime());

    String messageHistory = history.getVerboseMessageHistory();

    // 16777216 bytes = ~ 16MB was the error in #145, assuming chars*2, hence 16777216 / 2 = 8MB, using 7MB to consider the BSON
    // overhead
    if (messageHistory.length() > (7 * 1024 * 1024)) {
        messageHistory = history.getMessageHistory(); // just use non-verbose history for this case
    }
    historyNode.setProperty(PROPERTY_MESSAGES, messageHistory);
    historyNode.setProperty(PROPERTY_TIMESTAMP, history.getInstallationDate().getTime());
    historyNode.setProperty(PROPERTY_SLING_RESOURCE_TYPE, "/apps/netcentric/actool/components/historyRenderer");

    Map<String, String> configFileContentsByName = history.getConfigFileContentsByName();
    if (configFileContentsByName != null) {
        String commonPrefix = StringUtils.getCommonPrefix(
                configFileContentsByName.keySet().toArray(new String[configFileContentsByName.size()]));
        String crxPackageName = history.getCrxPackageName(); // for install hook case
        historyNode.setProperty(PROPERTY_INSTALLED_FROM,
                StringUtils.defaultString(crxPackageName) + commonPrefix);
    }

}

From source file:com.cisco.ca.cstg.pdi.controllers.license.LicenseController.java

@RequestMapping(value = "/getLicenseDetails.html", method = RequestMethod.POST)
@ResponseBody/*from   w ww  .  j a v  a2s.  c  o m*/
public String getLicenseDetails() {
    License license = (License) pdiLoginService.findById(License.class, 1);

    Map<String, Object> myMap = new LinkedHashMap<String, Object>();

    if (license != null) {
        myMap.put(CAM_NAME, StringUtils.defaultString(license.getName()));
        myMap.put(CAM_THEATRE, StringUtils.defaultString(license.getTheatre()));
        myMap.put(CUSTOMER_NAME, StringUtils.defaultString(license.getCustomerName()));
        myMap.put(CAM_SITE, StringUtils.defaultString(license.getSite()));
        myMap.put(AS_PDI, StringUtils.defaultString(license.getAsPid()));
        myMap.put(CREATED_BY, StringUtils.defaultString(license.getCreatedby()));
    }
    return Util.convertMapToJson(myMap);
}

From source file:com.joshlong.esb.springintegration.modules.net.sftp.SFTPSendingMessageHandler.java

private boolean sendFileToRemoteEndpoint(Message<?> message, File file) throws Throwable {
    assert this.pool != null : "need a working pool";

    SFTPSession session = this.pool.getSession();

    if (session == null) {
        throw new RuntimeException("the session returned from the pool is null, can't possibly proceed.");
    }//from   w w  w .  j  a  va2  s  .c  o  m

    session.start();

    ChannelSftp sftp = session.getChannel();

    InputStream fileInputStream = null;

    try {
        fileInputStream = new FileInputStream(file);

        String baseOfRemotePath = StringUtils.isEmpty(this.remoteDirectory) ? StringUtils.EMPTY
                : remoteDirectory; // the safe default

        logger.debug("going to send " + file.getAbsolutePath() + " to a remote sftp endpoint");

        String dynRd = null;
        MessageHeaders messageHeaders = null;

        if (message != null) {
            messageHeaders = message.getHeaders();

            if ((messageHeaders != null)
                    && messageHeaders.containsKey(SFTPConstants.SFTP_REMOTE_DIRECTORY_HEADER)) {
                dynRd = (String) messageHeaders.get(SFTPConstants.SFTP_REMOTE_DIRECTORY_HEADER);

                if (!StringUtils.isEmpty(dynRd)) {
                    baseOfRemotePath = dynRd;
                }
            }
        }

        if (!StringUtils.defaultString(baseOfRemotePath).endsWith("/")) {
            baseOfRemotePath += "/";
        }

        sftp.put(fileInputStream, baseOfRemotePath + file.getName());

        return true;
    } finally {
        IOUtils.closeQuietly(fileInputStream);

        if (pool != null) {
            pool.release(session);
        }
    }
}

From source file:demo.project.ExportTable.java

/**
 * @param row
 * @param col
 * @return
 */
private String toValue(IRow row, ARankColumnModel col) {
    return StringUtils.defaultString(col.getValue(row));
}

From source file:mitm.djigzo.web.pages.admin.backup.BackupManager.java

public String getBackupIdentifier() {
    return StringUtils.defaultString(backupIdentifier);
}

From source file:br.com.ingenieux.mojo.beanstalk.env.DumpEnvironmentSettings.java

protected Object executeInternal() throws Exception {
    DescribeConfigurationOptionsResult configOptions = getService()
            .describeConfigurationOptions(new DescribeConfigurationOptionsRequest()
                    .withApplicationName(applicationName).withEnvironmentName(curEnv.getEnvironmentName()));

    for (ConfigurationOptionDescription o : configOptions.getOptions()) {
        String key = String.format("beanstalk.env.%s.%s", o.getNamespace().replace(":", "."), o.getName());

        for (Map.Entry<String, ConfigurationOptionSetting> entry : COMMON_PARAMETERS.entrySet()) {
            ConfigurationOptionSetting cos = entry.getValue();

            if (cos.getNamespace().equals(o.getNamespace()) && cos.getOptionName().equals(o.getName())) {
                key = entry.getKey();/*from   w w w . ja  va  2 s .  co m*/
                break;
            }
        }

        defaultSettings.put(key, o);
    }

    DescribeConfigurationSettingsResult configurationSettings = getService()
            .describeConfigurationSettings(new DescribeConfigurationSettingsRequest()
                    .withApplicationName(applicationName).withEnvironmentName(curEnv.getEnvironmentName()));

    Properties newProperties = new Properties();

    if (configurationSettings.getConfigurationSettings().isEmpty()) {
        throw new IllegalStateException("No Configuration Settings received");
    }

    ConfigurationSettingsDescription configSettings = configurationSettings.getConfigurationSettings().get(0);

    Map<String, ConfigurationOptionSetting> keyMap = new LinkedHashMap<String, ConfigurationOptionSetting>();

    for (ConfigurationOptionSetting d : configSettings.getOptionSettings()) {
        String key = String.format("beanstalk.env.%s.%s", d.getNamespace().replaceAll(":", "."),
                d.getOptionName());
        String defaultValue = "";
        String outputKey = key;

        keyMap.put(key, d);

        for (Map.Entry<String, ConfigurationOptionSetting> cosEntry : COMMON_PARAMETERS.entrySet()) {
            ConfigurationOptionSetting v = cosEntry.getValue();

            boolean match = v.getNamespace().equals(d.getNamespace())
                    && v.getOptionName().equals(d.getOptionName());

            if (match) {
                outputKey = cosEntry.getKey();
                break;
            }
        }

        if (defaultSettings.containsKey(outputKey)) {
            defaultValue = StringUtils.defaultString(defaultSettings.get(outputKey).getDefaultValue());
        }

        String value = d.getValue();

        if (null == value || StringUtils.isBlank("" + value)) {
            continue;
        }

        if (!defaultValue.equals(value)) {
            if (!value.contains(curEnv.getEnvironmentId())) {
                getLog().info("Adding property " + key);

                if (changedOnly) {
                    String curValue = project.getProperties().getProperty(outputKey);

                    if (!value.equals(curValue)) {
                        newProperties.put(outputKey, value);
                    }
                } else {
                    newProperties.put(outputKey, value);
                }
            } else {
                getLog().info("Ignoring property " + outputKey + "(value=" + value
                        + ") due to containing references to the environment id");
            }

        } else {
            getLog().debug("Ignoring property " + key + " (defaulted)");
        }
    }

    if ("properties".equals(this.outputFileFormat)) {
        String comment = "elastic beanstalk environment properties for " + curEnv.getEnvironmentName();
        if (null != outputFile) {
            newProperties.store(new FileOutputStream(outputFile), comment);
        } else {
            newProperties.store(System.out, comment);
        }
    } else if ("yaml".equals(this.outputFileFormat)) {
        PrintStream printStream = System.out;

        if (null != outputFile) {
            printStream = new PrintStream(outputFile);
        }

        printStream.println("option_settings:");

        for (Map.Entry<Object, Object> e : newProperties.entrySet()) {
            ConfigurationOptionSetting c = keyMap.get("" + e.getKey());
            String value = "" + e.getValue();

            printStream.println("  - namespace: " + c.getNamespace());
            printStream.println("    option_name: " + c.getOptionName());
            printStream.println("    value: " + value);
        }

        printStream.close();
    }

    return null;
}

From source file:gov.nih.nci.firebird.selenium2.pages.util.VerificationUtils.java

public static void checkPhoneNumber(String country, String expected, String actual) {
    String expectedPhone = StringUtils.defaultString(expected);
    String actualPhone = StringUtils.defaultString(actual);

    if (StringUtils.isNotBlank(expectedPhone)) {
        if (FORMATTED_COUNTRIES.contains(country)) {
            assertTrue("Phone number from page " + actualPhone + " did not match the ###-###-####x#* pattern.",
                    actualPhone.matches("^\\d{3}-\\d{3}-\\d{4}(x\\d+)?$"));
            checkPhoneDigits(expectedPhone, actualPhone);
        } else {// w ww .  ja  v  a2 s  .  c o m
            assertEquals(expectedPhone, actualPhone);
        }
    }
}

From source file:dk.dma.msinm.user.security.JWTService.java

/**
 * Generates a temporary password token.
 * @param prefix a prefix//  www.  j av a 2s  .c om
 * @return the temporary password token
 */
public String createTempJwtPwdToken(String prefix) {
    String pwd = StringUtils.defaultString(prefix) + UUID.randomUUID().toString();
    return pwd;
}

From source file:com.manydesigns.portofino.actions.user.LoginAction.java

@Button(list = "login-buttons", key = "login", order = 1, type = Button.TYPE_PRIMARY)
public Resolution login() {
    Subject subject = SecurityUtils.getSubject();
    if (subject.isAuthenticated()) {
        logger.debug("Already logged in");
        return redirectToReturnUrl();
    }// w  w  w .java  2 s.co m

    userName = StringUtils.defaultString(userName);
    try {
        UsernamePasswordToken usernamePasswordToken = new UsernamePasswordToken(userName, pwd);
        usernamePasswordToken.setRememberMe(false);
        subject.login(usernamePasswordToken);
        logger.info("User {} login", ShiroUtils.getUserId(subject));
        String successMsg = ElementsThreadLocals.getText("user._.logged.in.successfully", userName);
        SessionMessages.addInfoMessage(successMsg);
        return redirectToReturnUrl();
    } catch (DisabledAccountException e) {
        String errMsg = ElementsThreadLocals.getText("user._.is.not.active", userName);
        SessionMessages.addErrorMessage(errMsg);
        logger.warn("Login failed for '" + userName + "': " + e.getMessage());
    } catch (IncorrectCredentialsException e) {
        String errMsg = ElementsThreadLocals.getText("login.failed.for.user._", userName);
        SessionMessages.addErrorMessage(errMsg);
        logger.warn("Login failed for '" + userName + "': " + e.getMessage());
    } catch (UnknownAccountException e) {
        String errMsg = ElementsThreadLocals.getText("login.failed.for.user._", userName);
        SessionMessages.addErrorMessage(errMsg);
        logger.warn("Login failed for '" + userName + "': " + e.getMessage());
    } catch (AuthenticationException e) {
        String errMsg = ElementsThreadLocals.getText("login.failed.for.user._", userName);
        SessionMessages.addErrorMessage(errMsg);
        logger.warn("Login failed for '" + userName + "': " + e.getMessage(), e);
    }
    return new ForwardResolution(getLoginPage());
}

From source file:com.redhat.rhn.frontend.action.configuration.files.DiffAction.java

private void setInfoDiffAttributes(ConfigRevision revision, ConfigRevision other, HttpServletRequest request) {
    ConfigInfo info = revision.getConfigInfo();
    ConfigInfo oinfo = other.getConfigInfo();
    if (!revision.isSymlink()) {
        //The following pieces are differences between revisions that are
        //not in the file content.  We only show these if they are different.
        if (!info.getFilemode().equals(oinfo.getFilemode())) {
            request.setAttribute("diffmode", "true");
        }/* ww  w .  j a  v  a  2  s  .  c om*/
        if (!info.getUsername().equals(oinfo.getUsername())) {
            request.setAttribute("diffuser", "true");
        }
        if (!info.getGroupname().equals(oinfo.getGroupname())) {
            request.setAttribute("diffgroup", "true");
        }
    } else if (other.isSymlink()) {
        ConfigFileName target = info.getTargetFileName();
        ConfigFileName otarget = oinfo.getTargetFileName();
        if ((target == null && otarget != null) || (target != null && otarget == null)
                || !otarget.equals(target)) {
            request.setAttribute("difftargetpath", "true");
        }
    }

    if (!revision.getConfigFileType().getLabel().equals(other.getConfigFileType().getLabel())
            || (revision.isFile()
                    && revision.getConfigContent().isBinary() != other.getConfigContent().isBinary())) {
        request.setAttribute("difftype", "true");
    }

    String selinux = StringUtils.defaultString(info.getSelinuxCtx());
    String otherSelinux = StringUtils.defaultString(oinfo.getSelinuxCtx());
    if (!selinux.equals(otherSelinux)) {
        request.setAttribute("diffselinux", "true");
    }

}