1 // $Id: CQLNode.java,v 1.15 2002-11-20 01:15:15 mike Exp $
3 package org.z3950.zing.cql;
4 import java.util.Properties;
5 import java.util.Vector;
9 * Represents a node in a CQL parse-tree.
11 * @version $Id: CQLNode.java,v 1.15 2002-11-20 01:15:15 mike Exp $
13 public abstract class CQLNode {
14 CQLNode() {} // prevent javadoc from documenting this
17 * Translates a parse-tree into an XCQL document.
20 * The number of levels to indent the top element of the XCQL
21 * document. This will typically be 0 when invoked by an
22 * application; it takes higher values when this method is
23 * invoked recursively for nodes further down the tree.
25 * A String containing an XCQL document equivalent to the
26 * parse-tree whose root is this node.
28 public String toXCQL(int level) {
29 return toXCQL(level, new Vector());
32 abstract public String toXCQL(int level, Vector prefixes);
34 protected static String renderPrefixes(int level, Vector prefixes) {
35 if (prefixes.size() == 0)
37 String res = indent(level) + "<prefixes>\n";
38 for (int i = 0; i < prefixes.size(); i++) {
39 CQLPrefix p = (CQLPrefix) prefixes.get(i);
40 res += indent(level+1) + "<prefix>\n";
42 res += indent(level+2) + "<name>" + p.name + "</name>\n";
43 res += indent(level+2) +
44 "<identifier>" + p.identifier + "</identifier>\n";
45 res += indent(level+1) + "</prefix>\n";
47 return res + indent(level) + "</prefixes>\n";
51 * Decompiles a parse-tree into a CQL query.
54 * A String containing a CQL query equivalent to the parse-tree
55 * whose root is this node, so that compiling that query will
56 * yield an identical tree.
58 abstract public String toCQL();
61 * Renders a parse-tree into a Yaz-style PQF string.
62 * PQF, or Prefix Query Format, is a cryptic but powerful notation
63 * that can be trivially mapped, one-to-one, int Z39.50 Type-1 and
64 * Type-101 queries. A specification for the format can be found
66 * <A href="http://indexdata.dk/yaz/doc/tools.php#PQF"
67 * >Chapter 7 (Supporting Tools)</A> of the
68 * <A href="http://indexdata.dk/yaz/">YAZ</A> manual.
71 * A <TT>Properties</TT> object containing configuration
72 * information that specifies the mapping from CQL qualifiers,
73 * relations, etc. to Type-1 attributes. The mapping
74 * specification is described in the cql-java distribution's
75 * sample PQF-mapping configuration file,
76 * <TT>etc/pqf.properties</TT>, which see.
78 * A String containing a PQF query equivalent to the parse-tree
79 * whose root is this node. This may be fed into the tool of
80 * your choice to obtain a BER-encoded packet.
82 abstract public String toPQF(Properties config)
83 throws PQFTranslationException;
86 * Returns a String of spaces for indenting to the specified level.
88 protected static String indent(int level) { return Utils.indent(level); }
91 * Returns the argument String quoted for XML.
92 * For example, each occurrence of <TT><</TT> is translated to
95 protected static String xq(String str) { return Utils.xq(str); }