1 // $Id: CQLTermNode.java,v 1.5 2002-10-30 09:19:26 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.5 2002-10-30 09:19:26 mike Exp $
12 public class CQLTermNode extends CQLNode {
13 private String qualifier;
14 private CQLRelation relation;
17 public CQLTermNode(String qualifier, CQLRelation 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>" + xq(qualifier) + "</index>\n" +
26 relation.toXCQL(level+1) +
27 indent(level+1) + "<term>" + xq(term) + "</term>\n" +
28 indent(level) + "</searchClause>\n");
32 String quotedQualifier = maybeQuote(qualifier);
33 String quotedTerm = maybeQuote(term);
35 // ### We don't always need spaces around `relation'.
36 return quotedQualifier + " " + relation.toCQL() + " " + quotedTerm;
39 static String maybeQuote(String str) {
40 // There _must_ be a better way to make this test ...
41 if (str.length() == 0 ||
42 str.indexOf('"') != -1 ||
43 str.indexOf(' ') != -1 ||
44 str.indexOf('\t') != -1 ||
45 str.indexOf('=') != -1 ||
46 str.indexOf('<') != -1 ||
47 str.indexOf('>') != -1 ||
48 str.indexOf('/') != -1 ||
49 str.indexOf('(') != -1 ||
50 str.indexOf(')') != -1) {
51 str = '"' + replace(str, "\"", "\\\"") + '"';