コード例 #1
0
ファイル: Find.java プロジェクト: phspaelti/basex
  /**
   * Creates an XQuery representation for the specified table query.
   *
   * @param filter filter terms
   * @param cols filter columns
   * @param elem element flag
   * @param name name of root element
   * @param root root flag
   * @return query
   */
  public static String findTable(
      final StringList filter,
      final TokenList cols,
      final BoolList elem,
      final byte[] name,
      final boolean root) {

    final TokenBuilder tb = new TokenBuilder();
    final int is = filter.size();
    for (int i = 0; i < is; ++i) {
      final String[] spl = split(filter.get(i));
      for (final String s : spl) {
        final byte[] term = trim(replace(token(s), '"', ' '));
        if (term.length == 0) continue;
        tb.add('[');

        final boolean elm = elem.get(i);
        tb.add(elm ? ".//" : "@");
        tb.add("*:");
        tb.add(cols.get(i));

        if (term[0] == '<' || term[0] == '>') {
          tb.add(term[0]);
          tb.addLong(calcNum(substring(term, 1)));
        } else {
          tb.add(" contains text \"");
          tb.add(term);
          tb.add('"');
        }
        tb.add(']');
      }
    }
    return tb.isEmpty() ? "/" : (root ? "/" : "") + Axis.DESCORSELF + "::*:" + string(name) + tb;
  }
コード例 #2
0
ファイル: XMLScanner.java プロジェクト: siserle/basex
 /**
  * Consumes an Nmtoken. [7]
  *
  * @throws IOException I/O exception
  */
 private void nmtoken() throws IOException {
   final TokenBuilder name = new TokenBuilder();
   int c;
   while (isChar(c = nextChar())) name.add(c);
   prev(1);
   if (name.isEmpty()) error(INVNAME);
 }
コード例 #3
0
 /**
  * Joins the path.
  *
  * @param s segment to start with
  * @return joined path
  */
 private String join(final int s) {
   final TokenBuilder tb = new TokenBuilder();
   for (int p = s; p < segments.length; p++) {
     if (!tb.isEmpty()) tb.add('/');
     tb.add(segments[p]);
   }
   return tb.toString();
 }
コード例 #4
0
 /**
  * Converts the path to a string array, containing the single segments.
  *
  * @param path path, or {@code null}
  * @return path depth
  */
 public static String[] toSegments(final String path) {
   final StringList sl = new StringList();
   if (path != null) {
     final TokenBuilder tb = new TokenBuilder();
     for (int s = 0; s < path.length(); s++) {
       final char ch = path.charAt(s);
       if (ch == '/') {
         if (tb.isEmpty()) continue;
         sl.add(tb.toString());
         tb.reset();
       } else {
         tb.add(ch);
       }
     }
     if (!tb.isEmpty()) sl.add(tb.toString());
   }
   return sl.toArray();
 }
コード例 #5
0
ファイル: HTTPContext.java プロジェクト: phspaelti/basex
 /**
  * Returns the database path (i.e., all path entries except for the first).
  *
  * @return path depth
  */
 public String dbpath() {
   final TokenBuilder tb = new TokenBuilder();
   final int ps = segments.length;
   for (int p = 1; p < ps; p++) {
     if (!tb.isEmpty()) tb.add('/');
     tb.add(segments[p]);
   }
   return tb.toString();
 }
コード例 #6
0
ファイル: XMLScanner.java プロジェクト: siserle/basex
 /**
  * Scans a document encoding.
  *
  * @return encoding
  * @throws IOException I/O exception
  */
 private String encoding() throws IOException {
   if (!consume(ENCOD)) {
     if (fragment) error(TEXTENC);
     return null;
   }
   s();
   check('=');
   s();
   final TokenBuilder enc = new TokenBuilder();
   final int d = qu();
   int ch = nextChar();
   if (letter(ch) && ch != '_') {
     while (letterOrDigit(ch) || ch == '.' || ch == '-') {
       enc.add(ch);
       ch = nextChar();
     }
     prev(1);
   }
   check((char) d);
   if (enc.isEmpty()) error(DECLENCODE, enc);
   final String e = string(enc.finish());
   input.encoding(e);
   return e;
 }