Revision 1271

View differences:

org.gvsig.wfs.app/tags/org.gvsig.wfs.app-2.0.231/pom.xml
1
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
2
    <modelVersion>4.0.0</modelVersion>
3
    <artifactId>org.gvsig.wfs.app</artifactId>
4
    <packaging>pom</packaging>
5

  
6
    <name>${project.artifactId}</name>
7
    <description>Web Feature Service support</description>
8
    <version>2.0.231</version>
9

  
10
    <parent>
11
        <groupId>org.gvsig</groupId>
12
        <artifactId>org.gvsig.desktop</artifactId>
13
        <version>2.0.431</version>
14
    </parent>
15

  
16
    <url>https://devel.gvsig.org/redmine/projects/gvsig-wfs</url>
17

  
18
    <repositories>
19
        <repository>
20
            <id>gvsig-public-http-repository</id>
21
            <name>gvSIG maven public HTTP repository</name>
22
            <url>http://devel.gvsig.org/m2repo/j2se</url>
23
            <releases>
24
                <enabled>true</enabled>
25
                <updatePolicy>daily</updatePolicy>
26
                <checksumPolicy>warn</checksumPolicy>
27
            </releases>
28
            <snapshots>
29
                <enabled>true</enabled>
30
                <updatePolicy>daily</updatePolicy>
31
                <checksumPolicy>warn</checksumPolicy>
32
            </snapshots>
33
        </repository>
34
    </repositories>
35

  
36
    <scm>
37
        <connection>scm:svn:https://devel.gvsig.org/svn/gvsig-wfs/org.gvsig.wfs.app/tags/org.gvsig.wfs.app-2.0.231</connection>
38
        <developerConnection>scm:svn:https://devel.gvsig.org/svn/gvsig-wfs/org.gvsig.wfs.app/tags/org.gvsig.wfs.app-2.0.231</developerConnection>
39
        <url>scm:svn:https://devel.gvsig.org/svn/gvsig-wfs/org.gvsig.wfs.app/tags/org.gvsig.wfs.app-2.0.231</url>
40
    </scm>
41

  
42
    <build>
43
        <plugins>
44
            <plugin>
45
                <groupId>org.apache.maven.plugins</groupId>
46
                <artifactId>maven-release-plugin</artifactId>
47
                <configuration>
48
                    <tagBase>https://devel.gvsig.org/svn/gvsig-wfs/org.gvsig.wfs.app/tags</tagBase>
49
                </configuration>
50
            </plugin>
51
        </plugins>
52
    </build>
53
   
54
    <properties>
55
        <org.gvsig.gpe.version>2.1.241</org.gvsig.gpe.version>
56
        <org.gvsig.xmlschema.version>2.0.43</org.gvsig.xmlschema.version>
57
    </properties>  
58
    
59
    <dependencyManagement>
60
        <dependencies>
61
            <!-- Childs -->
62
            <dependency>
63
                <groupId>org.gvsig</groupId>
64
                <artifactId>org.gvsig.wfs.app.mainplugin</artifactId>
65
                <version>2.0.231</version>
66
            </dependency>
67
                                 
68
            <!-- Extern libraries -->
69
            
70
            <!-- gvSIG extern libraries -->
71
            <dependency>
72
                <groupId>org.gvsig</groupId>
73
                <artifactId>org.gvsig.gpe</artifactId>
74
                <version>${org.gvsig.gpe.version}</version>
75
                <type>pom</type>
76
                <scope>import</scope>
77
                <exclusions>
78
                    <exclusion> 
79
                        <groupId>org.gvsig</groupId>
80
                        <artifactId>org.gvsig.tools.*</artifactId>
81
                    </exclusion>
82
                </exclusions> 
83
            </dependency>
84
            <dependency>
85
                <!-- Para proximas versiones de GPE, >2.1.80, quitar esta dependencia -->
86
                <groupId>org.gvsig</groupId>
87
                <artifactId>org.gvsig.gpe.app.mainplugin</artifactId>
88
                <version>${org.gvsig.gpe.version}</version>
89
            </dependency>
90
            <dependency>
91
                <groupId>org.gvsig</groupId>
92
                <artifactId>org.gvsig.xmlschema</artifactId>
93
                <version>${org.gvsig.xmlschema.version}</version>
94
                <type>pom</type>
95
                <scope>import</scope>
96
                <exclusions>
97
                    <exclusion> 
98
                        <groupId>org.gvsig</groupId>
99
                        <artifactId>org.gvsig.tools.*</artifactId>
100
                    </exclusion>
101
                </exclusions> 
102
            </dependency>
103
            
104
        </dependencies>
105
    </dependencyManagement>
106

  
107
    <modules>
108
        <module>org.gvsig.wfs.app.mainplugin</module>
109
    </modules>
110

  
111
</project>
org.gvsig.wfs.app/tags/org.gvsig.wfs.app-2.0.231/org.gvsig.wfs.app.mainplugin/src/main/assembly/gvsig-plugin-package.xml
1
<assembly>
2
  <id>gvsig-plugin-package</id>
3
  <formats>
4
    <format>zip</format>
5
  </formats>
6
  <baseDirectory>${project.artifactId}</baseDirectory>
7
  <includeBaseDirectory>true</includeBaseDirectory>
8
  <files>
9
    <file>
10
      <source>target/${project.artifactId}-${project.version}.jar</source>
11
      <outputDirectory>lib</outputDirectory>
12
    </file>
13
    <file>
14
      <source>target/package.info</source>
15
    </file>
16
  </files>
17

  
18
  <fileSets>
19
    <fileSet>
20
      <directory>src/main/resources-plugin</directory>
21
      <outputDirectory>.</outputDirectory>
22
    </fileSet>
23
  </fileSets>
24

  
25
<!--
26
  <dependencySets>
27
    <dependencySet>
28
      <useProjectArtifact>false</useProjectArtifact>
29
      <useTransitiveDependencies>false</useTransitiveDependencies>
30
      <outputDirectory>lib</outputDirectory>
31
      <includes>
32
        <include>org.gvsig:org.gvsig.wfs.app.mainplugin</include>
33
      </includes>
34
    </dependencySet>
35
  </dependencySets>
36
-->
37

  
38
</assembly>
org.gvsig.wfs.app/tags/org.gvsig.wfs.app-2.0.231/org.gvsig.wfs.app.mainplugin/src/main/java/org/gvsig/remoteclient/wfs/filters/AbstractFilter.java
1
/**
2
 * gvSIG. Desktop Geographic Information System.
3
 *
4
 * Copyright (C) 2007-2013 gvSIG Association.
5
 *
6
 * This program is free software; you can redistribute it and/or
7
 * modify it under the terms of the GNU General Public License
8
 * as published by the Free Software Foundation; either version 3
9
 * of the License, or (at your option) any later version.
10
 *
11
 * This program is distributed in the hope that it will be useful,
12
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14
 * GNU General Public License for more details.
15
 *
16
 * You should have received a copy of the GNU General Public License
17
 * along with this program; if not, write to the Free Software
18
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
19
 * MA  02110-1301, USA.
20
 *
21
 * For any additional information, do not hesitate to contact us
22
 * at info AT gvsig.com, or visit our website www.gvsig.com.
23
 */
