Example usage for org.apache.commons.lang3 StringUtils defaultIfBlank

List of usage examples for org.apache.commons.lang3 StringUtils defaultIfBlank

Introduction

In this page you can find the example usage for org.apache.commons.lang3 StringUtils defaultIfBlank.

Prototype

public static <T extends CharSequence> T defaultIfBlank(final T str, final T defaultStr) 

Source Link

Document

Returns either the passed in CharSequence, or if the CharSequence is whitespace, empty ("") or null , the value of defaultStr .

 StringUtils.defaultIfBlank(null, "NULL")  = "NULL" StringUtils.defaultIfBlank("", "NULL")    = "NULL" StringUtils.defaultIfBlank(" ", "NULL")   = "NULL" StringUtils.defaultIfBlank("bat", "NULL") = "bat" StringUtils.defaultIfBlank("", null)      = null 

Usage

From source file:controllers.ExpertApp.java

public static Result searchTag() {
    String st = request().getQueryString("st");
    String p = StringUtils.defaultIfBlank(request().getQueryString("p"), "1|1");
    String type = StringUtils.defaultIfBlank(request().getQueryString("type"), "html");
    ScriptEngine engine = SemUtils.getEngine();
    try {//from   w ww. ja v a  2 s  . c o m
        if (StringUtils.isNotBlank(st))
            st = engine.eval("decodeURIComponent('" + st + "')").toString();
    } catch (ScriptException e) {
        e.printStackTrace();
    }
    Transformer trf = new Transformer(st, p, null, null, null, null, null, null);
    String resultJson = SearchHttpClient.advancedQuery(trf.tranMustTagNVP());
    EPage<ExpertListVO> pageObj = trf.pageFromJson(resultJson, null, Constants.HOME_EXPERT_PAGE_SIZE);
    pageObj.setFt(st);
    if (!type.equals("json")) {
        return ok(views.html.expert.customerservice.render(pageObj));
    } else {
        return ok(play.libs.Json.toJson(pageObj));
    }
}

From source file:io.wcm.caravan.pipeline.extensions.hal.client.action.LoadLink.java

@Override
public String getId() {
    return "LOAD-LINK(" + httpMethod + "-" + serviceId.getServiceId(link.getHref()) + '-'
            + StringUtils.defaultIfBlank(link.getName(), "") + '-' + parameters.hashCode() + ")";
}

From source file:com.crosstreelabs.cognitio.gumshoe.format.HtmlFormatHandler.java

@Override
public void processLinks(final Visit visit) {
    try {//from   w  w  w.j  ava 2 s.  c  o  m
        String charset = StringUtils.defaultIfBlank(visit.contentCharset, "UTF-8");

        Document doc = Jsoup.parse(visit.contentStream, charset, visit.result.location);
        Elements anchors = doc.getElementsByTag("a");

        for (Element e : anchors) {
            String url = stripURLFragmentIdentifier(e.attr("abs:href"));
            String uri = stripURLFragmentIdentifier(e.attr("href").toLowerCase());
            if (uri.isEmpty() || url.isEmpty() || uri.contains("javascript:") || uri.contains("mailto:")
                    || uri.contains("@")) {
                continue;
            }

            visit.discoveredLinks.add(URL.parse(url).toString()); // TODO Need to add the link text as the title
        }
        visit.contentStream.reset();
    } catch (GalimatiasParseException | IOException ex) {
        throw new RuntimeException(ex);
    }
}

From source file:com.github.ferstl.depgraph.dependency.style.AbstractNode.java

void merge(AbstractNode other) {
    this.color = StringUtils.defaultIfBlank(other.color, this.color);
    this.fillColor = StringUtils.defaultIfBlank(other.fillColor, this.fillColor);
    this.style = StringUtils.defaultIfBlank(other.style, this.style);

    this.defaultFont.merge(other.defaultFont);
    this.groupIdFont.merge(other.groupIdFont);
    this.artifactIdFont.merge(other.artifactIdFont);
    this.versionFont.merge(other.versionFont);
    this.scopeFont.merge(other.scopeFont);
}

From source file:com.sonicle.webtop.tasks.TplHelper.java

