Пример #1
0
  public ByteArrayOutputStream cleanup(InputStream xml) throws XServerException {
    inputXml = xml;

    // Use the default (non-validating) parser
    SAXParserFactory factory = SAXParserFactory.newInstance();

    try {
      // Parse the input
      SAXParser saxParser = factory.newSAXParser();
      saxParser.parse(inputXml, this);

      // close the stream
      inputXml.close();
    } catch (SAXParseException spe) {
      // Use the contained exception, if any
      Exception x = spe;

      if (spe.getException() != null) {
        x = spe.getException();
      }

      // Error generated by the parser
      LOG.warn(
          "XMLCleanup.cleanup() parsing exception: "
              + spe.getMessage()
              + " - xml line "
              + spe.getLineNumber()
              + ", uri "
              + spe.getSystemId(),
          x);
    } catch (SAXException sxe) {
      // Error generated by this application
      // (or a parser-initialization error)
      Exception x = sxe;

      if (sxe.getException() != null) {
        x = sxe.getException();
      }

      LOG.warn("XMLCleanup.cleanup() SAX exception: " + sxe.getMessage(), x);
    } catch (ParserConfigurationException pce) {
      // Parser with specified options can't be built
      LOG.warn("XMLCleanup.cleanup() SAX parser cannot be built with " + "specified options");
    } catch (IOException ioe) {
      // I/O error
      LOG.warn("XMLCleanup.cleanup() IO exception", ioe);
    } catch (Throwable t) {
      LOG.warn("XMLCleanup.cleanup() exception", t);
    }

    if (error) {
      throw new XServerException(error_code, error_text);
    }

    return bytes;
  }
Пример #2
0
  public XMLCleanup() {
    bytes = new ByteArrayOutputStream();

    try {
      out = new OutputStreamWriter(bytes, "UTF8");
    } catch (UnsupportedEncodingException e) {
      LOG.warn("XMLCleanup() unsupported encoding: " + e.getMessage());
    }
  }
Пример #3
0
 // dump warnings too
 public void warning(SAXParseException err) throws SAXParseException {
   LOG.warn(
       "SAXParser warning" + ", xml line " + err.getLineNumber() + ", uri " + err.getSystemId());
   LOG.warn("   " + err.getMessage());
 }