/************************************************************************** /* A class encapsulating the rendering of results. /* /* Copyright (c) 2003-2004 by Bernhard Bablok (mail@bablokb.de) /* /* This library is free software; you can redistribute it and/or modify /* it under the terms of the GNU Lesser General Public License as published /* by the Free Software Foundation; either version 2 of the License or /* (at your option) any later version. /* /* This library is distributed in the hope that it will be useful, but /* WITHOUT ANY WARRANTY; without even the implied warranty of /* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the /* GNU Lesser General Public License for more details. /* /* You should have received a copy of the GNU Lesser General Public License /* along with this library; see the file COPYING.LESSER. If not, write to /* the Free Software Foundation Inc., 59 Temple Place - Suite 330, /* Boston, MA 02111-1307 USA /**************************************************************************/ package de.bablokb.luala.lib; import java.io.*; import org.apache.lucene.document.*; /** A class encapsulating the rendering of results. @version $Revision: 1.6 $ @author $Author: bablokb $ */ public class BasicResultRenderer implements ResultRenderer { //////////////////////////////////////////////////////////////////////////// /** Render summary: if true, also render summary-field (if available) */ private boolean iShowSummary = true; //////////////////////////////////////////////////////////////////////////// /** The header for the final result. */ private String iHeader; //////////////////////////////////////////////////////////////////////////// /** The footer for the final result. */ private String iFooter; //////////////////////////////////////////////////////////////////////////// /** The {@link DocumentRenderer} responsible of rendering individual hits. */ private DocumentRenderer iDocumentRenderer; //////////////////////////////////////////////////////////////////////////// /** Set the header. @param header The header to use. */ public void setHeader(String header) { iHeader = header; } //////////////////////////////////////////////////////////////////////////// /** Set the footer. @param footer The footer to use. */ public void setFooter(String footer) { iFooter = footer; } //////////////////////////////////////////////////////////////////////////// /** Set the showSummary-attribute. @param flag if true, show the summary. */ public void setShowSummary(boolean flag) { iShowSummary = flag; } //////////////////////////////////////////////////////////////////////////// /** Get the showSummary-attribute. @return returns the showSummary-attribute */ public boolean getShowSummary() { return iShowSummary; } //////////////////////////////////////////////////////////////////////////// /** Set the {@link DocumentRenderer} @param renderer The {@link DocumentRenderer} to use to render individual hits. */ public void setRenderer(DocumentRenderer renderer) { iDocumentRenderer = renderer; } //////////////////////////////////////////////////////////////////////////// /** {@inheritDoc} */ public Object render(Document[] results) throws IOException { StringBuffer buffer = new StringBuffer(); if (iHeader != null) buffer.append(iHeader); if (iDocumentRenderer != null) for (int i = 0; i < results.length; i++) buffer.append(iDocumentRenderer.render(results[i])); if (iFooter != null) buffer.append(iFooter); return buffer.toString(); } }