www.pudn.com > gvSIG-1_1-rc1-src.zip > AbstractGeneralLanguage.java
/* gvSIG. Sistema de Información Geográfica de la Generalitat Valenciana
*
* Copyright (C) 2004 IVER T.I. and Generalitat Valenciana.
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,USA.
*
* For more information, contact:
*
* Generalitat Valenciana
* Conselleria d'Infraestructures i Transport
* Av. Blasco Ibáñez, 50
* 46010 VALENCIA
* SPAIN
*
* +34 963862235
* gvsig@gva.es
* www.gvsig.gva.es
*
* or
*
* IVER T.I. S.A
* Salamanca 50
* 46005 Valencia
* Spain
*
* +34 963163400
* dac@iver.es
*/
package es.gva.cit.catalogClient.languages;
import java.util.Iterator;
import java.util.StringTokenizer;
import java.util.Vector;
/**
* All classes that implement a "Language" must to inherit of this class
*
*
* @author Jorge Piera Llodra (piera_jor@gva.es)
*/
public abstract class AbstractGeneralLanguage implements ILanguages {
/**
*
*
*/
protected String currentQuery = null;
/**
*
*
*/
protected String currentClause = null;
/**
* Divide a phrase in lines
*
* @param concordancia If is 'E' (exact) don't divide
*
* @return Iteraror
* A set of words
* @param line phrase to search
* @param titleKeys
*/
public Iterator parseValues(String line, String titleKeys) {
Vector values = new Vector();
if (titleKeys == null){
titleKeys = "E";
}
if (titleKeys.equals("E")) {
values.add(line);
return values.iterator();
}
StringTokenizer doubleQuotesTokenizer = new StringTokenizer(line, "\"",
true);
boolean inside = false;
while (doubleQuotesTokenizer.hasMoreTokens()) {
String token = doubleQuotesTokenizer.nextToken();
if (token.equals("\"")) {
inside = !inside;
} else if (inside) {
values.add(token);
} else {
StringTokenizer spaceTokenizer = new StringTokenizer(token, " ");
while (spaceTokenizer.hasMoreTokens()) {
String value = spaceTokenizer.nextToken();
values.add(value);
}
}
}
return values.iterator();
}
/**
* Return logic operators
*
*
* @return Or or And
* @param titleKeys E,A o Y --> Exact, All, anY
*/
public String getOperator(String titleKeys) {
if (titleKeys == null){
titleKeys = "E";
}
if (titleKeys.equals("Y")) {
return "Or";
} else {
return "And";
}
}
}