Statistics
| Revision:

gvsig-raster / org.gvsig.raster.multifile / trunk / org.gvsig.raster.multifile / org.gvsig.raster.multifile.app.multifileclient / src / main / java / org / gvsig / raster / multifile / app / panel / DriverFileFilter.java @ 2458

History | View | Annotate | Download (2.07 KB)

1
/* gvSIG. Geographic Information System of the Valencian Government
2
*
3
* Copyright (C) 2007-2008 Infrastructures and Transports Department
4
* of the Valencian Government (CIT)
5
* 
6
* This program is free software; you can redistribute it and/or
7
* modify it under the terms of the GNU General Public License
8
* as published by the Free Software Foundation; either version 2
9
* of the License, or (at your option) any later version.
10
* 
11
* This program is distributed in the hope that it will be useful,
12
* but WITHOUT ANY WARRANTY; without even the implied warranty of
13
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14
* GNU General Public License for more details.
15
* 
16
* You should have received a copy of the GNU General Public License
17
* along with this program; if not, write to the Free Software
18
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, 
19
* MA  02110-1301, USA.
20
* 
21
*/
22
package org.gvsig.raster.multifile.app.panel;
23

    
24
import java.io.File;
25
import java.io.FileInputStream;
26

    
27
import javax.swing.filechooser.FileFilter;
28

    
29
import org.gvsig.raster.fmap.layers.DefaultFLyrRaster;
30
/**
31
 * Clase para indicar los ficheros que se ver?n en el JFileChooser.
32
 * 
33
 * @version 04/09/2007
34
 * @author BorSanZa - Borja S?nchez Zamorano (borja.sanchez@iver.es)
35
 */
36
public class DriverFileFilter extends FileFilter {
37

    
38
        
39
        public boolean accept(File f) {
40
                if (f.isDirectory())
41
                        return true;
42

    
43
                if (f.getParentFile().getName().equals("cellhd")) {
44
                        if (f.getName().endsWith(".rmf") || f.getName().endsWith(".rmf~"))
45
                                return false;
46
                        return true;
47
                }
48

    
49
                // Comprobamos que no sea un rmf propio, osea, que contenga xml
50
                if (f.getName().toLowerCase().endsWith(".rmf")) {
51
                        FileInputStream reader = null;
52
                        try {
53
                                reader = new FileInputStream(f);
54
                                String xml = "";
55
                                for (int i = 0; i < 6; i++)
56
                                        xml += (char) reader.read();
57
                                if (xml.equals("<?xml "))
58
                                        return false;
59
                        } catch (Exception e) {
60
                        } finally {
61
                                try {
62
                                        reader.close();
63
                                } catch (Exception e) {}
64
                        }
65
                }
66

    
67
                return DefaultFLyrRaster.isFileSupported(f);
68
        }
69

    
70
        public String getDescription() {
71
                return "gvSIG Raster Driver";
72
        }
73
}