예제 #1
0
파일: ADate.java 프로젝트: jefferya/basex
  /**
   * Initializes the date format.
   *
   * @param d input
   * @param e example format
   * @param ii input info
   * @throws QueryException query exception
   */
  final void date(final byte[] d, final String e, final InputInfo ii) throws QueryException {
    final Matcher mt = DATE.matcher(Token.string(d).trim());
    if (!mt.matches()) throw dateError(d, e, ii);
    yea = toLong(mt.group(1), false, ii);
    // +1 is added to BC values to simplify computations
    if (yea < 0) yea++;
    mon = (byte) (Strings.toInt(mt.group(3)) - 1);
    day = (byte) (Strings.toInt(mt.group(4)) - 1);

    if (mon < 0 || mon >= 12 || day < 0 || day >= dpm(yea, mon)) throw dateError(d, e, ii);
    if (yea <= MIN_YEAR || yea > MAX_YEAR) throw DATERANGE_X_X.get(ii, type, chop(d, ii));
    zone(mt, 5, d, ii);
  }
예제 #2
0
파일: ADate.java 프로젝트: jefferya/basex
  /**
   * Initializes the timezone.
   *
   * @param matcher matcher
   * @param pos first matching position
   * @param value value
   * @param ii input info
   * @throws QueryException query exception
   */
  final void zone(final Matcher matcher, final int pos, final byte[] value, final InputInfo ii)
      throws QueryException {

    final String z = matcher.group(pos);
    if (z == null) return;
    if ("Z".equals(z)) {
      tz = 0;
    } else {
      final int th = Strings.toInt(matcher.group(pos + 2));
      final int tm = Strings.toInt(matcher.group(pos + 3));
      if (th > 14 || tm > 59 || th == 14 && tm != 0) throw INVALIDZONE_X.get(ii, value);
      final int mn = th * 60 + tm;
      tz = (short) ("-".equals(matcher.group(pos + 1)) ? -mn : mn);
    }
  }
예제 #3
0
파일: ADate.java 프로젝트: jefferya/basex
  /**
   * Initializes the time format.
   *
   * @param d input format
   * @param e expected format
   * @param ii input info
   * @throws QueryException query exception
   */
  final void time(final byte[] d, final String e, final InputInfo ii) throws QueryException {
    final Matcher mt = TIME.matcher(Token.string(d).trim());
    if (!mt.matches()) throw dateError(d, e, ii);

    hou = (byte) Strings.toInt(mt.group(1));
    min = (byte) Strings.toInt(mt.group(2));
    sec = toDecimal(mt.group(3), false, ii);
    if (min >= 60
        || sec.compareTo(BD60) >= 0
        || hou > 24
        || hou == 24 && (min > 0 || sec.compareTo(BigDecimal.ZERO) > 0)) throw dateError(d, e, ii);
    zone(mt, 5, d, ii);
    if (hou == 24) {
      hou = 0;
      add(DAYSECONDS);
    }
  }
예제 #4
0
파일: BaseX.java 프로젝트: james-jw/basex
  /**
   * Constructor.
   *
   * @param args command-line arguments
   * @throws IOException I/O exception
   */
  public BaseX(final String... args) throws IOException {
    super(args);

    // create session to show optional login request
    session();

    console = true;
    try {
      // loop through all commands
      final StringBuilder bind = new StringBuilder();
      SerializerOptions sopts = null;
      boolean v = false, qi = false, qp = false;
      final int os = ops.size();
      for (int o = 0; o < os; o++) {
        final int c = ops.get(o);
        String val = vals.get(o);

        if (c == 'b') {
          // set/add variable binding
          if (bind.length() != 0) bind.append(',');
          // commas are escaped by a second comma
          val = bind.append(val.replaceAll(",", ",,")).toString();
          execute(new Set(MainOptions.BINDINGS, val), false);
        } else if (c == 'c') {
          // evaluate commands
          final IO io = IO.get(val);
          String base = ".";
          if (io.exists() && !io.isDir()) {
            val = io.string();
            base = io.path();
          }
          execute(new Set(MainOptions.QUERYPATH, base), false);
          execute(val);
          execute(new Set(MainOptions.QUERYPATH, ""), false);
          console = false;
        } else if (c == 'D') {
          // hidden option: show/hide dot query graph
          execute(new Set(MainOptions.DOTPLAN, null), false);
        } else if (c == 'i') {
          // open database or create main memory representation
          execute(new Set(MainOptions.MAINMEM, true), false);
          execute(new Check(val), verbose);
          execute(new Set(MainOptions.MAINMEM, false), false);
        } else if (c == 'I') {
          // set/add variable binding
          if (bind.length() != 0) bind.append(',');
          // commas are escaped by a second comma
          val = bind.append("=").append(val.replaceAll(",", ",,")).toString();
          execute(new Set(MainOptions.BINDINGS, val), false);
        } else if (c == 'o') {
          // change output stream
          if (out != System.out) out.close();
          out = new PrintOutput(val);
          session().setOutputStream(out);
        } else if (c == 'q') {
          // evaluate query
          execute(new XQuery(val), verbose);
          console = false;
        } else if (c == 'Q') {
          // evaluate file contents or string as query
          final IO io = IO.get(val);
          String base = ".";
          if (io.exists() && !io.isDir()) {
            val = io.string();
            base = io.path();
          }
          execute(new Set(MainOptions.QUERYPATH, base), false);
          execute(new XQuery(val), verbose);
          execute(new Set(MainOptions.QUERYPATH, ""), false);
          console = false;
        } else if (c == 'r') {
          // parse number of runs
          execute(new Set(MainOptions.RUNS, Strings.toInt(val)), false);
        } else if (c == 'R') {
          // toggle query evaluation
          execute(new Set(MainOptions.RUNQUERY, null), false);
        } else if (c == 's') {
          // set/add serialization parameter
          if (sopts == null) sopts = new SerializerOptions();
          final String[] kv = val.split("=", 2);
          sopts.assign(kv[0], kv.length > 1 ? kv[1] : "");
          execute(new Set(MainOptions.SERIALIZER, sopts), false);
        } else if (c == 't') {
          // evaluate query
          execute(new Test(val), verbose);
          console = false;
        } else if (c == 'u') {
          // (de)activate write-back for updates
          execute(new Set(MainOptions.WRITEBACK, null), false);
        } else if (c == 'v') {
          // show/hide verbose mode
          v ^= true;
        } else if (c == 'V') {
          // show/hide query info
          qi ^= true;
          execute(new Set(MainOptions.QUERYINFO, null), false);
        } else if (c == 'w') {
          // toggle chopping of whitespaces
          execute(new Set(MainOptions.CHOP, null), false);
        } else if (c == 'x') {
          // show/hide xml query plan
          execute(new Set(MainOptions.XMLPLAN, null), false);
          qp ^= true;
        } else if (c == 'X') {
          // show query plan before/after query compilation
          execute(new Set(MainOptions.COMPPLAN, null), false);
        } else if (c == 'z') {
          // toggle result serialization
          execute(new Set(MainOptions.SERIALIZE, null), false);
        }
        verbose = qi || qp || v;
      }
      if (console) console();
    } finally {
      quit();
    }
  }