1 package org.apache.archiva.checksum;
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22 import java.io.File;
23
24 import org.apache.commons.io.FilenameUtils;
25
26
27
28
29
30
31 public enum ChecksumAlgorithm {
32 SHA1("SHA-1", "sha1", "SHA1"),
33 MD5("MD5", "md5", "MD5");
34
35 public static ChecksumAlgorithm getByExtension( File file )
36 {
37 String ext = FilenameUtils.getExtension( file.getName() ).toLowerCase();
38 if ( ChecksumAlgorithm.SHA1.getExt().equals( ext ) )
39 {
40 return ChecksumAlgorithm.SHA1;
41 }
42 else if ( ChecksumAlgorithm.MD5.getExt().equals( ext ) )
43 {
44 return ChecksumAlgorithm.MD5;
45 }
46
47 throw new IllegalArgumentException( "Filename " + file.getName() + " has no associated extension." );
48 }
49
50
51
52
53 private final String algorithm;
54
55
56
57
58 private final String ext;
59
60
61
62
63 private final String type;
64
65
66
67
68
69
70
71
72 private ChecksumAlgorithm( String algorithm, String ext, String type )
73 {
74 this.algorithm = algorithm;
75 this.ext = ext;
76 this.type = type;
77 }
78
79 public String getAlgorithm()
80 {
81 return algorithm;
82 }
83
84 public String getExt()
85 {
86 return ext;
87 }
88
89 public String getType()
90 {
91 return type;
92 }
93
94
95 }