001    //$HeadURL: svn+ssh://mschneider@svn.wald.intevation.org/deegree/base/trunk/resources/eclipse/svn_classfile_header_template.xml $
002    /*----------------    FILE HEADER  ------------------------------------------
003     This file is part of deegree.
004     Copyright (C) 2001-2007 by:
005     Department of Geography, University of Bonn
006     http://www.giub.uni-bonn.de/deegree/
007     lat/lon GmbH
008     http://www.lat-lon.de
009    
010     This library is free software; you can redistribute it and/or
011     modify it under the terms of the GNU Lesser General Public
012     License as published by the Free Software Foundation; either
013     version 2.1 of the License, or (at your option) any later version.
014     This library is distributed in the hope that it will be useful,
015     but WITHOUT ANY WARRANTY; without even the implied warranty of
016     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
017     Lesser General Public License for more details.
018     You should have received a copy of the GNU Lesser General Public
019     License along with this library; if not, write to the Free Software
020     Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
021     Contact:
022    
023     Andreas Poth
024     lat/lon GmbH
025     Aennchenstr. 19
026     53177 Bonn
027     Germany
028     E-Mail: poth@lat-lon.de
029    
030     Prof. Dr. Klaus Greve
031     Department of Geography
032     University of Bonn
033     Meckenheimer Allee 166
034     53115 Bonn
035     Germany
036     E-Mail: greve@giub.uni-bonn.de
037     ---------------------------------------------------------------------------*/
038    
039    package org.deegree.ogcwebservices.wfs.operation;
040    
041    import java.util.List;
042    import java.util.Map;
043    
044    import org.deegree.framework.xml.XMLParsingException;
045    import org.deegree.framework.xml.XMLTools;
046    import org.deegree.i18n.Messages;
047    import org.deegree.ogcwebservices.InvalidParameterValueException;
048    import org.deegree.ogcwebservices.wfs.operation.GetFeature.RESULT_TYPE;
049    import org.deegree.ogcwebservices.wfs.operation.LockFeature.ALL_SOME_TYPE;
050    import org.w3c.dom.Element;
051    
052    /**
053     * Parser for "wfs:GetFeatureWithLock" requests.
054     * <p>
055     * Identical to "wfs:GetFeature" requests, except for two additional attributes in the root element
056     * (and the name of the root element, of course).
057     * 
058     * @author <a href="mailto:schneider@lat-lon.de">Markus Schneider </a>
059     * @author last edited by: $Author:$
060     * 
061     * @version $Revision:$, $Date:$
062     */
063    public class GetFeatureWithLockDocument extends GetFeatureDocument {
064    
065        private static final long serialVersionUID = -5865330735585920611L;
066    
067        /**
068         * Parses the underlying document into a <code>GetFeatureWithLock</code> request object.
069         * 
070         * @param id
071         * @return corresponding <code>GetFeatureWithLock</code> object
072         * @throws XMLParsingException
073         */
074        @Override
075        public GetFeatureWithLock parse( String id )
076                                throws XMLParsingException {
077    
078            checkServiceAttribute();
079            String version = checkVersionAttribute();
080            
081            boolean useVersion_1_0_0 = "1.0.0".equals( version );
082    
083            Element root = this.getRootElement();
084            String handle = XMLTools.getNodeAsString( root, "@handle", nsContext, null );
085            String outputFormat = XMLTools.getNodeAsString( root, "@outputFormat", nsContext,
086                                                            AbstractWFSRequest.FORMAT_GML3 );
087    
088            int maxFeatures = XMLTools.getNodeAsInt( root, "@maxFeatures", nsContext, -1 );
089            int startPosition = XMLTools.getNodeAsInt( root, "@startPosition", nsContext, 1 );
090            if ( startPosition < 1 ) {
091                String msg = Messages.getMessage( "WFS_INVALID_STARTPOSITION", Integer.toString( startPosition ) );
092                throw new XMLParsingException( msg );
093            }
094    
095            int traverseXLinkDepth = XMLTools.getNodeAsInt( root, "@traverseXLinkDepth", nsContext, -1 );
096            int traverseXLinkExpiry = XMLTools.getNodeAsInt( root, "@traverseXLinkExpiry", nsContext, -1 );
097    
098            String resultTypeString = XMLTools.getNodeAsString( root, "@resultType", nsContext, "results" );
099            RESULT_TYPE resultType;
100            if ( "results".equals( resultTypeString ) ) {
101                resultType = RESULT_TYPE.RESULTS;
102            } else if ( "hits".equals( resultTypeString ) ) {
103                resultType = RESULT_TYPE.HITS;
104            } else {
105                String msg = Messages.getMessage( "WFS_INVALID_RESULT_TYPE", resultTypeString );
106                throw new XMLParsingException( msg );
107            }
108    
109            List<Element> nl = XMLTools.getRequiredElements( root, "wfs:Query", nsContext );
110            Query[] queries = new Query[nl.size()];
111            for ( int i = 0; i < queries.length; i++ ) {
112                queries[i] = parseQuery( nl.get( i ), useVersion_1_0_0 );
113            }
114    
115            // vendorspecific attributes; required by deegree rights management
116            Map<String, String> vendorSpecificParams = parseDRMParams( root );
117    
118            long expiry = LockFeatureDocument.parseExpiry( root );
119    
120            String lockActionString = XMLTools.getNodeAsString( root, "@lockAction", nsContext, "ALL" );
121            ALL_SOME_TYPE lockAction = ALL_SOME_TYPE.ALL;
122            try {
123                lockAction = LockFeature.validateLockAction( lockActionString );
124            } catch ( InvalidParameterValueException e ) {
125                throw new XMLParsingException( e.getMessage() );
126            }
127    
128            GetFeatureWithLock req = new GetFeatureWithLock( version, id, handle, resultType, outputFormat, maxFeatures,
129                                                             startPosition, traverseXLinkDepth, traverseXLinkExpiry,
130                                                             queries, vendorSpecificParams, expiry, lockAction );
131            return req;
132        }
133    }