Beispiel #1
0
 static {
   RSHIPS.put("NT", "BT");
   RSHIPS.put("BT", "BT");
   RSHIPS.put("BTG", "NTG");
   RSHIPS.put("NTG", "BTG");
   RSHIPS.put("BTP", "NTP");
   RSHIPS.put("NTP", "BTP");
   RSHIPS.put("USE", "UF");
   RSHIPS.put("UF", "USE");
   RSHIPS.put("RT", "RT");
 }
Beispiel #2
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.put(ENTITIES[e], ENTITIES[e + 1]);
      dtd = pr.is(Prop.DTD);

      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();
          int ch = nextChar();
          if (ch != '?') error(WRONGCHAR, '?', (char) ch);
          ch = nextChar();
          if (ch != '>') error(WRONGCHAR, '>', (char) ch);
        } else {
          prev(5);
        }
      }
      encoding = enc == null ? UTF8 : enc;

      if (!fragment) {
        final int n = consume();
        if (!s(n)) {
          if (n != '<') error(n == 0 ? DOCEMPTY : BEFOREROOT);
          prev(1);
        }
      }
    } catch (final IOException ex) {
      input.close();
      throw ex;
    }
  }
Beispiel #3
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.put(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.put(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;
  }