コード例 #1
0
ファイル: LogErrorHandler.java プロジェクト: rongbo-j/dwr
  /**
   * @param ex The exception to create a message from
   * @return A summary of what went wrong.
   */
  private static String getMessage(SAXParseException ex) {
    if (ex.getSystemId() != null) {
      return "SystemID=" + ex.getSystemId() + " Line=" + ex.getLineNumber() + ' ' + ex.getMessage();
    }

    if (ex.getPublicId() != null) {
      return "PublicID=" + ex.getPublicId() + " Line=" + ex.getLineNumber() + ' ' + ex.getMessage();
    }

    return "Line=" + ex.getLineNumber() + ' ' + ex.getMessage();
  }
コード例 #2
0
 private void throwError(final SAXParseException e) {
   throw new Error(
       e.getLocalizedMessage()
           + "\n\nPublic ID: "
           + (e.getPublicId() == null ? "None" : e.getPublicId())
           + ", System ID: "
           + (e.getPublicId() == null ? "None" : e.getPublicId())
           + ",\nLine number: "
           + e.getLineNumber()
           + ", Column number: "
           + e.getColumnNumber());
 }
 private MarshalSAXParseException marshalSAXParseException(SAXParseException exception) {
   return new MarshalSAXParseException(
       exception.getLocalizedMessage(),
       exception.getPublicId(),
       exception.getSystemId(),
       exception.getLineNumber(),
       exception.getColumnNumber(),
       exception.getException(),
       marshalRecord.getOwningObject());
 }
コード例 #4
0
ファイル: XmlChangeReader.java プロジェクト: junwuwei/osmosis
  /** Reads all data from the file and send it to the sink. */
  public void run() {
    InputStream inputStream = null;

    try {
      SAXParser parser;

      changeSink.initialize(Collections.<String, Object>emptyMap());

      // make "-" an alias for /dev/stdin
      if (file.getName().equals("-")) {
        inputStream = System.in;
      } else {
        inputStream = new FileInputStream(file);
      }

      inputStream =
          new CompressionActivator(compressionMethod).createCompressionInputStream(inputStream);

      parser = SaxParserFactory.createParser();

      parser.parse(inputStream, new OsmChangeHandler(changeSink, enableDateParsing));

      changeSink.complete();

    } catch (SAXParseException e) {
      throw new OsmosisRuntimeException(
          "Unable to parse xml file "
              + file
              + ".  publicId=("
              + e.getPublicId()
              + "), systemId=("
              + e.getSystemId()
              + "), lineNumber="
              + e.getLineNumber()
              + ", columnNumber="
              + e.getColumnNumber()
              + ".",
          e);
    } catch (SAXException e) {
      throw new OsmosisRuntimeException("Unable to parse XML.", e);
    } catch (IOException e) {
      throw new OsmosisRuntimeException("Unable to read XML file " + file + ".", e);
    } finally {
      changeSink.release();

      if (inputStream != null) {
        try {
          inputStream.close();
        } catch (IOException e) {
          log.log(Level.SEVERE, "Unable to close input stream.", e);
        }
        inputStream = null;
      }
    }
  }
コード例 #5
0
  /** Creates an XMLParseException from a SAXParseException. */
  protected static XMLParseException createXMLParseException(SAXParseException exception) {
    final String fPublicId = exception.getPublicId();
    final String fExpandedSystemId = exception.getSystemId();
    final int fLineNumber = exception.getLineNumber();
    final int fColumnNumber = exception.getColumnNumber();
    XMLLocator location =
        new XMLLocator() {
          public String getPublicId() {
            return fPublicId;
          }

          public String getExpandedSystemId() {
            return fExpandedSystemId;
          }

          public String getBaseSystemId() {
            return null;
          }

          public String getLiteralSystemId() {
            return null;
          }

          public int getColumnNumber() {
            return fColumnNumber;
          }

          public int getLineNumber() {
            return fLineNumber;
          }

          public int getCharacterOffset() {
            return -1;
          }

          public String getEncoding() {
            return null;
          }

          public String getXMLVersion() {
            return null;
          }
        };
    return new XMLParseException(location, exception.getMessage(), exception);
  } // createXMLParseException(SAXParseException):XMLParseException
コード例 #6
0
 // 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());
 }
コード例 #7
0
ファイル: JaxpTest.java プロジェクト: rath/libxml2-java
  @Test
  public void testParseExceptionThrownWithLocator() throws Exception {
    //		builderFactory = DocumentBuilderFactory.newInstance();
    builderFactory.setNamespaceAware(true);

    String xml =
        "<?xml version=\"1.0\"?>"
            + "<t:root xmlns=\"http://void.com/\" xmlns:t=\"http://t.com/\">"
            + "<t:item/>"
            + "<child />"
            + "<t:item/>"
            + "</root>";

    DocumentBuilder builder = builderFactory.newDocumentBuilder();
    try {
      builder.parse(new ByteArrayInputStream(xml.getBytes()));
      Assert.assertEquals(false, true);
    } catch (SAXParseException e) {
      Assert.assertEquals("public id", null, e.getPublicId());
      Assert.assertEquals("system id", null, e.getSystemId());
      Assert.assertEquals("line", 1, e.getLineNumber());
    }
  }
コード例 #8
0
 private void allErrors(SAXParseException e) {
   nrErrors++;
   if (errorMessage == null) {
     errorMessage = "";
   }
   errorMessage += Const.CR + Const.CR + "Error Nr." + nrErrors + " (";
   switch (error) {
     case 0:
       errorMessage += "Warning";
       break;
     case 1:
       errorMessage += "Error";
       break;
     case 2:
       errorMessage += "FatalError";
       break;
     default:
       break;
   }
   errorMessage +=
       ")"
           + Const.CR
           + "              Public ID: "
           + e.getPublicId()
           + Const.CR
           + "              System ID: "
           + e.getSystemId()
           + Const.CR
           + "              Line number: "
           + e.getLineNumber()
           + Const.CR
           + "              Column number: "
           + e.getColumnNumber()
           + Const.CR
           + "              Message: "
           + e.getMessage();
 }
コード例 #9
0
 /**
  * Constructor SAXSourceLocator
  *
  * @param spe SAXParseException exception.
  */
 public SAXSourceLocator(SAXParseException spe) {
   this.setLineNumber(spe.getLineNumber());
   this.setColumnNumber(spe.getColumnNumber());
   this.setPublicId(spe.getPublicId());
   this.setSystemId(spe.getSystemId());
 }
コード例 #10
0
ファイル: ErrorHandler.java プロジェクト: xialei/aug3-sys
 private void printError(SAXParseException ex) {
   LOG.warn(ex);
   LOG.warn("Warning while parsing XML file \n" + ex.getMessage());
   LOG.warn("Public ID : " + ex.getPublicId() + "   SystemID : " + ex.getSystemId());
   LOG.warn("Line: " + ex.getLineNumber() + "   Column : " + ex.getColumnNumber());
 }