Statistics
| Revision:

svn-gvsig-desktop / trunk / org.gvsig.desktop / org.gvsig.desktop.plugin / org.gvsig.app / org.gvsig.app.mainplugin / src / main / java / org / gvsig / app / project / documents / view / legend / gui / legendactions / AbstractLoadSaveLegendAction.java @ 43392

History | View | Annotate | Download (2.31 KB)

1
package org.gvsig.app.project.documents.view.legend.gui.legendactions;
2

    
3
import java.util.ArrayList;
4
import java.util.List;
5
import javax.swing.AbstractAction;
6
import org.gvsig.app.project.documents.view.legend.gui.LegendFileFilter;
7
import org.gvsig.fmap.mapcontext.MapContextLocator;
8
import org.gvsig.fmap.mapcontext.MapContextManager;
9

    
10
public abstract class AbstractLoadSaveLegendAction extends AbstractAction {
11

    
12
    private static final long serialVersionUID = 3282139517245723693L;
13

    
14
    protected AbstractLoadSaveLegendAction() {
15
        super();
16
    }
17
    
18
    protected List<LegendFileFilter> getLegendFileFilters(boolean writing) {
19

    
20
        List<LegendFileFilter> resp = new ArrayList<>();
21
        MapContextManager mcoman = MapContextLocator.getMapContextManager();
22
        List wformats;
23

    
24
        if( writing ) {
25
            wformats = mcoman.getLegendWritingFormats();
26
        } else {
27
            wformats = mcoman.getLegendReadingFormats();
28
        }
29

    
30
        String fmt;
31
        for( int i = 0; i < wformats.size(); i++ ) {
32
            fmt = (String) wformats.get(i);
33
            fmt = getFileExtension(fmt);
34
            if( fmt != null ) {
35
                resp.add(new LegendFileFilter(fmt));
36
            }
37
        }
38
        return resp;
39
    }
40

    
41
    /**
42
     * Returns null if mime format is not parsed properly
43
     *
44
     * @param fmt MIME format
45
     *
46
     * @return
47
     */
48
    protected String getFileExtension(String fmt) {
49
        // Example: "text/xml; subtype=gml/2.1.2" => "gml"
50
        if( fmt == null ) {
51
            return null;
52
        }
53
        String[] parts = fmt.split(";");
54
        String aux;
55
        if( parts.length > 1 ) {
56
            aux = parts[1].trim();
57
        } else {
58
            aux = parts[0].trim();
59
        }
60
        parts = aux.split("=");
61
        if( parts.length > 1 ) {
62
            aux = parts[1].trim();
63
            // Example: aux = "gml/2.1.2"
64
            parts = aux.split("/");
65
            return parts[0].length() == 0 ? null : parts[0].toLowerCase();
66
        } else {
67
            aux = parts[0].trim();
68
            // Example: "text/xml"
69
            parts = aux.split("/");
70
            if( parts.length > 1 ) {
71
                return parts[1].length() == 0 ? null : parts[1].toLowerCase();
72
            } else {
73
                return aux.length() == 0 ? null : aux.toLowerCase();
74
            }
75
        }
76
    }
77

    
78
}