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.File; 039 import java.io.FilenameFilter; 040 import java.io.IOException; 041 import java.util.ArrayList; 042 import java.util.List; 043 044 import javax.servlet.ServletException; 045 import javax.servlet.http.HttpServletRequest; 046 import javax.servlet.http.HttpServletResponse; 047 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.xml.NamespaceContext; 053 import org.deegree.framework.xml.XMLFragment; 054 import org.deegree.framework.xml.XMLTools; 055 import org.deegree.ogcbase.CommonNamespaces; 056 057 /** 058 * 059 * 060 * 061 * @author <a href="mailto:poth@lat-lon.de">Andreas Poth</a> 062 * @author last edited by: $Author: apoth $ 063 * 064 * @version $Revision: 27361 $, $Date: 2010-10-18 20:38:36 +0200 (Mo, 18 Okt 2010) $ 065 */ 066 public class GetTemplateListListener extends AbstractMetadataListener { 067 068 private static final ILogger LOG = LoggerFactory.getLogger( GetMetadataListListener.class ); 069 070 private static NamespaceContext nsc = CommonNamespaces.getNamespaceContext(); 071 072 /* 073 * (non-Javadoc) 074 * 075 * @see org.deegree.portal.cataloguemanager.control.AbstractMetadataListener#actionPerformed( 076 * org.deegree.enterprise.control.ajax.WebEvent, org.deegree.portal.cataloguemanager.control.ResponseHandler) 077 */ 078 public void actionPerformed( WebEvent event, ResponseHandler responseHandler ) 079 throws IOException { 080 List<String[]> rows = new ArrayList<String[]>(); 081 CatalogueManagerConfiguration config = getCatalogueManagerConfiguration( event ); 082 String templateDirectory = config.getTemplateDirectory(); 083 templateDirectory = event.getAbsolutePath( templateDirectory ); 084 File[] templates = new File( templateDirectory ).listFiles( new FilenameFilter() { 085 086 public boolean accept( File dir, String name ) { 087 return name != null && name.toLowerCase().endsWith( ".xml" ); 088 } 089 } ); 090 091 try { 092 for ( File file : templates ) { 093 XMLFragment xml = new XMLFragment( file.toURL() ); 094 String[] s = new String[3]; 095 s[0] = file.getAbsolutePath(); 096 String xpath = "./gmd:identificationInfo/gmd:MD_DataIdentification/gmd:citation/gmd:CI_Citation/gmd:title/gco:CharacterString"; 097 s[1] = XMLTools.getNodeAsString( xml.getRootElement(), xpath, nsc, "" ); 098 xpath = "./gmd:identificationInfo/gmd:MD_DataIdentification/gmd:abstract/gco:CharacterString"; 099 s[2] = XMLTools.getNodeAsString( xml.getRootElement(), xpath, nsc, "" ); 100 rows.add( s ); 101 102 } 103 } catch ( Exception e ) { 104 LOG.logError( e ); 105 throw new IOException( e.getMessage() ); 106 } 107 108 HttpServletRequest request = ( (HttpServletRequest) event.getSource() ); 109 request.setAttribute( "TEMPLATES", rows ); 110 111 try { 112 HttpServletResponse resp = responseHandler.getHttpServletResponse(); 113 // result page uses UTF-8 encoding 114 resp.setCharacterEncoding( "UTF-8" ); 115 request.getRequestDispatcher( '/' + getNextPage() ).forward( request, resp ); 116 } catch ( ServletException e ) { 117 throw new IOException( e.getMessage() ); 118 } 119 } 120 121 }