Package com.dci.intellij.dbn.data.export

Examples of com.dci.intellij.dbn.data.export.DataExportException


    public void export(DataExportModel model, DataExportInstructions instructions, ConnectionHandler connectionHandler)
            throws DataExportException {
        try {
            if (model.getColumnCount() == 0 || model.getRowCount() == 0) {
                throw new DataExportException("No content selected for export. Uncheck the Scope \"Selection\" if you want to export the entire content.");
            }
            String fileName = adjustFileName(instructions.getFileName());
            instructions.setFileName(fileName);
            performExport(model, instructions, connectionHandler);
        } catch (DataExportException e) {
            throw e;
        } catch (Exception e) {
            e.printStackTrace();
            throw new DataExportException(e.getMessage());
        }
    }
View Full Code Here


            fileWriter.write(content);
            fileWriter.flush();
            fileWriter.close();
        } catch (IOException e) {
            e.printStackTrace();
            throw new DataExportException("Could not write file " + file.getPath() + ".\n Reason: " + e.getMessage());
        }
    }
View Full Code Here

            workbook.write(fileOutputStream);
            fileOutputStream.flush();
            fileOutputStream.close();
        } catch (IOException e) {
            e.printStackTrace();
            throw new DataExportException(
                    "Could not write file " + file.getPath() +".\n" +
                    "Reason: " + e.getMessage());
        }
    }
View Full Code Here

                boolean quote =
                        instructions.quoteAllValues() || (
                        instructions.quoteValuesContainingSeparator() && containsSeparator);

                if (containsSeparator && !quote) {
                    throw new DataExportException(
                        "Can not create columns header with the given separator.\n" +
                        "Column " + columnName + " already contains the separator '" + separator + "'. \n" +
                        "Please consider quoting.");
                }

                if (columnIndex > 0) {
                    buffer.append(separator);
                }

                if (quote) {
                    if(columnName.indexOf('"') > -1) {
                        throw new DataExportException(
                            "Can not quote columns header.\n" +
                            "Column " + columnName + " contains quotes.");
                    }
                    buffer.append('"');
                    buffer.append(columnName);
                    buffer.append('"');
                } else {
                    buffer.append(columnName);
                }
            }
            buffer.append('\n');
        }

        for (int rowIndex=0; rowIndex < model.getRowCount(); rowIndex++) {
            for (int columnIndex=0; columnIndex < model.getColumnCount(); columnIndex++){
                String columnName = model.getColumnName(columnIndex);
                Object object = model.getValue(rowIndex, columnIndex);
                String value = object == null ? "" : object.toString();
                String separator = instructions.getValueSeparator();

                boolean containsSeparator = value.contains(separator);
                boolean quote =
                        instructions.quoteAllValues() || (
                        instructions.quoteValuesContainingSeparator() && containsSeparator);

                if (containsSeparator && !quote) {
                    throw new DataExportException(
                        "Can not create row " + rowIndex + " with the given separator.\n" +
                        "Value for column " + columnName + " already contains the separator '" + separator + "'. \n" +
                        "Please consider quoting.");
                }

                if (columnIndex > 0) {
                    buffer.append(separator);
                }

                if (quote) {
                    if(value.indexOf('"') > -1) {
                        throw new DataExportException(
                            "Can not quote value of " + columnName + " at row " + rowIndex + ".\n" +
                            "Value contains quotes itself.");
                    }
                    buffer.append('"');
                    buffer.append(value);
View Full Code Here

TOP

Related Classes of com.dci.intellij.dbn.data.export.DataExportException

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.