1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.kuali.ole.docstore.utility;
17
18 import org.apache.commons.io.FileUtils;
19 import org.kuali.ole.docstore.DocStoreConstants;
20 import org.slf4j.Logger;
21 import org.slf4j.LoggerFactory;
22
23 import java.io.File;
24 import java.net.URL;
25 import java.util.Enumeration;
26
27
28
29
30
31
32
33 public class DocStoreSettingsUtil {
34
35 private static final DocStoreSettingsUtil inst = new DocStoreSettingsUtil();
36 private static final Logger logger = LoggerFactory.getLogger(DocStoreSettingsUtil.class);
37
38
39
40
41
42 public void copyResources() {
43 try {
44 File targetFolder = new File(DocStoreConstants.DOCSTORE_SETTINGS_DIR_PATH + File.separator + DocStoreConstants.RESOURCES_DIR_NAME);
45 if (!targetFolder.exists() || (targetFolder.exists() && targetFolder.list().length <= 0)) {
46 Enumeration<URL> resources = this.getClass().getClassLoader().getResources(DocStoreConstants.RESOURCES_DIR_NAME);
47 boolean canItBeTaken = false;
48 while (resources.hasMoreElements()) {
49 URL url = resources.nextElement();
50 try {
51 url.toURI();
52 canItBeTaken = true;
53 } catch (Exception e) {
54 e.printStackTrace();
55 }
56 if (canItBeTaken) {
57 logger.debug("Copying Settings from source @:" + url.getFile());
58 File sourceDir = new File(url.toURI());
59 FileUtils.copyDirectoryToDirectory(sourceDir, targetFolder.getParentFile());
60 }
61 }
62 logger.debug("Copied Settings @: " + DocStoreConstants.DOCSTORE_SETTINGS_DIR_PATH);
63 } else
64 logger.info("Using Existing Settings @: " + DocStoreConstants.DOCSTORE_SETTINGS_DIR_PATH);
65 } catch (Exception e) {
66 e.printStackTrace();
67 }
68 }
69
70 private DocStoreSettingsUtil() {
71 }
72
73 public static DocStoreSettingsUtil getInstance() {
74 return inst;
75 }
76
77 }