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:com.afousan.controller.CookieInterceptor.java

@Override
public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler)
        throws Exception {
    // all non-root requests get analyzed
    Cookie[] cookies = request.getCookies();

    if (!ObjectUtils.isEmpty(cookies)) {
        for (Cookie cookie : cookies) {
            if (RETWIS_COOKIE.equals(cookie.getName())) {
                String auth = cookie.getValue();
                String name = twitter.findNameForAuth(auth);
                if (name != null) {
                    String uid = twitter.findUid(name);
                    RetwisSecurity.setUser(name, uid);
                }/*from  w w w .j a v a2s . c  om*/
            }
        }
    }
    return true;
}

From source file:net.nikey.interceptor.LoginRequiredInterceptor.java

@Override
public Object before(Invocation inv) throws Exception {
    // all non-root requests get analyzed
    Cookie[] cookies = inv.getRequest().getCookies();
    if (!ObjectUtils.isEmpty(cookies)) {
        for (Cookie cookie : cookies) {
            if (RETWIS_COOKIE.equals(cookie.getName())) {
                String auth = cookie.getValue();
                String name = user.findNameForAuth(auth);
                if (StringUtils.hasText(name)) {
                    String uid = user.findUid(name);
                    if (StringUtils.hasText(uid)) {
                        inv.addModel("isSignedIn", true);
                        inv.addModel("uid", uid);
                        NikeySecurity.setUser(name, uid);
                        return super.before(inv);
                    }/*from  www .j  av  a2s . c  om*/
                }
            }
        }
    }
    inv.addModel("isSignedIn", false);
    return super.before(inv);
}

From source file:jp.xet.uncommons.web.env.EnvironmentProfileApplicationContextInitializer.java

@Override
public void initialize(ConfigurableApplicationContext applicationContext) {
    ConfigurableEnvironment environment = applicationContext.getEnvironment();

    String[] activeProfiles = environment.getActiveProfiles();
    if (ObjectUtils.isEmpty(activeProfiles)) {
        String propEnvironment = environment.getProperty("environment");
        if (Strings.isNullOrEmpty(propEnvironment)) {
            environment.setActiveProfiles("development");
            logger.warn("Spring active profiles are not specified.  Set default value [{}]", DEFAULT_PROFILE);
        } else {/*from w ww  .j a v a  2s .  c o  m*/
            environment.setActiveProfiles(propEnvironment);
            logger.info("Set Spring active profiles to [{}]", propEnvironment);
        }
    } else {
        logger.info("Spring active profiles [{}]", activeProfiles);
    }
}

From source file:net.javacrumbs.springws.test.common.SchemaValidator.java

public void validate(WebServiceMessage message, XmlValidator validator) throws IOException {
    Source requestSource = message.getPayloadSource();
    if (requestSource != null) {
        SAXParseException[] errors = validator.validate(requestSource);
        if (!ObjectUtils.isEmpty(errors)) {
            handleRequestValidationErrors(message, errors);
        }//w  w  w.ja v  a2  s. c om
        logger.debug("Request message validated");
    } else {
        logger.warn("Request source is null");
    }
}

From source file:org.springmodules.jcr.jackrabbit.JackrabbitSessionFactory.java

protected void registerNodeTypes() throws Exception {
    if (!ObjectUtils.isEmpty(nodeDefinitions)) {
        Workspace ws = getSession().getWorkspace();

        // Get the NodeTypeManager from the Workspace.
        // Note that it must be cast from the generic JCR NodeTypeManager to
        // the/*from   w w w.  j  av  a2s . co m*/
        // Jackrabbit-specific implementation.
        JackrabbitNodeTypeManager nodeTypeManager = (JackrabbitNodeTypeManager) ws.getNodeTypeManager();

        boolean debug = log.isDebugEnabled();
        for (int i = 0; i < nodeDefinitions.length; i++) {
            Resource resource = nodeDefinitions[i];
            if (debug)
                log.debug("adding node type definitions from " + resource.getDescription());

            nodeTypeManager.registerNodeTypes(resource.getInputStream(), contentType);
        }
    }
}

From source file:org.eclipse.virgo.ide.beans.core.internal.locate.BlueprintConfigUtils.java

/**
 * Returns the location headers (if any) specified by the Blueprint-Bundle header (if available). The returned
 * Strings can be sent to a {@link org.springframework.core.io.ResourceLoader} for loading the configurations.
 * //from   ww w .  j  a  va  2  s  . c  o m
 * Different from {@link ConfigUtils#getLocationsFromHeader(String, String)} since "," is used for separating
 * clauses while ; is used inside a clause to allow parameters or directives besides paths.
 * 
 * Since the presence of the header, disables any processing this method will return null if the header is not
 * specified, an empty array if it's empty (disabled) or a populated array otherwise.
 */
public static String[] getBlueprintHeaderLocations(Dictionary<String, String> headers) {
    String header = getBlueprintHeader(headers);

    // no header specified
    if (header == null) {
        return null;
    }

    // empty header specified
    if (header.length() == 0) {
        return new String[0];
    }

    List<String> ctxEntries = new ArrayList<String>(4);
    if (StringUtils.hasText(header)) {
        String[] clauses = header.split(COMMA);
        for (String clause : clauses) {
            // split into directives
            String[] directives = clause.split(SEMI_COLON);
            if (!ObjectUtils.isEmpty(directives)) {
                // check if it's a path or not
                for (String directive : directives) {
                    if (!directive.contains(EQUALS)) {
                        ctxEntries.add(directive.trim());
                    }
                }
            }
        }
    }

    // replace * with a 'digestable' location
    for (int i = 0; i < ctxEntries.size(); i++) {
        String ctxEntry = ctxEntries.get(i);
        if (SpringOsgiConfigLocationUtils.CONFIG_WILDCARD.equals(ctxEntry))
            ctxEntry = "/META-INF/spring/*.xml";
    }

    return (String[]) ctxEntries.toArray(new String[ctxEntries.size()]);
}

