⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 exportertohtml.java

📁 It is all about project scheduling. GanttProject is a tool for creating a project schedule by means
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
/* * Created on 17.05.2005 */package org.ganttproject.impex.htmlpdf;import java.awt.image.BufferedImage;import java.awt.image.RenderedImage;import java.io.File;import java.io.FileInputStream;import java.io.FileOutputStream;import java.io.IOException;import java.lang.reflect.Array;import java.net.MalformedURLException;import java.net.URI;import java.net.URISyntaxException;import java.net.URL;import java.rmi.server.ExportException;import java.util.ArrayList;import java.util.List;import javax.imageio.ImageIO;import javax.xml.transform.OutputKeys;import javax.xml.transform.Result;import javax.xml.transform.Transformer;import javax.xml.transform.TransformerConfigurationException;import javax.xml.transform.TransformerFactory;import javax.xml.transform.sax.SAXTransformerFactory;import javax.xml.transform.sax.TransformerHandler;import javax.xml.transform.stream.StreamResult;import javax.xml.transform.stream.StreamSource;import org.eclipse.core.runtime.IConfigurationElement;import org.eclipse.core.runtime.IExtensionRegistry;import org.eclipse.core.runtime.IProgressMonitor;import org.eclipse.core.runtime.IStatus;import org.eclipse.core.runtime.Platform;import org.eclipse.core.runtime.Status;import org.eclipse.core.runtime.jobs.IJobManager;import org.eclipse.core.runtime.jobs.Job;import org.xml.sax.Attributes;import org.xml.sax.ContentHandler;import org.xml.sax.SAXException;import org.xml.sax.helpers.AttributesImpl;import net.sourceforge.ganttproject.GanttCalendar;import net.sourceforge.ganttproject.GanttExportSettings;import net.sourceforge.ganttproject.GanttProject;import net.sourceforge.ganttproject.chart.Chart;import net.sourceforge.ganttproject.export.Exporter;import net.sourceforge.ganttproject.export.TaskVisitor;import net.sourceforge.ganttproject.gui.UIFacade;import net.sourceforge.ganttproject.gui.options.model.DefaultEnumerationOption;import net.sourceforge.ganttproject.gui.options.model.EnumerationOption;import net.sourceforge.ganttproject.gui.options.model.GPOption;import net.sourceforge.ganttproject.gui.options.model.GPOptionGroup;import net.sourceforge.ganttproject.language.GanttLanguage;import net.sourceforge.ganttproject.resource.HumanResource;import net.sourceforge.ganttproject.resource.HumanResourceManager;import net.sourceforge.ganttproject.task.ResourceAssignment;import net.sourceforge.ganttproject.task.Task;import net.sourceforge.ganttproject.task.TaskManager;import net.sourceforge.ganttproject.util.FileUtil;public class ExporterToHTML extends ExporterBase implements Exporter {    private static final String PNG_FORMAT_NAME = "png";//    private AdvancedOptionGroup myAdvancedOptions = new AdvancedOptionGroup(new GPOption[0]);    private EnumerationOption myStylesheetOption;    private HTMLStylesheet mySelectedStylesheet;    public String getFileTypeDescription() {        return GanttLanguage.getInstance().getText("impex.html.description");    }    protected void setSelectedStylesheet(Stylesheet stylesheet) {        mySelectedStylesheet = (HTMLStylesheet) stylesheet;    }        public GPOptionGroup[] getSecondaryOptions() {        //return getGanttChart().getOptionGroups();        return null;    }            public String getFileNamePattern() {        return "html";    }    protected Job[] createJobs(File outputFile, List resultFiles) {        Job generateGanttChartJob = createGenerateGanttChartJob(outputFile, resultFiles);        Job generateResourceChartJob = createGenerateResourceChartJob(outputFile, resultFiles);        Job generatePagesJob = createGeneratePagesJob(outputFile, resultFiles);        Job copyImagesJob = createCopyImagesJob(outputFile, resultFiles);        return new Job[] {                generateGanttChartJob, generateResourceChartJob, generatePagesJob, copyImagesJob        };    }        private Job createGenerateGanttChartJob(final File outputFile, final List resultFiles) {        Job result = new ExportJob("generate gantt chart") {            protected IStatus run(IProgressMonitor monitor) {                if (monitor.isCanceled()) {                    Platform.getJobManager().cancel(ExporterBase.EXPORT_JOB_FAMILY);                    return Status.CANCEL_STATUS;                }                try {                    RenderedImage ganttChartImage = getGanttChart().getRenderedImage(new GanttExportSettings(true, true, true, true));                    File ganttChartImageFile;                    ganttChartImageFile = replaceExtension(outputFile, GANTT_CHART_FILE_EXTENSION);                    ImageIO.write(ganttChartImage, PNG_FORMAT_NAME, ganttChartImageFile);                    resultFiles.add(ganttChartImageFile);                    monitor.worked(1);                } catch (IOException e) {                    e.printStackTrace();                    this.cancel();                    return Status.CANCEL_STATUS;                } catch (OutOfMemoryError e) {                    cancel();                    ExporterToHTML.this.getUIFacade().showErrorDialog(new RuntimeException("Out of memory when creating Gantt chart image", e));                    return Status.CANCEL_STATUS;                }                return Status.OK_STATUS;            }        };        return result;    }        private Job createGenerateResourceChartJob(final File outputFile, final List resultFiles) {        Job result = new ExportJob("Generate resource chart") {            protected IStatus run(IProgressMonitor monitor) {                if (monitor.isCanceled()) {                    Platform.getJobManager().cancel(ExporterBase.EXPORT_JOB_FAMILY);                    return Status.CANCEL_STATUS;                }                try {                    RenderedImage resourceChartImage = getResourceChart().getRenderedImage(new GanttExportSettings(true, true, true, true));                    File resourceChartImageFile = replaceExtension(outputFile, RESOURCE_CHART_FILE_EXTENSION);                    ImageIO.write(resourceChartImage, PNG_FORMAT_NAME, resourceChartImageFile);                    resultFiles.add(resourceChartImageFile);                    monitor.worked(1);                } catch (IOException e) {                    e.printStackTrace();                    this.cancel();                    return Status.CANCEL_STATUS;                } catch (OutOfMemoryError e) {                    cancel();                    ExporterToHTML.this.getUIFacade().showErrorDialog(new RuntimeException("Out of memory when creating resource chart image", e));                    return Status.CANCEL_STATUS;                }                return Status.OK_STATUS;            }        };        return result;    }        private Job createGeneratePagesJob(final File outputFile, final List resultFiles) {        Job result = new ExportJob("Generate HTML pages") {            protected IStatus run(IProgressMonitor monitor) {                if (monitor.isCanceled()) {                    Platform.getJobManager().cancel(ExporterBase.EXPORT_JOB_FAMILY);                    return Status.CANCEL_STATUS;                }                try {                    {                        TransformerHandler handler = mySelectedStylesheet.createTitlePageHandler();                        handler.setResult(new StreamResult(outputFile));                        serialize(handler, outputFile);                        resultFiles.add(outputFile);                    }                    //                    {                        TransformerHandler handler = mySelectedStylesheet.createTasksPageHandler();                        File tasksPageFile = appendSuffixBeforeExtension(outputFile, "-tasks");                        handler.setResult(new StreamResult(tasksPageFile));                        serialize(handler, outputFile);                        resultFiles.add(tasksPageFile);                    }                    {                        TransformerHandler handler = mySelectedStylesheet.createGanttChartPageHandler();                        File chartPageFile = appendSuffixBeforeExtension(outputFile, "-chart");                        handler.setResult(new StreamResult(chartPageFile));                        serialize(handler, outputFile);                        resultFiles.add(chartPageFile);                           }                    {                        TransformerHandler handler = mySelectedStylesheet.createResourcesPageHandler();                        File resourcesPageFile = appendSuffixBeforeExtension(outputFile, "-resources");                        handler.setResult(new StreamResult(resourcesPageFile));                        serialize(handler, outputFile);                        resultFiles.add(resourcesPageFile);                                                        }                    monitor.worked(1);                } catch (SAXException e) {                    e.printStackTrace();                    this.cancel();                } catch (IOException e) {                    this.cancel();                    e.printStackTrace();                } catch (OutOfMemoryError e) {                    cancel();                    ExporterToHTML.this.getUIFacade().showErrorDialog(new RuntimeException("Out of memory when running XSL transformation", e));                    return Status.CANCEL_STATUS;                }                finally {                                    }                return Status.OK_STATUS;            }                    };        return result;    }        private Job createCopyImagesJob(final File outputFile, final List resultFiles) {        Job result = new ExportJob("Copying images") {            protected IStatus run(IProgressMonitor monitor) {                if (monitor.isCanceled()) {                    Platform.getJobManager().cancel(ExporterBase.EXPORT_JOB_FAMILY);                    return Status.CANCEL_STATUS;                }                try {                    File imagesDir = mySelectedStylesheet.getImagesDirectory();                    if (imagesDir!=null && imagesDir.isDirectory() && imagesDir.exists()) {                        File[] lof = imagesDir.listFiles();                        if (lof.length != 0) {                            File resultImagesDir = new File(outputFile.getParentFile(), imagesDir.getName());                            if (resultImagesDir.mkdir()) {                                for (int i = 0; i < lof.length; i++) {                                    File nextInFile = lof[i];                                    File outFile = new File(resultImagesDir, nextInFile.getName());                                    outFile.createNewFile();                                    FileInputStream inStream = new FileInputStream(nextInFile);                                    FileOutputStream outStream = new FileOutputStream(outFile);                                    byte[] buffer = new byte[(int) nextInFile.length()];                                    inStream.read(buffer);                                    outStream.write(buffer);                                }                            }                        }                    }                    monitor.worked(1);                } catch (IOException e) {                    e.printStackTrace();                    this.cancel();                    return Status.CANCEL_STATUS;                }                finally {                                    }                return Status.OK_STATUS;            }        };        return result;    }        private String i18n(String key) {

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -