001/*
002 * Licensed to the Apache Software Foundation (ASF) under one or more
003 * contributor license agreements.  See the NOTICE file distributed with
004 * this work for additional information regarding copyright ownership.
005 * The ASF licenses this file to You under the Apache License, Version 2.0
006 * (the "License"); you may not use this file except in compliance with
007 * the License.  You may obtain a copy of the License at
008 *
009 *      http://www.apache.org/licenses/LICENSE-2.0
010 *
011 * Unless required by applicable law or agreed to in writing, software
012 * distributed under the License is distributed on an "AS IS" BASIS,
013 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014 * See the License for the specific language governing permissions and
015 * limitations under the License.
016 */
017package org.apache.wicket.extensions.markup.html.repeater.data.table.export;
018
019import java.io.IOException;
020import java.io.OutputStream;
021import java.util.List;
022import org.apache.wicket.markup.repeater.data.IDataProvider;
023import org.apache.wicket.model.IModel;
024import org.apache.wicket.util.io.IClusterable;
025
026/**
027 * Exports data provided by a {@link IDataProvider} as described by {@link IExportableColumn}s. This interface is used by
028 * {@link ExportToolbar} to provide the export functionality.
029 *
030 * @author Jesse Long
031 * @see ExportToolbar
032 * @see IExportableColumn
033 */
034public interface IDataExporter
035        extends IClusterable
036{
037        /**
038         * Returns a model of the exported data format name. This should be something like "CSV" or "Excel" etc. The
039         * value of the model returned is displayed as the export type in the {@link ExportToolbar}.
040         *
041         * @return a model of the exported data format name.
042         */
043        IModel<String> getDataFormatNameModel();
044
045        /**
046         * Returns the MIME content type of the export data type. This could be something like "text/csv". This is used to provide
047         * the correct content type when downloading the exported data.
048         *
049         * @return the MIME content type of the export data type.
050         */
051        String getContentType();
052
053        /**
054         * Returns the file name extensions for the exported data, without the ".". For CSV, this should be "csv". For Excel
055         * exports, this should be "xls".
056         *
057         * @return the file name extensions for the exported data, without the ".".
058         */
059        String getFileNameExtension();
060
061        /**
062         * Exports the data provided by the {@link IDataProvider} to the {@link OutputStream}.
063         *
064         * @param <T>
065         *      The type of each row of data provided by the {@link IDataProvider}.
066         * @param dataProvider
067         *      The {@link IDataProvider} from which to retrieve the data.
068         * @param columns
069         *      The {@link IExportableColumn} to use to describe the data.
070         * @param outputStream
071         *      The {@link OutputStream} to which to write the exported data.
072         * @throws IOException If an error occurs.
073         */
074        <T> void exportData(IDataProvider<T> dataProvider, List<IExportableColumn<T, ?>> columns, OutputStream outputStream)
075                throws IOException;
076}