protected void throwEOFException() throws RDFParseException { throw new RDFParseException("Unexpected end of file"); }
private void loadZip(InputStream in, String baseURI, RDFFormat dataFormat, RDFHandler rdfHandler) throws IOException, RDFParseException, RDFHandlerException { try (ZipInputStream zipIn = new ZipInputStream(in);) { for (ZipEntry entry = zipIn.getNextEntry(); entry != null; entry = zipIn.getNextEntry()) { if (entry.isDirectory()) { continue; } try { RDFFormat format = Rio.getParserFormatForFileName(entry.getName()).orElse(dataFormat); // Prevent parser (Xerces) from closing the input stream UncloseableInputStream wrapper = new UncloseableInputStream(zipIn); load(wrapper, baseURI, format, rdfHandler); } catch (RDFParseException e) { String msg = e.getMessage() + " in " + entry.getName(); RDFParseException pe = new RDFParseException(msg, e.getLineNumber(), e.getColumnNumber()); pe.initCause(e); throw pe; } finally { zipIn.closeEntry(); } } // end for } }
/** * Creates a new ParseException. * * @param msg * An error message. * @param lineNo * A line number associated with the message. * @param columnNo * A column number associated with the message. */ public RDFParseException(String msg, long lineNo, long columnNo) { super(msg + getLocationString(lineNo, columnNo)); this.lineNo = lineNo; this.columnNo = columnNo; }
private static String createMessage(RDFParseException exception, CachedLog log) { long lineNumber = exception.getLineNumber(); // get three lines before the error long firstLineOfMessage = Math.max(lineNumber - 4, 0); // get three lines before after the error long lastLineOfMessage = lineNumber + 3; Path file = log.getFile().toPath(); StringBuilder message = new StringBuilder(exception.getMessage()); message.append("\n"); try (Stream<String> lines = Files.lines(file)) { Iterator<String> lineIterator = lines.skip(firstLineOfMessage).iterator(); for (long line = firstLineOfMessage; line < lastLineOfMessage && lineIterator.hasNext(); line++) { message.append(" ").append(line + 1).append(": ").append(lineIterator.next()).append("\n"); } return message.toString(); } catch (IOException e) { return exception.getMessage(); } } }
/** * Processes a single <i>html script</i> node. * * @param turtleParser the parser used to digest node content. * @param documentIRI the IRI of the original HTML document. * @param n the script node. * @param er the extraction result used to store triples. */ private void processScriptNode(RDFParser turtleParser, IRI documentIRI, Node n, ExtractionResult er) { final Node idAttribute = n.getAttributes().getNamedItem("id"); final String graphName = documentIRI.stringValue() + ( idAttribute == null ? "" : "#" + idAttribute.getTextContent() ); try { turtleParser.parse( new StringReader(n.getTextContent()), graphName ); } catch (RDFParseException rdfpe) { er.notifyIssue( IssueReport.IssueLevel.ERROR, String.format( "An error occurred while parsing turtle content within script node: %s", Arrays.toString(DomUtils.getXPathListForNode(n)) ), rdfpe.getLineNumber(), rdfpe.getColumnNumber() ); } catch (Exception e) { er.notifyIssue(IssueReport.IssueLevel.ERROR, "An error occurred while processing RDF data.", -1, -1); } }
ErrorInfo errInfo = new ErrorInfo(ErrorType.MALFORMED_DATA, e.getMessage()); throw new ClientHTTPException(SC_BAD_REQUEST, errInfo.toString());
ErrorInfo errInfo = new ErrorInfo(ErrorType.MALFORMED_DATA, e.getMessage()); throw new ClientHTTPException(SC_BAD_REQUEST, errInfo.toString());
protected void throwEOFException() throws RDFParseException { throw new RDFParseException("Unexpected end of file"); }
private void loadZip(InputStream in, String baseURI, RDFFormat dataFormat, RDFHandler rdfHandler) throws IOException, RDFParseException, RDFHandlerException { try (ZipInputStream zipIn = new ZipInputStream(in);) { for (ZipEntry entry = zipIn.getNextEntry(); entry != null; entry = zipIn.getNextEntry()) { if (entry.isDirectory()) { continue; } try { RDFFormat format = Rio.getParserFormatForFileName(entry.getName()).orElse(dataFormat); // Prevent parser (Xerces) from closing the input stream UncloseableInputStream wrapper = new UncloseableInputStream(zipIn); load(wrapper, baseURI, format, rdfHandler); } catch (RDFParseException e) { String msg = e.getMessage() + " in " + entry.getName(); RDFParseException pe = new RDFParseException(msg, e.getLineNumber(), e.getColumnNumber()); pe.initCause(e); throw pe; } finally { zipIn.closeEntry(); } } // end for } }
/** * Creates a new ParseException. * * @param msg * An error message. * @param lineNo * A line number associated with the message. * @param columnNo * A column number associated with the message. */ public RDFParseException(String msg, long lineNo, long columnNo) { super(msg + getLocationString(lineNo, columnNo)); this.lineNo = lineNo; this.columnNo = columnNo; }
protected void throwEOFException() throws RDFParseException { throw new RDFParseException("Unexpected end of file"); }
String msg = e.getMessage() + " in " + entry.getName(); RDFParseException pe = new RDFParseException(msg, e.getLineNumber(), e.getColumnNumber()); pe.initCause(e); throw pe; } finally {
/** * Creates a new ParseException wrapping another exception. The ParseException will inherit its message * from the supplied source exception. * * @param t * The source exception. * @param lineNo * A line number associated with the message. * @param columnNo * A column number associated with the message. */ public RDFParseException(String msg, Throwable t, long lineNo, long columnNo) { super(msg + getLocationString(lineNo, columnNo), t); this.lineNo = lineNo; this.columnNo = columnNo; }
protected void throwEOFException() throws RDFParseException { throw new RDFParseException("Unexpected end of file"); }
/** * Creates a new ParseException. * * @param msg * An error message. * @param lineNo * A line number associated with the message. * @param columnNo * A column number associated with the message. */ public RDFParseException(String msg, long lineNo, long columnNo) { super(msg + getLocationString(lineNo, columnNo)); this.lineNo = lineNo; this.columnNo = columnNo; }
/** * Reports a fatal error with associated line- and column number to the registered ParseErrorListener, if * any, and throws a <tt>ParseException</tt> afterwards. */ public static void reportFatalError(String msg, long lineNo, long columnNo, ParseErrorListener errListener) throws RDFParseException { if (errListener != null) { errListener.fatalError(msg, lineNo, columnNo); } throw new RDFParseException(msg, lineNo, columnNo); }
/** * Creates a new ParseException wrapping another exception. The ParseException will inherit its message * from the supplied source exception. * * @param t * The source exception. * @param lineNo * A line number associated with the message. * @param columnNo * A column number associated with the message. */ public RDFParseException(String msg, Throwable t, long lineNo, long columnNo) { super(msg + getLocationString(lineNo, columnNo), t); this.lineNo = lineNo; this.columnNo = columnNo; }
/** * Reports a fatal error with associated line- and column number to the registered ParseErrorListener, if * any, and throws a <tt>ParseException</tt> afterwards. */ public static void reportFatalError(String msg, long lineNo, long columnNo, ParseErrorListener errListener) throws RDFParseException { if (errListener != null) { errListener.fatalError(msg, lineNo, columnNo); } throw new RDFParseException(msg, lineNo, columnNo); }
/** * Creates a new ParseException wrapping another exception. The ParseException will inherit its message * from the supplied source exception. * * @param t * The source exception. * @param lineNo * A line number associated with the message. * @param columnNo * A column number associated with the message. */ public RDFParseException(String msg, Throwable t, long lineNo, long columnNo) { super(msg + getLocationString(lineNo, columnNo), t); this.lineNo = lineNo; this.columnNo = columnNo; }
/** * Reports a fatal error with associated line- and column number to the registered ParseErrorListener, if * any, and throws a <tt>ParseException</tt> afterwards. */ public static void reportFatalError(String msg, long lineNo, long columnNo, ParseErrorListener errListener) throws RDFParseException { if (errListener != null) { errListener.fatalError(msg, lineNo, columnNo); } throw new RDFParseException(msg, lineNo, columnNo); }