1 // $Id: CQLRelation.java,v 1.1 2002-10-30 09:19:26 mike Exp $
3 package org.z3950.zing.cql;
4 import java.util.Vector;
5 import java.lang.StringBuffer;
8 * Represents a relation between a CQL qualifier and term.
11 * @version $Id: CQLRelation.java,v 1.1 2002-10-30 09:19:26 mike Exp $
13 public class CQLRelation extends CQLNode {
17 public CQLRelation(String base) {
19 modifiers = new Vector();
22 public void addModifier(String modifier) {
23 modifiers.add(modifier);
26 public String[] getModifiers() {
27 int n = modifiers.size();
28 String[] res = new String[n];
29 for (int i = 0; i < n; i++) {
30 res[i] = (String) modifiers.get(i);
36 public String toXCQL(int level) {
37 StringBuffer buf = new StringBuffer();
38 buf.append (indent(level) + "<relation>\n" +
39 indent(level+1) + "<value>" + xq(base) + "</value>\n");
40 String[] mods = getModifiers();
41 if (mods.length > 0) {
42 buf.append(indent(level+1) + "<modifiers>\n");
43 for (int i = 0; i < mods.length; i++)
44 buf.append(indent(level+2)).
45 append("<modifier><value>"). append(mods[i]).
46 append("</value></modifier>\n");
47 buf.append(indent(level+1) + "</modifiers>\n");
49 buf.append(indent(level) + "</relation>\n");
50 return buf.toString();
53 public String toCQL() {
54 StringBuffer buf = new StringBuffer(base);
55 String[] mods = getModifiers();
56 for (int i = 0; i < mods.length; i++) {
57 buf.append("/").append(mods[i]);
60 return buf.toString();
63 public static void main(String[] args) {
64 if (args.length < 1) {
65 System.err.println("Usage: CQLRelation <base> <modifier>...");
69 CQLRelation res = new CQLRelation(args[0]);
70 for (int i = 1; i < args.length; i++) {
71 res.addModifier(args[i]);
74 System.out.println(res.toCQL());