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.net.URL;
040    import java.nio.charset.Charset;
041    import java.util.ArrayList;
042    import java.util.List;
043    
044    import javax.xml.bind.JAXBContext;
045    import javax.xml.bind.Unmarshaller;
046    
047    import org.deegree.enterprise.control.ajax.ResponseHandler;
048    import org.deegree.enterprise.control.ajax.WebEvent;
049    import org.deegree.framework.log.ILogger;
050    import org.deegree.framework.log.LoggerFactory;
051    import org.deegree.portal.cataloguemanager.model.CIAddress;
052    import org.deegree.portal.cataloguemanager.model.CIContact;
053    import org.deegree.portal.cataloguemanager.model.CIResponsibleParty;
054    import org.deegree.portal.cataloguemanager.model.EXExtent;
055    import org.deegree.portal.cataloguemanager.model.ExceptionBean;
056    import org.deegree.portal.cataloguemanager.model.Keyword;
057    import org.deegree.portal.cataloguemanager.model.MDDataIdentification;
058    import org.deegree.portal.cataloguemanager.model.MDMetadata;
059    import org.deegree.portal.cataloguemanager.model.MetadataBean;
060    import org.deegree.portal.cataloguemanager.model.TimePeriod;
061    
062    /**
063     * 
064     * 
065     * 
066     * @author <a href="mailto:poth@lat-lon.de">Andreas Poth</a>
067     * @author last edited by: $Author: jwilden $
068     * 
069     * @version $Revision: 25499 $, $Date: 2010-07-26 15:43:40 +0200 (Mo, 26 Jul 2010) $
070     */
071    public class ClearFormListener extends AbstractMetadataListener {
072    
073        private static final ILogger LOG = LoggerFactory.getLogger( ClearFormListener.class );
074    
075        @Override
076        public void actionPerformed( WebEvent event, ResponseHandler responseHandler )
077                                throws IOException {
078            CatalogueManagerConfiguration conf = getCatalogueManagerConfiguration( event );
079    
080            try {
081                JAXBContext jc = JAXBContext.newInstance( "org.deegree.portal.cataloguemanager.model" );
082                Unmarshaller u = jc.createUnmarshaller();
083    
084                String tmp = conf.getTemplateURL( "dataset" );
085                URL url = conf.resolve( tmp );
086                MDMetadata mdMetadata = (MDMetadata) u.unmarshal( url );
087    
088                MetadataBean metadata = new MetadataBean();
089    
090                metadata.setHlevel( "dataset" );
091                CIResponsibleParty resParty = mdMetadata.getContact().getCIResponsibleParty();
092                CIContact contact = resParty.getContactInfo().getCIContact();
093                CIAddress address = contact.getAddress().getCIAddress();
094                metadata.setContactCity( address.getCity().getCharacterString() );
095                metadata.setContactCountry( address.getCountry().getCharacterString() );
096                metadata.setContactDeliveryPoint( address.getDeliveryPoint().getCharacterString() );
097                metadata.setContactOrganisationName( resParty.getOrganisationName().getCharacterString() );
098                metadata.setContactPostalCode( address.getPostalCode().getCharacterString() );
099                metadata.setContactRole( resParty.getRole().getCIRoleCode().getCodeListValue() );
100    
101                MDDataIdentification dataIdent = mdMetadata.getIdentificationInfo().getMDDataIdentification();
102                EXExtent extent = dataIdent.getExtent().getEXExtent();
103                TimePeriod timePeriod = extent.getTemporalElement().getEXTemporalExtent().getExtent().getTimePeriod();
104                metadata.setBegin( timePeriod.getBeginPosition() );
105                metadata.setEnd( timePeriod.getEndPosition() );
106                if ( extent.getDescription() != null ) {
107                    metadata.setGeogrDescription( extent.getDescription().getCharacterString() );
108                }
109    
110                List<Keyword> keywords = dataIdent.getDescriptiveKeywords().getMDKeywords().getKeyword();
111                List<String> kws = new ArrayList<String>( keywords.size() );
112                for ( Keyword keyword : keywords ) {
113                    kws.add( keyword.getCharacterString() );
114                }
115                metadata.setKeywords( kws );
116    
117                resParty = dataIdent.getPointOfContact().getCIResponsibleParty();
118                contact = resParty.getContactInfo().getCIContact();
119                address = contact.getAddress().getCIAddress();
120                metadata.setPocCity( address.getCity().getCharacterString() );
121                metadata.setPocCountry( address.getCountry().getCharacterString() );
122                metadata.setPocDeliveryPoint( address.getDeliveryPoint().getCharacterString() );
123                metadata.setPocOrganisationName( resParty.getOrganisationName().getCharacterString() );
124                metadata.setPocPostalCode( address.getPostalCode().getCharacterString() );
125                metadata.setPocRole( resParty.getRole().getCIRoleCode().getCodeListValue() );
126                metadata.setTopCat( dataIdent.getTopicCategory().getMDTopicCategoryCode() );
127    
128                responseHandler.setContentType( "text/plain; charset=" + Charset.defaultCharset().displayName() );
129                responseHandler.writeAndClose( true, metadata );
130    
131            } catch ( Exception e ) {
132                LOG.logError( e.getMessage(), e );
133                ExceptionBean eb = new ExceptionBean( getClass().getName(), e.getMessage() );
134                responseHandler.writeAndClose( true, eb );
135                return;
136            }
137        }
138    
139    }