private void Message(String mode, SAXParseException exception) {
   System.out.println(
       mode
           + " Line: "
           + exception.getLineNumber()
           + " URI: "
           + exception.getSystemId()
           + "\n"
           + " Message: "
           + exception.getMessage());
 }
    /** Returns a string describing parse exception details */
    private String getParseExceptionInfo(SAXParseException spe) {
      String systemId = spe.getSystemId();
      if (systemId == null) {
        systemId = "null"; // $NON-NLS-1$
      }
      String info =
          "URI="
              + systemId
              + //$NON-NLS-1$
              " Line="
              + spe.getLineNumber()
              + //$NON-NLS-1$
              ": "
              + spe.getMessage(); // $NON-NLS-1$

      return info;
    }
  /**
   * start the parsing
   *
   * @param file to parse
   * @return Vector containing the test cases
   */
  public XMLcpimParser(String fileLocation) {
    try {
      SAXParserFactory saxParserFactory = SAXParserFactory.newInstance();
      saxParser = saxParserFactory.newSAXParser().getXMLReader();
      saxParser.setContentHandler(this);
      saxParser.setFeature("http://xml.org/sax/features/validation", true);
      // parse the xml specification for the event tags.
      saxParser.parse(fileLocation);

    } catch (SAXParseException spe) {
      spe.printStackTrace();
    } catch (SAXException sxe) {
      sxe.printStackTrace();
    } catch (IOException ioe) {
      // I/O error
      ioe.printStackTrace();
    } catch (Exception pce) {
      // Parser with specified options can't be built
      pce.printStackTrace();
    }
  }
 // Log the error
 private void log(int level, SAXParseException e) {
   int line = e.getLineNumber();
   int col = e.getColumnNumber();
   String publicId = e.getPublicId();
   String systemId = e.getSystemId();
   StringBuffer sb = new StringBuffer();
   sb.append(e.getMessage());
   if (line > 0 || col > 0) {
     sb.append(": line=");
     sb.append(line);
     sb.append(", col=");
     sb.append(col);
   }
   if (publicId != null || systemId != null) {
     sb.append(": publicId=");
     sb.append(publicId);
     sb.append(", systemId=");
     sb.append(systemId);
   }
   // Log the message
   log.log(level, sb.toString());
 }
Beispiel #5
0
  private static void inputSourceToSAX(
      InputSource inputSource,
      XMLReceiver xmlReceiver,
      XMLUtils.ParserConfiguration parserConfiguration,
      boolean handleLexical) {

    // Insert XInclude processor if needed
    final TransformerURIResolver resolver;
    if (parserConfiguration.handleXInclude) {
      parserConfiguration =
          new XMLUtils.ParserConfiguration(
              parserConfiguration.validating,
              false,
              parserConfiguration.externalEntities,
              parserConfiguration.uriReferences);
      resolver = new TransformerURIResolver(XMLUtils.ParserConfiguration.PLAIN);
      xmlReceiver =
          new XIncludeReceiver(null, xmlReceiver, parserConfiguration.uriReferences, resolver);
    } else {
      resolver = null;
    }

    try {
      final XMLReader xmlReader = newSAXParser(parserConfiguration).getXMLReader();
      xmlReader.setContentHandler(xmlReceiver);
      if (handleLexical) xmlReader.setProperty(XMLConstants.SAX_LEXICAL_HANDLER, xmlReceiver);

      xmlReader.setEntityResolver(ENTITY_RESOLVER);
      xmlReader.setErrorHandler(ERROR_HANDLER);
      xmlReader.parse(inputSource);
    } catch (SAXParseException e) {
      throw new ValidationException(e.getMessage(), new LocationData(e));
    } catch (Exception e) {
      throw new OXFException(e);
    } finally {
      if (resolver != null) resolver.destroy();
    }
  }
Beispiel #6
0
 public void fatalError(SAXParseException exception) throws SAXException {
   throw new ValidationException(
       "Fatal error: " + exception.getMessage(), new LocationData(exception));
 }