예제 #1
0
  /**
   * Reads a character from the reader disallowing entities.
   *
   * @param reader the reader
   * @param entityChar the escape character (& or %) used to indicate an entity
   */
  static char readChar(IXMLReader reader, char entityChar) throws IOException, XMLParseException {
    String str = XMLUtil.read(reader, entityChar);
    char ch = str.charAt(0);

    if (ch == entityChar) {
      XMLUtil.errorUnexpectedEntity(reader.getSystemID(), reader.getLineNr(), str);
    }

    return ch;
  }
예제 #2
0
  /**
   * Retrieves a delimited string from the data.
   *
   * @param reader the reader
   * @param entityChar the escape character (& or %)
   * @param entityResolver the entity resolver
   * @throws java.io.IOException if an error occurred reading the data
   */
  static String scanString(IXMLReader reader, char entityChar, IXMLEntityResolver entityResolver)
      throws IOException, XMLParseException {
    StringBuffer result = new StringBuffer();
    int startingLevel = reader.getStreamLevel();
    char delim = reader.read();

    if ((delim != '\'') && (delim != '"')) {
      XMLUtil.errorExpectedInput(reader.getSystemID(), reader.getLineNr(), "delimited string");
    }

    for (; ; ) {
      String str = XMLUtil.read(reader, entityChar);
      char ch = str.charAt(0);

      if (ch == entityChar) {
        if (str.charAt(1) == '#') {
          result.append(XMLUtil.processCharLiteral(str));
        } else {
          XMLUtil.processEntity(str, reader, entityResolver);
        }
      } else if (ch == '&') {
        reader.unread(ch);
        str = XMLUtil.read(reader, '&');
        if (str.charAt(1) == '#') {
          result.append(XMLUtil.processCharLiteral(str));
        } else {
          result.append(str);
        }
      } else if (reader.getStreamLevel() == startingLevel) {
        if (ch == delim) {
          break;
        } else if ((ch == 9) || (ch == 10) || (ch == 13)) {
          result.append(' ');
        } else {
          result.append(ch);
        }
      } else {
        result.append(ch);
      }
    }

    return result.toString();
  }