Java 类javax.xml.stream.EventFilter 实例源码

项目:openjdk-jdk10    文件:Bug6976938Test.java   
public void eventReaderTest(XMLInputFactory xif) {
    XMLEventReader eventReader = null;
    try {
        eventReader = xif.createXMLEventReader(this.getClass().getResourceAsStream(INPUT_FILE));
        XMLEventReader filteredEventReader = xif.createFilteredReader(eventReader, new EventFilter() {
            public boolean accept(XMLEvent event) {
                if (!event.isStartElement()) {
                    return false;
                }
                QName elementQName = event.asStartElement().getName();
                if ((elementQName.getLocalPart().equals(ATTACHMENT_NAME.getLocalPart()) || elementQName.getLocalPart().equals("Attachment"))
                        && elementQName.getNamespaceURI().equals(VF_GENERIC_TT_NAMESPACE)) {
                    return true;
                }
                return false;
            }
        });
        if (filteredEventReader.hasNext()) {
            System.out.println("containsAttachments() returns true");
        }
    } catch (Exception e) {
        e.printStackTrace();
        Assert.fail(e.getMessage());

    } finally {
        if (eventReader != null) {
            try {
                eventReader.close();
            } catch (XMLStreamException xse) {
                // Ignored by intention
            }
        }
    }
}
项目:datasource    文件:XmlFileRecordReader.java   
/**
 * @param dataFile
 * @throws FileNotFoundException
 * @throws XMLStreamException
 * @throws JAXBException
 */
