use of javax.xml.transform.TransformerException in project gocd by gocd.
the class GRDDLTransformer method transform.
public Graph transform(final Document inputDoc, TempGraphFactory graphFactory) throws GrddlTransformException {
final DocumentResult result = new DocumentResult();
try {
xsltTransformerRegistry.transformWithCorrectClassLoader(key, new XSLTTransformerExecutor<Void>() {
@Override
public Void execute(Transformer transformer) throws TransformerException {
DocumentSource source = new DocumentSource(inputDoc);
transformer.transform(source, result);
return null;
}
});
// TODO: likely need to optimize with some sort of streaming document reader here
Graph graph = graphFactory.createTempGraph();
graph.addTriplesFromRDFXMLAbbrev(new StringReader(result.getDocument().asXML()));
return graph;
} catch (ShineRuntimeException e) {
LOGGER.error("Could not convert to a graph. The document was: \n{}", result.getDocument().asXML(), e);
throw e;
} catch (TransformerException e) {
LOGGER.warn("Could not perform grddl transform. The document was: \n{}", result.getDocument().asXML(), e);
throw new GrddlTransformException(e);
}
}
use of javax.xml.transform.TransformerException in project gocd by gocd.
the class NUnitRDFizer method importFile.
public Graph importFile(final String parentURI, Document document) throws GrddlTransformException {
final DocumentResult result = new DocumentResult();
final DocumentSource source = new DocumentSource(document);
try {
return xsltTransformerRegistry.transformWithCorrectClassLoader(XSLTTransformerRegistry.XUNIT_NUNIT_TO_JUNIT_XSL, new XSLTTransformerExecutor<Graph>() {
@Override
public Graph execute(Transformer transformer) throws TransformerException, GrddlTransformException {
transformer.transform(source, result);
return jUnitRDFizer.importFile(parentURI, result.getDocument());
}
});
} catch (TransformerException e) {
throw new ShineRuntimeException(e);
}
}
use of javax.xml.transform.TransformerException in project uPortal by Jasig.
the class AbstractDom4jExporter method marshal.
/* (non-Javadoc)
* @see org.springframework.oxm.Marshaller#marshal(java.lang.Object, javax.xml.transform.Result)
*/
@Override
public void marshal(Object graph, Result result) throws IOException, XmlMappingException {
@SuppressWarnings("unchecked") final Tuple<String, Element> data = (Tuple<String, Element>) graph;
final Transformer transformer;
try {
transformer = this.xmlUtilities.getIdentityTransformer();
} catch (TransformerConfigurationException e) {
throw new RuntimeException("Failed to load identity Transformer", e);
}
// Setup the transformer to pretty-print the output
transformer.setOutputProperty(OutputKeys.INDENT, "yes");
transformer.setOutputProperty("{http://xml.apache.org/xslt}indent-amount", "2");
try {
transformer.transform(new DocumentSource(data.second), result);
} catch (TransformerException e) {
throw new RuntimeException("Failed to write Element to Result for: " + data.first, e);
}
}
use of javax.xml.transform.TransformerException in project uPortal by Jasig.
the class XSLTComponent method getEventReader.
/* (non-Javadoc)
* @see org.apereo.portal.rendering.StAXPipelineComponent#getXmlStreamReader(java.lang.Object, java.lang.Object)
*/
@Override
public PipelineEventReader<XMLEventReader, XMLEvent> getEventReader(HttpServletRequest request, HttpServletResponse response) {
final PipelineEventReader<XMLEventReader, XMLEvent> pipelineEventReader = this.wrappedComponent.getEventReader(request, response);
final Transformer transformer = this.transformerSource.getTransformer(request, response);
// Setup a URIResolver based on the current resource loader
transformer.setURIResolver(this.uriResolver);
// Configure the Transformer via injected class
if (this.xsltParameterSource != null) {
final Map<String, Object> transformerParameters = this.xsltParameterSource.getParameters(request, response);
if (transformerParameters != null) {
this.logger.debug("{} - Setting Transformer Parameters: ", this.beanName, transformerParameters);
for (final Map.Entry<String, Object> transformerParametersEntry : transformerParameters.entrySet()) {
final String name = transformerParametersEntry.getKey();
final Object value = transformerParametersEntry.getValue();
if (value != null) {
transformer.setParameter(name, value);
}
}
}
final Properties outputProperties = this.xsltParameterSource.getOutputProperties(request, response);
if (outputProperties != null) {
this.logger.debug("{} - Setting Transformer Output Properties: ", this.beanName, outputProperties);
transformer.setOutputProperties(outputProperties);
}
}
// The event reader from the previous component in the pipeline
final XMLEventReader eventReader = pipelineEventReader.getEventReader();
// Wrap the event reader in a stream reader to avoid a JDK bug
final XMLStreamReader streamReader;
try {
streamReader = new FixedXMLEventStreamReader(eventReader);
} catch (XMLStreamException e) {
throw new RuntimeException("Failed to create XMLStreamReader from XMLEventReader", e);
}
final Source xmlReaderSource = new StAXSource(streamReader);
// Setup logging for the transform
transformer.setErrorListener(this.errorListener);
// Transform to a SAX ContentHandler to avoid JDK bug:
// http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=6775588
final XMLEventBufferWriter eventWriterBuffer = new XMLEventBufferWriter();
final ContentHandler contentHandler = StaxUtils.createContentHandler(eventWriterBuffer);
contentHandler.setDocumentLocator(new LocatorImpl());
final SAXResult outputTarget = new SAXResult(contentHandler);
try {
this.logger.debug("{} - Begining XML Transformation", this.beanName);
transformer.transform(xmlReaderSource, outputTarget);
this.logger.debug("{} - XML Transformation complete", this.beanName);
} catch (TransformerException e) {
throw new RuntimeException("Failed to transform document", e);
}
final String mediaType = transformer.getOutputProperty(OutputKeys.MEDIA_TYPE);
final List<XMLEvent> eventBuffer = eventWriterBuffer.getEventBuffer();
final XMLEventReader outputEventReader = new XMLEventBufferReader(eventBuffer.listIterator());
final Map<String, String> outputProperties = pipelineEventReader.getOutputProperties();
final PipelineEventReaderImpl<XMLEventReader, XMLEvent> pipelineEventReaderImpl = new PipelineEventReaderImpl<XMLEventReader, XMLEvent>(outputEventReader, outputProperties);
pipelineEventReaderImpl.setOutputProperty(OutputKeys.MEDIA_TYPE, mediaType);
return pipelineEventReaderImpl;
}
use of javax.xml.transform.TransformerException in project uPortal by Jasig.
the class ResourceLoaderURIResolver method resolveResource.
/**
* Resolve the requested {@link Resource}
*/
protected Resource resolveResource(String href, String base) throws TransformerException {
final Resource resolvedResource;
if (base != null) {
final Resource baseResource = this.resourceLoader.getResource(base);
try {
resolvedResource = baseResource.createRelative(href);
} catch (IOException e) {
throw new TransformerException("Failed to find '" + href + "' relative to: " + baseResource, e);
}
this.logger.debug("Created resource {} for href: {} and base: {}", new Object[] { resolvedResource, href, baseResource });
} else {
resolvedResource = this.resourceLoader.getResource(href);
this.logger.debug("Created resource {} for href: {}", resolvedResource, href);
}
return resolvedResource;
}
Aggregations