Revision 2616 org.gvsig.raster/trunk/org.gvsig.raster/org.gvsig.raster.lib/org.gvsig.raster.lib.impl/src/main/java/org/gvsig/raster/impl/store/rmf/RmfBlocksManager.java
RmfBlocksManager.java | ||
---|---|---|
37 | 37 |
* escribir en el se registrar? a traves de ClientRegister y esta clase ser? la encargada |
38 | 38 |
* de gestionar la lectura y escritura de bloques. |
39 | 39 |
* |
40 |
* 21-abr-2007 |
|
41 | 40 |
* @author Nacho Brodin (nachobrodin@gmail.com) |
42 | 41 |
*/ |
43 | 42 |
public class RmfBlocksManager extends ClientRegister implements IRmfBlock { |
44 | 43 |
private final String MAIN_TAG = "RasterMetaFile"; |
44 |
private String version = "1.0"; |
|
45 |
|
|
45 | 46 |
private String path = null; |
46 | 47 |
|
47 | 48 |
/** |
... | ... | |
76 | 77 |
RasterLocator.getManager().getFileUtils().copyFile(getPath(), getPath() + "~"); |
77 | 78 |
} |
78 | 79 |
|
79 |
/* |
|
80 |
* (non-Javadoc) |
|
81 |
* @see org.gvsig.raster.dataset.io.rmf.IRmfBlock#read(java.lang.String) |
|
82 |
*/ |
|
83 | 80 |
public void read(String xml) throws ParsingException { |
84 | 81 |
File file = new File(getPath()); |
85 | 82 |
ArrayList<String> lines = new ArrayList<String>(); |
... | ... | |
133 | 130 |
file.createNewFile(); |
134 | 131 |
FileWriter writer = new FileWriter(file); |
135 | 132 |
writer.write("<?xml version=\"1.0\" encoding=\"ISO-8859-15\"?>\n"); |
136 |
writer.write("<RasterMetaFile>\n");
|
|
133 |
writer.write("<" + getMainTag() + " version=\"" + version + "\">\n");
|
|
137 | 134 |
for (int i = 0; i < clients.size(); i++) { |
138 | 135 |
IRmfBlock block = ((IRmfBlock) clients.get(i)); |
139 | 136 |
String xmlBlock = block.write(); |
140 | 137 |
if(xmlBlock != null) |
141 | 138 |
writer.write(xmlBlock); |
142 | 139 |
} |
143 |
writer.write("</RasterMetaFile>\n");
|
|
140 |
writer.write("</" + getMainTag() + ">\n");
|
|
144 | 141 |
writer.close(); |
145 | 142 |
} |
146 | 143 |
|
147 |
/* |
|
148 |
* (non-Javadoc) |
|
149 |
* @see org.gvsig.raster.dataset.io.rmf.IRmfBlock#write() |
|
150 |
*/ |
|
151 | 144 |
public String write() throws IOException { |
152 | 145 |
File file = new File(getPath()); |
153 | 146 |
ArrayList<String> lines = new ArrayList<String>(); |
... | ... | |
247 | 240 |
try { |
248 | 241 |
inGrf = new BufferedReader(new InputStreamReader(new FileInputStream(f))); |
249 | 242 |
String str = inGrf.readLine(); |
250 |
if (!str.startsWith("<?xml")) |
|
243 |
if (!str.startsWith("<?xml")) { |
|
244 |
inGrf.close(); |
|
251 | 245 |
return false; |
246 |
} |
|
247 |
while (str != null) { |
|
248 |
if (str.startsWith("<" + getMainTag())) { |
|
249 |
inGrf.close(); |
|
250 |
if(str.contains("version=\"")) { |
|
251 |
String versionNbr = str.substring(str.indexOf("version=\"") + 9); |
|
252 |
versionNbr = versionNbr.substring(0, versionNbr.indexOf("\"")); |
|
253 |
if(!versionNbr.equals(version)) { |
|
254 |
return false; |
|
255 |
} |
|
256 |
} |
|
257 |
return true; |
|
258 |
} |
|
259 |
str = inGrf.readLine(); |
|
260 |
} |
|
261 |
inGrf.close(); |
|
252 | 262 |
} catch (FileNotFoundException e) { |
253 | 263 |
return false; |
254 | 264 |
} catch (IOException e) { |
... | ... | |
258 | 268 |
return true; |
259 | 269 |
} |
260 | 270 |
|
261 |
/* |
|
262 |
* (non-Javadoc) |
|
263 |
* @see org.gvsig.raster.dataset.io.rmf.IRmfBlock#getMainTag() |
|
264 |
*/ |
|
265 | 271 |
public String getMainTag() { |
266 | 272 |
return MAIN_TAG; |
267 | 273 |
} |
268 | 274 |
|
269 |
/* |
|
270 |
* (non-Javadoc) |
|
271 |
* @see org.gvsig.raster.dataset.io.rmf.IRmfBlock#getResult() |
|
272 |
*/ |
|
273 | 275 |
public Object getResult() { |
274 | 276 |
return null; |
275 | 277 |
} |
Also available in: Unified diff