Java Code Examples for org.xml.sax.SAXParseException#getSystemId()

The following examples show how to use org.xml.sax.SAXParseException#getSystemId() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: ErrorHandlerWrapper.java    From openjdk-8 with GNU General Public License v2.0 6 votes vote down vote up
/** 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);
}
 
Example 2
Source File: DefaultValidationErrorHandler.java    From Bytecoder with Apache License 2.0 6 votes vote down vote up
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++;
}
 
Example 3
Source File: MCRServlet.java    From mycore with GNU General Public License v3.0 6 votes vote down vote up
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);
}
 
Example 4
Source File: DefaultValidationErrorHandler.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 6 votes vote down vote up
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++;
}
 
Example 5
Source File: PatternParser.java    From lucene-solr with Apache License 2.0 6 votes vote down vote up
/**
 * 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();

}
 
Example 6
Source File: IvyXmlModuleDescriptorParser.java    From pushfish-android with BSD 2-Clause "Simplified" License 6 votes vote down vote up
/** 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();

}
 
Example 7
Source File: IvyXmlModuleDescriptorParser.java    From pushfish-android with BSD 2-Clause "Simplified" License 6 votes vote down vote up
/** 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();

}
 
Example 8
Source File: DefaultValidationErrorHandler.java    From hottub with GNU General Public License v2.0 6 votes vote down vote up
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++;
}
 
Example 9
Source File: IvyXmlModuleDescriptorParser.java    From Pushjet-Android with BSD 2-Clause "Simplified" License 6 votes vote down vote up
/** 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();

}
 
Example 10
Source File: DefaultValidationErrorHandler.java    From jdk8u60 with GNU General Public License v2.0 6 votes vote down vote up
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++;
}
 
Example 11
Source File: ErrorReceiver.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 5 votes vote down vote up
/**
 * 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 );
    }
}
 
Example 12
Source File: XInclHandler.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
/**
 * 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();
}
 
Example 13
Source File: ConsoleErrorReporter.java    From openjdk-8-source with GNU General Public License v2.0 5 votes vote down vote up
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);
    }
}
 
Example 14
Source File: GetSemFromCat.java    From EventCoreference with Apache License 2.0 5 votes vote down vote up
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);
    }
 
Example 15
Source File: ErrorReceiver.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
/**
 * 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 );
    }
}
 
Example 16
Source File: XMLTypeValidatorTest.java    From vertx-web with Apache License 2.0 5 votes vote down vote up
@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);
      }
    }
  }

}
 
Example 17
Source File: ConsoleErrorReporter.java    From jdk8u60 with GNU General Public License v2.0 5 votes vote down vote up
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);
    }
}
 
Example 18
Source File: XjcLogAdapter.java    From jaxb2-maven-plugin with Apache License 2.0 4 votes vote down vote up
private String getLocation(final SAXParseException e) {

        final String exceptionId = e.getPublicId() == null ? e.getSystemId() : e.getPublicId();
        return exceptionId + " [" + e.getLineNumber() + "," + e.getColumnNumber() + "] ";
    }
 
Example 19
Source File: ValidateMojo.java    From xml-maven-plugin with Apache License 2.0 4 votes vote down vote up
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);
}
 
Example 20
Source File: DomUtil.java    From camunda-bpm-platform with Apache License 2.0 4 votes vote down vote up
private String getParseExceptionInfo(SAXParseException spe) {
  return "URI=" + spe.getSystemId() + " Line="
    + spe.getLineNumber() + ": " + spe.getMessage();
}