org.xml.sax.SAXParseException#getSystemId ( )源码实例Demo

下面列出了org.xml.sax.SAXParseException#getSystemId ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。

源代码1 项目: openjdk-8   文件: ErrorHandlerWrapper.java
/** 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);
}
 
源代码2 项目: mycore   文件: MCRServlet.java
private void throwIOException(Exception e) throws IOException {
    if (e instanceof IOException) {
        throw (IOException) e;
    }
    if (e instanceof TransformerException) {
        TransformerException te = MCRErrorListener.unwrapException((TransformerException) e);
        String myMessageAndLocation = MCRErrorListener.getMyMessageAndLocation(te);
        throw new IOException("Error while XSL Transformation: " + myMessageAndLocation, e);
    }
    if (e instanceof SAXParseException) {
        SAXParseException spe = (SAXParseException) e;
        String id = spe.getSystemId() != null ? spe.getSystemId() : spe.getPublicId();
        int line = spe.getLineNumber();
        int column = spe.getColumnNumber();
        String msg = new MessageFormat("Error on {0}:{1} while parsing {2}", Locale.ROOT)
            .format(new Object[] { line, column, id });
        throw new IOException(msg, e);
    }
    throw new IOException(e);
}
 
public void error(SAXParseException e) throws SAXException {
    if (errorCount >= ERROR_COUNT_LIMIT) {
        // Ignore all errors after reaching the limit
        return;
    } else if (errorCount == 0) {
        // Print a warning before the first error
        System.err.println(SAXMessageFormatter.formatMessage(locale,
                    "errorHandlerNotSet", new Object [] {errorCount}));
    }

    String systemId = e.getSystemId();
    if (systemId == null) {
        systemId = "null";
    }
    String message = "Error: URI=" + systemId +
        " Line=" + e.getLineNumber() +
        ": " + e.getMessage();
    System.err.println(message);
    errorCount++;
}
 
源代码4 项目: lucene-solr   文件: PatternParser.java
/**
 * Returns a string of the location.
 */
private String getLocationString(SAXParseException ex) {
  StringBuilder str = new StringBuilder();

  String systemId = ex.getSystemId();
  if (systemId != null) {
    int index = systemId.lastIndexOf('/');
    if (index != -1) {
      systemId = systemId.substring(index + 1);
    }
    str.append(systemId);
  }
  str.append(':');
  str.append(ex.getLineNumber());
  str.append(':');
  str.append(ex.getColumnNumber());

  return str.toString();

}
 
/** Returns a string of the location. */
private String getLocationString(SAXParseException ex) {
    StringBuffer str = new StringBuffer();

    String systemId = ex.getSystemId();
    if (systemId != null) {
        int index = systemId.lastIndexOf('/');
        if (index != -1) {
            systemId = systemId.substring(index + 1);
        }
        str.append(systemId);
    } else {
        str.append(getResource().getName());
    }
    str.append(':');
    str.append(ex.getLineNumber());
    str.append(':');
    str.append(ex.getColumnNumber());

    return str.toString();

}
 
/** Returns a string of the location. */
private String getLocationString(SAXParseException ex) {
    StringBuffer str = new StringBuffer();

    String systemId = ex.getSystemId();
    if (systemId != null) {
        int index = systemId.lastIndexOf('/');
        if (index != -1) {
            systemId = systemId.substring(index + 1);
        }
        str.append(systemId);
    } else {
        str.append(getResource().getName());
    }
    str.append(':');
    str.append(ex.getLineNumber());
    str.append(':');
    str.append(ex.getColumnNumber());

    return str.toString();

}
 
/** Returns a string of the location. */
private String getLocationString(SAXParseException ex) {
    StringBuffer str = new StringBuffer();

    String systemId = ex.getSystemId();
    if (systemId != null) {
        int index = systemId.lastIndexOf('/');
        if (index != -1) {
            systemId = systemId.substring(index + 1);
        }
        str.append(systemId);
    } else {
        str.append(getResource().getName());
    }
    str.append(':');
    str.append(ex.getLineNumber());
    str.append(':');
    str.append(ex.getColumnNumber());

    return str.toString();

}
 
源代码8 项目: jdk8u60   文件: DefaultValidationErrorHandler.java
public void error(SAXParseException e) throws SAXException {
    if (errorCount >= ERROR_COUNT_LIMIT) {
        // Ignore all errors after reaching the limit
        return;
    } else if (errorCount == 0) {
        // Print a warning before the first error
        System.err.println(SAXMessageFormatter.formatMessage(locale,
                    "errorHandlerNotSet", new Object [] {errorCount}));
    }

    String systemId = e.getSystemId();
    if (systemId == null) {
        systemId = "null";
    }
    String message = "Error: URI=" + systemId +
        " Line=" + e.getLineNumber() +
        ": " + e.getMessage();
    System.err.println(message);
    errorCount++;
}
 
