Example usage for org.apache.commons.beanutils ConvertUtils convert

List of usage examples for org.apache.commons.beanutils ConvertUtils convert

Introduction

In this page you can find the example usage for org.apache.commons.beanutils ConvertUtils convert.

Prototype

public static String convert(Object value) 

Source Link

Document

Convert the specified value into a String.

For more details see ConvertUtilsBean.

Usage

From source file:org.projectforge.excel.XlsContentProvider.java

/**
 * /*  ww w . ja  va  2  s. c  o m*/
 */
@Override
public XlsContentProvider setValue(final ExportCell cell, final Object value, final String property) {
    final Cell poiCell = cell.getPoiCell();
    final Object customizedValue = getCustomizedValue(value);
    if (customizedValue != null) {
        if (customizedValue instanceof Calendar) {
            poiCell.setCellValue((Calendar) customizedValue);
        } else if (customizedValue instanceof Date) {
            poiCell.setCellValue((Date) customizedValue);
        } else if (customizedValue instanceof String) {
            poiCell.setCellValue((String) customizedValue);
        } else {
            poiCell.setCellValue(String.valueOf(customizedValue));
        }
    } else if (value instanceof Date) { // Attention: Time zone is not given!
        poiCell.setCellValue((Date) value);
    } else if (value instanceof Calendar) {
        poiCell.setCellValue((Calendar) value);
    } else if (value instanceof Boolean) {
        poiCell.setCellValue(((Boolean) value).booleanValue());
    } else if (value instanceof Number) {
        poiCell.setCellValue(((Number) value).doubleValue());
    } else if (value instanceof Formula) {
        poiCell.setCellFormula(((Formula) value).getExpr());
    } else {
        poiCell.setCellValue(ConvertUtils.convert(value));
    }
    CellFormat cellFormat = getCellFormat(cell, value, property, formatMap);
    if (cellFormat == null) {
        cellFormat = getCellFormat(cell, value, property, defaultFormatMap);
    }
    if (cellFormat == null) {
        cellFormat = new CellFormat();
        cellFormat.setAlignment(CellStyle.ALIGN_LEFT);
        cellFormat.setDataFormat("@");
        cellFormat.setWrapText(true);
    }
    cell.setCellFormat(cellFormat);
    return this;
}

From source file:org.projectforge.export.XlsContentProvider.java

/**
 * //from  ww w.  j a  v a 2 s  .c  o  m
 */
public void setValue(final ExportCell cell, final Object value, final String property) {
    final Cell poiCell = cell.getPoiCell();
    if (value instanceof Date) { // Attention: Time zone is not given!
        poiCell.setCellValue((Date) value);
    } else if (value instanceof DateHolder) {
        poiCell.setCellValue(((DateHolder) value).getCalendar());
    } else if (value instanceof Calendar) {
        poiCell.setCellValue((Calendar) value);
    } else if (value instanceof Boolean) {
        poiCell.setCellValue(((Boolean) value).booleanValue());
    } else if (value instanceof Number) {
        poiCell.setCellValue(((Number) value).doubleValue());
    } else if (value instanceof Formula) {
        poiCell.setCellFormula(((Formula) value).getExpr());
    } else {
        poiCell.setCellValue(ConvertUtils.convert(value));
    }
    CellFormat cellFormat = getCellFormat(cell, value, property, formatMap);
    if (cellFormat == null) {
        cellFormat = getCellFormat(cell, value, property, defaultFormatMap);
    }
    if (cellFormat == null) {
        cellFormat = new CellFormat();
        cellFormat.setAlignment(CellStyle.ALIGN_LEFT);
        cellFormat.setDataFormat("@");
        cellFormat.setWrapText(true);
    }
    cell.setCellFormat(cellFormat);
}

From source file:org.pushio.datacenter.support.persistence.SearchFilter.java

/**
 * searchParamskey?LIKES_name/* w  w  w. j  ava 2  s . co  m*/
 */
