Classes in this File | Line Coverage | Branch Coverage | Complexity | ||||||||
XMLFileSoup |
|
| 2.75;2.75 |
1 | /* |
|
2 | Wotonomy: OpenStep design patterns for pure Java applications. |
|
3 | Copyright (C) 2000 Michael Powers |
|
4 | ||
5 | This library is free software; you can redistribute it and/or |
|
6 | modify it under the terms of the GNU Lesser General Public |
|
7 | License as published by the Free Software Foundation; either |
|
8 | version 2.1 of the License, or (at your option) any later version. |
|
9 | ||
10 | This library is distributed in the hope that it will be useful, |
|
11 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
|
13 | Lesser General Public License for more details. |
|
14 | ||
15 | You should have received a copy of the GNU Lesser General Public |
|
16 | License along with this library; if not, see http://www.gnu.org |
|
17 | */ |
|
18 | ||
19 | package net.wotonomy.datastore; |
|
20 | ||
21 | import java.io.File; |
|
22 | import java.io.FileInputStream; |
|
23 | import java.io.FileOutputStream; |
|
24 | import java.io.IOException; |
|
25 | import java.net.MalformedURLException; |
|
26 | ||
27 | import net.wotonomy.web.xml.XMLRPCDecoder; |
|
28 | import net.wotonomy.web.xml.XMLRPCEncoder; |
|
29 | ||
30 | public class XMLFileSoup extends FileSoup |
|
31 | { |
|
32 | public XMLFileSoup( String aPath ) |
|
33 | { |
|
34 | 0 | super( aPath ); |
35 | 0 | } |
36 | ||
37 | // file access methods |
|
38 | ||
39 | protected boolean writeFile( String name, Object anObject ) |
|
40 | { |
|
41 | //System.out.print( "writeFile: " + name + "..." ); |
|
42 | try |
|
43 | { |
|
44 | 0 | File f = new File( getHomeDirectory(), name ); |
45 | 0 | FileOutputStream fos = new FileOutputStream( f ); |
46 | 0 | XMLRPCEncoder encoder = new XMLRPCEncoder(); |
47 | 0 | encoder.encode( anObject, fos ); |
48 | 0 | fos.flush(); |
49 | 0 | fos.close(); |
50 | } |
|
51 | 0 | catch ( Exception exc ) |
52 | { |
|
53 | 0 | System.err.println( "XMLFileSoup.writeFile: " + exc ); |
54 | 0 | return false; |
55 | 0 | } |
56 | //System.out.println( "done." ); |
|
57 | 0 | return true; |
58 | } |
|
59 | ||
60 | protected Object readFile( String name ) |
|
61 | { |
|
62 | //System.out.print( "readFile: " + name + "..." ); |
|
63 | 0 | Object result = null; |
64 | ||
65 | try |
|
66 | { |
|
67 | 0 | File f = new File( getHomeDirectory(), name ); |
68 | 0 | FileInputStream fis = new FileInputStream( f ); |
69 | 0 | XMLRPCDecoder decoder = new XMLRPCDecoder(); |
70 | 0 | result = decoder.decode( fis, f.getAbsolutePath(), f.toURL() ); |
71 | 0 | fis.close(); |
72 | } |
|
73 | 0 | catch ( MalformedURLException exc ) |
74 | { |
|
75 | 0 | result = null; |
76 | } |
|
77 | 0 | catch ( IOException exc ) |
78 | { |
|
79 | 0 | result = null; |
80 | 0 | } |
81 | //System.out.println( "done." ); |
|
82 | 0 | return result; |
83 | } |
|
84 | ||
85 | protected boolean deleteFile( String name ) |
|
86 | { |
|
87 | try |
|
88 | { |
|
89 | 0 | File f = new File( getHomeDirectory(), name ); |
90 | 0 | if ( f.exists() ) |
91 | { |
|
92 | 0 | f.delete(); |
93 | 0 | return true; |
94 | } |
|
95 | } |
|
96 | 0 | catch ( Exception exc ) |
97 | { |
|
98 | 0 | System.err.println( "XMLFileSoup.deleteFile: " + exc ); |
99 | 0 | } |
100 | ||
101 | 0 | return false; |
102 | } |
|
103 | ||
104 | } |
|
105 | ||
106 | /* |
|
107 | * $Log$ |
|
108 | * Revision 1.2 2006/02/19 16:26:19 cgruber |
|
109 | * Move non-unit-test code to tests project |
|
110 | * Fix up code to work with proper imports |
|
111 | * Fix maven dependencies. |
|
112 | * |
|
113 | * Revision 1.1 2006/02/16 13:18:56 cgruber |
|
114 | * Check in all sources in eclipse-friendly maven-enabled packages. |
|
115 | * |
|
116 | * Revision 1.3 2003/08/14 19:29:38 chochos |
|
117 | * minor cleanup (imports, static method calls, etc) |
|
118 | * |
|
119 | * Revision 1.2 2001/02/07 19:26:28 mpowers |
|
120 | * XML classes are in new package. |
|
121 | * |
|
122 | * Revision 1.1.1.1 2000/12/21 15:47:23 mpowers |
|
123 | * Contributing wotonomy. |
|
124 | * |
|
125 | * Revision 1.6 2000/12/20 16:25:37 michael |
|
126 | * Added log to all files. |
|
127 | * |
|
128 | * |
|
129 | */ |
|
130 |