1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107
|
package nokogiri.internals;
import org.apache.xerces.xni.parser.XMLParseException;
import org.jruby.Ruby;
import org.xml.sax.SAXException;
import org.xml.sax.SAXParseException;
/**
* Non-strict error handler for NekoHtml.
*
* NekoHtml adds too many warnings, which makes later processing hard. For example,
* Nokogiri wants to know whether number of errors have been increased or not to judge
* availability of creating NodeSet from a given fragment. When the fragment nodes
* are to be created from HTML document, which means NekoHtml is used, always errors
* increases. As a result, even though the given fragment is correct HTML, NodeSet
* base on the given fragment won't be created. This is why all warnings are eliminated.
*
* @author Yoko Harada <yokolet@gmail.com>
*/
public class NokogiriNonStrictErrorHandler4NekoHtml extends NokogiriErrorHandler
{
public
NokogiriNonStrictErrorHandler4NekoHtml(Ruby runtime, boolean nowarning)
{
super(runtime, false, nowarning);
}
public
NokogiriNonStrictErrorHandler4NekoHtml(Ruby runtime, boolean noerror, boolean nowarning)
{
super(runtime, noerror, nowarning);
}
public void
warning(SAXParseException ex) throws SAXException
{
//noop. NekoHtml adds too many warnings.
}
public void
error(SAXParseException ex) throws SAXException
{
addError(ex);
}
public void
fatalError(SAXParseException ex) throws SAXException
{
addError(ex);
}
/**
* Implementation of org.apache.xerces.xni.parser.XMLErrorHandler. This method
* is invoked during parsing fired by HtmlDomParserContext and is a NekoHtml requirement.
*
* @param domain The domain of the error. The domain can be any string but is
* suggested to be a valid URI. The domain can be used to conveniently
* specify a web site location of the relevant specification or
* document pertaining to this warning.
* @param key The error key. This key can be any string and is implementation
* dependent.
* @param e Exception.
*/
public void
error(String domain, String key, XMLParseException e)
{
addError(e);
}
/**
* Implementation of org.apache.xerces.xni.parser.XMLErrorHandler. This method
* is invoked during parsing fired by HtmlDomParserContext and is a NekoHtml requirement.
*
* @param domain The domain of the fatal error. The domain can be any string but is
* suggested to be a valid URI. The domain can be used to conveniently
* specify a web site location of the relevant specification or
* document pertaining to this warning.
* @param key The fatal error key. This key can be any string and is implementation
* dependent.
* @param e Exception.
*/
public void
fatalError(String domain, String key, XMLParseException e)
{
addError(e);
}
/**
* Implementation of org.apache.xerces.xni.parser.XMLErrorHandler. This method
* is invoked during parsing fired by HtmlDomParserContext and is a NekoHtml requirement.
*
* @param domain The domain of the warning. The domain can be any string but is
* suggested to be a valid URI. The domain can be used to conveniently
* specify a web site location of the relevant specification or
* document pertaining to this warning.
* @param key The warning key. This key can be any string and is implementation
* dependent.
* @param e Exception.
*/
public void
warning(String domain, String key, XMLParseException e)
{
addError(e);
}
}
|