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

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

Introduction

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

Prototype

public static String defaultIfEmpty(String str, String defaultStr) 

Source Link

Document

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

Usage

From source file:info.magnolia.importexport.BootstrapUtil.java

/**
 * I.e. given a resource path like <code>/mgnl-bootstrap/foo/config.server.i18n.xml</code> and <code>.xml</code> extension it will return <code>config.server.i18n</code> (no trailing dot).
 * If extension is <code>null</code>, it defaults to <code>.xml</code>.
 *///from   w w w. j  a v  a  2  s . com
public static String getFilenameFromResource(final String resourcePath, final String extension) {
    String ext = StringUtils.defaultIfEmpty(extension, ".xml");
    String tmpResourcePath = resourcePath;
    if (resourcePath.contains("/")) {
        tmpResourcePath = StringUtils.substringAfterLast(resourcePath, "/");
    }
    return StringUtils.removeEnd(tmpResourcePath, ext.startsWith(".") ? ext : "." + ext);
}

From source file:com.adaptris.core.SerializableAdaptrisMessage.java

public void setNextServiceId(String s) {
    this.nextServiceId = StringUtils.defaultIfEmpty(s, "");
}

From source file:com.manydesigns.portofino.actions.admin.tables.forms.ColumnForm.java

public void copyTo(Column column) {
    column.setJavaType(getJavaType());//  w w w.  j a  va  2s . c o m
    column.setPropertyName(StringUtils.defaultIfEmpty(getPropertyName(), null));

    //Annotations
    for (String annotationClass : KNOWN_ANNOTATIONS) {
        removeAnnotation(annotationClass, column.getAnnotations());
    }

    if (fieldSize != null) {
        Annotation ann = new Annotation(column, FieldSize.class.getName());
        ann.getValues().add(fieldSize.toString());
        column.getAnnotations().add(ann);
    }
    if (maxLength != null) {
        Annotation ann = new Annotation(column, MaxLength.class.getName());
        ann.getValues().add(maxLength.toString());
        column.getAnnotations().add(ann);
    }
    if (typeOfContent != null) {
        Annotation ann = new Annotation(column, typeOfContent);
        ann.getValues().add("true");
        column.getAnnotations().add(ann);
    }
    if (stringFormat != null) {
        Annotation ann = new Annotation(column, stringFormat);
        column.getAnnotations().add(ann);
    }
    if (highlightLinks) {
        Annotation ann = new Annotation(column, HighlightLinks.class.getName());
        ann.getValues().add("true");
        column.getAnnotations().add(ann);
    }
    if (!StringUtils.isEmpty(regexp)) {
        Annotation ann = new Annotation(column, RegExp.class.getName());
        ann.getValues().add(regexp);
        ann.getValues().add("elements.error.field.regexp.format"); //Default error message
        column.getAnnotations().add(ann);
    }
    if (fileBlob) {
        Annotation ann = new Annotation(column, FileBlob.class.getName());
        column.getAnnotations().add(ann);
    }
    if (minValue != null) {
        Annotation ann = new Annotation(column, MinDecimalValue.class.getName());
        ann.getValues().add(minValue.toString());
        column.getAnnotations().add(ann);
    }
    if (maxValue != null) {
        Annotation ann = new Annotation(column, MaxDecimalValue.class.getName());
        ann.getValues().add(maxValue.toString());
        column.getAnnotations().add(ann);
    }
    if (!StringUtils.isEmpty(decimalFormat)) {
        Annotation ann = new Annotation(column, DecimalFormat.class.getName());
        ann.getValues().add(decimalFormat);
        column.getAnnotations().add(ann);
    }
    if (!StringUtils.isEmpty(dateFormat)) {
        Annotation ann = new Annotation(column, DateFormat.class.getName());
        ann.getValues().add(dateFormat);
        column.getAnnotations().add(ann);
    }
}

From source file:info.magnolia.objectfactory.configuration.ComponentProviderConfigurationBuilder.java

protected ComponentConfiguration getConfigured(ComponentDefinition definition) {
    ConfiguredComponentConfiguration configuration = new ConfiguredComponentConfiguration();
    configuration.setType(classForName(definition.getType()));
    configuration//from  w w w  .j a  v  a 2 s.c o m
            .setWorkspace(StringUtils.defaultIfEmpty(configuration.getWorkspace(), RepositoryConstants.CONFIG));
    configuration.setPath(definition.getPath());
    configuration.setObserved(false);
    configuration.setScope(definition.getScope());
    configuration.setLazy(parseLazyFlag(definition));
    return configuration;
}

From source file:hudson.plugins.testlink.util.TestLinkHelper.java

/**
 * Creates a Map (name, value) of environment variables for a TestLink Test Case.
 * //from w ww. ja  va2  s  . com
 * @param testCase TestLink test Case.
 * @param testProject TestLink Test Project.
 * @param testPlan TestLink Test Plan.
 * @param build TestLink Build.
 * @return Map (name, value) of environment variables.
 */