public static String buildTplTaskReminderBody(ProfileI18n profileI18n, VTask task)
        throws IOException, TemplateException, AddressException {
    MapItem i18n = new MapItem();
    i18n.put("whenStart",
            WT.lookupResource(SERVICE_ID, profileI18n.getLocale(), TasksLocale.TPL_EMAIL_TASK_BODY_WHENSTART));
    i18n.put("whenDue",
            WT.lookupResource(SERVICE_ID, profileI18n.getLocale(), TasksLocale.TPL_EMAIL_TASK_BODY_WHENDUE));
    i18n.put("whenCompleted", WT.lookupResource(SERVICE_ID, profileI18n.getLocale(),
            TasksLocale.TPL_EMAIL_TASK_BODY_WHENCOMPLETED));
    i18n.put("status",
            WT.lookupResource(SERVICE_ID, profileI18n.getLocale(), TasksLocale.TPL_EMAIL_TASK_BODY_STATUS));
    i18n.put("completion",
            WT.lookupResource(SERVICE_ID, profileI18n.getLocale(), TasksLocale.TPL_EMAIL_TASK_BODY_COMPLETION));

    DateTimeFormatter dateFmt = DateTimeUtils.createFormatter(profileI18n.getDateFormat(), DateTimeZone.UTC);
    MapItem item = new MapItem();
    item.put("subject", StringUtils.defaultIfBlank(task.getSubject(), ""));
    item.put("description", StringUtils.defaultIfBlank(task.getDescription(), null));
    item.put("startDate", formatAsDate(task.getStartDate(), dateFmt));
    item.put("dueDate", formatAsDate(task.getDueDate(), dateFmt));
    //evt.put("completedDate", dateFmt.print(task.getCompletedDate()));
    item.put("status", statusToString(profileI18n.getLocale(), task.getStatus()));
    item.put("completion", toCompletionPercentage(task.getCompletionPercentage()));

    MapItem vars = new MapItem();
    vars.put("i18n", i18n);
    vars.put("task", item);

    return WT.buildTemplate(SERVICE_ID, "tpl/email/task-body.html", vars);
}

From source file:ca.uhn.fhir.rest.method.SearchMethodBinding.java

public SearchMethodBinding(Class<? extends IBaseResource> theReturnResourceType, Method theMethod,
        FhirContext theContext, Object theProvider) {
    super(theReturnResourceType, theMethod, theContext, theProvider);
    Search search = theMethod.getAnnotation(Search.class);
    this.myQueryName = StringUtils.defaultIfBlank(search.queryName(), null);
    this.myCompartmentName = StringUtils.defaultIfBlank(search.compartmentName(), null);
    this.myIdParamIndex = MethodUtil.findIdParameterIndex(theMethod, getContext());
    this.myAllowUnknownParams = search.allowUnknownParams();

    Description desc = theMethod.getAnnotation(Description.class);
    if (desc != null) {
        if (isNotBlank(desc.formalDefinition())) {
            myDescription = StringUtils.defaultIfBlank(desc.formalDefinition(), null);
        } else {/*from w ww  .j  a va 2 s  .  c  o m*/
            myDescription = StringUtils.defaultIfBlank(desc.shortDefinition(), null);
        }
    }

    /*
     * Check for parameter combinations and names that are invalid
     */
    List<IParameter> parameters = getParameters();
    // List<SearchParameter> searchParameters = new ArrayList<SearchParameter>();
    for (int i = 0; i < parameters.size(); i++) {
        IParameter next = parameters.get(i);
        if (!(next instanceof SearchParameter)) {
            continue;
        }

        SearchParameter sp = (SearchParameter) next;
        if (sp.getName().startsWith("_")) {
            if (ALLOWED_PARAMS.contains(sp.getName())) {
                String msg = getContext().getLocalizer().getMessage(
                        getClass().getName() + ".invalidSpecialParamName", theMethod.getName(),
                        theMethod.getDeclaringClass().getSimpleName(), sp.getName());
                throw new ConfigurationException(msg);
            }
        }

        // searchParameters.add(sp);
    }
    // for (int i = 0; i < searchParameters.size(); i++) {
    // SearchParameter next = searchParameters.get(i);
    // // next.
    // }

    /*
     * Only compartment searching methods may have an ID parameter
     */
    if (isBlank(myCompartmentName) && myIdParamIndex != null) {
        String msg = theContext.getLocalizer().getMessage(getClass().getName() + ".idWithoutCompartment",
                theMethod.getName(), theMethod.getDeclaringClass());
        throw new ConfigurationException(msg);
    }

}

From source file:io.github.lxgaming.teleportbow.commands.HelpCommand.java

private Text buildDescription(AbstractCommand command) {
    Text.Builder textBuilder = Text.builder();
    textBuilder.append(Text.of(TextColors.AQUA, "Command: ", TextColors.DARK_GREEN,
            StringUtils.capitalize(command.getPrimaryAlias().orElse("unknown"))));
    textBuilder.append(Text.NEW_LINE);
    textBuilder.append(Text.of(TextColors.AQUA, "Description: ", TextColors.DARK_GREEN,
            StringUtils.defaultIfBlank(command.getDescription(), "No description provided")));
    textBuilder.append(Text.NEW_LINE);
    textBuilder.append(Text.of(TextColors.AQUA, "Usage: ", TextColors.DARK_GREEN, "/", Reference.PLUGIN_ID, " ",
            command.getPrimaryAlias().orElse("unknown")));
    if (StringUtils.isNotBlank(command.getUsage())) {
        textBuilder.append(Text.of(" ", TextColors.DARK_GREEN, command.getUsage()));
    }//from www . java 2  s . com

    textBuilder.append(Text.NEW_LINE);
    textBuilder.append(Text.of(TextColors.AQUA, "Permission: ", TextColors.DARK_GREEN,
            StringUtils.defaultIfBlank(command.getPermission(), "None")));
    textBuilder.append(Text.NEW_LINE);
    textBuilder.append(Text.NEW_LINE);
    textBuilder.append(Text.of(TextColors.GRAY, "Click to auto-complete."));
    return textBuilder.build();
}

