Search in sources :

Example 1 with HtmlParser

use of nu.validator.htmlparser.sax.HtmlParser in project validator by validator.

the class Html5SpecBuilder method parseSpec.

private static Spec parseSpec(InputSource in) throws IOException, SAXException {
    HtmlParser parser = new HtmlParser(XmlViolationPolicy.ALTER_INFOSET);
    Html5SpecBuilder handler = new Html5SpecBuilder();
    parser.setContentHandler(handler);
    parser.parse(in);
    return handler.buildSpec();
}
Also used : HtmlParser(nu.validator.htmlparser.sax.HtmlParser)

Example 2 with HtmlParser

use of nu.validator.htmlparser.sax.HtmlParser in project whole by wholeplatform.

the class HtmlPersistenceKit method doReadModel.

protected IEntity doReadModel(IPersistenceProvider pp) throws Exception {
    ModelBuilderOperation op = new ModelBuilderOperation();
    SaxConsumerHandler saxHandler = new SaxConsumerHandler(op, false);
    HtmlParser parser = new HtmlParser(XmlViolationPolicy.ALLOW);
    parser.setContentHandler(saxHandler);
    parser.setProperty("http://xml.org/sax/properties/lexical-handler", saxHandler);
    parser.parse(new InputSource(pp.getInputStream()));
    IEntity xhtmlDocument = NormalizerOperation.normalize(op.wGetResult());
    return BehaviorUtils.apply("whole:org.whole.lang.html:HTML5Semantics#toHtml", xhtmlDocument);
}
Also used : ModelBuilderOperation(org.whole.lang.builders.ModelBuilderOperation) HtmlParser(nu.validator.htmlparser.sax.HtmlParser) InputSource(org.xml.sax.InputSource) SaxConsumerHandler(org.whole.lang.xml.util.SaxConsumerHandler) IEntity(org.whole.lang.model.IEntity)

Example 3 with HtmlParser

use of nu.validator.htmlparser.sax.HtmlParser in project validator by validator.

the class RegisteredRelValuesBuilder method parseRegistry.

public static void parseRegistry() throws IOException, SAXException {
    HtmlParser parser = new HtmlParser(XmlViolationPolicy.ALTER_INFOSET);
    RegisteredRelValuesBuilder handler = new RegisteredRelValuesBuilder();
    parser.setContentHandler(handler);
    InputSource in = new InputSource(RegisteredRelValuesBuilder.class.getClassLoader().getResourceAsStream("nu/validator/localentities/files/existing-rel-values"));
    parser.parse(in);
}
Also used : HtmlParser(nu.validator.htmlparser.sax.HtmlParser) InputSource(org.xml.sax.InputSource)

Example 4 with HtmlParser

use of nu.validator.htmlparser.sax.HtmlParser in project validator by validator.

the class ValidationWorker method setupParser.

private XMLReader setupParser() {
    HtmlParser htmlParser = new HtmlParser();
    htmlParser.setCommentPolicy(XmlViolationPolicy.ALLOW);
    htmlParser.setContentNonXmlCharPolicy(XmlViolationPolicy.ALLOW);
    htmlParser.setContentSpacePolicy(XmlViolationPolicy.ALTER_INFOSET);
    htmlParser.setNamePolicy(XmlViolationPolicy.ALLOW);
    htmlParser.setStreamabilityViolationPolicy(XmlViolationPolicy.ALLOW);
    htmlParser.setXmlnsPolicy(XmlViolationPolicy.ALTER_INFOSET);
    htmlParser.setMappingLangToXmlLang(true);
    htmlParser.setHeuristics(Heuristics.ALL);
    htmlParser.setDoctypeExpectation(DoctypeExpectation.NO_DOCTYPE_ERRORS);
    htmlParser.setCheckingNormalization(true);
    htmlParser.setDocumentModeHandler(this);
    XMLReader rv = new AttributesPermutingXMLReaderWrapper(htmlParser);
    rv.setErrorHandler(this);
    return rv;
}
Also used : HtmlParser(nu.validator.htmlparser.sax.HtmlParser) AttributesPermutingXMLReaderWrapper(nu.validator.xml.AttributesPermutingXMLReaderWrapper) XMLReader(org.xml.sax.XMLReader)

Example 5 with HtmlParser

use of nu.validator.htmlparser.sax.HtmlParser in project validator by validator.

the class ParserPerfHarness method main.

/**
 * @param args
 * @throws IOException
 * @throws SAXException
 * @throws ParserConfigurationException
 */
public static void main(String[] args) throws SAXException, IOException, ParserConfigurationException {
    boolean html = "h".equals(args[0]);
    long duration = Long.parseLong(args[1]) * 60000L;
    String path = args[2];
    char[] testData = loadFileIntoArray(new File(path));
    XmlSerializer ch = new XmlSerializer(new NullWriter());
    XMLReader reader = null;
    if (html) {
        HtmlParser parser = new HtmlParser(XmlViolationPolicy.ALLOW);
        parser.setContentHandler(ch);
        parser.setStreamabilityViolationPolicy(XmlViolationPolicy.FATAL);
        reader = parser;
    } else {
        SAXParserFactory factory = SAXParserFactory.newInstance();
        factory.setNamespaceAware(true);
        factory.setValidating(false);
        reader = factory.newSAXParser().getXMLReader();
        reader.setContentHandler(ch);
        reader.setEntityResolver(new NullEntityResolver());
    }
    System.out.println("Warmup:");
    System.out.println((new ParserPerfHarness(System.currentTimeMillis() + duration, reader, testData)).runLoop());
    System.gc();
    System.out.println("Real:");
    System.out.println((new ParserPerfHarness(System.currentTimeMillis() + duration, reader, testData)).runLoop());
}
Also used : HtmlParser(nu.validator.htmlparser.sax.HtmlParser) NullEntityResolver(nu.validator.xml.NullEntityResolver) File(java.io.File) XMLReader(org.xml.sax.XMLReader) XmlSerializer(nu.validator.htmlparser.sax.XmlSerializer) SAXParserFactory(javax.xml.parsers.SAXParserFactory)

Aggregations

HtmlParser (nu.validator.htmlparser.sax.HtmlParser)10 InputSource (org.xml.sax.InputSource)4 NullEntityResolver (nu.validator.xml.NullEntityResolver)3 XMLReader (org.xml.sax.XMLReader)3 File (java.io.File)2 SAXDriver (nu.validator.gnu.xml.aelfred2.SAXDriver)2 XmlSerializer (nu.validator.htmlparser.sax.XmlSerializer)2 CombineValidator (com.thaiopensource.relaxng.impl.CombineValidator)1 PropertyMap (com.thaiopensource.util.PropertyMap)1 PropertyMapBuilder (com.thaiopensource.util.PropertyMapBuilder)1 Validator (com.thaiopensource.validate.Validator)1 Jaxp11XMLReaderCreator (com.thaiopensource.xml.sax.Jaxp11XMLReaderCreator)1 SAXParserFactory (javax.xml.parsers.SAXParserFactory)1 ConformingButObsoleteWarner (nu.validator.checker.ConformingButObsoleteWarner)1 MicrodataChecker (nu.validator.checker.MicrodataChecker)1 NormalizationChecker (nu.validator.checker.NormalizationChecker)1 TextContentChecker (nu.validator.checker.TextContentChecker)1 UncheckedSubtreeWarner (nu.validator.checker.UncheckedSubtreeWarner)1 UnsupportedFeatureChecker (nu.validator.checker.UnsupportedFeatureChecker)1 UsemapChecker (nu.validator.checker.UsemapChecker)1