    001    //$HeadURL: https://svn.wald.intevation.org/svn/deegree/base/branches/2.4_testing/src/org/deegree/ogcwebservices/csw/discovery/GetRecordByIdDocument.java $
    002    /*----------------------------------------------------------------------------
    003     This file is part of deegree, http://deegree.org/
    004     Copyright (C) 2001-2009 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.ogcwebservices.csw.discovery;
    037
    038    import java.io.IOException;
    039    import java.net.URL;
    040    import java.util.Map;
    041
    042    import org.deegree.framework.util.StringTools;
    043    import org.deegree.framework.xml.XMLTools;
    044    import org.deegree.ogcbase.ExceptionCode;
    045    import org.deegree.ogcwebservices.InvalidParameterValueException;
    046    import org.deegree.ogcwebservices.OGCWebServiceException;
    047    import org.deegree.ogcwebservices.csw.AbstractCSWRequestDocument;
    048    import org.w3c.dom.Node;
    049    import org.xml.sax.SAXException;
    050
    051    /**
    052     *
    053     *
    054     * @version $Revision: 18195 $
    055     * @author <a href="mailto:poth@lat-lon.de">Andreas Poth</a>
    056     * @author last edited by: $Author: mschneider $
    057     *
    058     * @version 1.0. $Revision: 18195 $, $Date: 2009-06-18 17:55:39 +0200 (Do, 18. Jun 2009) $
    059     *
    060     * @since 2.0
    061     */
    062    public class GetRecordByIdDocument extends AbstractCSWRequestDocument {
    063
    064        private static final long serialVersionUID = 2796229558893029054L;
    065
    066        private static final String XML_TEMPLATE = "GetRecordByIdTemplate.xml";
    067
    068        GetRecordById parse( String id )
    069                                throws OGCWebServiceException {
    070
    071            String version = null;
    072            Map<String, String> vendorSpecificParameters = null;
    073            String[] ids = null;
    074            String elementSetName = null;
    075
    076            try {
    077                // '<csw:GetRecords>'-element (required)
    078                Node contextNode = XMLTools.getRequiredNode( this.getRootElement(), "self::csw:GetRecordById", nsContext );
    079
    080                // 'service'-attribute (required, must be CSW)
    081                String service = XMLTools.getRequiredNodeAsString( contextNode, "@service", nsContext );
    082                if ( !service.equals( "CSW" ) ) {
    083                    ExceptionCode code = ExceptionCode.INVALIDPARAMETERVALUE;
    084                    throw new InvalidParameterValueException( "GetRecordById", "'service' must be 'CSW'", code );
    085                }
    086
    087                // 'version'-attribute (required)
    088                version = XMLTools.getNodeAsString( contextNode, "@version", nsContext, GetRecords.DEFAULT_VERSION );
    089
    090                // '<csw:ResponseHandler>'-elements (optional)
    091                ids = XMLTools.getNodesAsStrings( contextNode, "csw:Id", nsContext );
    092
    093                // '<csw:ElementSetName>'-element (optional)
    094                Node elementSetNameElement = XMLTools.getNode( contextNode, "csw:ElementSetName", nsContext );
    095
    096                if ( elementSetNameElement != null ) {
    097                    // must contain one of the values 'brief', 'summary' or
    098                    // 'full'
    099                    elementSetName = XMLTools.getRequiredNodeAsString( elementSetNameElement, "text()", nsContext,
    100                                                                       new String[] { "brief", "summary", "full" } );
    101
    102                } else {
    103                    elementSetName = "summary";
    104                }
    105                // in the future the vendorSpecificParameters
    106                vendorSpecificParameters = parseDRMParams( this.getRootElement() );
    107            } catch ( Exception e ) {
    108                ExceptionCode code = ExceptionCode.INVALIDPARAMETERVALUE;
    109                throw new OGCWebServiceException( "GetRecordByIdDocument", StringTools.stackTraceToString( e ), code );
    110            }
    111
    112            return new GetRecordById( id, version, vendorSpecificParameters, ids, elementSetName );
    113        }
    114
    115        /*
    116         * (non-Javadoc)
    117         *
    118         * @see org.deegree.framework.xml.XMLFragment#createEmptyDocument()
    119         */
    120        void createEmptyDocument()
    121                                throws IOException, SAXException {
    122            URL url = GetRecordByIdDocument.class.getResource( XML_TEMPLATE );
    123            if ( url == null ) {
    124                throw new IOException( "The resource '" + XML_TEMPLATE + " could not be found." );
    125            }
    126            load( url );
    127        }
    128
    129    }