24

  
25
package org.gvsig.remoteclient.wfs.filters;
26
import java.io.ByteArrayInputStream;
27
import java.util.ArrayList;
28
import java.util.Iterator;
29
import java.util.StringTokenizer;
30
import java.util.Vector;
31

  
32
import org.gvsig.fmap.geom.Geometry;
33
import org.gvsig.fmap.geom.primitive.Envelope;
34
import org.gvsig.remoteclient.wfs.filters.operations.WFSEnvelopeFilterOperation;
35
import org.gvsig.remoteclient.wfs.filters.operations.WFSGeometryFilterOperation;
36
import org.gvsig.remoteclient.wfs.filters.operations.WFSSpatialFilterOperation;
37

  
38
/**
39
 * All classes that implement a "Query Language" must to inherit of 
40
 * this class
41
 * 
42
 * @author Jorge Piera Llodra (piera_jor@gva.es)
43
 */
44
public abstract class AbstractFilter implements Filter {
45
	private BinaryTree root;
46
	private String currentClause;
47
	private ISQLExpressionFormat formatter;
48
	private ArrayList spatialFilterOperations;
49
	private ArrayList ids = null;	
50

  
51
	public AbstractFilter(ISQLExpressionFormat formatter){
52
		root = new BinaryTree();	
53
		this.formatter = formatter;
54
		spatialFilterOperations = new ArrayList();
55
	}
56
	
57
	/**
58
	 * It returns the Query like a String
59
	 */
60
	public abstract String toString(BinaryTree tree, String version);
61
	
62
	/**
63
	 * returns the String that represents the logic
64
	 * operator in this query language
65
	 * @param operator
66
	 * Logic operator
67
	 * @return
68
	 */
69
	public abstract String getLogicalOperator(int operator);
70

  
71
	/**
72
	 * returns the String that represents the relational
73
	 * operator in this query language
74
	 * @param operator
75
	 * Logic operator
76
	 * @return
77
	 */
78
	public abstract String getRelationalOperator(int operator);
79

  
80
	/**
81
	 * returns the String that represents the geometric
82
	 * operator in this query language
83
	 * @param operator
84
	 * Logic operator
85
	 * @return
86
	 */
87
	public abstract String getGeometricOperator(int operator);
88

  
89
	/**
90
	 * returns the String that represents the separator
91
	 * operator in this query language
92
	 * @param separator
93
	 * LSeparator "(" or ")" 
94
	 * @return
95
	 */
96
	public abstract String getSeparator(int separator);
97

  
98
	/**
99
	 * Adds a feature id
100
	 * @param id
101
	 * The feature id
102
	 */
103
	public void addFeatureById(Object id){
104
		if (ids == null){
105
			ids = new ArrayList();
106
		}
107
		ids.add(id);
108
	}
109

  
110
	/**
111
	 * @return the ids
112
	 */
113
	protected ArrayList getIds() {
114
		return ids;
115
	}
116

  
117
	public void setQueryByAttribute(String query){
118
		if (query != null){			
119
			ByteArrayInputStream is = new ByteArrayInputStream(query.getBytes());
120
			String sql = formatter.format(query);
121
			if (sql != null){
122
				ParseExpressions expressions = new ParseExpressions();
123
				ArrayList tokens = expressions.parseExpression(sql);
124

  
125
				for (int i=0 ; i<tokens.size() ; i++){
126
					String token = (String)tokens.get(i);
127
					root.addTerm(token);				
128
				}			
129
			}	
130
		}
131
	}
132

  
133
	/**
134
	 * It adds a new property and value using the AND
135
	 * operation 
136
	 * @param propertyName
137
	 * @param propertyValue
138
	 */
139
	public void addAndClause(String propertyName, String propertyValue){
140
		root.addTerm(propertyName + " = " + propertyValue,
141
				getLogicalOperator(LOGICAL_OPERATOR_AND));
142
	}
143

  
144
	public int getSpatialFiltersCount(){
145
		return spatialFilterOperations.size();
146
	}
147

  
148
	public WFSSpatialFilterOperation getSpatialFilterAt(int index){
149
		if (index < spatialFilterOperations.size()){
150
			return (WFSSpatialFilterOperation)spatialFilterOperations.get(index);
151
		}
152
		return null;
153
	}
154

  
155
	public void clearSpatialFilters(){
156
		spatialFilterOperations.clear();
157
	}
158
	
159
	public void addSpatialFilter(WFSSpatialFilterOperation spatialOperation){
160
		if (spatialOperation != null){
161
		    spatialFilterOperations.add(spatialOperation);
162
		}
163
	}
164

  
165
	public void addSpatialFilter(Geometry geometry,String attributeName, String nameSpacePrefix, String nameSpaceLocation, String srs, int operation) {
166
		addSpatialFilter(new WFSGeometryFilterOperation(geometry, operation, attributeName, nameSpacePrefix, nameSpaceLocation, srs));
167
	}
168
	
169
	public void addSpatialFilter(String version, Envelope envelope, String attributeName, String nameSpacePrefix, String nameSpaceLocation, String srs, int operation) {
170
		addSpatialFilter(new WFSEnvelopeFilterOperation(envelope, operation, attributeName, nameSpacePrefix, nameSpaceLocation, srs));
171
	}
172

  
173
	public void addClause(String value){
174
		if (currentClause == null){
175
			currentClause = new String("");
176
		}
177
		currentClause = currentClause + value;
178
	}
179

  
180
	public String toString(String version){
181
		if (currentClause != null){
182
			setQueryByAttribute(currentClause);
183
		}
184
		return toString(root, version);
185
	}	
186

  
187
	/**
188
	 * Return true if the token is a operator
189
	 * @param operator
190
	 * @return
191
	 */
192
	public String getOperator(int operator){
193
		if (isLogical(operator)){
194
			return getLogicalOperator(operator);
195
		}else if(isRelational(operator)){
196
			return getRelationalOperator(operator);
197
		}else if(isGeometric(operator)){
198
			return getGeometricOperator(operator);
199
		}
200
		return String.valueOf(operator);
201
	}	
202

  
203
	public int getRelationalOperator(String operator){
204
		if (operator.equals("=")){
205
			return RELATIONAL_OPERATOR_IS_EQUALS_TO;
206
		}else if(operator.equals("!=")){
207
			return RELATIONAL_OPERATOR_IS_NOT_EQUALS_TO;
208
		}else if(operator.equals("<>")){ // This is another way to tell not-equal
209
			return RELATIONAL_OPERATOR_IS_NOT_EQUALS_TO;
210
		}else if(operator.equals(">")){
211
			return RELATIONAL_OPERATOR_IS_GREATER_THAN;
212
		}else if(operator.equals(">=")){
213
			return RELATIONAL_OPERATOR_IS_GREATER_THAN_OR_EQUAL_TO;
214
		}else if(operator.equals("<")){
215
			return RELATIONAL_OPERATOR_IS_LESS_THAN;
216
		}else if(operator.equals("<=")){
217
			return RELATIONAL_OPERATOR_IS_LESS_THAN_OR_EQUAL_TO;
218
		}else if(operator.toUpperCase().equals("LIKE")){
219
			return RELATIONAL_OPERATOR_IS_LIKE;
220
		}
221
		return RELATIONAL_OPERATOR_IS_EQUALS_TO;
222
	}
223

  
224
	public int getLogicalOperator(String operator){
225
		if (operator.toUpperCase().equals("AND")){
226
			return LOGICAL_OPERATOR_AND;
227
		}else if(operator.toUpperCase().equals("NOT")){
228
			return LOGICAL_OPERATOR_NOT;
229
		}else if(operator.toUpperCase().equals("OR")){
230
			return LOGICAL_OPERATOR_OR;
231
		}
232
		return LOGICAL_OPERATOR_AND;
233
	}
234

  
235
	/**
236
	 * Return true if is a geometric operator
237
	 * @param type
238
	 * @return
239
	 */
240
	private boolean isGeometric(int type) {
241
		if ((type > 19) && (type < 40)){
242
			return true;
243
		}
244
		return false;
245
	}
246

  
247
	/**
248
	 * Return true if is a relational operator
249
	 * @param type
250
	 * @return
251
	 */
252
	private boolean isRelational(int type) {
253
		if ((type > 39) && (type < 60)){
254
			return true;
255
		}
256
		return false;
257
	}
258

  
259
	/**
260
	 * Return true if is a logical operator
261
	 * @param type
262
	 * @return
263
	 */
264
	private boolean isLogical(int type){
265
		if ((type > 9) && (type < 20)){
266
			return true;
267
		}
268
		return false;
269
	}
270

  
271

  
272

  
273
	/**
274
	 * Return true if is a seperator
275
	 * @param type
276
	 * @return
277
	 */
278
	private boolean isSeparator(int type){
279
		if ((type > 59) && (type < 70)){
280
			return true;
281
		}
282
		return false;
283
	}      
284

  
285
	/**
286
	 * Divide a line in a set of words
287
	 * @param line
288
	 * Line to divide
289
	 * @param option
290
	 * If the option is EXACT it returns the same line 
291
	 * @return Iteraror
292
	 * A set of words
293
	 */
294
	public Iterator parseValues(String line, int option) {        
295
		Vector values = new Vector();
296

  
297
		if (option == CONCORDANCIA_EXACT) {
298
			values.add(line);
299
			return values.iterator();
300
		}
301

  
302
		StringTokenizer doubleQuotesTokenizer = new StringTokenizer(line, "\"",
303
				true);
304
		boolean inside = false;
305
		while (doubleQuotesTokenizer.hasMoreTokens()) {
306
			String token = doubleQuotesTokenizer.nextToken();
307
			if (token.equals("\"")) {
308
				inside = !inside;
309
			} else if (inside) {
310
				values.add(token);
311
			} else {
312
				StringTokenizer spaceTokenizer = new StringTokenizer(token, " ");
313
				while (spaceTokenizer.hasMoreTokens()) {
314
					String value = spaceTokenizer.nextToken();
315
					values.add(value);
316
				}
317
			}
318
		}
319
		return values.iterator();
320
	} 
321
}
org.gvsig.wfs.app/tags/org.gvsig.wfs.app-2.0.231/org.gvsig.wfs.app.mainplugin/src/main/java/org/gvsig/remoteclient/wfs/filters/filterencoding/FilterEncoding.java
1
/**
2
 * gvSIG. Desktop Geographic Information System.
3
 *
4
 * Copyright (C) 2007-2013 gvSIG Association.
5
 *
6
 * This program is free software; you can redistribute it and/or
7
 * modify it under the terms of the GNU General Public License
8
 * as published by the Free Software Foundation; either version 3
9
 * of the License, or (at your option) any later version.
10
 *
11
 * This program is distributed in the hope that it will be useful,
12
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14
 * GNU General Public License for more details.
15
 *
16
 * You should have received a copy of the GNU General Public License
17
 * along with this program; if not, write to the Free Software
18
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
19
 * MA  02110-1301, USA.
20
 *
21
 * For any additional information, do not hesitate to contact us
22
 * at info AT gvsig.com, or visit our website www.gvsig.com.
23
 */
