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:org.apache.solr.handler.component.AlfrescoHttpShardHandlerFactory.java

/**
 * Rebuilds the URL replacing the URL scheme of the passed URL with the
 * configured scheme replacement.If no scheme was configured, the passed URL's
 * scheme is left alone./* w  w w. ja v  a2s.c o m*/
 */
private String buildUrl(String url) {
    if (!URLUtil.hasScheme(url)) {
        return StringUtils.defaultIfEmpty(scheme, DEFAULT_SCHEME) + "://" + url;
    } else if (StringUtils.isNotEmpty(scheme)) {
        return scheme + "://" + URLUtil.removeScheme(url);
    }

    return url;
}

From source file:org.apache.zeppelin.sap.UniverseInterpreter.java

@Override
public void open() throws InterpreterException {
    String user = getProperty("universe.user");
    String password = getProperty("universe.password");
    String apiUrl = getProperty("universe.api.url");
    String authType = getProperty("universe.authType");
    final int queryTimeout = Integer
            .parseInt(StringUtils.defaultIfEmpty(getProperty("universe.queryTimeout"), "7200000"));
    this.client = new UniverseClient(user, password, apiUrl, authType, queryTimeout);
    this.universeUtil = new UniverseUtil();
}

From source file:org.apache.zeppelin.sap.UniverseInterpreter.java

private int getMaxConcurrentConnection() {
    return Integer.valueOf(StringUtils.defaultIfEmpty(getProperty(CONCURRENT_EXECUTION_COUNT), "10"));
}

From source file:org.archive.modules.extractor.JerichoExtractorHTML.java

protected void processForm(CrawlURI curi, Element element) {
    String action = element.getAttributeValue("action");
    String name = element.getAttributeValue("name");
    String queryURL = "";

    final boolean ignoreFormActions = getIgnoreFormActionUrls();

    if (ignoreFormActions) {
        return;/*from   w  ww . java2  s .co m*/
    }

    // method-sensitive extraction
    String method = StringUtils.defaultIfEmpty(element.getAttributeValue("method"), "GET");
    if (getExtractOnlyFormGets() && !"GET".equalsIgnoreCase(method)) {
        return;
    }
    numberOfFormsProcessed.incrementAndGet();

    // get all form fields
    for (FormField formField : (Iterable<FormField>) element.findFormFields()) {
        // for each form control
        for (FormControl formControl : (Iterable<FormControl>) formField.getFormControls()) {
            // get name of control element (and URLEncode it)
            String controlName = formControl.getName();

            // retrieve list of values - submit needs special handling
            Collection<String> controlValues;
            if (!(formControl.getFormControlType() == FormControlType.SUBMIT)) {
                controlValues = formControl.getValues();
            } else {
                controlValues = formControl.getPredefinedValues();
            }

            if (controlValues.size() > 0) {
                // for each value set
                for (String value : controlValues) {
                    queryURL += "&" + controlName + "=" + value;
                }
            } else {
                queryURL += "&" + controlName + "=";
            }
        }
    }

    // clean up url
    if (action == null) {
        queryURL = queryURL.replaceFirst("&", "?");
    } else {
        if (!action.contains("?"))
            queryURL = queryURL.replaceFirst("&", "?");
        queryURL = action + queryURL;
    }

    CharSequence context = elementContext(element.getName(), "name=" + name);
    processLink(curi, queryURL, context);

}

From source file:org.bsc.maven.plugin.findclass.DependencyWrapper.java

public boolean matches(final Artifact artifact) {
    ArtifactVersion version;//from w w w .  j a  v a 2s .  c o m

    try {
        if (artifact.getVersionRange() != null) {
            version = artifact.getSelectedVersion();
        } else {
            version = new DefaultArtifactVersion(artifact.getVersion());
        }
    } catch (final OverConstrainedVersionException ex) {
        return false;
    }

    return StringUtils.equals(dependency.getGroupId(), artifact.getGroupId())
            && StringUtils.equals(dependency.getArtifactId(), artifact.getArtifactId())
            && StringUtils.equals(StringUtils.defaultIfEmpty(dependency.getType(), "jar"),
                    StringUtils.defaultIfEmpty(artifact.getType(), "jar"))
            && StringUtils.equals(dependency.getClassifier(), artifact.getClassifier())
            && (versionRange == null || versionRange.containsVersion(version)
                    || StringUtils.equals(artifact.getVersion(), dependency.getVersion()));
}

From source file:org.candlepin.client.CLIMain.java