From source file:io.spring.initializr.actuate.info.DependencyRangesInfoContributor.java

private void contribute(Map<String, Object> details, Dependency d) {
    if (!ObjectUtils.isEmpty(d.getMappings())) {
        Map<String, VersionRange> dep = new LinkedHashMap<>();
        d.getMappings().forEach((it) -> {
            if (it.getRange() != null && it.getVersion() != null) {
                dep.put(it.getVersion(), it.getRange());
            }//from   www.  jav a  2 s.co  m
        });
        if (!dep.isEmpty()) {
            if (d.getRange() == null) {
                boolean openRange = dep.values().stream().anyMatch((v) -> v.getHigherVersion() == null);
                if (!openRange) {
                    Version higher = getHigher(dep);
                    dep.put("managed", new VersionRange(higher));
                }
            }
            Map<String, Object> depInfo = new LinkedHashMap<>();
            dep.forEach((k, r) -> {
                depInfo.put(k, "Spring Boot " + r);
            });
            details.put(d.getId(), depInfo);
        }
    } else if (d.getVersion() != null && d.getRange() != null) {
        Map<String, Object> dep = new LinkedHashMap<>();
        String requirement = "Spring Boot " + d.getRange();
        dep.put(d.getVersion(), requirement);
        details.put(d.getId(), dep);
    }
}

From source file:org.statefulj.demo.ddd.config.MVCInitializer.java

@Override
protected void registerDispatcherServlet(ServletContext servletContext) {
    String servletName = getServletName();

    WebApplicationContext servletAppContext = createServletApplicationContext();

    DispatcherServlet dispatcherServlet = new DispatcherServlet(servletAppContext);

    // throw NoHandlerFoundException to Controller when a User requests a non-existent page
    ///*from w  w w.ja  va2  s. c o m*/
    dispatcherServlet.setThrowExceptionIfNoHandlerFound(true);

    ServletRegistration.Dynamic registration = servletContext.addServlet(servletName, dispatcherServlet);

    registration.setLoadOnStartup(1);
    registration.addMapping(getServletMappings());
    registration.setAsyncSupported(isAsyncSupported());

    Filter[] filters = getServletFilters();
    if (!ObjectUtils.isEmpty(filters)) {
        for (Filter filter : filters) {
            registerServletFilter(servletContext, filter);
        }
    }

    customizeRegistration(registration);
}

From source file:com.autentia.wuija.security.SecurityUtils.java

/**
 * Internal function to check if the current user is in one or all roles listed
 * <p>/*from   w w  w. ja  va  2s.  c o  m*/
 * If the list of roles is null or empty, this method returns true.
 * 
 * @param inclusive if <code>true</code>, the user must to be in all the roles, if <code>false</code> the user must
 *            be in at least one of the roles
 * @param roles the list of roles to check
 * @return <code>true</code> if the user match the condition or the list of roles is empty, <code>false</code> in
 *         other case.
 */
// XXX [wuija] ya que los roles son del usuario, parece que tendria mas sentido segun el patron experto que esto estuviera en el usuario
public static boolean matchUserRoles(UserDetails user, boolean inclusive, String... roles) {
    if (user == null) {
        return false;
    }
    if (ObjectUtils.isEmpty(roles)) {
        return true;
    }
    boolean isInRole = false;
    for (String role : roles) {
        isInRole = isUserInSingleRole(user, role);
        if ((inclusive && !isInRole) || (!inclusive && isInRole)) {
            break;
        }
    }
    return isInRole;
}

From source file:kr.co.skysoft.framework.dbms.ibatis.FwSqlMapClientFactoryBean.java

protected SqlMapClient buildSqlMapClient(Resource[] configLocations, Resource[] mappingLocations,
        Properties properties) throws IOException {

    if (ObjectUtils.isEmpty(configLocations)) {
        throw new IllegalArgumentException("At least 1 'configLocation' entry is required");
    }//ww w .  j a  v  a  2 s .  co m

    SqlMapClient client = null;
    FwSqlMapConfigParser configParser = new FwSqlMapConfigParser();
    for (Resource configLocation : configLocations) {
        InputStream is = configLocation.getInputStream();
        try {
            client = configParser.parse(is, properties);
        } catch (RuntimeException ex) {
            //SqlMap? ?  ???? ?   ? ?  ?? 
            logger.error("##### Failed to parse config resource: " + configLocation, ex);
        }
    }

    if (mappingLocations != null) {
        SqlMapParser mapParser = SqlMapParserFactory.createSqlMapParser(configParser);
        for (Resource mappingLocation : mappingLocations) {
            try {
                mapParser.parse(mappingLocation.getInputStream());
            } catch (NodeletException ex) {
                throw new NestedIOException("Failed to parse mapping resource: " + mappingLocation, ex);
            }
        }
    }

    return client;
}