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

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

Introduction

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

Prototype

public static boolean isNumeric(String str) 

Source Link

Document

Checks if the String contains only unicode digits.

Usage

From source file:net.sourceforge.fenixedu.presentationTier.validator.form.ValidateIntegerArray.java

public static boolean validate(Object bean, ValidatorAction va, Field field, ActionMessages errors,
        HttpServletRequest request, ServletContext application) {

    try {//  w  w w . j a  v a  2  s  .co  m
        DynaActionForm form = (DynaActionForm) bean;

        String sProperty = field.getProperty();
        String[] integerArray = (String[]) form.get(sProperty);

        if ((integerArray == null) || (integerArray.length <= 0)) {
            errors.add(field.getKey(), Resources.getActionMessage(request, va, field));
            return true;
        }
        for (int i = 0; i < integerArray.length; i++) {
            if (integerArray[i].equals("") || !StringUtils.isNumeric(integerArray[i])) {
                errors.add(field.getKey(), Resources.getActionMessage(request, va, field));
                return true;
            }
        }
        return false;

    } catch (Exception e) {
        errors.add(field.getKey(), Resources.getActionMessage(request, va, field));
        return true;
    }

}

From source file:com.devnexus.ting.web.converter.StringToEvent.java

@Override
public Event convert(String source) {

    if (StringUtils.isEmpty(source) || !StringUtils.isNumeric(source)) {
        return null;
    } else {//from w  ww . j  ava2 s. c o  m
        return new Event(Long.valueOf(source));
    }

}

From source file:com.devnexus.ting.web.converter.StringToSkillLevel.java

@Override
public SkillLevel convert(String source) {

    if (StringUtils.isEmpty(source) || !StringUtils.isNumeric(source)) {
        return null;
    } else {/*  w w  w . j  av  a 2 s  .  co m*/
        return SkillLevel.fromId(Long.valueOf(source));
    }

}

From source file:com.griddynamics.genesis.notification.utils.ConfigReaderUtils.java

public static Integer getIntParameter(java.util.Map<String, String> config, String paramName, int maxValue) {
    String paramValue = config.get(paramName);
    if (StringUtils.isNotEmpty(paramValue) && StringUtils.isNumeric(paramValue)) {
        try {//from  w  w  w . ja v a2s.c  om
            int i = Integer.parseInt(paramValue);
            if (i > maxValue) {
                throw new IllegalArgumentException(String.format("%s is too big: %s", paramName, paramValue));
            }
            return i;
        } catch (NumberFormatException e) {
            throw new IllegalArgumentException(String.format("%s is is too big: %s", paramName, paramValue));
        }
    } else {
        throw new IllegalArgumentException(
                paramName + String.format("%s is not a number: '%s'", paramName, paramValue));
    }
}

From source file:com.core.util.wx.XmlUtils.java

/**
 * arrayxml// w  w  w .j a v a2  s .co  m
 * 
 * @param map
 * @return
 */
public static String mapToXml(Map<String, String> map) {
    StringBuilder xml = new StringBuilder();
    xml.append("<xml>");
    String value = null;
    for (String key : map.keySet()) {
        value = map.get(key);
        xml.append("<").append(key).append(">");
        if (StringUtils.isNumeric(value)) {
            xml.append(value);
        } else {
            xml.append("<![CDATA[").append(value).append("]]>");
        }
        xml.append("</").append(key).append(">");
    }
    xml.append("</xml>");
    return xml.toString();
}

From source file:com.timesheet.data.SqlUtilsImp.java

@Override
public void insetIntoProjectUserAss(Integer projectId, String userList) {
    Session session = sessionFactory.getCurrentSession();

    //Transaction tx  = session.beginTransaction();

    String[] userListArr = userList.split(",");

    if (userListArr.length > 0) {
        for (String userId : userListArr) {
            if (StringUtils.isNumeric(userId)) {
                String sql = "INSERT INTO ProjectUser(projectId, userId) VALUES(:projectId, :userId)";

                //System.out.println("Inide manual sql @@@@@@@@@@@@"+projectId);

                Query query = session.createSQLQuery(sql);

                query.setInteger("projectId", projectId);

                query.setInteger("userId", Integer.parseInt(userId));

                query.executeUpdate();//from  w w w .j  a  va  2 s.  com

                session.flush();

                session.clear();
            }
        }
    }

    //tx.commit();
    //session.close();
    //throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
}

From source file:com.devnexus.ting.web.converter.StringToSponsorLevel.java

@Override
public SponsorLevel convert(String source) {
    if (StringUtils.isEmpty(source) || !StringUtils.isNumeric(source)) {
        return null;
    } else {/*from   w w w. java  2 s.co m*/
        return SponsorLevel.fromId(Long.valueOf(source));
    }
}

From source file:averagetemperature.AverageTemperatureMapper.java

@Override
public void map(LongWritable key, Text value, OutputCollector<Text, IntWritable> output, Reporter reporter)
        throws IOException {

    String[] line = value.toString().split(",");
    String datePart = line[1];//from w ww .j  a  v  a  2s.c o m
    String temp = line[10];

    if (StringUtils.isNumeric(temp))
        try {
            output.collect(new Text(datePart), new IntWritable(Integer.parseInt(temp)));
        } catch (NumberFormatException e) {
        }
    ;

}

From source file:com.devnexus.ting.web.converter.StringToPresentationType.java

@Override
public PresentationType convert(String source) {
    if (StringUtils.isEmpty(source) || !StringUtils.isNumeric(source)) {
        return null;
    } else {//from ww w  . j ava  2  s. c o m
        return PresentationType.fromId(Long.valueOf(source));
    }
}

From source file:com.devnexus.ting.web.converter.StringToPurchaseGroup.java

@Override
public TicketGroup convert(String source) {
    if (StringUtils.isEmpty(source) || !StringUtils.isNumeric(source)) {
        return null;
    } else {/*ww  w .  j a  v a  2s . c o  m*/
        return TicketGroup.fromId(Long.valueOf(source));
    }
}