File file = new File(System.getProperty("user.home")
+ System.getProperty("file.separator") + sFileName);
// DataOutputStream fout = new DataOutputStream(new
// FileOutputStream(file));
TransformerHandler handler = ((SAXTransformerFactory) SAXTransformerFactory
.newInstance()).newTransformerHandler();
Transformer serializer = handler.getTransformer();
serializer.setOutputProperty(OutputKeys.ENCODING, "UTF-8");
serializer.setOutputProperty(OutputKeys.INDENT, "yes");
serializer.setOutputProperty(
"{http://xml.apache.org/xslt}indent-amount", "4");
handler.setResult(new StreamResult(file));
handler.startDocument();
// handler.startDTD("ganttproject.sourceforge.net",
// "-//GanttProject.org//DTD GanttProject-1.x//EN",
// "http://ganttproject.sourceforge.net/dtd/ganttproject.dtd");
// handler.endDTD();
//
AttributesImpl attrs = new AttributesImpl();
handler.startElement("", "ganttproject-options",
"ganttproject-options", attrs);
//
attrs.addAttribute("", "selection", "selection", "CDATA", language
.getText("shortLanguage"));
handler.startElement("", "language", "language", attrs);
handler.endElement("", "language", "language");
attrs.clear();
// write the task Color
/*
* Color color = getUIConfiguration().getTaskColor();
* attrs.addAttribute("", "red", "red", "CDATA", ""+color.getRed());
* attrs.addAttribute("", "green", "green", "CDATA",
* ""+color.getGreen()); attrs.addAttribute("", "blue", "blue",
* "CDATA", ""+color.getBlue()); handler.startElement("",
* "task-color", "task-color", attrs); handler.endElement("",
* "task-color", "task-color"); attrs.clear();
*/
Color resourceColor = myUIConfig.getResourceColor();
if (resourceColor != null)
attrs.addAttribute("", "resources", "resources", "CDATA", ""
+ ColorConvertion.getColor(resourceColor));
Color resourceOverloadColor = myUIConfig.getResourceOverloadColor();
if (resourceOverloadColor != null)
attrs.addAttribute("", "resourcesOverload",
"resourcesOverload", "CDATA", ""
+ ColorConvertion
.getColor(resourceOverloadColor));
Color resourceUnderloadColor = myUIConfig
.getResourceUnderloadColor();
if (resourceUnderloadColor != null)
attrs.addAttribute("", "resourcesUnderload",
"resourcesUnderload", "CDATA", ""
+ ColorConvertion
.getColor(resourceUnderloadColor));
Color weekEndColor = myUIConfig.getWeekEndColor();
if (weekEndColor != null)
attrs.addAttribute("", "weekEnd", "weekEnd", "CDATA", ""
+ ColorConvertion.getColor(weekEndColor));
Color daysOffColor = myUIConfig.getDayOffColor();
if (daysOffColor != null)
attrs.addAttribute("", "daysOff", "daysOff", "CDATA", ""
+ ColorConvertion.getColor(daysOffColor));
handler.startElement("", "colors", "colors", attrs);
handler.endElement("", "colors", "colors");
attrs.clear();
// Geometry of the window
addAttribute("x", "" + x, attrs);
addAttribute("y", "" + y, attrs);
addAttribute("width", "" + width, attrs);
addAttribute("height", "" + height, attrs);
emptyElement("geometry", attrs, handler);
// look'n'feel
addAttribute("name", lookAndFeel.getName(), attrs);
addAttribute("class", lookAndFeel.getClassName(), attrs);
emptyElement("looknfeel", attrs, handler);
// ToolBar position
addAttribute("position", "" + toolBarPosition, attrs);
addAttribute("icon-size", "" + iconSize, attrs);
addAttribute("show", "" + buttonsshow, attrs);
emptyElement("toolBar", attrs, handler);
addAttribute("show", "" + bShowStatusBar, attrs);
emptyElement("statusBar", attrs, handler);
// Export options
addAttribute("name", "" + bExportName, attrs);
addAttribute("complete", "" + bExportComplete, attrs);
addAttribute("border3d", "" + bExport3DBorders, attrs);
addAttribute("relations", "" + bExportRelations, attrs);
emptyElement("export", attrs, handler);
// csv export options
startElement("csv-export", attrs, handler);
addAttribute("fixed", "" + csvOptions.bFixedSize, attrs);
addAttribute("separatedChar", "" + csvOptions.sSeparatedChar, attrs);
addAttribute("separatedTextChar", ""
+ csvOptions.sSeparatedTextChar, attrs);
emptyElement("csv-general", attrs, handler);
addAttribute("id", "" + csvOptions.bExportTaskID, attrs);
addAttribute("name", "" + csvOptions.bExportTaskName, attrs);
addAttribute("start-date", "" + csvOptions.bExportTaskStartDate,
attrs);
addAttribute("end-date", "" + csvOptions.bExportTaskEndDate, attrs);
addAttribute("percent", "" + csvOptions.bExportTaskPercent, attrs);
addAttribute("duration", "" + csvOptions.bExportTaskDuration, attrs);
addAttribute("webLink", "" + csvOptions.bExportTaskWebLink, attrs);
addAttribute("resources", "" + csvOptions.bExportTaskResources,
attrs);
addAttribute("notes", "" + csvOptions.bExportTaskNotes, attrs);
emptyElement("csv-tasks", attrs, handler);
addAttribute("id", "" + csvOptions.bExportResourceID, attrs);
addAttribute("name", "" + csvOptions.bExportResourceName, attrs);
addAttribute("mail", "" + csvOptions.bExportResourceMail, attrs);
addAttribute("phone", "" + csvOptions.bExportResourcePhone, attrs);
addAttribute("role", "" + csvOptions.bExportResourceRole, attrs);
emptyElement("csv-resources", attrs, handler);
endElement("csv-export", handler);
// automatic popup launch
addAttribute("value", "" + automatic, attrs);
emptyElement("automatic-launch", attrs, handler);
// automaticdrag time on the chart
// addAttribute("value", ""+dragTime, attrs);
emptyElement("dragTime", attrs, handler);
// automatic tips of the day launch
addAttribute("value", "" + openTips, attrs);
emptyElement("tips-on-startup", attrs, handler);
// Should WebDAV resources be locked, when opening them?
addAttribute("value", "" + lockDAVMinutes, attrs);
emptyElement("lockdavminutes", attrs, handler);
// write the xsl directory
addAttribute("dir", xslDir, attrs);
emptyElement("xsl-dir", attrs, handler);
// write the xslfo directory
addAttribute("file", xslFo, attrs);
emptyElement("xsl-fo", attrs, handler);
// write the working directory directory
addAttribute("dir", workingDir, attrs);
emptyElement("working-dir", attrs, handler);
// write the task name prefix
addAttribute("prefix", sTaskNamePrefix, attrs);
emptyElement("task-name", attrs, handler);
// The last opened files
{
startElement("files", attrs, handler);
for (Iterator iterator = documentsMRU.iterator(); iterator
.hasNext();) {
Document document = (Document) iterator.next();
addAttribute("path", document.getPath(), attrs);
emptyElement("file", attrs, handler);
}
endElement("files", handler);
}
addAttribute("category", "menu", attrs);
addAttribute("spec",
getFontSpec(getUIConfiguration().getMenuFont()), attrs);
emptyElement("font", attrs, handler);
//
addAttribute("category", "chart-main", attrs);
addAttribute("spec", getFontSpec(getUIConfiguration()
.getChartMainFont()), attrs);
emptyElement("font", attrs, handler);
//
saveIconPositions(handler);
saveRoleSets(handler);
for (Iterator options = myGPOptions.entrySet().iterator(); options.hasNext();) {
Map.Entry nextEntry = (Entry) options.next();
GPOption nextOption = (GPOption)nextEntry.getValue();
if (nextOption.getPersistentValue()!=null) {
addAttribute("id", nextEntry.getKey().toString(), attrs);
addAttribute("value", nextOption.getPersistentValue(), attrs);
emptyElement("option", attrs, handler);
}
}
endElement("ganttproject-options", handler);
//
GPLogger.log("[GanttOptions] save(): finished!!");
handler.endDocument();
} catch (Exception e) {
if (!GPLogger.log(e)) {
e.printStackTrace(System.err);
}
}