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