use of javax.xml.transform.stax.StAXSource 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.transform.stax.StAXSource in project camel by apache.
the class CachedCxfPayloadTest method testCachedCxfPayloadStAXSource.
@Test
public void testCachedCxfPayloadStAXSource() throws TypeConversionException, NoTypeConversionAvailableException, IOException {
StAXSource source = context.getTypeConverter().mandatoryConvertTo(StAXSource.class, PAYLOAD);
doTest(source, PAYLOAD);
}
use of javax.xml.transform.stax.StAXSource in project camel by apache.
the class XmlConverterTest method testToDomSourceByStAXSource.
public void testToDomSourceByStAXSource() throws Exception {
XmlConverter conv = new XmlConverter();
// because of https://bugs.openjdk.java.net/show_bug.cgi?id=100228, we have to set the XML version explicitly
StAXSource source = conv.toStAXSource("<?xml version=\"1.0\" encoding=\"UTF-8\"?><foo>bar</foo>", null);
DOMSource out = conv.toDOMSource(source);
assertNotSame(source, out);
assertEquals("<foo>bar</foo>", conv.toString(out, null));
}
use of javax.xml.transform.stax.StAXSource in project camel by apache.
the class XsltBuilder method process.
public void process(Exchange exchange) throws Exception {
notNull(getTemplate(), "template");
if (isDeleteOutputFile()) {
// add on completion so we can delete the file when the Exchange is done
String fileName = ExchangeHelper.getMandatoryHeader(exchange, Exchange.XSLT_FILE_NAME, String.class);
exchange.addOnCompletion(new XsltBuilderOnCompletion(fileName));
}
Transformer transformer = getTransformer();
configureTransformer(transformer, exchange);
ResultHandler resultHandler = resultHandlerFactory.createResult(exchange);
Result result = resultHandler.getResult();
// let's copy the headers before we invoke the transform in case they modify them
Message out = exchange.getOut();
out.copyFrom(exchange.getIn());
// the underlying input stream, which we need to close to avoid locking files or other resources
InputStream is = null;
try {
Source source;
// only convert to input stream if really needed
if (isInputStreamNeeded(exchange)) {
is = exchange.getIn().getBody(InputStream.class);
source = getSource(exchange, is);
} else {
Object body = exchange.getIn().getBody();
source = getSource(exchange, body);
}
if (source instanceof StAXSource) {
// Always convert StAXSource to SAXSource.
// * Xalan and Saxon-B don't support StAXSource.
// * The JDK default implementation (XSLTC) doesn't handle CDATA events
// (see com.sun.org.apache.xalan.internal.xsltc.trax.StAXStream2SAX).
// * Saxon-HE/PE/EE seem to support StAXSource, but don't advertise this
// officially (via TransformerFactory.getFeature(StAXSource.FEATURE))
source = new StAX2SAXSource(((StAXSource) source).getXMLStreamReader());
}
LOG.trace("Using {} as source", source);
transformer.transform(source, result);
LOG.trace("Transform complete with result {}", result);
resultHandler.setBody(out);
} finally {
releaseTransformer(transformer);
// IOHelper can handle if is is null
IOHelper.close(is);
}
}
use of javax.xml.transform.stax.StAXSource in project webservices-axiom by apache.
the class XOPRoundtripTest method runTest.
@Override
protected void runTest() throws Throwable {
OMFactory factory = metaFactory.getOMFactory();
DataHandler dh = new DataHandler(new TestDataSource('x', Runtime.getRuntime().maxMemory()));
OMElement element1 = factory.createOMElement(new QName("test"));
element1.addChild(factory.createOMText(dh, true));
XOPEncoded<XMLStreamReader> xopEncodedStream = element1.getXOPEncodedStreamReader(true);
OMElement element2 = OMXMLBuilderFactory.createOMBuilder(factory, new StAXSource(xopEncodedStream.getRootPart()), xopEncodedStream.getAttachmentAccessor()).getDocumentElement();
OMText child = (OMText) element2.getFirstOMChild();
assertNotNull(child);
assertTrue(child.isBinary());
assertTrue(child.isOptimized());
assertSame(dh, child.getDataHandler());
}
Aggregations