1 19 20 package org.netbeans.modules.tasklist.usertasks.translators; 21 22 import java.io.File ; 23 import java.io.FileOutputStream ; 24 import java.io.IOException ; 25 import java.io.InputStream ; 26 import java.io.OutputStream ; 27 import java.net.MalformedURLException ; 28 import java.net.URL ; 29 import java.util.logging.Level ; 30 import javax.xml.transform.Transformer ; 31 import javax.xml.transform.TransformerConfigurationException ; 32 import javax.xml.transform.TransformerException ; 33 import javax.xml.transform.TransformerFactory ; 34 import javax.xml.transform.stream.StreamSource ; 35 36 import org.netbeans.modules.tasklist.core.export.ExportImportProvider; 37 import org.netbeans.modules.tasklist.core.export.SaveFilePanel; 38 import org.netbeans.modules.tasklist.core.util.ExtensionFileFilter; 39 import org.netbeans.modules.tasklist.core.util.SimpleWizardPanel; 40 import org.netbeans.modules.tasklist.usertasks.options.Settings; 41 import org.netbeans.modules.tasklist.usertasks.util.UTUtils; 42 import org.openide.DialogDisplayer; 43 import org.openide.NotifyDescriptor; 44 import org.openide.WizardDescriptor; 45 import org.openide.awt.HtmlBrowser; 46 import org.openide.util.NbBundle; 47 48 51 public class HtmlExportFormat extends XmlExportFormat { 52 private static String [] LAYOUTS = { 53 "usertasks-simple-html.xsl", "usertasks-effort-html.xsl", "usertasks-planning-html.xsl", "usertasks-table-html.xsl", "usertasks-tree-html.xsl" }; 59 60 66 private static void copyResourceToFile(String from, File to) 67 throws IOException { 68 InputStream is = TextExportFormat.class.getResourceAsStream(from); 69 try { 70 OutputStream os = new FileOutputStream (to); 71 try { 72 UTUtils.copyStream(is, os); 73 } finally { 74 os.close(); 75 } 76 } finally { 77 is.close(); 78 } 79 } 80 81 private String res = "usertasks-effort-html.xsl"; 83 86 public HtmlExportFormat() { 87 } 88 89 public String getName() { 90 return NbBundle.getMessage(HtmlExportFormat.class, "HTML"); } 92 93 public org.openide.WizardDescriptor getWizard() { 94 SaveFilePanel chooseFilePanel = new SaveFilePanel(); 95 SimpleWizardPanel chooseFileWP = new SimpleWizardPanel(chooseFilePanel); 96 chooseFilePanel.setWizardPanel(chooseFileWP); 97 chooseFilePanel.getFileChooser().addChoosableFileFilter( 98 new ExtensionFileFilter( 99 NbBundle.getMessage(XmlExportFormat.class, 100 "HtmlFilter"), new String [] {".html"})); chooseFilePanel.setFile(new File ( 103 Settings.getDefault().getLastUsedExportFolder(), 104 "tasklist.html")); chooseFileWP.setContentHighlightedIndex(0); 106 107 XslTemplatesPanel templatesPanel = new XslTemplatesPanel(); 108 templatesPanel.setAvailableLayouts(new String [] { 109 NbBundle.getMessage( 110 XmlExportFormat.class, "Simple"), NbBundle.getMessage( 112 XmlExportFormat.class, "Effort"), NbBundle.getMessage( 114 XmlExportFormat.class, "Planning"), NbBundle.getMessage( 116 XmlExportFormat.class, "Table"), NbBundle.getMessage( 118 XmlExportFormat.class, "Tree") }); 120 SimpleWizardPanel templatesWP = new SimpleWizardPanel(templatesPanel); 121 templatesWP.setFinishPanel(true); 122 templatesWP.setContentHighlightedIndex(1); 123 124 WizardDescriptor.Iterator iterator = 126 new WizardDescriptor.ArrayIterator( 127 new WizardDescriptor.Panel[] {chooseFileWP, templatesWP}); 128 WizardDescriptor wd = new WizardDescriptor(iterator); 129 wd.putProperty("WizardPanel_contentData", new String [] { 131 NbBundle.getMessage( 132 XmlExportFormat.class, "ChooseDestination"), NbBundle.getMessage( 134 XmlExportFormat.class, "ChooseLayout") } 136 ); wd.putProperty("WizardPanel_autoWizardStyle", Boolean.TRUE); wd.putProperty("WizardPanel_contentDisplayed", Boolean.TRUE); wd.putProperty("WizardPanel_contentNumbered", Boolean.TRUE); wd.setTitle(NbBundle.getMessage(XmlExportFormat.class, 141 "ExportHTML")); wd.putProperty(getClass().getName() + 143 ".TemplatesPanel", templatesPanel); wd.putProperty(CHOOSE_FILE_PANEL_PROP, chooseFilePanel); 145 wd.setTitleFormat(new java.text.MessageFormat ("{0}")); 147 return wd; 148 } 149 150 155 private static void showFileInBrowser(File file) { 156 URL url; 157 try { 158 url = file.toURI().toURL(); 159 } catch (MalformedURLException e) { 160 UTUtils.LOGGER.log(Level.SEVERE, "", e); 162 return; 163 } 164 165 HtmlBrowser.URLDisplayer.getDefault().showURL(url); 166 } 167 168 protected Transformer createTransformer() { 169 TransformerFactory tf = TransformerFactory.newInstance(); 170 try { 171 InputStream xsl = HtmlExportFormat.class. 172 getResourceAsStream(res); 173 return tf.newTransformer(new StreamSource (xsl)); 174 } catch (TransformerConfigurationException e) { 175 UTUtils.LOGGER.log(Level.WARNING, "", e); 176 return null; 177 } catch (TransformerException e) { 178 UTUtils.LOGGER.log(Level.WARNING, "", e); 179 return null; 180 } 181 } 182 183 public void doExportImport(ExportImportProvider provider, 184 WizardDescriptor wd) { 185 SaveFilePanel chooseFilePanel = (SaveFilePanel) 186 wd.getProperty(CHOOSE_FILE_PANEL_PROP); 187 XslTemplatesPanel templatesPanel = (XslTemplatesPanel) 188 wd.getProperty(getClass().getName() + 189 ".TemplatesPanel"); this.res = LAYOUTS[templatesPanel.getLayoutIndex()]; 191 File dir = chooseFilePanel.getFile().getParentFile(); 192 super.doExportImport(provider, wd); 193 try { 194 copyResourceToFile( 195 "/org/netbeans/modules/tasklist/core/task.gif", new File (dir, "undone.gif")); copyResourceToFile( 198 "/org/netbeans/modules/tasklist/core/doneItem.gif", new File (dir, "done.gif")); } catch (IOException ex) { 201 NotifyDescriptor nd = new NotifyDescriptor.Message(ex.getMessage(), 202 NotifyDescriptor.Message.ERROR_MESSAGE); 203 DialogDisplayer.getDefault().notify(nd); 204 } 205 if (templatesPanel.getOpenFile()) { 206 showFileInBrowser(chooseFilePanel.getFile()); 207 } 208 } 209 } 210 | Popular Tags |