Search in sources :

Example 56 with XMLEventReader

use of javax.xml.stream.XMLEventReader in project uPortal by Jasig.

the class SitemapPortletController method displaySitemap.

/**
     * Display the user sitemap.
     *
     * @param request
     * @return "sitemapView" and a supporting model
     * @throws XMLStreamException
     * @throws IllegalStateException if components required for the SiteMap portlet fail to
     *     auto-wire
     */
@RequestMapping
public ModelAndView displaySitemap(PortletRequest request) throws XMLStreamException {
    Map<String, Object> model = new HashMap<String, Object>();
    if (this.xsltPortalUrlProvider == null) {
        throw new IllegalStateException("Sitemap portlet requires a XsltPortalUrlProvider but it failed to " + "auto-wire");
    }
    if (this.attributeIncorporationComponent == null) {
        throw new IllegalStateException("Sitemap portlet requires a StAXPipelineComponent with qualifier structureAttributeIncorporationComponent but it failed to auto-wire");
    }
    if (this.portalRequestUtils == null) {
        throw new IllegalStateException("Sitemap portlet requires an IPortalRequestUtils but it failed to " + "auto-wire");
    }
    // retrieve the user layout with structure attributes applied (required in order to display tab groups)
    final HttpServletRequest httpServletRequest = this.portalRequestUtils.getPortletHttpRequest(request);
    final HttpServletResponse httpServletResponse = this.portalRequestUtils.getOriginalPortalResponse(request);
    final PipelineEventReader<XMLEventReader, XMLEvent> reader = attributeIncorporationComponent.getEventReader(httpServletRequest, httpServletResponse);
    // create a Source from the user's layout document
    StAXSource source = new StAXSource(reader.getEventReader());
    model.put("source", source);
    model.put(XsltPortalUrlProvider.CURRENT_REQUEST, httpServletRequest);
    model.put(XsltPortalUrlProvider.XSLT_PORTAL_URL_PROVIDER, this.xsltPortalUrlProvider);
    model.put(USE_TAB_GROUPS, useTabGroups);
    model.put(USER_LANG, ObjectUtils.toString(request.getLocale()));
    return new ModelAndView("sitemapView", model);
}
Also used : HttpServletRequest(javax.servlet.http.HttpServletRequest) HashMap(java.util.HashMap) XMLEvent(javax.xml.stream.events.XMLEvent) ModelAndView(org.springframework.web.portlet.ModelAndView) HttpServletResponse(javax.servlet.http.HttpServletResponse) XMLEventReader(javax.xml.stream.XMLEventReader) StAXSource(javax.xml.transform.stax.StAXSource) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 57 with XMLEventReader

use of javax.xml.stream.XMLEventReader in project wildfly by wildfly.

the class SchemaLocationsRewriteTestCase method getAttributeValues.

private List<String> getAttributeValues(URL url, String localPart) throws Exception {
    String document = IOUtils.toString(url.openStream());
    log.trace(document);
    List<String> values = new ArrayList<>();
    XMLInputFactory xmlif = XMLInputFactory.newInstance();
    XMLEventReader eventReader = xmlif.createXMLEventReader(new ByteArrayInputStream(document.getBytes()));
    while (eventReader.hasNext()) {
        XMLEvent xmlEvent = eventReader.nextEvent();
        if (xmlEvent.getEventType() == XMLStreamConstants.START_ELEMENT) {
            StartElement startElement = xmlEvent.asStartElement();
            Attribute attribute = startElement.getAttributeByName(new QName("", localPart));
            if (attribute != null) {
                values.add(attribute.getValue());
            }
        }
    }
    return values;
}
Also used : StartElement(javax.xml.stream.events.StartElement) ByteArrayInputStream(java.io.ByteArrayInputStream) Attribute(javax.xml.stream.events.Attribute) QName(javax.xml.namespace.QName) ArrayList(java.util.ArrayList) XMLEvent(javax.xml.stream.events.XMLEvent) XMLEventReader(javax.xml.stream.XMLEventReader) XMLInputFactory(javax.xml.stream.XMLInputFactory)

Example 58 with XMLEventReader

