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.StringReader; 040 import java.net.URL; 041 import java.util.Enumeration; 042 import java.util.HashMap; 043 import java.util.Map; 044 045 import javax.servlet.http.HttpServletRequest; 046 047 import org.apache.commons.httpclient.HttpMethod; 048 import org.deegree.enterprise.control.ajax.ResponseHandler; 049 import org.deegree.enterprise.control.ajax.WebEvent; 050 import org.deegree.framework.log.ILogger; 051 import org.deegree.framework.log.LoggerFactory; 052 import org.deegree.framework.util.FileUtils; 053 import org.deegree.framework.util.HttpUtils; 054 import org.deegree.framework.util.StringTools; 055 import org.deegree.framework.xml.XMLFragment; 056 import org.deegree.portal.cataloguemanager.model.ExceptionBean; 057 058 /** 059 * 060 * 061 * 062 * @author <a href="mailto:poth@lat-lon.de">Andreas Poth</a> 063 * @author last edited by: $Author: apoth $ 064 * 065 * @version $Revision: 30690 $, $Date: 2011-05-06 10:23:46 +0200 (Fr, 06 Mai 2011) $ 066 */ 067 public class DeleteMetadataListener extends AbstractMetadataListener { 068 069 private static final ILogger LOG = LoggerFactory.getLogger( DeleteMetadataListener.class ); 070 071 @SuppressWarnings("unchecked") 072 public void actionPerformed( WebEvent event, ResponseHandler responseHandler ) 073 throws IOException { 074 075 try { 076 CatalogueManagerConfiguration conf = getCatalogueManagerConfiguration( event ); 077 String id = (String) event.getParameter().get( "ID" ); 078 079 URL url = getClass().getResource( "delete.xml" ); 080 String s = FileUtils.readTextFile( url ).toString(); 081 s = StringTools.replace( s, "$id$", id, false ); 082 XMLFragment xml = new XMLFragment(); 083 xml.load( new StringReader( s ), XMLFragment.DEFAULT_URL ); 084 085 Enumeration<String> en = ( (HttpServletRequest) getRequest() ).getHeaderNames(); 086 Map<String, String> map = new HashMap<String, String>(); 087 while ( en.hasMoreElements() ) { 088 String name = (String) en.nextElement(); 089 if ( !name.equalsIgnoreCase( "accept-encoding" ) && !name.equalsIgnoreCase( "content-length" ) 090 && !name.equalsIgnoreCase( "user-agent" ) ) { 091 map.put( name, ( (HttpServletRequest) getRequest() ).getHeader( name ) ); 092 } 093 } 094 HttpMethod post = HttpUtils.performHttpPost( conf.getCatalogueURL(), xml, 60000, null, null, map ); 095 s = post.getResponseBodyAsString(); 096 if ( s.toLowerCase().indexOf( "exception" ) > -1 ) { 097 ExceptionBean eb = new ExceptionBean( getClass().getName(), "delete failed" ); 098 responseHandler.writeAndClose( true, eb ); 099 } else { 100 responseHandler.writeAndClose( "insert performed" ); 101 } 102 } catch ( Exception e ) { 103 LOG.logError( e.getMessage(), e ); 104 ExceptionBean eb = new ExceptionBean( getClass().getName(), e.getMessage() ); 105 responseHandler.writeAndClose( true, eb ); 106 return; 107 } 108 109 } 110 111 }