コード例 #1
0
  /**
   * Parses the specified input source.
   *
   * @param source The input source.
   * @exception XNIException Throws exception on XNI error.
   * @exception java.io.IOException Throws exception on i/o error.
   */
  public void parse(XMLInputSource source) throws XNIException, IOException {

    if (fParseInProgress) {
      // REVISIT - need to add new error message
      throw new XNIException("FWK005 parse may not be called while parsing.");
    }
    fParseInProgress = true;

    try {
      setInputSource(source);
      parse(true);
    } catch (XNIException ex) {
      if (PRINT_EXCEPTION_STACK_TRACE) ex.printStackTrace();
      throw ex;
    } catch (IOException ex) {
      if (PRINT_EXCEPTION_STACK_TRACE) ex.printStackTrace();
      throw ex;
    } catch (RuntimeException ex) {
      if (PRINT_EXCEPTION_STACK_TRACE) ex.printStackTrace();
      throw ex;
    } catch (Exception ex) {
      if (PRINT_EXCEPTION_STACK_TRACE) ex.printStackTrace();
      throw new XNIException(ex);
    } finally {
      fParseInProgress = false;
      // close all streams opened by xerces
      this.cleanup();
    }
  } // parse(InputSource)
コード例 #2
0
ファイル: ValidatorImpl.java プロジェクト: xquery/AntRecipes
 static SAXException toSAXException(XNIException e) {
   if (e instanceof XMLParseException) {
     XMLParseException pe = (XMLParseException) e;
     return new SAXParseException(
         pe.getMessage(),
         pe.getPublicId(),
         pe.getExpandedSystemId(),
         pe.getLineNumber(),
         pe.getColumnNumber(),
         pe.getException());
   }
   Exception nested = e.getException();
   if (nested == null) return new SAXException(e.getMessage());
   if (nested instanceof SAXException) return (SAXException) nested;
   if (nested instanceof RuntimeException) throw (RuntimeException) nested;
   return new SAXException(nested);
 }
コード例 #3
0
  /**
   * Parses the document in a pull parsing fashion.
   *
   * @param complete True if the pull parser should parse the remaining document completely.
   * @return True if there is more document to parse.
   * @exception XNIException Any XNI exception, possibly wrapping another exception.
   * @exception IOException An IO exception from the parser, possibly from a byte stream or
   *     character stream supplied by the parser.
   * @see #setInputSource
   */
  public boolean parse(boolean complete) throws XNIException, IOException {
    //
    // reset and configure pipeline and set InputSource.
    if (fInputSource != null) {
      try {
        // resets and sets the pipeline.
        reset();
        fScanner.setInputSource(fInputSource);
        fInputSource = null;
      } catch (XNIException ex) {
        if (PRINT_EXCEPTION_STACK_TRACE) ex.printStackTrace();
        throw ex;
      } catch (IOException ex) {
        if (PRINT_EXCEPTION_STACK_TRACE) ex.printStackTrace();
        throw ex;
      } catch (RuntimeException ex) {
        if (PRINT_EXCEPTION_STACK_TRACE) ex.printStackTrace();
        throw ex;
      } catch (Exception ex) {
        if (PRINT_EXCEPTION_STACK_TRACE) ex.printStackTrace();
        throw new XNIException(ex);
      }
    }

    try {
      return fScanner.scanDocument(complete);
    } catch (XNIException ex) {
      if (PRINT_EXCEPTION_STACK_TRACE) ex.printStackTrace();
      throw ex;
    } catch (IOException ex) {
      if (PRINT_EXCEPTION_STACK_TRACE) ex.printStackTrace();
      throw ex;
    } catch (RuntimeException ex) {
      if (PRINT_EXCEPTION_STACK_TRACE) ex.printStackTrace();
      throw ex;
    } catch (Exception ex) {
      if (PRINT_EXCEPTION_STACK_TRACE) ex.printStackTrace();
      throw new XNIException(ex);
    }
  } // parse(boolean):boolean
コード例 #4
0
  public boolean parse(boolean complete) throws XNIException, IOException {
    //
    // reset and configure pipeline and set InputSource.
    if (fInputSource != null) {
      try {
        fValidationManager.reset();
        fVersionDetector.reset(this);
        resetCommon();

        short version = fVersionDetector.determineDocVersion(fInputSource);
        // XML 1.0
        if (version == Constants.XML_VERSION_1_0) {
          configurePipeline();
          reset();
        }
        // XML 1.1
        else if (version == Constants.XML_VERSION_1_1) {
          initXML11Components();
          configureXML11Pipeline();
          resetXML11();
        }
        // Unrecoverable error reported during version detection
        else {
          return false;
        }

        // mark configuration as fixed
        fConfigUpdated = false;

        // resets and sets the pipeline.
        fVersionDetector.startDocumentParsing((XMLEntityHandler) fCurrentScanner, version);
        fInputSource = null;
      } catch (XNIException ex) {
        if (PRINT_EXCEPTION_STACK_TRACE) ex.printStackTrace();
        throw ex;
      } catch (IOException ex) {
        if (PRINT_EXCEPTION_STACK_TRACE) ex.printStackTrace();
        throw ex;
      } catch (RuntimeException ex) {
        if (PRINT_EXCEPTION_STACK_TRACE) ex.printStackTrace();
        throw ex;
      } catch (Exception ex) {
        if (PRINT_EXCEPTION_STACK_TRACE) ex.printStackTrace();
        throw new XNIException(ex);
      }
    }

    try {
      return fCurrentScanner.scanDocument(complete);
    } catch (XNIException ex) {
      if (PRINT_EXCEPTION_STACK_TRACE) ex.printStackTrace();
      throw ex;
    } catch (IOException ex) {
      if (PRINT_EXCEPTION_STACK_TRACE) ex.printStackTrace();
      throw ex;
    } catch (RuntimeException ex) {
      if (PRINT_EXCEPTION_STACK_TRACE) ex.printStackTrace();
      throw ex;
    } catch (Exception ex) {
      if (PRINT_EXCEPTION_STACK_TRACE) ex.printStackTrace();
      throw new XNIException(ex);
    }
  } // parse(boolean):boolean