001    /*
002     * Copyright 2012 The Kuali Foundation.
003     * 
004     * Licensed under the Educational Community License, Version 2.0 (the "License");
005     * you may not use this file except in compliance with the License.
006     * You may obtain a copy of the License at
007     * 
008     * http://www.opensource.org/licenses/ecl2.php
009     * 
010     * Unless required by applicable law or agreed to in writing, software
011     * distributed under the License is distributed on an "AS IS" BASIS,
012     * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
013     * See the License for the specific language governing permissions and
014     * limitations under the License.
015     */
016    package org.kuali.ole.docstore.model.xmlpojo.metadata;
017    
018    import org.apache.commons.io.IOUtils;
019    import org.kuali.ole.docstore.model.xstream.metadata.DocStoreMetaDataXmlProcessor;
020    import org.slf4j.Logger;
021    import org.slf4j.LoggerFactory;
022    
023    import com.thoughtworks.xstream.annotations.XStreamAlias;
024    import com.thoughtworks.xstream.annotations.XStreamImplicit;
025    
026    import java.util.List;
027    
028    /**
029     * Class to DocumentsMetaData.
030     * 
031     * @author Rajesh Chowdary K
032     * @created Jun 14, 2012
033     */
034    @XStreamAlias("documentsMetaData")
035    public class DocumentsMetaData {
036    
037        public static Logger            logger            = LoggerFactory.getLogger(DocumentsMetaData.class);
038        public static DocumentsMetaData docStoreMetaData  = null;
039    
040        @XStreamImplicit
041        @XStreamAlias("documentMetaData")
042        private List<DocumentMetaData>  documentsMetaData = null;
043    
044        public List<DocumentMetaData> getDocumentsMetaData() {
045            return documentsMetaData;
046        }
047    
048        public void setDocumentsMetaData(List<DocumentMetaData> documentsMetaData) {
049            this.documentsMetaData = documentsMetaData;
050        }
051    
052        public DocumentMetaData getDocumentMetaData(String category, String type, String format) {
053            if (documentsMetaData != null && documentsMetaData.size() > 0)
054                for (DocumentMetaData docMetaData : documentsMetaData)
055                    if (docMetaData.getCategory().equals(category) && docMetaData.getType().equals(type) && docMetaData.getFormat().equals(format))
056                        return docMetaData;
057            return null;
058        }
059    
060        public static DocumentsMetaData getInstance() {
061            if (docStoreMetaData == null) {
062                try {
063                    DocStoreMetaDataXmlProcessor parser = new DocStoreMetaDataXmlProcessor();
064                    String xml = IOUtils.toString(DocumentsMetaData.class.getResourceAsStream("/org/kuali/ole/docstore/documentsMetaData.xml"));
065                    docStoreMetaData = parser.fromXml(xml);
066                    logger.info("Loaded Doc Store Meta Data Successfully.");
067                } catch (Exception e) {
068                    logger.error("Failed in Loading Doc Store Meta Data : Cause : " + e.getMessage(), e);
069                }
070            }
071            return docStoreMetaData;
072        }
073    
074    }