001 //$HeadURL$
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
038 package org.deegree.security.owsrequestvalidator.csw;
039
040 import java.io.IOException;
041 import java.io.StringReader;
042 import java.util.List;
043
044 import org.deegree.framework.xml.XMLFragment;
045 import org.deegree.model.filterencoding.AbstractFilter;
046 import org.deegree.model.filterencoding.ComplexFilter;
047 import org.deegree.model.filterencoding.FilterConstructionException;
048 import org.deegree.model.filterencoding.Literal;
049 import org.deegree.model.filterencoding.LogicalOperation;
050 import org.deegree.model.filterencoding.Operation;
051 import org.deegree.model.filterencoding.OperationDefines;
052 import org.deegree.model.filterencoding.PropertyIsCOMPOperation;
053 import org.deegree.model.filterencoding.PropertyName;
054 import org.deegree.security.owsrequestvalidator.Policy;
055 import org.deegree.security.owsrequestvalidator.ResponseValidator;
056 import org.xml.sax.SAXException;
057
058 /**
059 *
060 *
061 * @author <a href="mailto:poth@lat-lon.de">Andreas Poth</a>
062 * @author last edited by: $Author: poth $
063 *
064 * @version $Revision: 6251 $, $Date: 2007-03-19 16:59:28 +0100 (Mo, 19 Mrz 2007) $
065 */
066 abstract class AbstractCSWResponseValidator extends ResponseValidator {
067
068 private static final String PROPERTY_INSTANCEFILTER = "instanceFilter";
069
070 /**
071 *
072 * @param policy
073 */
074 public AbstractCSWResponseValidator( Policy policy ) {
075 super( policy );
076 }
077
078 /**
079 *
080 * @param operation
081 * @return the extracted filter
082 * @throws IOException
083 * @throws SAXException
084 * @throws FilterConstructionException
085 */
086 protected ComplexFilter extractInstanceFilter( Operation operation, List<ComplexFilter> foundFilters )
087 throws SAXException, IOException, FilterConstructionException {
088 ComplexFilter filter = null;
089 if ( operation.getOperatorId() == OperationDefines.AND || operation.getOperatorId() == OperationDefines.OR ) {
090 List<Operation> arguments = ( (LogicalOperation) operation ).getArguments();
091 for ( int i = 0; i < arguments.size(); i++ ) {
092 Operation op = arguments.get( i );
093 filter = extractInstanceFilter( op, foundFilters );
094 if ( filter != null ) {
095 // foundFilters.add( filter );
096 }
097 /*
098 * if ( op.getOperatorId() == OperationDefines.PROPERTYISEQUALTO ) { PropertyName pn = (PropertyName) (
099 * (PropertyIsCOMPOperation) op ).getFirstExpression(); if ( PROPERTY_INSTANCEFILTER.equals(
100 * pn.getValue().getAsString() ) ) { Literal literal = (Literal) ( (PropertyIsCOMPOperation) op
101 * ).getSecondExpression(); StringReader sr = new StringReader( literal.getValue() ); XMLFragment xml =
102 * new XMLFragment( sr, XMLFragment.DEFAULT_URL ); filter = (ComplexFilter) AbstractFilter.buildFromDOM(
103 * xml.getRootElement() ); } }
104 */
105 }
106 } else {
107 if ( operation.getOperatorId() == OperationDefines.PROPERTYISEQUALTO ) {
108 PropertyName pn = (PropertyName) ( (PropertyIsCOMPOperation) operation ).getFirstExpression();
109 if ( PROPERTY_INSTANCEFILTER.equals( pn.getValue().getAsString() ) ) {
110 Literal literal = (Literal) ( (PropertyIsCOMPOperation) operation ).getSecondExpression();
111 StringReader sr = new StringReader( literal.getValue() );
112 XMLFragment xml = new XMLFragment( sr, XMLFragment.DEFAULT_URL );
113 filter = (ComplexFilter) AbstractFilter.buildFromDOM( xml.getRootElement(), false );
114 if ( filter != null ) {
115 foundFilters.add( filter );
116 }
117 }
118 }
119 }
120 return filter;
121 }
122
123 }