Example usage for com.google.common.base Strings emptyToNull

List of usage examples for com.google.common.base Strings emptyToNull

Introduction

In this page you can find the example usage for com.google.common.base Strings emptyToNull.

Prototype

@Nullable
public static String emptyToNull(@Nullable String string) 

Source Link

Document

Returns the given string if it is nonempty; null otherwise.

Usage

From source file:io.github.bktlib.command.CommandBase.java

/**
 * @return A {@link Command#usage() usage} desse commando
 *//*ww w. j  ava  2  s.co m*/
public Optional<String> getUsage() {
    return Optional.ofNullable(Strings.emptyToNull(commandAnnotation.usage()));
}

From source file:org.osiam.security.controller.LoginController.java

private Optional<String> getErrorMessageFromSession() {
    Object attribute = session.getAttribute(SESSION_ERROR_KEY);
    if (attribute == null || !(attribute instanceof String)) {
        return Optional.empty();
    }//from   w  w  w .  j  a  v  a2 s  .c  o m
    String errorMessage = (String) attribute;
    session.removeAttribute(SESSION_ERROR_KEY);
    return Optional.ofNullable(Strings.emptyToNull(errorMessage));
}

From source file:org.jboss.hal.client.bootstrap.endpoint.EndpointManager.java

public void select(Callback callback) {
    this.callback = callback;

    String connect = requestParameter(CONNECT_PARAMETER);
    if (Strings.emptyToNull(connect) != null) {
        // Connect to a server given as a request parameter
        Endpoint endpoint = storage.get(connect);
        if (endpoint != null) {
            logger.info("Try to connect to endpoint '{}'", endpoint.getUrl());
            pingServer(endpoint, new AsyncCallback<Void>() {
                @Override/*from ww  w . j av  a  2  s  .c  o m*/
                public void onFailure(Throwable throwable) {
                    logger.error("Unable to connect to specified endpoint '{}'", endpoint.getUrl());
                    openDialog();
                }

                @Override
                public void onSuccess(Void whatever) {
                    logger.info("Successfully connected to '{}'", endpoint.getUrl());
                    onConnect(endpoint);
                }
            });
        } else {
            logger.error("Unable to get URL for named endpoint '{}' from local storage", connect);
            openDialog();
        }

    } else {
        // Test whether this console is served from a WildFly / EAP instance
        String baseUrl = Endpoints.getBaseUrl();
        String managementEndpoint = baseUrl + MANAGEMENT;
        XMLHttpRequest xhr = new XMLHttpRequest();
        xhr.onload = event -> {
            int status = xhr.status;
            switch (status) {
            case 0:
            case 200:
            case 401:
                if (keycloakPresentAndValid()) {
                    endpoints.useBase(baseUrl);
                    callback.execute();
                } else {
                    checkKeycloakAdapter(baseUrl, keycloakServerJsUrl -> {
                        // if there is a keycloak adapter, call keycloak authentication
                        authKeycloak(getKeycloakAdapterUrl(baseUrl), keycloakServerJsUrl, callback::execute);
                    }, () -> {
                        // if there is no keycloak adapter for wildfly-console, proceed with regular authentication
                        endpoints.useBase(baseUrl);
                        callback.execute();
                    });
                }
                break;
            // TODO Show an error page!
            // case 500:
            //     break;
            default:
                logger.info("Unable to serve HAL from '{}'. Please select a management interface.",
                        managementEndpoint);
                openDialog();
                break;
            }
        };
        xhr.open(GET.name(), managementEndpoint, true);
        xhr.withCredentials = true;
        xhr.send();
    }
}

From source file:org.n52.sos.util.Reference.java

public Reference setRemoteSchema(String remoteSchema) {
    this.remoteSchema = Optional.fromNullable(Strings.emptyToNull(remoteSchema));
    return this;
}

From source file:ratpack.config.internal.module.ServerConfigDeserializer.java

private ServerConfig.Builder builderForBasedir(ObjectNode serverNode, DeserializationContext ctxt)
        throws IOException {
    JsonNode baseDirNode = serverNode.get("baseDir");
    if (baseDirNode != null) {
        if (baseDirNode.isTextual()) {
            return DefaultServerConfigBuilder.baseDir(serverEnvironment, Paths.get(baseDirNode.asText()));
        } else {//from  w  w w  .j ava  2  s  .c om
            throw ctxt.mappingException(ServerConfig.class, baseDirNode.asToken());
        }
    }
    JsonNode baseDirPropsNode = serverNode.get("baseDirProps");
    if (baseDirPropsNode != null) {
        if (baseDirPropsNode.isTextual()) {
            String propertiesPath = Optional.ofNullable(Strings.emptyToNull(baseDirPropsNode.asText()))
                    .orElse(ServerConfig.Builder.DEFAULT_PROPERTIES_FILE_NAME);
            return DefaultServerConfigBuilder.findBaseDirProps(serverEnvironment, propertiesPath);
        } else {
            throw ctxt.mappingException(ServerConfig.class, baseDirPropsNode.asToken());
        }
    }
    return DefaultServerConfigBuilder.noBaseDir(serverEnvironment);
}