24

  
25
package org.gvsig.remoteclient.wfs.filters.filterencoding;
26
import java.util.ArrayList;
27
import java.util.Hashtable;
28
import java.util.Iterator;
29
import java.util.Set;
30

  
31
import org.gvsig.compat.CompatLocator;
32
import org.gvsig.compat.lang.StringUtils;
33
import org.gvsig.remoteclient.wfs.WFSStatus;
34
import org.gvsig.remoteclient.wfs.edition.WFSTTags;
35
import org.gvsig.remoteclient.wfs.filters.AbstractFilter;
36
import org.gvsig.remoteclient.wfs.filters.BinaryTree;
37
import org.gvsig.remoteclient.wfs.filters.BinaryTree.Node;
38
import org.gvsig.remoteclient.wfs.filters.DefaultSQLExpressionFormat;
39
import org.gvsig.remoteclient.wfs.filters.ISQLExpressionFormat;
40
import org.gvsig.remoteclient.wfs.filters.filterencoding.wfs_1_0_0.EnvelopeFEQuery1_0_0;
41
import org.gvsig.remoteclient.wfs.filters.filterencoding.wfs_1_0_0.GeometryFEQuery_1_0_0;
42
import org.gvsig.remoteclient.wfs.filters.filterencoding.wfs_1_1_0.EnvelopeFEQuery1_1_0;
43
import org.gvsig.remoteclient.wfs.filters.filterencoding.wfs_1_1_0.GeometryFEQuery_1_1_0;
44
import org.gvsig.remoteclient.wfs.filters.operations.WFSEnvelopeFilterOperation;
45
import org.gvsig.remoteclient.wfs.filters.operations.WFSGeometryFilterOperation;
46
import org.gvsig.remoteclient.wfs.filters.operations.WFSSpatialFilterOperation;
47

  
48
/**
49
 * This class implements the Filter Encoding Language. It is used to
50
 * create querys in this language
51
 *
52
 * Name: OpenGIS? Filter Encoding Implementation Specification
53
 * Version: 1.1.0
54
 * Project Document: OGC 04-095
55
 * @see http://portal.opengeospatial.org/files/?artifact_id=8340
56
 *
57
 * @author Jorge Piera Llodra (piera_jor@gva.es)
58
 */
