📄 htmlexportdialog.java
字号:
new Object[]{getZipFilename()}
),
getResources().getString(key2),
JOptionPane.YES_NO_OPTION, JOptionPane.QUESTION_MESSAGE)
== JOptionPane.NO_OPTION)
{
return false;
}
}
try
{
final File dataDir = new File(getZipDataFilename());
final File baseDir = new File("");
if (IOUtils.getInstance().isSubDirectory(baseDir, dataDir) == false)
{
JOptionPane.showMessageDialog(this,
getResources().getString(
"htmlexportdialog.targetPathIsAbsolute"),
getResources().getString("htmlexportdialog.errorTitle"),
JOptionPane.ERROR_MESSAGE);
return false;
}
}
catch (Exception e)
{
showExceptionDialog("error.validationfailed", e);
return false;
}
return true;
}
public boolean performQueryForExport (final JFreeReport report)
{
setModal(true);
initFromConfiguration(report.getReportConfiguration());
setVisible(true);
if (isConfirmed() == false)
{
return false;
}
storeToConfiguration(report.getReportConfiguration());
return true;
}
/**
* Shows this dialog and (if the dialog is confirmed) saves the complete report into an
* HTML file.
*
* @param report the report being processed.
*
* @return A boolean.
* @deprecated this dialog should only be used to configure the export process
*/
public boolean performExport(final JFreeReport report)
{
setModal(true);
initFromConfiguration(report.getReportConfiguration());
setVisible(true);
if (isConfirmed() == false)
{
return true;
}
if (getSelectedExportMethod() == EXPORT_STREAM)
{
return writeHtmlStream(report);
}
else if (getSelectedExportMethod() == EXPORT_DIR)
{
return writeHtmlDir(report);
}
else if (getSelectedExportMethod() == EXPORT_ZIP)
{
return writeHtmlZip(report);
}
return false;
}
/**
* Returns the selected export method.
*
* @return the selected Export method, one of EXPORT_STREAM, EXPORT_ZIP or EXPORT_DIR.
*/
public int getSelectedExportMethod()
{
return exportSelection.getSelectedIndex();
}
/**
* Sets the export method.
*
* @param index the method index.
*/
public void setSelectedExportMethod(final int index)
{
exportSelection.setSelectedIndex(index);
}
/**
* Validates the contents of the dialogs input fields. If the selected file exists, it is also
* checked for validity.
*
* @return true, if the input is valid, false otherwise
*/
public boolean performValidateDir()
{
final String filename = getDirFilename();
if (filename.trim().length() == 0)
{
JOptionPane.showMessageDialog(this,
getResources().getString("htmlexportdialog.targetIsEmpty"),
getResources().getString("htmlexportdialog.errorTitle"),
JOptionPane.ERROR_MESSAGE);
return false;
}
final File f = new File(filename);
if (f.exists())
{
if (f.isFile() == false)
{
JOptionPane.showMessageDialog(this,
getResources().getString("htmlexportdialog.targetIsNoFile"),
getResources().getString("htmlexportdialog.errorTitle"),
JOptionPane.ERROR_MESSAGE);
return false;
}
if (f.canWrite() == false)
{
JOptionPane.showMessageDialog(this,
getResources().getString(
"htmlexportdialog.targetIsNotWritable"),
getResources().getString("htmlexportdialog.errorTitle"),
JOptionPane.ERROR_MESSAGE);
return false;
}
final String key1 = "htmlexportdialog.targetOverwriteConfirmation";
final String key2 = "htmlexportdialog.targetOverwriteTitle";
if (JOptionPane.showConfirmDialog(this,
MessageFormat.format(getResources().getString(key1),
new Object[]{getDirFilename()}
),
getResources().getString(key2),
JOptionPane.YES_NO_OPTION, JOptionPane.QUESTION_MESSAGE)
== JOptionPane.NO_OPTION)
{
return false;
}
}
File dataDir = new File(getDirDataFilename());
if (dataDir.isAbsolute() == false)
{
dataDir = new File(f.getParentFile(), dataDir.getPath());
}
if (dataDir.exists())
{
// dataDirectory does exist ... if no directory : fail
if (dataDir.isDirectory() == false)
{
JOptionPane.showMessageDialog(this,
getResources().getString(
"htmlexportdialog.targetDataDirIsNoDirectory"),
getResources().getString("htmlexportdialog.errorTitle"),
JOptionPane.ERROR_MESSAGE);
return false;
}
}
else
{
final String key1 = "htmlexportdialog.targetCreateDataDirConfirmation";
final String key2 = "htmlexportdialog.targetCreateDataDirTitle";
if (JOptionPane.showConfirmDialog(this,
MessageFormat.format(getResources().getString(key1),
new Object[]{getDirFilename()}
),
getResources().getString(key2),
JOptionPane.YES_NO_OPTION, JOptionPane.QUESTION_MESSAGE)
== JOptionPane.NO_OPTION)
{
return false;
}
}
return true;
}
/**
* Writes an HTML stream.
*
* @param report the report.
*
* @return A boolean.
* @deprecated this dialog should only be used to configure the export process
*/
public boolean writeHtmlStream(final JFreeReport report)
{
OutputStream out = null;
try
{
out = new BufferedOutputStream(new FileOutputStream(new File(getStreamFilename())));
final HtmlProcessor target = new HtmlProcessor(report);
target.setFilesystem(new StreamHtmlFilesystem(out));
target.setStrictLayout(isStrictLayout());
target.setProperty(HtmlProducer.ENCODING, getEncoding());
target.setProperty(HtmlProducer.AUTHOR, getAuthor());
target.setProperty(HtmlProducer.TITLE, getHTMLTitle());
target.setGenerateXHTML(isGenerateXHTML());
target.processReport();
out.close();
return true;
}
catch (Exception re)
{
showExceptionDialog("error.processingfailed", re);
return false;
}
finally
{
try
{
if (out != null)
{
out.close();
}
}
catch (Exception e)
{
showExceptionDialog("error.savefailed", e);
}
}
}
/**
* Writers the report to HTML inside a ZIP file.
*
* @param report the report.
*
* @return A boolean.
* @deprecated this dialog should only be used to configure the export process
*/
public boolean writeHtmlZip(final JFreeReport report)
{
OutputStream out = null;
try
{
out = new BufferedOutputStream(new FileOutputStream(new File(getZipFilename())));
final HtmlProcessor target = new HtmlProcessor(report);
target.setFilesystem(new ZIPHtmlFilesystem(out, getZipDataFilename()));
target.setStrictLayout(isStrictLayout());
target.setProperty(HtmlProducer.ENCODING, getEncoding());
target.setProperty(HtmlProducer.AUTHOR, getAuthor());
target.setProperty(HtmlProducer.TITLE, getHTMLTitle());
target.setGenerateXHTML(isGenerateXHTML());
target.processReport();
out.close();
return true;
}
catch (Exception re)
{
showExceptionDialog("error.processingfailed", re);
return false;
}
finally
{
try
{
if (out != null)
{
out.close();
}
}
catch (Exception e)
{
showExceptionDialog("error.savefailed", e);
}
}
}
/**
* Writes the report to HTML in a directory.
*
* @param report the report.
*
* @return A boolean.
* @deprecated this dialog should only be used to configure the export process
*/
public boolean writeHtmlDir(final JFreeReport report)
{
try
{
final File targetFile = new File(getDirFilename());
File targetDataFile = new File(getDirDataFilename());
if (targetDataFile.isAbsolute() == false)
{
targetDataFile = new File(targetFile.getParentFile(), targetDataFile.getPath());
}
if (targetDataFile.mkdirs() == false)
{
if ((targetDataFile.exists() && targetDataFile.isDirectory()) == false)
{
throw new IOException("Unable to create the mssing directories.");
}
}
final DirectoryHtmlFilesystem fs = new DirectoryHtmlFilesystem(targetFile, targetDataFile);
final HtmlProcessor target = new HtmlProcessor(report);
target.setProperty(HtmlProducer.ENCODING, getEncoding());
target.setProperty(HtmlProducer.AUTHOR, getAuthor());
target.setProperty(HtmlProducer.TITLE, getHTMLTitle());
target.setStrictLayout(isStrictLayout());
target.setGenerateXHTML(isGenerateXHTML());
target.setFilesystem(fs);
target.processReport();
return true;
}
catch (Exception re)
{
showExceptionDialog("error.processingfailed", re);
return false;
}
}
/**
* Shows the exception dialog by using localized messages. The message base is
* used to construct the localisation key by appending ".title" and ".message" to the
* base name.
*
* @param localisationBase the resource key prefix.
* @param e the exception.
*/
private void showExceptionDialog(final String localisationBase, final Exception e)
{
ExceptionDialog.showExceptionDialog(
getResources().getString(localisationBase + ".title"),
MessageFormat.format(
getResources().getString(localisationBase + ".message"),
new Object[]{e.getLocalizedMessage()}
),
e);
}
/**
* Initialises the Html export dialog from the settings in the report configuration.
*
* @param config the report configuration.
*/
public void initFromConfiguration(final ReportConfiguration config)
{
String strict = config.getConfigProperty
(HtmlProcessor.CONFIGURATION_PREFIX +
HtmlProcessor.STRICT_LAYOUT,
config.getConfigProperty (ReportConfiguration.STRICT_TABLE_LAYOUT,
ReportConfiguration.STRICT_TABLE_LAYOUT_DEFAULT));
setStrictLayout(strict.equals("true"));
String encoding = config.getConfigProperty
(HtmlProcessor.CONFIGURATION_PREFIX +
HtmlProducer.ENCODING, HtmlProducer.ENCODING_DEFAULT);
setAuthor
(config.getConfigProperty(HtmlProcessor.CONFIGURATION_PREFIX +
HtmlProducer.AUTHOR, getAuthor()));
setHTMLTitle
(config.getConfigProperty(HtmlProcessor.CONFIGURATION_PREFIX +
HtmlProducer.TITLE, getHTMLTitle()));
encodingModel.ensureEncodingAvailable(encoding);
setEncoding(encoding);
}
public void storeToConfiguration (final ReportConfiguration config)
{
config.setConfigProperty(HtmlProcessor.CONFIGURATION_PREFIX +
HtmlProducer.ENCODING, getEncoding());
config.setConfigProperty(HtmlProcessor.CONFIGURATION_PREFIX +
HtmlProducer.AUTHOR, getAuthor());
config.setConfigProperty(HtmlProcessor.CONFIGURATION_PREFIX +
HtmlProducer.TITLE, getHTMLTitle());
config.setConfigProperty(HtmlProcessor.CONFIGURATION_PREFIX +
HtmlProcessor.STRICT_LAYOUT, String.valueOf(isStrictLayout()));
}
/**
* For debugging.
*
* @param args ignored.
*/
public static void main(final String[] args)
{
final HtmlExportDialog dialog = new HtmlExportDialog();
dialog.addWindowListener(new WindowAdapter()
{
/**
* Invoked when a window is in the process of being closed.
* The close operation can be overridden at this point.
*/
public void windowClosing(final WindowEvent e)
{
System.exit(0);
}
});
dialog.pack();
dialog.setVisible(true);
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -