X-Git-Url: http://git.indexdata.com/?a=blobdiff_plain;f=src%2Forg%2Fz3950%2Fzing%2Fcql%2FCQLNode.java;h=5965da621c6eea1afa47700f5ebfad68da2e3d0d;hb=f744abfa23a7e569a156e4686e0e8e3cec242652;hp=baa6cad12d7adc6a2c4ff00695c7fffa02d09186;hpb=9b7bbaf04b9492a1071d10fe5a1ce3f1ee60a0fc;p=cql-java-moved-to-github.git diff --git a/src/org/z3950/zing/cql/CQLNode.java b/src/org/z3950/zing/cql/CQLNode.java index baa6cad..5965da6 100644 --- a/src/org/z3950/zing/cql/CQLNode.java +++ b/src/org/z3950/zing/cql/CQLNode.java @@ -1,39 +1,96 @@ -// $Id: CQLNode.java,v 1.5 2002-10-27 00:46:25 mike Exp $ +// $Id: CQLNode.java,v 1.15 2002-11-20 01:15:15 mike Exp $ package org.z3950.zing.cql; +import java.util.Properties; +import java.util.Vector; /** - * Represents a node in a CQL parse-tree ... - * ### + * Represents a node in a CQL parse-tree. * - * @version $Id: CQLNode.java,v 1.5 2002-10-27 00:46:25 mike Exp $ + * @version $Id: CQLNode.java,v 1.15 2002-11-20 01:15:15 mike Exp $ */ public abstract class CQLNode { - abstract String toXCQL(int level); - abstract String toCQL(); + CQLNode() {} // prevent javadoc from documenting this - protected String indent(int level) { - String x = ""; - while (level-- > 0) { - x += " "; - } - return x; + /** + * Translates a parse-tree into an XCQL document. + *
+ * @param level
+ * The number of levels to indent the top element of the XCQL
+ * document. This will typically be 0 when invoked by an
+ * application; it takes higher values when this method is
+ * invoked recursively for nodes further down the tree.
+ * @return
+ * A String containing an XCQL document equivalent to the
+ * parse-tree whose root is this node.
+ */
+ public String toXCQL(int level) {
+ return toXCQL(level, new Vector());
}
- protected String xq(String str) {
- // XML Quote
- // ### s/&/&/g;
- // s/</g;
- // s/>/>/g;
- return str;
- }
+ abstract public String toXCQL(int level, Vector prefixes);
- // Test harness
- public static void main (String[] args) {
- CQLNode n1 = new CQLTermNode("dc.author", "=", "kernighan");
- CQLNode n2 = new CQLTermNode("dc.title", "all", "elements style");
- CQLNode root = new CQLAndNode(n1, n2);
- System.out.println(root.toXCQL(0));
+ protected static String renderPrefixes(int level, Vector prefixes) {
+ if (prefixes.size() == 0)
+ return "";
+ String res = indent(level) + "
+ * @return + * A String containing a CQL query equivalent to the parse-tree + * whose root is this node, so that compiling that query will + * yield an identical tree. + */ + abstract public String toCQL(); + + /** + * Renders a parse-tree into a Yaz-style PQF string. + * PQF, or Prefix Query Format, is a cryptic but powerful notation + * that can be trivially mapped, one-to-one, int Z39.50 Type-1 and + * Type-101 queries. A specification for the format can be found + * in + * Chapter 7 (Supporting Tools) of the + * YAZ manual. + *
+ * @param config + * A Properties object containing configuration + * information that specifies the mapping from CQL qualifiers, + * relations, etc. to Type-1 attributes. The mapping + * specification is described in the cql-java distribution's + * sample PQF-mapping configuration file, + * etc/pqf.properties, which see. + * @return + * A String containing a PQF query equivalent to the parse-tree + * whose root is this node. This may be fed into the tool of + * your choice to obtain a BER-encoded packet. + */ + abstract public String toPQF(Properties config) + throws PQFTranslationException; + + /** + * Returns a String of spaces for indenting to the specified level. + */ + protected static String indent(int level) { return Utils.indent(level); } + + /** + * Returns the argument String quoted for XML. + * For example, each occurrence of < is translated to + * <. + */ + protected static String xq(String str) { return Utils.xq(str); } }