Search in sources :

Example 1 with Document

use of org.whole.lang.xml.model.Document 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 Document

use of org.whole.lang.xml.model.Document in project whole by wholeplatform.

the class DocumentPart method getModelSpecificChildren.

protected List<IEntity> getModelSpecificChildren() {
    List<IEntity> list = new ArrayList<IEntity>(2);
    Document document = getModelEntity();
    list.add(document.getProlog());
    list.add(document.getElement());
    return list;
}
Also used : IEntity(org.whole.lang.model.IEntity) ArrayList(java.util.ArrayList) Document(org.whole.lang.xml.model.Document)

Example 3 with Document

use of org.whole.lang.xml.model.Document in project whole by wholeplatform.

the class XmlNormalizerBuilderTest method testNormalizationWithCDataSectMerge.

@Test
public void testNormalizationWithCDataSectMerge() {
    try {
        // create queries
        Path findNestedContent = (Path) XmlNormalizerBuilderTemplateManager.instance().create("findNestedContent");
        Path findMissingContentEntities = (Path) XmlNormalizerBuilderTemplateManager.instance().create("findMissingContentEntities");
        Path findConsecutiveCharDataOrCDataSect = (Path) XmlNormalizerBuilderTemplateManager.instance().create("findConsecutiveCharDataOrCDataSect");
        // create normalized sample xml model
        SampleXmlModel sampleXmlModelTemplate = new SampleXmlModel();
        Document xmlDocument = sampleXmlModelTemplate.create();
        IBindingManager parameters = BindingManagerFactory.instance.createArguments();
        parameters.wDefValue("mergeCDataSect", true);
        ModelBuilderOperation mop = new ModelBuilderOperation();
        XmlNormalizerBuilderOperation xnop = new XmlNormalizerBuilderOperation(mop, parameters);
        sampleXmlModelTemplate.apply(xnop);
        Document normalizedXmlDocument = (Document) mop.wGetResult();
        // no nested Content
        IEntityIterator<IEntity> iterator = BehaviorUtils.compileAndLazyEvaluate(findNestedContent, normalizedXmlDocument);
        assertFalse(iterator.hasNext());
        // no nested implied Content
        iterator = BehaviorUtils.compileAndLazyEvaluate(findMissingContentEntities, normalizedXmlDocument);
        assertFalse(iterator.hasNext());
        // no consecutive CharData
        iterator = BehaviorUtils.compileAndLazyEvaluate(findConsecutiveCharDataOrCDataSect, normalizedXmlDocument);
        assertFalse(iterator.hasNext());
        // no CDataSect at all
        iterator = IteratorFactory.descendantOrSelfMatcherIterator().withPattern(XmlEntityDescriptorEnum.CDataSect);
        iterator.reset(normalizedXmlDocument);
        assertFalse(iterator.hasNext());
        // both normalization strategies must yield the same result
        assertTrue(Matcher.match(normalizedXmlDocument, NormalizerOperation.normalize(xmlDocument, parameters)));
    } catch (Exception e) {
        fail();
    }
}
Also used : Path(org.whole.lang.queries.model.Path) ModelBuilderOperation(org.whole.lang.builders.ModelBuilderOperation) XmlNormalizerBuilderOperation(org.whole.lang.xml.codebase.XmlNormalizerBuilderOperation) IEntity(org.whole.lang.model.IEntity) IBindingManager(org.whole.lang.bindings.IBindingManager) Document(org.whole.lang.xml.model.Document) Test(org.junit.Test)

Example 4 with Document

use of org.whole.lang.xml.model.Document in project whole by wholeplatform.

the class XmlNormalizerBuilderTest method testNormalizationWithoutCDataSectMerge.

@Test
public void testNormalizationWithoutCDataSectMerge() {
    try {
        // create queries
        Path findNestedContent = (Path) XmlNormalizerBuilderTemplateManager.instance().create("findNestedContent");
        Path findMissingContentEntities = (Path) XmlNormalizerBuilderTemplateManager.instance().create("findMissingContentEntities");
        Path findConsecutiveCharDataOrCDataSect = (Path) XmlNormalizerBuilderTemplateManager.instance().create("findConsecutiveCharDataOrCDataSect");
        // create sample xml model
        SampleXmlModel sampleXmlModelTemplate = new SampleXmlModel();
        Document xmlDocument = sampleXmlModelTemplate.create();
        // has nested Content
        IEntityIterator<IEntity> iterator = BehaviorUtils.compileAndLazyEvaluate(findNestedContent, xmlDocument);
        assertTrue(iterator.hasNext());
        // has nested implied Content
        iterator = BehaviorUtils.compileAndLazyEvaluate(findMissingContentEntities, xmlDocument);
        assertTrue(iterator.hasNext());
        // has consecutive CharData or consecutive CDataSect
        iterator = BehaviorUtils.compileAndLazyEvaluate(findConsecutiveCharDataOrCDataSect, xmlDocument);
        assertTrue(iterator.hasNext());
        // create normalized sample xml model
        ModelBuilderOperation mop = new ModelBuilderOperation();
        XmlNormalizerBuilderOperation xnop = new XmlNormalizerBuilderOperation(mop);
        sampleXmlModelTemplate.apply(xnop);
        Document normalizedXmlDocument = (Document) mop.wGetResult();
        // no nested Content
        iterator = BehaviorUtils.compileAndLazyEvaluate(findNestedContent, normalizedXmlDocument);
        assertFalse(iterator.hasNext());
        // no nested implied Content
        iterator = BehaviorUtils.compileAndLazyEvaluate(findMissingContentEntities, normalizedXmlDocument);
        assertFalse(iterator.hasNext());
        // no consecutive CharData or consecutive CDataSect
        iterator = BehaviorUtils.compileAndLazyEvaluate(findConsecutiveCharDataOrCDataSect, normalizedXmlDocument);
        assertFalse(iterator.hasNext());
        // both normalization strategies must yield the same result
        assertTrue(Matcher.match(normalizedXmlDocument, NormalizerOperation.normalize(xmlDocument)));
    } catch (Exception e) {
        fail();
    }
}
Also used : Path(org.whole.lang.queries.model.Path) ModelBuilderOperation(org.whole.lang.builders.ModelBuilderOperation) IEntity(org.whole.lang.model.IEntity) XmlNormalizerBuilderOperation(org.whole.lang.xml.codebase.XmlNormalizerBuilderOperation) Document(org.whole.lang.xml.model.Document) Test(org.junit.Test)

