use of nokogiri.internals.NokogiriXsltErrorListener 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 nokogiri.internals.NokogiriXsltErrorListener in project gocd by gocd.
the class XsltStylesheet method init.
private void init(IRubyObject stylesheet, Document document) throws TransformerConfigurationException {
// either RubyString or RubyFile
this.stylesheet = stylesheet;
if (factory == null)
factory = TransformerFactory.newInstance();
NokogiriXsltErrorListener elistener = new NokogiriXsltErrorListener();
factory.setErrorListener(elistener);
sheet = factory.newTemplates(new DOMSource(document));
}
use of nokogiri.internals.NokogiriXsltErrorListener in project nokogiri by sparklemotion.
the class XsltStylesheet method init.
private void init(IRubyObject stylesheet, Document document) throws TransformerConfigurationException {
// either RubyString or RubyFile
this.stylesheet = stylesheet;
if (factory == null) {
factory = TransformerFactory.newInstance();
}
NokogiriXsltErrorListener elistener = new NokogiriXsltErrorListener();
factory.setErrorListener(elistener);
sheet = factory.newTemplates(new DOMSource(document));
}
use of nokogiri.internals.NokogiriXsltErrorListener in project nokogiri by sparklemotion.
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());
final DOMResult result;
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);
}
}
Aggregations