Lots of changes, mostly to documentation, towards initial release.
[cql-java-moved-to-github.git] / src / org / z3950 / zing / cql / CQLNode.java
index 3d16a37..4eb8023 100644 (file)
@@ -1,60 +1,30 @@
-// $Id: CQLNode.java,v 1.6 2002-10-29 10:15:58 mike Exp $
+// $Id: CQLNode.java,v 1.9 2002-10-31 22:22:01 mike Exp $
 
 package org.z3950.zing.cql;
 
 
 /**
- * Represents a node in a CQL parse-tree ...
- * ###
+ * Represents a node in a CQL parse-tree.
+ * ##
  *
- * @version    $Id: CQLNode.java,v 1.6 2002-10-29 10:15:58 mike Exp $
+ * @version    $Id: CQLNode.java,v 1.9 2002-10-31 22:22:01 mike Exp $
  */
 public abstract class CQLNode {
     abstract String toXCQL(int level);
     abstract String toCQL();
 
-    protected String indent(int level) {
-       String x = "";
-       while (level-- > 0) {
-           x += "  ";
-       }
-       return x;
-    }
-
-    // XML Quote --
-    // s/&/&/g;
-    // s/</&lt;/g;
-    // s/>/&gt;/g;
-    // This is hideously inefficient, but I just don't see a better
-    // way using the standard JAVA library.
-    //
-    protected String xq(String str) {
-       str = replace(str, "&", "&amp;");
-       str = replace(str, "<", "&lt;");
-       str = replace(str, ">", "&gt;");
-       return str;
-    }
-
-    String replace(String str, String from, String to) {
-       StringBuffer sb = new StringBuffer();
-       int ix;                 // index of next `from'
-       int offset = 0;         // index of previous `from' + length(from)
-
-       while ((ix = str.indexOf(from, offset)) != -1) {
-           sb.append(str.substring(offset, ix));
-           sb.append(to);
-           offset = ix + from.length();
-       }
-
-       // End of string: append last bit and we're done
-       sb.append(str.substring(offset));
-       return sb.toString();
-    }
+    // Utility-function abbreviations for the use of subclasses
+    protected static String indent(int level) { return Utils.indent(level); }
+    protected static String xq(String str) { return Utils.xq(str); }
 
     // 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 n1 = new CQLTermNode("dc.author",
+                                    new CQLRelation("="),
+                                    "kernighan");
+       CQLNode n2 = new CQLTermNode("dc.title",
+                                    new CQLRelation("all"),
+                                    "elements style");
        CQLNode root = new CQLAndNode(n1, n2);
        System.out.println(root.toXCQL(0));
     }