Example usage for org.apache.commons.lang StringUtils isEmpty

List of usage examples for org.apache.commons.lang StringUtils isEmpty

Introduction

In this page you can find the example usage for org.apache.commons.lang StringUtils isEmpty.

Prototype

public static boolean isEmpty(String str) 

Source Link

Document

Checks if a String is empty ("") or null.

Usage

From source file:com.bfd.harpc.common.configure.PathUtils.java

/**
 * Normalize the path by suppressing sequences like "path/.." and inner
 * simple dots.//from   w  w w.  java2 s . c  o  m
 * <p>
 * The result is convenient for path comparison. For other uses, notice that
 * Windows separators ("\") are replaced by simple slashes.
 * 
 * @param path
 *            the original path
 * @return the normalized path
 */
public static String cleanPath(String path) {
    if (StringUtils.isEmpty(path)) {
        return null;
    }

    // ClassLoader.getResource??jar
    if (path.startsWith("jar:file")) {
        path = cleanJarPath(path);
    }

    String pathToUse = StringUtils.replace(path, ResourceConstants.WINDOWS_FOLDER_SEPARATOR.getValue(),
            ResourceConstants.FOLDER_SEPARATOR.getValue());

    // Strip prefix from path to analyze, to not treat it as part of the
    // first path element. This is necessary to correctly parse paths like
    // "file:core/../core/io/Resource.class", where the ".." should just
    // strip the first "core" directory while keeping the "file:" prefix.
    int prefixIndex = pathToUse.indexOf(":");
    String prefix = "";
    if (prefixIndex != -1) {
        prefix = pathToUse.substring(0, prefixIndex + 1);
        pathToUse = pathToUse.substring(prefixIndex + 1);
    }
    if (pathToUse.startsWith(ResourceConstants.FOLDER_SEPARATOR.getValue())) {
        prefix = prefix + ResourceConstants.FOLDER_SEPARATOR.getValue();
        pathToUse = pathToUse.substring(1);
    }

    String[] pathArray = StringUtils.split(pathToUse, ResourceConstants.FOLDER_SEPARATOR.getValue());
    List<String> pathElements = new LinkedList<String>();
    int tops = 0;

    for (int i = pathArray.length - 1; i >= 0; i--) {
        String element = pathArray[i];
        if (ResourceConstants.CURRENT_PATH.getValue().equals(element)) {
            // Points to current directory - drop it.
        } else if (ResourceConstants.TOP_PATH.getValue().equals(element)) {
            // Registering top path found.
            tops++;
        } else {
            if (tops > 0) {
                // Merging path element with element corresponding to top
                // path.
                tops--;
            } else {
                // Normal path element found.
                pathElements.add(0, element);
            }
        }
    }

    // Remaining top paths need to be retained.
    for (int i = 0; i < tops; i++) {
        pathElements.add(0, ResourceConstants.TOP_PATH.getValue());
    }

    return prefix + StringUtils.join(pathElements, ResourceConstants.FOLDER_SEPARATOR.getValue());
}

From source file:com.clican.pluto.common.resource.ClassPathResource.java

public ClassPathResource(String classPath) {
    if (StringUtils.isEmpty(classPath)) {
        throw new IllegalArgumentException("classPath cannot be null");
    }//from  w w w. ja va 2 s  .com
    if (!classPath.startsWith(CLASS_PATH_RESOURCE_PREFIX)) {
        this.classPath = classPath;
    } else {
        this.classPath = classPath.substring(CLASS_PATH_RESOURCE_PREFIX.length());
    }
    resource = Thread.currentThread().getContextClassLoader().getResource(this.classPath);
    if (resource == null) {
        throw new IllegalArgumentException("resource cannot be found");
    }
}

From source file:com.baomidou.framework.common.JarHelper.java

public static List<String> readLines(JarFile jarFile, String fileName) throws IOException {
    if (jarFile == null || StringUtils.isEmpty(fileName)) {
        return null;
    }/*from   ww w.ja v a2 s  .co  m*/
    List<String> lines = new ArrayList<String>();
    JarEntry entry = jarFile.getJarEntry(fileName);
    InputStream inputStream = jarFile.getInputStream(entry);
    InputStreamReader inputStreamReader = new InputStreamReader(inputStream);
    BufferedReader bufferedReader = new BufferedReader(inputStreamReader);
    String line;
    while ((line = bufferedReader.readLine()) != null) {
        lines.add(line);
    }
    bufferedReader.close();
    inputStreamReader.close();
    return lines;
}

From source file:cz.strmik.cmmitool.web.controller.propertyeditor.ModelEditor.java

@Override
public void setAsText(String text) {
    if (StringUtils.isEmpty(text)) {
        setValue(null);//from   ww w  .j  av a 2s . com
    } else {
        setValue(modelDao.read(Long.parseLong(text)));
    }
}

