use of nokogiri.XmlDocument in project nokogiri by sparklemotion.
the class HtmlDomParserContext method parse.
@Override
public XmlDocument parse(ThreadContext context, RubyClass klass, IRubyObject url) {
XmlDocument xmlDoc = super.parse(context, klass, url);
// https://github.com/sparklemotion/nokogiri/issues/2130
if (!options.recover && errorHandler.getErrors().size() > 0) {
XmlSyntaxError xmlSyntaxError = XmlSyntaxError.createXMLSyntaxError(context.runtime);
String exceptionMsg = String.format("%s: '%s'", "Parser without recover option encountered error or warning", errorHandler.getErrors().get(0));
xmlSyntaxError.setException(new Exception(exceptionMsg));
throw xmlSyntaxError.toThrowable();
}
return xmlDoc;
}
use of nokogiri.XmlDocument in project nokogiri by sparklemotion.
the class XmlDomParserContext method wrapDocument.
/**
* This method is broken out so that HtmlDomParserContext can
* override it.
*/
protected XmlDocument wrapDocument(ThreadContext context, RubyClass klass, Document doc) {
XmlDocument xmlDocument = new XmlDocument(context.runtime, klass, doc);
Helpers.invoke(context, xmlDocument, "initialize");
xmlDocument.setEncoding(ruby_encoding);
if (options.dtdLoad) {
IRubyObject dtd = XmlDtd.newFromExternalSubset(context.runtime, doc);
if (!dtd.isNil()) {
doc.setUserData(XmlDocument.DTD_EXTERNAL_SUBSET, (XmlDtd) dtd, null);
}
}
return xmlDocument;
}
use of nokogiri.XmlDocument in project nokogiri by sparklemotion.
the class XmlDomParserContext method getInterruptedOrNewXmlDocument.
private XmlDocument getInterruptedOrNewXmlDocument(ThreadContext context, RubyClass klass) {
Document document = parser.getDocument();
XmlDocument xmlDocument = new XmlDocument(context.runtime, klass, document);
xmlDocument.setEncoding(ruby_encoding);
return xmlDocument;
}
use of nokogiri.XmlDocument in project gocd by gocd.
the class XmlDomParserContext method getInterruptedOrNewXmlDocument.
private XmlDocument getInterruptedOrNewXmlDocument(ThreadContext context, RubyClass klazz) {
Document document = parser.getDocument();
XmlDocument xmlDocument = (XmlDocument) NokogiriService.XML_DOCUMENT_ALLOCATOR.allocate(context.getRuntime(), klazz);
if (document != null) {
xmlDocument.setDocumentNode(context, document);
}
xmlDocument.setEncoding(ruby_encoding);
return xmlDocument;
}
use of nokogiri.XmlDocument in project gocd by gocd.
the class NokogiriHelpers method constructNode.
/**
* Construct a new XmlNode wrapping <code>node</code>. The proper
* subclass of XmlNode is chosen based on the type of
* <code>node</code>.
*/
public static IRubyObject constructNode(Ruby runtime, Node node) {
if (node == null)
return runtime.getNil();
// this is slow; need a way to cache nokogiri classes/modules somewhere
switch(node.getNodeType()) {
case Node.ELEMENT_NODE:
XmlElement xmlElement = (XmlElement) NokogiriService.XML_ELEMENT_ALLOCATOR.allocate(runtime, getNokogiriClass(runtime, "Nokogiri::XML::Element"));
xmlElement.setNode(runtime.getCurrentContext(), node);
return xmlElement;
case Node.ATTRIBUTE_NODE:
XmlAttr xmlAttr = (XmlAttr) NokogiriService.XML_ATTR_ALLOCATOR.allocate(runtime, getNokogiriClass(runtime, "Nokogiri::XML::Attr"));
xmlAttr.setNode(runtime.getCurrentContext(), node);
return xmlAttr;
case Node.TEXT_NODE:
XmlText xmlText = (XmlText) NokogiriService.XML_TEXT_ALLOCATOR.allocate(runtime, getNokogiriClass(runtime, "Nokogiri::XML::Text"));
xmlText.setNode(runtime.getCurrentContext(), node);
return xmlText;
case Node.COMMENT_NODE:
XmlComment xmlComment = (XmlComment) NokogiriService.XML_COMMENT_ALLOCATOR.allocate(runtime, getNokogiriClass(runtime, "Nokogiri::XML::Comment"));
xmlComment.setNode(runtime.getCurrentContext(), node);
return xmlComment;
case Node.ENTITY_NODE:
return new XmlNode(runtime, getNokogiriClass(runtime, "Nokogiri::XML::EntityDecl"), node);
case Node.ENTITY_REFERENCE_NODE:
XmlEntityReference xmlEntityRef = (XmlEntityReference) NokogiriService.XML_ENTITY_REFERENCE_ALLOCATOR.allocate(runtime, getNokogiriClass(runtime, "Nokogiri::XML::EntityReference"));
xmlEntityRef.setNode(runtime.getCurrentContext(), node);
return xmlEntityRef;
case Node.PROCESSING_INSTRUCTION_NODE:
XmlProcessingInstruction xmlProcessingInstruction = (XmlProcessingInstruction) NokogiriService.XML_PROCESSING_INSTRUCTION_ALLOCATOR.allocate(runtime, getNokogiriClass(runtime, "Nokogiri::XML::ProcessingInstruction"));
xmlProcessingInstruction.setNode(runtime.getCurrentContext(), node);
return xmlProcessingInstruction;
case Node.CDATA_SECTION_NODE:
XmlCdata xmlCdata = (XmlCdata) NokogiriService.XML_CDATA_ALLOCATOR.allocate(runtime, getNokogiriClass(runtime, "Nokogiri::XML::CDATA"));
xmlCdata.setNode(runtime.getCurrentContext(), node);
return xmlCdata;
case Node.DOCUMENT_NODE:
XmlDocument xmlDocument = (XmlDocument) NokogiriService.XML_DOCUMENT_ALLOCATOR.allocate(runtime, getNokogiriClass(runtime, "Nokogiri::XML::Document"));
xmlDocument.setDocumentNode(runtime.getCurrentContext(), node);
return xmlDocument;
case Node.DOCUMENT_TYPE_NODE:
XmlDtd xmlDtd = (XmlDtd) NokogiriService.XML_DTD_ALLOCATOR.allocate(runtime, getNokogiriClass(runtime, "Nokogiri::XML::DTD"));
xmlDtd.setNode(runtime, node);
return xmlDtd;
default:
XmlNode xmlNode = (XmlNode) NokogiriService.XML_NODE_ALLOCATOR.allocate(runtime, getNokogiriClass(runtime, "Nokogiri::XML::Node"));
xmlNode.setNode(runtime.getCurrentContext(), node);
return xmlNode;
}
}
Aggregations