001 //$HeadURL: svn+ssh://developername@svn.wald.intevation.org/deegree/base/trunk/resources/eclipse/files_template.xml $ 002 /*---------------------------------------------------------------------------- 003 This file is part of deegree, http://deegree.org/ 004 Copyright (C) 2001-2009 by: 005 - Department of Geography, University of Bonn - 006 and 007 - lat/lon GmbH - 008 009 This library is free software; you can redistribute it and/or modify it under 010 the terms of the GNU Lesser General Public License as published by the Free 011 Software Foundation; either version 2.1 of the License, or (at your option) 012 any later version. 013 This library is distributed in the hope that it will be useful, but WITHOUT 014 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS 015 FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more 016 details. 017 You should have received a copy of the GNU Lesser General Public License 018 along with this library; if not, write to the Free Software Foundation, Inc., 019 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 020 021 Contact information: 022 023 lat/lon GmbH 024 Aennchenstr. 19, 53177 Bonn 025 Germany 026 http://lat-lon.de/ 027 028 Department of Geography, University of Bonn 029 Prof. Dr. Klaus Greve 030 Postfach 1147, 53001 Bonn 031 Germany 032 http://www.geographie.uni-bonn.de/deegree/ 033 034 e-mail: info@deegree.org 035 ----------------------------------------------------------------------------*/ 036 package org.deegree.portal.cataloguemanager.control; 037 038 import java.io.IOException; 039 import java.util.List; 040 import java.util.Map; 041 import java.util.UUID; 042 043 import org.deegree.enterprise.control.ajax.ResponseHandler; 044 import org.deegree.enterprise.control.ajax.WebEvent; 045 import org.deegree.framework.log.ILogger; 046 import org.deegree.framework.log.LoggerFactory; 047 import org.deegree.framework.util.Pair; 048 import org.deegree.framework.xml.XMLFragment; 049 import org.deegree.ogcwebservices.csw.discovery.GetRecords; 050 import org.deegree.ogcwebservices.csw.discovery.Query; 051 import org.deegree.ogcwebservices.csw.discovery.GetRecords.RESULT_TYPE; 052 import org.deegree.portal.cataloguemanager.model.ExceptionBean; 053 054 /** 055 * TODO add class documentation here 056 * 057 * @author <a href="mailto:name@deegree.org">Andreas Poth</a> 058 * @author last edited by: $Author: admin $ 059 * 060 * @version $Revision: $, $Date: $ 061 */ 062 public class PageingListener extends AbstractSearchListener { 063 064 private static final ILogger LOG = LoggerFactory.getLogger( PageingListener.class ); 065 066 /* 067 * (non-Javadoc) 068 * 069 * @see 070 * org.deegree.enterprise.control.ajax.AbstractListener#actionPerformed(org.deegree.enterprise.control.ajax.WebEvent 071 * , org.deegree.enterprise.control.ajax.ResponseHandler) 072 */ 073 @SuppressWarnings("unchecked") 074 public void actionPerformed( WebEvent event, ResponseHandler responseHandler ) 075 throws IOException { 076 077 config = getCatalogueManagerConfiguration( event ); 078 Map<String, String> param = event.getParameter(); 079 080 GetRecords getRecords = (GetRecords) event.getSession().getAttribute( CURRENTSEARCH ); 081 int counter = Integer.parseInt( param.get( "counter" ) ); 082 083 if ( counter < 0 ) { 084 // '<' button has been pressed 085 int tmp = (Integer) event.getSession().getAttribute( COUNTER ); 086 counter = tmp - 1; 087 if ( counter < 0 ) { 088 counter = 0; 089 } 090 } else if ( counter > 999 ) { 091 // '>' button has been pressed 092 int tmp = (Integer) event.getSession().getAttribute( COUNTER ); 093 counter = tmp + 1; 094 if ( counter > 4 ) { 095 counter = 4; 096 } 097 } 098 Query query = getRecords.getQuery(); 099 // in/decrease start position for query 100 getRecords = new GetRecords( UUID.randomUUID().toString(), "2.0.2", null, null, RESULT_TYPE.RESULTS, 101 "application/xml", "http://www.isotc211.org/2005/gmd", 102 1 + ( counter * config.getStepSize() ), config.getStepSize(), -1, null, query ); 103 104 List<Pair<String, XMLFragment>> result; 105 try { 106 result = performQuery( getRecords ); 107 } catch ( Throwable e ) { 108 LOG.logError( e ); 109 ExceptionBean bean = new ExceptionBean( this.getClass().getName(), e.getMessage() ); 110 responseHandler.writeAndClose( true, bean ); 111 return; 112 } 113 114 List<SearchResultBean> formattedResult = null; 115 try { 116 formattedResult = formatResult( result ); 117 } catch ( Exception e ) { 118 LOG.logError( e ); 119 ExceptionBean bean = new ExceptionBean( this.getClass().getName(), e.getMessage() ); 120 responseHandler.writeAndClose( true, bean ); 121 return; 122 } 123 124 // store search meta informations to be used for pageing 125 event.getSession().setAttribute( SEARCHRESULTINFO, searchResultInfos ); 126 127 int c = 0; 128 for ( SearchResultInfo sri : searchResultInfos ) { 129 c += sri.getNumberOfRecordsMatched(); 130 } 131 132 event.getSession().setAttribute( CURRENTSEARCH, getRecords ); 133 event.getSession().setAttribute( COUNTER, counter ); 134 135 responseHandler.writeAndClose( false, new Object[] { formattedResult, new Integer( c ), new Integer( counter ) } ); 136 137 } 138 139 }