01: /*
02: * FindBugs - Find Bugs in Java programs
03: * Copyright (C) 2006, University of Maryland
04: *
05: * This library is free software; you can redistribute it and/or
06: * modify it under the terms of the GNU Lesser General Public
07: * License as published by the Free Software Foundation; either
08: * version 2.1 of the License, or (at your option) any later version.
09: *
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, write to the Free Software
17: * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18: */
19:
20: package edu.umd.cs.findbugs.gui2;
21:
22: import java.io.File;
23:
24: import edu.umd.cs.findbugs.util.Util;
25:
26: enum SaveType {
27: NOT_KNOWN, PROJECT, XML_ANALYSIS, FBP_FILE, FBA_FILE;
28: public FindBugsFileFilter getFilter() {
29: switch (this ) {
30: case PROJECT:
31: return FindBugsProjectFileFilter.INSTANCE;
32: case XML_ANALYSIS:
33: return FindBugsAnalysisFileFilter.INSTANCE;
34: case FBP_FILE:
35: return FindBugsFBPFileFilter.INSTANCE;
36: case FBA_FILE:
37: return FindBugsFBAFileFilter.INSTANCE;
38: default:
39: throw new IllegalArgumentException(
40: "No filter for type NOT_UNKNOWN");
41: }
42: }
43:
44: public boolean isValid(File f) {
45: if (this == PROJECT) {
46: return OriginalGUI2ProjectFile.isValid(f);
47: }
48: if (f.isDirectory())
49: return false;
50: FindBugsFileFilter filter = getFilter();
51: return filter.accept(f);
52: }
53:
54: public String getFileExtension() {
55: switch (this ) {
56: case PROJECT:
57: return "";
58: case XML_ANALYSIS:
59: return ".xml";
60: case FBP_FILE:
61: return ".fbp";
62: case FBA_FILE:
63: return ".fba";
64: default:
65: throw new IllegalArgumentException(
66: "No filter for type NOT_UNKNOWN");
67: }
68: }
69:
70: public static SaveType forFile(File f) {
71: String extension = Util.getFileExtension(f);
72: if (OriginalGUI2ProjectFile.isValid(f))
73: return PROJECT;
74: if (extension.equals("fbp"))
75: return FBP_FILE;
76: if (extension.equals("fba"))
77: return FBA_FILE;
78: if (extension.equals("xml"))
79: return XML_ANALYSIS;
80: return NOT_KNOWN;
81: }
82: }
|