Ejemplo n.º 1
0
 private void Message(String mode, SAXParseException exception) {
   System.out.println(
       mode
           + " Line: "
           + exception.getLineNumber()
           + " URI: "
           + exception.getSystemId()
           + "\n"
           + " Message: "
           + exception.getMessage());
 }
 // 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());
 }
Ejemplo n.º 3
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();
    }
  }
Ejemplo n.º 4
0
 public void fatalError(SAXParseException exception) throws SAXException {
   throw new ValidationException(
       "Fatal error: " + exception.getMessage(), new LocationData(exception));
 }