/** * This is protected rather than private to allow subclassing, * however, reimplementors should be aware that the default configuration * via {@link #create()} includes functionality that is not simply * included. The most important is to do with character encoding checking. * A common user error is to not have correct XML encoding, or to open * files with the wrong encodings on their reader. The {@link #setEncoding(String)} * method does what it can to try and detect these user errors, and is worth the effort. * Consider using {@link SAXParserWithEncodingCheck} * @param rdr */ protected RDFXMLParser(XMLReader rdr) { super(); saxParser = rdr; try { SAX2RDF.installHandlers(rdr, this); } catch (SAXException e) { throw new RuntimeException("Supposedly impossible:", e); } }
/** * Factory method to create a new SAX2RDF. * Use * {@link #getHandlers} or {@link #setHandlersWith} to provide * a {@link StatementHandler}, and usually an {@link org.xml.sax.ErrorHandler} * * @param base The retrieval URL, or the base URI to be * used while parsing. * @return A new SAX2RDF * @throws ParseException */ static public SAX2RDF create(String base) throws SAXParseException { return new SAX2RDF(base,""); } /**
@Override public void close() { // System.err.println("closing;"); if (!closed) { super.close(); closed = true; } }
SAX2RDF(String base, String lang) throws SAXParseException { super(base,lang); initParse(base); }
/** * Begin the scope of a prefix-URI Namespace mapping. * * <p> * This is passed to any {@link NamespaceHandler} associated with this * parser. It can be called before the initial <code>startElement</code> * event, or other events associated with the elements being processed. When * building a Jena Model, it is not required to match this with * corresponding <code>endPrefixMapping</code> events. Other * {@link NamespaceHandler}s may be fussier. When building a Jena Model, * the prefix bindings are remembered with the Model, and may be used in * some output routines. It is permitted to not call this method for * prefixes declared in the outer context, in which case, any output routine * will need to use a gensym for such namespaces. * </p> * * @param prefix * The Namespace prefix being declared. * @param uri * The Namespace URI the prefix is mapped to. * */ @Override public void startPrefixMapping(String prefix, String uri) throws SAXParseException { super.startPrefixMapping(prefix, uri); }
SAX2RDF(String base, String lang) throws SAXParseException { super(base,lang); initParse(base); }
/** * Begin the scope of a prefix-URI Namespace mapping. * * <p> * This is passed to any {@link NamespaceHandler} associated with this * parser. It can be called before the initial <code>startElement</code> * event, or other events associated with the elements being processed. When * building a Jena Model, it is not required to match this with * corresponding <code>endPrefixMapping</code> events. Other * {@link NamespaceHandler}s may be fussier. When building a Jena Model, * the prefix bindings are remembered with the Model, and may be used in * some output routines. It is permitted to not call this method for * prefixes declared in the outer context, in which case, any output routine * will need to use a gensym for such namespaces. * </p> * * @param prefix * The Namespace prefix being declared. * @param uri * The Namespace URI the prefix is mapped to. * */ @Override public void startPrefixMapping(String prefix, String uri) throws SAXParseException { super.startPrefixMapping(prefix, uri); }
/** * This is protected rather than private to allow subclassing, * however, reimplementors should be aware that the default configuration * via {@link #create()} includes functionality that is not simply * included. The most important is to do with character encoding checking. * A common user error is to not have correct XML encoding, or to open * files with the wrong encodings on their reader. The {@link #setEncoding(String)} * method does what it can to try and detect these user errors, and is worth the effort. * Consider using {@link SAXParserWithEncodingCheck} * @param rdr */ protected RDFXMLParser(XMLReader rdr) { super(); saxParser = rdr; try { SAX2RDF.installHandlers(rdr, this); } catch (SAXException e) { throw new RuntimeException("Supposedly impossible:", e); } }
/** * Factory method to create a new SAX2RDF. * Use * {@link #getHandlers} or {@link #setHandlersWith} to provide * a {@link StatementHandler}, and usually an {@link org.xml.sax.ErrorHandler} * * @param base The retrieval URL, or the base URI to be * used while parsing. * @return A new SAX2RDF * @throws ParseException */ static public SAX2RDF create(String base) throws SAXParseException { return new SAX2RDF(base,""); } /**
@Override public void close() { // System.err.println("closing;"); if (!closed) { super.close(); closed = true; } }
void loadXMLModel(Model m2, InputStream in, RDFEHArray eh2) throws SAXException, IOException { XMLReader saxParser = XMLReaderFactory.createXMLReader(); SAX2Model handler = SAX2Model.create(base, m2); SAX2RDF.installHandlers(saxParser, handler); handler.setErrorHandler(eh2); InputSource ins = new InputSource(in); ins.setSystemId(base); try { try { saxParser.parse(ins); } finally { handler.close(); } } catch (SAXParseException e) { // already reported, leave it be. } }
/** * Factory method to create a new SAX2RDF. * This is particularly * intended for when parsing a non-root element within * an XML document. In which case the application * needs to find this value in the outer context. * Optionally, namespace prefixes can be passed from the * outer context using {@link #startPrefixMapping}. * @param base The retrieval URL, or the base URI to be * used while parsing. Use * {@link #getHandlers} or {@link #setHandlersWith} to provide * a {@link StatementHandler}, and usually an {@link org.xml.sax.ErrorHandler} * @param lang The current value of xml:lang when parsing starts, usually "". * @return A new SAX2RDF * @throws ParseException If base or lang is bad. */ static public SAX2RDF create(String base, String lang) throws SAXParseException { return new SAX2RDF(base,lang); }
void loadXMLModel(Model m2, InputStream in, RDFEHArray eh2) throws SAXException, IOException { XMLReader saxParser = XMLReaderFactory.createXMLReader(); SAX2Model handler = SAX2Model.create(base, m2); SAX2RDF.installHandlers(saxParser, handler); handler.setErrorHandler(eh2); InputSource ins = new InputSource(in); ins.setSystemId(base); try { try { saxParser.parse(ins); } finally { handler.close(); } } catch (SAXParseException e) { // already reported, leave it be. } }
/** * Factory method to create a new SAX2RDF. * This is particularly * intended for when parsing a non-root element within * an XML document. In which case the application * needs to find this value in the outer context. * Optionally, namespace prefixes can be passed from the * outer context using {@link #startPrefixMapping}. * @param base The retrieval URL, or the base URI to be * used while parsing. Use * {@link #getHandlers} or {@link #setHandlersWith} to provide * a {@link StatementHandler}, and usually an {@link org.xml.sax.ErrorHandler} * @param lang The current value of xml:lang when parsing starts, usually "". * @return A new SAX2RDF * @throws ParseException If base or lang is bad. */ static public SAX2RDF create(String base, String lang) throws SAXParseException { return new SAX2RDF(base,lang); }
synchronized public void parse(InputSource input, String base) throws IOException, SAXException { // Make sure we have a sane state for // Namespace processing. initParse(base,""); SAX2RDF.installHandlers(saxParser, this); initEncodingChecks(input); try { saxParser.parse(input); } catch (UTFDataFormatException e) { generalError(ERR_UTF_ENCODING, e); } catch (IOException e) { generalError(ERR_GENERIC_IO, e); } catch (WrappedException wrapped) { wrapped.throwMe(); } catch (FatalParsingErrorException e) { // ignore this. } finally { afterParse(); } }
synchronized public void parse(InputSource input, String base) throws IOException, SAXException { // Make sure we have a sane state for // Namespace processing. initParse(base,""); SAX2RDF.installHandlers(saxParser, this); initEncodingChecks(input); try { saxParser.parse(input); } catch (UTFDataFormatException e) { generalError(ERR_UTF_ENCODING, e); } catch (IOException e) { generalError(ERR_GENERIC_IO, e); } catch (WrappedException wrapped) { wrapped.throwMe(); } catch (FatalParsingErrorException e) { // ignore this. } finally { afterParse(); } }
XMLReader saxParser = XMLReaderFactory.createXMLReader(); SAX2Model handler = SAX2Model.create("http://example.org/", m2, "fr"); SAX2RDF.installHandlers(saxParser, handler); handler.setErrorHandler(eh2);
XMLReader saxParser = XMLReaderFactory.createXMLReader(); SAX2Model handler = SAX2Model.create("http://example.org/", m2, "fr"); SAX2RDF.installHandlers(saxParser, handler); handler.setErrorHandler(eh2);