public static Map<String, SearchFilter> parse(Map<String, Object> searchParams) {
    Map<String, SearchFilter> filters = Maps.newHashMap();
    String filedName;
    Operator operator;
    for (Entry<String, Object> entry : searchParams.entrySet()) {
        // 
        String key = entry.getKey();

        Object value = entry.getValue();
        if (key == null || value == null || StringUtils.isBlank(value.toString())) {
            continue;
        }
        // http:\\192.168.1.1:8080\bigdata\tt.do?db_sum_alias=carCount,busCount&db_query=a=
        // operatorfiledAttribute
        String[] names = StringUtils.split(key, "_");
        if (names.length != 2 && names.length != 3) {
            // throw new IllegalArgumentException(key + " is not a valid search filter name");
            logger.warn(key + " is not a valid search filter name");
            continue;
        }

        Class<?> propertyClass = null;
        if (names.length == 3) {
            try {
                propertyClass = Enum.valueOf(PropertyType.class, names[2]).getValue();
                logger.debug(key + ":" + propertyClass.getName());
                if (propertyClass != null) {
                    if (propertyClass.getName().equals("java.util.Date")) {
                        String str = value.toString();
                        if (str.length() == 10) {
                            if (names[0].equals("GT") || names[0].equals("GTE")) {
                                str += " 00:00:00";
                            } else if (names[0].equals("LT") || names[0].equals("LTE")) {
                                str += " 23:59:59";
                            }
                        }
                        value = dateTimeFormat.parseObject(str);
                    } else {
                        value = ConvertUtils.convert(value);
                    }
                }

            } catch (RuntimeException e) {
                logger.warn(key + " PropertyType is not a valid type!", e);
            } catch (ParseException e) {
                logger.warn(key + " PropertyType is not a valid type!", e);
            }
        }

        filedName = names[1];
        operator = Operator.valueOf(names[0]);
        // searchFilter
        SearchFilter filter = new SearchFilter(filedName, operator, value);
        filters.put(key, filter);
    }

    return filters;
}

From source file:org.toobsframework.data.beanutil.BeanMonkey.java

public static void concatPropertyList(Object bean, String propertyList, StringBuffer result, boolean quoted)
        throws NoSuchMethodException, InvocationTargetException, IllegalAccessException {
    if (bean == null || propertyList == null || result == null) {
        return;/*  w  w  w . j a  v  a 2  s  .  c o  m*/
    }

    StringTokenizer st = new StringTokenizer(propertyList, ",");
    while (st.hasMoreTokens()) {
        String name = st.nextToken();
        Object value = PropertyUtils.getProperty(bean, name);
        if (value instanceof String && value != null) {
            result.append(" ");
            if (quoted)
                result.append("\"");
            result.append(value);
            if (quoted)
                result.append("\"");
        } else if (value instanceof Collection && value != null) {
            Iterator valIter = ((Collection) value).iterator();
            while (valIter.hasNext()) {
                concatPropertyList(valIter.next(), "displayName", result, quoted);
                // result.append(" " + ConvertUtils.convert(valIter.next()));
            }
        } else if (value != null) {
            result.append(" ");
            if (quoted)
                result.append("\"");
            result.append(ConvertUtils.convert(value));
            if (quoted)
                result.append("\"");
        }
    }
}

From source file:org.webguitoolkit.ui.controls.util.PropertyAccessor.java

public static String retrieveString(Object data, String att) {
    return ConvertUtils.convert(retrieveProperty(data, att));
}

From source file:org.webguitoolkit.ui.controls.util.PropertyAccessor.java

/**
 * convert data using your own converter, which may be configured using the format attribut
 * For a list of converters see ConvertUtil.
 * @return/* w  w  w. j  av  a 2  s.  co m*/
 */
public static String retrieveString(Object data, String att, IConverter conv) {
    // use standard converter or custom?
    if (conv == null) {
        return ConvertUtils.convert(retrieveProperty(data, att));
    } else {
        return (String) conv.convert(String.class, retrieveProperty(data, att));
    }
}

From source file:ro.nextreports.server.api.client.jdbc.ResultSet.java

@Override
public String getString(int columnIndex) throws SQLException {
    //      return (String) getObject(columnIndex);
    return ConvertUtils.convert(getObject(columnIndex));
}