1 package net.sf.openrocket.file;
3 import java.io.BufferedOutputStream;
5 import java.io.FileOutputStream;
6 import java.io.IOException;
7 import java.io.OutputStream;
9 import net.sf.openrocket.document.OpenRocketDocument;
10 import net.sf.openrocket.document.StorageOptions;
13 public abstract class RocketSaver {
16 * Save the document to the specified file using the default storage options.
18 * @param dest the destination file.
19 * @param document the document to save.
20 * @throws IOException in case of an I/O error.
22 public final void save(File dest, OpenRocketDocument document) throws IOException {
23 save(dest, document, document.getDefaultStorageOptions());
28 * Save the document to the specified file using the given storage options.
30 * @param dest the destination file.
31 * @param document the document to save.
32 * @param options the storage options.
33 * @throws IOException in case of an I/O error.
35 public void save(File dest, OpenRocketDocument document, StorageOptions options)
37 OutputStream s = new BufferedOutputStream(new FileOutputStream(dest));
39 save(s, document, options);
47 * Save the document to the specified output stream using the default storage options.
49 * @param dest the destination stream.
50 * @param doc the document to save.
51 * @throws IOException in case of an I/O error.
53 public final void save(OutputStream dest, OpenRocketDocument doc) throws IOException {
54 save(dest, doc, doc.getDefaultStorageOptions());
59 * Save the document to the specified output stream using the given storage options.
61 * @param dest the destination stream.
62 * @param doc the document to save.
63 * @param options the storage options.
64 * @throws IOException in case of an I/O error.
66 public abstract void save(OutputStream dest, OpenRocketDocument doc,
67 StorageOptions options) throws IOException;
75 public static String escapeXML(String s) {
77 s = s.replace("&", "&");
78 s = s.replace("<", "<");
79 s = s.replace(">", ">");
80 s = s.replace("\"",""");
81 s = s.replace("'", "'");
83 for (int i=0; i < s.length(); i++) {
85 if (((n < 32) && (n != 9) && (n != 10) && (n != 13)) || (n == 127)) {
86 s = s.substring(0,i) + "&#" + ((int)n) + ";" + s.substring(i+1);