/** Creates a new instance of XMLStreamFilterImpl */ public XMLStreamFilterImpl(XMLStreamReader reader,StreamFilter filter){ fStreamReader = reader; this.fStreamFilter = filter; //this is debatable to initiate at an acceptable event, //but it's neccessary in order to pass the TCK and yet avoid skipping element try { if (fStreamFilter.accept(fStreamReader)) { fEventAccepted = true; } else { findNextEvent(); } }catch(XMLStreamException xs){ System.err.println("Error while creating a stream Filter"+xs); } }
@Test public void testReadingNamespace() { is = new java.io.ByteArrayInputStream(getXML().getBytes()); try { XMLStreamReader sr = factory.createFilteredReader(factory.createXMLStreamReader(is), (StreamFilter) filter); while (sr.hasNext()) { int eventType = sr.getEventType(); if (eventType == XMLStreamConstants.START_ELEMENT) { if (sr.getLocalName().equals(rootElement)) { Assert.assertTrue(sr.getNamespacePrefix(0).equals(prefixApple) && sr.getNamespaceURI(0).equals(namespaceURIApple)); } } eventType = sr.next(); } } catch (Exception ex) { Assert.fail("Exception: " + ex.getMessage()); } }
@Test public void testRootElementNamespace() { is = new java.io.ByteArrayInputStream(getXML().getBytes()); try { XMLStreamReader sr = factory.createFilteredReader(factory.createXMLStreamReader(is), (StreamFilter) filter); while (sr.hasNext()) { int eventType = sr.next(); if (eventType == XMLStreamConstants.START_ELEMENT) { if (sr.getLocalName().equals(rootElement)) { Assert.assertTrue(sr.getNamespacePrefix(0).equals(prefixApple) && sr.getNamespaceURI(0).equals(namespaceURIApple)); } } } } catch (Exception ex) { Assert.fail("Exception: " + ex.getMessage()); } }
@Test public void testChildElementNamespace() { is = new java.io.ByteArrayInputStream(getXML().getBytes()); try { XMLStreamReader sr = factory.createFilteredReader(factory.createXMLStreamReader(is), (StreamFilter) filter); while (sr.hasNext()) { int eventType = sr.next(); if (eventType == XMLStreamConstants.START_ELEMENT) { if (sr.getLocalName().equals(childElement)) { QName qname = sr.getName(); Assert.assertTrue(qname.getPrefix().equals(prefixApple) && qname.getNamespaceURI().equals(namespaceURIApple) && qname.getLocalPart().equals(childElement)); } } } } catch (Exception ex) { Assert.fail("Exception: " + ex.getMessage()); } }
@Test public void testNamespaceContext() { is = new java.io.ByteArrayInputStream(getXML().getBytes()); try { XMLStreamReader sr = factory.createFilteredReader(factory.createXMLStreamReader(is), (StreamFilter) filter); while (sr.hasNext()) { int eventType = sr.next(); if (eventType == XMLStreamConstants.START_ELEMENT) { if (sr.getLocalName().equals(childElement)) { NamespaceContext context = sr.getNamespaceContext(); Assert.assertTrue(context.getPrefix(namespaceURIApple).equals(prefixApple)); } } } } catch (Exception ex) { Assert.fail("Exception: " + ex.getMessage()); } }
@Test public void testNamespaceCount() { is = new java.io.ByteArrayInputStream(getXML().getBytes()); try { XMLStreamReader sr = factory.createFilteredReader(factory.createXMLStreamReader(is), (StreamFilter) filter); while (sr.hasNext()) { int eventType = sr.next(); if (eventType == XMLStreamConstants.START_ELEMENT) { if (sr.getLocalName().equals(rootElement)) { int count = sr.getNamespaceCount(); Assert.assertTrue(count == 3); } } } } catch (Exception ex) { Assert.fail("Exception: " + ex.getMessage()); } }
private XMLStreamReader createStreamReader(HasNextTypeFilter f) { try { XMLInputFactory factory = XMLInputFactory.newInstance(); factory = XMLInputFactory.newInstance(); return factory.createFilteredReader(factory.createXMLStreamReader(this.getClass().getResourceAsStream(INPUT_FILE)), (StreamFilter) f); } catch (Exception e) { e.printStackTrace(); Assert.fail("Unexpected Exception: " + e.getMessage()); return null; } }
public static XMLStreamReader createFilteredReader(XMLStreamReader reader, StreamFilter filter) { XMLInputFactory factory = getXMLInputFactory(); try { return factory.createFilteredReader(reader, filter); } catch (XMLStreamException e) { throw new RuntimeException("Cant' create XMLStreamReader", e); } finally { returnXMLInputFactory(factory); } }
public StAXFilteredParser(XMLStreamReader reader, StreamFilter filter) { super(reader); _filter = filter; }
public void setFilter(StreamFilter filter) { _filter = filter; }
@Override public XMLStreamReader createFilteredReader(XMLStreamReader reader, StreamFilter filter) throws XMLStreamException { throw new UnsupportedOperationException("Not supported yet."); }
@Override public XMLStreamReader createFilteredReader(XMLStreamReader reader, StreamFilter filter) throws XMLStreamException { return defaultImpl.createFilteredReader(reader, filter); }
@Override public XMLStreamReader createFilteredReader(XMLStreamReader reader, StreamFilter filter) throws XMLStreamException { return null; }
public XMLStreamReader createFilteredReader(XMLStreamReader reader, StreamFilter filter) throws XMLStreamException { return new FilteredStreamReader(reader, filter); }
FilteredStreamReader(XMLStreamReader reader, StreamFilter filter) { super(reader); this.reader = reader; this.filter = filter; }
public XMLStreamReader createFilteredReader(XMLStreamReader arg0, StreamFilter arg1) throws XMLStreamException { // TODO Auto-generated method stub return null; }