From source file:org.fenixedu.bennu.struts.plugin.StrutsAnnotationsPlugIn.java

private static void registerExceptionHandling(final ActionMapping actionMapping, Class<?> actionClass) {
    for (final ExceptionHandling exception : actionClass.getAnnotationsByType(ExceptionHandling.class)) {
        final ExceptionConfig exceptionConfig = new ExceptionConfig();

        Class<? extends Exception> exClass = exception.type();
        Class<? extends ExceptionHandler> handlerClass = exception.handler();

        exceptionConfig.setKey(Strings.emptyToNull(exception.key()));
        exceptionConfig.setHandler(handlerClass.getName());
        exceptionConfig.setType(exClass.getName());

        if (!Strings.isNullOrEmpty(exception.path())) {
            exceptionConfig.setPath(exception.path());
        }// w ww.  j  av a 2s .  co m

        if (!Strings.isNullOrEmpty(exception.scope())) {
            exceptionConfig.setScope(exception.scope());
        }

        actionMapping.addExceptionConfig(exceptionConfig);
    }
}

From source file:com.google.gerrit.httpd.auth.oauth.OAuthSession.java

boolean isOAuthFinal(HttpServletRequest request) {
    return Strings.emptyToNull(request.getParameter("code")) != null;
}

From source file:de.metas.ui.web.window.datatypes.json.JSONOptions.java

private JSONOptions(final Builder builder) {
    adLanguage = builder.getAD_Language();
    showAdvancedFields = builder.isShowAdvancedFields();
    dataFieldsListStr = Strings.emptyToNull(builder.dataFieldsListStr);
    debugShowColumnNamesForCaption = builder.isShowColumnNamesForCaption(false);

    newRecordDescriptorsProvider = builder.getNewRecordDescriptorsProvider();

    documentPermissionsSupplier = builder.getPermissionsSupplier();
}

From source file:org.killbill.billing.plugin.notification.generator.formatters.DefaultInvoiceItemFormatter.java

@Override
public String getPlanName() {
    return MoreObjects.firstNonNull(Strings.emptyToNull(translator.get(item.getPlanName())),
            Strings.nullToEmpty(item.getPlanName()));
}

From source file:com.google.gerrit.server.change.PutTopic.java

@Override
public Object apply(ChangeResource req, Input input)
        throws BadRequestException, AuthException, ResourceConflictException, Exception {
    if (input == null) {
        input = new Input();
    }//  ww w.  j  ava2 s .co  m

    ChangeControl control = req.getControl();
    Change change = req.getChange();
    if (!control.canEditTopicName()) {
        throw new AuthException("changing topic not permitted");
    }

    ReviewDb db = dbProvider.get();
    final String newTopicName = Strings.nullToEmpty(input.topic);
    String oldTopicName = Strings.nullToEmpty(change.getTopic());
    if (!oldTopicName.equals(newTopicName)) {
        String summary;
        if (oldTopicName.isEmpty()) {
            summary = "Topic set to \"" + newTopicName + "\".";
        } else if (newTopicName.isEmpty()) {
            summary = "Topic \"" + oldTopicName + "\" removed.";
        } else {
            summary = String.format("Topic updated from \"%s\" to \"%s\".", oldTopicName, newTopicName);
        }

        ChangeMessage cmsg = new ChangeMessage(
                new ChangeMessage.Key(change.getId(), ChangeUtil.messageUUID(db)),
                ((IdentifiedUser) control.getCurrentUser()).getAccountId(), change.currentPatchSetId());
        StringBuilder msgBuf = new StringBuilder(summary);
        if (!Strings.isNullOrEmpty(input.message)) {
            msgBuf.append("\n\n");
            msgBuf.append(input.message);
        }
        cmsg.setMessage(msgBuf.toString());

        db.changes().atomicUpdate(change.getId(), new AtomicUpdate<Change>() {
            @Override
            public Change update(Change change) {
                change.setTopic(Strings.emptyToNull(newTopicName));
                return change;
            }
        });
        db.changeMessages().insert(Collections.singleton(cmsg));
    }
    return Strings.isNullOrEmpty(newTopicName) ? Response.none() : newTopicName;
}