View Javadoc
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   * <p/>
16   * Java class for DocumentConfig complex type.
17   * <p/>
18   * <p/>
19   * The following schema fragment specifies the expected content contained within this class.
20   * <p/>
21   * <pre>
22   * &lt;complexType name="DocumentConfig">
23   *   &lt;complexContent>
24   *     &lt;restriction base="{http://www.w3.org/2001/XMLSchema}anyType">
25   *       &lt;sequence>
26   *         &lt;element name="documentCategories" type="{}DocumentCategory" maxOccurs="unbounded" minOccurs="0"/>
27   *       &lt;/sequence>
28   *     &lt;/restriction>
29   *   &lt;/complexContent>
30   * &lt;/complexType>
31   * </pre>
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       * Gets the value of the documentCategories property.
45       * <p/>
46       * <p/>
47       * This accessor method returns a reference to the live list, not a snapshot. Therefore any modification you make to the returned list will be present inside the JAXB object. This is why there is not a <CODE>set</CODE> method for the documentCategories property.
48       * <p/>
49       * <p/>
50       * For example, to add a new item, do as follows:
51       * <p/>
52       * <pre>
53       * getDocumentCategories().add(newItem);
54       * </pre>
55       * <p/>
56       * <p/>
57       * <p/>
58       * Objects of the following type(s) are allowed in the list {@link DocumentCategory }
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  }