001 //$HeadURL: 002 /*---------------------------------------------------------------------------- 003 This file is part of deegree, http://deegree.org/ 004 Copyright (C) 2001-2010 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.io.InputStream; 040 import java.net.URL; 041 import java.util.ArrayList; 042 import java.util.Enumeration; 043 import java.util.HashMap; 044 import java.util.List; 045 import java.util.Map; 046 047 import javax.servlet.ServletException; 048 import javax.servlet.http.HttpServletRequest; 049 import javax.servlet.http.HttpServletResponse; 050 051 import org.deegree.enterprise.control.ajax.ResponseHandler; 052 import org.deegree.enterprise.control.ajax.WebEvent; 053 import org.deegree.framework.log.ILogger; 054 import org.deegree.framework.log.LoggerFactory; 055 import org.deegree.framework.util.HttpUtils; 056 import org.deegree.framework.xml.NamespaceContext; 057 import org.deegree.framework.xml.XMLFragment; 058 import org.deegree.framework.xml.XMLTools; 059 import org.deegree.ogcbase.CommonNamespaces; 060 import org.w3c.dom.Element; 061 062 /** 063 * 064 * 065 * 066 * @author <a href="mailto:poth@lat-lon.de">Andreas Poth</a> 067 * @author last edited by: $Author: apoth $ 068 * 069 * @version $Revision: 30690 $, $Date: 2011-05-06 10:23:46 +0200 (Fr, 06 Mai 2011) $ 070 */ 071 public class GetMetadataListListener extends AbstractMetadataListener { 072 073 private static final ILogger LOG = LoggerFactory.getLogger( GetMetadataListListener.class ); 074 075 private static NamespaceContext nsc = CommonNamespaces.getNamespaceContext(); 076 077 /* 078 * (non-Javadoc) 079 * 080 * @see org.deegree.portal.cataloguemanager.control.AbstractMetadataListener#actionPerformed( 081 * org.deegree.enterprise.control.ajax.WebEvent, org.deegree.portal.cataloguemanager.control.ResponseHandler) 082 */ 083 @SuppressWarnings("unchecked") 084 public void actionPerformed( WebEvent event, ResponseHandler responseHandler ) 085 throws IOException { 086 List<String[]> rows = new ArrayList<String[]>(); 087 CatalogueManagerConfiguration config = getCatalogueManagerConfiguration( event ); 088 String addr = config.getCatalogueURL(); 089 URL url = getClass().getResource( "GetRecords.xml" ); 090 // read all metadata sets from a CSW 091 Enumeration<String> en = ( (HttpServletRequest) getRequest() ).getHeaderNames(); 092 Map<String, String> map = new HashMap<String, String>(); 093 while ( en.hasMoreElements() ) { 094 String name = (String) en.nextElement(); 095 if ( !name.equalsIgnoreCase( "accept-encoding" ) && !name.equalsIgnoreCase( "content-length" ) 096 && !name.equalsIgnoreCase( "user-agent" ) ) { 097 map.put( name, ( (HttpServletRequest) getRequest() ).getHeader( name ) ); 098 } 099 } 100 InputStream is = HttpUtils.performHttpPost( addr, url.openStream(), 60000, null, null, "text/xml", null, map ).getResponseBodyAsStream(); 101 try { 102 XMLFragment xml = new XMLFragment(); 103 xml.load( is, addr ); 104 String xpath = "./csw202:SearchResults/gmd:MD_Metadata"; 105 List<Element> mdSets = XMLTools.getElements( xml.getRootElement(), xpath, nsc ); 106 for ( Element element : mdSets ) { 107 String[] s = new String[3]; 108 xpath = "./gmd:fileIdentifier/gco:CharacterString"; 109 s[0] = XMLTools.getNodeAsString( element, xpath, nsc, "" ); 110 xpath = "./gmd:identificationInfo/gmd:MD_DataIdentification/gmd:citation/gmd:CI_Citation/gmd:title/gco:CharacterString"; 111 s[1] = XMLTools.getNodeAsString( element, xpath, nsc, "" ); 112 xpath = "./gmd:identificationInfo/gmd:MD_DataIdentification/gmd:abstract/gco:CharacterString"; 113 s[2] = XMLTools.getNodeAsString( element, xpath, nsc, "" ); 114 rows.add( s ); 115 } 116 } catch ( Exception e ) { 117 LOG.logError( e ); 118 throw new IOException( e.getMessage() ); 119 } 120 121 HttpServletRequest request = ( (HttpServletRequest) event.getSource() ); 122 request.setAttribute( "METADATASETS", rows ); 123 124 try { 125 HttpServletResponse resp = responseHandler.getHttpServletResponse(); 126 // result page uses UTF-8 encoding 127 resp.setCharacterEncoding( "UTF-8" ); 128 request.getRequestDispatcher( '/' + getNextPage() ).forward( request, resp ); 129 } catch ( ServletException e ) { 130 throw new IOException( e.getMessage() ); 131 } 132 } 133 134 }