javax.xml.stream.StreamFilter Java Examples

The following examples show how to use javax.xml.stream.StreamFilter. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: Bug6481678.java    From openjdk-jdk9 with GNU General Public License v2.0 6 votes vote down vote up
@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());
    }
}
 
Example #2
Source File: XMLStreamFilterImpl.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 6 votes vote down vote up
/** 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);
        }
    }
 
Example #3
Source File: XMLStreamFilterImpl.java    From Bytecoder with Apache License 2.0 6 votes vote down vote up
/** 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);
        }
    }
 
Example #4
Source File: XMLStreamFilterImpl.java    From openjdk-jdk9 with GNU General Public License v2.0 6 votes vote down vote up
/** 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);
        }
    }
 
Example #5
Source File: XMLStreamFilterImpl.java    From openjdk-jdk8u with GNU General Public License v2.0 6 votes vote down vote up
/** 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);
        }
    }
 
Example #6
Source File: Bug6481678.java    From openjdk-jdk9 with GNU General Public License v2.0 6 votes vote down vote up
@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());
    }
}
 
Example #7
Source File: Bug6481678.java    From openjdk-jdk9 with GNU General Public License v2.0 6 votes vote down vote up
@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());
    }
}
 
Example #8
Source File: Bug6481678.java    From openjdk-jdk9 with GNU General Public License v2.0 6 votes vote down vote up
@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());
    }
}
 
Example #9
Source File: XMLStreamFilterImpl.java    From JDKSourceCode1.8 with MIT License 6 votes vote down vote up
/** 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);
        }
    }
 
Example #10
Source File: XMLStreamFilterImpl.java    From jdk8u60 with GNU General Public License v2.0 6 votes vote down vote up
/** 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);
        }
    }
 
Example #11
Source File: Bug6481678.java    From openjdk-jdk9 with GNU General Public License v2.0 6 votes vote down vote up
@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());
    }
}
 
Example #12
Source File: XMLStreamFilterImpl.java    From hottub with GNU General Public License v2.0 6 votes vote down vote up
/** 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);
        }
    }
 
Example #13
Source File: XMLStreamFilterImpl.java    From TencentKona-8 with GNU General Public License v2.0 6 votes vote down vote up
/** 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);
        }
    }
 
Example #14
Source File: XMLStreamFilterImpl.java    From openjdk-8-source with GNU General Public License v2.0 6 votes vote down vote up
/** 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);
        }
    }
 
Example #15
Source File: XMLStreamFilterImpl.java    From openjdk-8 with GNU General Public License v2.0 6 votes vote down vote up
/** 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);
        }
    }
 
Example #16
Source File: XMLStreamFilterImpl.java    From jdk1.8-source-analysis with Apache License 2.0 6 votes vote down vote up
/** 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);
        }
    }
 
Example #17
Source File: StaxUtils.java    From cxf with Apache License 2.0 5 votes vote down vote up
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);
    }
}
 
Example #18
Source File: HasNextTest.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
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;
        }
    }
 
Example #19
Source File: StAXFilteredParser.java    From openjdk-8 with GNU General Public License v2.0 4 votes vote down vote up
public StAXFilteredParser(XMLStreamReader reader, StreamFilter filter) {
    super(reader);
    _filter = filter;
}
 
Example #20
Source File: StAXFilteredParser.java    From openjdk-8-source with GNU General Public License v2.0 4 votes vote down vote up
public void setFilter(StreamFilter filter) {
    _filter = filter;
}
 
Example #21
Source File: StAXFilteredParser.java    From openjdk-8-source with GNU General Public License v2.0 4 votes vote down vote up
public StAXFilteredParser(XMLStreamReader reader, StreamFilter filter) {
    super(reader);
    _filter = filter;
}
 
Example #22
Source File: StAXFilteredParser.java    From TencentKona-8 with GNU General Public License v2.0 4 votes vote down vote up
public void setFilter(StreamFilter filter) {
    _filter = filter;
}
 
Example #23
Source File: StAXFilteredParser.java    From hottub with GNU General Public License v2.0 4 votes vote down vote up
public void setFilter(StreamFilter filter) {
    _filter = filter;
}
 
Example #24
Source File: StAXFilteredParser.java    From hottub with GNU General Public License v2.0 4 votes vote down vote up
public StAXFilteredParser(XMLStreamReader reader, StreamFilter filter) {
    super(reader);
    _filter = filter;
}
 
Example #25
Source File: XMLInputFactoryImpl.java    From openjdk-jdk9 with GNU General Public License v2.0 4 votes vote down vote up
@Override
public XMLStreamReader createFilteredReader(XMLStreamReader reader, StreamFilter filter)
        throws XMLStreamException {
    return null;
}
 
Example #26
Source File: XMLInputFactoryWrapper.java    From openjdk-jdk9 with GNU General Public License v2.0 4 votes vote down vote up
@Override
public XMLStreamReader createFilteredReader(XMLStreamReader reader, StreamFilter filter)
        throws XMLStreamException {
    return defaultImpl.createFilteredReader(reader, filter);
}
 
Example #27
Source File: MyInputFactory.java    From openjdk-jdk9 with GNU General Public License v2.0 4 votes vote down vote up
@Override
public XMLStreamReader createFilteredReader(XMLStreamReader reader, StreamFilter filter) throws XMLStreamException {
    throw new UnsupportedOperationException("Not supported yet.");
}
 
Example #28
Source File: StAXFilteredParser.java    From jdk8u60 with GNU General Public License v2.0 4 votes vote down vote up
public StAXFilteredParser(XMLStreamReader reader, StreamFilter filter) {
    super(reader);
    _filter = filter;
}
 
Example #29
Source File: StAXFilteredParser.java    From jdk8u60 with GNU General Public License v2.0 4 votes vote down vote up
public void setFilter(StreamFilter filter) {
    _filter = filter;
}
 
Example #30
Source File: StAXFilteredParser.java    From openjdk-8 with GNU General Public License v2.0 4 votes vote down vote up
public void setFilter(StreamFilter filter) {
    _filter = filter;
}