    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.List;
    043
    044    import org.deegree.enterprise.control.ajax.ResponseHandler;
    045    import org.deegree.enterprise.control.ajax.WebEvent;
    046    import org.deegree.framework.log.ILogger;
    047    import org.deegree.framework.log.LoggerFactory;
    048    import org.deegree.framework.util.HttpUtils;
    049    import org.deegree.framework.xml.NamespaceContext;
    050    import org.deegree.framework.xml.XMLFragment;
    051    import org.deegree.framework.xml.XMLTools;
    052    import org.deegree.ogcbase.CommonNamespaces;
    053    import org.w3c.dom.Element;
    054
    055    /**
    056     *
    057     *
    058     *
    059     * @author <a href="mailto:poth@lat-lon.de">Andreas Poth</a>
    060     * @author last edited by: $Author: apoth $
    061     *
    062     * @version $Revision: 24932 $, $Date: 2010-06-17 20:16:34 +0200 (Do, 17. Jun 2010) $
    063     */
    064    public class GetParentsListener extends AbstractMetadataListener {
    065
    066        private static final ILogger LOG = LoggerFactory.getLogger( GetParentsListener.class );
    067
    068        private static NamespaceContext nsc = CommonNamespaces.getNamespaceContext();
    069
    070        /*
    071         * (non-Javadoc)
    072         *
    073         * @see org.deegree.portal.cataloguemanager.control.AbstractMetadataListener#actionPerformed(
    074         * org.deegree.enterprise.control.ajax.WebEvent, org.deegree.portal.cataloguemanager.control.ResponseHandler)
    075         */
    076        public void actionPerformed( WebEvent event, ResponseHandler responseHandler )
    077                                throws IOException {
    078            List<String> parents = new ArrayList<String>();
    079            CatalogueManagerConfiguration config = getCatalogueManagerConfiguration( event );
    080            String addr = config.getCatalogueURL();
    081            URL url = getClass().getResource( "GetRecordsSeries.xml" );
    082            // read all metadata series from a CSW
    083            LOG.logInfo( "CSW Address: ", addr );
    084            InputStream is = HttpUtils.performHttpPost( addr, url.openStream(), 60000, null, null, "text/xml", null, null ).getResponseBodyAsStream();
    085            try {
    086                XMLFragment xml = new XMLFragment();
    087                xml.load( is, addr );
    088                String xpath = "./csw202:SearchResults/gmd:MD_Metadata";
    089                List<Element> mdSets = XMLTools.getElements( xml.getRootElement(), xpath, nsc );
    090                for ( Element element : mdSets ) {
    091                    xpath = "./gmd:fileIdentifier/gco:CharacterString";
    092                    String s1 = XMLTools.getNodeAsString( element, xpath, nsc, "" );
    093                    xpath = "./gmd:identificationInfo/gmd:MD_DataIdentification/gmd:citation/gmd:CI_Citation/gmd:title/gco:CharacterString";
    094                    String s2 = XMLTools.getNodeAsString( element, xpath, nsc, "" );
    095                    parents.add( s1 + ';' + s2 );
    096                }
    097            } catch ( Exception e ) {
    098                LOG.logError( e );
    099                throw new IOException( e.getMessage() );
    100            }
    101            responseHandler.writeAndClose( false, parents );
    102        }
    103
    104    }