From source file:com.bstek.dorado.data.type.BigDecimalDataType.java

public Object fromText(String text) {
    if (StringUtils.isEmpty(text)) {
        return null;
    } else {/*www.j a  v  a2s . com*/
        return new BigDecimal(text);
    }
}

From source file:gov.nih.nci.cabig.caaers.validation.fields.validators.TextSizeValidator.java

@Override
public boolean isValid(Object fieldValue) {
    if (fieldValue == null || StringUtils.isEmpty(fieldValue.toString()))
        return true;
    return (fieldValue.toString().length() < this.size);
}

From source file:hudson.plugins.sonar.template.SonarPomGenerator.java

public static void generatePomForNonMavenProject(LightProjectConfig project, FilePath root, String pomName)
        throws IOException, InterruptedException {
    SimpleTemplate pomTemplate = new SimpleTemplate("hudson/plugins/sonar/sonar-light-pom.template");
    pomTemplate.setAttribute("groupId", project.getGroupId());
    pomTemplate.setAttribute("artifactId", project.getArtifactId());
    pomTemplate.setAttribute("projectName", project.getProjectName()); // FIXME Godin: env.expand because projectName can be "${JOB_NAME}"
    pomTemplate.setAttribute("projectVersion",
            StringUtils.isEmpty(project.getProjectVersion()) ? "1.0" : project.getProjectVersion());
    pomTemplate.setAttribute("javaVersion",
            StringUtils.isEmpty(project.getJavaVersion()) ? "1.5" : project.getJavaVersion());

    List<String> srcDirs = getProjectSrcDirsList(project.getProjectSrcDir());
    boolean multiSources = srcDirs.size() > 1;
    setPomElement("sourceDirectory", srcDirs.size() == 0 ? "src" : srcDirs.get(0), pomTemplate);
    pomTemplate.setAttribute("srcDirsPlugin",
            multiSources ? generateSrcDirsPluginTemplate(srcDirs).toString() : "");

    setPomElement("project.build.sourceEncoding", project.getProjectSrcEncoding(), pomTemplate);
    setPomElement("encoding", project.getProjectSrcEncoding(), pomTemplate);
    setPomElement("description", project.getProjectDescription(), pomTemplate);
    setPomElement("sonar.phase", multiSources ? "generate-sources" : "", pomTemplate);
    setPomElement("outputDirectory", project.getProjectBinDir(), pomTemplate);

    setPomElement("sonar.language", project.getLanguage(), pomTemplate);

    ReportsConfig reports = project.isReuseReports() ? project.getReports() : new ReportsConfig();
    setPomElement("sonar.dynamicAnalysis", project.isReuseReports() ? "reuseReports" : "false", true,
            pomTemplate);/*from ww w  .j  ava2  s .  c o m*/
    setPomElement("sonar.surefire.reportsPath", reports.getSurefireReportsPath(), project.isReuseReports(),
            pomTemplate);
    setPomElement("sonar.cobertura.reportPath", reports.getCoberturaReportPath(), project.isReuseReports(),
            pomTemplate);
    setPomElement("sonar.clover.reportPath", reports.getCloverReportPath(), project.isReuseReports(),
            pomTemplate);

    pomTemplate.write(root, pomName);
}

From source file:cz.strmik.cmmitool.web.controller.propertyeditor.MethodEditor.java

@Override
public void setAsText(String text) {
    if (StringUtils.isEmpty(text)) {
        setValue(null);//w  ww. ja va 2s. c o m
    } else {
        setValue(methodDao.read(Long.parseLong(text)));
    }
}

From source file:ddf.security.principal.AnonymousPrincipal.java

/**
 * Parses the ip address out of an anonymous principal name that has the format
 * Anonymous@127.0.0.1/* ww  w . ja  va 2  s .co m*/
 * @param fullName
 * @return
 */
public static String parseAddressFromName(String fullName) {
    if (!StringUtils.isEmpty(fullName)) {
        String[] parts = fullName.split(NAME_DELIMITER);
        if (parts.length == 2) {
            return parts[1];
        }
    }
    return null;
}

From source file:gov.nih.nci.cabig.caaers.validation.fields.validators.PhoneNumberValidator.java

@Override
public boolean isValid(Object fieldValue) {
    String strVal = stringValue(fieldValue);
    if (StringUtils.isEmpty(strVal))
        return true; // valid.
    String regex = "^(\\+?\\d{10,11}|((\\+)?\\d[-\\.])?(((\\d{3}[-\\.]){2}\\d{4}))|((\\+)?\\d)?((\\(\\d{3}[\\)][-\\.]?\\d{3}[-\\.]?\\d{4})))(x\\d+)?$";
    Pattern p = Pattern.compile(regex);
    Matcher m = p.matcher(strVal);
    return m.matches();
}