/*
* regain - A file search engine providing plenty of formats
* Copyright (C) 2004-2010 Til Schneider, Thomas Tesche
*
* 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.1 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; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*
* Contact: Til Schneider, info@murfman.de, Thomas Tesche, www.thtesche.com
*
* CVS information:
* $RCSfile$
* $Source$
* $Date: 2009-11-26 18:14:25 +0100 (Do, 26. Nov 2009) $
* $Author: thtesche $
* $Revision: 430 $
*/
package net.sf.regain.search.sharedlib.hit;
import java.text.DateFormat;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;
import net.sf.regain.RegainException;
import net.sf.regain.util.sharedtag.PageRequest;
import net.sf.regain.util.sharedtag.PageResponse;
import org.apache.lucene.document.Document;
/**
* Generates the last modified date of the current hit's document.
*
* @author Thomas Tesche, www.thtesche.com
*/
public class LastModifiedTag extends AbstractHitTag {
/**
* Generates the tag.
*
* @param request The page request.
* @param response The page response.
* @param hit The current search hit.
* @param hitIndex The index of the hit.
* @throws RegainException If there was an exception.
*/
protected void printEndTag(PageRequest request, PageResponse response,
Document hit, int hitIndex)
throws RegainException {
String value = hit.get("last-modified");
if (value != null || value.length() > 0) {
DateFormat dateFormatter = DateFormat.getDateInstance(DateFormat.DEFAULT, request.getLocale());
DateFormat formatter = new SimpleDateFormat("yyyyMMdd");
try {
response.print(dateFormatter.format((Date) formatter.parse(value)));
} catch (ParseException ex) {
throw new RegainException("Couldn't parse last-modified date.", ex);
}
}
}
}