001    /*
002     * 
003     * $Revision: 15105 $ $Date: 2009-04-23 11:23:28 +0200 (Do, 23. Apr 2009) $
004     *
005     * This file is part of ***  M y C o R e  ***
006     * See http://www.mycore.de/ for details.
007     *
008     * This program is free software; you can use it, redistribute it
009     * and / or modify it under the terms of the GNU General Public License
010     * (GPL) as published by the Free Software Foundation; either version 2
011     * of the License or (at your option) any later version.
012     *
013     * This program is distributed in the hope that it will be useful, but
014     * WITHOUT ANY WARRANTY; without even the implied warranty of
015     * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
016     * GNU General Public License for more details.
017     *
018     * You should have received a copy of the GNU General Public License
019     * along with this program, in a file called gpl.txt or license.txt.
020     * If not, write to the Free Software Foundation Inc.,
021     * 59 Temple Place - Suite 330, Boston, MA  02111-1307 USA
022     */
023    
024    package org.mycore.frontend.indexbrowser.lucene;
025    
026    import java.util.Enumeration;
027    
028    import javax.servlet.http.HttpServletRequest;
029    
030    import org.jdom.Document;
031    import org.mycore.frontend.servlets.MCRServlet;
032    import org.mycore.frontend.servlets.MCRServletJob;
033    
034    /**
035     * Servlet to create an xml document which is parsed by xsl
036     * to display the index browser results of the current request.
037     * 
038     * @author Anja Schaar, Andreas Trappe, Matthias Eichner
039     */
040    public class MCRIndexBrowserServlet extends MCRServlet {
041    
042        private static final long serialVersionUID = 4963472470316616461L;
043    
044        protected MCRIndexBrowserIncomingData incomingBrowserData;
045    
046        protected MCRIndexBrowserConfig config;
047        
048        protected void doGetPost(MCRServletJob job) throws Exception {
049            @SuppressWarnings("unchecked")
050            Enumeration<String> ee = job.getRequest().getParameterNames();
051            while (ee.hasMoreElements()) {
052                String param = ee.nextElement();
053                System.out.println("PARAM: " + param + " VALUE: " + job.getRequest().getParameter(param));
054            }
055    
056            incomingBrowserData = getIncomingBrowserData(job.getRequest());
057            config = new MCRIndexBrowserConfig(incomingBrowserData.getSearchclass());
058    
059            Document pageContent = null;
060            // if init is true, then create an empty document, otherwise create
061            // the result list
062            if(!incomingBrowserData.isInit()) {
063                pageContent = createResultListDocument();
064            } else {
065                pageContent = createEmptyDocument();
066            }
067    
068            if (getProperty(job.getRequest(), "XSL.Style") == null) {
069                job.getRequest().setAttribute("XSL.Style", job.getRequest().getParameter("searchclass"));
070            }
071            getLayoutService().doLayout(job.getRequest(), job.getResponse(), pageContent);
072        }
073    
074        /**
075         * Creates a xml document with the results of the index browser.
076         * @return a new xml document with the result list
077         */
078        protected Document createResultListDocument() {
079            return MCRIndexBrowserUtils.createResultListDocument(incomingBrowserData, config);
080        }
081    
082        /**
083         * Creates an empty xml index browser document.
084         * @return a new empty document
085         */
086        protected Document createEmptyDocument() {
087            return MCRIndexBrowserUtils.createEmptyDocument(incomingBrowserData);
088        }
089    
090        protected MCRIndexBrowserIncomingData getIncomingBrowserData(HttpServletRequest request) {
091            return  MCRIndexBrowserUtils.getIncomingBrowserData(request);
092        }
093    }