Re: [Squirrel-sql-develop] Fileencoding in CSV export
A Java SQL client for any JDBC compliant database
Brought to you by:
colbell,
gerdwagner
From: Gerd W. <bir...@t-...> - 2007-06-23 13:06:46
|
Hi Thorsten, thanks for your work quoted below. This should solve Andre Schild's request about Fileencoding in CSV export. In case you and Andre already talked about it, excuse me for being gabby. Gerd tmuerell wrote: > Update of /cvsroot/squirrel-sql/sql12/fw/src/net/sourceforge/squirrel_sql/fw/gui/action > In directory sc8-pr-cvs8.sourceforge.net:/tmp/cvs-serv24423/fw/src/net/sourceforge/squirrel_sql/fw/gui/action > > Modified Files: > TableExportCsvDlg.java TableExportCsvController.java > I18NStrings.properties TableExportCsvCommand.java > Log Message: > Added the ability to choose the csv export file encoding. > > Index: TableExportCsvController.java > =================================================================== > RCS file: /cvsroot/squirrel-sql/sql12/fw/src/net/sourceforge/squirrel_sql/fw/gui/action/TableExportCsvController.java,v > retrieving revision 1.9 > retrieving revision 1.10 > diff -C2 -d -r1.9 -r1.10 > *** TableExportCsvController.java 13 Dec 2006 22:24:23 -0000 1.9 > --- TableExportCsvController.java 22 Jun 2007 17:39:38 -0000 1.10 > *************** > *** 7,10 **** > --- 7,12 ---- > import javax.swing.*; > import java.io.File; > + import java.nio.charset.Charset; > + import java.nio.charset.IllegalCharsetNameException; > import java.awt.event.*; > import java.awt.*; > *************** > *** 14,17 **** > --- 16,20 ---- > { > private static final String PREF_KEY_CSV_FILE = "SquirrelSQL.csvexport.csvfile"; > + private static final String PREF_KEY_CSV_ENCODING = "SquirrelSQL.csvexport.csvencoding"; > private static final String PREF_KEY_WITH_HEADERS = "SquirrelSQL.csvexport.withColumnHeaders"; > private static final String PREF_KEY_SEPERATOR_TAB = "SquirrelSQL.csvexport.sepearatorTab"; > *************** > *** 156,159 **** > --- 159,164 ---- > _dlg.chkSeparatorTab.setEnabled(true); > _dlg.txtSeparatorChar.setEnabled(true); > + _dlg.lblCharset.setEnabled(true); > + _dlg.charsets.setEnabled(true); > > if(_dlg.chkSeparatorTab.isSelected()) > *************** > *** 177,182 **** > --- 182,189 ---- > { > _dlg.lblSeparator.setEnabled(false); > + _dlg.lblCharset.setEnabled(false); > _dlg.chkSeparatorTab.setEnabled(false); > _dlg.txtSeparatorChar.setEnabled(false); > + _dlg.charsets.setEnabled(false); > if(replaceEnding) > { > *************** > *** 355,358 **** > --- 362,366 ---- > { > Preferences.userRoot().put(PREF_KEY_CSV_FILE, _dlg.txtFile.getText()); > + Preferences.userRoot().put(PREF_KEY_CSV_ENCODING, _dlg.charsets.getSelectedItem().toString()); > Preferences.userRoot().putBoolean(PREF_KEY_WITH_HEADERS, _dlg.chkWithHeaders.isSelected()); > Preferences.userRoot().putBoolean(PREF_KEY_FORMAT_CSV, _dlg.radFormatCSV.isSelected()); > *************** > *** 370,373 **** > --- 378,382 ---- > { > _dlg.txtFile.setText(Preferences.userRoot().get(PREF_KEY_CSV_FILE, null)); > + _dlg.charsets.setSelectedItem(Preferences.userRoot().get(PREF_KEY_CSV_ENCODING, Charset.defaultCharset().name())); > _dlg.chkWithHeaders.setSelected(Preferences.userRoot().getBoolean(PREF_KEY_WITH_HEADERS, true)); > > *************** > *** 473,476 **** > --- 482,493 ---- > } > } > + > + Charset getCSVCharset() { > + try { > + return Charset.forName(_dlg.charsets.getSelectedItem().toString()); > + } catch (IllegalCharsetNameException icne) { > + return Charset.defaultCharset(); > + } > + } > > boolean includeHeaders() > > Index: TableExportCsvCommand.java > =================================================================== > RCS file: /cvsroot/squirrel-sql/sql12/fw/src/net/sourceforge/squirrel_sql/fw/gui/action/TableExportCsvCommand.java,v > retrieving revision 1.13 > retrieving revision 1.14 > diff -C2 -d -r1.13 -r1.14 > *** TableExportCsvCommand.java 21 Mar 2007 09:48:46 -0000 1.13 > --- TableExportCsvCommand.java 22 Jun 2007 17:39:38 -0000 1.14 > *************** > *** 3,8 **** > --- 3,11 ---- > import java.io.BufferedWriter; > import java.io.File; > + import java.io.FileOutputStream; > import java.io.FileWriter; > import java.io.IOException; > + import java.io.OutputStream; > + import java.io.OutputStreamWriter; > import java.sql.Types; > import java.util.Calendar; > *************** > *** 378,383 **** > throws IOException > { > ! FileWriter fw = new FileWriter(file); > ! BufferedWriter bw = new BufferedWriter(fw); > > String separator = ctrl.getSeparatorChar(); > --- 381,385 ---- > throws IOException > { > ! BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(file), ctrl.getCSVCharset())); > > String separator = ctrl.getSeparatorChar(); > *************** > *** 433,439 **** > > bw.flush(); > - fw.flush(); > bw.close(); > - fw.close(); > > return true; > --- 435,439 ---- > > Index: I18NStrings.properties > =================================================================== > RCS file: /cvsroot/squirrel-sql/sql12/fw/src/net/sourceforge/squirrel_sql/fw/gui/action/I18NStrings.properties,v > retrieving revision 1.10 > retrieving revision 1.11 > diff -C2 -d -r1.10 -r1.11 > *** I18NStrings.properties 17 Mar 2007 23:53:35 -0000 1.10 > --- I18NStrings.properties 22 Jun 2007 17:39:38 -0000 1.11 > *************** > *** 14,17 **** > --- 14,18 ---- > TableExportCsvDlg.exportCsvFile=Export to file: > TableExportCsvDlg.separator=Separator: > + TableExportCsvDlg.charset=Charset: > TableExportCsvDlg.exportCompleteTable=Export complete table > TableExportCsvDlg.exportSelection=Export selection > > Index: TableExportCsvDlg.java > =================================================================== > RCS file: /cvsroot/squirrel-sql/sql12/fw/src/net/sourceforge/squirrel_sql/fw/gui/action/TableExportCsvDlg.java,v > retrieving revision 1.4 > retrieving revision 1.5 > diff -C2 -d -r1.4 -r1.5 > *** TableExportCsvDlg.java 20 Dec 2006 21:40:28 -0000 1.4 > --- TableExportCsvDlg.java 22 Jun 2007 17:39:38 -0000 1.5 > *************** > *** 9,12 **** > --- 9,13 ---- > import javax.swing.*; > import java.awt.*; > + import java.nio.charset.Charset; > > public class TableExportCsvDlg extends JDialog > *************** > *** 21,24 **** > --- 22,26 ---- > JRadioButton radFormatCSV; > JLabel lblSeparator; > + JLabel lblCharset; > JTextField txtSeparatorChar; > JCheckBox chkSeparatorTab; > *************** > *** 32,35 **** > --- 34,38 ---- > JButton btnOk; > JButton btnCancel; > + JComboBox charsets; > > public TableExportCsvDlg() > *************** > *** 231,238 **** > ret.add(chkSeparatorTab, gbc); > > - > gbc = new GridBagConstraints(3, 0, 1, 1, 1, 0, GridBagConstraints.WEST, GridBagConstraints.HORIZONTAL, new Insets(0, 0, 0, 0), 0, 0); > ret.add(new JPanel(), gbc); > > > return ret; > --- 234,256 ---- > ret.add(chkSeparatorTab, gbc); > > gbc = new GridBagConstraints(3, 0, 1, 1, 1, 0, GridBagConstraints.WEST, GridBagConstraints.HORIZONTAL, new Insets(0, 0, 0, 0), 0, 0); > ret.add(new JPanel(), gbc); > + > + > + charsets = new JComboBox(); > + for (String s : Charset.availableCharsets().keySet()) { > + charsets.addItem(s); > + } > + > + gbc = new GridBagConstraints(0, 1, 2, 1, 0, 0, GridBagConstraints.WEST, GridBagConstraints.NONE, new Insets(0, 0, 0, 0), 0, 0); > + // i18n[TableExportCsvDlg.charset=Charset:] > + lblCharset = new JLabel(s_stringMgr.getString("TableExportCsvDlg.charset")); > + ret.add(lblCharset, gbc); > + > + gbc = new GridBagConstraints(2, 1, 1, 1, 0, 0, GridBagConstraints.WEST, GridBagConstraints.NONE, new Insets(0, 0, 0, 0), 0, 0); > + ret.add(charsets, gbc); > > + gbc = new GridBagConstraints(3, 1, 1, 1, 1, 0, GridBagConstraints.WEST, GridBagConstraints.HORIZONTAL, new Insets(0, 0, 0, 0), 0, 0); > + ret.add(new JPanel(), gbc); > > return ret; > > > ------------------------------------------------------------------------- > This SF.net email is sponsored by DB2 Express > Download DB2 Express C - the FREE version of DB2 express and take > control of your XML. No limits. Just data. Click to get it now. > http://sourceforge.net/powerbar/db2/ > _______________________________________________ > Squirrel-sql-commits mailing list > Squ...@li... > https://lists.sourceforge.net/lists/listinfo/squirrel-sql-commits > |