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