Search in sources :

Example 1 with XmlNormalizerBuilderOperation

use of org.whole.lang.xml.codebase.XmlNormalizerBuilderOperation in project whole by wholeplatform.

the class AbstractXsiPersistenceKit method doReadModel.

@Override
protected IEntity doReadModel(IPersistenceProvider pp) throws Exception {
    IBindingManager bm = pp.getBindings();
    ModelBuilderOperation mop = new ModelBuilderOperation(RegistryConfigurations.RESOLVER);
    IBuilderOperation xsiBuilderOperation = getBuilderOperation(mop, bm);
    bm.wDefValue("mergeCDataSect", true);
    XmlNormalizerBuilderOperation normalizerOp = new XmlNormalizerBuilderOperation(xsiBuilderOperation, bm);
    SaxConsumerHandler.parse(pp.getInputStream(), pp.getEncoding(), normalizerOp);
    return mop.wGetResult();
}
Also used : ModelBuilderOperation(org.whole.lang.builders.ModelBuilderOperation) IBuilderOperation(org.whole.lang.builders.IBuilderOperation) XmlNormalizerBuilderOperation(org.whole.lang.xml.codebase.XmlNormalizerBuilderOperation) IBindingManager(org.whole.lang.bindings.IBindingManager)

Example 2 with XmlNormalizerBuilderOperation

use of org.whole.lang.xml.codebase.XmlNormalizerBuilderOperation 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 3 with XmlNormalizerBuilderOperation

use of org.whole.lang.xml.codebase.XmlNormalizerBuilderOperation 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 4 with XmlNormalizerBuilderOperation

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

Example 5 with XmlNormalizerBuilderOperation

use of org.whole.lang.xml.codebase.XmlNormalizerBuilderOperation in project whole by wholeplatform.

the class XsiModelTemplateTest method testXsiModelTemplate.

@Category({ KnownFailingTests.class, SlowTests.class })
@Test
public void testXsiModelTemplate() throws Exception {
    fail();
    IBindingManager bm = BindingManagerFactory.instance.createBindingManager();
    bm.wDefValue("folderLocation", new File("test/org/whole/lang/xsd/templates").getAbsolutePath());
    bm.wDefValue("packageName", "");
    XsdDeployStrategies.setDeployStrategy(bm, XsdDeployStrategies.ALL);
    String fileName = "S202SCTDIRPFRAA0001.C.xml";
    IEntity xsiModel = XsiPersistenceKit.instance().readModel(new StreamPersistenceProvider(getInputStream(fileName), null, bm));
    CommonsEntityFactory.instance.createRootFragment(xsiModel.wGetAdapter(CommonsEntityDescriptorEnum.Any));
    IEntity xmlModel = XmlSourcePersistenceKit.instance().readModel(new StreamPersistenceProvider(getInputStream(fileName), null, bm));
    CommonsEntityFactory.instance.createRootFragment(xmlModel.wGetAdapter(CommonsEntityDescriptorEnum.Any));
    ModelBuilderOperation mop = new ModelBuilderOperation();
    XmlNormalizerBuilderOperation xnbo = new XmlNormalizerBuilderOperation(mop);
    XsiModelTemplate xsiModelTemplate = new XsiModelTemplate(xsiModel);
    xsiModelTemplate.apply(xnbo);
    IEntity xmlModelFromXsiModel = mop.wGetResult();
    Assert.assertTrue(Matcher.match(xmlModelFromXsiModel, xmlModel));
}
Also used : ModelBuilderOperation(org.whole.lang.builders.ModelBuilderOperation) IEntity(org.whole.lang.model.IEntity) XmlNormalizerBuilderOperation(org.whole.lang.xml.codebase.XmlNormalizerBuilderOperation) IBindingManager(org.whole.lang.bindings.IBindingManager) StreamPersistenceProvider(org.whole.lang.codebase.StreamPersistenceProvider) File(java.io.File) Category(org.junit.experimental.categories.Category) Test(org.junit.Test)

Aggregations

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