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.cms.gui.controlx.list.ListControl.java

/**
 * @see info.magnolia.cms.gui.controlx.list.ListModel#getSortByOrder()
 *//*from   w w w .j av a  2  s . co  m*/
public String getSortByOrder() {
    return StringUtils.defaultIfEmpty(this.model.getSortByOrder(), "asc");
}

From source file:de.iteratec.iteraplan.businesslogic.exchange.legacyExcel.importer.ObjectRelatedPermissionsWorkbook.java

/**
 * Imports the data out of the specified Excel file input stream. If data
 * could not be imported, an {@code empty} list will be returned.
 * /*from   w  ww.ja va 2 s .  com*/
 * @param is the Excel file input stream
 * @return the list of imported object related permission data objects
 */
public List<ObjectRelatedPermissionsData> doImport(InputStream is) {
    List<ObjectRelatedPermissionsData> result = Lists.newArrayList();

    loadWorkbookFromInputStream(is);

    if (!readInConfigSheet()) {
        getProcessingLog().error("Could not read in configuration sheet. Aborting.");
        return result;
    }

    calculateAllFormulas();
    final Map<String, TypeOfBuildingBlock> supportedSheetNames = getSupportedSheetNames();
    for (int i = 0; i < getWb().getNumberOfSheets(); i++) {
        Sheet sheet = getWb().getSheetAt(i);
        String sheetName = sheet.getSheetName();

        getProcessingLog().debug("Current Sheet: " + StringUtils.defaultIfEmpty(sheetName, "null"));

        if (supportedSheetNames.containsKey(sheetName)) {
            List<ObjectRelatedPermissionsData> sheetObjectPerrmissions = importSheet(sheet,
                    supportedSheetNames.get(sheetName));
            result.addAll(sheetObjectPerrmissions);
        } else if (!DEFAULT_SHEET_KEY.equals(sheetName)) {
            getProcessingLog().warn("Unknown Sheet Name '" + sheetName + "'(different Locale?). Skipping.");
        }
    }

    return result;
}

From source file:com.cognifide.aemrules.extensions.RulesLoader.java

private void loadParameters(RulesDefinition.NewRule rule, Field field) {
    org.sonar.check.RuleProperty propertyAnnotation = field.getAnnotation(org.sonar.check.RuleProperty.class);
    if (propertyAnnotation != null) {
        String fieldKey = StringUtils.defaultIfEmpty(propertyAnnotation.key(), field.getName());
        RulesDefinition.NewParam param = rule.createParam(fieldKey)
                .setDescription(propertyAnnotation.description())
                .setDefaultValue(propertyAnnotation.defaultValue());

        if (!StringUtils.isBlank(propertyAnnotation.type())) {
            try {
                param.setType(RuleParamType.parse(propertyAnnotation.type().trim()));
            } catch (IllegalArgumentException e) {
                throw new IllegalArgumentException("Invalid property type [" + propertyAnnotation.type() + "]",
                        e);/* w ww .  j ava  2  s  .c  om*/
            }
        } else {
            param.setType(guessType(field.getType()));
        }
    }
}

From source file:ch.admin.suis.msghandler.config.Inbox.java

@Override
public String toString() {

    return MessageFormat.format(
            "name: {0}; transparent: {1}; types of the incoming messages: {2}; sedex ID of the receiver: {3};",
            //        StringUtils.defaultIfEmpty(getDirectory(), ClientCommons.NOT_SPECIFIED),
            getDirectory(), mode,/*from   ww  w  .j  a va 2s  . co m*/
            StringUtils.defaultIfEmpty(MessageType.collectionToString(types), ClientCommons.NOT_SPECIFIED),
            StringUtils.defaultIfEmpty(getSedexId(), ClientCommons.NOT_SPECIFIED));
}

From source file:jp.co.tis.gsp.tools.dba.mojo.ImportSchemaMojo.java

private ImportParams createImportParams() {
    String importFilename = StringUtils.defaultIfEmpty(dmpFile, schema + ".dmp");
    File importFile = new File(inputDirectory, importFilename);

    ImportParams param = new ImportParams();

    param.setUser(user);// w ww  .  j  a va  2 s  . c  o  m
    param.setPassword(password);
    param.setAdminUser(adminUser);
    param.setAdminPassword(adminPassword);
    param.setSchema(schema);
    param.setDelimiter(delimiter);
    param.setCharset(UTF8);
    param.setOnError(onError);
    param.setInputDirectory(inputDirectory);
    param.setDumpFile(importFile);
    param.setLogger(getLog());

    return param;
}

From source file:com.appleframework.monitor.model.MetricDog.java

public List<Alert> work(Project project) {
    List<Alert> alerts = Lists.newArrayList();
    for (String metric : project.findMetricNames()) {
        if (StringUtils.equals(metric, metricName)) {
            MetricValue metricValue = project.findLastMetric(metricName);
            String cacheKey = project.getName() + "_" + this.getName() + "_" + metricName
                    + metricValue.getTimeStamp();
            logger.debug("current value={} ,dog={}", metricValue.getValue(), this);
            //??//from   w ww . j  a  va2 s  .  co m
            if (hasFireMetrics.containsKey(cacheKey)) {
                logger.debug("this value has fire,just ignore {}", cacheKey);
                continue;
            } else {
                hasFireMetrics.put(cacheKey, true);
            }
            boolean fire = bite(metricValue.getValue());
            if (fire) {
                Alert alert = new Alert();
                alert.setTitle(String.format("?%s->%s", project.getAlias(), name));

                String _desc = StringUtils.defaultIfEmpty(desc, "");
                String _content = StringUtils.defaultIfEmpty(metricValue.getContent(), "");
                alert.setIp(metricValue.getIp() != null ? metricValue.getIp() : "127.0.0.1");
                alert.setContent(String.format("%s:?=%s %s %s \n\n %s \n %s", metricName,
                        metricValue.getValue(), operator, targetValue, _desc, _content));
                alert.setProjectName(project.getName());
                alert.setMetricDog(this);
                String _level = fixLevel(project, alert);
                alert.setLevel(_level);
                alerts.add(alert);

            } else {
                //?0
                resetFireTimes(project.getName(), metricName);
            }
        }
    }
    return alerts;
}

