Search in sources :

Example 16 with RobustFileWriter

use of net.sourceforge.processdash.util.RobustFileWriter in project processdash by dtuma.

the class TeamProject method saveXML.

/** Save a WBSModel. Return false on error. */
private boolean saveXML(WBSModel model, File directory, String filename) {
    try {
        File f = new File(directory, filename);
        RobustFileWriter out = new RobustFileWriter(f, "UTF-8");
        BufferedWriter buf = new BufferedWriter(out);
        model.getAsXML(buf);
        buf.flush();
        out.close();
    } catch (Exception e) {
        e.printStackTrace();
        return false;
    }
    return true;
}
Also used : RobustFileWriter(net.sourceforge.processdash.util.RobustFileWriter) File(java.io.File) IOException(java.io.IOException) BufferedWriter(java.io.BufferedWriter)

Example 17 with RobustFileWriter

use of net.sourceforge.processdash.util.RobustFileWriter in project processdash by dtuma.

the class WBSTabPanel method saveTabs.

/**
     * Save custom tab definitions to file.
     * @param file
     * @throws IOException
     */
public void saveTabs(File file) throws IOException {
    try {
        RobustFileWriter out = new RobustFileWriter(file, "UTF-8");
        // write out xml
        out.write("<?xml version='1.0' encoding='utf-8'?>\n");
        out.write("<" + WBS_TABS_ELEMENT + " " + VERSION_ATTRIBUTE + "='" + getVersionNumber() + "'>\n");
        for (int i = 0; i < tabbedPane.getTabCount() - 1; i++) {
            if (isTabEditable(i)) {
                out.write("\t<" + TAB_ELEMENT + " " + NAME_ATTRIBUTE + "='" + XMLUtils.escapeAttribute(tabbedPane.getTitleAt(i)) + "'>\n");
                TableColumnModel tableColumnModel = (TableColumnModel) tableColumnModels.get(i);
                for (Enumeration e = tableColumnModel.getColumns(); e.hasMoreElements(); ) {
                    TableColumn column = (TableColumn) e.nextElement();
                    out.write("\t\t<" + COLUMN_ELEMENT + " " + NAME_ATTRIBUTE + "='" + XMLUtils.escapeAttribute(column.getHeaderValue().toString()) + "'" + " " + ID_ATTRIBUTE + "='" + XMLUtils.escapeAttribute(column.getIdentifier().toString()) + "'/>\n");
                }
                out.write("\t</" + TAB_ELEMENT + ">\n");
            }
        }
        out.write("</" + WBS_TABS_ELEMENT + ">\n");
        out.close();
    } catch (Exception e) {
        IOException exception = new IOException(SAVE_TABS_ERROR_MESSAGE);
        exception.initCause(e);
        throw exception;
    }
}
Also used : Enumeration(java.util.Enumeration) TableColumnModel(javax.swing.table.TableColumnModel) DefaultTableColumnModel(javax.swing.table.DefaultTableColumnModel) RobustFileWriter(net.sourceforge.processdash.util.RobustFileWriter) IOException(java.io.IOException) TableColumn(javax.swing.table.TableColumn) SAXException(org.xml.sax.SAXException) MalformedURLException(java.net.MalformedURLException) IOException(java.io.IOException)

Example 18 with RobustFileWriter

use of net.sourceforge.processdash.util.RobustFileWriter in project processdash by dtuma.

the class WorkingTimeLog method ensureTimeLogFileExists.

private File ensureTimeLogFileExists(File file) throws IOException {
    if (!file.exists()) {
        RobustFileWriter rout = new RobustFileWriter(file, TIME_LOG_ENCODING);
        BufferedWriter out = new BufferedWriter(rout);
        TimeLogWriter.write(out, Collections.EMPTY_LIST.iterator());
    }
    return file;
}
Also used : RobustFileWriter(net.sourceforge.processdash.util.RobustFileWriter) BufferedWriter(java.io.BufferedWriter)

Example 19 with RobustFileWriter

use of net.sourceforge.processdash.util.RobustFileWriter in project processdash by dtuma.

the class WBSDataWriter method write.

/** Write XML WBS data to the given file.
     */
public void write(File f) throws IOException {
    RobustFileWriter out = new RobustFileWriter(f, "UTF-8");
    write(out);
    out.close();
}
Also used : RobustFileWriter(net.sourceforge.processdash.util.RobustFileWriter)

Example 20 with RobustFileWriter

use of net.sourceforge.processdash.util.RobustFileWriter in project processdash by dtuma.

the class InternalSettings method saveSettings.

static synchronized void saveSettings() {
    if (isReadOnly())
        return;
    AccessController.doPrivileged(new PrivilegedAction() {

        public Object run() {
            if (fsettings != null)
                try {
                    String oldName, destName;
                    if (settingsFileRename == null) {
                        oldName = null;
                        destName = settingsFile;
                    } else {
                        oldName = settingsFile;
                        destName = settingsFileRename;
                    }
                    File destFile = new File(destName);
                    Writer out = new RobustFileWriter(destFile);
                    fsettings.store(out);
                    out.close();
                    if (oldName != null) {
                        new File(oldName).delete();
                        settingsFile = destName;
                        settingsFileRename = null;
                    }
                    settingsFileTimestamp = destFile.lastModified();
                    dirty = false;
                } catch (Exception e) {
                    logger.log(Level.SEVERE, "Unable to save settings file.", e);
                }
            return null;
        }
    });
}
Also used : PrivilegedAction(java.security.PrivilegedAction) RobustFileWriter(net.sourceforge.processdash.util.RobustFileWriter) File(java.io.File) RobustFileWriter(net.sourceforge.processdash.util.RobustFileWriter) Writer(java.io.Writer) IOException(java.io.IOException)

Aggregations

RobustFileWriter (net.sourceforge.processdash.util.RobustFileWriter)22 BufferedWriter (java.io.BufferedWriter)17 File (java.io.File)11 IOException (java.io.IOException)11 Writer (java.io.Writer)6 InputStreamReader (java.io.InputStreamReader)2 Iterator (java.util.Iterator)2 BufferedReader (java.io.BufferedReader)1 FileInputStream (java.io.FileInputStream)1 PrintWriter (java.io.PrintWriter)1 Reader (java.io.Reader)1 MalformedURLException (java.net.MalformedURLException)1 PrivilegedAction (java.security.PrivilegedAction)1 Date (java.util.Date)1 Enumeration (java.util.Enumeration)1 HashSet (java.util.HashSet)1 Set (java.util.Set)1 Matcher (java.util.regex.Matcher)1 Pattern (java.util.regex.Pattern)1 DefaultTableColumnModel (javax.swing.table.DefaultTableColumnModel)1