Example usage for org.springframework.util ObjectUtils isEmpty

List of usage examples for org.springframework.util ObjectUtils isEmpty

Introduction

In this page you can find the example usage for org.springframework.util ObjectUtils isEmpty.

Prototype

@SuppressWarnings("rawtypes")
public static boolean isEmpty(@Nullable Object obj) 

Source Link

Document

Determine whether the given object is empty.

Usage

From source file:org.springframework.web.servlet.i18n.LocaleChangeInterceptor.java

private boolean checkHttpMethod(String currentMethod) {
    String[] configuredMethods = getHttpMethods();
    if (ObjectUtils.isEmpty(configuredMethods)) {
        return true;
    }/*from   w w w.ja  v a 2s  .c o m*/
    for (String configuredMethod : configuredMethods) {
        if (configuredMethod.equalsIgnoreCase(currentMethod)) {
            return true;
        }
    }
    return false;
}

From source file:org.springframework.web.servlet.mvc.method.annotation.AbstractJsonpResponseBodyAdvice.java

protected AbstractJsonpResponseBodyAdvice(String... queryParamNames) {
    Assert.isTrue(!ObjectUtils.isEmpty(queryParamNames), "At least one query param name is required");
    this.jsonpQueryParamNames = queryParamNames;
}

From source file:org.springframework.web.servlet.mvc.method.annotation.MvcUriComponentsBuilder.java

private static String getTypeRequestMapping(Class<?> controllerType) {
    Assert.notNull(controllerType, "'controllerType' must not be null");
    RequestMapping requestMapping = AnnotatedElementUtils.findMergedAnnotation(controllerType,
            RequestMapping.class);
    if (requestMapping == null) {
        return "/";
    }//from  w  ww. j  a v a 2 s . c o m
    String[] paths = requestMapping.path();
    if (ObjectUtils.isEmpty(paths) || StringUtils.isEmpty(paths[0])) {
        return "/";
    }
    if (paths.length > 1 && logger.isWarnEnabled()) {
        logger.warn("Multiple paths on controller " + controllerType.getName() + ", using first one");
    }
    return paths[0];
}

From source file:org.springframework.web.servlet.mvc.method.annotation.MvcUriComponentsBuilder.java

private static String getMethodRequestMapping(Method method) {
    Assert.notNull(method, "'method' must not be null");
    RequestMapping requestMapping = AnnotatedElementUtils.findMergedAnnotation(method, RequestMapping.class);
    if (requestMapping == null) {
        throw new IllegalArgumentException("No @RequestMapping on: " + method.toGenericString());
    }/*from   w ww.j a v  a2  s. c  o m*/
    String[] paths = requestMapping.path();
    if (ObjectUtils.isEmpty(paths) || StringUtils.isEmpty(paths[0])) {
        return "/";
    }
    if (paths.length > 1 && logger.isWarnEnabled()) {
        logger.warn("Multiple paths on method " + method.toGenericString() + ", using first one");
    }
    return paths[0];
}

From source file:org.springframework.web.servlet.mvc.support.MvcUrlUtils.java

/**
 * Extract the type-level URL mapping or return an empty String. If multiple mappings
 * are found, the first one is used./*from w  ww .  j  a v a2 s .  c om*/
 */
public static String getTypeLevelMapping(Class<?> controllerType) {
    Assert.notNull(controllerType, "'controllerType' must not be null");
    RequestMapping annot = AnnotationUtils.findAnnotation(controllerType, RequestMapping.class);
    if ((annot == null) || ObjectUtils.isEmpty(annot.value())) {
        return "/";
    }
    if (annot.value().length > 1) {
        logger.warn("Multiple class level mappings on " + controllerType.getName() + ", using the first one");
    }
    return annot.value()[0];

}

From source file:org.springframework.web.servlet.resource.ResourceHttpRequestHandler.java

/**
 * Look for a {@code PathResourceResolver} among the configured resource
 * resolvers and set its {@code allowedLocations} property (if empty) to
 * match the {@link #setLocations locations} configured on this class.
 *//*from  ww  w.ja  v  a  2  s  . c  o m*/
protected void initAllowedLocations() {
    if (CollectionUtils.isEmpty(this.locations)) {
        return;
    }
    for (int i = getResourceResolvers().size() - 1; i >= 0; i--) {
        if (getResourceResolvers().get(i) instanceof PathResourceResolver) {
            PathResourceResolver pathResolver = (PathResourceResolver) getResourceResolvers().get(i);
            if (ObjectUtils.isEmpty(pathResolver.getAllowedLocations())) {
                pathResolver.setAllowedLocations(getLocations().toArray(new Resource[getLocations().size()]));
            }
            if (this.urlPathHelper != null) {
                pathResolver.setLocationCharsets(this.locationCharsets);
                pathResolver.setUrlPathHelper(this.urlPathHelper);
            }
            break;
        }
    }
}

From source file:org.springframework.web.socket.sockjs.AbstractSockJsService.java

