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:cz.strmik.cmmitool.web.controller.propertyeditor.ProcessGroupEditor.java

@Override
public void setAsText(String text) {
    if (StringUtils.isEmpty(text)) {
        setValue(null);/*  w w  w  .  jav a 2s  .com*/
    } else {
        setValue(processGroupDao.read(Long.parseLong(text)));
    }
}

From source file:edu.cornell.mannlib.vitro.webapp.utils.dataGetter.DataGetterBase.java

/** 
 * Get the model to use based on a model URI.
 *//*from  w w  w .  j  a  va2s  .  c  om*/
protected Model getModel(ServletContext context, VitroRequest vreq, String modelName) {
    //if not set use jenaOntModel from the request
    if (StringUtils.isEmpty(modelName)) {
        return vreq.getJenaOntModel();
    } else if (REQUEST_DISPLAY_MODEL.equals(modelName)) {
        return vreq.getDisplayModel();
    } else if (REQUEST_JENA_ONT_MODEL.equals(modelName)) {
        return vreq.getJenaOntModel();
    } else if (CONTEXT_DISPLAY_MODEL.equals(modelName)) {
        return ModelAccess.on(context).getOntModel(DISPLAY);
    } else if (!StringUtils.isEmpty(modelName)) {
        Model model = JenaIngestController.getModel(modelName, vreq);
        if (model == null)
            throw new IllegalAccessError("Cannot get model <" + modelName + "> for DataGetter.");
        else
            return model;
    } else {
        //default is just the JeanOntModel from the vreq.
        return vreq.getJenaOntModel();
    }
}

From source file:com.laxser.blitz.util.PlaceHolderUtils.java

public static String resolve(String text, Invocation inv) {
    if (StringUtils.isEmpty(text)) {
        return text;
    }/*from   w w  w  . j a v a  2s  .  c o  m*/
    int startIndex = text.indexOf(PLACEHOLDER_PREFIX);
    if (startIndex == -1) {
        return text;
    }
    StringBuilder buf = new StringBuilder(text);
    while (startIndex != -1) {
        int endIndex = buf.indexOf(PLACEHOLDER_SUFFIX, startIndex + PLACEHOLDER_PREFIX.length());
        if (endIndex != -1) {
            String placeholder = null;
            String defaultValue = null;
            for (int i = startIndex + PLACEHOLDER_PREFIX.length(); i < endIndex; i++) {
                if (buf.charAt(i) == '?') {
                    placeholder = buf.substring(startIndex + PLACEHOLDER_PREFIX.length(), i);
                    defaultValue = buf.substring(i + 1, endIndex);
                    break;
                }
            }
            if (placeholder == null) {
                placeholder = buf.substring(startIndex + PLACEHOLDER_PREFIX.length(), endIndex);
            }
            int nextIndex = endIndex + PLACEHOLDER_SUFFIX.length();
            try {
                int dot = placeholder.indexOf('.');
                String attributeName = dot == -1 ? placeholder : placeholder.substring(0, dot);
                String propertyPath = dot == -1 ? "" : placeholder.substring(dot + 1);
                Object propVal = inv.getModel().get(attributeName);
                if (propVal != null) {
                    if (propertyPath.length() > 0) {
                        propVal = new BeanWrapperImpl(propVal).getPropertyValue(propertyPath);
                    }
                } else {
                    if ("flash".equals(attributeName)) {
                        propVal = inv.getFlash().get(propertyPath);
                    } else {
                        propVal = inv.getParameter(placeholder);
                    }
                }
                //
                if (propVal == null) {
                    propVal = defaultValue;
                }
                if (propVal == null) {
                    if (logger.isWarnEnabled()) {
                        logger.warn("Could not resolve placeholder '" + placeholder + "' in [" + text + "].");
                    }
                } else {
                    String toString = propVal.toString();
                    buf.replace(startIndex, endIndex + PLACEHOLDER_SUFFIX.length(), toString);
                    nextIndex = startIndex + toString.length();
                }
            } catch (Throwable ex) {
                logger.warn("Could not resolve placeholder '" + placeholder + "' in [" + text + "] : " + ex);
            }
            startIndex = buf.indexOf(PLACEHOLDER_PREFIX, nextIndex);
        } else {
            startIndex = -1;
        }
    }

    return buf.toString();
}

From source file:com.baifendian.swordfish.common.utils.CommonUtil.java

/**
 * sql ?, ?, ?? ";"//  www . j av a2  s .c  o m
 */
