Example usage for org.springframework.util Assert hasText

List of usage examples for org.springframework.util Assert hasText

Introduction

In this page you can find the example usage for org.springframework.util Assert hasText.

Prototype

public static void hasText(@Nullable String text, Supplier<String> messageSupplier) 

Source Link

Document

Assert that the given String contains valid text content; that is, it must not be null and must contain at least one non-whitespace character.

Usage

From source file:com.baidu.cc.patch.struts2.ReloadableJsonAwareParametersInterceptor.java

/**
 * do property load here./* w  ww  . ja  v  a2s.c o  m*/
 */
@Override
public void init() {
    super.init();

    ccServerUrl = Constants.getServerUrl(ccServerUrl);
    ccUser = Constants.getUser(ccUser);
    ccPassword = Constants.getPassword(ccPassword);

    Assert.hasLength(ccServerUrl, "property 'ccServerUrl' can not blank");
    Assert.hasLength(ccUser, "property 'ccUser' can not blank");
    Assert.hasText(ccVersionName, "property 'ccVersionName' can not blank");

    configLoader = ConfigLoader.createConfigLoader(this);
}

From source file:com.scf.module.security.matcher.AntPathRequestMatcher.java

/**
 * Creates a matcher with the supplied pattern which will match the
 * specified Http method/*from w  ww .ja  va 2  s  .  c o m*/
 *
 * @param pattern
 *            the ant pattern to use for matching
 * @param httpMethod
 *            the HTTP method. The {@code matches} method will return false
 *            if the incoming request doesn't doesn't have the same method.
 * @param caseSensitive
 *            true if the matcher should consider case, else false
 */
public AntPathRequestMatcher(String pattern, String httpMethod, boolean caseSensitive) {
    Assert.hasText(pattern, "Pattern cannot be null or empty");
    this.caseSensitive = caseSensitive;

    if (pattern.equals(MATCH_ALL) || pattern.equals("**")) {
        pattern = MATCH_ALL;
        matcher = null;
    } else {
        if (!caseSensitive) {
            pattern = pattern.toLowerCase();
        }

        // If the pattern ends with {@code /**} and has no other wildcards, then optimize to a sub-path match
        if (pattern.endsWith(MATCH_ALL) && pattern.indexOf('?') == -1
                && pattern.indexOf("*") == pattern.length() - 2) {
            matcher = new SubpathMatcher(pattern.substring(0, pattern.length() - 3));
        } else {
            matcher = new SpringAntMatcher(pattern);
        }
    }

    this.pattern = pattern;
    this.httpMethod = StringUtils.hasText(httpMethod) ? HttpMethod.valueOf(httpMethod) : null;
}

From source file:org.openwms.core.configuration.file.ModulePreference.java

/**
 * Create a new {@code ModulePreference}.
 *
 * @param owner The name of the owning module
 * @param key the key/*from ww  w.  j  a  va 2s.c o m*/
 * @throws IllegalArgumentException when key or owner is {@literal null} or empty
 */
public ModulePreference(String owner, String key) {
    // Called from the client-side only.
    super();
    Assert.hasText(owner, "Not allowed to create an ModulePreference with an empty owner");
    Assert.hasText(key, "Not allowed to create an ModulePreference with an empty key");
    this.owner = owner;
    this.key = key;
}

From source file:org.red5.server.script.groovy.GroovyScriptFactory.java

/**
 * Create a new GroovyScriptFactory for the given script source,
 * specifying a strategy interface that can create a custom MetaClass
 * to supply missing methods and otherwise change the behavior of the object.
 * <p>We don't need to specify script interfaces here, since
 * a Groovy script defines its Java interfaces itself.
 * @param scriptSourceLocator a locator that points to the source of the script.
 * Interpreted by the post-processor that actually creates the script.
 * @param groovyObjectCustomizer a customizer that can set a custom metaclass
 * or make other changes to the GroovyObject created by this factory
 * (may be <code>null</code>)
 *//*www  . j  a va2 s.c o m*/
public GroovyScriptFactory(String scriptSourceLocator, GroovyObjectCustomizer groovyObjectCustomizer) {
    Assert.hasText(scriptSourceLocator, "'scriptSourceLocator' must not be empty");
    this.scriptSourceLocator = scriptSourceLocator;
    this.groovyObjectCustomizer = groovyObjectCustomizer;
}

From source file:org.openwms.core.configuration.file.RolePreference.java

/**
 * Create a new RolePreference.//from  w  ww  . j a va  2s  .c om
 *
 * @param rolename The name of the Role that owns this preference
 * @param key the key
 * @throws IllegalArgumentException when rolename or key is {@literal null} or empty
 */