private void initialize(InputStream is) throws FileNotFoundException, XMLStreamException, JAXBException {
    this.is = is;
    ctx = JAXBContext.newInstance(entryClass);
    um = ctx.createUnmarshaller();
    XMLInputFactory xmlif = XMLInputFactory.newInstance();
    xmler = xmlif.createXMLEventReader(is);
    EventFilter filter = new EventFilter() {
        public boolean accept(XMLEvent event) {
            return event.isStartElement();
        }
    };
    xmlfer = xmlif.createFilteredReader(xmler, filter);
    // Jump to the first element in the document, the enclosing Uniprot in
    // the case of uniprot
    // xml
    StartElement e = (StartElement) xmlfer.nextEvent();
    advanceToRecordWithTaxonOfInterest();
}
项目:teiid    文件:TestXMLSystemFunctions.java   
@Test public void testRepairingNamespaces() throws Exception {
    XMLOutputFactory factory = XMLSystemFunctions.getOutputFactory(true);
    ByteArrayOutputStream baos = new ByteArrayOutputStream();
    XMLEventWriter writer = factory.createXMLEventWriter(baos);
    XMLEventReader reader = XMLType.getXmlInputFactory().createXMLEventReader(new StringReader("<a xmlns:x=\"http://foo\"><b x:y=\"1\"/></a>"));
    reader.nextTag();
    reader = XMLType.getXmlInputFactory().createFilteredReader(reader, new EventFilter() {

        @Override
        public boolean accept(XMLEvent arg0) {
            if (arg0.isStartDocument() || arg0.isEndDocument()) {
                return false;
            }
            if (arg0.isEndElement() && ((EndElement)arg0).getName().getLocalPart().equals("a")) {
                return false;
            }
            return true;
        }
    });
    writer.add(reader);
    writer.close();
    assertEquals("<b xmlns=\"\" xmlns:x=\"http://foo\" x:y=\"1\"></b>", new String(baos.toByteArray(), "UTF-8"));
}
项目:openjdk9    文件:Bug6976938Test.java   
public void eventReaderTest(XMLInputFactory xif) {
    XMLEventReader eventReader = null;
    try {
        eventReader = xif.createXMLEventReader(this.getClass().getResourceAsStream(INPUT_FILE));
        XMLEventReader filteredEventReader = xif.createFilteredReader(eventReader, new EventFilter() {
            public boolean accept(XMLEvent event) {
                if (!event.isStartElement()) {
                    return false;
                }
                QName elementQName = event.asStartElement().getName();
                if ((elementQName.getLocalPart().equals(ATTACHMENT_NAME.getLocalPart()) || elementQName.getLocalPart().equals("Attachment"))
                        && elementQName.getNamespaceURI().equals(VF_GENERIC_TT_NAMESPACE)) {
                    return true;
                }
                return false;
            }
        });
        if (filteredEventReader.hasNext()) {
            System.out.println("containsAttachments() returns true");
        }
    } catch (Exception e) {
        e.printStackTrace();
        Assert.fail(e.getMessage());

    } finally {
        if (eventReader != null) {
            try {
                eventReader.close();
            } catch (XMLStreamException xse) {
                // Ignored by intention
            }
        }
    }
}
项目:Wikipedia-Corpus-Converter    文件:I5Writer.java   
private EventFilter createEventFilter() {
    EventFilter filter = new EventFilter() {            
        @Override
        public boolean accept(XMLEvent event) {
            if (event.isEndDocument() /*|| event.getEventType() == XMLStreamConstants.DTD*/) return false;
            else return true;
        }
    };

    return filter;

}
项目:OpenJSharp    文件:StAXFilteredEvent.java   
public StAXFilteredEvent(XMLEventReader reader, EventFilter filter) throws XMLStreamException
{
    eventReader = reader;
    _filter = filter;
}
项目:OpenJSharp    文件:StAXFilteredEvent.java   
public void setFilter(EventFilter filter) {
    _filter = filter;
}
项目:OpenJSharp    文件:EventFilterSupport.java   
/** Creates a new instance of EventFilterSupport */
public EventFilterSupport(XMLEventReader eventReader, EventFilter eventFilter) {
    setParent(eventReader);
    fEventFilter = eventFilter;
}
项目:openjdk-jdk10    文件:StAXFilteredEvent.java   
public StAXFilteredEvent(XMLEventReader reader, EventFilter filter) throws XMLStreamException
{
    eventReader = reader;
    _filter = filter;
}
项目:openjdk-jdk10    文件:StAXFilteredEvent.java   
public void setFilter(EventFilter filter) {
    _filter = filter;
}
项目:openjdk-jdk10    文件:EventFilterSupport.java   
/** Creates a new instance of EventFilterSupport */
public EventFilterSupport(XMLEventReader eventReader, EventFilter eventFilter) {
    setParent(eventReader);
    fEventFilter = eventFilter;
}
项目:openjdk-jdk10    文件:MyInputFactory.java   
@Override
public XMLEventReader createFilteredReader(XMLEventReader reader, EventFilter filter) throws XMLStreamException {
    throw new UnsupportedOperationException("Not supported yet.");
}
项目:openjdk-jdk10    文件:XMLInputFactoryWrapper.java   
@Override
public XMLEventReader createFilteredReader(XMLEventReader reader, EventFilter filter)
        throws XMLStreamException {
    return defaultImpl.createFilteredReader(reader, filter);
}
项目:openjdk-jdk10    文件:XMLInputFactoryImpl.java   
@Override
public XMLEventReader createFilteredReader(XMLEventReader reader, EventFilter filter)
        throws XMLStreamException {
    return null;
}
项目:openjdk9    文件:StAXFilteredEvent.java   
public StAXFilteredEvent(XMLEventReader reader, EventFilter filter) throws XMLStreamException
{
    eventReader = reader;
    _filter = filter;
}
项目:openjdk9    文件:StAXFilteredEvent.java   
public void setFilter(EventFilter filter) {
    _filter = filter;
}
项目:openjdk9    文件:EventFilterSupport.java   
/** Creates a new instance of EventFilterSupport */
public EventFilterSupport(XMLEventReader eventReader, EventFilter eventFilter) {
    setParent(eventReader);
    fEventFilter = eventFilter;
}
项目:openjdk9    文件:MyInputFactory.java   
@Override
public XMLEventReader createFilteredReader(XMLEventReader reader, EventFilter filter) throws XMLStreamException {
    throw new UnsupportedOperationException("Not supported yet.");
}
项目:openjdk9    文件:XMLInputFactoryImpl.java   
@Override
public XMLEventReader createFilteredReader(XMLEventReader reader, EventFilter filter)
        throws XMLStreamException {
    return null;
}
项目:lookaside_java-1.8.0-openjdk    文件:StAXFilteredEvent.java   
public StAXFilteredEvent(XMLEventReader reader, EventFilter filter) throws XMLStreamException
{
    eventReader = reader;
    _filter = filter;
}
项目:lookaside_java-1.8.0-openjdk    文件:StAXFilteredEvent.java   
public void setFilter(EventFilter filter) {
    _filter = filter;
}
项目:lookaside_java-1.8.0-openjdk    文件:EventFilterSupport.java   
/** Creates a new instance of EventFilterSupport */
public EventFilterSupport(XMLEventReader eventReader, EventFilter eventFilter) {
    setParent(eventReader);
    fEventFilter = eventFilter;
}
项目:javify    文件:XMLInputFactoryImpl.java   
public XMLEventReader createFilteredReader(XMLEventReader reader,
                                           EventFilter filter)
  throws XMLStreamException
{
  return new FilteredEventReader(reader, filter);
}
项目:javify    文件:FilteredEventReader.java   
FilteredEventReader(XMLEventReader reader, EventFilter filter)
{
  super(reader);
  this.filter = filter;
}
项目:jvm-stm    文件:XMLInputFactoryImpl.java   
public XMLEventReader createFilteredReader(XMLEventReader reader,
                                           EventFilter filter)
  throws XMLStreamException
{
  return new FilteredEventReader(reader, filter);
}
项目:jvm-stm    文件:FilteredEventReader.java   
FilteredEventReader(XMLEventReader reader, EventFilter filter)
{
  super(reader);
  this.filter = filter;
}
项目:service-epitope    文件:XMLFilteredEventReader.java   
public XMLFilteredEventReader withFilter(EventFilter filter) {
    this.f = filter;
    return this;
}
项目:jettison    文件:AbstractXMLInputFactory.java   
public XMLEventReader createFilteredReader(XMLEventReader arg0, EventFilter arg1) throws XMLStreamException {
    // TODO Auto-generated method stub
    return null;
}
项目:infobip-open-jdk-8    文件:StAXFilteredEvent.java   
public StAXFilteredEvent(XMLEventReader reader, EventFilter filter) throws XMLStreamException
{
    eventReader = reader;
    _filter = filter;
}
项目:infobip-open-jdk-8    文件:StAXFilteredEvent.java   
public void setFilter(EventFilter filter) {
    _filter = filter;
}
项目:infobip-open-jdk-8    文件:EventFilterSupport.java   
/** Creates a new instance of EventFilterSupport */
public EventFilterSupport(XMLEventReader eventReader, EventFilter eventFilter) {
    setParent(eventReader);
    fEventFilter = eventFilter;
}
项目:OLD-OpenJDK8    文件:StAXFilteredEvent.java   
public StAXFilteredEvent(XMLEventReader reader, EventFilter filter) throws XMLStreamException
{
    eventReader = reader;
    _filter = filter;
}
项目:OLD-OpenJDK8    文件:StAXFilteredEvent.java   
public void setFilter(EventFilter filter) {
    _filter = filter;
}
项目:OLD-OpenJDK8    文件:EventFilterSupport.java   
/** Creates a new instance of EventFilterSupport */
public EventFilterSupport(XMLEventReader eventReader, EventFilter eventFilter) {
    setParent(eventReader);
    fEventFilter = eventFilter;
}
项目:werval    文件:XMLInputFactoryImpl.java   
@Override
public XMLEventReader createFilteredReader( XMLEventReader reader, EventFilter filter )
    throws XMLStreamException
{
    return delegate.createFilteredReader( reader, filter );
}
项目:JamVM-PH    文件:XMLInputFactoryImpl.java   
public XMLEventReader createFilteredReader(XMLEventReader reader,
                                           EventFilter filter)
  throws XMLStreamException
{
  return new FilteredEventReader(reader, filter);
}
项目:JamVM-PH    文件:FilteredEventReader.java   
FilteredEventReader(XMLEventReader reader, EventFilter filter)
{
  super(reader);
  this.filter = filter;
}
项目:opennmszh    文件:HypericAckProcessor.java   
/**
 * <p>parseHypericAlerts</p>
 *
 * @param reader a {@link java.io.Reader} object.
 * @return a {@link java.util.List} object.
 * @throws javax.xml.bind.JAXBException if any.
 * @throws javax.xml.stream.XMLStreamException if any.
 */
