/** * Parse the StAX XML reader passed at construction-time. * <p><b>NOTE:</b>: The given {@code InputSource} is not read, but ignored. * @param ignored is ignored * @throws SAXException a SAX exception, possibly wrapping a {@code XMLStreamException} */ @Override public final void parse(InputSource ignored) throws SAXException { parse(); }
/** * End the prefix mapping for the given prefix. * @see org.xml.sax.ContentHandler#endPrefixMapping(String) */ protected void endPrefixMapping(String prefix) throws SAXException { if (getContentHandler() != null && this.namespaces.containsKey(prefix)) { getContentHandler().endPrefixMapping(prefix); this.namespaces.remove(prefix); } }
private void parse() throws SAXException { try { parseInternal(); } catch (XMLStreamException ex) { Locator locator = null; if (ex.getLocation() != null) { locator = new StaxLocator(ex.getLocation()); } SAXParseException saxException = new SAXParseException(ex.getMessage(), locator, ex); if (getErrorHandler() != null) { getErrorHandler().fatalError(saxException); } else { throw saxException; } } }
@Test public void contentHandlerNamespacesNoPrefixes() throws Exception { standardReader.setFeature("http://xml.org/sax/features/namespaces", true); standardReader.setFeature("http://xml.org/sax/features/namespace-prefixes", false); standardReader.parse(new InputSource(createTestInputStream())); AbstractStaxXMLReader staxXmlReader = createStaxXmlReader(createTestInputStream()); ContentHandler contentHandler = mockContentHandler(); staxXmlReader.setFeature("http://xml.org/sax/features/namespaces", true); staxXmlReader.setFeature("http://xml.org/sax/features/namespace-prefixes", false); staxXmlReader.setContentHandler(contentHandler); staxXmlReader.parse(new InputSource()); verifyIdenticalInvocations(standardContentHandler, contentHandler); }
@Test public void lexicalHandler() throws Exception { Resource testLexicalHandlerXml = new ClassPathResource("testLexicalHandler.xml", getClass()); LexicalHandler expectedLexicalHandler = mockLexicalHandler(); standardReader.setContentHandler(null); standardReader.setProperty("http://xml.org/sax/properties/lexical-handler", expectedLexicalHandler); standardReader.parse(new InputSource(testLexicalHandlerXml.getInputStream())); inputFactory.setProperty("javax.xml.stream.isCoalescing", Boolean.FALSE); inputFactory.setProperty("http://java.sun.com/xml/stream/properties/report-cdata-event", Boolean.TRUE); inputFactory.setProperty("javax.xml.stream.isReplacingEntityReferences", Boolean.FALSE); inputFactory.setProperty("javax.xml.stream.isSupportingExternalEntities", Boolean.FALSE); LexicalHandler actualLexicalHandler = mockLexicalHandler(); willAnswer(invocation -> invocation.getArguments()[0] = "element"). given(actualLexicalHandler).startDTD(anyString(), anyString(), anyString()); AbstractStaxXMLReader staxXmlReader = createStaxXmlReader(testLexicalHandlerXml.getInputStream()); staxXmlReader.setProperty("http://xml.org/sax/properties/lexical-handler", actualLexicalHandler); staxXmlReader.parse(new InputSource()); // TODO: broken comparison since Mockito 2.2 upgrade // verifyIdenticalInvocations(expectedLexicalHandler, actualLexicalHandler); }
@Test public void contentHandlerNamespacesPrefixes() throws Exception { standardReader.setFeature("http://xml.org/sax/features/namespaces", true); standardReader.setFeature("http://xml.org/sax/features/namespace-prefixes", true); standardReader.parse(new InputSource(createTestInputStream())); AbstractStaxXMLReader staxXmlReader = createStaxXmlReader(createTestInputStream()); ContentHandler contentHandler = mockContentHandler(); staxXmlReader.setFeature("http://xml.org/sax/features/namespaces", true); staxXmlReader.setFeature("http://xml.org/sax/features/namespace-prefixes", true); staxXmlReader.setContentHandler(contentHandler); staxXmlReader.parse(new InputSource()); verifyIdenticalInvocations(standardContentHandler, contentHandler); }
private void parse() throws SAXException { try { parseInternal(); } catch (XMLStreamException ex) { Locator locator = null; if (ex.getLocation() != null) { locator = new StaxLocator(ex.getLocation()); } SAXParseException saxException = new SAXParseException(ex.getMessage(), locator, ex); if (getErrorHandler() != null) { getErrorHandler().fatalError(saxException); } else { throw saxException; } } }
/** * Parse the StAX XML reader passed at construction-time. * <p><b>NOTE:</b>: The given system identifier is not read, but ignored. * @param ignored is ignored * @throws SAXException a SAX exception, possibly wrapping a {@code XMLStreamException} */ @Override public final void parse(String ignored) throws SAXException { parse(); }
/** * Start the prefix mapping for the given prefix. * @see org.xml.sax.ContentHandler#startPrefixMapping(String, String) */ protected void startPrefixMapping(@Nullable String prefix, String namespace) throws SAXException { if (getContentHandler() != null && StringUtils.hasLength(namespace)) { if (prefix == null) { prefix = ""; } if (!namespace.equals(this.namespaces.get(prefix))) { getContentHandler().startPrefixMapping(prefix, namespace); this.namespaces.put(prefix, namespace); } } }
@Test public void contentHandlerNoNamespacesPrefixes() throws Exception { standardReader.setFeature("http://xml.org/sax/features/namespaces", false); standardReader.setFeature("http://xml.org/sax/features/namespace-prefixes", true); standardReader.parse(new InputSource(createTestInputStream())); AbstractStaxXMLReader staxXmlReader = createStaxXmlReader(createTestInputStream()); ContentHandler contentHandler = mockContentHandler(); staxXmlReader.setFeature("http://xml.org/sax/features/namespaces", false); staxXmlReader.setFeature("http://xml.org/sax/features/namespace-prefixes", true); staxXmlReader.setContentHandler(contentHandler); staxXmlReader.parse(new InputSource()); verifyIdenticalInvocations(standardContentHandler, contentHandler); }
private void parse() throws SAXException { try { parseInternal(); } catch (XMLStreamException ex) { Locator locator = null; if (ex.getLocation() != null) { locator = new StaxLocator(ex.getLocation()); } SAXParseException saxException = new SAXParseException(ex.getMessage(), locator, ex); if (getErrorHandler() != null) { getErrorHandler().fatalError(saxException); } else { throw saxException; } } }
/** * Parse the StAX XML reader passed at construction-time. * <p><b>NOTE:</b>: The given {@code InputSource} is not read, but ignored. * @param ignored is ignored * @throws SAXException a SAX exception, possibly wrapping a {@code XMLStreamException} */ @Override public final void parse(InputSource ignored) throws SAXException { parse(); }
/** * End the prefix mapping for the given prefix. * @see org.xml.sax.ContentHandler#endPrefixMapping(String) */ protected void endPrefixMapping(String prefix) throws SAXException { if (getContentHandler() != null && this.namespaces.containsKey(prefix)) { getContentHandler().endPrefixMapping(prefix); this.namespaces.remove(prefix); } }
private void parse() throws SAXException { try { parseInternal(); } catch (XMLStreamException ex) { Locator locator = null; if (ex.getLocation() != null) { locator = new StaxLocator(ex.getLocation()); } SAXParseException saxException = new SAXParseException(ex.getMessage(), locator, ex); if (getErrorHandler() != null) { getErrorHandler().fatalError(saxException); } else { throw saxException; } } }
/** * Parse the StAX XML reader passed at construction-time. * <p><b>NOTE:</b>: The given system identifier is not read, but ignored. * @param ignored is ignored * @throws SAXException a SAX exception, possibly wrapping a {@code XMLStreamException} */ @Override public final void parse(String ignored) throws SAXException { parse(); }
/** * Start the prefix mapping for the given prefix. * @see org.xml.sax.ContentHandler#startPrefixMapping(String, String) */ protected void startPrefixMapping(@Nullable String prefix, String namespace) throws SAXException { if (getContentHandler() != null && StringUtils.hasLength(namespace)) { if (prefix == null) { prefix = ""; } if (!namespace.equals(this.namespaces.get(prefix))) { getContentHandler().startPrefixMapping(prefix, namespace); this.namespaces.put(prefix, namespace); } } }
private void parse() throws SAXException { try { parseInternal(); } catch (XMLStreamException ex) { Locator locator = null; if (ex.getLocation() != null) { locator = new StaxLocator(ex.getLocation()); } SAXParseException saxException = new SAXParseException(ex.getMessage(), locator, ex); if (getErrorHandler() != null) { getErrorHandler().fatalError(saxException); } else { throw saxException; } } }
/** * Parse the StAX XML reader passed at construction-time. * <p><b>NOTE:</b>: The given <code>InputSource</code> is not read, but ignored. * @param ignored is ignored * @throws SAXException a SAX exception, possibly wrapping a <code>XMLStreamException</code> */ public final void parse(InputSource ignored) throws SAXException { parse(); }
/** * Ends the prefix mapping for the given prefix. * @see org.xml.sax.ContentHandler#endPrefixMapping(String) */ protected void endPrefixMapping(String prefix) throws SAXException { if (getContentHandler() != null) { if (namespaces.containsKey(prefix)) { getContentHandler().endPrefixMapping(prefix); namespaces.remove(prefix); } } }
/** * Parse the StAX XML reader passed at construction-time. * <p><b>NOTE:</b>: The given system identifier is not read, but ignored. * @param ignored is ignored * @throws SAXException A SAX exception, possibly wrapping a <code>XMLStreamException</code> */ public final void parse(String ignored) throws SAXException { parse(); }