Classes in this File | Line Coverage | Branch Coverage | Complexity | ||||
PolicyFileFilter |
|
| 1.0;1 |
1 | /* | |
2 | * Copyright (c) 2009, Swiss Federal Department of Defence Civil Protection and Sport | |
3 | * (http://www.vbs.admin.ch) | |
4 | * Copyright (c) 2009, Ergon Informatik AG (http://www.ergon.ch) | |
5 | * All rights reserved. | |
6 | * | |
7 | * Licensed under the Open Permis License which accompanies this distribution, | |
8 | * and is available at http://www.openpermis.org/BSDlicenceKent.txt | |
9 | */ | |
10 | package org.openpermis.editor.policy; | |
11 | ||
12 | import java.io.File; | |
13 | ||
14 | import javax.swing.filechooser.FileFilter; | |
15 | ||
16 | /** | |
17 | * Utility class for policy file filters. | |
18 | * @since 0.3.0 | |
19 | */ | |
20 | public class PolicyFileFilter | |
21 | extends FileFilter | |
22 | { | |
23 | ||
24 | //---- Static | |
25 | ||
26 | /** | |
27 | * XML extension <tt>.xml</tt>. | |
28 | * @since 0.3.0 | |
29 | */ | |
30 | private static final String XML_EXTENSION = ".xml"; | |
31 | ||
32 | /** | |
33 | * ACE extension <tt>.ace</tt>. | |
34 | * @since 0.3.0 | |
35 | */ | |
36 | private static final String ACE_EXTENSION = ".ace"; | |
37 | ||
38 | /** | |
39 | * WSDL extension <tt>.wsdl</tt>. | |
40 | * @since 0.3.0 | |
41 | */ | |
42 | private static final String WSDL_EXTENSION = ".wsdl"; | |
43 | ||
44 | /** | |
45 | * Filter for XML policy files. | |
46 | * @since 0.3.0 | |
47 | */ | |
48 | 0 | public static final PolicyFileFilter XML_FILE_FILTER = |
49 | new PolicyFileFilter(XML_EXTENSION, "XML"); | |
50 | ||
51 | /** | |
52 | * Filter for ACE policy files. | |
53 | * @since 0.3.0 | |
54 | */ | |
55 | 0 | public static final PolicyFileFilter ACE_FILE_FILTER = |
56 | new PolicyFileFilter(ACE_EXTENSION, "ACE"); | |
57 | ||
58 | ||
59 | /** | |
60 | * Filter for WSDL files. | |
61 | * @since 0.3.0 | |
62 | */ | |
63 | 0 | public static final PolicyFileFilter WSDL_FILE_FILTER = |
64 | new PolicyFileFilter(WSDL_EXTENSION, "WSDL"); | |
65 | ||
66 | ||
67 | //---- State | |
68 | ||
69 | /** | |
70 | * @since 0.3.0 | |
71 | */ | |
72 | private String extension; | |
73 | ||
74 | /** | |
75 | * @since 0.3.0 | |
76 | */ | |
77 | private String description; | |
78 | ||
79 | ||
80 | //---- Constructors | |
81 | ||
82 | /** | |
83 | * @since 0.3.0 | |
84 | */ | |
85 | public PolicyFileFilter (String extension, String description) { | |
86 | 0 | super(); |
87 | 0 | this.extension = extension; |
88 | 0 | this.description = description; |
89 | 0 | } |
90 | ||
91 | ||
92 | //---- Methods | |
93 | ||
94 | ||
95 | ||
96 | // ---- FileFilter | |
97 | ||
98 | /** | |
99 | * @since 0.3.0 | |
100 | */ | |
101 | public boolean accept (File file) { | |
102 | 0 | return file.getName().toLowerCase().endsWith(this.extension); |
103 | } | |
104 | ||
105 | /** | |
106 | * @since 0.3.0 | |
107 | */ | |
108 | public String getDescription () { | |
109 | 0 | return this.description + " (*" + this.extension + ")"; |
110 | } | |
111 | ||
112 | ||
113 | } |