源代码9 项目: hottub   文件: DefaultValidationErrorHandler.java
public void error(SAXParseException e) throws SAXException {
    if (errorCount >= ERROR_COUNT_LIMIT) {
        // Ignore all errors after reaching the limit
        return;
    } else if (errorCount == 0) {
        // Print a warning before the first error
        System.err.println(SAXMessageFormatter.formatMessage(locale,
                    "errorHandlerNotSet", new Object [] {errorCount}));
    }

    String systemId = e.getSystemId();
    if (systemId == null) {
        systemId = "null";
    }
    String message = "Error: URI=" + systemId +
        " Line=" + e.getLineNumber() +
        ": " + e.getMessage();
    System.err.println(message);
    errorCount++;
}
 
源代码10 项目: Bytecoder   文件: DefaultValidationErrorHandler.java
public void error(SAXParseException e) throws SAXException {
    if (errorCount >= ERROR_COUNT_LIMIT) {
        // Ignore all errors after reaching the limit
        return;
    } else if (errorCount == 0) {
        // Print a warning before the first error
        System.err.println(SAXMessageFormatter.formatMessage(locale,
                    "errorHandlerNotSet", new Object [] {errorCount}));
    }

    String systemId = e.getSystemId();
    if (systemId == null) {
        systemId = "null";
    }
    String message = "Error: URI=" + systemId +
        " Line=" + e.getLineNumber() +
        ": " + e.getMessage();
    System.err.println(message);
    errorCount++;
}
 
源代码11 项目: openjdk-jdk9   文件: XInclHandler.java
/**
 * Prints the error message.
 * @param type error type
 * @param ex exception that need to be printed
 */
private void printError(String type, SAXParseException ex) {
    System.err.print("[" + type + "] ");
    String systemId = ex.getSystemId();
    if (systemId != null) {
        int index = systemId.lastIndexOf('/');
        if (index != -1)
            systemId = systemId.substring(index + 1);
        System.err.print(systemId);
    }
    System.err.print(':' + ex.getLineNumber());
    System.err.print(':' + ex.getColumnNumber());
    System.err.println(": " + ex.getMessage());
    System.err.flush();
}
 
源代码12 项目: jdk8u60   文件: ConsoleErrorReporter.java
public void error(SAXParseException e) {
    if(debug)
        e.printStackTrace();
    hasError = true;
    if((e.getSystemId() == null && e.getPublicId() == null) && (e.getCause() instanceof UnknownHostException)) {
        print(WscompileMessages.WSIMPORT_ERROR_MESSAGE(e.toString()), e);
    } else {
        print(WscompileMessages.WSIMPORT_ERROR_MESSAGE(e.getMessage()), e);
    }
}
 
源代码13 项目: vertx-web   文件: XMLTypeValidatorTest.java
@Test
public void isValidPattern() throws IOException {

    File tempFile = File.createTempFile("xml-", "-xxe");
    tempFile.deleteOnExit();

  try (OutputStream out = new FileOutputStream(tempFile)) {
    out.write("<appinfo>you should not see me!!!</appinfo>".getBytes(StandardCharsets.UTF_8));
  }

  try {
    XMLTypeValidator.XMLTypeValidatorFactory.createXMLTypeValidator(
      "<?xml version=\"1.0\" encoding=\"ISO-8859-1\"?>\n" +
        "<!DOCTYPE foo [ <!ELEMENT foo ANY >\n" +
        "<!ENTITY xxe SYSTEM \"file://" + tempFile.getCanonicalPath() + "\" >]>\n" +
        "<creds>\n" +
        "    <user>&xxe;</user>\n" +
        "    <pass>mypass</pass>\n" +
        "</creds>"
    );
  } catch (Throwable e) {
    if (e.getCause() instanceof SAXParseException) {
      SAXParseException xxe = (SAXParseException) e.getCause();
      // here comes the nasty XXE verification
      String message = xxe.getMessage();

      if (xxe.getSystemId() == null && message.contains(tempFile.getName()) && message.contains("accessExternalDTD")) {
        // we're safe, the parsed failed to load the XXE
      } else {
        fail("XML got access to FS: " + message);
      }
    }
  }

}
 
源代码14 项目: openjdk-jdk9   文件: ErrorReceiver.java
/**
 * Returns the human readable string representation of the
 * {@link org.xml.sax.Locator} part of the specified
 * {@link SAXParseException}.
 *
 * @return  non-null valid object.
 */
protected final String getLocationString( SAXParseException e ) {
    if(e.getLineNumber()!=-1 || e.getSystemId()!=null) {
        int line = e.getLineNumber();
        return Messages.format( Messages.LINE_X_OF_Y,
            line==-1?"?":Integer.toString( line ),
            getShortName( e.getSystemId() ) );
    } else {
        return Messages.format( Messages.UNKNOWN_LOCATION );
    }
}
 
