Search in sources :

Example 1 with SaxConsumerHandler

use of org.whole.lang.xml.util.SaxConsumerHandler in project whole by wholeplatform.

the class PersistenceTest method testSaxHandlerBuilder.

@Test
public void testSaxHandlerBuilder() throws Exception {
    Document xmlModel = (Document) XmlSourcePersistenceKit.instance().readModel(new ClasspathPersistenceProvider("org/whole/lang/xsd/util/javaee_web_services_client_1_2.xsd"));
    ModelBuilderOperation op = new ModelBuilderOperation();
    SaxConsumerHandler saxHandler = new SaxConsumerHandler(op, !EntityUtils.isResolver(xmlModel.getProlog().getXmlDecl()));
    SaxHandlerBuilderOperation sbop = new SaxHandlerBuilderOperation(saxHandler, saxHandler);
    new ModelTemplate(xmlModel).apply(sbop);
    assertTrue(Matcher.match(op.wGetResult(), xmlModel));
}
Also used : ModelBuilderOperation(org.whole.lang.builders.ModelBuilderOperation) ModelTemplate(org.whole.lang.templates.ModelTemplate) SaxConsumerHandler(org.whole.lang.xml.util.SaxConsumerHandler) SaxHandlerBuilderOperation(org.whole.lang.xml.util.SaxHandlerBuilderOperation) Document(org.whole.lang.xml.model.Document) Test(org.junit.Test)

Example 2 with SaxConsumerHandler

use of org.whole.lang.xml.util.SaxConsumerHandler 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)

Aggregations

ModelBuilderOperation (org.whole.lang.builders.ModelBuilderOperation)2 SaxConsumerHandler (org.whole.lang.xml.util.SaxConsumerHandler)2 HtmlParser (nu.validator.htmlparser.sax.HtmlParser)1 Test (org.junit.Test)1 IEntity (org.whole.lang.model.IEntity)1 ModelTemplate (org.whole.lang.templates.ModelTemplate)1 Document (org.whole.lang.xml.model.Document)1 SaxHandlerBuilderOperation (org.whole.lang.xml.util.SaxHandlerBuilderOperation)1 InputSource (org.xml.sax.InputSource)1