1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22 package com.soebes.subversion.sapm;
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37 public class FileName {
38
39 private String name;
40 private String ext;
41 private String baseName;
42 private String path;
43 private String nameWithoutExtension;
44
45 public FileName(String fileName, boolean isDir) {
46 init(fileName, isDir);
47 }
48
49 public FileName(String fileName) {
50 init(fileName, false);
51 }
52
53 private void init(String fileName, boolean isDir) {
54 setExt("");
55 setName("");
56 setBaseName("");
57 setNameWithoutExtension("");
58 setPath("");
59 if (!isDir) {
60 if (fileName.endsWith("/")) {
61 isDir = true;
62 }
63 }
64
65 if (isDir) {
66 if (!fileName.endsWith("/")) {
67 fileName += "/";
68 }
69 setPath(fileName);
70 } else {
71 int pos = fileName.lastIndexOf("/");
72 if (pos >= 0) {
73 setBaseName(fileName.substring(pos + 1));
74 setPath(fileName.substring(0, pos + 1));
75 } else {
76 setBaseName(fileName);
77 }
78 pos = getBaseName().indexOf('.');
79 if (pos >= 0) {
80 setNameWithoutExtension(getBaseName().substring(0, pos));
81 setName(getNameWithoutExtension());
82 setExt(getBaseName().substring(pos + 1));
83 } else {
84 setNameWithoutExtension(getBaseName());
85 setName(getBaseName());
86 }
87 }
88 }
89
90
91
92
93 public String getExt() {
94 return ext;
95 }
96
97 public void setExt(String ext) {
98 this.ext = ext;
99 }
100
101
102
103
104 public String getName() {
105 return name;
106 }
107
108 public void setName(String name) {
109 this.name = name;
110 }
111
112 public String getBaseName() {
113 return baseName;
114 }
115
116 public void setBaseName(String baseName) {
117 this.baseName = baseName;
118 }
119
120 public String getPath() {
121 return path;
122 }
123
124 public void setPath(String path) {
125 this.path = path;
126 }
127
128 public String getNameWithoutExtension() {
129 return nameWithoutExtension;
130 }
131
132 public void setNameWithoutExtension(String nameWithoutExtension) {
133 this.nameWithoutExtension = nameWithoutExtension;
134 }
135
136 }