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.model.xmlpojo.metadata;
17  
18  import org.apache.commons.io.IOUtils;
19  import org.kuali.ole.docstore.model.xstream.metadata.DocStoreMetaDataXmlProcessor;
20  import org.slf4j.Logger;
21  import org.slf4j.LoggerFactory;
22  
23  import com.thoughtworks.xstream.annotations.XStreamAlias;
24  import com.thoughtworks.xstream.annotations.XStreamImplicit;
25  
26  import java.util.List;
27  
28  /**
29   * Class to DocumentsMetaData.
30   *
31   * @author Rajesh Chowdary K
32   * @created Jun 14, 2012
33   */
34  @XStreamAlias("documentsMetaData")
35  public class DocumentsMetaData {
36  
37      public static Logger logger = LoggerFactory.getLogger(DocumentsMetaData.class);
38      public static DocumentsMetaData docStoreMetaData = null;
39  
40      @XStreamImplicit
41      @XStreamAlias("documentMetaData")
42      private List<DocumentMetaData> documentsMetaData = null;
43  
44      public List<DocumentMetaData> getDocumentsMetaData() {
45          return documentsMetaData;
46      }
47  
48      public void setDocumentsMetaData(List<DocumentMetaData> documentsMetaData) {
49          this.documentsMetaData = documentsMetaData;
50      }
51  
52      public DocumentMetaData getDocumentMetaData(String category, String type, String format) {
53          if (documentsMetaData != null && documentsMetaData.size() > 0)
54              for (DocumentMetaData docMetaData : documentsMetaData)
55                  if (docMetaData.getCategory().equals(category) && docMetaData.getType().equals(type) && docMetaData.getFormat().equals(format))
56                      return docMetaData;
57          return null;
58      }
59  
60      public static DocumentsMetaData getInstance() {
61          if (docStoreMetaData == null) {
62              try {
63                  DocStoreMetaDataXmlProcessor parser = new DocStoreMetaDataXmlProcessor();
64                  String xml = IOUtils.toString(DocumentsMetaData.class.getResourceAsStream("/org/kuali/ole/docstore/documentsMetaData.xml"));
65                  docStoreMetaData = parser.fromXml(xml);
66                  logger.info("Loaded Doc Store Meta Data Successfully.");
67              } catch (Exception e) {
68                  logger.error("Failed in Loading Doc Store Meta Data : Cause : " + e.getMessage(), e);
69              }
70          }
71          return docStoreMetaData;
72      }
73  
74  }