use of javax.xml.transform.TransformerConfigurationException in project nokogiri by sparklemotion.
the class XmlRelaxng method getSchema.
private Schema getSchema(Source source, ThreadContext context) {
InputStream is;
VerifierFactory factory = new com.thaiopensource.relaxng.jarv.VerifierFactoryImpl();
if (source instanceof StreamSource) {
StreamSource ss = (StreamSource) source;
is = ss.getInputStream();
} else {
//if (this.source instanceof DOMSource)
DOMSource ds = (DOMSource) source;
StringWriter xmlAsWriter = new StringWriter();
StreamResult result = new StreamResult(xmlAsWriter);
try {
TransformerFactory.newInstance().newTransformer().transform(ds, result);
} catch (TransformerConfigurationException ex) {
throw context.getRuntime().newRuntimeError("Could not parse document: " + ex.getMessage());
} catch (TransformerException ex) {
throw context.getRuntime().newRuntimeError("Could not parse document: " + ex.getMessage());
}
try {
is = new ByteArrayInputStream(xmlAsWriter.toString().getBytes("UTF-8"));
} catch (UnsupportedEncodingException ex) {
throw context.getRuntime().newRuntimeError("Could not parse document: " + ex.getMessage());
}
}
try {
return factory.compileSchema(is);
} catch (VerifierConfigurationException ex) {
throw context.getRuntime().newRuntimeError("Could not parse document: " + ex.getMessage());
} catch (SAXException ex) {
throw context.getRuntime().newRuntimeError("Could not parse document: " + ex.getMessage());
} catch (IOException ex) {
throw context.getRuntime().newIOError(ex.getMessage());
}
}
use of javax.xml.transform.TransformerConfigurationException in project gocd by gocd.
the class XsltStylesheet method parse_stylesheet_doc.
@JRubyMethod(meta = true, rest = true)
public static IRubyObject parse_stylesheet_doc(ThreadContext context, IRubyObject klazz, IRubyObject[] args) {
Ruby runtime = context.getRuntime();
ensureFirstArgIsDocument(runtime, args[0]);
XmlDocument xmlDoc = (XmlDocument) args[0];
ensureDocumentHasNoError(context, xmlDoc);
Document doc = ((XmlDocument) xmlDoc.dup_implementation(context, true)).getDocument();
XsltStylesheet xslt = (XsltStylesheet) NokogiriService.XSLT_STYLESHEET_ALLOCATOR.allocate(runtime, (RubyClass) klazz);
try {
xslt.init(args[1], doc);
} catch (TransformerConfigurationException ex) {
throw runtime.newRuntimeError("could not parse xslt stylesheet");
}
return xslt;
}
use of javax.xml.transform.TransformerConfigurationException in project gocd by gocd.
the class XsltStylesheet method transform.
@JRubyMethod(rest = true, required = 1, optional = 2)
public IRubyObject transform(ThreadContext context, IRubyObject[] args) {
Ruby runtime = context.getRuntime();
argumentTypeCheck(runtime, args[0]);
NokogiriXsltErrorListener elistener = new NokogiriXsltErrorListener();
DOMSource domSource = new DOMSource(((XmlDocument) args[0]).getDocument());
DOMResult result = null;
String stringResult = null;
try {
// DOMResult
result = tryXsltTransformation(context, args, domSource, elistener);
if (result.getNode().getFirstChild() == null) {
// StreamResult
stringResult = retryXsltTransformation(context, args, domSource, elistener);
}
} catch (TransformerConfigurationException ex) {
throw runtime.newRuntimeError(ex.getMessage());
} catch (TransformerException ex) {
throw runtime.newRuntimeError(ex.getMessage());
} catch (IOException ex) {
throw runtime.newRuntimeError(ex.getMessage());
}
switch(elistener.getErrorType()) {
case ERROR:
case FATAL:
throw runtime.newRuntimeError(elistener.getErrorMessage());
case WARNING:
default:
}
if (stringResult == null) {
return createDocumentFromDomResult(context, runtime, result);
} else {
return createDocumentFromString(context, runtime, stringResult);
}
}
use of javax.xml.transform.TransformerConfigurationException in project j2objc by google.
the class TransformerFactoryImpl method processFromNode.
public javax.xml.transform.Templates processFromNode(Node node) throws TransformerConfigurationException {
try {
TemplatesHandler builder = newTemplatesHandler();
TreeWalker walker = new TreeWalker(builder, new org.apache.xml.utils.DOM2Helper(), builder.getSystemId());
walker.traverse(node);
return builder.getTemplates();
} catch (org.xml.sax.SAXException se) {
if (m_errorListener != null) {
try {
m_errorListener.fatalError(new TransformerException(se));
} catch (TransformerConfigurationException ex) {
throw ex;
} catch (TransformerException ex) {
throw new TransformerConfigurationException(ex);
}
return null;
} else {
// se.printStackTrace();
throw new TransformerConfigurationException(XSLMessages.createMessage(XSLTErrorResources.ER_PROCESSFROMNODE_FAILED, null), se);
//"processFromNode failed", se);
}
} catch (TransformerConfigurationException tce) {
// Assume it's already been reported to the error listener.
throw tce;
}/* catch (TransformerException tce)
{
// Assume it's already been reported to the error listener.
throw new TransformerConfigurationException(tce.getMessage(), tce);
}*/
catch (Exception e) {
if (m_errorListener != null) {
try {
m_errorListener.fatalError(new TransformerException(e));
} catch (TransformerConfigurationException ex) {
throw ex;
} catch (TransformerException ex) {
throw new TransformerConfigurationException(ex);
}
return null;
} else {
//"processFromNode failed",
throw new TransformerConfigurationException(XSLMessages.createMessage(XSLTErrorResources.ER_PROCESSFROMNODE_FAILED, null), e);
//e);
}
}
}
use of javax.xml.transform.TransformerConfigurationException in project j2objc by google.
the class TransformerFactoryImpl method newTransformerHandler.
/**
* Get a TransformerHandler object that can process SAX
* ContentHandler events into a Result, based on the Templates argument.
*
* @param templates The source of the transformation instructions.
*
* @return TransformerHandler ready to transform SAX events.
* @throws TransformerConfigurationException
*/
public TransformerHandler newTransformerHandler(Templates templates) throws TransformerConfigurationException {
try {
TransformerImpl transformer = (TransformerImpl) templates.newTransformer();
transformer.setURIResolver(m_uriResolver);
TransformerHandler th = (TransformerHandler) transformer.getInputContentHandler(true);
return th;
} catch (TransformerConfigurationException ex) {
if (m_errorListener != null) {
try {
m_errorListener.fatalError(ex);
return null;
} catch (TransformerConfigurationException ex1) {
throw ex1;
} catch (TransformerException ex1) {
throw new TransformerConfigurationException(ex1);
}
}
throw ex;
}
}
Aggregations