Example usage for org.apache.wicket.util.string StringValueConversionException StringValueConversionException

List of usage examples for org.apache.wicket.util.string StringValueConversionException StringValueConversionException

Introduction

In this page you can find the example usage for org.apache.wicket.util.string StringValueConversionException StringValueConversionException.

Prototype

public StringValueConversionException(final String message, final Throwable cause) 

Source Link

Document

Constructor.

Usage

From source file:org.cast.cwm.admin.CSVDownload.java

License:Open Source License

/**
 * creates a new resource response based on the request attributes
 *
 * @param attributes current request attributes from client
 * @return resource response for answering request
 *///from ww w  .j av a  2  s  .  co m
@Override
protected ResourceResponse newResourceResponse(Attributes attributes) {
    ResourceResponse rr = new ResourceResponse();
    rr.disableCaching();
    rr.setFileName("log.csv");
    rr.setContentDisposition(ContentDisposition.ATTACHMENT);
    rr.setContentType("text/csv");

    if (rr.dataNeedsToBeWritten(attributes)) {
        rr.setWriteCallback(new WriteCallback() {
            @Override
            public void writeData(Attributes attributes) {
                Response response = attributes.getResponse();

                try {
                    CSVPrinter writer = new CSVPrinter(
                            new OutputStreamWriter(response.getOutputStream(), "UTF-8"), CSVFormat.EXCEL);

                    // Write header row
                    for (IDataColumn<E> col : columns) {
                        writer.print(col.getHeaderString());
                    }
                    writer.println();

                    // Write documentation row, if requested
                    if (includeDocumentationRow) {
                        for (IDataColumn<E> col : columns) {
                            if (col instanceof IDocumentedColumn
                                    && ((IDocumentedColumn) col).getDocumentationModel() != null) {
                                writer.print(((IDocumentedColumn) col).getDocumentationModel().getObject());
                            } else {
                                writer.print("");
                            }
                        }
                        writer.println();
                    }

                    // Write Data
                    Iterator<? extends E> it = iteratorProvider.getIterator();
                    while (it.hasNext()) {
                        E e = it.next();
                        for (IDataColumn<E> col : columns) {
                            String columnValue = col.getItemString(new Model<E>(e));
                            if (columnValue == null) {
                                log.warn("Got a null value for {} of item {}", col.getHeaderString(), e);
                                columnValue = "null";
                            }
                            // Clean up text -- CSV file cannot have newlines in it
                            writer.print(columnValue.replaceAll("[\r\n]", " "));
                        }
                        writer.println();
                    }
                    writer.close();

                } catch (UnsupportedEncodingException e) {
                    throw new StringValueConversionException("UTF-8 translation not supported?!", e);
                } catch (IOException e) {
                    throw new WicketRuntimeException("Couldn't write to resource", e);
                }
            }
        });
    }

    return rr;
}

From source file:org.hippoecm.frontend.plugin.config.impl.AbstractPluginDecorator.java

License:Apache License

@Override
public double getDouble(String key, double defaultValue) throws StringValueConversionException {
    Object value = get(key);/*  w  ww. j  a v  a 2 s  .  c om*/
    if (value instanceof Double) {
        return (Double) value;
    }
    if (value == null) {
        return defaultValue;
    }
    final String s = value.toString();
    try {
        return Double.parseDouble(s);
    } catch (NumberFormatException e) {
        throw new StringValueConversionException("Cannot convert '" + s + "' to double value", e);
    }
}

From source file:org.wicketstuff.gmap.event.ClickListener.java

License:Apache License

@Override
protected void onEvent(AjaxRequestTarget target) {
    Request request = RequestCycle.get().getRequest();
    NumberFormat fmt = DecimalFormat.getInstance(Locale.US);
    GLatLng latLng = null;//from w  ww  .  j  ava  2 s. c o m

    String latStr = request.getRequestParameters().getParameterValue("lat").toString();
    String lngStr = request.getRequestParameters().getParameterValue("lng").toString();
    Double lat = null;
    Double lng = null;
    try {
        lat = fmt.parse(latStr).doubleValue();
        lng = fmt.parse(lngStr).doubleValue();
    } catch (ParseException e) {
        throw new StringValueConversionException("Unable to convert 'lat/lng' to a double value", e);
    }
    latLng = new GLatLng(lat, lng);

    onClick(target, latLng);
}

From source file:org.wicketstuff.gmap.event.DblClickListener.java

License:Apache License

@Override
protected final void onEvent(AjaxRequestTarget target) {
    Request request = RequestCycle.get().getRequest();
    NumberFormat fmt = DecimalFormat.getInstance(Locale.US);
    GLatLng latLng = null;/*from ww w .  j  av a2 s.c  om*/
    String latStr = request.getRequestParameters().getParameterValue("lat").toString();
    String lngStr = request.getRequestParameters().getParameterValue("lng").toString();
    Double lat = null;
    Double lng = null;
    try {
        lat = fmt.parse(latStr).doubleValue();
        lng = fmt.parse(lngStr).doubleValue();
    } catch (ParseException e) {
        throw new StringValueConversionException("Unable to convert 'lat/lng' to a double value", e);
    }
    latLng = new GLatLng(lat, lng);

    onDblClick(target, latLng);
}