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

The following examples show how to use org.xml.sax.SAXParseException#getPublicId() . 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: 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 2
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 3
Source File: ErrorHandlerWrapper.java    From openjdk-jdk9 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 4
Source File: ErrorHandlerWrapper.java    From jdk8u60 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 5
Source File: ErrorHandlerWrapper.java    From JDKSourceCode1.8 with MIT License 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 6
Source File: DTDValidator.java    From pentaho-kettle with Apache License 2.0 6 votes vote down vote up
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();
}
 
Example 7
Source File: ErrorHandlerWrapper.java    From openjdk-jdk8u 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 8
Source File: DefaultXMLProcessorDetail.java    From netbeans with Apache License 2.0 6 votes vote down vote up
/**
 * Create new DefaultXMLProcessorMessage based on SAXParseException.
 * @param spex SAX exception to be wrapped (never <code>null</code>).
 */
public DefaultXMLProcessorDetail(SAXParseException spex) {
    if (spex == null) throw new NullPointerException();

    this.exception = spex;
    this.columnNumber = spex.getColumnNumber();
    this.lineNumber = spex.getLineNumber();
    this.publicId = spex.getPublicId();
    this.systemId = spex.getSystemId();

    if ( Util.THIS.isLoggable() ) /* then */ {
        Util.THIS.debug ("DefaultXMLProcessorDetail: SAXParseException");
        Util.THIS.debug ("    exception= " + exception);
        Util.THIS.debug ("    columnNumber= " + columnNumber);
        Util.THIS.debug ("    lineNumber= " + lineNumber);
        Util.THIS.debug ("    publicId= " + publicId);
        Util.THIS.debug ("    systemId= " + systemId);
    }
}
 
Example 9
Source File: ErrorHandlerWrapper.java    From Bytecoder with Apache License 2.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 10
Source File: ErrorHandlerWrapper.java    From openjdk-jdk8u-backup 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 11
Source File: ConsoleErrorReporter.java    From openjdk-8 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 12
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 13
Source File: ConsoleErrorReporter.java    From openjdk-jdk8u-backup 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: ConsoleErrorReporter.java    From openjdk-jdk8u 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 15
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 16
Source File: LoggingErrorReceiver.java    From maven-jaxb2-plugin with BSD 2-Clause "Simplified" License 5 votes vote down vote up
private String getMessage(SAXParseException ex) {
	final int row = ex.getLineNumber();
	final int col = ex.getColumnNumber();
	final String sys = ex.getSystemId();
	final String pub = ex.getPublicId();

	return messagePrefix + "Location [" + (sys != null ? " " + sys : "")
			+ (pub != null ? " " + pub : "")
			+ (row > 0 ? "{" + row + (col > 0 ? "," + col : "") + "}" : "")
			+ "].";
}
 
Example 17
Source File: ConsoleErrorReporter.java    From TencentKona-8 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: DefaultXMLProcessorDetail.java    From netbeans with Apache License 2.0 4 votes vote down vote up
private void tryWrappedLocator(Exception ex) {
    if ( Util.THIS.isLoggable() ) /* then */ {
        Util.THIS.debug ("DefaultXMLProcessorDetail.tryWrappedLocator: " + ex);
    }

    // I saw SAXException wrapped in TransformerException and vice versa

    Throwable wrapped = null;
    if (ex instanceof TransformerException) {
        wrapped = ((TransformerException) ex).getException();
    } else if (ex instanceof SAXException) {
        wrapped = ((SAXException) ex).getException();
    } else {
        return;
    }

    // look if wrapped exception does not provide location info

    if (wrapped instanceof SAXParseException) {
        SAXParseException pex = (SAXParseException) wrapped;
        if (pex.getLineNumber() == -1) {
            tryWrappedLocator(pex);
        } else {
            this.columnNumber = pex.getColumnNumber();
            this.lineNumber = pex.getLineNumber();
            this.publicId = pex.getPublicId();
            this.systemId = pex.getSystemId();                    
        }
    } else if (wrapped instanceof TransformerException) {
        TransformerException wrappedTransformerEx = 
            (TransformerException) wrapped;
        SourceLocator locator = wrappedTransformerEx.getLocator();
        if (locator == null) {
            tryWrappedLocator(wrappedTransformerEx);
        } else {
            if (locator.getLineNumber() == -1) {
                tryWrappedLocator(wrappedTransformerEx);
            } else {
                this.columnNumber = locator.getColumnNumber();
                this.lineNumber = locator.getLineNumber();
                this.publicId = locator.getPublicId();
                this.systemId = locator.getSystemId();                        
            }
        }
    } else if (wrapped instanceof SAXException) {
        tryWrappedLocator((SAXException)wrapped);
    }
}
 
Example 19
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 20
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);
}