From source file:com.savoirtech.eos.itest.pax.ManagedServiceFactoryIT.java

@Configuration
public Option[] configure() {
    final String jvmOptions = StringUtils.defaultIfBlank(System.getProperty("jvm.options"), "-Dnoop");
    final String karafVersion = System.getProperty("karaf.version", DEFAULT_KARAF_VERSION);
    final String projectVersion = System.getProperty("project.version");
    return options(
            karafDistributionConfiguration()
                    .frameworkUrl(maven("org.apache.karaf", "apache-karaf", karafVersion).type("tar.gz"))
                    .unpackDirectory(new File("target/karaf")),
            vmOption(jvmOptions), configureConsole().startRemoteShell().ignoreLocalConsole(),
            editConfigurationFileExtend("etc/com.savoirtech.eos.itest.bundle.greeter-1.cfg", "language",
                    "english"),
            editConfigurationFileExtend("etc/com.savoirtech.eos.itest.bundle.greeter-1.cfg", "pattern",
                    "Hello, %s!"),
            editConfigurationFileExtend("etc/com.savoirtech.eos.itest.bundle.greeter-2.cfg", "language",
                    "spanish"),
            editConfigurationFileExtend("etc/com.savoirtech.eos.itest.bundle.greeter-2.cfg", "pattern",
                    "Hola, %s!"),

            features(maven("com.savoirtech.eos", "eos-itest-features", projectVersion).type("xml")
                    .classifier("features"), "eos-itest-bundle"),
            junitBundles(), keepRuntimeFolder(), logLevel(LogLevelOption.LogLevel.WARN));
}

From source file:de.blizzy.documentr.markdown.macro.impl.NeighborsMacro.java

@Override
public String getHtml(IMacroContext macroContext) {

    htmlSerializerContext = macroContext.getHtmlSerializerContext();
    path = htmlSerializerContext.getPagePath();
    if (path != null) {
        Map<String, String> params = Util.parseParameters(macroContext.getParameters());
        try {//from   w w  w  . j  a v a 2s.c  o m
            String childrenStr = StringUtils.defaultIfBlank(params.get("children"), "1"); //$NON-NLS-1$ //$NON-NLS-2$
            if (childrenStr.equals("all")) { //$NON-NLS-1$
                maxChildren = Integer.MAX_VALUE;
            } else {
                maxChildren = Integer.parseInt(childrenStr);
                maxChildren = Math.max(maxChildren, 1);
            }
        } catch (NumberFormatException e) {
            maxChildren = 1;
        }

        pageStore = macroContext.getPageStore();
        permissionEvaluator = macroContext.getPermissionEvaluator();
        locale = macroContext.getLocale();
        messageSource = macroContext.getMessageSource();
        projectName = htmlSerializerContext.getProjectName();
        branchName = htmlSerializerContext.getBranchName();

        Authentication authentication = htmlSerializerContext.getAuthentication();
        reorderAllowed = (locale != null) && (messageSource != null) && permissionEvaluator
                .hasBranchPermission(authentication, projectName, branchName, Permission.EDIT_PAGE);

        if (log.isInfoEnabled()) {
            log.info("rendering neighbors for page: {}/{}/{}, user: {}", //$NON-NLS-1$
                    projectName, branchName, Util.toUrlPagePath(path), authentication.getName());
        }

        Stopwatch stopwatch = new Stopwatch().start();
        try {
            StringBuilder buf = new StringBuilder();
            Page page = getPage(path);
            buf.append("<span class=\"well well-small neighbors pull-right\"><ul class=\"nav nav-list\">") //$NON-NLS-1$
                    .append(printParent(printLinkListItem(page, 1, maxChildren), path));
            if ((locale != null) && (messageSource != null)) {
                String hoverInfoText = messageSource.getMessage("neighborsItemsHoverExpandHelp", null, locale); //$NON-NLS-1$
                buf.append("<div class=\"hover-help\">").append(hoverInfoText).append("</div>"); //$NON-NLS-1$ //$NON-NLS-2$
            }
            buf.append("</ul></span>"); //$NON-NLS-1$
            return buf.toString();
        } catch (IOException e) {
            throw new RuntimeException(e);
        } finally {
            log.trace("rendering neighbors took {} ms", stopwatch.stop().elapsed(TimeUnit.MILLISECONDS)); //$NON-NLS-1$
        }
    } else {
        return null;
    }
}

From source file:com.webbfontaine.valuewebb.irms.action.mail.MailActionHandler.java

private String getFrom(MailActionDef event) {
    return StringUtils.defaultIfBlank(event.getFrom(), applicationProperties.getEmailFrom());
}