private Configuration loadConfig(CommandLine cmdLine) {
    Properties pr = Utils.getDefaultProperties();
    L.debug("Loaded default config values : {}", Utils.toStr(pr));
    try {// www . j  a  v  a  2s  .co  m
        String loc = cmdLine.getOptionValue("cfg");
        File file = new File(StringUtils.defaultIfEmpty(loc, Constants.DEFAULT_CONF_LOC));
        // config file exists
        if (file.exists() && file.canRead() && !file.isDirectory()) {
            L.debug("Config file {} exists. Trying to load values", file.getAbsolutePath());
            Properties conf = new Properties();
            FileInputStream inputStream = new FileInputStream(file);
            conf.load(inputStream);
            L.debug("Loaded config from file {}", file.getAbsolutePath());
            pr = conf;
        } else {
            L.debug("Config file {} does not exist. " + "Trying to load values from System.getProperty()",
                    file.getAbsolutePath());
            /*
             * config file not found. Try getting values from from system
             * environment
             */
            tryStoringSystemProperty(pr, Constants.SERVER_URL_KEY);
            tryStoringSystemProperty(pr, Constants.CP_HOME_DIR);
            tryStoringSystemProperty(pr, Constants.CP_CERT_LOC);
        }
    } catch (IOException e) {
        // cannot and should not happen since
        // defaultValues.properties is within the jar file
        L.error("Exception trying to load config information", e);
        System.err.println("Unable to load configuration information.");
        System.exit(0);
    }
    L.info("Config info: {}", Utils.toStr(pr));
    return new Configuration(pr);
}

From source file:org.candlepin.client.CLIMain.java

/**
 * Try storing system property.//from  www.  j  av  a  2 s  .c o  m
 *
 * @param properties the properties
 * @param key the key
 */
private void tryStoringSystemProperty(Properties properties, String key) {
    String value = properties.getProperty(key);
    properties.setProperty(key, StringUtils.defaultIfEmpty(getProperty(key), value));
}

From source file:org.candlepin.client.cmds.SubscribeCommand.java

@Override
protected void execute(CommandLine cmdLine, CandlepinClientFacade client) {
    String[] pools = cmdLine.getOptionValues("p");
    String[] products = cmdLine.getOptionValues("pr");
    String[] regTokens = cmdLine.getOptionValues("r");
    int[] quantity = Utils.toInt(cmdLine.getOptionValues("q"));
    String email = cmdLine.getOptionValue("e");
    String defLocale = StringUtils.defaultIfEmpty(cmdLine.getOptionValue("l"), SystemUtils.USER_LANGUAGE);
    int iter = 0;
    if (!this.getClient().isRegistered()) {
        System.out.println("This system is currently not registered.");
        return;//from   ww  w  . j a  v a 2  s  .c  o m
    }
    if (isEmpty(pools) && isEmpty(products) && isEmpty(regTokens)) {
        System.err.println("Error: Need either --product or --pool" + " or --regtoken, Try --help");
        return;
    }
    if (!isEmpty(pools)) {
        for (String pool : pools) {
            client.bindByPool(pool.trim(), Utils.getSafeInt(quantity, iter++, 1));
        }
    }

    if (!isEmpty(products)) {
        for (String product : products) {
            client.bindByProductId(product, Utils.getSafeInt(quantity, iter++, 1));
        }
    }

    if (!isEmpty(regTokens)) {
        for (String token : regTokens) {
            if (StringUtils.isNotBlank(email)) {
                client.bindByRegNumber(token, Utils.getSafeInt(quantity, iter++, 1), email, defLocale);
            } else {
                client.bindByRegNumber(token, Utils.getSafeInt(quantity, iter++, 1));
            }
        }
    }
    client.updateEntitlementCertificates();
}

From source file:org.carewebframework.vista.security.base.BaseAuthenticationProvider.java

@SuppressWarnings("deprecation")
private void checkAuthResult(AuthResult result, IUser user) throws AuthenticationException {
    switch (result.status) {
    case SUCCESS:
        return;//from  ww w . j a va  2  s . co  m

    case CANCELED:
        throw new AuthenticationCancelledException(
                StringUtils.defaultIfEmpty(result.reason, "Authentication attempt was cancelled."));

    case EXPIRED:
        throw new CredentialsExpiredException(
                StringUtils.defaultIfEmpty(result.reason, "Your password has expired."), user);

    case FAILURE:
        throw new BadCredentialsException(
                StringUtils.defaultIfEmpty(result.reason, "Your username or password was not recognized."));

    case LOCKED:
        throw new LockedException(StringUtils.defaultIfEmpty(result.reason,
                "Your user account has been locked and cannot be accessed."));

    case NOLOGINS:
        throw new DisabledException(
                StringUtils.defaultIfEmpty(result.reason, "Logins are currently disabled."));
    }
}

From source file:org.carrot2.core.benchmarks.memtime.MemTimeBenchmark.java

/**
 * Index documents in-memory using Lucene.
 */// www. j a va 2  s .c  o m
private void luceneIndex(List<Document> inputList) {
    try {
        Directory dir = new RAMDirectory();
        IndexWriterConfig config = new IndexWriterConfig(new StandardAnalyzer());
        IndexWriter w = new IndexWriter(dir, config);

        for (Document d : inputList) {
            final org.apache.lucene.document.Document nd = new org.apache.lucene.document.Document();
            nd.add(new TextField("title", StringUtils.defaultIfEmpty(d.getTitle(), ""), Store.NO));
            nd.add(new TextField("snippet", StringUtils.defaultIfEmpty(d.getSummary(), ""), Store.NO));
            w.addDocument(nd);
        }

        w.close();
    } catch (IOException e) {
        throw new RuntimeException(e);
    }
}