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();
}
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();
}
}
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();
}
}
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));
}
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));
}
Aggregations