public static Map<String, String> createTestLinkEnvironmentVariables(TestCaseWrapper testCase,
        TestProject testProject, TestPlan testPlan, Build build) {
    Map<String, String> testLinkEnvVar = new HashMap<String, String>();

    testLinkEnvVar.put(TESTLINK_TESTCASE_ID_ENVVAR, "" + testCase.getId());
    testLinkEnvVar.put(TESTLINK_TESTCASE_NAME_ENVVAR, StringUtils.defaultIfEmpty(testCase.getName(), ""));
    testLinkEnvVar.put(TESTLINK_TESTCASE_TESTSUITE_ID_ENVVAR, "" + testCase.getTestSuiteId());
    testLinkEnvVar.put(TESTLINK_TESTCASE_TESTPROJECT_ID, "" + testCase.getTestProjectId());
    testLinkEnvVar.put(TESTLINK_TESTCASE_AUTHOR_ENVVAR, "" + testCase.getAuthorLogin());
    testLinkEnvVar.put(TESTLINK_TESTCASE_SUMMARY_ENVVAR, StringUtils.defaultIfEmpty(testCase.getSummary(), ""));
    testLinkEnvVar.put(TESTLINK_BUILD_NAME_ENVVAR, StringUtils.defaultIfEmpty(build.getName(), ""));
    testLinkEnvVar.put(TESTLINK_TESTPLAN_NAME_ENVVAR, StringUtils.defaultIfEmpty(testPlan.getName(), ""));
    testLinkEnvVar.put(TESTLINK_TESTPROJECT_NAME_ENVVAR, StringUtils.defaultIfEmpty(testProject.getName(), ""));

    List<CustomField> customFields = testCase.getCustomFields();
    for (CustomField customField : customFields) {
        addCustomFieldEnvironmentVariableName(customField, testLinkEnvVar);
    }

    List<TestCaseStep> steps = testCase.getSteps();
    testLinkEnvVar.put(TESTLINK_TESTCASE_STEP_PREFIX + "TOTAL", Integer.toString(steps.size()));
    for (TestCaseStep step : steps) {
        String name = TESTLINK_TESTCASE_STEP_PREFIX + step.getNumber() + "_ACTION";
        String action = step.getActions();
        testLinkEnvVar.put(name, action);

        name = TESTLINK_TESTCASE_STEP_PREFIX + step.getNumber() + "_EXPECTED";
        String expected = step.getExpectedResults();
        testLinkEnvVar.put(name, expected);
    }
    return testLinkEnvVar;
}

From source file:gov.nih.nci.caarray.magetab.idf.IdfDocument.java

private void validateMatchingColumns() {
    for (Person aPerson : investigation.getPersons()) {
        if (StringUtils.isEmpty(aPerson.getFirstName()) || StringUtils.isEmpty(aPerson.getLastName())) {
            addWarningMessage("Name is missing : First name = "
                    + StringUtils.defaultIfEmpty(aPerson.getFirstName(), "<MISSING>") + " Last name = "
                    + StringUtils.defaultIfEmpty(aPerson.getLastName(), "<MISSING>"));
        }/*  w w w .ja v  a2  s.  c  o  m*/
    }
    for (Person aPerson : investigation.getPersons()) {
        if (aPerson.getRoles().size() == 0) {
            addWarningMessage("Role is missing for : " + StringUtils.defaultIfEmpty(aPerson.getFirstName(), "")
                    + " " + StringUtils.defaultIfEmpty(aPerson.getLastName(), ""));
        }
    }
    for (TermSource aTermSource : docTermSources) {
        if (StringUtils.isEmpty(aTermSource.getFile())) {
            addWarningMessage("File is missing from term source : " + aTermSource.getName());
        }
        if (StringUtils.isEmpty(aTermSource.getName())) {
            addWarningMessage("No term source associated with the file name : " + aTermSource.getFile());
        }
    }
    for (ExperimentalFactor experimentalFactor : investigation.getFactors()) {
        if (StringUtils.isEmpty(experimentalFactor.getName())) {
            addErrorMessage("Experimental Factors must have a non-empty name");
        }
    }
}

From source file:biblivre3.administration.reports.BaseBiblivreReport.java

protected Chunk getNormalChunk(String text) {
    Chunk chunk = new Chunk(StringUtils.defaultIfEmpty(text, ""));
    chunk.setFont(textFont);
    return chunk;
}

From source file:de.iteratec.iteraplan.businesslogic.common.URLBuilder.java

/**
 * Returns the URL of the IdentityEntity object by using the {@link Dialog} enum in combination
 * with a given server address./* w w w .j ava2  s .co m*/
 * 
 * @param entity
 *          An IdentityEntity object.
 * @param serverURL
 *          The known server + application url. Should look like https://127.0.0.1:8443/iteraplan
 * @param representation
 *          The presentation form of the entity that should be linked to
 * @return The URL of the BuildingBlock object as String.
 */
public static String getEntityURL(IdentityEntity entity, String serverURL,
        EntityRepresentation representation) {
    StringBuilder url = new StringBuilder(BUFFER_SIZE);

    // iteraplan properties are checked for server address override
    url.append(StringUtils.defaultIfEmpty(APPLICATION_ADDRESS_FROM_PROPERTIES, serverURL));

    LOGGER.info("The application address from the properties is: " + APPLICATION_ADDRESS_FROM_PROPERTIES);
    LOGGER.info("URL created from the application address: " + url.toString());

    IdEntity linkTarget = deriveLinkTarget(entity);

    String type = Dialog.dialogNameForClass(linkTarget.getClass());
    if (type == null) { // entity class is still unknown --> no link
        return "";
    }
    type = type.toLowerCase(Locale.ENGLISH);
    url.append(FLOW_MAPPING);
    url.append(type);
    url.append(FORWARD_SLASH);
    url.append(representation.getUriComponent());
    url.append(linkTarget.getId());

    return url.toString();
}

From source file:com.gst.infrastructure.core.api.JsonQuery.java

public String stringValueOfParameterNamed(final String parameterName) {
    final String value = this.fromApiJsonHelper.extractStringNamed(parameterName, this.parsedQuery);
    return StringUtils.defaultIfEmpty(value, "");
}

From source file:ezbake.deployer.configuration.EzDeployerConfiguration.java

public String getUserFacingDomain() {
    WebApplicationConfigurationHelper webApp = new WebApplicationConfigurationHelper(configuration);
    return StringUtils.defaultIfEmpty(webApp.getExternalFacingDomain(), "example.local");
}