Example usage for org.apache.commons.beanutils.converters LongConverter LongConverter

List of usage examples for org.apache.commons.beanutils.converters LongConverter LongConverter

Introduction

In this page you can find the example usage for org.apache.commons.beanutils.converters LongConverter LongConverter.

Prototype

public LongConverter(Object defaultValue) 

Source Link

Document

Create a Converter that will return the specified default value if a conversion error occurs.

Usage

From source file:org.kuali.rice.kns.web.struts.action.KualiActionServlet.java

/**
 * <p>Initialize other global characteristics of the controller servlet.</p>
 * Overridden to remove the ConvertUtils.deregister() command that caused problems
 * with the concurrent data dictionary load.  (KULRNE-4405)
 *
 * @exception ServletException if we cannot initialize these resources
 *///  w ww .ja  v  a 2 s  . c  o m
@Override
protected void initOther() throws ServletException {

    String value = null;
    value = getServletConfig().getInitParameter("config");
    if (value != null) {
        config = value;
    }

    // Backwards compatibility for form beans of Java wrapper classes
    // Set to true for strict Struts 1.0 compatibility
    value = getServletConfig().getInitParameter("convertNull");
    if ("true".equalsIgnoreCase(value) || "yes".equalsIgnoreCase(value) || "on".equalsIgnoreCase(value)
            || "y".equalsIgnoreCase(value) || "1".equalsIgnoreCase(value)) {

        convertNull = true;
    }

    if (convertNull) {
        ConvertUtils.register(new BigDecimalConverter(null), BigDecimal.class);
        ConvertUtils.register(new BigIntegerConverter(null), BigInteger.class);
        ConvertUtils.register(new BooleanConverter(null), Boolean.class);
        ConvertUtils.register(new ByteConverter(null), Byte.class);
        ConvertUtils.register(new CharacterConverter(null), Character.class);
        ConvertUtils.register(new DoubleConverter(null), Double.class);
        ConvertUtils.register(new FloatConverter(null), Float.class);
        ConvertUtils.register(new IntegerConverter(null), Integer.class);
        ConvertUtils.register(new LongConverter(null), Long.class);
        ConvertUtils.register(new ShortConverter(null), Short.class);
    }

    // KULRICE-8176: KFS Notes/Attachments Tab Functionality for Note Text Error - Visible/Special characters, spaces, or tabs
    parameterEncoding = getServletConfig().getInitParameter("PARAMETER_ENCODING");
}

From source file:org.quickbundle.third.struts.action.RmActionServlet.java

/**
  * <p>Initialize other global characteristics of the controller
  * servlet.</p>//from w w  w  .  j  a va 2  s.  co m
  *
  * @throws ServletException if we cannot initialize these resources
  */