protected void addCorsHeaders(ServerHttpRequest request, ServerHttpResponse response,
        HttpMethod... httpMethods) {/*from  w  ww .ja v a 2s . com*/

    String origin = request.getHeaders().getFirst("origin");
    origin = ((origin == null) || origin.equals("null")) ? "*" : origin;

    response.getHeaders().add("Access-Control-Allow-Origin", origin);
    response.getHeaders().add("Access-Control-Allow-Credentials", "true");

    List<String> accessControllerHeaders = request.getHeaders().get("Access-Control-Request-Headers");
    if (accessControllerHeaders != null) {
        for (String header : accessControllerHeaders) {
            response.getHeaders().add("Access-Control-Allow-Headers", header);
        }
    }

    if (!ObjectUtils.isEmpty(httpMethods)) {
        response.getHeaders().add("Access-Control-Allow-Methods",
                StringUtils.arrayToDelimitedString(httpMethods, ", "));
        response.getHeaders().add("Access-Control-Max-Age", String.valueOf(ONE_YEAR));
    }
}

From source file:org.springframework.ws.client.core.WebServiceTemplate.java

/**
 * Initialize the default implementations for the template's strategies: {@link SoapFaultMessageResolver}, {@link
 * org.springframework.ws.soap.saaj.SaajSoapMessageFactory}, and {@link HttpUrlConnectionMessageSender}.
 *
 * @throws BeanInitializationException in case of initalization errors
 * @see #setFaultMessageResolver(FaultMessageResolver)
 * @see #setMessageFactory(WebServiceMessageFactory)
 * @see #setMessageSender(WebServiceMessageSender)
 *///  w  ww.j  av  a 2  s .c  om
protected void initDefaultStrategies() {
    DefaultStrategiesHelper strategiesHelper = new DefaultStrategiesHelper(WebServiceTemplate.class);
    if (getMessageFactory() == null) {
        initMessageFactory(strategiesHelper);
    }
    if (ObjectUtils.isEmpty(getMessageSenders())) {
        initMessageSenders(strategiesHelper);
    }
    if (getFaultMessageResolver() == null) {
        initFaultMessageResolver(strategiesHelper);
    }
}

From source file:org.springframework.ws.server.MessageDispatcher.java

/**
 * Trigger handleResponse or handleFault on the mapped EndpointInterceptors. Will just invoke said method on all
 * interceptors whose handleRequest invocation returned <code>true</code>, in addition to the last interceptor who
 * returned <code>false</code>.
 *
 * @param mappedEndpoint   the mapped EndpointInvocationChain
 * @param interceptorIndex index of last interceptor that was called
 * @param messageContext   the message context, whose request and response are filled
 * @see EndpointInterceptor#handleResponse(MessageContext,Object)
 * @see EndpointInterceptor#handleFault(MessageContext, Object)
 *//*from ww  w .j a v a  2s . co m*/
private void triggerHandleResponse(EndpointInvocationChain mappedEndpoint, int interceptorIndex,
        MessageContext messageContext) throws Exception {
    if (mappedEndpoint != null && messageContext.hasResponse()
            && !ObjectUtils.isEmpty(mappedEndpoint.getInterceptors())) {
        boolean hasFault = false;
        WebServiceMessage response = messageContext.getResponse();
        if (response instanceof FaultAwareWebServiceMessage) {
            hasFault = ((FaultAwareWebServiceMessage) response).hasFault();
        }
        boolean resume = true;
        for (int i = interceptorIndex; resume && i >= 0; i--) {
            EndpointInterceptor interceptor = mappedEndpoint.getInterceptors()[i];
            if (!hasFault) {
                resume = interceptor.handleResponse(messageContext, mappedEndpoint.getEndpoint());
            } else {
                resume = interceptor.handleFault(messageContext, mappedEndpoint.getEndpoint());
            }
        }
    }
}

From source file:org.springframework.yarn.fs.DefaultResourceLocalizer.java

@Override
protected Map<String, LocalResource> doFileTransfer(FileSystem fs) throws Exception {
    Map<String, LocalResource> returned = new HashMap<String, LocalResource>();
    Path resolvedStagingDirectory = resolveStagingDirectory();
    for (TransferEntry e : transferEntries) {
        Path remotePath = (!e.staging) ? new Path(e.path)
                : new Path(resolvedStagingDirectory.toUri().getPath() + e.path);
        FileStatus[] fileStatuses = fs.globStatus(remotePath);
        if (log.isDebugEnabled()) {
            log.debug("Trying path " + remotePath + " glob fileStatus length="
                    + (fileStatuses != null ? fileStatuses.length : "null"));
        }//from  w  ww .  j ava2 s. c  o  m
        if (!ObjectUtils.isEmpty(fileStatuses)) {
            for (FileStatus status : fileStatuses) {
                if (log.isDebugEnabled()) {
                    log.debug("FileStatus=" + status);
                }
                if (status.isFile()) {
                    Path path = status.getPath();
                    LocalResource res = Records.newRecord(LocalResource.class);
                    res.setType(e.type);
                    res.setVisibility(e.visibility);
                    res.setResource(ConverterUtils.getYarnUrlFromPath(path));
                    res.setTimestamp(status.getModificationTime());
                    res.setSize(status.getLen());
                    if (log.isDebugEnabled()) {
                        log.debug("Using path [" + path + "]");
                    }
                    returned.put(status.getPath().getName(), res);
                }
            }
        }
    }
    return returned;
}