001    //$HeadURL: svn+ssh://mschneider@svn.wald.intevation.org/deegree/base/trunk/resources/eclipse/svn_classfile_header_template.xml $
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    
037    package org.deegree.ogcwebservices.wfs.operation;
038    
039    import static org.deegree.ogcwebservices.wfs.operation.AbstractWFSRequest.FORMAT_GML2_WFS100;
040    import static org.deegree.ogcwebservices.wfs.operation.AbstractWFSRequest.FORMAT_GML3;
041    
042    import java.util.List;
043    import java.util.Map;
044    
045    import org.deegree.framework.xml.XMLParsingException;
046    import org.deegree.framework.xml.XMLTools;
047    import org.deegree.i18n.Messages;
048    import org.deegree.ogcwebservices.InvalidParameterValueException;
049    import org.deegree.ogcwebservices.wfs.operation.GetFeature.RESULT_TYPE;
050    import org.deegree.ogcwebservices.wfs.operation.LockFeature.ALL_SOME_TYPE;
051    import org.w3c.dom.Element;
052    
053    /**
054     * Parser for "wfs:GetFeatureWithLock" requests.
055     * <p>
056     * Identical to "wfs:GetFeature" requests, except for two additional attributes in the root element (and the name of the
057     * root element, of course).
058     *
059     * @author <a href="mailto:schneider@lat-lon.de">Markus Schneider </a>
060     * @author last edited by: $Author:$
061     *
062     * @version $Revision:$, $Date:$
063     */
064    public class GetFeatureWithLockDocument extends GetFeatureDocument {
065    
066        private static final long serialVersionUID = -5865330735585920611L;
067    
068        /**
069         * Parses the underlying document into a <code>GetFeatureWithLock</code> request object.
070         *
071         * @param id
072         * @return corresponding <code>GetFeatureWithLock</code> object
073         * @throws XMLParsingException
074         * @throws InvalidParameterValueException
075         */
076        @Override
077        public GetFeatureWithLock parse( String id )
078                                throws XMLParsingException, InvalidParameterValueException {
079    
080            checkServiceAttribute();
081            String version = checkVersionAttribute();
082    
083            boolean useVersion_1_0_0 = "1.0.0".equals( version );
084    
085            Element root = this.getRootElement();
086            String handle = XMLTools.getNodeAsString( root, "@handle", nsContext, null );
087            String outputFormat = XMLTools.getNodeAsString( root, "@outputFormat", nsContext,
088                                                            useVersion_1_0_0 ? FORMAT_GML2_WFS100 : FORMAT_GML3 );
089    
090            int maxFeatures = XMLTools.getNodeAsInt( root, "@maxFeatures", nsContext, -1 );
091            int startPosition = XMLTools.getNodeAsInt( root, "@startPosition", nsContext, 1 );
092            if ( startPosition < 1 ) {
093                String msg = Messages.getMessage( "WFS_INVALID_STARTPOSITION", Integer.toString( startPosition ) );
094                throw new XMLParsingException( msg );
095            }
096    
097            int traverseXLinkDepth = XMLTools.getNodeAsInt( root, "@traverseXLinkDepth", nsContext, -1 );
098            int traverseXLinkExpiry = XMLTools.getNodeAsInt( root, "@traverseXLinkExpiry", nsContext, -1 );
099    
100            String resultTypeString = XMLTools.getNodeAsString( root, "@resultType", nsContext, "results" );
101            RESULT_TYPE resultType;
102            if ( "results".equals( resultTypeString ) ) {
103                resultType = RESULT_TYPE.RESULTS;
104            } else if ( "hits".equals( resultTypeString ) ) {
105                resultType = RESULT_TYPE.HITS;
106            } else {
107                String msg = Messages.getMessage( "WFS_INVALID_RESULT_TYPE", resultTypeString );
108                throw new XMLParsingException( msg );
109            }
110    
111            List<Element> nl = XMLTools.getRequiredElements( root, "wfs:Query", nsContext );
112            Query[] queries = new Query[nl.size()];
113            for ( int i = 0; i < queries.length; i++ ) {
114                queries[i] = parseQuery( nl.get( i ), useVersion_1_0_0 );
115            }
116    
117            // vendorspecific attributes; required by deegree rights management
118            Map<String, String> vendorSpecificParams = parseDRMParams( root );
119    
120            long expiry = LockFeatureDocument.parseExpiry( root );
121    
122            String lockActionString = XMLTools.getNodeAsString( root, "@lockAction", nsContext, "ALL" );
123            ALL_SOME_TYPE lockAction = ALL_SOME_TYPE.ALL;
124            try {
125                lockAction = LockFeature.validateLockAction( lockActionString );
126            } catch ( InvalidParameterValueException e ) {
127                throw new XMLParsingException( e.getMessage() );
128            }
129    
130            GetFeatureWithLock req = new GetFeatureWithLock( version, id, handle, resultType, outputFormat, maxFeatures,
131                                                             startPosition, traverseXLinkDepth, traverseXLinkExpiry,
132                                                             queries, vendorSpecificParams, expiry, lockAction );
133            return req;
134        }
135    }