+ Vector attrs = getAttrs(config);
+
+ String attr, s = "";
+ for (int i = 0; i < attrs.size(); i++) {
+ attr = (String) attrs.get(i);
+ s += "@attr " + Utils.replaceString(attr, " ", " @attr ") + " ";
+ }
+
+ String text = term;
+ if (text.length() > 0 && text.substring(0, 1).equals("^"))
+ text = text.substring(1);
+ int len = text.length();
+ if (len > 0 && text.substring(len-1, len).equals("^"))
+ text = text.substring(0, len-1);
+
+ return s + maybeQuote(text);
+ }
+
+ static String maybeQuote(String str) {
+ // There _must_ be a better way to make this test ...
+ if (str.length() == 0 ||
+ str.indexOf('"') != -1 ||
+ str.indexOf(' ') != -1 ||
+ str.indexOf('\t') != -1 ||
+ str.indexOf('=') != -1 ||
+ str.indexOf('<') != -1 ||
+ str.indexOf('>') != -1 ||
+ str.indexOf('/') != -1 ||
+ str.indexOf('(') != -1 ||
+ str.indexOf(')') != -1) {
+ str = '"' + Utils.replaceString(str, "\"", "\\\"") + '"';
+ }
+
+ return str;
+ }
+
+ public byte[] toType1BER(Properties config) throws PQFTranslationException {
+ if (qualifier.equals("srw.resultSet")) {
+ // Special case: ignore relation, modifiers, wildcards, etc.
+ // There's parallel code in toPQF()
+ byte[] operand = new byte[term.length()+100];
+ int offset;
+ offset = putTag(CONTEXT, 0, CONSTRUCTED, operand, 0); // op
+ operand[offset++] = (byte)(0x80&0xff); // indefinite length
+ offset = putTag(CONTEXT, 31, PRIMITIVE, operand, offset); // ResultSetId
+ byte[] t = term.getBytes();
+ offset = putLen(t.length, operand, offset);
+ System.arraycopy(t, 0, operand, offset, t.length);
+ offset += t.length;
+ operand[offset++] = 0x00; // end of Operand
+ operand[offset++] = 0x00;
+ byte[] o = new byte[offset];
+ System.arraycopy(operand, 0, o, 0, offset);
+ return o;
+ }
+
+ String text = term;
+ if (text.length() > 0 && text.substring(0, 1).equals("^"))
+ text = text.substring(1);
+ int len = text.length();
+ if (len > 0 && text.substring(len-1, len).equals("^"))
+ text = text.substring(0, len-1);
+
+ String attr, attrList, term = maybeQuote(text);
+ System.out.println("in CQLTermNode.toType1BER(): PQF=" + toPQF(config));
+ byte[] operand = new byte[text.length()+100];
+ int i, j, offset, type, value;
+ offset = putTag(CONTEXT, 0, CONSTRUCTED, operand, 0); // op
+ operand[offset++]=(byte)(0x80&0xff); // indefinite length
+ offset = putTag(CONTEXT, 102, CONSTRUCTED, operand, offset); // AttributesPlusTerm
+ operand[offset++] = (byte)(0x80&0xff); // indefinite length
+ offset = putTag(CONTEXT, 44, CONSTRUCTED, operand, offset); // AttributeList
+ operand[offset++] = (byte)(0x80&0xff); // indefinite length
+ offset = putTag(UNIVERSAL, SEQUENCE, CONSTRUCTED, operand, offset);
+ operand[offset++] = (byte)(0x80&0xff);
+
+ Vector attrs = getAttrs(config);
+ for(i = 0; i < attrs.size(); i++) {
+ attrList = (String) attrs.get(i);
+ java.util.StringTokenizer st =
+ new java.util.StringTokenizer(attrList);
+ while (st.hasMoreTokens()) {
+ attr = st.nextToken();
+ j = attr.indexOf('=');
+ offset = putTag(CONTEXT, 120, PRIMITIVE, operand, offset);
+ type = Integer.parseInt(attr.substring(0, j));
+ offset = putLen(numLen(type), operand, offset);
+ offset = putNum(type, operand, offset);
+
+ offset = putTag(CONTEXT, 121, PRIMITIVE, operand, offset);
+ value = Integer.parseInt(attr.substring(j+1));
+ offset = putLen(numLen(value), operand, offset);
+ offset = putNum(value, operand, offset);
+ }
+ }
+ operand[offset++] = 0x00; // end of SEQUENCE
+ operand[offset++] = 0x00;
+ operand[offset++] = 0x00; // end of AttributeList
+ operand[offset++] = 0x00;
+
+ offset = putTag(CONTEXT, 45, PRIMITIVE, operand, offset); // general Term
+ byte[] t = term.getBytes();
+ offset = putLen(t.length, operand, offset);
+ System.arraycopy(t, 0, operand, offset, t.length);
+ offset += t.length;
+
+ operand[offset++] = 0x00; // end of AttributesPlusTerm
+ operand[offset++] = 0x00;
+ operand[offset++] = 0x00; // end of Operand
+ operand[offset++] = 0x00;
+ byte[] o = new byte[offset];
+ System.arraycopy(operand, 0, o, 0, offset);
+ return o;