Example 5 with Document

use of org.whole.lang.xml.model.Document in project whole by wholeplatform.

the class XsdModelBuilderTest method testBuilderAPI.

@Category(KnownFailingTests.class)
@Test
public void testBuilderAPI() throws Exception {
    Schema xsdFromInputStream = (Schema) XsdPersistenceKit.instance().readModel(new StreamPersistenceProvider(getInputStream("datatypes.xsd")));
    Document document = (Document) XmlSourcePersistenceKit.instance().readModel(new StreamPersistenceProvider(getInputStream("datatypes.xsd")));
    IBindingManager bm = BindingManagerFactory.instance.createBindingManager();
    bm.wDefValue("mergeCDataSect", true);
    XsdDeployStrategies.setDeployStrategy(bm, XsdDeployStrategies.ALL);
    ModelBuilderOperation mop = new ModelBuilderOperation();
    IBuilderOperation xsdBuilderOperation = new XmlSpecific2XsdBuilderAdapterOperation(mop, bm);
    XmlNormalizerBuilderOperation normalizerOp = new XmlNormalizerBuilderOperation(xsdBuilderOperation, bm);
    ModelTemplate template = new ModelTemplate(document);
    template.apply(new XmlGenericBuilderAdapter((IXmlBuilder) normalizerOp.wGetBuilder(XmlLanguageKit.URI)));
    Schema xsdFromXmlModel = (Schema) mop.wGetResult();
    Assert.assertTrue(Matcher.match(xsdFromInputStream, xsdFromXmlModel));
}
Also used : ModelBuilderOperation(org.whole.lang.builders.ModelBuilderOperation) ModelTemplate(org.whole.lang.templates.ModelTemplate) IBuilderOperation(org.whole.lang.builders.IBuilderOperation) XmlNormalizerBuilderOperation(org.whole.lang.xml.codebase.XmlNormalizerBuilderOperation) XmlGenericBuilderAdapter(org.whole.lang.xml.builders.XmlGenericBuilderAdapter) Schema(org.whole.lang.xsd.model.Schema) IBindingManager(org.whole.lang.bindings.IBindingManager) IXmlBuilder(org.whole.lang.xml.builders.IXmlBuilder) StreamPersistenceProvider(org.whole.lang.codebase.StreamPersistenceProvider) Document(org.whole.lang.xml.model.Document) Category(org.junit.experimental.categories.Category) Test(org.junit.Test)

Aggregations

Document (org.whole.lang.xml.model.Document)5 Test (org.junit.Test)4 ModelBuilderOperation (org.whole.lang.builders.ModelBuilderOperation)4 IEntity (org.whole.lang.model.IEntity)3 XmlNormalizerBuilderOperation (org.whole.lang.xml.codebase.XmlNormalizerBuilderOperation)3 IBindingManager (org.whole.lang.bindings.IBindingManager)2 Path (org.whole.lang.queries.model.Path)2 ModelTemplate (org.whole.lang.templates.ModelTemplate)2 ArrayList (java.util.ArrayList)1 Category (org.junit.experimental.categories.Category)1 IBuilderOperation (org.whole.lang.builders.IBuilderOperation)1 StreamPersistenceProvider (org.whole.lang.codebase.StreamPersistenceProvider)1 IXmlBuilder (org.whole.lang.xml.builders.IXmlBuilder)1 XmlGenericBuilderAdapter (org.whole.lang.xml.builders.XmlGenericBuilderAdapter)1 SaxConsumerHandler (org.whole.lang.xml.util.SaxConsumerHandler)1 SaxHandlerBuilderOperation (org.whole.lang.xml.util.SaxHandlerBuilderOperation)1 Schema (org.whole.lang.xsd.model.Schema)1