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);
}
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;
}
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());
}
}
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();
}
}
}
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);
}
Aggregations