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.yarn.integration.convert.MindHolderToObjectConverter.java

/**
 * Resolve the class.// ww w.  j  a  va  2  s.  c o m
 *
 * @param type the type
 * @return the class
 */
@SuppressWarnings("unchecked")
private Class<?> resolveClass(String type) {
    String clazzName = type;
    Class<?> clazz = classCache.get(clazzName);

    if (clazz == null) {
        try {
            clazz = ClassUtils.resolveClassName(clazzName, getClass().getClassLoader());
        } catch (IllegalArgumentException e) {
        }
        if (clazz != null) {
            classCache.put(clazzName, (Class<? extends BaseObject>) clazz);
        }
    }
    if (clazz != null) {
        return clazz;
    }

    if (!ObjectUtils.isEmpty(basePackage)) {
        for (String base : basePackage) {
            clazzName = base + "." + type;
            if (log.isDebugEnabled()) {
                log.debug("Trying to resolve type " + type + " as " + clazzName);
            }
            clazz = classCache.get(clazzName);
            if (log.isDebugEnabled() && clazz != null) {
                log.debug("Found " + clazz + " from a cache");
            }
            if (clazz == null) {
                try {
                    clazz = ClassUtils.resolveClassName(clazzName, getClass().getClassLoader());
                } catch (IllegalArgumentException e) {
                }
                if (clazz != null) {
                    classCache.put(clazzName, (Class<? extends BaseObject>) clazz);
                }
            }
            if (clazz != null) {
                return clazz;
            }
        }
    }

    return clazz;
}

From source file:org.tightblog.service.FileService.java

@Autowired
public FileService(WebloggerPropertiesRepository webloggerPropertiesRepository,
        @Value("${media.file.showTab}") boolean allowUploads,
        @Value("${mediafiles.storage.dir}") String storageDir,
        @Value("#{'${media.file.allowedMimeTypes}'.split(',')}") Set<String> allowedMimeTypes,
        @Value("${media.file.maxFileSizeMb:3}") long maxFileSizeMb) {

    this.webloggerPropertiesRepository = webloggerPropertiesRepository;
    this.allowUploads = allowUploads;
    this.storageDir = storageDir;
    this.allowedMimeTypes = allowedMimeTypes;
    this.maxFileSizeMb = maxFileSizeMb;

    if (allowUploads) {
        log.info("Allowed MIME types for media files = {}",
                ObjectUtils.isEmpty(allowedMimeTypes) ? "NONE (all blocked)"
                        : Arrays.toString(allowedMimeTypes.toArray()));
    } else {/* w ww  . ja v  a2  s. com*/
        log.info("Property media.file.showTab=false so media file uploading is disabled");
    }

    // Note: System property expansion is now handled by WebloggerStaticConfig.
    if (StringUtils.isEmpty(this.storageDir)) {
        this.storageDir = System.getProperty("user.home") + File.separator + "tightblog_data" + File.separator
                + "mediafiles";
    }
    if (!this.storageDir.endsWith(File.separator)) {
        this.storageDir += File.separator;
    }
}

From source file:org.tightblog.service.FileService.java

/**
 * Return true if file is allowed to be uploaded given specified allowed MIME types
 *//*from   ww w. j  ava 2  s .  c o m*/
private boolean checkFileType(String fileName, String contentType) {
    String fileDesc = String.format("Media File %s (content type %s)", fileName, contentType);

    // if content type is invalid, reject file
    if (contentType == null || contentType.indexOf('/') == -1) {
        log.warn("{} blocked from uploading because of invalid content type", fileDesc);
        return false;
    }

    // default to false
    boolean allowFile = false;

    if (!ObjectUtils.isEmpty(allowedMimeTypes)) {
        for (String allowedMimeType : allowedMimeTypes) {
            if (matchContentType(contentType, allowedMimeType)) {
                allowFile = true;
                break;
            }
        }
        log.warn("{} blocked from uploading because not in allowed MIME types", fileDesc);
    }

    return allowFile;
}

From source file:org.tightblog.service.WeblogManager.java

/**
 * Add new weblog, give creator admin permission, creates blogroll,
 * creates categories and other objects required for new weblog.
 *
 * @param newWeblog New weblog to be created, must have creator field populated.
 *///from ww  w.j a v  a 2s . c  om
public void addWeblog(Weblog newWeblog) {
    weblogRepository.save(newWeblog);

    if (weblogRepository.count() == 1) {
        // first weblog, let's make it the frontpage one.
        WebloggerProperties props = webloggerPropertiesRepository.findOrNull();
        props.setMainBlog(newWeblog);
        webloggerPropertiesRepository.save(props);
    }

    // grant weblog creator OWNER permission
    userManager.grantWeblogRole(newWeblog.getCreator(), newWeblog, WeblogRole.OWNER);

    // add default categories and bookmarks
    if (!ObjectUtils.isEmpty(newBlogCategories)) {
        for (String category : newBlogCategories) {
            WeblogCategory c = new WeblogCategory(newWeblog, category);
            newWeblog.addCategory(c);
        }
    }

    if (!ObjectUtils.isEmpty(newBlogBlogroll)) {
        for (String splitItem : newBlogBlogroll) {
            String[] rollitems = splitItem.split("\\|");
            if (rollitems.length > 1) {
                WeblogBookmark b = new WeblogBookmark(newWeblog, rollitems[0], rollitems[1].trim(), "");
                newWeblog.addBookmark(b);
            }
        }
    }
    // create initial media file directory named "default"
    mediaManager.createMediaDirectory(newWeblog, "default");
    saveWeblog(newWeblog, true);
}