Classes in this File | Line Coverage | Branch Coverage | Complexity | ||||
MoveAction |
|
| 1.25;1.25 |
1 | package org.jtheque.core.managers.update.actions; | |
2 | ||
3 | /* | |
4 | * This file is part of JTheque. | |
5 | * | |
6 | * JTheque is free software: you can redistribute it and/or modify | |
7 | * it under the terms of the GNU General Public License as published by | |
8 | * the Free Software Foundation, either version 3 of the License. | |
9 | * | |
10 | * JTheque 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 | |
13 | * GNU General Public License for more details. | |
14 | * | |
15 | * You should have received a copy of the GNU General Public License | |
16 | * along with JTheque. If not, see <http://www.gnu.org/licenses/>. | |
17 | */ | |
18 | ||
19 | import org.jtheque.core.managers.Managers; | |
20 | import org.jtheque.core.managers.log.ILoggingManager; | |
21 | import org.jtheque.utils.io.CopyException; | |
22 | import org.jtheque.utils.io.FileUtils; | |
23 | ||
24 | /** | |
25 | * An update action that move a file. | |
26 | * | |
27 | * @author Baptiste Wicht | |
28 | */ | |
29 | 0 | public final class MoveAction extends AbstractUpdateAction { |
30 | private String sourceFile; | |
31 | private String sourceFolder; | |
32 | ||
33 | @Override | |
34 | public void execute() { | |
35 | try { | |
36 | 0 | FileUtils.move(getSource(), getDestination()); |
37 | 0 | } catch (CopyException e) { |
38 | 0 | Managers.getManager(ILoggingManager.class).getLogger(getClass()).debug("The file ({}) can not be moved.", getSource()); |
39 | 0 | } |
40 | 0 | } |
41 | ||
42 | /** | |
43 | * Return the path of the source's file. | |
44 | * | |
45 | * @return The source's path. | |
46 | */ | |
47 | private String getSource() { | |
48 | 0 | return buildFilePath(sourceFolder, sourceFile); |
49 | } | |
50 | ||
51 | /** | |
52 | * Set the path to the source's file. | |
53 | * | |
54 | * @param sourceFile The path to the source's file. | |
55 | */ | |
56 | public void setSourceFile(String sourceFile) { | |
57 | 0 | this.sourceFile = sourceFile; |
58 | 0 | } |
59 | ||
60 | /** | |
61 | * Set the path to the source's folder. | |
62 | * | |
63 | * @param sourceFolder The path to the source's folder. | |
64 | */ | |
65 | public void setSourceFolder(String sourceFolder) { | |
66 | 0 | this.sourceFolder = sourceFolder; |
67 | 0 | } |
68 | } |