001    /**
002     * Copyright (c) 2000-2013 Liferay, Inc. All rights reserved.
003     *
004     * This library is free software; you can redistribute it and/or modify it under
005     * the terms of the GNU Lesser General Public License as published by the Free
006     * Software Foundation; either version 2.1 of the License, or (at your option)
007     * any later version.
008     *
009     * This library is distributed in the hope that it will be useful, but WITHOUT
010     * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
011     * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
012     * details.
013     */
014    
015    package com.liferay.portal.kernel.bi.reporting.servlet;
016    
017    import com.liferay.portal.kernel.bi.reporting.ReportDesignRetriever;
018    
019    import java.io.InputStream;
020    
021    import java.util.Date;
022    
023    import javax.servlet.ServletContext;
024    
025    /**
026     * @author Michael C. Han
027     */
028    public class ServletContextReportDesignRetriever
029            implements ReportDesignRetriever {
030    
031            public ServletContextReportDesignRetriever(
032                    ServletContext servletContext, String reportName, String prefix,
033                    String postfix) {
034    
035                    _servletContext = servletContext;
036                    _reportName = reportName;
037                    _prefix = prefix;
038                    _postfix = postfix;
039            }
040    
041            @Override
042            public InputStream getInputStream() {
043                    return _servletContext.getResourceAsStream(
044                            _prefix + _reportName + _postfix);
045            }
046    
047            @Override
048            public Date getModifiedDate() {
049                    return new Date();
050            }
051    
052            @Override
053            public String getReportName() {
054                    return _reportName;
055            }
056    
057            private String _postfix;
058            private String _prefix;
059            private String _reportName;
060            private ServletContext _servletContext;
061    
062    }