public static List<String> sqlSplit(String sql) {
    if (StringUtils.isEmpty(sql)) {
        return Collections.EMPTY_LIST;
    }

    List<String> r = new ArrayList<>();

    Status status = Status.START;
    StringBuffer buffer = new StringBuffer();

    for (int i = 0; i < sql.length(); ++i) {
        char c = sql.charAt(i);
        char nextChar = ((i + 1) < sql.length()) ? sql.charAt(i + 1) : ' '; // add at 2017/1/6

        boolean skip = false;

        switch (status) {
        case START: {
            if (c == ';') {
                status = Status.END;
                skip = true; //  ;
            } else if (c == '\'') {
                status = Status.SINGLE_QUOTE;
            } else if (c == '"') {
                status = Status.QUOTE;
            } else if (c == '-' && nextChar == '-') { // add at 2017/1/6
                status = Status.COMMENT;
                ++i; // add at 2017/1/6
                skip = true;
            } else if (Character.isWhitespace(c)) {
                status = Status.BLANK;
            }
        }
            break;
        case BLANK: {
            if (c == ';') {
                status = Status.END;
                skip = true; //  ;
            } else if (c == '"') {
                status = Status.QUOTE;
            } else if (c == '\'') {
                status = Status.SINGLE_QUOTE;
            } else if (c == '-' && nextChar == '-') { // add at 2017/1/6)
                status = Status.COMMENT;
                ++i; // add at 2017/1/6
                skip = true;
            } else if (!Character.isWhitespace(c)) {
                status = Status.START;
            } else {
                skip = true;
            }
        }
            break;
        case END: {
            if (c == '"') {
                status = Status.QUOTE;
            } else if (c == '\'') {
                status = Status.SINGLE_QUOTE;
            } else if (Character.isWhitespace(c)) {
                status = Status.BLANK;
            } else if (c == '-' && nextChar == '-') { // add at 2017/1/6)
                status = Status.COMMENT;
                ++i; // add at 2017/1/6
                skip = true;
            } else if (c != ';') {
                status = Status.START;
            } else {
                skip = true;
            }
        }
            break;
        case QUOTE: {
            if (c == '"') {
                status = Status.START;
            } else if (c == '\\') {
                status = Status.BACKSLASH_FOR_QUOTE;
            }
        }
            break;
        case SINGLE_QUOTE: {
            if (c == '\'') {
                status = Status.START;
            } else if (c == '\\') {
                status = Status.BACKSLASH_FOR_SINGLE_QUOTE;
            }
        }
            break;
        case BACKSLASH_FOR_QUOTE: {
            status = Status.QUOTE;
        }
            break;
        case BACKSLASH_FOR_SINGLE_QUOTE: {
            status = Status.SINGLE_QUOTE;
        }
            break;
        case COMMENT: {
            if (c != '\r' && c != '\n') {
                status = Status.COMMENT;
                skip = true;
            } else {
                status = Status.START;
            }
        }
            break;
        }

        if (!skip) {
            //  white space ??
            if (Character.isWhitespace(c)) {
                buffer.append(' ');
            } else {
                buffer.append(c);
            }
        }

        if (status == Status.END) {
            String sub = buffer.toString();
            if (!StringUtils.isWhitespace(sub)) {
                r.add(sub.trim());
            }
            buffer = new StringBuffer();
        }
    }

    String sub = buffer.toString();
    if (!StringUtils.isWhitespace(sub)) {
        r.add(sub.trim());
    }

    return r;
}

From source file:com.clican.pluto.cms.ui.ext.converter.ArraySplitStringConverter.java

public Object getAsObject(FacesContext context, UIComponent component, String value) {
    if (StringUtils.isEmpty(value)) {
        return null;
    } else {//from www  . j a  v a 2  s .c o m
        return value.split(",");
    }

}

From source file:com.taobao.diamond.manager.impl.PropertiesListener.java

public void receiveConfigInfo(String configInfo) {
    if (StringUtils.isEmpty(configInfo)) {
        log.warn("");
        return;/*from   w  ww . ja v a 2  s . c  om*/
    }

    Properties properties = new Properties();
    try {
        properties.load(new StringReader(configInfo));
        innerReceive(properties);
    } catch (IOException e) {
        log.warn("properties" + configInfo, e);
    }

}

From source file:cn.leancloud.diamond.manager.impl.PropertiesListener.java

public void receiveConfigInfo(String configInfo) {
    if (StringUtils.isEmpty(configInfo)) {
        log.warn("??");
        return;/*  w  w w.ja  va2 s  .  c o  m*/
    }

    Properties properties = new Properties();
    try {
        properties.load(new StringReader(configInfo));
        innerReceive(properties);
    } catch (IOException e) {
        log.warn("properties" + configInfo, e);
    }

}

From source file:com.clican.pluto.dataprocess.dpl.function.impl.Duration.java

public static double duration(Date d1, Date d2, String step) throws PrefixAndSuffixException {
    if (StringUtils.isEmpty(step) || step.equals("day")) {
        return (d1.getTime() - d2.getTime()) / (1000L * 3600 * 24);
    } else if (step.equals("month")) {
        Calendar c1 = Calendar.getInstance();
        c1.setTime(d1);/*from  w  w  w. j  a  v  a 2 s  .  co  m*/
        Calendar c2 = Calendar.getInstance();
        c2.setTime(d2);
        int month = (c1.get(Calendar.YEAR) - c2.get(Calendar.YEAR)) * 12
                + (c1.get(Calendar.MONTH) - c2.get(Calendar.MONTH));
        return month;
    } else {
        throw new PrefixAndSuffixException("??");
    }
}

From source file:gov.nih.nci.cabig.caaers.utils.CaaersSerializerUtil.java

/**
 * This method serializes Entities in the ObjectToSerialize. This class contains HttpRequest,HttpSession,HibernateSession & Exception.
 * @param objectToSerialize//  w  w  w. ja  v a 2 s  .com
 * @return
 */
public static String serialize(ObjectToSerialize objectToSerialize) {
    String serializedContent = "";

    try {
        if (objectToSerialize != null) {
            XStream xstream = new XStream();
            xstream.registerConverter(new ObjectToSerializeConverter());
            xstream.setMode(XStream.ID_REFERENCES);
            serializedContent = xstream.toXML(objectToSerialize);
            if (!StringUtils.isEmpty(serializedContent)) {
                dumpContentToFile(serializedContent);
            }
        }
    } catch (Exception e) {
        logger.error("Exception while serializing --", e);
    }
    return serializedContent;
}

From source file:converters.StringToFileConverter.java

@Override
public File convert(String text) {
    File result;/*from   w w w.  j a  v  a2 s.  c o  m*/
    int id;

    try {
        if (StringUtils.isEmpty(text))
            result = null;
        else {
            id = Integer.valueOf(text);
            result = fileRepository.findOne(id);
        }
    } catch (Throwable oops) {
        throw new IllegalArgumentException(oops);
    }

    return result;
}