源代码15 项目: EventCoreference   文件: GetSemFromCat.java
public void parseFile(String filePath) {
        initPart();
        fileName = new File(filePath).getName();
        initSingletonId(filePath);
        String myerror = "";
        try {
            SAXParserFactory factory = SAXParserFactory.newInstance();
            factory.setValidating(false);
            SAXParser parser = factory.newSAXParser();
            InputSource inp = new InputSource(new FileReader(filePath));
            parser.parse(inp, this);
/*
            System.out.println("eventTermArrayList.size(); = " + eventTermArrayList.size());
            System.out.println("timeLinks = " + timeLinks.size());
            System.out.println("locationLinks = " + locationLinks.size());
            System.out.println("plotLinks = " + plotLinks.size());
*/

        } catch (SAXParseException err) {
            myerror = "\n** Parsing error" + ", line " + err.getLineNumber()
                    + ", uri " + err.getSystemId();
            myerror += "\n" + err.getMessage();
            System.out.println("myerror = " + myerror);
        } catch (SAXException e) {
            Exception x = e;
            if (e.getException() != null)
                x = e.getException();
            myerror += "\nSAXException --" + x.getMessage();
            System.out.println("myerror = " + myerror);
        } catch (Exception eee) {
            eee.printStackTrace();
            myerror += "\nException --" + eee.getMessage();
            System.out.println("myerror = " + myerror);
        }
        //System.out.println("myerror = " + myerror);
    }
 
源代码16 项目: openjdk-8-source   文件: ConsoleErrorReporter.java
public void error(SAXParseException e) {
    if(debug)
        e.printStackTrace();
    hasError = true;
    if((e.getSystemId() == null && e.getPublicId() == null) && (e.getCause() instanceof UnknownHostException)) {
        print(WscompileMessages.WSIMPORT_ERROR_MESSAGE(e.toString()), e);
    } else {
        print(WscompileMessages.WSIMPORT_ERROR_MESSAGE(e.getMessage()), e);
    }
}
 
源代码17 项目: openjdk-jdk8u-backup   文件: ErrorReceiver.java
/**
 * Returns the human readable string representation of the
 * {@link org.xml.sax.Locator} part of the specified
 * {@link SAXParseException}.
 *
 * @return  non-null valid object.
 */
protected final String getLocationString( SAXParseException e ) {
    if(e.getLineNumber()!=-1 || e.getSystemId()!=null) {
        int line = e.getLineNumber();
        return Messages.format( Messages.LINE_X_OF_Y,
            line==-1?"?":Integer.toString( line ),
            getShortName( e.getSystemId() ) );
    } else {
        return Messages.format( Messages.UNKNOWN_LOCATION );
    }
}
 
源代码18 项目: camunda-bpm-platform   文件: DomUtil.java
private String getParseExceptionInfo(SAXParseException spe) {
  return "URI=" + spe.getSystemId() + " Line="
    + spe.getLineNumber() + ": " + spe.getMessage();
}
 
源代码19 项目: xml-maven-plugin   文件: ValidateMojo.java
private void appendMessage(StringBuffer messageBuffer,ValidationErrorHandler.ErrorRecord error) {
    SAXParseException e = error.getException();
        final String publicId = e.getPublicId();
        final String systemId = e.getSystemId();
        final int lineNum = e.getLineNumber();
        final int colNum = e.getColumnNumber();
        final String location;
        if ( publicId == null && systemId == null && lineNum == -1 && colNum == -1 )
        {
            location = "";
        }
        else
        {
            final StringBuffer loc = new StringBuffer();
            String sep = "";
            if ( publicId != null )
            {
                loc.append( "Public ID " );
                loc.append( publicId );
                sep = ", ";
            }
            if ( systemId != null )
            {
                loc.append( sep );
                loc.append( systemId );
                sep = ", ";
            }
            if ( lineNum != -1 )
            {
                loc.append( sep );
                loc.append( "line " );
                loc.append( lineNum );
                sep = ", ";
            }
            if ( colNum != -1 )
            {
                loc.append( sep );
                loc.append( " column " );
                loc.append( colNum );
                sep = ", ";
            }
            location = loc.toString();
        }
        messageBuffer.append("While parsing ");
        messageBuffer.append(error.getContext().getPath());
        messageBuffer.append(( "".equals( location ) ? "" : ", at " + location ));
        messageBuffer.append(": " );
        messageBuffer.append(error.getType().toString());
        messageBuffer.append(": " );
        messageBuffer.append(e.getMessage());
        String lineSep = System.getProperty("line.separator");
        messageBuffer.append(lineSep);
}
 
源代码20 项目: jaxb2-maven-plugin   文件: XjcLogAdapter.java
private String getLocation(final SAXParseException e) {

        final String exceptionId = e.getPublicId() == null ? e.getSystemId() : e.getPublicId();
        return exceptionId + " [" + e.getLineNumber() + "," + e.getColumnNumber() + "] ";
    }