protected void initOther() throws ServletException {
    String value;

    value = getServletConfig().getInitParameter("config");

    if (value != null) {
        //QB-RM add *.xml
        if (value.trim().length() > 0 && value.indexOf("*.xml") > -1) { //
            String finalValue = "";
            String[] aValue = value.trim().split(",");
            for (int j = 0; j < aValue.length; j++) {
                String path = aValue[j];
                if (path.trim().length() == 0) {
                    continue;
                }
                //??*.xml
                if (path.trim().endsWith("*.xml")) {
                    File fWarDirStr = RmPathHelper.getWarDir();
                    File fPath = new File(fWarDirStr + File.separator
                            + (path.substring(0, path.length() - "*.xml".length())));
                    for (int i = 0; i < fPath.listFiles().length; i++) {
                        File fPathXml = fPath.listFiles()[i];
                        if (fPathXml.isFile() && fPathXml.toString().toLowerCase().endsWith(".xml")) {
                            String newPath = fPathXml.getAbsolutePath()
                                    .substring((int) fWarDirStr.getAbsoluteFile().toString().length())
                                    .replaceAll("\\\\", "/");
                            finalValue += newPath + ",";
                        }
                    }
                } else {
                    finalValue += path + ",";
                }
            }
            if (finalValue.endsWith(",")) {
                finalValue = finalValue.substring(0, finalValue.length() - ",".length());
            }
            config = finalValue;
        } else {
            config = value;
        }
    }

    // Backwards compatibility for form beans of Java wrapper classes
    // Set to true for strict Struts 1.0 compatibility
    value = getServletConfig().getInitParameter("convertNull");

    if ("true".equalsIgnoreCase(value) || "yes".equalsIgnoreCase(value) || "on".equalsIgnoreCase(value)
            || "y".equalsIgnoreCase(value) || "1".equalsIgnoreCase(value)) {
        convertNull = true;
    }

    if (convertNull) {
        ConvertUtils.deregister();
        ConvertUtils.register(new BigDecimalConverter(null), BigDecimal.class);
        ConvertUtils.register(new BigIntegerConverter(null), BigInteger.class);
        ConvertUtils.register(new BooleanConverter(null), Boolean.class);
        ConvertUtils.register(new ByteConverter(null), Byte.class);
        ConvertUtils.register(new CharacterConverter(null), Character.class);
        ConvertUtils.register(new DoubleConverter(null), Double.class);
        ConvertUtils.register(new FloatConverter(null), Float.class);
        ConvertUtils.register(new IntegerConverter(null), Integer.class);
        ConvertUtils.register(new LongConverter(null), Long.class);
        ConvertUtils.register(new ShortConverter(null), Short.class);
    }
}

From source file:org.sputnikdev.bluetooth.gattparser.FieldHolder.java

/**
 * Returns a Long representation of the field or a default value in case if the field cannot
 * be converted to a Long.// ww  w.  jav a  2s  .  c  om
 * @param def the default value to be returned if an error occurs converting the field
 * @return a Long representation of the field
 */
public Long getLong(Long def) {
    Long result = new LongConverter(null).convert(Long.class, prepareValue());
    if (result != null) {
        double multiplier = getMultiplier();
        double offset = getOffset();
        if (multiplier != 1.0 || offset != 0.0) {
            return Math.round(result * multiplier + offset);
        } else {
            return result;
        }
    } else {
        return def;
    }
}

From source file:org.waterforpeople.mapping.app.util.DtoMarshaller.java

/**
 * sets up the converters that this marshaller should use
 *//*from   w w w  .j  a v  a2s . c  o  m*/
private static void configureConverters() {
    String pattern = "MM/dd/yy";
    Locale locale = Locale.getDefault();
    DateLocaleConverter converter = new DateLocaleConverter(locale, pattern);
    converter.setLenient(true);
    ConvertUtils.register(converter, java.util.Date.class);

    TypeEnumConverter enumConverter = new TypeEnumConverter();
    ConvertUtils.register(enumConverter, Question.Type.class);
    ConvertUtils.register(enumConverter, QuestionDto.QuestionType.class);
    ConvertUtils.register(enumConverter, AccessPoint.Status.class);
    ConvertUtils.register(enumConverter, AccessPoint.AccessPointType.class);
    ConvertUtils.register(enumConverter, UnitOfMeasure.UnitOfMeasureSystem.class);
    ConvertUtils.register(enumConverter, UnitOfMeasure.UnitOfMeasureType.class);
    ConvertUtils.register(enumConverter, QuestionHelpMedia.Type.class);
    ConvertUtils.register(enumConverter, QuestionHelpDto.Type.class);
    ConvertUtils.register(enumConverter, OGRFeatureDto.FeatureType.class);
    ConvertUtils.register(enumConverter, Survey.Status.class);
    ConvertUtils.register(enumConverter, Survey.Sector.class);

    // Resetting default values from zero to null
    ConvertUtils.register(new DoubleConverter(null), Double.class);
    ConvertUtils.register(new LongConverter(null), Long.class);
    ConvertUtils.register(new IntegerConverter(null), Integer.class);

    DatastoreTextConverter textConverter = new DatastoreTextConverter();
    ConvertUtils.register(textConverter, Text.class);
    ConvertUtils.register(textConverter, String.class);
}