View Javadoc

1   /*
2    * Copyright 2012 The Kuali Foundation.
3    * 
4    * Licensed under the Educational Community License, Version 2.0 (the "License");
5    * you may not use this file except in compliance with the License.
6    * You may obtain a copy of the License at
7    * 
8    * http://www.opensource.org/licenses/ecl2.php
9    * 
10   * Unless required by applicable law or agreed to in writing, software
11   * distributed under the License is distributed on an "AS IS" BASIS,
12   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13   * See the License for the specific language governing permissions and
14   * limitations under the License.
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   * Class to Doc Store Settings Util.
29   * 
30   * @author Rajesh Chowdary K
31   * @created Apr 9, 2012
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       * Method to copyResources
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  }