public static List<HypericAlertStatus> parseHypericAlerts(Reader reader) throws JAXBException, XMLStreamException {
    List<HypericAlertStatus> retval = new ArrayList<HypericAlertStatus>();

    // Instantiate a JAXB context to parse the alert status
    JAXBContext context = JAXBContext.newInstance(new Class[] { HypericAlertStatuses.class, HypericAlertStatus.class });
    XMLInputFactory xmlif = XMLInputFactory.newInstance();
    XMLEventReader xmler = xmlif.createXMLEventReader(reader);
    EventFilter filter = new EventFilter() {
        public boolean accept(XMLEvent event) {
            return event.isStartElement();
        }
    };
    XMLEventReader xmlfer = xmlif.createFilteredReader(xmler, filter);
    // Read up until the beginning of the root element
    StartElement startElement = (StartElement)xmlfer.nextEvent();
    // Fetch the root element name for {@link HypericAlertStatus} objects
    String rootElementName = context.createJAXBIntrospector().getElementName(new HypericAlertStatuses()).getLocalPart();
    if (rootElementName.equals(startElement.getName().getLocalPart())) {
        Unmarshaller unmarshaller = context.createUnmarshaller();
        // Use StAX to pull parse the incoming alert statuses
        while (xmlfer.peek() != null) {
            Object object = unmarshaller.unmarshal(xmler);
            if (object instanceof HypericAlertStatus) {
                HypericAlertStatus alertStatus = (HypericAlertStatus)object;
                retval.add(alertStatus);
            }
        }
    } else {
        // Try to pull in the HTTP response to give the user a better idea of what went wrong
        StringBuffer errorContent = new StringBuffer();
        LineNumberReader lineReader = new LineNumberReader(reader);
        try {
            String line;
            while (true) {
                line = lineReader.readLine();
                if (line == null) {
                    break;
                } else {
                    errorContent.append(line.trim());
                }
            }
        } catch (IOException e) {
            errorContent.append("Exception while trying to print out message content: " + e.getMessage());
        }

        // Throw an exception and include the erroneous HTTP response in the exception text
        throw new JAXBException("Found wrong root element in Hyperic XML document, expected: \"" + rootElementName + "\", found \"" + startElement.getName().getLocalPart() + "\"\n" + 
                                errorContent.toString());
    }
    return retval;
}
项目:classpath    文件:XMLInputFactoryImpl.java   
public XMLEventReader createFilteredReader(XMLEventReader reader,
                                           EventFilter filter)
  throws XMLStreamException
{
  return new FilteredEventReader(reader, filter);
}
项目:classpath    文件:FilteredEventReader.java   
FilteredEventReader(XMLEventReader reader, EventFilter filter)
{
  super(reader);
  this.filter = filter;
}