Subversion Repositories Applications.papyrus

Rev

Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
1318 alexandre_ 1
/**
2
	This is a simple class that can load, save, and remove
3
	files from the native file system. It is needed by Safari and Opera
4
	for the dojo.storage.browser.FileStorageProvider, since both of
5
	these platforms have no native way to talk to the file system
6
	for file:// URLs. Safari supports LiveConnect, but only for talking
7
	to an applet, not for generic scripting by JavaScript, so we must
8
	have an applet.
9
 
10
	@author Brad Neuberg, bkn3@columbia.edu
11
*/
12
 
13
import java.io.*;
14
import java.util.*;
15
 
16
public class DojoFileStorageProvider{
17
	public String load(String filePath)
18
			throws IOException, FileNotFoundException{
19
		StringBuffer results = new StringBuffer();
20
		BufferedReader reader = new BufferedReader(
21
					new FileReader(filePath));
22
		String line = null;
23
		while((line = reader.readLine()) != null){
24
			results.append(line);
25
		}
26
 
27
		reader.close();
28
 
29
		return results.toString();
30
	}
31
 
32
	public void save(String filePath, String content)
33
			throws IOException, FileNotFoundException{
34
		PrintWriter writer = new PrintWriter(
35
					new BufferedWriter(
36
						new FileWriter(filePath, false)));
37
		writer.print(content);
38
 
39
		writer.close();
40
	}
41
 
42
	public void remove(String filePath)
43
			throws IOException, FileNotFoundException{
44
		File f = new File(filePath);
45
 
46
		if(f.exists() == false || f.isDirectory()){
47
			return;
48
		}
49
 
50
		if(f.exists() && f.isFile()){
51
			f.delete();
52
		}
53
	}
54
}