📄 exportertohtml.java
字号:
String text = GanttLanguage.getInstance().getText(key); return GanttLanguage.getInstance().correctLabel(text); } private void serialize(TransformerHandler handler, File outputFile) throws SAXException, IOException { String filenameWithoutExtension = getFilenameWithoutExtension(outputFile); handler.startDocument(); AttributesImpl attrs = new AttributesImpl(); startElement("ganttproject",attrs, handler); textElement("title", attrs, "GanttProject - " + filenameWithoutExtension, handler); // addAttribute("prefix", filenameWithoutExtension, attrs); startElement("links", attrs, handler); textElement("home", attrs, i18n("home"), handler); textElement("chart", attrs, i18n("gantt"), handler); textElement("tasks", attrs, i18n("task"), handler); textElement("resources", attrs, i18n("human"), handler); endElement("links", handler); // startElement("project", attrs, handler); addAttribute("title", i18n("project"), attrs); textElement("name", attrs, getProject().getProjectName(), handler); addAttribute("title", i18n("organization"), attrs); textElement("organization", attrs, getProject().getOrganization(), handler); addAttribute("title", i18n("webLink"), attrs); textElement("webLink", attrs, getProject().getWebLink(), handler); addAttribute("title", i18n("shortDescription"), attrs); textElement("description", attrs, getProject().getDescription(), handler); endElement("project", handler); // //TODO: [dbarashev, 10.09.2005] introduce output files grouping structure String ganttChartFileName = replaceExtension(outputFile,GANTT_CHART_FILE_EXTENSION).getName(); textElement("chart", attrs, ganttChartFileName, handler); addAttribute("name", i18n("colName"), attrs); addAttribute("role", i18n("colRole"), attrs); addAttribute("mail", i18n("colMail"), attrs); addAttribute("phone", i18n("colPhone"), attrs); startElement("resources", attrs, handler); writeResources((HumanResourceManager) getProject().getHumanResourceManager(), handler); String resourceChartFileName = replaceExtension(outputFile, RESOURCE_CHART_FILE_EXTENSION).getName(); addAttribute("path", resourceChartFileName, attrs); emptyElement("chart", attrs, handler); endElement("resources", handler); // addAttribute("name", i18n("name"), attrs); addAttribute("begin", i18n("start"), attrs); addAttribute("end", i18n("end"), attrs); addAttribute("milestone", i18n("meetingPoint"), attrs); addAttribute("progress", i18n("advancement"), attrs); addAttribute("assigned-to", i18n("assignTo"), attrs); addAttribute("notes", i18n("notesTask"), attrs); startElement("tasks", attrs, handler); try { writeTasks(getProject().getTaskManager(), handler); } catch (Exception e) { throw new ExportException("Failed to write tasks", e); } endElement("tasks", handler); // addAttribute("version", "Ganttproject ("+GanttProject.version + ")", attrs); addAttribute("date", GanttCalendar.getDateAndTime(), attrs); emptyElement("footer", attrs, handler); endElement("ganttproject", handler); handler.endDocument(); } private void writeResources(HumanResourceManager resMan, TransformerHandler handler) throws SAXException { AttributesImpl attrs = new AttributesImpl(); List lor = resMan.getResources(); // String []_function=RoleManager.Access.getInstance().getRoleNames(); for (int i = 0, j = lor.size(); i < j; i++) { HumanResource p = (HumanResource) lor.get(i); startElement("resource", attrs, handler); textElement("name", attrs, p.getName(), handler); textElement("role", attrs, p.getRole().getName(), handler); textElement("mail", attrs, p.getMail(), handler); textElement("phone", attrs, p.getPhone(), handler); endElement("resource", handler); } } private void writeTasks(final TaskManager taskManager, final TransformerHandler handler) throws Exception { TaskVisitor visitor = new TaskVisitor() { AttributesImpl attrs = new AttributesImpl(); protected String serializeTask(Task t, int depth) { addAttribute("depth", String.valueOf(depth), attrs); try { startElement("task", attrs, handler); textElement("name", attrs, t.getName(), handler); textElement("begin", attrs, String.valueOf(t.getStart()), handler); textElement("end", attrs, String.valueOf(t.getEnd()), handler); textElement("milestone", attrs, String.valueOf(t .isMilestone()), handler); textElement("progress", attrs, String.valueOf(t .getCompletionPercentage()), handler); StringBuffer usersS = new StringBuffer(); ResourceAssignment[] assignments = t.getAssignments(); if (assignments.length > 0) { usersS.append(assignments[0].getResource().getName()); } for (int j = 1; j < assignments.length; j++) { usersS.append(", " + assignments[j].getResource().getName()); } textElement("assigned-to", attrs, usersS.toString(), handler); textElement("notes", attrs, t.getNotes(), handler); endElement("task", handler); } catch (SAXException e) { return "Failed to serialize task="+t.getName(); } return ""; } }; visitor.visit(taskManager); } public String proposeFileExtension() { return "html"; }// private class AdvancedOptionGroup extends GPOptionGroup implements GPOption {// public AdvancedOptionGroup(GPOption[] options) {// super("exporter.html.advanced", options);// }//// public String getPersistentValue() {// return null;// }//// public void loadPersistentValue(String value) {// }//// public boolean isChanged() {// return false;// }// // } public String[] getFileExtensions() { String s [] = {"html"}; return s; } /////////////////////////////////////////////////////////////////////////////// // protected String getStylesheetOptionID() { return "impex.html.stylesheet"; } protected Stylesheet[] getStylesheets() { StylesheetFactoryImpl factory = new StylesheetFactoryImpl() { protected Stylesheet newStylesheet(URL resolvedUrl, String localizedName) { return new HTMLStylesheetImpl(resolvedUrl, localizedName); } }; return (Stylesheet[]) factory.createStylesheets(HTMLStylesheet.class); } class HTMLStylesheetImpl extends StylesheetImpl implements HTMLStylesheet { HTMLStylesheetImpl(URL stylesheetURL, String localizedName) { super(stylesheetURL, localizedName); } public String getInputVersion() { return HTMLStylesheet.InputVersion.GP1X; } public TransformerHandler createTitlePageHandler() { try { URL titleUrl = new URL(getUrl(), "gantt.xsl"); TransformerHandler result = createHandler(titleUrl.toString()); return result; } catch (MalformedURLException e) { // TODO Auto-generated catch block e.printStackTrace(); throw new RuntimeException(e); } } public TransformerHandler createTasksPageHandler() { try { URL tasksUrl = new URL(getUrl(), "gantt-tasks.xsl"); TransformerHandler result = createHandler(tasksUrl.toString()); return result; } catch (MalformedURLException e) { e.printStackTrace(); throw new RuntimeException(e); } } public TransformerHandler createGanttChartPageHandler() { try { URL tasksUrl = new URL(getUrl(), "gantt-chart.xsl"); TransformerHandler result = createHandler(tasksUrl.toString()); return result; } catch (MalformedURLException e) { e.printStackTrace(); throw new RuntimeException(e); } } public TransformerHandler createResourcesPageHandler() { try { URL tasksUrl = new URL(getUrl(), "gantt-resources.xsl"); TransformerHandler result = createHandler(tasksUrl.toString()); return result; } catch (MalformedURLException e) { e.printStackTrace(); throw new RuntimeException(e); } } public File getImagesDirectory() { try { URL imagesUrl = new URL(getUrl(), "images"); File result = new File(new URI(imagesUrl.toString())); return result; } catch (MalformedURLException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (URISyntaxException e) { // TODO Auto-generated catch block e.printStackTrace(); } return null; } } private static File replaceExtension(File f, String newExtension) throws IOException { File result = FileUtil.replaceExtension(f, newExtension); if (!result.exists()) { result.createNewFile(); } return result; } private static File appendSuffixBeforeExtension(File f, String suffix) throws IOException { return FileUtil.appendSuffixBeforeExtension(f, suffix); } private static String getFilenameWithoutExtension(File f) { return FileUtil.getFilenameWithoutExtension(f); } private static final String GANTT_CHART_FILE_EXTENSION = "png"; private static final String RESOURCE_CHART_FILE_EXTENSION = "res.png"; }
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -