001: /**
002: * ===========================================
003: * JFreeReport : a free Java reporting library
004: * ===========================================
005: *
006: * Project Info: http://reporting.pentaho.org/
007: *
008: * (C) Copyright 2001-2007, by Object Refinery Ltd, Pentaho Corporation and Contributors.
009: *
010: * This library is free software; you can redistribute it and/or modify it under the terms
011: * of the GNU Lesser General Public License as published by the Free Software Foundation;
012: * either version 2.1 of the License, or (at your option) any later version.
013: *
014: * This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
015: * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
016: * See the GNU Lesser General Public License for more details.
017: *
018: * You should have received a copy of the GNU Lesser General Public License along with this
019: * library; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330,
020: * Boston, MA 02111-1307, USA.
021: *
022: * [Java is a trademark or registered trademark of Sun Microsystems, Inc.
023: * in the United States and other countries.]
024: *
025: * ------------
026: * HtmlZipExportDialog.java
027: * ------------
028: * (C) Copyright 2001-2007, by Object Refinery Ltd, Pentaho Corporation and Contributors.
029: */package org.jfree.report.modules.gui.html;
030:
031: import java.awt.BorderLayout;
032: import java.awt.Dialog;
033: import java.awt.Frame;
034: import java.awt.GridBagConstraints;
035: import java.awt.GridBagLayout;
036: import java.awt.Insets;
037: import java.awt.event.ActionEvent;
038: import java.io.File;
039: import java.text.MessageFormat;
040: import java.util.Locale;
041: import java.util.ResourceBundle;
042: import javax.swing.AbstractAction;
043: import javax.swing.Action;
044: import javax.swing.JCheckBox;
045: import javax.swing.JComboBox;
046: import javax.swing.JFileChooser;
047: import javax.swing.JLabel;
048: import javax.swing.JOptionPane;
049: import javax.swing.JPanel;
050: import javax.swing.JTabbedPane;
051: import javax.swing.JTextField;
052:
053: import org.jfree.fonts.encoding.EncodingRegistry;
054: import org.jfree.io.IOUtils;
055: import org.jfree.report.JFreeReportBoot;
056: import org.jfree.report.modules.gui.commonswing.AbstractExportDialog;
057: import org.jfree.report.modules.gui.commonswing.EncodingComboBoxModel;
058: import org.jfree.report.modules.gui.commonswing.JStatusBar;
059: import org.jfree.report.modules.gui.commonswing.StatusType;
060: import org.jfree.ui.FilesystemFilter;
061: import org.jfree.ui.action.ActionButton;
062: import org.jfree.util.Configuration;
063: import org.jfree.util.DefaultConfiguration;
064: import org.jfree.util.StringUtils;
065:
066: /**
067: * A dialog that is used to perform the printing of a report into an HTML file.
068: *
069: * @author Heiko Evermann
070: */
071: public class HtmlZipExportDialog extends AbstractExportDialog {
072: /**
073: * The 'HTML encoding' property key.
074: */
075: public static final String HTML_OUTPUT_ENCODING = "org.jfree.report.modules.output.table.html.Encoding"; //$NON-NLS-1$
076: /**
077: * A default value of the 'HTML encoding' property key.
078: */
079: public static final String HTML_OUTPUT_ENCODING_DEFAULT = "UTF-16"; //$NON-NLS-1$
080:
081: /**
082: * An action to select the export target file.
083: */
084: private class ActionSelectDirFile extends AbstractAction {
085: /**
086: * Default constructor.
087: */
088: protected ActionSelectDirFile(final ResourceBundle resources) {
089: putValue(Action.NAME, resources
090: .getString("htmlexportdialog.selectFile")); //$NON-NLS-1$
091: }
092:
093: /**
094: * Receives notification that the action has occurred.
095: *
096: * @param e the action event.
097: */
098: public void actionPerformed(final ActionEvent e) {
099: performSelectFileZip();
100: }
101: }
102:
103: /**
104: * Filename text field.
105: */
106: private JTextField txFilename;
107:
108: /**
109: * Data file name field.
110: */
111: private JTextField txDataFilename;
112:
113: /**
114: * Title text field.
115: */
116: private JTextField txTitle;
117:
118: /**
119: * Author text field.
120: */
121: private JTextField txAuthor;
122:
123: /**
124: * A combo-box for selecting the encoding.
125: */
126: private JComboBox cbEncoding;
127:
128: /**
129: * The encoding data model.
130: */
131: private EncodingComboBoxModel encodingModel;
132:
133: /**
134: * A check-box for selecting 'strict layout'.
135: */
136: private JCheckBox cbxStrictLayout;
137:
138: /**
139: * A check-box for...
140: */
141: private JCheckBox cbxCopyExternalReferences;
142:
143: /**
144: * A file chooser for a ZIP file.
145: */
146: private JFileChooser fileChooserZip;
147:
148: private static final String ZIP_FILE_EXTENSION = ".zip"; //$NON-NLS-1$
149: private static final String JAR_FILE_EXTENSION = ".jar"; //$NON-NLS-1$
150: private JStatusBar statusBar;
151: private JTextField txKeywords;
152: private JTextField txDescription;
153:
154: /**
155: * Creates a new HTML save dialog.
156: *
157: * @param owner the dialog owner.
158: */
159: public HtmlZipExportDialog(final Frame owner) {
160: super (owner);
161: initConstructor();
162: }
163:
164: /**
165: * Creates a new HTML export dialog.
166: *
167: * @param owner the dialog owner.
168: */
169: public HtmlZipExportDialog(final Dialog owner) {
170: super (owner);
171: initConstructor();
172: }
173:
174: /**
175: * Creates a new HTML save dialog. The created dialog is modal.
176: */
177: public HtmlZipExportDialog() {
178: initConstructor();
179: }
180:
181: /**
182: * Initialisation.
183: */
184: private void initConstructor() {
185: statusBar = new JStatusBar();
186: setTitle(getResources().getString(
187: "htmlexportdialog.dialogtitle")); //$NON-NLS-1$
188: initialize();
189: clear();
190: }
191:
192: public JStatusBar getStatusBar() {
193: return statusBar;
194: }
195:
196: private JPanel createExportPanel() {
197: final JLabel lblDirFileName = new JLabel(getResources()
198: .getString("htmlexportdialog.filename")); //$NON-NLS-1$
199: final JLabel lblDirDataFileName = new JLabel(getResources()
200: .getString("htmlexportdialog.datafilename")); //$NON-NLS-1$
201:
202: final JPanel contentPane = new JPanel();
203: contentPane.setLayout(new GridBagLayout());
204:
205: GridBagConstraints gbc = new GridBagConstraints();
206: gbc.fill = GridBagConstraints.NONE;
207: gbc.anchor = GridBagConstraints.WEST;
208: gbc.gridx = 0;
209: gbc.gridy = 1;
210: gbc.insets = new Insets(1, 1, 1, 5);
211: contentPane.add(lblDirFileName, gbc);
212:
213: gbc = new GridBagConstraints();
214: gbc.anchor = GridBagConstraints.WEST;
215: gbc.fill = GridBagConstraints.HORIZONTAL;
216: gbc.gridx = 1;
217: gbc.gridy = 1;
218: gbc.gridwidth = 1;
219: gbc.weightx = 1;
220: gbc.insets = new Insets(1, 1, 1, 1);
221: contentPane.add(txFilename, gbc);
222:
223: gbc = new GridBagConstraints();
224: gbc.anchor = GridBagConstraints.WEST;
225: gbc.fill = GridBagConstraints.HORIZONTAL;
226: gbc.gridx = 2;
227: gbc.gridy = 1;
228: contentPane.add(new ActionButton(new ActionSelectDirFile(
229: getResources())), gbc);
230:
231: gbc = new GridBagConstraints();
232: gbc.fill = GridBagConstraints.NONE;
233: gbc.anchor = GridBagConstraints.WEST;
234: gbc.gridx = 0;
235: gbc.gridy = 2;
236: gbc.insets = new Insets(1, 1, 1, 5);
237: contentPane.add(lblDirDataFileName, gbc);
238:
239: gbc = new GridBagConstraints();
240: gbc.anchor = GridBagConstraints.WEST;
241: gbc.fill = GridBagConstraints.HORIZONTAL;
242: gbc.gridx = 1;
243: gbc.gridy = 2;
244: gbc.gridwidth = 1;
245: gbc.weightx = 1;
246: gbc.insets = new Insets(1, 1, 1, 1);
247: contentPane.add(txDataFilename, gbc);
248:
249: final JPanel advancedOptionsPane = new JPanel();
250: advancedOptionsPane.setLayout(new BorderLayout());
251: advancedOptionsPane.add(contentPane, BorderLayout.NORTH);
252: return advancedOptionsPane;
253: }
254:
255: private JPanel createExportOptionsPanel() {
256: final JLabel lblEncoding = new JLabel(getResources().getString(
257: "htmlexportdialog.encoding")); //$NON-NLS-1$
258: final JPanel contentPane = new JPanel();
259: contentPane.setLayout(new GridBagLayout());
260:
261: GridBagConstraints gbc = new GridBagConstraints();
262: gbc.anchor = GridBagConstraints.WEST;
263: gbc.fill = GridBagConstraints.NONE;
264: gbc.gridx = 1;
265: gbc.gridy = 2;
266: gbc.gridwidth = 1;
267: gbc.weightx = 1;
268: gbc.insets = new Insets(1, 1, 1, 1);
269: contentPane.add(cbxCopyExternalReferences, gbc);
270:
271: gbc = new GridBagConstraints();
272: gbc.anchor = GridBagConstraints.WEST;
273: gbc.gridx = 0;
274: gbc.gridy = 0;
275: gbc.insets = new Insets(1, 1, 1, 1);
276: contentPane.add(lblEncoding, gbc);
277:
278: gbc = new GridBagConstraints();
279: gbc.fill = GridBagConstraints.HORIZONTAL;
280: gbc.weightx = 1;
281: gbc.gridx = 1;
282: gbc.gridy = 0;
283: gbc.gridwidth = 2;
284: gbc.insets = new Insets(1, 1, 1, 1);
285: contentPane.add(cbEncoding, gbc);
286:
287: gbc = new GridBagConstraints();
288: gbc.anchor = GridBagConstraints.WEST;
289: gbc.fill = GridBagConstraints.HORIZONTAL;
290: gbc.gridx = 1;
291: gbc.gridy = 1;
292: gbc.gridwidth = 2;
293: gbc.insets = new Insets(1, 1, 1, 1);
294: contentPane.add(cbxStrictLayout, gbc);
295:
296: final JPanel advancedOptionsPane = new JPanel();
297: advancedOptionsPane.setLayout(new BorderLayout());
298: advancedOptionsPane.add(contentPane, BorderLayout.NORTH);
299: return advancedOptionsPane;
300: }
301:
302: private JPanel createMetaDataPanel() {
303: final JPanel contentPane = new JPanel();
304: contentPane.setLayout(new GridBagLayout());
305:
306: final JLabel lblAuthor = new JLabel(getResources().getString(
307: "htmlexportdialog.author")); //$NON-NLS-1$
308: final JLabel lblTitel = new JLabel(getResources().getString(
309: "htmlexportdialog.title")); //$NON-NLS-1$
310: final JLabel lblKeywords = new JLabel(getResources().getString(
311: "htmlexportdialog.keywords")); //$NON-NLS-1$
312: final JLabel lblDescription = new JLabel(getResources()
313: .getString("htmlexportdialog.description")); //$NON-NLS-1$
314:
315: GridBagConstraints gbc = new GridBagConstraints();
316: gbc.gridx = 0;
317: gbc.gridy = 0;
318: gbc.anchor = GridBagConstraints.WEST;
319: gbc.insets = new Insets(3, 1, 1, 1);
320: contentPane.add(lblTitel, gbc);
321:
322: gbc = new GridBagConstraints();
323: gbc.anchor = GridBagConstraints.WEST;
324: gbc.gridx = 0;
325: gbc.gridy = 1;
326: gbc.insets = new Insets(1, 1, 1, 1);
327: contentPane.add(lblAuthor, gbc);
328:
329: gbc = new GridBagConstraints();
330: gbc.anchor = GridBagConstraints.WEST;
331: gbc.gridx = 0;
332: gbc.gridy = 2;
333: gbc.insets = new Insets(1, 1, 1, 1);
334: contentPane.add(lblKeywords, gbc);
335:
336: gbc = new GridBagConstraints();
337: gbc.anchor = GridBagConstraints.WEST;
338: gbc.gridx = 0;
339: gbc.gridy = 3;
340: gbc.insets = new Insets(1, 1, 1, 1);
341: contentPane.add(lblDescription, gbc);
342:
343: gbc = new GridBagConstraints();
344: gbc.fill = GridBagConstraints.HORIZONTAL;
345: gbc.weightx = 1;
346: gbc.gridx = 1;
347: gbc.gridy = 0;
348: gbc.gridwidth = 2;
349: gbc.insets = new Insets(3, 1, 1, 1);
350: contentPane.add(txTitle, gbc);
351:
352: gbc = new GridBagConstraints();
353: gbc.fill = GridBagConstraints.HORIZONTAL;
354: gbc.weightx = 1;
355: gbc.gridx = 1;
356: gbc.gridy = 1;
357: gbc.gridwidth = 2;
358: gbc.insets = new Insets(1, 1, 1, 1);
359: contentPane.add(txAuthor, gbc);
360:
361: gbc = new GridBagConstraints();
362: gbc.fill = GridBagConstraints.HORIZONTAL;
363: gbc.weightx = 1;
364: gbc.gridx = 1;
365: gbc.gridy = 2;
366: gbc.gridwidth = 2;
367: gbc.insets = new Insets(1, 1, 1, 1);
368: contentPane.add(txKeywords, gbc);
369:
370: gbc = new GridBagConstraints();
371: gbc.fill = GridBagConstraints.HORIZONTAL;
372: gbc.weightx = 1;
373: gbc.gridx = 1;
374: gbc.gridy = 3;
375: gbc.gridwidth = 2;
376: gbc.insets = new Insets(1, 1, 1, 1);
377: contentPane.add(txDescription, gbc);
378:
379: final JPanel advancedOptionsPane = new JPanel();
380: advancedOptionsPane.setLayout(new BorderLayout());
381: advancedOptionsPane.add(contentPane, BorderLayout.NORTH);
382: return advancedOptionsPane;
383: }
384:
385: /**
386: * Initializes the Swing components of this dialog.
387: */
388: private void initialize() {
389:
390: txAuthor = new JTextField();
391: txAuthor.setColumns(40);
392: txTitle = new JTextField();
393: txTitle.setColumns(40);
394: txKeywords = new JTextField();
395: txKeywords.setColumns(40);
396: txDescription = new JTextField();
397: txDescription.setColumns(40);
398: txFilename = new JTextField();
399: txFilename.setColumns(40);
400: txDataFilename = new JTextField();
401: txDataFilename.setColumns(40);
402:
403: encodingModel = EncodingComboBoxModel.createDefaultModel(Locale
404: .getDefault());
405: encodingModel.sort();
406:
407: cbEncoding = new JComboBox(encodingModel);
408: cbxStrictLayout = new JCheckBox(getResources().getString(
409: "htmlexportdialog.strict-layout")); //$NON-NLS-1$
410: cbxCopyExternalReferences = new JCheckBox(getResources()
411: .getString("htmlexportdialog.copy-external-references")); //$NON-NLS-1$
412:
413: getFormValidator().registerButton(cbxStrictLayout);
414: getFormValidator().registerTextField(txFilename);
415: getFormValidator().registerTextField(txDataFilename);
416: getFormValidator().registerComboBox(cbEncoding);
417:
418: final JPanel exportPane = createExportPanel();
419:
420: final Configuration config = JFreeReportBoot.getInstance()
421: .getGlobalConfig();
422: final boolean advancedSettingsTabAvail = "true"
423: .equals(config
424: .getConfigProperty("org.jfree.report.modules.gui.html.zip.AdvancedSettingsAvailable"));
425: final boolean metaDataSettingsTabAvail = "true"
426: .equals(config
427: .getConfigProperty("org.jfree.report.modules.gui.html.zip.MetaDataSettingsAvailable"));
428: if (advancedSettingsTabAvail || metaDataSettingsTabAvail) {
429: final JTabbedPane tabbedPane = new JTabbedPane();
430: tabbedPane.add(getResources().getString(
431: "htmlexportdialog.export-settings"), exportPane); //$NON-NLS-1$
432: if (metaDataSettingsTabAvail) {
433: tabbedPane
434: .add(
435: getResources()
436: .getString(
437: "htmlexportdialog.metadata-settings"), createMetaDataPanel()); //$NON-NLS-1$
438: }
439: if (advancedSettingsTabAvail) {
440: tabbedPane
441: .add(
442: getResources()
443: .getString(
444: "htmlexportdialog.advanced-settings"), createExportOptionsPanel()); //$NON-NLS-1$
445: }
446:
447: setContentPane(createContentPane(tabbedPane));
448: } else {
449: setContentPane(createContentPane(exportPane));
450: }
451: }
452:
453: /**
454: * Returns the title of the HTML file.
455: *
456: * @return the title
457: */
458: public String getHTMLTitle() {
459: return txTitle.getText();
460: }
461:
462: /**
463: * Defines the title of the HTML file.
464: *
465: * @param title the title
466: */
467: public void setHTMLTitle(final String title) {
468: this .txTitle.setText(title);
469: }
470:
471: /**
472: * Gets the author of the dialog. This is not yet implemented in the HTML-Target.
473: *
474: * @return the name of the author of this report.
475: */
476: public String getAuthor() {
477: return txAuthor.getText();
478: }
479:
480: /**
481: * Defines the Author of the report. Any freeform text is valid. This defaults to the
482: * value of the systemProperty "user.name".
483: *
484: * @param author the name of the author.
485: */
486: public void setAuthor(final String author) {
487: this .txAuthor.setText(author);
488: }
489:
490: public void setKeywords(final String keywords) {
491: this .txKeywords.setText(keywords);
492: }
493:
494: public String getKeywords() {
495: return this .txKeywords.getText();
496: }
497:
498: public void setDescription(final String description) {
499: this .txDescription.setText(description);
500: }
501:
502: public String getDescription() {
503: return this .txDescription.getText();
504: }
505:
506: /**
507: * Clears all selections and input fields.
508: */
509: public void clear() {
510: txAuthor.setText(JFreeReportBoot.getInstance()
511: .getGlobalConfig().getConfigProperty("user.name", "")); //$NON-NLS-1$ //$NON-NLS-2$
512: txFilename.setText(""); //$NON-NLS-1$
513: txDataFilename.setText(""); //$NON-NLS-1$
514: txTitle.setText(""); //$NON-NLS-1$
515: txKeywords.setText(""); //$NON-NLS-1$
516: txDescription.setText(""); //$NON-NLS-1$
517: cbEncoding
518: .setSelectedIndex(encodingModel
519: .indexOf(EncodingRegistry
520: .getPlatformDefaultEncoding()));
521: cbxCopyExternalReferences.setSelected(false);
522: cbxStrictLayout.setSelected(false);
523: }
524:
525: /**
526: * Returns a new (and not connected to the default config from the job)
527: * configuration containing all properties from the dialog.
528: *
529: * @param full
530: * @return
531: */
532: protected Configuration grabDialogContents(final boolean full) {
533: final DefaultConfiguration p = new DefaultConfiguration();
534: if (full) {
535: p
536: .setProperty(
537: "org.jfree.report.modules.gui.html.ExportMethod", "zip"); //$NON-NLS-1$ //$NON-NLS-2$
538: p
539: .setProperty(
540: "org.jfree.report.modules.gui.html.zip.DataDirectory", getDataFilename()); //$NON-NLS-1$
541: p
542: .setProperty(
543: "org.jfree.report.modules.gui.html.zip.TargetFileName", getFilename()); //$NON-NLS-1$
544: }
545:
546: p
547: .setConfigProperty(
548: "org.jfree.report.modules.output.table.html.Keywords", getKeywords()); //$NON-NLS-1$
549: p
550: .setConfigProperty(
551: "org.jfree.report.modules.output.table.html.Description", getDescription()); //$NON-NLS-1$
552: p
553: .setConfigProperty(
554: "org.jfree.report.modules.output.table.html.Author", getAuthor()); //$NON-NLS-1$
555: p
556: .setConfigProperty(
557: "org.jfree.report.modules.output.table.html.Encoding", getEncoding()); //$NON-NLS-1$
558: p
559: .setConfigProperty(
560: "org.jfree.report.modules.output.table.html.Title", getHTMLTitle()); //$NON-NLS-1$
561: p
562: .setConfigProperty(
563: "org.jfree.report.modules.output.table.html.StrictLayout", String.valueOf(isStrictLayout())); //$NON-NLS-1$
564: return p;
565: }
566:
567: protected void setDialogContents(final Configuration p) {
568: setHTMLTitle(p.getConfigProperty(
569: "org.jfree.report.modules.output.table.html.Title", //$NON-NLS-1$
570: p.getConfigProperty("org.jfree.report.metadata.Title"))); //$NON-NLS-1$
571: setAuthor(p
572: .getConfigProperty(
573: "org.jfree.report.modules.output.table.html.Author", //$NON-NLS-1$
574: p
575: .getConfigProperty("org.jfree.report.metadata.Author"))); //$NON-NLS-1$
576: setKeywords(p
577: .getConfigProperty(
578: "org.jfree.report.modules.output.table.html.Keywords", //$NON-NLS-1$
579: p
580: .getConfigProperty("org.jfree.report.metadata.Keywords"))); //$NON-NLS-1$
581: setDescription(p
582: .getConfigProperty(
583: "org.jfree.report.modules.output.table.html.Description", //$NON-NLS-1$
584: p
585: .getConfigProperty("org.jfree.report.metadata.Description"))); //$NON-NLS-1$
586:
587: setStrictLayout("true".equals(p.getConfigProperty //$NON-NLS-1$
588: ("org.jfree.report.modules.output.table.html.StrictLayout"))); //$NON-NLS-1$
589:
590: final String encoding = p.getConfigProperty(
591: "org.jfree.report.modules.output.table.html.Encoding", //$NON-NLS-1$
592: EncodingRegistry.getPlatformDefaultEncoding());
593: encodingModel.ensureEncodingAvailable(encoding);
594: setEncoding(encoding);
595:
596: setDataFilename(p
597: .getConfigProperty(
598: "org.jfree.report.modules.gui.html.zip.DataDirectory", "")); //$NON-NLS-1$ //$NON-NLS-2$
599: setFilename(p
600: .getConfigProperty(
601: "org.jfree.report.modules.gui.html.zip.TargetFileName", "")); //$NON-NLS-1$ //$NON-NLS-2$
602:
603: }
604:
605: /**
606: * Returns the directory data file name.
607: *
608: * @return The file name.
609: */
610: public String getDataFilename() {
611: return txDataFilename.getText();
612: }
613:
614: /**
615: * Sets the directory data file name.
616: *
617: * @param dirFilename the file name.
618: */
619: public void setDataFilename(final String dirFilename) {
620: this .txDataFilename.setText(dirFilename);
621: }
622:
623: /**
624: * Returns the directory file name.
625: *
626: * @return The directory file name.
627: */
628: public String getFilename() {
629: return txFilename.getText();
630: }
631:
632: /**
633: * Sets the directory file name.
634: *
635: * @param dirFilename the file name.
636: */
637: public void setFilename(final String dirFilename) {
638: this .txFilename.setText(dirFilename);
639: }
640:
641: /**
642: * Returns the setting of the 'strict layout' check-box.
643: *
644: * @return A boolean.
645: */
646: public boolean isStrictLayout() {
647: return cbxStrictLayout.isSelected();
648: }
649:
650: /**
651: * Sets the 'strict layout' check-box.
652: *
653: * @param s boolean.
654: */
655: public void setStrictLayout(final boolean s) {
656: cbxStrictLayout.setSelected(s);
657: }
658:
659: /**
660: * Returns the selected encoding.
661: *
662: * @return The encoding name.
663: */
664: public String getEncoding() {
665: if (cbEncoding.getSelectedIndex() == -1) {
666: return EncodingRegistry.getPlatformDefaultEncoding();
667: } else {
668: return encodingModel.getEncoding(cbEncoding
669: .getSelectedIndex());
670: }
671: }
672:
673: /**
674: * Sets the encoding.
675: *
676: * @param encoding the encoding name.
677: */
678: public void setEncoding(final String encoding) {
679: cbEncoding.setSelectedIndex(encodingModel.indexOf(encoding));
680: }
681:
682: /**
683: * Selects a file to use as target for the report processing.
684: */
685: protected void performSelectFileZip() {
686: final File file = new File(getFilename());
687:
688: if (fileChooserZip == null) {
689: fileChooserZip = new JFileChooser();
690: fileChooserZip.addChoosableFileFilter(new FilesystemFilter(
691: new String[] { ZIP_FILE_EXTENSION,
692: JAR_FILE_EXTENSION },
693: getResources().getString(
694: "htmlexportdialog.zip-archives"), true)); //$NON-NLS-1$
695: fileChooserZip.setMultiSelectionEnabled(false);
696: }
697:
698: fileChooserZip.setCurrentDirectory(file);
699: fileChooserZip.setSelectedFile(file);
700: final int option = fileChooserZip.showSaveDialog(this );
701: if (option == JFileChooser.APPROVE_OPTION) {
702: final File selFile = fileChooserZip.getSelectedFile();
703: String selFileName = selFile.getAbsolutePath();
704:
705: // Test if ends on xls
706: if (StringUtils.endsWithIgnoreCase(selFileName,
707: ZIP_FILE_EXTENSION) == false) {
708: selFileName = selFileName + ZIP_FILE_EXTENSION;
709: }
710: setFilename(selFileName);
711: }
712: }
713:
714: /**
715: * Validates the contents of the dialog's input fields. If the selected file exists, it
716: * is also checked for validity.
717: *
718: * @return true, if the input is valid, false otherwise
719: */
720: public boolean performValidate() {
721: getStatusBar().clear();
722:
723: final String filename = getFilename();
724: if (filename.trim().length() == 0) {
725: getStatusBar().setStatus(
726: StatusType.ERROR,
727: getResources().getString(
728: "htmlexportdialog.targetIsEmpty")); //$NON-NLS-1$
729: return false;
730: }
731: final File f = new File(filename);
732: if (f.exists()) {
733: if (f.isFile() == false) {
734: getStatusBar().setStatus(
735: StatusType.ERROR,
736: getResources().getString(
737: "htmlexportdialog.targetIsNoFile")); //$NON-NLS-1$
738: return false;
739: }
740: if (f.canWrite() == false) {
741: getStatusBar()
742: .setStatus(
743: StatusType.ERROR,
744: getResources()
745: .getString(
746: "htmlexportdialog.targetIsNotWritable")); //$NON-NLS-1$
747: return false;
748: }
749:
750: final String message = MessageFormat.format(getResources()
751: .getString("htmlexportdialog.targetExistsWarning"), //$NON-NLS-1$
752: new Object[] { filename });
753: getStatusBar().setStatus(StatusType.WARNING, message);
754: }
755:
756: try {
757: final File dataDir = new File(getDataFilename());
758: final File baseDir = new File(""); //$NON-NLS-1$
759:
760: if (IOUtils.getInstance().isSubDirectory(baseDir, dataDir) == false) {
761: getStatusBar()
762: .setStatus(
763: StatusType.ERROR,
764: getResources()
765: .getString(
766: "htmlexportdialog.targetPathIsAbsolute")); //$NON-NLS-1$
767: return false;
768: }
769: } catch (Exception e) {
770: getStatusBar().setStatus(StatusType.ERROR,
771: "error.validationfailed"); //$NON-NLS-1$
772: return false;
773: }
774: return true;
775: }
776:
777: protected boolean performConfirm() {
778: final String filename = getFilename();
779: final File f = new File(filename).getAbsoluteFile();
780: if (f.exists()) {
781: final String key1 = "htmlexportdialog.targetOverwriteConfirmation"; //$NON-NLS-1$
782: final String key2 = "htmlexportdialog.targetOverwriteTitle"; //$NON-NLS-1$
783: if (JOptionPane.showConfirmDialog(this , MessageFormat
784: .format(getResources().getString(key1),
785: new Object[] { getFilename() }),
786: getResources().getString(key2),
787: JOptionPane.YES_NO_OPTION,
788: JOptionPane.QUESTION_MESSAGE) == JOptionPane.NO_OPTION) {
789: return false;
790: }
791: }
792:
793: return true;
794: }
795:
796: protected String getConfigurationSuffix() {
797: return "_html-zip-export"; //$NON-NLS-1$
798: }
799:
800: protected String getResourceBaseName() {
801: return HtmlZipExportPlugin.BASE_RESOURCE_CLASS;
802: }
803:
804: protected String getConfigurationPrefix() {
805: return "org.jfree.report.modules.gui.html.zip."; //$NON-NLS-1$
806: }
807: }
|