1 // $Id: CQLTermNode.java,v 1.3 2002-10-25 16:56:43 mike Exp $
3 package org.z3950.zing.cql;
7 * Represents a terminal node in a CQL parse-tree ...
10 * @version $Id: CQLTermNode.java,v 1.3 2002-10-25 16:56:43 mike Exp $
12 public class CQLTermNode extends CQLNode {
13 private String qualifier;
14 private String relation;
17 public CQLTermNode(String qualifier, String relation, String term) {
18 this.qualifier = qualifier;
19 this.relation = relation;
23 String toXCQL(int level) {
24 return (indent(level) + "<searchClause>\n" +
25 indent(level+1) + "<index>" + qualifier + "<index>\n" +
26 indent(level+1) + "<relation>" + relation + "<relation>\n" +
27 indent(level+1) + "<term>" + term + "<term>\n" +
28 indent(level) + "</searchClause>\n");
32 String quotedTerm = term;
34 if (quotedTerm.indexOf('"') != -1) {
35 // ### precede each '"' with a '/'
38 // ### There must be a better way ...
39 if (quotedTerm.indexOf('"') != -1 ||
40 quotedTerm.indexOf(' ') != -1 ||
41 quotedTerm.indexOf('\t') != -1 ||
42 quotedTerm.indexOf('=') != -1 ||
43 quotedTerm.indexOf('<') != -1 ||
44 quotedTerm.indexOf('>') != -1 ||
45 quotedTerm.indexOf('/') != -1 ||
46 quotedTerm.indexOf('(') != -1 ||
47 quotedTerm.indexOf(')') != -1) {
48 quotedTerm = '"' + quotedTerm + '"';
51 // ### The qualifier may need quoting.
52 // ### We don't always need spaces around `relation'.
53 return qualifier + " " + relation + " " + quotedTerm;