001 //$HeadURL: https://svn.wald.intevation.org/svn/deegree/base/branches/2.3_testing/src/org/deegree/security/owsrequestvalidator/csw/AbstractCSWRequestValidator.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.security.owsrequestvalidator.csw;
037
038 import java.io.IOException;
039 import java.io.StringReader;
040 import java.util.List;
041
042 import org.deegree.framework.xml.XMLFragment;
043 import org.deegree.model.filterencoding.AbstractFilter;
044 import org.deegree.model.filterencoding.ComplexFilter;
045 import org.deegree.model.filterencoding.FilterConstructionException;
046 import org.deegree.model.filterencoding.Literal;
047 import org.deegree.model.filterencoding.LogicalOperation;
048 import org.deegree.model.filterencoding.Operation;
049 import org.deegree.model.filterencoding.OperationDefines;
050 import org.deegree.model.filterencoding.PropertyIsCOMPOperation;
051 import org.deegree.model.filterencoding.PropertyName;
052 import org.deegree.security.owsproxy.Condition;
053 import org.deegree.security.owsrequestvalidator.Policy;
054 import org.deegree.security.owsrequestvalidator.RequestValidator;
055 import org.xml.sax.SAXException;
056
057 /**
058 * Abstract super class for validating catalogue requests.
059 *
060 * @version $Revision: 18195 $
061 * @author <a href="mailto:poth@lat-lon.de">Andreas Poth</a>
062 * @author last edited by: $Author: mschneider $
063 *
064 * @version 1.0. $Revision: 18195 $, $Date: 2009-06-18 17:55:39 +0200 (Do, 18. Jun 2009) $
065 *
066 * @since 2.0
067 */
068 public abstract class AbstractCSWRequestValidator extends RequestValidator {
069
070 private static final String PROPERTY_INSTANCEFILTER = "instanceFilter";
071
072 /**
073 * initializes the AbstractCSWRequestValidator by passing an instance of the policy to be used by each concrete
074 * implementation
075 *
076 * @param policy
077 */
078 public AbstractCSWRequestValidator( Policy policy ) {
079 super( policy );
080 }
081
082 /**
083 * validates the requested record type / outputTypeRec. If the current user is not allowed to request a record type
084 * (e.g. ISO 19115) an UnauthorizedException will be thrown.
085 *
086 * @param condition
087 * @param typeNames
088 */
089 public void validateRecordTypes( Condition condition, String[] typeNames ) {
090 throw new UnsupportedOperationException( "validateRecordTypes is not implemented yet" );
091 }
092
093 protected ComplexFilter extractInstanceFilter( Operation operation, List<ComplexFilter> foundFilters )
094 throws SAXException, IOException, FilterConstructionException {
095 ComplexFilter filter = null;
096 if ( operation.getOperatorId() == OperationDefines.AND || operation.getOperatorId() == OperationDefines.OR ) {
097 List<Operation> arguments = ( (LogicalOperation) operation ).getArguments();
098 for ( int i = 0; i < arguments.size(); i++ ) {
099 Operation op = arguments.get( i );
100 filter = extractInstanceFilter( op, foundFilters );
101 if ( filter != null ) {
102 // foundFilters.add( filter );
103 }
104 /*
105 * if ( op.getOperatorId() == OperationDefines.PROPERTYISEQUALTO ) { PropertyName pn = (PropertyName) (
106 * (PropertyIsCOMPOperation) op ).getFirstExpression(); if ( PROPERTY_INSTANCEFILTER.equals(
107 * pn.getValue().getAsString() ) ) { Literal literal = (Literal) ( (PropertyIsCOMPOperation) op
108 * ).getSecondExpression(); StringReader sr = new StringReader( literal.getValue() ); XMLFragment xml =
109 * new XMLFragment( sr, XMLFragment.DEFAULT_URL ); filter = (ComplexFilter) AbstractFilter.buildFromDOM(
110 * xml.getRootElement() ); } }
111 */
112 }
113 } else {
114 if ( operation.getOperatorId() == OperationDefines.PROPERTYISEQUALTO ) {
115 PropertyName pn = (PropertyName) ( (PropertyIsCOMPOperation) operation ).getFirstExpression();
116 if ( PROPERTY_INSTANCEFILTER.equals( pn.getValue().getAsString() ) ) {
117 Literal literal = (Literal) ( (PropertyIsCOMPOperation) operation ).getSecondExpression();
118 StringReader sr = new StringReader( literal.getValue() );
119 XMLFragment xml = new XMLFragment( sr, XMLFragment.DEFAULT_URL );
120 filter = (ComplexFilter) AbstractFilter.buildFromDOM( xml.getRootElement() );
121 if ( filter != null ) {
122 foundFilters.add( filter );
123 }
124 }
125 }
126 }
127 return filter;
128 }
129
130 }