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 } }
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 } }
/** * 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); } }
RDFParseException pe = new RDFParseException(msg, e.getLineNumber(), e.getColumnNumber()); pe.initCause(e); throw pe;