1   package org.kuali.ole.docstore.model.xmlpojo.config;
2   
3   import org.apache.commons.io.FileUtils;
4   import org.apache.commons.io.IOUtils;
5   import org.kuali.ole.docstore.model.jaxb.config.DocumentConfigConverter;
6   import org.slf4j.Logger;
7   import org.slf4j.LoggerFactory;
8   
9   import javax.xml.bind.annotation.*;
10  import java.io.File;
11  import java.util.ArrayList;
12  import java.util.List;
13  
14  
15  
16  
17  
18  
19  
20  
21  
22  
23  
24  
25  
26  
27  
28  
29  
30  
31  
32  
33  @XmlAccessorType(XmlAccessType.FIELD)
34  @XmlRootElement(name = "documentConfig")
35  @XmlType(name = "DocumentConfig")
36  public class DocumentConfig {
37  
38      public static Logger logger = LoggerFactory.getLogger(DocumentConfig.class);
39      public static DocumentConfig docStoreMetaData = null;
40      @XmlElement(name = "documentCategory")
41      protected List<DocumentCategory> documentCategories;
42  
43      
44  
45  
46  
47  
48  
49  
50  
51  
52  
53  
54  
55  
56  
57  
58  
59  
60      public List<DocumentCategory> getDocumentCategories() {
61          if (documentCategories == null) {
62              documentCategories = new ArrayList<DocumentCategory>();
63          }
64          return this.documentCategories;
65      }
66  
67      public static DocumentConfig getInstance() {
68          if (docStoreMetaData == null) {
69              try {
70                  DocumentConfigConverter documentConverter = new DocumentConfigConverter();
71                  String docConfigFilePath = System.getProperty("document.config.file");
72                  if (docConfigFilePath != null) {
73                      logger.info("docConfigFilePath-->" + docConfigFilePath);
74                      File docConfigFile = new File(docConfigFilePath);
75                      docStoreMetaData = documentConverter.unmarshal(FileUtils.readFileToString(docConfigFile));
76                  } else {
77                      docStoreMetaData = documentConverter.unmarshal(IOUtils.toString(DocumentConfig.class
78                              .getResourceAsStream("/org/kuali/ole/docstore/DocumentConfig.xml")));
79                  }
80                  logger.info("docStoreMetaData-->" + docStoreMetaData);
81                  logger.info("Loaded Doc Store Meta Data Successfully.");
82              } catch (Exception e) {
83                  logger.error("Failed in Loading Doc Store Meta Data : Cause : " + e.getMessage(), e);
84              }
85          }
86          return docStoreMetaData;
87      }
88  
89  }