use of javax.xml.stream.XMLEventReader in project jdk8u_jdk by JetBrains.

the class SkipDTDTest method runReader.

public void runReader(XMLInputFactory factory, int offset) throws XMLStreamException {
    StringReader stringReader = new StringReader(createXMLDocument(offset));
    XMLEventReader reader = factory.createXMLEventReader(stringReader);
    while (reader.hasNext()) {
        XMLEvent event = reader.nextEvent();
        System.out.println("Event Type: " + event.getEventType());
    }
}
Also used : StringReader(java.io.StringReader) XMLEvent(javax.xml.stream.events.XMLEvent) XMLEventReader(javax.xml.stream.XMLEventReader)

Example 59 with XMLEventReader

use of javax.xml.stream.XMLEventReader in project karaf by apache.

the class SpringDeploymentListener method getRootElement.

protected StartElement getRootElement(File artifact) throws Exception {
    XMLEventReader parser = null;
    InputStream in = null;
    try {
        if (factory == null) {
            factory = XMLInputFactory.newInstance();
        }
        in = new FileInputStream(artifact);
        parser = factory.createXMLEventReader(in);
        while (parser.hasNext()) {
            XMLEvent event = parser.nextEvent();
            if (event.isStartElement()) {
                return event.asStartElement();
            }
        }
        return null;
    } finally {
        if (parser != null) {
            parser.close();
        }
        if (in != null) {
            in.close();
        }
    }
}
Also used : FileInputStream(java.io.FileInputStream) InputStream(java.io.InputStream) XMLEvent(javax.xml.stream.events.XMLEvent) XMLEventReader(javax.xml.stream.XMLEventReader) FileInputStream(java.io.FileInputStream)

Example 60 with XMLEventReader

use of javax.xml.stream.XMLEventReader in project jena by apache.

the class StAX2ModelTest method runTest.

@Override
public void runTest() throws Exception {
    Model expected = ModelFactory.createDefaultModel();
    Model got = ModelFactory.createDefaultModel();
    InputStream in;
    // Load expected using normal mechanism
    try {
        in = new FileInputStream(file);
        expected.read(in, base);
        in.close();
    } catch (Exception e) {
        return;
    }
    in = new FileInputStream(file);
    XMLEventReader eventStream = inputFactory.createXMLEventReader(base, in);
    StAX2Model.read(eventStream, got, base);
    in.close();
    boolean result = expected.isIsomorphicWith(got);
    /*if (!result) {
            System.err.println("\n\n==== Expected ====");
            expected.write(System.err, "TTL");
            System.err.println("\n\n==== Got ====");
            got.write(System.err, "TTL");
        }*/
    assertTrue(file + " matches", result);
}
Also used : FileInputStream(java.io.FileInputStream) InputStream(java.io.InputStream) Model(org.apache.jena.rdf.model.Model) StAX2Model(org.apache.jena.rdfxml.xmlinput.StAX2Model) XMLEventReader(javax.xml.stream.XMLEventReader) FileInputStream(java.io.FileInputStream)

Aggregations

XMLEventReader (javax.xml.stream.XMLEventReader)71 XMLInputFactory (javax.xml.stream.XMLInputFactory)36 XMLEvent (javax.xml.stream.events.XMLEvent)34 XMLStreamException (javax.xml.stream.XMLStreamException)23 StringReader (java.io.StringReader)18 Test (org.junit.Test)17 InputStream (java.io.InputStream)15 StAXSource (javax.xml.transform.stax.StAXSource)13 StartElement (javax.xml.stream.events.StartElement)12 IOException (java.io.IOException)10 Unmarshaller (javax.xml.bind.Unmarshaller)9 Attribute (javax.xml.stream.events.Attribute)8 ByteArrayInputStream (java.io.ByteArrayInputStream)6 StringWriter (java.io.StringWriter)6 ArrayList (java.util.ArrayList)6 QName (javax.xml.namespace.QName)6 Document (org.w3c.dom.Document)6 ByteArrayOutputStream (java.io.ByteArrayOutputStream)5 InputStreamReader (java.io.InputStreamReader)5 JAXBContext (javax.xml.bind.JAXBContext)5