From source file:com.gst.infrastructure.jobs.domain.ScheduledJobDetail.java

public Map<String, Object> update(final JsonCommand command) {
    final Map<String, Object> actualChanges = new LinkedHashMap<>(9);

    if (command.isChangeInStringParameterNamed(SchedulerJobApiConstants.displayNameParamName,
            this.jobDisplayName)) {
        final String newValue = command
                .stringValueOfParameterNamed(SchedulerJobApiConstants.displayNameParamName).trim();
        actualChanges.put(SchedulerJobApiConstants.displayNameParamName, newValue);
        this.jobDisplayName = StringUtils.defaultIfEmpty(newValue, null);
    }/*from   ww  w .  ja v a 2s  .  c o  m*/
    if (command.isChangeInStringParameterNamed(SchedulerJobApiConstants.cronExpressionParamName,
            this.cronExpression)) {
        final String newValue = command
                .stringValueOfParameterNamed(SchedulerJobApiConstants.cronExpressionParamName).trim();
        actualChanges.put(SchedulerJobApiConstants.cronExpressionParamName, newValue);
        this.cronExpression = StringUtils.defaultIfEmpty(newValue, null);
    }

    if (command.isChangeInBooleanParameterNamed(SchedulerJobApiConstants.jobActiveStatusParamName,
            this.activeSchedular)) {
        final boolean newValue = command
                .booleanPrimitiveValueOfParameterNamed(SchedulerJobApiConstants.jobActiveStatusParamName);
        actualChanges.put(SchedulerJobApiConstants.jobActiveStatusParamName, newValue);
        this.activeSchedular = newValue;
    }

    return actualChanges;
}

From source file:com.opengamma.component.tool.AbstractToolWithoutContext.java

/**
 * Initializes and runs the tool from standard command-line arguments.
 * <p>//  w  w w  .  j  a  v  a2 s  .c o  m
 * The base class defined three options:<br />
 * l/logback - the logback configuration, default tool-logback.xml<br />
 * h/help - prints the help tool<br />
 * 
 * @param args the command-line arguments, not null
 * @param defaultLogbackResource the default logback resource, null to use tool-logback.xml as the default
 * @return true if successful, false otherwise
 */
public boolean initAndRun(String[] args, String defaultLogbackResource) {
    ArgumentChecker.notNull(args, "args");

    Options options = createOptions();
    CommandLineParser parser = new PosixParser();
    CommandLine line;
    try {
        line = parser.parse(options, args);
    } catch (ParseException e) {
        usage(options);
        return false;
    }
    _commandLine = line;
    if (line.hasOption(HELP_OPTION)) {
        usage(options);
        return true;
    }
    String logbackResource = line.getOptionValue(LOGBACK_RESOURCE_OPTION);
    logbackResource = StringUtils.defaultIfEmpty(logbackResource, getDefaultLogbackConfiguration());

    return init(logbackResource) && run();
}

From source file:com.gst.infrastructure.codes.domain.CodeValue.java

public Map<String, Object> update(final JsonCommand command) {

    final Map<String, Object> actualChanges = new LinkedHashMap<>(2);

    final String labelParamName = CODEVALUE_JSON_INPUT_PARAMS.NAME.getValue();
    if (command.isChangeInStringParameterNamed(labelParamName, this.label)) {
        final String newValue = command.stringValueOfParameterNamed(labelParamName);
        actualChanges.put(labelParamName, newValue);
        this.label = StringUtils.defaultIfEmpty(newValue, null);
    }/*from w w w  .j  a  v a  2  s . c om*/

    final String decriptionParamName = CODEVALUE_JSON_INPUT_PARAMS.DESCRIPTION.getValue();
    if (command.isChangeInStringParameterNamed(decriptionParamName, this.description)) {
        final String newValue = command.stringValueOfParameterNamed(decriptionParamName);
        actualChanges.put(decriptionParamName, newValue);
        this.description = StringUtils.defaultIfEmpty(newValue, null);
    }

    final String positionParamName = CODEVALUE_JSON_INPUT_PARAMS.POSITION.getValue();
    if (command.isChangeInIntegerSansLocaleParameterNamed(positionParamName, this.position)) {
        final Integer newValue = command.integerValueSansLocaleOfParameterNamed(positionParamName);
        actualChanges.put(positionParamName, newValue);
        this.position = newValue.intValue();
    }

    final String isActiveParamName = CODEVALUE_JSON_INPUT_PARAMS.IS_ACTIVE.getValue();
    if (command.isChangeInBooleanParameterNamed(isActiveParamName, this.isActive)) {
        final Boolean newValue = command.booleanPrimitiveValueOfParameterNamed(isActiveParamName);
        actualChanges.put(isActiveParamName, newValue);
        this.isActive = newValue.booleanValue();
    }

    return actualChanges;
}

From source file:edu.samplu.admin.test.DocumentSearchURLParametersIT.java

@Before
public void setUp() throws Exception {
    driver = new RemoteWebDriver(new URL("http://localhost:4444/wd/hub"), DesiredCapabilities.firefox());
    // default to locally running dev sampleapp
    base = StringUtils.defaultIfEmpty(System.getProperty("remote.public.url"), "http://localhost:8080/kr-dev");
}