示例#1
0
  /**
   * Initializes the scanner.
   *
   * @param f input file
   * @param pr database properties
   * @param frag allow parsing of document fragment
   * @throws IOException I/O exception
   */
  XMLScanner(final IO f, final Prop pr, final boolean frag) throws IOException {
    input = new XMLInput(f);
    fragment = frag;

    try {
      for (int e = 0; e < ENTITIES.length; e += 2) {
        ents.add(token(ENTITIES[e]), token(ENTITIES[e + 1]));
      }
      dtd = pr.is(Prop.DTD);
      chop = pr.is(Prop.CHOP);

      String enc = null;
      // process document declaration...
      if (consume(DOCDECL)) {
        if (s()) {
          if (!version()) error(DECLSTART);
          boolean s = s();
          enc = encoding();
          if (enc != null) {
            if (!s) error(WSERROR);
            s = s();
          }
          if (sddecl() != null && !s) error(WSERROR);
          s();
          final int ch = nextChar();
          if (ch != '?' || nextChar() != '>') error(DECLWRONG);
        } else {
          prev(5);
        }
      }
      encoding = enc == null ? UTF8 : enc;

      if (!fragment) {
        final int n = consume();
        if (!s(n)) {
          if (n != '<') error(BEFOREROOT);
          prev(1);
        }
      }
    } catch (final IOException ex) {
      input.close();
      throw ex;
    }
  }
示例#2
0
  /**
   * Scans a markup declaration. [29]
   *
   * @return true if a declaration was found
   * @throws IOException I/O exception
   */
  private boolean markupDecl() throws IOException {
    if (consume(ENT)) { // [70]
      checkS();
      if (consume('%')) { // [72] PEDecl
        checkS();
        final byte[] key = name(true);
        checkS();
        byte[] val = entityValue(true); // [74]
        if (val == null) {
          val = externalID(true, false);
          if (val == null) error(INVEND);
        }
        s();
        pents.add(key, val);
      } else { // [71] GEDecl
        final byte[] key = name(true);
        checkS();
        byte[] val = entityValue(false); // [73] EntityDef
        if (val == null) {
          val = externalID(true, false);
          if (val == null) error(INVEND);
          if (s()) {
            check(ND);
            checkS();
            name(true);
          }
        }
        s();
        ents.add(key, val);
      }
      check('>');
      pe = true;
    } else if (consume(ELEM)) { // [45]
      checkS();
      name(true);
      checkS();
      pe = true;
      if (!consume(EMP) && !consume(ANY)) { // [46]
        if (consume('(')) {
          s();
          if (consume(PC)) { // [51]
            s();
            boolean alt = false;
            while (consume('|')) {
              s();
              name(true);
              s();
              alt = true;
            }
            check(')');
            if (!consume('*') && alt) error(INVEND);
          } else {
            cp();
            s();
            // check(')'); // to be fixed...
            while (!consume(')')) consume();
            // input.prev(1);
            occ();
          }
        } else {
          error(INVEND);
        }
      }
      s();
      check('>');
    } else if (consume(ATTL)) { // [52]
      pe = true;
      checkS();
      name(true);
      s();
      while (name(false) != null) { // [53]
        checkS();
        if (!consume(CD)
            && !consume(IDRS)
            && !consume(IDR)
            && !consume(ID)
            && !consume(ENTS)
            && !consume(ENT1)
            && !consume(NMTS)
            && !consume(NMT)) { // [56]
          if (consume(NOT)) { // [57,58]
            checkS();
            check('(');
            s();
            name(true);
            s();
            while (consume('|')) {
              s();
              name(true);
              s();
            }
            check(')');
          } else { // [59]
            check('(');
            s();
            nmtoken();
            s();
            while (consume('|')) {
              s();
              nmtoken();
              s();
            }
            check(')');
          }
        }

        // [54]
        pe = true;
        checkS();
        if (!consume(REQ) && !consume(IMP)) { // [60]
          if (consume(FIX)) checkS();
          quote = qu();
          attValue(consume());
        }
        s();
      }
      check('>');
    } else if (consume(NOTA)) { // [82]
      checkS();
      name(true);
      s();
      externalID(false, false);
      s();
      check('>');
    } else if (consume(COMS)) {
      comment();
    } else if (consume(XML)) {
      pi();
    } else {
      return false;
    }
    s();
    pe = false;
    return true;
  }