public RolePreference(String rolename, String key) {
    // Called from the client.
    super();
    Assert.hasText(owner, "Not allowed to create a RolePreference with an empty rolename");
    Assert.hasText(key, "Not allowed to create a RolePreference with an empty key");
    owner = rolename;
    this.key = key;
}

From source file:org.data.support.beans.factory.xml.SchemaResolver.java

/**
 * Loads the schema URL -> schema file location mappings using the given
 * mapping file pattern.//  ww  w  .  j  av  a  2s  . co  m
 * @param classLoader the ClassLoader to use for loading
 * (can be <code>null</code>) to use the default ClassLoader)
 * @param schemaMappingsLocation the location of the file that defines schema mappings
 * (must not be empty)
 * @see PropertiesLoaderUtils#loadAllProperties(String, ClassLoader)
 */
public SchemaResolver(ClassLoader classLoader, String schemaMappingsLocation) {
    Assert.hasText(schemaMappingsLocation, "'schemaMappingsLocation' must not be empty");
    this.classLoader = classLoader;
    this.schemaMappingsLocation = schemaMappingsLocation;
}

From source file:org.cleverbus.core.common.file.DefaultFileRepository.java

@Override
public void commitFile(String fileId, String fileName, FileContentTypeExtEnum contentType,
        List<String> subFolders) {
    Assert.hasText(fileId, "fileId must not be empty");
    Assert.hasText(fileName, "fileName must not be empty");
    Assert.notNull(subFolders, "subFolders must not be null");

    File tmpFile = new File(tempDir, fileId);

    // check file existence
    if (!tmpFile.exists() || !tmpFile.canRead()) {
        String msg = "temp file " + tmpFile + " doesn't exist or can't be read";
        Log.error(msg);//from ww  w  .ja  v a2 s . c  o  m
        throw new IntegrationException(InternalErrorEnum.E115, msg);
    }

    // move file to target directory
    String targetDirName = FilenameUtils.concat(fileRepoDir.getAbsolutePath(),
            StringUtils.join(subFolders, File.separator));
    targetDirName = FilenameUtils.normalize(targetDirName);

    File targetDir = new File(targetDirName);

    try {
        FileUtils.moveFileToDirectory(tmpFile, targetDir, true);

        Log.debug("File (" + tmpFile + ") was successfully moved to directory - " + targetDir);
    } catch (IOException e) {
        String msg = "error occurred during moving temp file " + tmpFile + " to target directory - "
                + targetDirName;
        Log.error(msg);
        throw new IntegrationException(InternalErrorEnum.E115, msg);
    }

    // rename file
    File targetTmpFile = new File(targetDir, fileId);

    String targetFileName = FilenameUtils.concat(targetDir.getAbsolutePath(),
            getFileName(fileName, contentType));
    targetFileName = FilenameUtils.normalize(targetFileName);

    try {
        FileUtils.moveFile(targetTmpFile, new File(targetFileName));

        Log.debug("File (" + tmpFile + ") was successfully committed. New path: " + targetFileName);
    } catch (IOException e) {
        String msg = "error occurred during renaming temp file " + tmpFile + " to target directory - "
                + targetDirName;
        Log.error(msg);
        throw new IntegrationException(InternalErrorEnum.E115, msg);
    }
}

From source file:com.tealium.publisher.ftp.FtpSession.java

@Override
public void read(String path, OutputStream fos) throws IOException {
    Assert.hasText(path, "path must not be null");
    Assert.notNull(fos, "outputStream must not be null");
    try {//w w w  .j  a va  2s .  c  o  m
        this.client.download(path, fos, 0, null);
    } catch (IllegalStateException | FTPIllegalReplyException | FTPException | FTPDataTransferException
            | FTPAbortedException e) {
        logger.error("read: " + path + "-" + getError(e), e);
        throw new IOException(getError(e).toString());
    }

    logger.info("File has been successfully transfered from: " + path);
}

From source file:com.sshdemo.common.security.web.authentication.UsernamePasswordCheckcodeAuthenticationFilter.java

public void setCheckcodeParameter(String parameter) {
    Assert.hasText(parameter, "checkcode parameter must not be empty or null");
    this.checkcodeParameter = parameter;
}

From source file:com.cxypub.baseframework.sdk.util.ReflectionUtils.java

/**
 * ?, ?DeclaredField./*from  w ww. j av  a  2 s. c  o  m*/
 * 
 * ?Object?, null.
 */
protected static Field getDeclaredField(final Object object, final String fieldName) {
    Assert.notNull(object, "object?");
    Assert.hasText(fieldName, "fieldName");
    for (Class<?> superClass = object.getClass(); superClass != Object.class; superClass = superClass
            .getSuperclass()) {
        try {
            return superClass.getDeclaredField(fieldName);
        } catch (NoSuchFieldException e) {// NOSONAR
            // Field??,?
        }
    }
    return null;
}