added preliminary mailing list support
[org.ibex.mail.git] / src / org / ibex / mail / SkaringaFile.java
1 // Copyright 2000-2005 the Contributors, as shown in the revision logs.
2 // Licensed under the Apache Public Source License 2.0 ("the License").
3 // You may not use this file except in compliance with the License.
4
5 package org.ibex.mail;
6 import org.ibex.util.*;
7 import org.ibex.io.*;
8 import org.ibex.mail.target.*;
9 import org.ibex.mail.protocol.*;
10 import java.util.*;
11 import java.io.*;
12 import com.skaringa.javaxml.*;
13 import javax.xml.transform.stream.*;
14
15 public class SkaringaFile {
16
17     //private transient File file;
18     //private transient String path;
19     //private transient boolean exists;
20     private static WeakHashMap cache = new WeakHashMap();
21
22     /*
23     public void delete() throws IOException {
24         exists = false;
25         cache.remove(path, this);
26         file.delete();
27     }
28     */
29
30     public static Object read(File file) throws Exception {
31         FileInputStream in = null;
32         try {
33             ObjectTransformer trans = ObjectTransformerFactory.getInstance().getImplementation();
34             in = new FileInputStream(file);
35             return trans.deserialize(new StreamSource(in));
36         } finally {
37             if (in!=null) in.close();
38         }
39     }
40
41     public void write(File file) throws Exception {
42         ObjectTransformer trans = ObjectTransformerFactory.getInstance().getImplementation();
43         trans.setProperty(javax.xml.transform.OutputKeys.INDENT, "yes");
44         trans.setProperty("{http://xml.apache.org/xalan}indent-amount", "2");
45         FileOutputStream out = new FileOutputStream(file);
46         trans.serialize(this, new StreamResult(out));
47         out.close();
48         // FIXME: sync
49         // FIXME: write-aside
50     }
51
52 }