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, String defaultStr) 

Source Link

Document

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

Usage

From source file:com.thoughtworks.go.legacywrapper.TestSuiteExtractor.java

private BuildTestSuite createSingleTestSuite(Attributes attributes) {
    String name = attributes.getValue("name");
    float duration = Float.parseFloat(StringUtils.defaultString(attributes.getValue("time"), "0.0"));
    int tests = Integer.parseInt(StringUtils.defaultString(attributes.getValue("tests"), "0"));
    int failures = Integer.parseInt(StringUtils.defaultString(attributes.getValue("failures"), "0"));
    int errors = Integer.parseInt(StringUtils.defaultString(attributes.getValue("errors"), "0"));
    return new BuildTestSuite(name, duration);
}

From source file:com.canoo.webtest.plugins.emailtest.AbstractSelectStep.java

static boolean doMatch(final String expected, String actual) {
    actual = StringUtils.defaultString(actual, ""); // catch null

    // semantics are: if no expectation then match
    if (StringUtils.isEmpty(expected)) {
        return true;
    }/*w  w  w .  j  av  a 2s .  co m*/

    if (isRegexMatch(expected)) {
        return getVerifier(true).verifyStrings(expected.substring(1, expected.length() - 1), actual);
    }
    return getVerifier(false).verifyStrings(expected, actual);
}

From source file:adalid.core.wrappers.ExpressionWrapper.java

/**
 * @param separator// ww  w .j  av  a  2  s. co  m
 * @return the default error message join
 */
public String getDefaultErrorMessageJoin(String separator) {
    if (_booleanExpression == null) {
        return null;
    }
    List<String> messages = getDefaultErrorMessagesList();
    String sep = StringUtils.defaultString(separator, ERROR_MESSAGE_JOIN_SEPARATOR);
    return StringUtils.join(messages, sep);
}

From source file:info.magnolia.cms.filters.CosMultipartRequestFilter.java

/**
 * Adds all request paramaters as request attributes.
 * @param request HttpServletRequest/*from w ww.j a  v  a2s  .co m*/
 */
private static MultipartForm parseParameters(HttpServletRequest request) throws IOException {
    MultipartForm form = new MultipartForm();
    String encoding = StringUtils.defaultString(request.getCharacterEncoding(), "UTF-8");
    MultipartRequest multi = new MultipartRequest(request, Path.getTempDirectoryPath(), MAX_FILE_SIZE, encoding,
            null);
    Enumeration params = multi.getParameterNames();
    while (params.hasMoreElements()) {
        String name = (String) params.nextElement();
        String value = multi.getParameter(name);
        form.addParameter(name, value);
        String[] s = multi.getParameterValues(name);
        if (s != null) {
            form.addparameterValues(name, s);
        }
    }
    Enumeration files = multi.getFileNames();
    while (files.hasMoreElements()) {
        String name = (String) files.nextElement();
        form.addDocument(name, multi.getFilesystemName(name), multi.getContentType(name), multi.getFile(name));
    }
    request.setAttribute(MultipartForm.REQUEST_ATTRIBUTE_NAME, form);
    return form;
}

From source file:com.redhat.rhn.domain.kickstart.KickstartCommand.java

/**
 *
 * @param kc KickstartCommand to compare
 * @return how does it stack up!// w ww . ja  va  2s  .  co m
 */
public int compareTo(Object kc) {
    if (kc == this) {
        return 0;
    }
    KickstartCommand k = (KickstartCommand) kc;
    int order = getCommandName().getOrder().compareTo(k.getCommandName().getOrder());

    if (order == 0) {
        String ourArgs = StringUtils.defaultString(getArguments(), "");
        String theirArgs = StringUtils.defaultString(k.getArguments(), "");
        order = ourArgs.compareTo(theirArgs);
    }

    return order;
}

From source file:mitm.common.fetchmail.FetchmailConfigBuilder.java

private static void injectConfig(FetchmailConfig config, StrBuilder output) {
    if (config.isCheckCertificate()) {
        output.append("sslcertck").appendNewLine();
    }//from w w  w  .  java  2s .c  o m

    output.append("set daemon ").append(config.getPollInterval()).appendNewLine();
    output.append("set postmaster ").append(escape(config.getPostmaster())).appendNewLine();

    for (Poll poll : config.getPolls()) {
        output.append("poll ").append(escape(StringUtils.defaultString(poll.getServer(), "undefined")));

        if (poll.getPort() != null) {
            output.append(" service ").append(poll.getPort());
        }

        if (poll.getProtocol() != null) {
            output.append(" proto ").append(poll.getProtocol());
        }

        output.append(poll.isUIDL() ? " uidl " : " no uidl");
        ;

        if (poll.getUsername() != null) {
            output.append(" user ").append(escape(poll.getUsername()));
        }

        if (poll.getPassword() != null) {
            output.append(" password ").append(escape(poll.getPassword()));
        }

        if (poll.getForwardTo() != null) {
            output.append(" is ").append(escape(poll.getForwardTo()));
        }

        if (poll.getFolder() != null) {
            output.append(" folder ").append(escape(poll.getFolder()));
        }

        output.append(" options");

        if (poll.isSSL()) {
            output.append(" ssl");
        }

        output.append(poll.isIdle() ? " idle" : " no idle");
        ;
        output.append(poll.isKeep() ? " keep" : " no keep");
        ;

        output.appendNewLine();
    }
}

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