59
public class FilterEncoding extends AbstractFilter {
60
    public static final int RELATIONSHIP_PROPERTY = 0;
61
    public static final int RELATIONSHIP_VAUES = 1;
62

  
63
    private StringBuffer currentQuery = null;
64
    //Operation types
65
    private static final int OPERATION_PROPERTYNAME = 0;
66
    private static final int OPERATION_LITERAL = 1;
67

  
68
    //Filter namespace.
69
    private String nameSpacePrefix = null;
70
    private String nameSpaceLocation = null;
71

  
72
    //If the Filter can have blanckSpaces
73
    private boolean hasBlankSpaces = true;
74
    private String defaultBlankSpace = "%20";
75
    //This character must be replaced by any set of characters (typically "*")
76
    private String wildCardChar = null;
77
    //This character must be replaced by one character (typically "?")
78
    private String singleChar = null;
79
    //Escape character (typically "\")
80
    private String escapeChar = null;
81
    //Default values
82
    public static final String DEFAULT_NAMESPACE_PREFIX = "ogc";
83
    public static final String DEFAULT_WILDCARD = "*";
84
    public static final String DEFAULT_SINGLECHAR = "?";
85
    public static final String DEFAULT_ESCAPE = "\\";
86
    public static final String DEFAULT_NAMESPACE = "xmlns:ogc=\"http://www.opengis.net/ogc\"";
87

  
88
    private Hashtable filterAttributes = new Hashtable();
89

  
90
    /**
91
     * If the namespace XML is qualified
92
     */
93
    private boolean isQualified = false;
94

  
95
    private static final StringUtils stringUtils = CompatLocator.getStringUtils();
96

  
97
    /**
98
     * Create a new Filter Encoding Parser
99
     *
100
     *
101
     * @param nameSpacePrefix
102
     * Filter namespace. (typically "ogc")
103
     * @param wildCardChar
104
     * This character must be replaced by any set of characters (typically "*")
105
     * @param singleChar
106
     * This character must be replaced by one character (typically "?")
107
     * @param escape
108
     * Escape character
109
     * @param filterAttribute Sometimes, "Field" label needs an attribute.
110
     */
111
    public FilterEncoding(ISQLExpressionFormat formatter,String namesPacePrefix, String wildCard, String singleChar, String escape, Hashtable filterAttributes) {
112
        super(formatter);
113
        if (namesPacePrefix == null){
114
            setQualified(false);
115
        }else{
116
            setQualified(true);
117
        }
118
        this.wildCardChar = wildCard;
119
        this.singleChar = singleChar;
120
        this.escapeChar = escape;
121
        this.filterAttributes = filterAttributes;
122
    }
123

  
124

  
125
    /**
126
     * Create a new Filter Encoding Parser
127
     * @param formatter
128
     */
129
    public FilterEncoding(ISQLExpressionFormat formatter) {
130
        this(formatter,null,DEFAULT_WILDCARD,DEFAULT_SINGLECHAR,
131
            DEFAULT_ESCAPE,new Hashtable());
132
    }
133

  
134
    /**
135
     * Create a new Filter Encoding Parser
136
     */
137
    FilterEncoding() {
138
        this(new DefaultSQLExpressionFormat());
139
    }
140

  
141
    /**
142
     * Create a new Filter Encoding Parser
143
     */
144
    public FilterEncoding(WFSStatus status) {
145
        this();
146
        this.nameSpacePrefix = status.getNamespacePrefix();
147
        this.nameSpaceLocation = status.getNamespaceLocation();
148
        setQueryByAttribute(status.getFilterByAttribute());
149
        clearSpatialFilters();
150
        addSpatialFilter(status.getFilterByArea());
151
    }
152

  
153
    /*
154
     *  (non-Javadoc)
155
     * @see org.gvsig.remoteClient.filterEncoding.QueryLanguage#toString(org.gvsig.remoteClient.filterEncoding.BinaryTree)
156
     */
157
    public String toString(BinaryTree tree, String version) {
158
        //If is a filter by ids...
159
        StringBuffer idQuery = null;
160
        if (getIds() != null){
161
            idQuery = new StringBuffer();
162
            ArrayList ids = getIds();
163
            for (int i=0 ; i<ids.size() ; i++){
164
                if (ids.get(i) != null){
165
                    Hashtable attributes = new Hashtable();
166
                    attributes.put("fid","\"" + ids.get(i).toString() + "\"");
167
                    idQuery.append(setTag("FeatureId", attributes, null));
168
                }
169
            }
170
            return enclosesWithFilterTag(idQuery.toString(), version);
171
        }
172
        //If is a filter by attributes...
173
        String filterQuery = null;
174
        if ((tree.getRoot() == null) && (getSpatialFiltersCount() == 0)){
175
            return null;
176
        }
177
        if (tree.getRoot() != null){
178
            currentQuery = new StringBuffer();
179
            filterQuery = getFilterNode(tree.getRoot());
180
            if (getSpatialFiltersCount() == 0){
181
                return enclosesWithFilterTag(filterQuery, version);
182
            }
183
        }
184
        //If is a filter by area
185
        String bboxQuery = null;
186
        if (getSpatialFiltersCount() > 0){
187
            for (int i=0 ; i<getSpatialFiltersCount() ; i++){
188
                WFSSpatialFilterOperation spatialFilter = getSpatialFilterAt(i);
189
                SpatialFEQuery feQuery = null;
190
                if (spatialFilter instanceof WFSGeometryFilterOperation){
191
                    if (version.equals("1.0.0")){
192
                    	feQuery = new GeometryFEQuery_1_0_0((WFSGeometryFilterOperation)spatialFilter);
193
                    }else{
194
                        feQuery = new GeometryFEQuery_1_1_0((WFSGeometryFilterOperation)spatialFilter);
195
                    }
196
                }else if (spatialFilter instanceof WFSEnvelopeFilterOperation){
197
                    //TODO add this for a manager
198
                    if (version.equals("1.0.0")){
199
                        feQuery = new EnvelopeFEQuery1_0_0((WFSEnvelopeFilterOperation)spatialFilter);
200
                    }else{
201
                        feQuery = new EnvelopeFEQuery1_1_0((WFSEnvelopeFilterOperation)spatialFilter);
202
                    }
203
                }
204
                //If there is a spatial query
205
                if (feQuery != null){
206
                    bboxQuery = feQuery.getFilterEncoding();
207
                    if (tree.getRoot() == null){
208
                        String filter_bbox = enclosesWithFilterTag(bboxQuery, version);
209
                        return filter_bbox;
210
                    }
211
                }
212
            }
213
        }
214
        return enclosesWithFilterTag(filterQuery + bboxQuery, version);
215
    }
216

  
217
    /**
218
     * Gets the filter code from a node
219
     * @param node
220
     */
221
    private String getFilterNode(Node node){
222
        if (node.isField()){
223
            return getExpression(node.getValue());
224
        }else{
225
            String left = "";
226
            String rigth = "";
227
            if (node.getLeftNode() != null){
228
                left = getFilterNode(node.getLeftNode());
229
            }
230
            if (node.getRigthNode() != null){
231
                rigth = getFilterNode(node.getRigthNode());
232
            }
233
            int operationCode = getLogicalOperator(node.getValue());
234
            String operation = getLogicalOperator(operationCode);
235
            return enterLabel(left+rigth, operation);
236
        }
237
    }
238

  
239
    /**
240
     * Parses a expresion like 'A op B' and returns the
241
     * expresion using the filter encoding language
242
     * @param expression
243
     * @return
244
     */
245
    private String getExpression(String expression){
246
        String[] words = stringUtils.split(expression, " ");
247
        //Param
248
        String param = words[0];
249
        if (param.charAt(0) == '"'){
250
            param = param.substring(1,param.length());
251
        }
252
        if (param.charAt(param.length()-1) == '"'){
253
            param = param.substring(0,param.length()-1);
254
        }
255
        //Operator
256
        String operator = words[1];
257
        //Value
258
        String value = words[2];
259
        for (int i=3 ; i<words.length ; i++){
260
            value = value + " " + words[i];
261
        }
262
        if (value.charAt(0) == '\''){
263
            value = value.substring(1,value.length());
264
        }
265
        if (value.charAt(value.length()-1) == '\''){
266
            value = value.substring(0,value.length()-1);
267
        }
268
        int operatorCode = getRelationalOperator(operator);
269
        operator = getRelationalOperator(operatorCode);
270
        return createExpression(operator,param,value);
271
    }
272

  
273
    /**
274
     * It writes a "PropertyIsXXX" part of a filtyer encoding query
275
     *
276
     *
277
     * @return The part of the query
278
     * @param property Possible Values: PropertIsLike, PropertyIsLess, PropertyIsGreater,... See
279
     * the Filter Encoding documentation
280
     * @param parameter Parameter name
281
     * @param value Parameter value
282
     * @param type Values: "P" (to comparate two propertyes) or "L" (to comparate one property
283
     * and one literal value)
284
     */
285
    private String createExpression(String property, String parameter, String value) {
286
        String cadena = "";
287
        cadena = "<" + WFSTTags.OGC_NAMESPACE_PREFIX + ":" + property;
288
        if (property.equals("PropertyIsLike")) {
289
            if (wildCardChar != null) {
290
                cadena = cadena + " wildCard=\"" + this.wildCardChar + "\"";
291
            }
292
            if (singleChar != null) {
293
                cadena = cadena + " singleChar=\"" + this.singleChar + "\"";
294
            }
295
            if (escapeChar != null) {
296
                cadena = cadena + " escape=\"" + this.escapeChar + "\"";
297
            }
298
        }
299
        cadena = cadena + ">" + enterLabel(nameSpacePrefix + ":" + parameter, "PropertyName");
300
        cadena = cadena + enterLabel(value, "Literal");
301
        return cadena + "</" + WFSTTags.OGC_NAMESPACE_PREFIX + ":" + property + ">";
302
    }
303

  
304
    /**
305
     * Envuelve a una pregunta con una etiqueta
306
     *
307
     *
308
     * @return String : parte de la query en el lenguaje soportado
309
     * @param pregunta Pregunta a envolver
310
     * @param etiqueta Nombre de la etiqueta
311
     */
312
    private String enterLabel(String value, String tagName) {
313
        if (tagName.equals("Filter") && (!(filterAttributes.isEmpty()))) {
314
            return setTag(tagName,filterAttributes,value);
315
        } else {
316
            return setTag(tagName,null,value);
317
        }
318
    }
319

  
320
    /**
321
     * Envolves a value with an XML tag
322
     *
323
     * @return String
324
     * XML tag with its value
325
     * @param tagName
326
     * XML tag name
327
     * @param attributes
328
     * XML tag attributes
329
     * @param value
330
     * Tag value
331
     */
332
    public String setTag(String tagName, Hashtable attributes, String value) {
333
        StringBuffer tag = new StringBuffer();
334

  
335
        tag.append("<");
336
        tag.append(WFSTTags.OGC_NAMESPACE_PREFIX + ":");
337
        tag.append(tagName);
338
        if (attributes != null){
339
            Set keys = attributes.keySet();
340
            if (attributes.size() > 0){
341
                Iterator it = keys.iterator();
342
                while (it.hasNext()){
343
                    String key = (String)it.next();
344
                    if (hasBlankSpaces){
345
                        tag.append(" ");
346
                    }else{
347
                        tag.append(defaultBlankSpace);
348
                    }
349
                    tag.append(key + "=" + (String)attributes.get(key));
350

  
351
                }
352
            }
353
        }
354
        if (value == null){
355
            tag.append("/>");
356
        }else{
357
            tag.append(">" + value);
358
            tag.append("</");
359
            tag.append(WFSTTags.OGC_NAMESPACE_PREFIX + ":");
360
            tag.append(tagName);
361
            tag.append(">");
362
        }
363
        return tag.toString();
364
    }
365

  
366

  
367
    /**
368
     * Encloses a query with the filter tag
369
     * @param query
370
     * @return
371
     */
372
    private String enclosesWithFilterTag(String query, String version){
373
        StringBuffer filter = new StringBuffer();
374
        filter.append("<ogc:Filter");
375
        if (!isQualified){
376
            filter.append(" ");
377
            addNamespace(filter, WFSTTags.OGC_NAMESPACE_PREFIX, WFSTTags.OGC_NAMESPACE);
378
            addNamespace(filter, WFSTTags.GML_NAMESPACE_PREFIX, WFSTTags.GML_NAMESPACE);
379
            if (nameSpacePrefix != null){
380
                addNamespace(filter, nameSpacePrefix, nameSpaceLocation);
381
            }
382
            filter.append("xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" ");
383
            filter.append("xsi:schemaLocation=\"http://www.opengis.net/ogc ../filter/".concat(version).concat("/filter.xsd http://www.opengis.net/gml ../gml/2.1.2/geometry.xsd\""));
384
        }
385
        filter.append(">");
386
        filter.append(query);
387
        filter.append("</ogc:Filter>");
388
        return filter.toString();
389
    }
390

  
391
    private void addNamespace(StringBuffer buffer, String nameSpacePrefix, String nameSpaceLocation){
392
        buffer.append(WFSTTags.XMLNS + ":" + nameSpacePrefix + "=\"" + nameSpaceLocation + "\" ");
393
    }
394

  
395
    /*
396
     *  (non-Javadoc)
397
     * @see org.gvsig.remoteClient.filterEncoding.AQueryLanguage#getLogicOperator(int)
398
     */
399
    public String getLogicalOperator(int operator) {
400
        switch (operator){
401
        case LOGICAL_OPERATOR_AND:
402
            return "And";
403
        case LOGICAL_OPERATOR_OR:
404
            return "Or";
405
        case LOGICAL_OPERATOR_NOT:
406
            return "Not";
407
        default:
408
            return "And";
409
        }
410
    }
411

  
412
    /*
413
     *  (non-Javadoc)
414
     * @see org.gvsig.remoteClient.filterEncoding.AQueryLanguage#getRelationalOperator(int)
415
     */
416
    public String getRelationalOperator(int operator) {
417
        switch (operator){
418
        case RELATIONAL_OPERATOR_IS_EQUALS_TO:
419
            return "PropertyIsEqualTo";
420
        case RELATIONAL_OPERATOR_IS_NOT_EQUALS_TO:
421
            return "PropertyIsNotEqualTo";
422
        case RELATIONAL_OPERATOR_IS_LESS_THAN:
423
            return "PropertyIsLessThan";
424
        case RELATIONAL_OPERATOR_IS_GREATER_THAN:
425
            return "PropertyIsGreaterThan";
426
        case RELATIONAL_OPERATOR_IS_LESS_THAN_OR_EQUAL_TO:
427
            return "PropertyIsLessThanOrEqualTo";
428
        case RELATIONAL_OPERATOR_IS_GREATER_THAN_OR_EQUAL_TO:
429
            return "PropertyIsGreaterThanOrEqualTo";
430
        case RELATIONAL_OPERATOR_IS_LIKE:
431
            return "PropertyIsLike";
432
        case RELATIONAL_OPERATOR_IS_NULL:
433
            return "PropertyIsNull";
434
        case RELATIONAL_OPERATOR_IS_BETWEEN:
435
            return "PropertyIsBetween";
436
        default:
437
            return "PropertyIsLike";
438
        }
439
    }
440

  
441
    /*
442
     *  (non-Javadoc)
443
     * @see org.gvsig.remoteClient.filterEncoding.AQueryLanguage#getGeometricOperator(int)
444
     */
445
    public String getGeometricOperator(int operator) {
446
        switch (operator){
447
        case GEOMETRIC_OPERATOR_EQUALS:
448
            return "Equals";
449
        case GEOMETRIC_OPERATOR_DISJOINT:
450
            return "Disjoint";
451
        case GEOMETRIC_OPERATOR_TOUCHES:
452
            return "Touches";
453
        case GEOMETRIC_OPERATOR_WITHIN:
454
            return "Within";
455
        case GEOMETRIC_OPERATOR_OVERLAPS:
456
            return "Overlaps";
457
        case GEOMETRIC_OPERATOR_CROSSES:
458
            return "Crosses";
459
        case GEOMETRIC_OPERATOR_INTERSECT:
460
            return "Intersect";
461
        case GEOMETRIC_OPERATOR_CONTAINS:
462
            return "Contains";
463
        case GEOMETRIC_OPERATOR_DWITHIN:
464
            return "Dwithin";
465
        case GEOMETRIC_OPERATOR_BEYOND:
466
            return "Beyond";
467
        case GEOMETRIC_OPERATOR_BBOX:
468
            return "BBOX";
469
        default:
470
            return "Equals";
471
        }
472

  
473
    }
474

  
475
    public String getSeparator(int separator) {
476
        return null;
477
    }
478

  
479
    /**
480
     * @param isQualified the isQualified to set
481
     */
482
    public void setQualified(boolean isQualified) {
483
        this.isQualified = isQualified;
484
        if (isQualified){
485
            nameSpacePrefix = DEFAULT_NAMESPACE_PREFIX + ":";
486
        }else{
487
            nameSpacePrefix = "";
488
        }
489
    }
490

  
491

  
492
    /**
493
     * @param namepacePrefix the namepacePrefix to set
494
     */
495
    public void setNamepacePrefix(String namepacePrefix) {
496
        if ((namepacePrefix == null) || (namepacePrefix.equals(""))){
497
            this.nameSpacePrefix = "";
498
        }else{
499
            this.nameSpacePrefix = namepacePrefix + ":";
500
        }
501
    }
502

  
503

  
504
    /**
505
     * @param hasBlankSpaces the hasBlankSpaces to set
506
     */
507
    public void setHasBlankSpaces(boolean hasBlankSpaces) {
508
        this.hasBlankSpaces = hasBlankSpaces;
509
    }
510
}
org.gvsig.wfs.app/tags/org.gvsig.wfs.app-2.0.231/org.gvsig.wfs.app.mainplugin/src/main/java/org/gvsig/remoteclient/wfs/filters/filterencoding/GeometryFEQuery.java
1
/**
2
 * gvSIG. Desktop Geographic Information System.
3
 *
4
 * Copyright (C) 2007-2013 gvSIG Association.
5
 *
6
 * This program is free software; you can redistribute it and/or
7
 * modify it under the terms of the GNU General Public License
8
 * as published by the Free Software Foundation; either version 3
9
 * of the License, or (at your option) any later version.
10
 *
11
 * This program is distributed in the hope that it will be useful,
12
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14
 * GNU General Public License for more details.
15
 *
16
 * You should have received a copy of the GNU General Public License
17
 * along with this program; if not, write to the Free Software
18
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
19
 * MA  02110-1301, USA.
20
 *
21
 * For any additional information, do not hesitate to contact us
22
 * at info AT gvsig.com, or visit our website www.gvsig.com.
23
 */
24

  
25
package org.gvsig.remoteclient.wfs.filters.filterencoding;
26

  
27
import java.awt.geom.PathIterator;
28

  
29
import org.gvsig.fmap.geom.Geometry;
30
import org.gvsig.fmap.geom.Geometry.TYPES;
31
import org.gvsig.fmap.geom.primitive.GeneralPathX;
32
import org.gvsig.fmap.geom.primitive.Surface;
33
import org.gvsig.remoteclient.wfs.filters.operations.WFSGeometryFilterOperation;
34

  
35
/**
36
 * @author <a href="mailto:jpiera@gvsig.org">Jorge Piera</a>
37
 */
38
public abstract class GeometryFEQuery extends SpatialFEQuery{
39
	protected Geometry geometry = null;
40

  
41
	public GeometryFEQuery(WFSGeometryFilterOperation geometryOperation) {
42
		super(geometryOperation);
43
		this.geometry = geometryOperation.getGeometry();
44
	}
45

  
46

  
47

  
48
}
49

  
org.gvsig.wfs.app/tags/org.gvsig.wfs.app-2.0.231/org.gvsig.wfs.app.mainplugin/src/main/java/org/gvsig/remoteclient/wfs/filters/filterencoding/wfs_1_0_0/GeometryFEQuery_1_0_0.java
1
/**
2
 * gvSIG. Desktop Geographic Information System.
3
 *
4
 * Copyright (C) 2007-2013 gvSIG Association.
5
 *
6
 * This program is free software; you can redistribute it and/or
7
 * modify it under the terms of the GNU General Public License
8
 * as published by the Free Software Foundation; either version 3
9
 * of the License, or (at your option) any later version.
10
 *
11
 * This program is distributed in the hope that it will be useful,
12
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14
 * GNU General Public License for more details.
15
 *
16
 * You should have received a copy of the GNU General Public License
17
 * along with this program; if not, write to the Free Software
18
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
19
 * MA  02110-1301, USA.
20
 *
21
 * For any additional information, do not hesitate to contact us
22
 * at info AT gvsig.com, or visit our website www.gvsig.com.
23
 */
24

  
25
package org.gvsig.remoteclient.wfs.filters.filterencoding.wfs_1_0_0;
26

  
27
import java.awt.geom.PathIterator;
28

  
29
import org.gvsig.fmap.geom.Geometry;
30
import org.gvsig.fmap.geom.Geometry.TYPES;
31
import org.gvsig.fmap.geom.primitive.GeneralPathX;
32
import org.gvsig.fmap.geom.primitive.Surface;
33
import org.gvsig.remoteclient.wfs.filters.filterencoding.GeometryFEQuery;
34
import org.gvsig.remoteclient.wfs.filters.operations.WFSGeometryFilterOperation;
35

  
36
/**
37
 * @author <a href="mailto:jpiera@gvsig.org">Jorge Piera</a>
38
 */
39
public class GeometryFEQuery_1_0_0 extends GeometryFEQuery{
40

  
41
	public GeometryFEQuery_1_0_0(WFSGeometryFilterOperation geometryOperation) {
42
		super(geometryOperation);
43
	}
44

  
45
	public String getFilterEncoding(){
46
		StringBuffer request = new StringBuffer();
47
		if (geometry.getType() == TYPES.SURFACE){
48

  
49
			Surface surface = (Surface)geometry;
50
			request.append("<ogc:Intersects>");
51
			request.append("<ogc:PropertyName>" + spatialFilterOperation.getAttributeName() + "</ogc:PropertyName>");
52
			request.append("<gml:MultiPolygon srsName=\"" + spatialFilterOperation.getSrsName() + "\">");
53
			request.append("<gml:polygonMember>");
54
			request.append("<gml:Polygon>");
55
			request.append("<gml:outerBoundaryIs>");
56
			request.append("<gml:LinearRing>");
57
			request.append("<gml:coordinates cs=\",\" decimal=\".\" ts=\" \">");
58
			GeneralPathX generalPath = surface.getGeneralPath();
59
			PathIterator it = generalPath.getPathIterator(null);
60
			int type;
61
			double[] coordinates = new double[6];
62
			double[] firstCoordinates = null;
63
			while (!it.isDone()){
64
				type = it.currentSegment(coordinates);
65
				switch (type) {
66
					case PathIterator.SEG_MOVETO:
67
					case PathIterator.SEG_LINETO:
68
						request.append(coordinates[0]);
69
						request.append(",");
70
						request.append(coordinates[1]);
71
						request.append(" ");
72
						if (firstCoordinates == null){
73
							firstCoordinates = new double[2];
74
							firstCoordinates[0] = coordinates[0];
75
							firstCoordinates[1] = coordinates[1];
76
						}
77
						break;
78
				}
79
				it.next();
80
			}
81
			if ((coordinates[0] != firstCoordinates[0]) ||
82
					(coordinates[1] != firstCoordinates[1])){
83
				request.append(firstCoordinates[0]);
84
				request.append(",");
85
				request.append(firstCoordinates[1]);
86
			}
87
			request.append("</gml:coordinates>");
88
			request.append("</gml:LinearRing>");
89
			request.append("</gml:outerBoundaryIs>");
90
			request.append("</gml:Polygon>");
91
			request.append("</gml:polygonMember>");
92
			request.append("</gml:MultiPolygon>");
93
			request.append("</ogc:Intersects>");
94
		}
95
		return request.toString();
96
	}
97

  
98

  
99
}
100

  
org.gvsig.wfs.app/tags/org.gvsig.wfs.app-2.0.231/org.gvsig.wfs.app.mainplugin/src/main/java/org/gvsig/remoteclient/wfs/filters/filterencoding/wfs_1_0_0/EnvelopeFEQuery1_0_0.java
1
/**
2
 * gvSIG. Desktop Geographic Information System.
3
 *
4
 * Copyright (C) 2007-2013 gvSIG Association.
5
 *
6
 * This program is free software; you can redistribute it and/or
7
 * modify it under the terms of the GNU General Public License
8
 * as published by the Free Software Foundation; either version 3
9
 * of the License, or (at your option) any later version.
10
 *
11
 * This program is distributed in the hope that it will be useful,
12
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14
 * GNU General Public License for more details.
15
 *
16
 * You should have received a copy of the GNU General Public License
17
 * along with this program; if not, write to the Free Software
18
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
19
 * MA  02110-1301, USA.
20
 *
21
 * For any additional information, do not hesitate to contact us
22
 * at info AT gvsig.com, or visit our website www.gvsig.com.
23
 */
24
package org.gvsig.remoteclient.wfs.filters.filterencoding.wfs_1_0_0;
25

  
26
import org.gvsig.remoteclient.wfs.filters.filterencoding.EnvelopeFEQuery;
27
import org.gvsig.remoteclient.wfs.filters.operations.WFSEnvelopeFilterOperation;
28

  
29

  
30
/**
31
 * @author gvSIG Team
32
 * @version $Id$
33
 *
34
 */
35
public class EnvelopeFEQuery1_0_0 extends EnvelopeFEQuery{
36

  
37
    /**
38
     * @param envelopeOperation
39
     */
40
    public EnvelopeFEQuery1_0_0(WFSEnvelopeFilterOperation envelopeOperation) {
41
        super(envelopeOperation);       
42
    }
43
    
44
    public String getFilterEncoding(){
45
        StringBuffer request = new StringBuffer();
46
        request.append("<ogc:BBOX>");       
47
        request.append("<ogc:PropertyName>" + spatialFilterOperation.getAttributeFullName() + "</ogc:PropertyName>");
48
        request.append("<gml:Box srsName=\"" + spatialFilterOperation.getSrsName() + "\">");
49
        request.append("<gml:coordinates>");
50
        request.append(envelope.getMinimum(0) + "," + envelope.getMinimum(1));
51
        request.append(" ");
52
        request.append(envelope.getMaximum(0) + "," + envelope.getMaximum(1));
53
        request.append("</gml:coordinates>");
54
        request.append("</gml:Box>");
55
        request.append("</ogc:BBOX>");
56
        return request.toString();
57
    }
58

  
59
}
org.gvsig.wfs.app/tags/org.gvsig.wfs.app-2.0.231/org.gvsig.wfs.app.mainplugin/src/main/java/org/gvsig/remoteclient/wfs/filters/filterencoding/EnvelopeFEQuery.java
1
/**
2
 * gvSIG. Desktop Geographic Information System.
3
 *
4
 * Copyright (C) 2007-2013 gvSIG Association.
5
 *
6
 * This program is free software; you can redistribute it and/or
7
 * modify it under the terms of the GNU General Public License
8
 * as published by the Free Software Foundation; either version 3
9
 * of the License, or (at your option) any later version.
10
 *
11
 * This program is distributed in the hope that it will be useful,
12
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14
 * GNU General Public License for more details.
15
 *
16
 * You should have received a copy of the GNU General Public License
17
 * along with this program; if not, write to the Free Software
18
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
19
 * MA  02110-1301, USA.
20
 *
21
 * For any additional information, do not hesitate to contact us
22
 * at info AT gvsig.com, or visit our website www.gvsig.com.
23
 */
24

  
25
package org.gvsig.remoteclient.wfs.filters.filterencoding;
26

  
27
import org.gvsig.fmap.geom.primitive.Envelope;
28
import org.gvsig.remoteclient.wfs.filters.operations.WFSEnvelopeFilterOperation;
29

  
30
/**
31
 * @author <a href="mailto:jpiera@gvsig.org">Jorge Piera</a>
32
 */
33
public abstract class EnvelopeFEQuery extends SpatialFEQuery {
34
	protected Envelope envelope = null;
35

  
36
	public EnvelopeFEQuery(WFSEnvelopeFilterOperation envelopeOperation) {
37
		super(envelopeOperation);
38
		this.envelope = envelopeOperation.getEnvelope(); 
39
	}
40
}
41

  
org.gvsig.wfs.app/tags/org.gvsig.wfs.app-2.0.231/org.gvsig.wfs.app.mainplugin/src/main/java/org/gvsig/remoteclient/wfs/filters/filterencoding/SpatialFEQuery.java
1
/**
2
 * gvSIG. Desktop Geographic Information System.
3
 *
4
 * Copyright (C) 2007-2013 gvSIG Association.
5
 *
6
 * This program is free software; you can redistribute it and/or
7
 * modify it under the terms of the GNU General Public License
8
 * as published by the Free Software Foundation; either version 3
9
 * of the License, or (at your option) any later version.
10
 *
11
 * This program is distributed in the hope that it will be useful,
12
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14
 * GNU General Public License for more details.
15
 *
16
 * You should have received a copy of the GNU General Public License
17
 * along with this program; if not, write to the Free Software
18
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
19
 * MA  02110-1301, USA.
20
 *
21
 * For any additional information, do not hesitate to contact us
22
 * at info AT gvsig.com, or visit our website www.gvsig.com.
23
 */
24

  
25
package org.gvsig.remoteclient.wfs.filters.filterencoding;
26

  
27
import org.gvsig.remoteclient.wfs.filters.operations.WFSSpatialFilterOperation;
28

  
29
/**
30
 * @author <a href="mailto:jpiera@gvsig.org">Jorge Piera</a>
31
 */
32
public abstract class SpatialFEQuery implements FEQuery{
33
    protected WFSSpatialFilterOperation spatialFilterOperation = null;
34
  
35
    public SpatialFEQuery(WFSSpatialFilterOperation spatialFilterOperation) {
36
        this.spatialFilterOperation = spatialFilterOperation;           
37
    }
38

  
39
}
40

  
org.gvsig.wfs.app/tags/org.gvsig.wfs.app-2.0.231/org.gvsig.wfs.app.mainplugin/src/main/java/org/gvsig/remoteclient/wfs/filters/filterencoding/wfs_1_1_0/EnvelopeFEQuery1_1_0.java
1
/**
2
 * gvSIG. Desktop Geographic Information System.
3
 *
4
 * Copyright (C) 2007-2013 gvSIG Association.
5
 *
6
 * This program is free software; you can redistribute it and/or
7
 * modify it under the terms of the GNU General Public License
8
 * as published by the Free Software Foundation; either version 3
9
 * of the License, or (at your option) any later version.
10
 *
11
 * This program is distributed in the hope that it will be useful,
12
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14
 * GNU General Public License for more details.
15
 *
16
 * You should have received a copy of the GNU General Public License
17
 * along with this program; if not, write to the Free Software
18
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
19
 * MA  02110-1301, USA.
20
 *
21
 * For any additional information, do not hesitate to contact us
22
 * at info AT gvsig.com, or visit our website www.gvsig.com.
23
 */
24
package org.gvsig.remoteclient.wfs.filters.filterencoding.wfs_1_1_0;
25

  
26
import org.gvsig.remoteclient.wfs.filters.filterencoding.EnvelopeFEQuery;
27
import org.gvsig.remoteclient.wfs.filters.operations.WFSEnvelopeFilterOperation;
28

  
29

  
30
/**
31
 * @author gvSIG Team
32
 * @version $Id$
33
 *
34
 */
35
public class EnvelopeFEQuery1_1_0 extends EnvelopeFEQuery{
36

  
37
    /**
38
     * @param envelopeOperation
39
     */
40
    public EnvelopeFEQuery1_1_0(WFSEnvelopeFilterOperation envelopeOperation) {
41
        super(envelopeOperation);       
42
    }
43
    
44
    public String getFilterEncoding(){
45
        StringBuffer request = new StringBuffer();
46
        request.append("<ogc:BBOX>");
47
        request.append("<ogc:PropertyName>" + spatialFilterOperation.getAttributeFullName() + "</ogc:PropertyName>");
48
        request.append("<gml:Envelope srsName=\"" + spatialFilterOperation.getSrsName() + "\">");
49
        request.append("<gml:lowerCorner>");
50
        request.append(envelope.getMinimum(0) + " " + envelope.getMinimum(1));
51
        request.append("</gml:lowerCorner>");
52
        request.append("<gml:upperCorner>");
53
        request.append(envelope.getMaximum(0) + " " + envelope.getMaximum(1));
54
        request.append("</gml:upperCorner>");
55
        request.append("</gml:Envelope>");
56
        request.append("</ogc:BBOX>");
57
        return request.toString();
58
    }
59

  
60
}
org.gvsig.wfs.app/tags/org.gvsig.wfs.app-2.0.231/org.gvsig.wfs.app.mainplugin/src/main/java/org/gvsig/remoteclient/wfs/filters/filterencoding/wfs_1_1_0/GeometryFEQuery_1_1_0.java
1
/**
2
 * gvSIG. Desktop Geographic Information System.
3
 *
4
 * Copyright (C) 2007-2013 gvSIG Association.
5
 *
6
 * This program is free software; you can redistribute it and/or
7
 * modify it under the terms of the GNU General Public License
8
 * as published by the Free Software Foundation; either version 3
9
 * of the License, or (at your option) any later version.
10
 *
11
 * This program is distributed in the hope that it will be useful,
12
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14
 * GNU General Public License for more details.
15
 *
16
 * You should have received a copy of the GNU General Public License
17
 * along with this program; if not, write to the Free Software
18
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
19
 * MA  02110-1301, USA.
20
 *
21
 * For any additional information, do not hesitate to contact us
22
 * at info AT gvsig.com, or visit our website www.gvsig.com.
23
 */
24

  
25
package org.gvsig.remoteclient.wfs.filters.filterencoding.wfs_1_1_0;
26

  
27
import java.awt.geom.PathIterator;
28

  
29
import org.gvsig.fmap.geom.Geometry;
30
import org.gvsig.fmap.geom.Geometry.TYPES;
31
import org.gvsig.fmap.geom.primitive.GeneralPathX;
32
import org.gvsig.fmap.geom.primitive.Surface;
33
import org.gvsig.remoteclient.wfs.filters.filterencoding.GeometryFEQuery;
34
import org.gvsig.remoteclient.wfs.filters.operations.WFSGeometryFilterOperation;
35

  
36
/**
37
 * @author <a href="mailto:jpiera@gvsig.org">Jorge Piera</a>
38
 */
39
public class GeometryFEQuery_1_1_0 extends GeometryFEQuery{
40

  
41
	public GeometryFEQuery_1_1_0(WFSGeometryFilterOperation geometryOperation) {
42
		super(geometryOperation);
43
	}
44

  
45
	public String getFilterEncoding(){
46
		StringBuffer request = new StringBuffer();
47
		if (geometry.getType() == TYPES.SURFACE){
48
			Surface surface = (Surface)geometry;
49
			request.append("<ogc:Intersects>");
50
			request.append("<ogc:PropertyName>" + spatialFilterOperation.getAttributeName() + "</ogc:PropertyName>");
51
			request.append("<gml:MultiSurface srsName=\"" + spatialFilterOperation.getSrsName() + "\">");
52
			request.append("<gml:surfaceMember>");
53
			request.append("<gml:Polygon>");
54
			request.append("<gml:exterior>");
55
			request.append("<gml:LinearRing>");
56
			request.append("<gml:coordinates cs=\",\" decimal=\".\" ts=\" \">");
57
			GeneralPathX generalPath = surface.getGeneralPath();
58
			PathIterator it = generalPath.getPathIterator(null);
59
			int type;
60
			double[] coordinates = new double[6];
61
			double[] firstCoordinates = null;
62
			while (!it.isDone()){
63
				type = it.currentSegment(coordinates);
64
				switch (type) {
65
					case PathIterator.SEG_MOVETO:
66
					case PathIterator.SEG_LINETO:
67
						request.append(coordinates[0]);
68
						request.append(",");
69
						request.append(coordinates[1]);
70
						request.append(" ");
71
						if (firstCoordinates == null){
72
							firstCoordinates = new double[2];
73
							firstCoordinates[0] = coordinates[0];
74
							firstCoordinates[1] = coordinates[1];
75
						}
76
						break;
77
				}
78
				it.next();
79
			}
80
			if ((coordinates[0] != firstCoordinates[0]) ||
81
					(coordinates[1] != firstCoordinates[1])){
82
				request.append(firstCoordinates[0]);
83
				request.append(",");
84
				request.append(firstCoordinates[1]);
85
			}
86
			request.append("</gml:coordinates>");
87
			request.append("</gml:LinearRing>");
88
			request.append("</gml:exterior>");
89
			request.append("</gml:Polygon>");
90
			request.append("</gml:surfaceMember>");
91
			request.append("</gml:MultiSurface>");
92
			request.append("</ogc:Intersects>");
93
		}
94
		return request.toString();
95
	}
96

  
97

  
98
}
99

  
org.gvsig.wfs.app/tags/org.gvsig.wfs.app-2.0.231/org.gvsig.wfs.app.mainplugin/src/main/java/org/gvsig/remoteclient/wfs/filters/filterencoding/FEQuery.java
1
/**
2
 * gvSIG. Desktop Geographic Information System.
3
 *
4
 * Copyright (C) 2007-2013 gvSIG Association.
5
 *
6
 * This program is free software; you can redistribute it and/or
7
 * modify it under the terms of the GNU General Public License
8
 * as published by the Free Software Foundation; either version 3
9
 * of the License, or (at your option) any later version.
10
 *
11
 * This program is distributed in the hope that it will be useful,
12
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
... This diff was truncated because it exceeds the maximum size that can be displayed.

Also available in: Unified diff