|
13 | 13 | import com.angkorteam.pluggable.framework.service.ResourceController; |
14 | 14 | import com.angkorteam.pluggable.framework.wicket.RestController; |
15 | 15 |
|
16 | | -//import com.angkorteam.pluggable.framework.framework.service.ResourceController; |
17 | | - |
18 | 16 | public final class RepositoryUtils { |
19 | 17 |
|
20 | 18 | private RepositoryUtils() { |
@@ -55,11 +53,43 @@ private static String localStore(AbstractWebApplication application, |
55 | 53 | return FrameworkConstants.REPOSITORY_LOCAL_URI + filename; |
56 | 54 | } |
57 | 55 |
|
| 56 | + private static String localStore(AbstractWebApplication application, |
| 57 | + File file) { |
| 58 | + String system = String.valueOf(System.nanoTime()); |
| 59 | + String clientName = file.getName(); |
| 60 | + String exentsion = FilenameUtils.getExtension(clientName); |
| 61 | + String filename = null; |
| 62 | + if (exentsion == null || "".equals(exentsion)) { |
| 63 | + filename = org.apache.commons.codec.digest.DigestUtils |
| 64 | + .md5Hex(system); |
| 65 | + } else { |
| 66 | + filename = org.apache.commons.codec.digest.DigestUtils |
| 67 | + .md5Hex(system) + "." + exentsion; |
| 68 | + } |
| 69 | + |
| 70 | + String local = application.select(FrameworkConstants.REPOSITORY, |
| 71 | + String.class); |
| 72 | + File copyTo = new File(local, filename); |
| 73 | + |
| 74 | + try { |
| 75 | + FileUtils.copyFile(file, copyTo); |
| 76 | + FileUtils.deleteQuietly(file); |
| 77 | + } catch (IOException e) { |
| 78 | + FileUtils.deleteQuietly(copyTo); |
| 79 | + return null; |
| 80 | + } |
| 81 | + return FrameworkConstants.REPOSITORY_LOCAL_URI + filename; |
| 82 | + } |
| 83 | + |
58 | 84 | public static String store(AbstractWebApplication application, |
59 | 85 | FileUpload fileUpload) { |
60 | 86 | return localStore(application, fileUpload); |
61 | 87 | } |
62 | 88 |
|
| 89 | + public static String store(AbstractWebApplication application, File file) { |
| 90 | + return localStore(application, file); |
| 91 | + } |
| 92 | + |
63 | 93 | private static void localDelete(AbstractWebApplication application, |
64 | 94 | String filename) { |
65 | 95 | String local = application.select(FrameworkConstants.REPOSITORY, |
|
0 commit comments