@Override
protected Object executeInternal() throws Exception {
    AmazonEC2 ec2 = clientFactory.getService(AmazonEC2Client.class);

    DescribeEnvironmentResourcesResult envResources = getService().describeEnvironmentResources(
            new DescribeEnvironmentResourcesRequest().withEnvironmentId(curEnv.getEnvironmentId())
                    .withEnvironmentName(curEnv.getEnvironmentName()));
    List<String> instanceIds = new ArrayList<String>();

    for (Instance i : envResources.getEnvironmentResources().getInstances()) {
        instanceIds.add(i.getId());// w  w  w . ja  v  a2  s. c o  m
    }

    DescribeInstancesResult ec2Instances = ec2
            .describeInstances(new DescribeInstancesRequest().withInstanceIds(instanceIds));

    PrintStream printStream = null;

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

    for (Reservation r : ec2Instances.getReservations()) {
        for (com.amazonaws.services.ec2.model.Instance i : r.getInstances()) {
            String ipAddress = dumpPrivateAddresses ? i.getPrivateIpAddress()
                    : StringUtils.defaultString(i.getPublicIpAddress(), i.getPrivateDnsName());
            String instanceId = i.getInstanceId();

            if (null != printStream) {
                printStream.println(ipAddress + " # " + instanceId);
            } else {
                getLog().info(" * " + instanceId + ": " + ipAddress);
            }
        }
    }

    if (null != printStream) {
        printStream.close();
    }

    return null;
}

From source file:com.bstek.dorado.view.type.property.MappingPropertyOutputter.java

protected void outputArray(Mapping mapping, Object elements, OutputContext context) throws Exception {
    String keyProperty = StringUtils.defaultString(mapping.getKeyProperty(), "key");
    String valueProperty = StringUtils.defaultString(mapping.getValueProperty(), "value");

    JsonBuilder json = context.getJsonBuilder();
    json.array();//from ww  w .  j  av a2s .c  o m

    int length = Array.getLength(elements);
    for (int i = 0; i < length; i++) {
        Object element = Array.get(elements, i);
        EntityWrapper entity = EntityWrapper.create(element);
        json.object();

        json.key("key");
        outputData(entity.get(keyProperty), context);
        json.endKey();

        json.key("value");
        outputData(entity.get(valueProperty), context);
        json.endKey();

        json.endObject();
    }
    json.endArray();
}

From source file:com.flexive.core.search.cmis.parser.CmisSqlUtils.java

private static FxCmisSqlParseException translateException(String query, RecognitionException e) {
    // TODO: add more detailed error messages
    final FxCmisSqlParseException parseExc;
    if (e instanceof NoViableAltException) {
        // standard error message when the query syntax is not correct or a keyword is missing
        parseExc = new FxCmisSqlParseException(LOG, ErrorCause.UNPARSED_INPUT,
                getUnparsedInput(query, e.line, e.charPositionInLine));
    } else {/* www. j a  v a2 s .c  om*/
        parseExc = new FxCmisSqlParseException(LOG, ErrorCause.RECOGNIZER_ERROR,
                StringUtils.defaultString(e.getMessage(), e.toString()),
                getUnparsedInput(query, e.line, e.charPositionInLine));
    }
    parseExc.setStackTrace(e.getStackTrace());
    return parseExc;
}

From source file:com.flexive.shared.ContentLinkFormatter.java

/**
 * <p>Uses the given format string to create a hyperlink for the given primary key.
 * Supported placeholders are:</p>
 * <table>/*from   w w  w .j  a  v a2s .c o  m*/
 * <tr>
 * <th>%{pk}</th>
 * <td>The primary key in "dot" notation. For example, new FxPK(42, 1)
 * results in "42.1" being substituted in the URI.</td>
 * </tr>
 * <tr>
 * <th>%{id}</th>
 * <td>The object ID.</td>
 * </tr>
 * <tr>
 * <th>%{version}</th>
 * <td>The object version.</td>
 * </tr>
 * </table>
 *
 * @param formatString  the input format string. For example, <code>"/content/%{id}.html"</code>
 * @param pk    the content PK to be formatted
 * @return  the resulting hyperlink
 */
public String format(String formatString, FxPK pk) {
    return StringUtils.defaultString(formatString, DEFAULT).replace("%{id}", String.valueOf(pk.getId()))
            .replace("%{version}", String.valueOf(pk.getVersion())).replace("%{pk}", pk.toString());
}