Revision 9336

View differences:

trunk/extensions/extWFS2/src/com/iver/cit/gvsig/gui/panels/sqlFormat/SQLExpressionFormatForFilterGUI.java
1
package com.iver.cit.gvsig.gui.panels.sqlFormat;
2

  
3
import java.io.ByteArrayInputStream;
4
import java.io.InputStream;
5

  
6
import javax.swing.JOptionPane;
7

  
8
import com.iver.andami.PluginServices;
9

  
10
import Zql.ParseException;
11
import Zql.ZExp;
12
import Zql.ZqlParser;
13

  
14
/* gvSIG. Sistema de Informaci?n Geogr?fica de la Generalitat Valenciana
15
 *
16
 * Copyright (C) 2004 IVER T.I. and Generalitat Valenciana.
17
 *
18
 * This program is free software; you can redistribute it and/or
19
 * modify it under the terms of the GNU General Public License
20
 * as published by the Free Software Foundation; either version 2
21
 * of the License, or (at your option) any later version.
22
 *
23
 * This program is distributed in the hope that it will be useful,
24
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
25
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
26
 * GNU General Public License for more details.
27
 *
28
 * You should have received a copy of the GNU General Public License
29
 * along with this program; if not, write to the Free Software
30
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307,USA.
31
 *
32
 * For more information, contact:
33
 *
34
 *  Generalitat Valenciana
35
 *   Conselleria d'Infraestructures i Transport
36
 *   Av. Blasco Ib??ez, 50
37
 *   46010 VALENCIA
38
 *   SPAIN
39
 *
40
 *      +34 963862235
41
 *   gvsig@gva.es
42
 *      www.gvsig.gva.es
43
 *
44
 *    or
45
 *
46
 *   IVER T.I. S.A
47
 *   Salamanca 50
48
 *   46005 Valencia
49
 *   Spain
50
 *
51
 *   +34 963163400
52
 *   dac@iver.es
53
 */
54

  
55
/**
56
 * This is a version of 'SQLExpressionFormat' that has a modified method that shows a JOptionPane that displays with warning
57
 *    message if there is an error. 
58
 *
59
 * @author Pablo Piqueras Bartolom? (p_queras@hotmail.com)
60
 * @author Jorge Piera Llodr? (piera_jor@gva.es) 
61
 */
62
public class SQLExpressionFormatForFilterGUI {
63
	/**
64
	 * @see SQLExpressionFormatForFilterGUI#format(String)
65
	 * 
66
	 * Returns 'null' if there has been some error
67
	 */
68
	public static String validateSQLquery(String query) {
69
		if (query == null) {
70
			JOptionPane.showMessageDialog(null, PluginServices.getText(null, "error_coding_filter_query"), PluginServices.getText(null, "error"), JOptionPane.ERROR_MESSAGE);
71
			return null;
72
		}
73
		
74
		if (query.trim().compareTo("") == 0)
75
			return query;
76
		
77
		InputStream is = new ByteArrayInputStream(query.getBytes());
78
		ZqlParser parser = new ZqlParser();
79
		parser.initParser(is);
80
		ZExp exp;
81
		try {
82
			exp = parser.readExpression();
83
			return query;
84
		} catch (ParseException e) {			
85
			JOptionPane.showMessageDialog(null, PluginServices.getText(null, "error_validating_sql_filter_query") + ":\n" + e.getMessage(), PluginServices.getText(null, "error"), JOptionPane.ERROR_MESSAGE);
86
			return null;
87
		}
88
	}
89
}
0 90

  

Also available in: Unified diff